@clawswarm/core 0.1.0-alpha
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/README.md +41 -0
- package/dist/agent.d.ts +79 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +146 -0
- package/dist/agent.js.map +1 -0
- package/dist/chief.d.ts +80 -0
- package/dist/chief.d.ts.map +1 -0
- package/dist/chief.js +221 -0
- package/dist/chief.js.map +1 -0
- package/dist/clawswarm.d.ts +84 -0
- package/dist/clawswarm.d.ts.map +1 -0
- package/dist/clawswarm.js +224 -0
- package/dist/clawswarm.js.map +1 -0
- package/dist/goal.d.ts +66 -0
- package/dist/goal.d.ts.map +1 -0
- package/dist/goal.js +164 -0
- package/dist/goal.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/swarm.d.ts +67 -0
- package/dist/swarm.d.ts.map +1 -0
- package/dist/swarm.js +201 -0
- package/dist/swarm.js.map +1 -0
- package/dist/task.d.ts +86 -0
- package/dist/task.d.ts.map +1 -0
- package/dist/task.js +177 -0
- package/dist/task.js.map +1 -0
- package/dist/types.d.ts +189 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/package.json +67 -0
- package/src/__tests__/integration.test.ts +686 -0
- package/src/agent.ts +163 -0
- package/src/chief.ts +264 -0
- package/src/clawswarm.ts +257 -0
- package/src/goal.ts +183 -0
- package/src/index.ts +62 -0
- package/src/swarm.ts +225 -0
- package/src/task.ts +204 -0
- package/src/types.ts +240 -0
- package/tsconfig.json +11 -0
- package/tsconfig.tsbuildinfo +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# @clawswarm/core
|
|
2
|
+
|
|
3
|
+
The core agent framework for ClawSwarm. Provides the base classes and types for building multi-agent systems.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @clawswarm/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { ClawSwarm, Agent, Goal } from '@clawswarm/core';
|
|
15
|
+
|
|
16
|
+
const swarm = new ClawSwarm({
|
|
17
|
+
agents: [
|
|
18
|
+
Agent.research({ model: 'claude-sonnet-4' }),
|
|
19
|
+
Agent.code({ model: 'gpt-4o' }),
|
|
20
|
+
],
|
|
21
|
+
chiefReview: {
|
|
22
|
+
autoApproveThreshold: 8,
|
|
23
|
+
humanReviewThreshold: 5,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const goal = await swarm.createGoal({
|
|
28
|
+
title: 'Build a REST API',
|
|
29
|
+
description: 'Create a Node.js REST API with authentication',
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const result = await swarm.execute(goal);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## API
|
|
36
|
+
|
|
37
|
+
See the [API Reference](../../docs/api-reference.md) for full documentation.
|
|
38
|
+
|
|
39
|
+
## License
|
|
40
|
+
|
|
41
|
+
MIT
|
package/dist/agent.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Agent class and specialist agent factories.
|
|
3
|
+
* @module @clawswarm/core/agent
|
|
4
|
+
*/
|
|
5
|
+
import { AgentConfig, AgentStatus, AgentType, ModelId, Task, Deliverable } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Base class for all ClawSwarm agents.
|
|
8
|
+
* Extend this to create custom specialist agents.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* class MyCustomAgent extends Agent {
|
|
13
|
+
* async execute(task: Task): Promise<Deliverable[]> {
|
|
14
|
+
* // your custom logic here
|
|
15
|
+
* return [{ type: 'text', label: 'Output', content: '...' }];
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare class Agent {
|
|
21
|
+
readonly id: string;
|
|
22
|
+
readonly config: AgentConfig;
|
|
23
|
+
status: AgentStatus;
|
|
24
|
+
currentTaskId?: string;
|
|
25
|
+
constructor(config: AgentConfig);
|
|
26
|
+
/** Agent's display name */
|
|
27
|
+
get name(): string;
|
|
28
|
+
/** Agent's specialization type */
|
|
29
|
+
get type(): AgentType;
|
|
30
|
+
/**
|
|
31
|
+
* Execute a task and return deliverables.
|
|
32
|
+
* Override this in custom agents.
|
|
33
|
+
*
|
|
34
|
+
* @param task - The task to execute
|
|
35
|
+
* @returns Array of deliverables produced
|
|
36
|
+
*/
|
|
37
|
+
execute(task: Task): Promise<Deliverable[]>;
|
|
38
|
+
/**
|
|
39
|
+
* Check if this agent can handle a given task type.
|
|
40
|
+
* Override to restrict which tasks this agent accepts.
|
|
41
|
+
*/
|
|
42
|
+
canHandle(_task: Task): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Get the system prompt for this agent.
|
|
45
|
+
* Override to customize the agent's behavior.
|
|
46
|
+
*/
|
|
47
|
+
getSystemPrompt(): string;
|
|
48
|
+
/**
|
|
49
|
+
* Create a ResearchClaw agent.
|
|
50
|
+
* Specializes in information gathering, analysis, and written reports.
|
|
51
|
+
*/
|
|
52
|
+
static research(options: Partial<AgentConfig> & {
|
|
53
|
+
model: ModelId;
|
|
54
|
+
}): AgentConfig;
|
|
55
|
+
/**
|
|
56
|
+
* Create a CodeClaw agent.
|
|
57
|
+
* Specializes in writing, reviewing, and debugging code.
|
|
58
|
+
*/
|
|
59
|
+
static code(options: Partial<AgentConfig> & {
|
|
60
|
+
model: ModelId;
|
|
61
|
+
}): AgentConfig;
|
|
62
|
+
/**
|
|
63
|
+
* Create an OpsClaw agent.
|
|
64
|
+
* Specializes in infrastructure, deployment, and monitoring.
|
|
65
|
+
*/
|
|
66
|
+
static ops(options: Partial<AgentConfig> & {
|
|
67
|
+
model: ModelId;
|
|
68
|
+
}): AgentConfig;
|
|
69
|
+
/**
|
|
70
|
+
* Create a Planner agent.
|
|
71
|
+
* Decomposes goals into tasks and assigns them to specialist agents.
|
|
72
|
+
*/
|
|
73
|
+
static planner(options: Partial<AgentConfig> & {
|
|
74
|
+
model: ModelId;
|
|
75
|
+
}): AgentConfig;
|
|
76
|
+
private _defaultName;
|
|
77
|
+
private _defaultSystemPrompt;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAI7F;;;;;;;;;;;;;GAaG;AACH,qBAAa,KAAK;IAChB,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,SAAgB,MAAM,EAAE,WAAW,CAAC;IAC7B,MAAM,EAAE,WAAW,CAAU;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;gBAElB,MAAM,EAAE,WAAW;IAK/B,2BAA2B;IAC3B,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,kCAAkC;IAClC,IAAI,IAAI,IAAI,SAAS,CAEpB;IAED;;;;;;OAMG;IACG,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAIjD;;;OAGG;IACH,SAAS,CAAC,KAAK,EAAE,IAAI,GAAG,OAAO;IAI/B;;;OAGG;IACH,eAAe,IAAI,MAAM;IAMzB;;;OAGG;IACH,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG;QAAE,KAAK,EAAE,OAAO,CAAA;KAAE,GAAG,WAAW;IAShF;;;OAGG;IACH,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG;QAAE,KAAK,EAAE,OAAO,CAAA;KAAE,GAAG,WAAW;IAS5E;;;OAGG;IACH,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG;QAAE,KAAK,EAAE,OAAO,CAAA;KAAE,GAAG,WAAW;IAS3E;;;OAGG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG;QAAE,KAAK,EAAE,OAAO,CAAA;KAAE,GAAG,WAAW;IAW/E,OAAO,CAAC,YAAY;IAWpB,OAAO,CAAC,oBAAoB;CAwB7B"}
|
package/dist/agent.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Base Agent class and specialist agent factories.
|
|
4
|
+
* @module @clawswarm/core/agent
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.Agent = void 0;
|
|
8
|
+
// ─── Agent Base Class ─────────────────────────────────────────────────────────
|
|
9
|
+
/**
|
|
10
|
+
* Base class for all ClawSwarm agents.
|
|
11
|
+
* Extend this to create custom specialist agents.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* class MyCustomAgent extends Agent {
|
|
16
|
+
* async execute(task: Task): Promise<Deliverable[]> {
|
|
17
|
+
* // your custom logic here
|
|
18
|
+
* return [{ type: 'text', label: 'Output', content: '...' }];
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
class Agent {
|
|
24
|
+
id;
|
|
25
|
+
config;
|
|
26
|
+
status = 'idle';
|
|
27
|
+
currentTaskId;
|
|
28
|
+
constructor(config) {
|
|
29
|
+
this.config = config;
|
|
30
|
+
this.id = `agent-${config.type}-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`;
|
|
31
|
+
}
|
|
32
|
+
/** Agent's display name */
|
|
33
|
+
get name() {
|
|
34
|
+
return this.config.name ?? this._defaultName(this.config.type);
|
|
35
|
+
}
|
|
36
|
+
/** Agent's specialization type */
|
|
37
|
+
get type() {
|
|
38
|
+
return this.config.type;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Execute a task and return deliverables.
|
|
42
|
+
* Override this in custom agents.
|
|
43
|
+
*
|
|
44
|
+
* @param task - The task to execute
|
|
45
|
+
* @returns Array of deliverables produced
|
|
46
|
+
*/
|
|
47
|
+
async execute(task) {
|
|
48
|
+
throw new Error(`Agent.execute() must be implemented. Agent: ${this.name}, Task: ${task.id}`);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Check if this agent can handle a given task type.
|
|
52
|
+
* Override to restrict which tasks this agent accepts.
|
|
53
|
+
*/
|
|
54
|
+
canHandle(_task) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get the system prompt for this agent.
|
|
59
|
+
* Override to customize the agent's behavior.
|
|
60
|
+
*/
|
|
61
|
+
getSystemPrompt() {
|
|
62
|
+
return this.config.systemPrompt ?? this._defaultSystemPrompt(this.config.type);
|
|
63
|
+
}
|
|
64
|
+
// ─── Factory Methods ─────────────────────────────────────────────────────────
|
|
65
|
+
/**
|
|
66
|
+
* Create a ResearchClaw agent.
|
|
67
|
+
* Specializes in information gathering, analysis, and written reports.
|
|
68
|
+
*/
|
|
69
|
+
static research(options) {
|
|
70
|
+
return {
|
|
71
|
+
type: 'research',
|
|
72
|
+
name: 'ResearchClaw',
|
|
73
|
+
tools: ['web_search', 'web_fetch', 'summarize'],
|
|
74
|
+
...options,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Create a CodeClaw agent.
|
|
79
|
+
* Specializes in writing, reviewing, and debugging code.
|
|
80
|
+
*/
|
|
81
|
+
static code(options) {
|
|
82
|
+
return {
|
|
83
|
+
type: 'code',
|
|
84
|
+
name: 'CodeClaw',
|
|
85
|
+
tools: ['read_file', 'write_file', 'execute_code', 'run_tests'],
|
|
86
|
+
...options,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Create an OpsClaw agent.
|
|
91
|
+
* Specializes in infrastructure, deployment, and monitoring.
|
|
92
|
+
*/
|
|
93
|
+
static ops(options) {
|
|
94
|
+
return {
|
|
95
|
+
type: 'ops',
|
|
96
|
+
name: 'OpsClaw',
|
|
97
|
+
tools: ['shell', 'docker', 'kubernetes', 'monitoring'],
|
|
98
|
+
...options,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Create a Planner agent.
|
|
103
|
+
* Decomposes goals into tasks and assigns them to specialist agents.
|
|
104
|
+
*/
|
|
105
|
+
static planner(options) {
|
|
106
|
+
return {
|
|
107
|
+
type: 'planner',
|
|
108
|
+
name: 'Planner',
|
|
109
|
+
tools: [],
|
|
110
|
+
...options,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
// ─── Private Helpers ─────────────────────────────────────────────────────────
|
|
114
|
+
_defaultName(type) {
|
|
115
|
+
const names = {
|
|
116
|
+
research: 'ResearchClaw',
|
|
117
|
+
code: 'CodeClaw',
|
|
118
|
+
ops: 'OpsClaw',
|
|
119
|
+
planner: 'Planner',
|
|
120
|
+
custom: 'CustomAgent',
|
|
121
|
+
};
|
|
122
|
+
return names[type] ?? 'Agent';
|
|
123
|
+
}
|
|
124
|
+
_defaultSystemPrompt(type) {
|
|
125
|
+
const prompts = {
|
|
126
|
+
research: `You are ResearchClaw, a specialist research agent.
|
|
127
|
+
Your job is to gather information, analyze data, synthesize findings, and produce clear written reports.
|
|
128
|
+
Always cite your sources. Prioritize accuracy over speed. Flag uncertainty explicitly.`,
|
|
129
|
+
code: `You are CodeClaw, a specialist software engineering agent.
|
|
130
|
+
Your job is to write clean, well-tested, production-ready code.
|
|
131
|
+
Follow best practices for the language/framework. Write tests. Document your code.
|
|
132
|
+
Never ship broken code.`,
|
|
133
|
+
ops: `You are OpsClaw, a specialist infrastructure and operations agent.
|
|
134
|
+
Your job is to deploy, monitor, and optimize systems.
|
|
135
|
+
Prefer idempotent operations. Document every change. Always have a rollback plan.`,
|
|
136
|
+
planner: `You are the Planner, responsible for decomposing high-level goals into concrete tasks.
|
|
137
|
+
Break goals into the smallest meaningful units of work.
|
|
138
|
+
Assign each task to the most appropriate specialist agent.
|
|
139
|
+
Identify dependencies between tasks and sequence them correctly.`,
|
|
140
|
+
custom: `You are a custom ClawSwarm agent. Follow your configured instructions.`,
|
|
141
|
+
};
|
|
142
|
+
return prompts[type] ?? prompts.custom;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.Agent = Agent;
|
|
146
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,iFAAiF;AAEjF;;;;;;;;;;;;;GAaG;AACH,MAAa,KAAK;IACA,EAAE,CAAS;IACX,MAAM,CAAc;IAC7B,MAAM,GAAgB,MAAM,CAAC;IAC7B,aAAa,CAAU;IAE9B,YAAY,MAAmB;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,EAAE,GAAG,SAAS,MAAM,CAAC,IAAI,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;IAC3F,CAAC;IAED,2BAA2B;IAC3B,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC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EAAE,SAAS;YACf,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,EAAE;YACT,GAAG,OAAO;SACX,CAAC;IACJ,CAAC;IAED,gFAAgF;IAExE,YAAY,CAAC,IAAe;QAClC,MAAM,KAAK,GAA8B;YACvC,QAAQ,EAAE,cAAc;YACxB,IAAI,EAAE,UAAU;YAChB,GAAG,EAAE,SAAS;YACd,OAAO,EAAE,SAAS;YAClB,MAAM,EAAE,aAAa;SACtB,CAAC;QACF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC;IAChC,CAAC;IAEO,oBAAoB,CAAC,IAAe;QAC1C,MAAM,OAAO,GAA8B;YACzC,QAAQ,EAAE;;uFAEuE;YAEjF,IAAI,EAAE;;;wBAGY;YAElB,GAAG,EAAE;;kFAEuE;YAE5E,OAAO,EAAE;;;iEAGkD;YAE3D,MAAM,EAAE,wEAAwE;SACjF,CAAC;QACF,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC;IACzC,CAAC;CACF;AA3ID,sBA2IC"}
|
package/dist/chief.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chief review pipeline — the quality gate for ClawSwarm.
|
|
3
|
+
*
|
|
4
|
+
* Every task deliverable passes through a 3-tier scoring system:
|
|
5
|
+
* - Score ≥ autoApproveThreshold (default 8) → auto-approved
|
|
6
|
+
* - Score ≥ humanReviewThreshold (default 5) → human review required
|
|
7
|
+
* - Score < humanReviewThreshold → auto-rejected + rework
|
|
8
|
+
*
|
|
9
|
+
* @module @clawswarm/core/chief
|
|
10
|
+
*/
|
|
11
|
+
import EventEmitter from 'eventemitter3';
|
|
12
|
+
import { Task, ReviewResult, ChiefReviewConfig } from './types.js';
|
|
13
|
+
/**
|
|
14
|
+
* The Chief Reviewer evaluates task deliverables against a rubric
|
|
15
|
+
* and decides whether to approve, send for human review, or reject.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const reviewer = new ChiefReviewer({
|
|
20
|
+
* autoApproveThreshold: 8,
|
|
21
|
+
* humanReviewThreshold: 5,
|
|
22
|
+
* reviewerModel: 'claude-opus-4',
|
|
23
|
+
* criteria: ['completeness', 'accuracy', 'quality'],
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* const result = await reviewer.review(task);
|
|
27
|
+
*
|
|
28
|
+
* if (result.decision === 'approved') {
|
|
29
|
+
* console.log('✅ Task approved!', result.score);
|
|
30
|
+
* } else if (result.decision === 'human_review') {
|
|
31
|
+
* console.log('👀 Needs human review', result.feedback);
|
|
32
|
+
* } else {
|
|
33
|
+
* console.log('❌ Rejected:', result.issues);
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare class ChiefReviewer extends EventEmitter {
|
|
38
|
+
private readonly autoApproveThreshold;
|
|
39
|
+
private readonly humanReviewThreshold;
|
|
40
|
+
private readonly reviewerModel;
|
|
41
|
+
private readonly criteria;
|
|
42
|
+
constructor(config?: ChiefReviewConfig);
|
|
43
|
+
/**
|
|
44
|
+
* Review a task and produce a structured ReviewResult.
|
|
45
|
+
*
|
|
46
|
+
* @param task - The task to review (must have deliverables)
|
|
47
|
+
* @returns A ReviewResult with score, decision, and feedback
|
|
48
|
+
*/
|
|
49
|
+
review(task: Task): Promise<ReviewResult>;
|
|
50
|
+
/**
|
|
51
|
+
* Synchronously check what decision would be made for a given score.
|
|
52
|
+
* Useful for dry-runs and testing.
|
|
53
|
+
*/
|
|
54
|
+
scoreToDecision(score: number): ReviewResult['decision'];
|
|
55
|
+
/**
|
|
56
|
+
* Get the current review configuration (read-only).
|
|
57
|
+
*/
|
|
58
|
+
get config(): Required<ChiefReviewConfig>;
|
|
59
|
+
/**
|
|
60
|
+
* Build a review prompt for the LLM.
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
private _buildPrompt;
|
|
64
|
+
/**
|
|
65
|
+
* Call the LLM reviewer. In production, replace the stub with a real LLM call.
|
|
66
|
+
* @internal
|
|
67
|
+
*/
|
|
68
|
+
private _callReviewerLLM;
|
|
69
|
+
/**
|
|
70
|
+
* Assemble a ReviewResult from raw LLM data.
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
private _buildResult;
|
|
74
|
+
/**
|
|
75
|
+
* Validate that thresholds are logically consistent.
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
private _validateThresholds;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=chief.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chief.d.ts","sourceRoot":"","sources":["../src/chief.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,EACL,IAAI,EACJ,YAAY,EACZ,iBAAiB,EAElB,MAAM,YAAY,CAAC;AAkBpB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,aAAc,SAAQ,YAAY;IAC7C,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAS;IAC9C,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAS;IAC9C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAU;IACxC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;gBAExB,MAAM,GAAE,iBAAsB;IAU1C;;;;;OAKG;IACG,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,YAAY,CAAC;IAoB/C;;;OAGG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,CAAC,UAAU,CAAC;IAMxD;;OAEG;IACH,IAAI,MAAM,IAAI,QAAQ,CAAC,iBAAiB,CAAC,CAOxC;IAID;;;OAGG;IACH,OAAO,CAAC,YAAY;IAmCpB;;;OAGG;YACW,gBAAgB;IA8C9B;;;OAGG;IACH,OAAO,CAAC,YAAY;IAqBpB;;;OAGG;IACH,OAAO,CAAC,mBAAmB;CAW5B"}
|
package/dist/chief.js
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Chief review pipeline — the quality gate for ClawSwarm.
|
|
4
|
+
*
|
|
5
|
+
* Every task deliverable passes through a 3-tier scoring system:
|
|
6
|
+
* - Score ≥ autoApproveThreshold (default 8) → auto-approved
|
|
7
|
+
* - Score ≥ humanReviewThreshold (default 5) → human review required
|
|
8
|
+
* - Score < humanReviewThreshold → auto-rejected + rework
|
|
9
|
+
*
|
|
10
|
+
* @module @clawswarm/core/chief
|
|
11
|
+
*/
|
|
12
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.ChiefReviewer = void 0;
|
|
17
|
+
const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
18
|
+
// ─── Constants ────────────────────────────────────────────────────────────────
|
|
19
|
+
const DEFAULT_AUTO_APPROVE_THRESHOLD = 8;
|
|
20
|
+
const DEFAULT_HUMAN_REVIEW_THRESHOLD = 5;
|
|
21
|
+
const DEFAULT_REVIEWER_MODEL = 'claude-sonnet-4';
|
|
22
|
+
const DEFAULT_CRITERIA = [
|
|
23
|
+
'completeness: Does the output fully address the task requirements?',
|
|
24
|
+
'accuracy: Is the information correct and well-sourced?',
|
|
25
|
+
'quality: Is the output production-ready (no TODOs, no placeholders)?',
|
|
26
|
+
'clarity: Is the output clear, well-structured, and easy to understand?',
|
|
27
|
+
'safety: Does the output avoid harmful, biased, or problematic content?',
|
|
28
|
+
];
|
|
29
|
+
// ─── Chief Reviewer ───────────────────────────────────────────────────────────
|
|
30
|
+
/**
|
|
31
|
+
* The Chief Reviewer evaluates task deliverables against a rubric
|
|
32
|
+
* and decides whether to approve, send for human review, or reject.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const reviewer = new ChiefReviewer({
|
|
37
|
+
* autoApproveThreshold: 8,
|
|
38
|
+
* humanReviewThreshold: 5,
|
|
39
|
+
* reviewerModel: 'claude-opus-4',
|
|
40
|
+
* criteria: ['completeness', 'accuracy', 'quality'],
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* const result = await reviewer.review(task);
|
|
44
|
+
*
|
|
45
|
+
* if (result.decision === 'approved') {
|
|
46
|
+
* console.log('✅ Task approved!', result.score);
|
|
47
|
+
* } else if (result.decision === 'human_review') {
|
|
48
|
+
* console.log('👀 Needs human review', result.feedback);
|
|
49
|
+
* } else {
|
|
50
|
+
* console.log('❌ Rejected:', result.issues);
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
class ChiefReviewer extends eventemitter3_1.default {
|
|
55
|
+
autoApproveThreshold;
|
|
56
|
+
humanReviewThreshold;
|
|
57
|
+
reviewerModel;
|
|
58
|
+
criteria;
|
|
59
|
+
constructor(config = {}) {
|
|
60
|
+
super();
|
|
61
|
+
this.autoApproveThreshold = config.autoApproveThreshold ?? DEFAULT_AUTO_APPROVE_THRESHOLD;
|
|
62
|
+
this.humanReviewThreshold = config.humanReviewThreshold ?? DEFAULT_HUMAN_REVIEW_THRESHOLD;
|
|
63
|
+
this.reviewerModel = config.reviewerModel ?? DEFAULT_REVIEWER_MODEL;
|
|
64
|
+
this.criteria = config.criteria ?? DEFAULT_CRITERIA;
|
|
65
|
+
this._validateThresholds();
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Review a task and produce a structured ReviewResult.
|
|
69
|
+
*
|
|
70
|
+
* @param task - The task to review (must have deliverables)
|
|
71
|
+
* @returns A ReviewResult with score, decision, and feedback
|
|
72
|
+
*/
|
|
73
|
+
async review(task) {
|
|
74
|
+
if (task.deliverables.length === 0) {
|
|
75
|
+
return this._buildResult(task.id, 0, [], ['No deliverables were produced by the agent.'], []);
|
|
76
|
+
}
|
|
77
|
+
// In production: call LLM with structured review prompt
|
|
78
|
+
const raw = await this._callReviewerLLM(task);
|
|
79
|
+
const result = this._buildResult(task.id, raw.score, raw.issues, raw.suggestions, raw.feedback);
|
|
80
|
+
this.emit('reviewed', result);
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Synchronously check what decision would be made for a given score.
|
|
85
|
+
* Useful for dry-runs and testing.
|
|
86
|
+
*/
|
|
87
|
+
scoreToDecision(score) {
|
|
88
|
+
if (score >= this.autoApproveThreshold)
|
|
89
|
+
return 'approved';
|
|
90
|
+
if (score >= this.humanReviewThreshold)
|
|
91
|
+
return 'human_review';
|
|
92
|
+
return 'rejected';
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get the current review configuration (read-only).
|
|
96
|
+
*/
|
|
97
|
+
get config() {
|
|
98
|
+
return {
|
|
99
|
+
autoApproveThreshold: this.autoApproveThreshold,
|
|
100
|
+
humanReviewThreshold: this.humanReviewThreshold,
|
|
101
|
+
reviewerModel: this.reviewerModel,
|
|
102
|
+
criteria: this.criteria,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
// ─── Private ──────────────────────────────────────────────────────────────
|
|
106
|
+
/**
|
|
107
|
+
* Build a review prompt for the LLM.
|
|
108
|
+
* @internal
|
|
109
|
+
*/
|
|
110
|
+
_buildPrompt(task) {
|
|
111
|
+
const deliverablesSummary = task.deliverables
|
|
112
|
+
.map((d, i) => `[${i + 1}] ${d.label} (${d.type}):\n${d.content.slice(0, 2000)}`)
|
|
113
|
+
.join('\n\n');
|
|
114
|
+
const criteriaList = this.criteria.map((c, i) => `${i + 1}. ${c}`).join('\n');
|
|
115
|
+
return `You are a Chief Reviewer for an AI agent system. Your job is to objectively score the quality of agent-produced work.
|
|
116
|
+
|
|
117
|
+
## Task
|
|
118
|
+
Title: ${task.title}
|
|
119
|
+
Description: ${task.description}
|
|
120
|
+
|
|
121
|
+
## Deliverables
|
|
122
|
+
${deliverablesSummary}
|
|
123
|
+
|
|
124
|
+
## Review Criteria (score each 0-10, then average)
|
|
125
|
+
${criteriaList}
|
|
126
|
+
|
|
127
|
+
## Instructions
|
|
128
|
+
1. Score each criterion from 0 to 10
|
|
129
|
+
2. Identify specific issues (things that are wrong or missing)
|
|
130
|
+
3. Provide concrete suggestions for improvement
|
|
131
|
+
4. Give an overall score (0-10) and a 2-3 sentence summary
|
|
132
|
+
|
|
133
|
+
Respond in JSON:
|
|
134
|
+
{
|
|
135
|
+
"criteriaScores": { "<criterion>": <score> },
|
|
136
|
+
"overallScore": <number>,
|
|
137
|
+
"issues": ["<issue1>", ...],
|
|
138
|
+
"suggestions": ["<suggestion1>", ...],
|
|
139
|
+
"feedback": "<2-3 sentence summary>"
|
|
140
|
+
}`;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Call the LLM reviewer. In production, replace the stub with a real LLM call.
|
|
144
|
+
* @internal
|
|
145
|
+
*/
|
|
146
|
+
async _callReviewerLLM(task) {
|
|
147
|
+
// ── Production stub ──────────────────────────────────────────────────────
|
|
148
|
+
// Replace this with your actual LLM client call, e.g.:
|
|
149
|
+
//
|
|
150
|
+
// const response = await openai.chat.completions.create({
|
|
151
|
+
// model: this.reviewerModel,
|
|
152
|
+
// messages: [{ role: 'user', content: this._buildPrompt(task) }],
|
|
153
|
+
// response_format: { type: 'json_object' },
|
|
154
|
+
// });
|
|
155
|
+
// return JSON.parse(response.choices[0].message.content!);
|
|
156
|
+
//
|
|
157
|
+
// ────────────────────────────────────────────────────────────────────────
|
|
158
|
+
void this._buildPrompt(task); // reference so it's not dead code
|
|
159
|
+
// Stub: evaluate based on deliverable completeness heuristics
|
|
160
|
+
const hasContent = task.deliverables.some(d => d.content.trim().length > 100);
|
|
161
|
+
const hasTodo = task.deliverables.some(d => /TODO|FIXME|placeholder/i.test(d.content));
|
|
162
|
+
const hasCode = task.deliverables.some(d => d.type === 'code');
|
|
163
|
+
const contentLength = task.deliverables.reduce((sum, d) => sum + d.content.length, 0);
|
|
164
|
+
let score = hasContent ? 7 : 3;
|
|
165
|
+
if (hasTodo)
|
|
166
|
+
score -= 2;
|
|
167
|
+
if (hasCode && contentLength > 500)
|
|
168
|
+
score += 1;
|
|
169
|
+
score = Math.max(0, Math.min(10, score));
|
|
170
|
+
const issues = [];
|
|
171
|
+
const suggestions = [];
|
|
172
|
+
if (!hasContent)
|
|
173
|
+
issues.push('Deliverables appear to be empty or too short.');
|
|
174
|
+
if (hasTodo) {
|
|
175
|
+
issues.push('Output contains TODO/FIXME markers — not production-ready.');
|
|
176
|
+
suggestions.push('Complete all TODO items before submitting.');
|
|
177
|
+
}
|
|
178
|
+
if (contentLength < 200)
|
|
179
|
+
suggestions.push('Expand the output with more detail.');
|
|
180
|
+
return {
|
|
181
|
+
score,
|
|
182
|
+
issues,
|
|
183
|
+
suggestions,
|
|
184
|
+
feedback: issues.length === 0
|
|
185
|
+
? 'Work looks complete and meets the task requirements.'
|
|
186
|
+
: `Found ${issues.length} issue(s) that need attention before approval.`,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Assemble a ReviewResult from raw LLM data.
|
|
191
|
+
* @internal
|
|
192
|
+
*/
|
|
193
|
+
_buildResult(taskId, score, issues, suggestions, feedback) {
|
|
194
|
+
const clampedScore = Math.max(0, Math.min(10, score));
|
|
195
|
+
const feedbackStr = Array.isArray(feedback) ? feedback.join(' ') : feedback;
|
|
196
|
+
return {
|
|
197
|
+
taskId,
|
|
198
|
+
score: clampedScore,
|
|
199
|
+
decision: this.scoreToDecision(clampedScore),
|
|
200
|
+
feedback: feedbackStr,
|
|
201
|
+
issues,
|
|
202
|
+
suggestions,
|
|
203
|
+
reviewedAt: new Date().toISOString(),
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Validate that thresholds are logically consistent.
|
|
208
|
+
* @internal
|
|
209
|
+
*/
|
|
210
|
+
_validateThresholds() {
|
|
211
|
+
if (this.autoApproveThreshold < this.humanReviewThreshold) {
|
|
212
|
+
throw new Error(`ChiefReviewer: autoApproveThreshold (${this.autoApproveThreshold}) must be ` +
|
|
213
|
+
`>= humanReviewThreshold (${this.humanReviewThreshold})`);
|
|
214
|
+
}
|
|
215
|
+
if (this.autoApproveThreshold > 10 || this.humanReviewThreshold < 0) {
|
|
216
|
+
throw new Error('ChiefReviewer: thresholds must be between 0 and 10');
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
exports.ChiefReviewer = ChiefReviewer;
|
|
221
|
+
//# sourceMappingURL=chief.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chief.js","sourceRoot":"","sources":["../src/chief.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;AAEH,kEAAyC;AAQzC,iFAAiF;AAEjF,MAAM,8BAA8B,GAAG,CAAC,CAAC;AACzC,MAAM,8BAA8B,GAAG,CAAC,CAAC;AACzC,MAAM,sBAAsB,GAAY,iBAAiB,CAAC;AAE1D,MAAM,gBAAgB,GAAG;IACvB,oEAAoE;IACpE,wDAAwD;IACxD,sEAAsE;IACtE,wEAAwE;IACxE,wEAAwE;CACzE,CAAC;AAEF,iFAAiF;AAEjF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAa,aAAc,SAAQ,uBAAY;IAC5B,oBAAoB,CAAS;IAC7B,oBAAoB,CAAS;IAC7B,aAAa,CAAU;IACvB,QAAQ,CAAW;IAEpC,YAAY,SAA4B,EAAE;QACxC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,oBAAoB,GAAG,MAAM,CAAC,oBAAoB,IAAI,8BAA8B,CAAC;QAC1F,IAAI,CAAC,oBAAoB,GAAG,MAAM,CAAC,oBAAoB,IAAI,8BAA8B,CAAC;QAC1F,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,IAAI,sBAAsB,C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,EAChB,WAAqB,EACrB,QAA2B;QAE3B,MAAM,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC;QACtD,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;QAE5E,OAAO;YACL,MAAM;YACN,KAAK,EAAE,YAAY;YACnB,QAAQ,EAAE,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC;YAC5C,QAAQ,EAAE,WAAW;YACrB,MAAM;YACN,WAAW;YACX,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACrC,CAAC;IACJ,CAAC;IAED;;;OAGG;IACK,mBAAmB;QACzB,IAAI,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC1D,MAAM,IAAI,KAAK,CACb,wCAAwC,IAAI,CAAC,oBAAoB,YAAY;gBAC7E,4BAA4B,IAAI,CAAC,oBAAoB,GAAG,CACzD,CAAC;QACJ,CAAC;QACD,IAAI,IAAI,CAAC,oBAAoB,GAAG,EAAE,IAAI,IAAI,CAAC,oBAAoB,GAAG,CAAC,EAAE,CAAC;YACpE,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;CACF;AAnMD,sCAmMC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ClawSwarm — main orchestrator class.
|
|
3
|
+
*
|
|
4
|
+
* Creates and manages a swarm of specialist agents, decomposes goals
|
|
5
|
+
* into tasks, runs the chief review pipeline, and emits events throughout.
|
|
6
|
+
*
|
|
7
|
+
* @module @clawswarm/core/clawswarm
|
|
8
|
+
*/
|
|
9
|
+
import EventEmitter from 'eventemitter3';
|
|
10
|
+
import { Agent } from './agent.js';
|
|
11
|
+
import { TaskManager } from './task.js';
|
|
12
|
+
import { ChiefReviewer } from './chief.js';
|
|
13
|
+
import { SwarmConfig, SwarmEvents, GoalResult, CreateGoalInput, Goal, AgentType } from './types.js';
|
|
14
|
+
declare const ClawSwarm_base: new () => EventEmitter<SwarmEvents>;
|
|
15
|
+
/**
|
|
16
|
+
* The primary interface for the ClawSwarm framework.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const swarm = new ClawSwarm({
|
|
21
|
+
* agents: [
|
|
22
|
+
* Agent.research({ model: 'claude-sonnet-4' }),
|
|
23
|
+
* Agent.code({ model: 'gpt-4o' }),
|
|
24
|
+
* Agent.ops({ model: 'gemini-pro' }),
|
|
25
|
+
* ],
|
|
26
|
+
* chiefReview: { autoApproveThreshold: 8, humanReviewThreshold: 5 },
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* swarm.on('task:completed', (task) => console.log('✅', task.title));
|
|
30
|
+
*
|
|
31
|
+
* const result = await swarm.execute(goal);
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare class ClawSwarm extends ClawSwarm_base {
|
|
35
|
+
private readonly goalManager;
|
|
36
|
+
private readonly taskManager;
|
|
37
|
+
private readonly planner;
|
|
38
|
+
private readonly reviewer;
|
|
39
|
+
private readonly agents;
|
|
40
|
+
private readonly config;
|
|
41
|
+
constructor(config: SwarmConfig);
|
|
42
|
+
/**
|
|
43
|
+
* Create a new goal (without executing it).
|
|
44
|
+
* Use `execute()` to run the goal.
|
|
45
|
+
*/
|
|
46
|
+
createGoal(input: CreateGoalInput): Goal;
|
|
47
|
+
/**
|
|
48
|
+
* Execute a goal end-to-end:
|
|
49
|
+
* 1. Decompose into tasks (Planner)
|
|
50
|
+
* 2. Run each task with the appropriate specialist agent
|
|
51
|
+
* 3. Review each task with ChiefReviewer
|
|
52
|
+
* 4. Handle rework cycles
|
|
53
|
+
* 5. Return final result
|
|
54
|
+
*/
|
|
55
|
+
execute(goal: Goal): Promise<GoalResult>;
|
|
56
|
+
/**
|
|
57
|
+
* Get a registered agent by type.
|
|
58
|
+
*/
|
|
59
|
+
getAgent(type: AgentType): Agent | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* List all registered agents.
|
|
62
|
+
*/
|
|
63
|
+
listAgents(): Agent[];
|
|
64
|
+
/**
|
|
65
|
+
* Get the ChiefReviewer instance (for inspection or custom review logic).
|
|
66
|
+
*/
|
|
67
|
+
getReviewer(): ChiefReviewer;
|
|
68
|
+
/**
|
|
69
|
+
* Get the TaskManager instance (for direct task inspection).
|
|
70
|
+
*/
|
|
71
|
+
getTaskManager(): TaskManager;
|
|
72
|
+
/**
|
|
73
|
+
* Execute a single task with the appropriate agent.
|
|
74
|
+
* @internal
|
|
75
|
+
*/
|
|
76
|
+
private _executeTask;
|
|
77
|
+
/**
|
|
78
|
+
* Handle a chief review result for a task.
|
|
79
|
+
* @internal
|
|
80
|
+
*/
|
|
81
|
+
private _handleReview;
|
|
82
|
+
}
|
|
83
|
+
export {};
|
|
84
|
+
//# sourceMappingURL=clawswarm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clawswarm.d.ts","sourceRoot":"","sources":["../src/clawswarm.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EACL,WAAW,EACX,WAAW,EACX,UAAU,EACV,eAAe,EACf,IAAI,EAGJ,SAAS,EACV,MAAM,YAAY,CAAC;8BAuB4B,UAAU,YAAY,CAAC,WAAW,CAAC;AAnBnF;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,SAAU,SAAQ,cAAq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