ruleloom 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/LICENSE +21 -0
- package/README.md +151 -2
- package/dist/adapters/claude.d.ts +3 -0
- package/dist/adapters/claude.d.ts.map +1 -0
- package/dist/adapters/claude.js +59 -0
- package/dist/adapters/claude.js.map +1 -0
- package/dist/adapters/codex.d.ts +3 -0
- package/dist/adapters/codex.d.ts.map +1 -0
- package/dist/adapters/codex.js +84 -0
- package/dist/adapters/codex.js.map +1 -0
- package/dist/adapters/copilot.d.ts +3 -0
- package/dist/adapters/copilot.d.ts.map +1 -0
- package/dist/adapters/copilot.js +53 -0
- package/dist/adapters/copilot.js.map +1 -0
- package/dist/adapters/format.d.ts +27 -0
- package/dist/adapters/format.d.ts.map +1 -0
- package/dist/adapters/format.js +55 -0
- package/dist/adapters/format.js.map +1 -0
- package/dist/adapters/index.d.ts +10 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +11 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/types.d.ts +19 -0
- package/dist/adapters/types.d.ts.map +1 -0
- package/dist/adapters/types.js +2 -0
- package/dist/adapters/types.js.map +1 -0
- package/dist/assemble.d.ts +61 -0
- package/dist/assemble.d.ts.map +1 -0
- package/dist/assemble.js +133 -0
- package/dist/assemble.js.map +1 -0
- package/dist/blocks.d.ts +32 -0
- package/dist/blocks.d.ts.map +1 -0
- package/dist/blocks.js +59 -0
- package/dist/blocks.js.map +1 -0
- package/dist/bundle.d.ts +121 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +157 -0
- package/dist/bundle.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +141 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +360 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +207 -0
- package/dist/config.js.map +1 -0
- package/dist/errors.d.ts +12 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +16 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/project.d.ts +149 -0
- package/dist/project.d.ts.map +1 -0
- package/dist/project.js +102 -0
- package/dist/project.js.map +1 -0
- package/dist/prompt.d.ts +62 -0
- package/dist/prompt.d.ts.map +1 -0
- package/dist/prompt.js +91 -0
- package/dist/prompt.js.map +1 -0
- package/dist/resources.d.ts +39 -0
- package/dist/resources.d.ts.map +1 -0
- package/dist/resources.js +118 -0
- package/dist/resources.js.map +1 -0
- package/dist/select.d.ts +14 -0
- package/dist/select.d.ts.map +1 -0
- package/dist/select.js +25 -0
- package/dist/select.js.map +1 -0
- package/dist/slots.d.ts +35 -0
- package/dist/slots.d.ts.map +1 -0
- package/dist/slots.js +86 -0
- package/dist/slots.js.map +1 -0
- package/docs/agent-definition.md +86 -0
- package/docs/api.md +65 -0
- package/docs/architecture.md +47 -0
- package/docs/cli.md +28 -0
- package/docs/errors.md +76 -0
- package/docs/targets.md +49 -0
- package/package.json +51 -4
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type McpServer } from './config.js';
|
|
2
|
+
import type { Project, Target } from './project.js';
|
|
3
|
+
import { type ResolvedResource } from './resources.js';
|
|
4
|
+
/**
|
|
5
|
+
* An agent resolved and assembled, before any platform format: what every
|
|
6
|
+
* adapter receives. Rules and skills are bound (slots filled), named and in
|
|
7
|
+
* `agent.json` order; nothing here knows where a file will be written.
|
|
8
|
+
*/
|
|
9
|
+
export interface AssembledFile {
|
|
10
|
+
/** Kebab-case name, unique among rules or among skills. */
|
|
11
|
+
slug: string;
|
|
12
|
+
/** The module path it came from. */
|
|
13
|
+
source: string;
|
|
14
|
+
body: string;
|
|
15
|
+
}
|
|
16
|
+
export interface AssembledSkill extends AssembledFile {
|
|
17
|
+
/** The skill's description: its first heading, without the `[nn]` prefix. */
|
|
18
|
+
description: string;
|
|
19
|
+
}
|
|
20
|
+
export interface AssembledAgent {
|
|
21
|
+
/** Directory name under the agents root. */
|
|
22
|
+
dir: string;
|
|
23
|
+
/** Generated name: the project prefix, then the directory name. */
|
|
24
|
+
name: string;
|
|
25
|
+
summary: string;
|
|
26
|
+
version: string;
|
|
27
|
+
preamble: string;
|
|
28
|
+
mission: string;
|
|
29
|
+
/** The project's constraints paragraph, or empty. */
|
|
30
|
+
constraints: string;
|
|
31
|
+
rules: AssembledFile[];
|
|
32
|
+
skills: AssembledSkill[];
|
|
33
|
+
/** Skills to preload, already checked against `skills`. */
|
|
34
|
+
preload: string[];
|
|
35
|
+
mcp: Record<string, McpServer>;
|
|
36
|
+
/** This target's overrides from `agent.json`. */
|
|
37
|
+
overrides: Record<string, string | string[]>;
|
|
38
|
+
slots: Record<string, string>;
|
|
39
|
+
used: Set<string>;
|
|
40
|
+
resources: ResolvedResource[];
|
|
41
|
+
/** Every source read, with the text it contributed after binding. */
|
|
42
|
+
sources: {
|
|
43
|
+
path: string;
|
|
44
|
+
body: string;
|
|
45
|
+
}[];
|
|
46
|
+
}
|
|
47
|
+
/** `source/rules/30_SINGLE_POLICY.md` → `30-single-policy`. */
|
|
48
|
+
export declare function moduleSlug(path: string): string;
|
|
49
|
+
/** First markdown heading, without its `[nn]` prefix; the slug otherwise. */
|
|
50
|
+
export declare function moduleTitle(body: string, path: string): string;
|
|
51
|
+
export interface AssembleOptions {
|
|
52
|
+
project: Project;
|
|
53
|
+
agent: string;
|
|
54
|
+
target: Target;
|
|
55
|
+
data?: Record<string, string>;
|
|
56
|
+
random?: Record<string, string>;
|
|
57
|
+
/** One of the agent's `modes`. */
|
|
58
|
+
mode?: string;
|
|
59
|
+
}
|
|
60
|
+
export declare function assembleAgent(options: AssembleOptions): AssembledAgent;
|
|
61
|
+
//# sourceMappingURL=assemble.d.ts.map
|
|
@@ -0,0 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9B,qEAAqE;IACrE,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAC3C;AAED,+DAA+D;AAC/D,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG/C;AAED,6EAA6E;AAC7E,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAI9D;AAYD,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,kCAAkC;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,eAAe,GAAG,cAAc,CAwGtE"}
|
package/dist/assemble.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { loadBlockTemplates } from './blocks.js';
|
|
4
|
+
import { moduleKind, readAgentConfig } from './config.js';
|
|
5
|
+
import { RuleLoomError } from './errors.js';
|
|
6
|
+
import { ModuleReader } from './resources.js';
|
|
7
|
+
import { selectModules } from './select.js';
|
|
8
|
+
import { bindSlots, resolveAgentSlots } from './slots.js';
|
|
9
|
+
/** `source/rules/30_SINGLE_POLICY.md` → `30-single-policy`. */
|
|
10
|
+
export function moduleSlug(path) {
|
|
11
|
+
const base = path.split('/').pop() ?? path;
|
|
12
|
+
return base.replace(/\.md$/i, '').replace(/_/g, '-').toLowerCase();
|
|
13
|
+
}
|
|
14
|
+
/** First markdown heading, without its `[nn]` prefix; the slug otherwise. */
|
|
15
|
+
export function moduleTitle(body, path) {
|
|
16
|
+
const heading = /^#\s+(.+)$/m.exec(body)?.[1]?.trim();
|
|
17
|
+
if (!heading)
|
|
18
|
+
return moduleSlug(path).replace(/-/g, ' ');
|
|
19
|
+
return heading.replace(/^\[\d+\]\s*/, '').trim() || moduleSlug(path);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The skill name every target accepts: Copilot requires lowercase letters,
|
|
23
|
+
* digits and hyphens, at most 64 characters, equal to the directory name —
|
|
24
|
+
* and a skill that breaks the rule is skipped silently, which is why it is
|
|
25
|
+
* refused here instead.
|
|
26
|
+
*/
|
|
27
|
+
const SKILL_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
28
|
+
const SKILL_NAME_MAX = 64;
|
|
29
|
+
const SKILL_DESCRIPTION_MAX = 1024;
|
|
30
|
+
export function assembleAgent(options) {
|
|
31
|
+
const { project, agent } = options;
|
|
32
|
+
const agentDir = join(project.agentsRoot, agent);
|
|
33
|
+
if (!existsSync(join(agentDir, 'agent.json'))) {
|
|
34
|
+
throw new RuleLoomError('AGENT_NOT_FOUND', join(agentDir, 'agent.json'));
|
|
35
|
+
}
|
|
36
|
+
const config = readAgentConfig(agentDir);
|
|
37
|
+
const reader = new ModuleReader(project);
|
|
38
|
+
const slots = resolveAgentSlots(config, {
|
|
39
|
+
...(options.random ? { random: options.random } : {}),
|
|
40
|
+
...(options.data ? { data: options.data } : {}),
|
|
41
|
+
});
|
|
42
|
+
const used = new Set();
|
|
43
|
+
const sources = [];
|
|
44
|
+
// A rule may name a run block (`{{BRIEF}}`): it stays as written, since the
|
|
45
|
+
// run sends its blocks beside the bundle. Any other `{{NAME}}` is refused.
|
|
46
|
+
const blocks = loadBlockTemplates(project.blocksRoot, { floor: project.blockNumberFloor }).map((b) => b.name);
|
|
47
|
+
const fill = (text, where) => bindSlots(text, slots, { where, used, blocks });
|
|
48
|
+
// The agent's whole environment for one mode, not one attempt's narrowed prompt.
|
|
49
|
+
const selected = selectModules(config, options.mode ? { mode: options.mode } : {});
|
|
50
|
+
const missions = selected.filter((m) => moduleKind(m) === 'mission');
|
|
51
|
+
if (missions.length > 1) {
|
|
52
|
+
throw new RuleLoomError('AGENT_MULTIPLE_MISSIONS', `${agent} marks ${missions.length} modules as mission`);
|
|
53
|
+
}
|
|
54
|
+
const rules = [];
|
|
55
|
+
const seenRules = new Set();
|
|
56
|
+
const addRule = (source, raw) => {
|
|
57
|
+
const slug = moduleSlug(source);
|
|
58
|
+
if (seenRules.has(slug))
|
|
59
|
+
throw new RuleLoomError('RULE_SLUG_COLLISION', `${slug} (${source})`);
|
|
60
|
+
seenRules.add(slug);
|
|
61
|
+
const body = fill(raw, source);
|
|
62
|
+
rules.push({ slug, source, body });
|
|
63
|
+
sources.push({ path: source, body });
|
|
64
|
+
};
|
|
65
|
+
for (const name of config.sharedRules)
|
|
66
|
+
addRule(`shared/rules/${name}`, reader.readSharedRule(name));
|
|
67
|
+
for (const module of selected) {
|
|
68
|
+
if (moduleKind(module) === 'rule')
|
|
69
|
+
addRule(module.path, reader.read(agentDir, module.path));
|
|
70
|
+
}
|
|
71
|
+
const skills = [];
|
|
72
|
+
const seenSkills = new Set();
|
|
73
|
+
for (const module of selected) {
|
|
74
|
+
if (moduleKind(module) !== 'skill')
|
|
75
|
+
continue;
|
|
76
|
+
const slug = moduleSlug(module.path);
|
|
77
|
+
if (!SKILL_NAME.test(slug) || slug.length > SKILL_NAME_MAX) {
|
|
78
|
+
throw new RuleLoomError('SKILL_NAME_INVALID', `${module.path} → "${slug}": lowercase letters, digits and hyphens, at most ${SKILL_NAME_MAX} characters`);
|
|
79
|
+
}
|
|
80
|
+
if (seenSkills.has(slug))
|
|
81
|
+
throw new RuleLoomError('SKILL_SLUG_COLLISION', `${slug} (${module.path})`);
|
|
82
|
+
seenSkills.add(slug);
|
|
83
|
+
const body = fill(reader.read(agentDir, module.path), module.path);
|
|
84
|
+
const description = moduleTitle(body, module.path);
|
|
85
|
+
if (description.length > SKILL_DESCRIPTION_MAX) {
|
|
86
|
+
throw new RuleLoomError('SKILL_DESCRIPTION_TOO_LONG', `${module.path}: ${description.length} > ${SKILL_DESCRIPTION_MAX}`);
|
|
87
|
+
}
|
|
88
|
+
skills.push({ slug, source: module.path, body, description });
|
|
89
|
+
sources.push({ path: module.path, body });
|
|
90
|
+
}
|
|
91
|
+
/*
|
|
92
|
+
* A preload naming a skill the mode leaves out is not a typo — the agent
|
|
93
|
+
* preloads it in the mode it belongs to — so it is dropped. One naming a
|
|
94
|
+
* skill the agent does not have at all is refused: the preload would be a
|
|
95
|
+
* silent no-op.
|
|
96
|
+
*/
|
|
97
|
+
const allSkills = new Set(config.modules.filter((m) => moduleKind(m) === 'skill').map((m) => moduleSlug(m.path)));
|
|
98
|
+
const unknownPreload = config.runtime.skills.filter((name) => !allSkills.has(name));
|
|
99
|
+
if (unknownPreload.length > 0) {
|
|
100
|
+
throw new RuleLoomError('AGENT_PRELOAD_SKILL_UNKNOWN', `${agent} preloads ${unknownPreload.join(', ')} — it has ${[...allSkills].sort().join(', ') || '(no skill)'}`);
|
|
101
|
+
}
|
|
102
|
+
const preload = config.runtime.skills.filter((name) => seenSkills.has(name));
|
|
103
|
+
const mission = missions[0];
|
|
104
|
+
const missionBody = mission ? fill(reader.read(agentDir, mission.path), mission.path) : '';
|
|
105
|
+
if (mission)
|
|
106
|
+
sources.push({ path: mission.path, body: missionBody });
|
|
107
|
+
const preamble = config.preamble.length > 0 ? fill(config.preamble.join('\n').trim(), 'the preamble') : '';
|
|
108
|
+
const constraints = project.constraintsFile ? readConstraints(project.constraintsFile) : '';
|
|
109
|
+
return {
|
|
110
|
+
dir: agent,
|
|
111
|
+
name: `${project.namePrefix}${agent}`,
|
|
112
|
+
summary: config.summary,
|
|
113
|
+
version: config.version,
|
|
114
|
+
preamble,
|
|
115
|
+
mission: missionBody,
|
|
116
|
+
constraints,
|
|
117
|
+
rules,
|
|
118
|
+
skills,
|
|
119
|
+
preload,
|
|
120
|
+
mcp: config.mcp,
|
|
121
|
+
overrides: config.targets[options.target] ?? {},
|
|
122
|
+
slots,
|
|
123
|
+
used,
|
|
124
|
+
resources: reader.used(),
|
|
125
|
+
sources,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function readConstraints(file) {
|
|
129
|
+
if (!existsSync(file))
|
|
130
|
+
throw new RuleLoomError('CONSTRAINTS_MISSING', file);
|
|
131
|
+
return readFileSync(file, 'utf8').trimEnd();
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=assemble.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assemble.js","sourceRoot":"","sources":["../src/assemble.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAoC,MAAM,aAAa,CAAC;AAC5F,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,YAAY,EAAyB,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AA8C1D,+DAA+D;AAC/D,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC;IAC3C,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;AACrE,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,IAAY;IACpD,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AG,OAAO,CAAC,UAAU,GAAG,KAAK,EAAE;QACrC,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,QAAQ;QACR,OAAO,EAAE,WAAW;QACpB,WAAW;QACX,KAAK;QACL,MAAM;QACN,OAAO;QACP,GAAG,EAAE,MAAM,CAAC,GAAG;QACf,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE;QAC/C,KAAK;QACL,IAAI;QACJ,SAAS,EAAE,MAAM,CAAC,IAAI,EAAE;QACxB,OAAO;KACR,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,IAAY;IACnC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,aAAa,CAAC,qBAAqB,EAAE,IAAI,CAAC,CAAC;IAC5E,OAAO,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC;AAC9C,CAAC"}
|
package/dist/blocks.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run blocks: what a run appends after an agent's static text — the data it
|
|
3
|
+
* works on, the contract it must meet, the feedback from the last attempt.
|
|
4
|
+
*
|
|
5
|
+
* One template per block, `<number>_<NAME>.md` in the blocks directory, whose
|
|
6
|
+
* first line is `# [<number>] …` and which cites `{{NAME}}` exactly once. The
|
|
7
|
+
* number is the order: what changes least comes first, so everything above
|
|
8
|
+
* the last changed block stays a cacheable prefix.
|
|
9
|
+
*
|
|
10
|
+
* Numbers start at a floor (100 by default) so a run block can never collide
|
|
11
|
+
* with the `[nn]` of a hand-written rule.
|
|
12
|
+
*/
|
|
13
|
+
export interface BlockTemplate {
|
|
14
|
+
name: string;
|
|
15
|
+
number: number;
|
|
16
|
+
/** The file's contents, slot included, trailing whitespace removed. */
|
|
17
|
+
template: string;
|
|
18
|
+
}
|
|
19
|
+
export interface LoadBlocksOptions {
|
|
20
|
+
/** Lowest number a block may carry. */
|
|
21
|
+
floor?: number;
|
|
22
|
+
/** Block names the caller requires; any missing or extra one is refused. */
|
|
23
|
+
expected?: readonly string[];
|
|
24
|
+
}
|
|
25
|
+
/** The block templates of a directory, in prompt order. Empty when the directory does not exist and nothing is expected. */
|
|
26
|
+
export declare function loadBlockTemplates(dir: string, options?: LoadBlocksOptions): BlockTemplate[];
|
|
27
|
+
/**
|
|
28
|
+
* One block with its value in place. A function replacer: the value is often
|
|
29
|
+
* text a person typed, and `$&` in it must stay text.
|
|
30
|
+
*/
|
|
31
|
+
export declare function renderBlock(block: BlockTemplate, value: string): string;
|
|
32
|
+
//# sourceMappingURL=blocks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../src/blocks.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;GAWG;AAEH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAChC,uCAAuC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC9B;AAID,4HAA4H;AAC5H,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB,GAAG,aAAa,EAAE,CAiDhG;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAEvE"}
|
package/dist/blocks.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { RuleLoomError } from './errors.js';
|
|
4
|
+
const slot = (name) => `{{${name}}}`;
|
|
5
|
+
/** The block templates of a directory, in prompt order. Empty when the directory does not exist and nothing is expected. */
|
|
6
|
+
export function loadBlockTemplates(dir, options = {}) {
|
|
7
|
+
const floor = options.floor ?? 100;
|
|
8
|
+
if (!existsSync(dir)) {
|
|
9
|
+
if (options.expected && options.expected.length > 0) {
|
|
10
|
+
throw new RuleLoomError('PROMPT_BLOCKS_MISSING', `${dir} does not exist`);
|
|
11
|
+
}
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
const known = options.expected ? new Set(options.expected) : undefined;
|
|
15
|
+
const seen = new Map();
|
|
16
|
+
const blocks = [];
|
|
17
|
+
for (const file of readdirSync(dir).filter((f) => f.endsWith('.md') && f !== 'README.md').sort()) {
|
|
18
|
+
const parsed = /^(\d+)_([A-Z][A-Z0-9_]*)\.md$/.exec(file);
|
|
19
|
+
if (!parsed)
|
|
20
|
+
throw new RuleLoomError('PROMPT_BLOCK_NAME', `${file} — expected <number>_<NAME>.md`);
|
|
21
|
+
const number = Number(parsed[1]);
|
|
22
|
+
const name = parsed[2];
|
|
23
|
+
if (known && !known.has(name)) {
|
|
24
|
+
throw new RuleLoomError('PROMPT_BLOCK_UNKNOWN', `${file} — ${name} is not one of ${[...known].join(', ')}`);
|
|
25
|
+
}
|
|
26
|
+
if (seen.has(name))
|
|
27
|
+
throw new RuleLoomError('PROMPT_BLOCK_DUPLICATE', `${name} in ${seen.get(name)} and ${file}`);
|
|
28
|
+
if (number < floor) {
|
|
29
|
+
throw new RuleLoomError('PROMPT_BLOCK_NUMBER_RANGE', `${file} — run blocks start at [${floor}]; below it they collide with hand-written rules`);
|
|
30
|
+
}
|
|
31
|
+
const template = readFileSync(join(dir, file), 'utf8').trimEnd();
|
|
32
|
+
const heading = /^# \[(\d+)\] /.exec(template.split('\n', 1)[0] ?? '');
|
|
33
|
+
if (!heading || Number(heading[1]) !== number) {
|
|
34
|
+
throw new RuleLoomError('PROMPT_BLOCK_NUMBER_MISMATCH', `${file} — the heading must start with # [${number}]`);
|
|
35
|
+
}
|
|
36
|
+
const own = template.split(slot(name)).length - 1;
|
|
37
|
+
if (own !== 1)
|
|
38
|
+
throw new RuleLoomError('PROMPT_BLOCK_SLOT', `${file} — ${slot(name)} expected once, found ${own}`);
|
|
39
|
+
const foreign = [...template.matchAll(/\{\{([A-Z][A-Z0-9_]*)\}\}/g)].map((m) => m[1]).filter((n) => n !== name);
|
|
40
|
+
if (foreign.length > 0)
|
|
41
|
+
throw new RuleLoomError('PROMPT_BLOCK_FOREIGN_SLOT', `${file} — also cites ${foreign.join(', ')}`);
|
|
42
|
+
seen.set(name, file);
|
|
43
|
+
blocks.push({ name, number, template });
|
|
44
|
+
}
|
|
45
|
+
if (options.expected) {
|
|
46
|
+
const missing = options.expected.filter((name) => !seen.has(name));
|
|
47
|
+
if (missing.length > 0)
|
|
48
|
+
throw new RuleLoomError('PROMPT_BLOCK_MISSING', `no template for ${missing.join(', ')}`);
|
|
49
|
+
}
|
|
50
|
+
return blocks.sort((a, b) => a.number - b.number);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* One block with its value in place. A function replacer: the value is often
|
|
54
|
+
* text a person typed, and `$&` in it must stay text.
|
|
55
|
+
*/
|
|
56
|
+
export function renderBlock(block, value) {
|
|
57
|
+
return block.template.replace(slot(block.name), () => value.trim());
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=blocks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blocks.js","sourceRoot":"","sources":["../src/blocks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AA6B5C,MAAM,IAAI,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,KAAK,IAAI,IAAI,CAAC;AAEr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ED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { Project, Target } from './project.js';
|
|
2
|
+
/**
|
|
3
|
+
* An agent compiled into a platform's own configuration: a directory the
|
|
4
|
+
* platform loads by itself, rather than one prompt string.
|
|
5
|
+
*
|
|
6
|
+
* Every bundle carries `build-manifest.json`: the sources it was built from,
|
|
7
|
+
* the files it contains, one checksum over them, the slot values it cited,
|
|
8
|
+
* and the commit of every Git resource it read. No timestamp anywhere — a
|
|
9
|
+
* manifest that changes when nothing else did cannot answer "is this the
|
|
10
|
+
* same bundle".
|
|
11
|
+
*/
|
|
12
|
+
/** `isolated`: the bundle is meant to be the whole configuration of a dedicated workspace. */
|
|
13
|
+
export type BundleScope = 'shared' | 'isolated';
|
|
14
|
+
export interface BuildManifestFile {
|
|
15
|
+
path: string;
|
|
16
|
+
sha256: string;
|
|
17
|
+
bytes: number;
|
|
18
|
+
}
|
|
19
|
+
export interface BuildManifest {
|
|
20
|
+
agent: string;
|
|
21
|
+
version: string;
|
|
22
|
+
target: Target;
|
|
23
|
+
scope: BundleScope;
|
|
24
|
+
sources: BuildManifestFile[];
|
|
25
|
+
/** Git resources read, with the commit actually compiled. */
|
|
26
|
+
resources?: {
|
|
27
|
+
alias: string;
|
|
28
|
+
url: string;
|
|
29
|
+
ref: string;
|
|
30
|
+
commit: string;
|
|
31
|
+
}[];
|
|
32
|
+
files: BuildManifestFile[];
|
|
33
|
+
checksum: string;
|
|
34
|
+
/** Slots the text cited. Absent when none: such a bundle is the same whatever any slot took. */
|
|
35
|
+
cited?: Record<string, string>;
|
|
36
|
+
slots?: Record<string, string>;
|
|
37
|
+
/** What a human must know or do about this output. */
|
|
38
|
+
notes?: string[];
|
|
39
|
+
}
|
|
40
|
+
export interface AgentBundle {
|
|
41
|
+
agent: string;
|
|
42
|
+
/** The name the platform knows the agent by. */
|
|
43
|
+
agentName: string;
|
|
44
|
+
target: Target;
|
|
45
|
+
/** Published path inside the bundle → content, `build-manifest.json` included. */
|
|
46
|
+
files: Map<string, string>;
|
|
47
|
+
manifest: BuildManifest;
|
|
48
|
+
}
|
|
49
|
+
export declare const BUILD_MANIFEST = "build-manifest.json";
|
|
50
|
+
export interface CompileBundleOptions {
|
|
51
|
+
project: Project;
|
|
52
|
+
agent: string;
|
|
53
|
+
target?: Target;
|
|
54
|
+
scope?: BundleScope;
|
|
55
|
+
data?: Record<string, string>;
|
|
56
|
+
random?: Record<string, string>;
|
|
57
|
+
/** One of the agent's `modes`. */
|
|
58
|
+
mode?: string;
|
|
59
|
+
}
|
|
60
|
+
export declare function compileBundle(options: CompileBundleOptions): AgentBundle;
|
|
61
|
+
/** Agent directories: those holding an `agent.json`, minus the shared directory and the exclusions. */
|
|
62
|
+
export declare function discoverAgents(project: Project): string[];
|
|
63
|
+
/** Every agent, for one target. */
|
|
64
|
+
export declare function compileAllBundles(project: Project, options?: Omit<CompileBundleOptions, 'project' | 'agent'>): AgentBundle[];
|
|
65
|
+
export interface WriteBundlesOptions extends Omit<CompileBundleOptions, 'project' | 'agent'> {
|
|
66
|
+
project: Project;
|
|
67
|
+
/** Where `<agent>/` directories are written. */
|
|
68
|
+
outRoot: string;
|
|
69
|
+
/** Only this agent. */
|
|
70
|
+
agent?: string;
|
|
71
|
+
/** Report drift instead of writing. */
|
|
72
|
+
check?: boolean;
|
|
73
|
+
}
|
|
74
|
+
export interface WriteReport {
|
|
75
|
+
written: string[];
|
|
76
|
+
drifted: string[];
|
|
77
|
+
/** Files on disk no bundle produces any more: removed, or reported under `check`. */
|
|
78
|
+
orphaned: string[];
|
|
79
|
+
bundles: {
|
|
80
|
+
agent: string;
|
|
81
|
+
target: Target;
|
|
82
|
+
checksum: string;
|
|
83
|
+
}[];
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Writes bundles under `outRoot/<agent>/` and makes each directory match its
|
|
87
|
+
* bundle exactly. Stale files are removed: a platform loads what is in the
|
|
88
|
+
* directory, not what the manifest lists, so a retired rule left on disk is
|
|
89
|
+
* still followed.
|
|
90
|
+
*/
|
|
91
|
+
export declare function writeBundles(options: WriteBundlesOptions): WriteReport;
|
|
92
|
+
/**
|
|
93
|
+
* Platform configuration found in the parents of a directory — what an agent
|
|
94
|
+
* launched there would inherit on top of its own bundle.
|
|
95
|
+
*/
|
|
96
|
+
export declare function inheritedConfig(dir: string, target: Target): string[];
|
|
97
|
+
export interface MaterialiseOptions extends Omit<CompileBundleOptions, 'scope'> {
|
|
98
|
+
/** Directory the agent's own root is created under. */
|
|
99
|
+
runtimeRoot: string;
|
|
100
|
+
/** Accept a root with platform configuration above it. Tests only. */
|
|
101
|
+
allowInherited?: boolean;
|
|
102
|
+
}
|
|
103
|
+
export interface MaterialisedAgent {
|
|
104
|
+
/** The directory to launch the agent in. */
|
|
105
|
+
cwd: string;
|
|
106
|
+
/** Where the agent reads inputs and writes deliverables. */
|
|
107
|
+
workspace: string;
|
|
108
|
+
agentName: string;
|
|
109
|
+
target: Target;
|
|
110
|
+
checksum: string;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Lays a bundle out as a dedicated workspace, and refuses a dirty root.
|
|
114
|
+
*
|
|
115
|
+
* Several configuration directories side by side isolate nothing on their
|
|
116
|
+
* own: Claude Code and Codex both walk up the tree and load what they find.
|
|
117
|
+
* A root under a repository or `$HOME` would hand the agent instructions
|
|
118
|
+
* nobody meant it to read, so the offending paths are named instead.
|
|
119
|
+
*/
|
|
120
|
+
export declare function materialiseAgent(options: MaterialiseOptions): MaterialisedAgent;
|
|
121
|
+
//# sourceMappingURL=bundle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGpD;;;;;;;;;GASG;AAEH,8FAA8F;AAC9F,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,UAAU,CAAC;AAEhD,M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AAoB,EAAE,OAAO,CAAC;IAC7E,uDAAuD;IACvD,WAAW,EAAE,MAAM,CAAC;IACpB,sEAAsE;IACtE,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,iBAAiB;IAChC,4CAA4C;IAC5C,GAAG,EAAE,MAAM,CAAC;IACZ,4DAA4D;IAC5D,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,kBAAkB,GAAG,iBAAiB,CAuB/E"}
|
package/dist/bundle.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { dirname, join, resolve } from 'node:path';
|
|
4
|
+
import { ADAPTERS } from './adapters/index.js';
|
|
5
|
+
import { assembleAgent } from './assemble.js';
|
|
6
|
+
import { RuleLoomError } from './errors.js';
|
|
7
|
+
import { usedSlots } from './slots.js';
|
|
8
|
+
export const BUILD_MANIFEST = 'build-manifest.json';
|
|
9
|
+
const sha256 = (value) => createHash('sha256').update(value, 'utf8').digest('hex');
|
|
10
|
+
const record = (path, content) => ({ path, sha256: sha256(content), bytes: Buffer.byteLength(content, 'utf8') });
|
|
11
|
+
export function compileBundle(options) {
|
|
12
|
+
const target = options.target ?? options.project.targets[0];
|
|
13
|
+
const assembled = assembleAgent({
|
|
14
|
+
project: options.project,
|
|
15
|
+
agent: options.agent,
|
|
16
|
+
target,
|
|
17
|
+
...(options.data ? { data: options.data } : {}),
|
|
18
|
+
...(options.random ? { random: options.random } : {}),
|
|
19
|
+
...(options.mode ? { mode: options.mode } : {}),
|
|
20
|
+
});
|
|
21
|
+
const { files, notes } = ADAPTERS[target].emit(assembled);
|
|
22
|
+
if (files.has(BUILD_MANIFEST))
|
|
23
|
+
throw new RuleLoomError('ADAPTER_RESERVED_PATH', BUILD_MANIFEST);
|
|
24
|
+
const emitted = [...files].map(([path, content]) => record(path, content)).sort((a, b) => a.path.localeCompare(b.path));
|
|
25
|
+
const git = assembled.resources.filter((r) => r.git).map((r) => ({ alias: r.alias, ...r.git }));
|
|
26
|
+
const manifest = {
|
|
27
|
+
agent: options.agent,
|
|
28
|
+
version: assembled.version,
|
|
29
|
+
target,
|
|
30
|
+
scope: options.scope ?? 'isolated',
|
|
31
|
+
sources: assembled.sources.map((s) => record(s.path, s.body)).sort((a, b) => a.path.localeCompare(b.path)),
|
|
32
|
+
...(git.length > 0 ? { resources: git } : {}),
|
|
33
|
+
files: emitted,
|
|
34
|
+
checksum: sha256(JSON.stringify(emitted.map((f) => [f.path, f.sha256]))),
|
|
35
|
+
...(assembled.used.size > 0 ? { cited: usedSlots(assembled.slots, assembled.used) } : {}),
|
|
36
|
+
...(Object.keys(assembled.slots).length > 0 ? { slots: assembled.slots } : {}),
|
|
37
|
+
...(notes.length > 0 ? { notes } : {}),
|
|
38
|
+
};
|
|
39
|
+
files.set(BUILD_MANIFEST, `${JSON.stringify(manifest, null, 2)}\n`);
|
|
40
|
+
return { agent: options.agent, agentName: assembled.name, target, files, manifest };
|
|
41
|
+
}
|
|
42
|
+
/** Agent directories: those holding an `agent.json`, minus the shared directory and the exclusions. */
|
|
43
|
+
export function discoverAgents(project) {
|
|
44
|
+
if (!existsSync(project.agentsRoot))
|
|
45
|
+
throw new RuleLoomError('AGENTS_ROOT_MISSING', project.agentsRoot);
|
|
46
|
+
const excluded = new Set(project.exclude);
|
|
47
|
+
return readdirSync(project.agentsRoot, { withFileTypes: true })
|
|
48
|
+
.filter((entry) => entry.isDirectory() && !excluded.has(entry.name)
|
|
49
|
+
&& resolve(project.agentsRoot, entry.name) !== project.sharedRoot)
|
|
50
|
+
.map((entry) => entry.name)
|
|
51
|
+
.filter((name) => existsSync(join(project.agentsRoot, name, 'agent.json')))
|
|
52
|
+
.sort();
|
|
53
|
+
}
|
|
54
|
+
/** Every agent, for one target. */
|
|
55
|
+
export function compileAllBundles(project, options = {}) {
|
|
56
|
+
return discoverAgents(project).map((agent) => compileBundle({ ...options, project, agent }));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Writes bundles under `outRoot/<agent>/` and makes each directory match its
|
|
60
|
+
* bundle exactly. Stale files are removed: a platform loads what is in the
|
|
61
|
+
* directory, not what the manifest lists, so a retired rule left on disk is
|
|
62
|
+
* still followed.
|
|
63
|
+
*/
|
|
64
|
+
export function writeBundles(options) {
|
|
65
|
+
const { project, outRoot, agent, check, ...compile } = options;
|
|
66
|
+
const all = agent ? [compileBundle({ ...compile, project, agent })] : compileAllBundles(project, compile);
|
|
67
|
+
const expected = new Map();
|
|
68
|
+
for (const bundle of all)
|
|
69
|
+
for (const [path, content] of bundle.files)
|
|
70
|
+
expected.set(join(bundle.agent, path), content);
|
|
71
|
+
const onDisk = new Set();
|
|
72
|
+
const walk = (absolute, relative) => {
|
|
73
|
+
if (!existsSync(absolute))
|
|
74
|
+
return;
|
|
75
|
+
for (const entry of readdirSync(absolute, { withFileTypes: true })) {
|
|
76
|
+
const next = join(relative, entry.name);
|
|
77
|
+
if (entry.isDirectory())
|
|
78
|
+
walk(join(absolute, entry.name), next);
|
|
79
|
+
else
|
|
80
|
+
onDisk.add(next);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
for (const bundle of all)
|
|
84
|
+
walk(join(outRoot, bundle.agent), bundle.agent);
|
|
85
|
+
const written = [];
|
|
86
|
+
const drifted = [];
|
|
87
|
+
const orphaned = [...onDisk].filter((path) => !expected.has(path)).sort();
|
|
88
|
+
if (!check)
|
|
89
|
+
for (const path of orphaned)
|
|
90
|
+
rmSync(join(outRoot, path), { force: true });
|
|
91
|
+
for (const [path, content] of [...expected].sort(([a], [b]) => a.localeCompare(b))) {
|
|
92
|
+
const file = join(outRoot, path);
|
|
93
|
+
if (existsSync(file) && readFileSync(file, 'utf8') === content)
|
|
94
|
+
continue;
|
|
95
|
+
if (check) {
|
|
96
|
+
drifted.push(path);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
100
|
+
writeFileSync(file, content, 'utf8');
|
|
101
|
+
written.push(path);
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
written,
|
|
105
|
+
drifted,
|
|
106
|
+
orphaned,
|
|
107
|
+
bundles: all.map((b) => ({ agent: b.agent, target: b.target, checksum: b.manifest.checksum })),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Platform configuration found in the parents of a directory — what an agent
|
|
112
|
+
* launched there would inherit on top of its own bundle.
|
|
113
|
+
*/
|
|
114
|
+
export function inheritedConfig(dir, target) {
|
|
115
|
+
const names = ADAPTERS[target].inheritedConfig;
|
|
116
|
+
const found = [];
|
|
117
|
+
let current = resolve(dir);
|
|
118
|
+
for (;;) {
|
|
119
|
+
const parent = dirname(current);
|
|
120
|
+
if (parent === current)
|
|
121
|
+
break;
|
|
122
|
+
current = parent;
|
|
123
|
+
for (const name of names)
|
|
124
|
+
if (existsSync(join(current, name)))
|
|
125
|
+
found.push(join(current, name));
|
|
126
|
+
}
|
|
127
|
+
return found;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Lays a bundle out as a dedicated workspace, and refuses a dirty root.
|
|
131
|
+
*
|
|
132
|
+
* Several configuration directories side by side isolate nothing on their
|
|
133
|
+
* own: Claude Code and Codex both walk up the tree and load what they find.
|
|
134
|
+
* A root under a repository or `$HOME` would hand the agent instructions
|
|
135
|
+
* nobody meant it to read, so the offending paths are named instead.
|
|
136
|
+
*/
|
|
137
|
+
export function materialiseAgent(options) {
|
|
138
|
+
const { runtimeRoot, allowInherited, ...compile } = options;
|
|
139
|
+
const bundle = compileBundle({ ...compile, scope: 'isolated' });
|
|
140
|
+
const cwd = join(runtimeRoot, options.agent);
|
|
141
|
+
mkdirSync(cwd, { recursive: true });
|
|
142
|
+
if (!allowInherited) {
|
|
143
|
+
const inherited = inheritedConfig(cwd, bundle.target);
|
|
144
|
+
if (inherited.length > 0) {
|
|
145
|
+
throw new RuleLoomError('RUNTIME_ROOT_NOT_ISOLATED', `${cwd} inherits ${inherited.join(', ')} — choose a root with no ${bundle.target} configuration above it`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
for (const [path, content] of bundle.files) {
|
|
149
|
+
const file = join(cwd, path);
|
|
150
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
151
|
+
writeFileSync(file, content, 'utf8');
|
|
152
|
+
}
|
|
153
|
+
const workspace = join(cwd, 'workspace');
|
|
154
|
+
mkdirSync(workspace, { recursive: true });
|
|
155
|
+
return { cwd, workspace, agentName: bundle.agentName, target: bundle.target, checksum: bundle.manifest.checksum };
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=bundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.js","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAClG,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAiDvC,MAAM,CAAC,MAAM,cAAc,GAAG,qBAAqB,CAAC;AAEpD,MAAM,MAAM,GAAG,CAAC,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