@adhd/agent-engine-compiler 2.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/drizzle/meta/_journal.json +5 -0
- package/package.json +58 -0
- package/src/cache/composed-prompt-cache.d.ts +60 -0
- package/src/cache/composed-prompt-cache.d.ts.map +1 -0
- package/src/cache/composed-prompt-cache.js +120 -0
- package/src/cache/composed-prompt-cache.js.map +1 -0
- package/src/cli/compile.d.ts +3 -0
- package/src/cli/compile.d.ts.map +1 -0
- package/src/cli/compile.js +294 -0
- package/src/cli/compile.js.map +1 -0
- package/src/compile.d.ts +61 -0
- package/src/compile.d.ts.map +1 -0
- package/src/compile.js +279 -0
- package/src/compile.js.map +1 -0
- package/src/db/client.d.ts +7 -0
- package/src/db/client.d.ts.map +1 -0
- package/src/db/client.js +31 -0
- package/src/db/client.js.map +1 -0
- package/src/db/migrate-runner.d.ts +31 -0
- package/src/db/migrate-runner.d.ts.map +1 -0
- package/src/db/migrate-runner.js +35 -0
- package/src/db/migrate-runner.js.map +1 -0
- package/src/db/migrate.d.ts +9 -0
- package/src/db/migrate.d.ts.map +1 -0
- package/src/db/migrate.js +13 -0
- package/src/db/migrate.js.map +1 -0
- package/src/db/schema.d.ts +3 -0
- package/src/db/schema.d.ts.map +1 -0
- package/src/db/schema.js +30 -0
- package/src/db/schema.js.map +1 -0
- package/src/emit/json.d.ts +50 -0
- package/src/emit/json.d.ts.map +1 -0
- package/src/emit/json.js +66 -0
- package/src/emit/json.js.map +1 -0
- package/src/emit/markdown.d.ts +35 -0
- package/src/emit/markdown.d.ts.map +1 -0
- package/src/emit/markdown.js +90 -0
- package/src/emit/markdown.js.map +1 -0
- package/src/index.d.ts +20 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +23 -0
- package/src/index.js.map +1 -0
- package/src/resolve/composition.d.ts +28 -0
- package/src/resolve/composition.d.ts.map +1 -0
- package/src/resolve/composition.js +33 -0
- package/src/resolve/composition.js.map +1 -0
- package/src/resolve/model.d.ts +22 -0
- package/src/resolve/model.d.ts.map +1 -0
- package/src/resolve/model.js +69 -0
- package/src/resolve/model.js.map +1 -0
- package/src/resolve/policy.d.ts +34 -0
- package/src/resolve/policy.d.ts.map +1 -0
- package/src/resolve/policy.js +44 -0
- package/src/resolve/policy.js.map +1 -0
- package/src/resolve/tools.d.ts +33 -0
- package/src/resolve/tools.d.ts.map +1 -0
- package/src/resolve/tools.js +62 -0
- package/src/resolve/tools.js.map +1 -0
- package/src/seed/fixtures.d.ts +52 -0
- package/src/seed/fixtures.d.ts.map +1 -0
- package/src/seed/fixtures.js +148 -0
- package/src/seed/fixtures.js.map +1 -0
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@adhd/agent-engine-compiler",
|
|
3
|
+
"version": "2.1.0",
|
|
4
|
+
"description": "Registry-family store for agent-compiler: drizzle-backed SQLite tables sharing the one registry database.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"src",
|
|
11
|
+
"drizzle"
|
|
12
|
+
],
|
|
13
|
+
"bin": {
|
|
14
|
+
"agent-compiler": "./src/cli/compile.js"
|
|
15
|
+
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./src/index.d.ts",
|
|
19
|
+
"default": "./src/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "nx build agent-compiler",
|
|
24
|
+
"typecheck": "tsc -p tsconfig.lib.json --noEmit",
|
|
25
|
+
"db:generate": "drizzle-kit generate",
|
|
26
|
+
"db:migrate": "drizzle-kit migrate"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"better-sqlite3": "12.10.0",
|
|
30
|
+
"drizzle-orm": "0.45.2",
|
|
31
|
+
"@adhd/agent-store-prompts": "^2.1.0",
|
|
32
|
+
"@adhd/agent-store-tools": "^2.1.0",
|
|
33
|
+
"@adhd/agent-core-provider": "^2.1.0",
|
|
34
|
+
"@adhd/agent-core-policy": "^2.1.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/better-sqlite3": "^7.6.13",
|
|
38
|
+
"@vitest/coverage-v8": "^1.0.4",
|
|
39
|
+
"drizzle-kit": "^0.31.10",
|
|
40
|
+
"tslib": "^2.6.0",
|
|
41
|
+
"typescript": "^5.5.0",
|
|
42
|
+
"vite": "~5.0.13",
|
|
43
|
+
"vite-plugin-dts": "~3.8.3",
|
|
44
|
+
"vitest": "^1.6.0"
|
|
45
|
+
},
|
|
46
|
+
"license": "MIT",
|
|
47
|
+
"repository": {
|
|
48
|
+
"type": "git",
|
|
49
|
+
"url": "git+https://github.com/PseudoSky/adhd.git",
|
|
50
|
+
"directory": "packages/agent/agent-engine-compiler"
|
|
51
|
+
},
|
|
52
|
+
"homepage": "https://github.com/PseudoSky/adhd/tree/main/packages/agent/agent-engine-compiler#readme",
|
|
53
|
+
"bugs": {
|
|
54
|
+
"url": "https://github.com/PseudoSky/adhd/issues"
|
|
55
|
+
},
|
|
56
|
+
"module": "./src/index.js",
|
|
57
|
+
"main": "./src/index.js"
|
|
58
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';
|
|
2
|
+
import type { ComposedPrompt } from '@adhd/agent-store-prompts';
|
|
3
|
+
import type { ComponentVersionMap } from '../resolve/composition.js';
|
|
4
|
+
/**
|
|
5
|
+
* Compute the combined `context_hash` for the `registry_composed_prompts` cache.
|
|
6
|
+
*
|
|
7
|
+
* Decision D (decisions.md): `context_hash = SHA-256(sortedJSON(context) + " " +
|
|
8
|
+
* sortedJSON(componentVersions) + " " + platform)`.
|
|
9
|
+
*
|
|
10
|
+
* The `registryContextHash` (from @adhd/agent-registry) handles sorted-key JSON
|
|
11
|
+
* canonicalization of the context part. We apply the same sorted-key approach to
|
|
12
|
+
* `componentVersions` and append the `platform` string as a third field so that any
|
|
13
|
+
* of the three inputs changing produces a distinct hash.
|
|
14
|
+
*
|
|
15
|
+
* A ` ` (space) field separator is used between parts — plain JSON can never contain
|
|
16
|
+
* an unescaped space at the top level, so the three blobs cannot collide by
|
|
17
|
+
* concatenation.
|
|
18
|
+
*
|
|
19
|
+
* @param context - Runtime context key/value map (e.g. `{ticket_type:"security"}`).
|
|
20
|
+
* @param componentVersions - Resolved component-version map from `resolveComposition`.
|
|
21
|
+
* @param platform - Target platform id (e.g. `claude_code`, `claude_api`).
|
|
22
|
+
* @returns 64-character lowercase hex SHA-256 string.
|
|
23
|
+
*/
|
|
24
|
+
export declare function computeContextHash(context: Record<string, string>, componentVersions: ComponentVersionMap, platform: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Look up a `registry_composed_prompts` row by `(agentSlug, platform, context_hash)`.
|
|
27
|
+
*
|
|
28
|
+
* The `context_hash` encodes `(context, componentVersions, platform)` per Decision D.
|
|
29
|
+
* Returns the cached row (with its `id`) on a HIT, or `null` on a MISS.
|
|
30
|
+
*
|
|
31
|
+
* A cache hit means `compileAgent` can return the persisted `{id, content}` WITHOUT
|
|
32
|
+
* re-running the resolve layers (the assembly step is bypassed). This is the
|
|
33
|
+
* `[dod.4]` negative-control guarantee: removing this SELECT before assembly causes
|
|
34
|
+
* a duplicate row on every compile.
|
|
35
|
+
*
|
|
36
|
+
* @param db - Shared Drizzle handle (all four table prefixes).
|
|
37
|
+
* @param agentSlug - Agent to look up.
|
|
38
|
+
* @param platform - Target platform id.
|
|
39
|
+
* @param context - Runtime context key/value map.
|
|
40
|
+
* @param componentVersions - Resolved component-version map from `resolveComposition`.
|
|
41
|
+
* @returns The cached `ComposedPrompt` row on a HIT, or `null` on a MISS.
|
|
42
|
+
*/
|
|
43
|
+
export declare function lookup(db: BetterSQLite3Database<any>, agentSlug: string, platform: string, context: Record<string, string>, componentVersions: ComponentVersionMap): ComposedPrompt | null;
|
|
44
|
+
/**
|
|
45
|
+
* Write a new `registry_composed_prompts` row for `(agentSlug, platform, context_hash)`.
|
|
46
|
+
*
|
|
47
|
+
* Called on a cache MISS: after assembly is complete, persists the composed prompt
|
|
48
|
+
* so subsequent compiles can hit the cache. Returns the inserted row, including the
|
|
49
|
+
* generated `id` (the [def:composed-output].id audit/cache handle).
|
|
50
|
+
*
|
|
51
|
+
* @param db - Shared Drizzle handle (all four table prefixes).
|
|
52
|
+
* @param agentSlug - Agent the row belongs to.
|
|
53
|
+
* @param platform - Target platform id (folded into the hash).
|
|
54
|
+
* @param context - Runtime context key/value map used for assembly.
|
|
55
|
+
* @param componentVersions - Resolved component-version map (audit trail).
|
|
56
|
+
* @param content - The assembled platform artifact (markdown, JSON, etc.).
|
|
57
|
+
* @returns The inserted `ComposedPrompt` row with its generated `id`.
|
|
58
|
+
*/
|
|
59
|
+
export declare function write(db: BetterSQLite3Database<any>, agentSlug: string, platform: string, context: Record<string, string>, componentVersions: ComponentVersionMap, content: string): ComposedPrompt;
|
|
60
|
+
//# sourceMappingURL=composed-prompt-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composed-prompt-cache.d.ts","sourceRoot":"","sources":["../../../../../../packages/agent/agent-engine-compiler/src/cache/composed-prompt-cache.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAMxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAMrE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,iBAAiB,EAAE,mBAAmB,EACtC,QAAQ,EAAE,MAAM,GACf,MAAM,CAiBR;AAMD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,MAAM,CAEpB,EAAE,EAAE,qBAAqB,CAAC,GAAG,CAAC,EAC9B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,iBAAiB,EAAE,mBAAmB,GACrC,cAAc,GAAG,IAAI,CAIvB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,KAAK,CAEnB,EAAE,EAAE,qBAAqB,CAAC,GAAG,CAAC,EAC9B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,iBAAiB,EAAE,mBAAmB,EACtC,OAAO,EAAE,MAAM,GACd,cAAc,CAShB"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// ──────────────────────────────────────────────
|
|
2
|
+
// composed-prompt-cache — cache lookup + write for the composed_prompts table.
|
|
3
|
+
//
|
|
4
|
+
// Implements Decision D (decisions.md [def:context-hash]):
|
|
5
|
+
// context_hash = SHA-256( sortedJSON(context) + " " + sortedJSON(componentVersions) + " " + platform )
|
|
6
|
+
//
|
|
7
|
+
// The three-part key encodes:
|
|
8
|
+
// 1. The runtime context (any key/value change → different hash → cache miss).
|
|
9
|
+
// 2. The resolved component-version set (an unpinned component advancing to a
|
|
10
|
+
// new latest → different componentVersions → miss).
|
|
11
|
+
// 3. The target platform (different platform → different content shape → miss).
|
|
12
|
+
//
|
|
13
|
+
// The "context part" reuses @adhd/agent-registry's exported `contextHash` helper
|
|
14
|
+
// for consistent sorted-key JSON canonicalization — do NOT reimplement
|
|
15
|
+
// ([ref:store-read], decisions.md Decision D note).
|
|
16
|
+
//
|
|
17
|
+
// The composed_prompts table comes from @adhd/agent-registry (plan 1,
|
|
18
|
+
// `registry_composed_prompts`). We use the existing table via the shared DB
|
|
19
|
+
// handle passed by `compileAgent` ([inv:one-db-handle]). No duplicate table
|
|
20
|
+
// is created here.
|
|
21
|
+
//
|
|
22
|
+
// [def:context-hash] — the combined cache key algorithm (decisions.md Decision D)
|
|
23
|
+
// [inv:one-db-handle] — shared Drizzle handle, all four table prefixes
|
|
24
|
+
// [inv:reopen-proves-cache] — persistence proven by CLOSE+REOPEN (test invariant)
|
|
25
|
+
// ──────────────────────────────────────────────
|
|
26
|
+
import { createHash } from 'node:crypto';
|
|
27
|
+
import { ComposedPromptStore, contextHash as registryContextHash, } from '@adhd/agent-store-prompts';
|
|
28
|
+
// ──────────────────────────────────────────────
|
|
29
|
+
// Combined cache-key hash
|
|
30
|
+
// ──────────────────────────────────────────────
|
|
31
|
+
/**
|
|
32
|
+
* Compute the combined `context_hash` for the `registry_composed_prompts` cache.
|
|
33
|
+
*
|
|
34
|
+
* Decision D (decisions.md): `context_hash = SHA-256(sortedJSON(context) + " " +
|
|
35
|
+
* sortedJSON(componentVersions) + " " + platform)`.
|
|
36
|
+
*
|
|
37
|
+
* The `registryContextHash` (from @adhd/agent-registry) handles sorted-key JSON
|
|
38
|
+
* canonicalization of the context part. We apply the same sorted-key approach to
|
|
39
|
+
* `componentVersions` and append the `platform` string as a third field so that any
|
|
40
|
+
* of the three inputs changing produces a distinct hash.
|
|
41
|
+
*
|
|
42
|
+
* A ` ` (space) field separator is used between parts — plain JSON can never contain
|
|
43
|
+
* an unescaped space at the top level, so the three blobs cannot collide by
|
|
44
|
+
* concatenation.
|
|
45
|
+
*
|
|
46
|
+
* @param context - Runtime context key/value map (e.g. `{ticket_type:"security"}`).
|
|
47
|
+
* @param componentVersions - Resolved component-version map from `resolveComposition`.
|
|
48
|
+
* @param platform - Target platform id (e.g. `claude_code`, `claude_api`).
|
|
49
|
+
* @returns 64-character lowercase hex SHA-256 string.
|
|
50
|
+
*/
|
|
51
|
+
export function computeContextHash(context, componentVersions, platform) {
|
|
52
|
+
// Part 1: sorted-key JSON of context (reuse the upstream helper for parity).
|
|
53
|
+
const contextPart = registryContextHash(context);
|
|
54
|
+
// Part 2: sorted-key JSON of componentVersions (apply the same canonicalization).
|
|
55
|
+
const sortedVersions = Object.fromEntries(Object.keys(componentVersions)
|
|
56
|
+
.sort()
|
|
57
|
+
.map((k) => [k, componentVersions[k]]));
|
|
58
|
+
const versionPart = JSON.stringify(sortedVersions);
|
|
59
|
+
// Combined: context_hash(context) + " " + sortedJSON(componentVersions) + " " + platform
|
|
60
|
+
// Field separator is a bare space — JSON strings never contain unescaped spaces
|
|
61
|
+
// at the outermost level, so the three segments cannot collide.
|
|
62
|
+
const combined = `${contextPart} ${versionPart} ${platform}`;
|
|
63
|
+
return createHash('sha256').update(combined, 'utf8').digest('hex');
|
|
64
|
+
}
|
|
65
|
+
// ──────────────────────────────────────────────
|
|
66
|
+
// Cache operations
|
|
67
|
+
// ──────────────────────────────────────────────
|
|
68
|
+
/**
|
|
69
|
+
* Look up a `registry_composed_prompts` row by `(agentSlug, platform, context_hash)`.
|
|
70
|
+
*
|
|
71
|
+
* The `context_hash` encodes `(context, componentVersions, platform)` per Decision D.
|
|
72
|
+
* Returns the cached row (with its `id`) on a HIT, or `null` on a MISS.
|
|
73
|
+
*
|
|
74
|
+
* A cache hit means `compileAgent` can return the persisted `{id, content}` WITHOUT
|
|
75
|
+
* re-running the resolve layers (the assembly step is bypassed). This is the
|
|
76
|
+
* `[dod.4]` negative-control guarantee: removing this SELECT before assembly causes
|
|
77
|
+
* a duplicate row on every compile.
|
|
78
|
+
*
|
|
79
|
+
* @param db - Shared Drizzle handle (all four table prefixes).
|
|
80
|
+
* @param agentSlug - Agent to look up.
|
|
81
|
+
* @param platform - Target platform id.
|
|
82
|
+
* @param context - Runtime context key/value map.
|
|
83
|
+
* @param componentVersions - Resolved component-version map from `resolveComposition`.
|
|
84
|
+
* @returns The cached `ComposedPrompt` row on a HIT, or `null` on a MISS.
|
|
85
|
+
*/
|
|
86
|
+
export function lookup(
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
88
|
+
db, agentSlug, platform, context, componentVersions) {
|
|
89
|
+
const hash = computeContextHash(context, componentVersions, platform);
|
|
90
|
+
const store = new ComposedPromptStore(db);
|
|
91
|
+
return store.lookup(agentSlug, hash);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Write a new `registry_composed_prompts` row for `(agentSlug, platform, context_hash)`.
|
|
95
|
+
*
|
|
96
|
+
* Called on a cache MISS: after assembly is complete, persists the composed prompt
|
|
97
|
+
* so subsequent compiles can hit the cache. Returns the inserted row, including the
|
|
98
|
+
* generated `id` (the [def:composed-output].id audit/cache handle).
|
|
99
|
+
*
|
|
100
|
+
* @param db - Shared Drizzle handle (all four table prefixes).
|
|
101
|
+
* @param agentSlug - Agent the row belongs to.
|
|
102
|
+
* @param platform - Target platform id (folded into the hash).
|
|
103
|
+
* @param context - Runtime context key/value map used for assembly.
|
|
104
|
+
* @param componentVersions - Resolved component-version map (audit trail).
|
|
105
|
+
* @param content - The assembled platform artifact (markdown, JSON, etc.).
|
|
106
|
+
* @returns The inserted `ComposedPrompt` row with its generated `id`.
|
|
107
|
+
*/
|
|
108
|
+
export function write(
|
|
109
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
110
|
+
db, agentSlug, platform, context, componentVersions, content) {
|
|
111
|
+
const hash = computeContextHash(context, componentVersions, platform);
|
|
112
|
+
const store = new ComposedPromptStore(db);
|
|
113
|
+
return store.write({
|
|
114
|
+
agentSlug,
|
|
115
|
+
contextHash: hash,
|
|
116
|
+
content,
|
|
117
|
+
componentVersions,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=composed-prompt-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composed-prompt-cache.js","sourceRoot":"","sources":["../../../../../../packages/agent/agent-engine-compiler/src/cache/composed-prompt-cache.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,+EAA+E;AAC/E,EAAE;AACF,2DAA2D;AA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D;AAEjD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,MAAM;AACpB,8DAA8D;AAC9D,EAA8B,EAC9B,SAAiB,EACjB,QAAgB,EAChB,OAA+B,EAC/B,iBAAsC;IAEtC,MAAM,IAAI,GAAG,kBAAkB,CAAC,OAAO,EAAE,iBAAiB,EAAE,QAAQ,CAAC,CAAC;IACtE,MAAM,KAAK,GAAG,IAAI,mBAAmB,CAAC,EAAE,CAAC,CAAC;IAC1C,OAAO,KAAK,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AACvC,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,KAAK;AACnB,8DAA8D;AAC9D,EAA8B,EAC9B,SAAiB,EACjB,QAAgB,EAChB,OAA+B,EAC/B,iBAAsC,EACtC,OAAe;IAEf,MAAM,IAAI,GAAG,kBAAkB,CAAC,OAAO,EAAE,iBAAiB,EAAE,QAAQ,CAAC,CAAC;IACtE,MAAM,KAAK,GAAG,IAAI,mBAAmB,CAAC,EAAE,CAAC,CAAC;IAC1C,OAAO,KAAK,CAAC,KAAK,CAAC;QACjB,SAAS;QACT,WAAW,EAAE,IAAI;QACjB,OAAO;QACP,iBAAiB;KAClB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../../../../../packages/agent/agent-engine-compiler/src/cli/compile.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// ──────────────────────────────────────────────
|
|
3
|
+
// cli/compile.ts — argv parser + dispatcher for the agent-compiler bin.
|
|
4
|
+
//
|
|
5
|
+
// Usage:
|
|
6
|
+
// node cli/compile.js compile <slug> [options]
|
|
7
|
+
//
|
|
8
|
+
// Options:
|
|
9
|
+
// --platform <p> Target platform (default: claude_code).
|
|
10
|
+
// Must match a row in tool_platforms.
|
|
11
|
+
// --context '<json>' Runtime context key/value object (JSON string).
|
|
12
|
+
// --format json Emit JSON instead of platform default.
|
|
13
|
+
// --out-dir <d> Write <slug>.md (or <slug>.json) under <d>
|
|
14
|
+
// instead of printing to stdout.
|
|
15
|
+
// --all Compile every agent in the registry (use with
|
|
16
|
+
// --category to limit scope).
|
|
17
|
+
// --category <c> Filter to agents in this taxonomy category slug.
|
|
18
|
+
// --db <path> Path to the SQLite registry file. Defaults to
|
|
19
|
+
// AGENT_REGISTRY_DB env var, then ~/.agent-registry/registry.db.
|
|
20
|
+
//
|
|
21
|
+
// Exit codes:
|
|
22
|
+
// 0 — success
|
|
23
|
+
// 1 — unknown slug / unknown platform / bad argument / I/O error
|
|
24
|
+
//
|
|
25
|
+
// [ref:cli-bin] — mirrors agent-mcp's bin entry in package.json;
|
|
26
|
+
// parses compile <slug> ... and writes content to stdout or --out-dir.
|
|
27
|
+
// [inv:platform-node] — no browser imports; pure Node + SQLite.
|
|
28
|
+
// [inv:one-db-handle] — opens ONE better-sqlite3 handle for the shared DB.
|
|
29
|
+
// ──────────────────────────────────────────────
|
|
30
|
+
import fs from 'node:fs';
|
|
31
|
+
import os from 'node:os';
|
|
32
|
+
import path from 'node:path';
|
|
33
|
+
import process from 'node:process';
|
|
34
|
+
import { fileURLToPath } from 'node:url';
|
|
35
|
+
import Database from 'better-sqlite3';
|
|
36
|
+
import { drizzle } from 'drizzle-orm/better-sqlite3';
|
|
37
|
+
import { migrate } from 'drizzle-orm/better-sqlite3/migrator';
|
|
38
|
+
import { AgentStore } from '@adhd/agent-store-prompts';
|
|
39
|
+
import { compileAgent } from '../compile.js';
|
|
40
|
+
// ── Migration folders ─────────────────────────────────────────────────────
|
|
41
|
+
//
|
|
42
|
+
// Resolved relative to this compiled file's __dirname at runtime so the bin
|
|
43
|
+
// works from the dist layout without referencing source paths.
|
|
44
|
+
//
|
|
45
|
+
// dist/packages/agent/agent-engine-compiler/src/cli/compile.js
|
|
46
|
+
// → ../../ = dist/packages/agent/agent-engine-compiler/
|
|
47
|
+
// → ../../../ = dist/packages/agent/
|
|
48
|
+
// → ../../../<pkg>/drizzle = dist/packages/agent/<pkg>/drizzle
|
|
49
|
+
//
|
|
50
|
+
// Timestamp order (ascending) matters so Drizzle's journal bookkeeping
|
|
51
|
+
// doesn't skip a migration set:
|
|
52
|
+
// provider (1750*) → registry (1782193*) → tool-registry (1782250*)
|
|
53
|
+
// → policy (1782256*) → compiler (18*)
|
|
54
|
+
//
|
|
55
|
+
// This mirrors the migration order in compile-agent.test.ts.
|
|
56
|
+
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
|
57
|
+
const AI_DIST = path.resolve(__dirname, '../../../');
|
|
58
|
+
const PROVIDER_MIGRATIONS = path.join(AI_DIST, 'agent-core-provider/drizzle');
|
|
59
|
+
const REGISTRY_MIGRATIONS = path.join(AI_DIST, 'agent-store-prompts/drizzle');
|
|
60
|
+
const TOOL_REGISTRY_MIGRATIONS = path.join(AI_DIST, 'agent-store-tools/drizzle');
|
|
61
|
+
const POLICY_MIGRATIONS = path.join(AI_DIST, 'agent-core-policy/drizzle');
|
|
62
|
+
const COMPILER_MIGRATIONS = path.join(AI_DIST, 'agent-engine-compiler/drizzle');
|
|
63
|
+
// ──────────────────────────────────────────────
|
|
64
|
+
// argv parser
|
|
65
|
+
// ──────────────────────────────────────────────
|
|
66
|
+
/**
|
|
67
|
+
* Parse process.argv into a CliArgs object.
|
|
68
|
+
* Exits 1 with a usage message on any parse error.
|
|
69
|
+
*/
|
|
70
|
+
function parseArgs(argv) {
|
|
71
|
+
// argv: [ node, compile.js, 'compile', <slug?>, ...flags ]
|
|
72
|
+
const args = argv.slice(2); // strip node + script path
|
|
73
|
+
if (args[0] !== 'compile') {
|
|
74
|
+
die(`Expected sub-command 'compile', got: ${args[0] ?? '(nothing)'}`);
|
|
75
|
+
}
|
|
76
|
+
let slug = null;
|
|
77
|
+
let platform = 'claude_code';
|
|
78
|
+
let context = {};
|
|
79
|
+
let formatJson = false;
|
|
80
|
+
let outDir = null;
|
|
81
|
+
let all = false;
|
|
82
|
+
let category = null;
|
|
83
|
+
let dbPath = process.env['AGENT_REGISTRY_DB'] ??
|
|
84
|
+
path.join(os.homedir(), '.agent-registry', 'registry.db');
|
|
85
|
+
const flags = args.slice(1); // everything after 'compile'
|
|
86
|
+
let i = 0;
|
|
87
|
+
while (i < flags.length) {
|
|
88
|
+
const tok = flags[i];
|
|
89
|
+
if (tok === '--platform') {
|
|
90
|
+
platform = requireNext(flags, i, '--platform');
|
|
91
|
+
i += 2;
|
|
92
|
+
}
|
|
93
|
+
else if (tok === '--context') {
|
|
94
|
+
const raw = requireNext(flags, i, '--context');
|
|
95
|
+
try {
|
|
96
|
+
// Parse as unknown first, then cast to CompositionContext (Record<string, string>).
|
|
97
|
+
// The runtime contract is that --context values are string-keyed, string-valued.
|
|
98
|
+
context = JSON.parse(raw);
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
die(`--context must be valid JSON; got: ${raw}`);
|
|
102
|
+
}
|
|
103
|
+
i += 2;
|
|
104
|
+
}
|
|
105
|
+
else if (tok === '--format') {
|
|
106
|
+
const fmt = requireNext(flags, i, '--format');
|
|
107
|
+
if (fmt !== 'json') {
|
|
108
|
+
die(`--format only supports 'json'; got: '${fmt}'`);
|
|
109
|
+
}
|
|
110
|
+
formatJson = true;
|
|
111
|
+
i += 2;
|
|
112
|
+
}
|
|
113
|
+
else if (tok === '--out-dir') {
|
|
114
|
+
outDir = requireNext(flags, i, '--out-dir');
|
|
115
|
+
i += 2;
|
|
116
|
+
}
|
|
117
|
+
else if (tok === '--all') {
|
|
118
|
+
all = true;
|
|
119
|
+
i++;
|
|
120
|
+
}
|
|
121
|
+
else if (tok === '--category') {
|
|
122
|
+
category = requireNext(flags, i, '--category');
|
|
123
|
+
i += 2;
|
|
124
|
+
}
|
|
125
|
+
else if (tok === '--db') {
|
|
126
|
+
dbPath = requireNext(flags, i, '--db');
|
|
127
|
+
i += 2;
|
|
128
|
+
}
|
|
129
|
+
else if (tok != null && !tok.startsWith('-')) {
|
|
130
|
+
// Positional slug — only accepted once.
|
|
131
|
+
if (slug !== null) {
|
|
132
|
+
die(`Unexpected extra positional argument: '${tok}'`);
|
|
133
|
+
}
|
|
134
|
+
slug = tok;
|
|
135
|
+
i++;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
die(`Unknown flag: '${tok}'`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (!all && slug === null) {
|
|
142
|
+
die('Provide a slug (compile <slug>) or use --all [--category <c>]');
|
|
143
|
+
}
|
|
144
|
+
if (all && slug !== null) {
|
|
145
|
+
die('--all and a positional slug are mutually exclusive');
|
|
146
|
+
}
|
|
147
|
+
return { slug, platform, context, formatJson, outDir, all, category, dbPath };
|
|
148
|
+
}
|
|
149
|
+
function requireNext(flags, i, flag) {
|
|
150
|
+
const val = flags[i + 1];
|
|
151
|
+
if (val == null || val.startsWith('-')) {
|
|
152
|
+
die(`${flag} requires a value`);
|
|
153
|
+
}
|
|
154
|
+
return val;
|
|
155
|
+
}
|
|
156
|
+
// ──────────────────────────────────────────────
|
|
157
|
+
// DB open helper
|
|
158
|
+
// ──────────────────────────────────────────────
|
|
159
|
+
/**
|
|
160
|
+
* Open the shared SQLite registry file and apply migrations so the schema is
|
|
161
|
+
* always current ([inv:one-db-handle]).
|
|
162
|
+
*
|
|
163
|
+
* Runs all five migration sets in ascending timestamp order so Drizzle's
|
|
164
|
+
* journal does not skip any set.
|
|
165
|
+
*/
|
|
166
|
+
function openDb(dbPath) {
|
|
167
|
+
if (!fs.existsSync(dbPath)) {
|
|
168
|
+
const parent = path.dirname(dbPath);
|
|
169
|
+
if (!fs.existsSync(parent)) {
|
|
170
|
+
fs.mkdirSync(parent, { recursive: true });
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
const conn = new Database(dbPath);
|
|
174
|
+
conn.pragma('journal_mode = WAL');
|
|
175
|
+
conn.pragma('foreign_keys = OFF');
|
|
176
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
177
|
+
const db = drizzle(conn, { schema: {} });
|
|
178
|
+
// Migrate in ascending timestamp order — same pattern as the test suite.
|
|
179
|
+
for (const folder of [
|
|
180
|
+
PROVIDER_MIGRATIONS,
|
|
181
|
+
REGISTRY_MIGRATIONS,
|
|
182
|
+
TOOL_REGISTRY_MIGRATIONS,
|
|
183
|
+
POLICY_MIGRATIONS,
|
|
184
|
+
COMPILER_MIGRATIONS,
|
|
185
|
+
]) {
|
|
186
|
+
if (fs.existsSync(folder)) {
|
|
187
|
+
migrate(db, { migrationsFolder: folder });
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
process.stderr.write(`agent-compiler: warning: migration folder not found: ${folder}\n`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
conn.pragma('foreign_keys = ON');
|
|
194
|
+
return { conn, db };
|
|
195
|
+
}
|
|
196
|
+
// ──────────────────────────────────────────────
|
|
197
|
+
// Compile a single agent → string artifact
|
|
198
|
+
// ──────────────────────────────────────────────
|
|
199
|
+
function compileSingle(slug, args,
|
|
200
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
201
|
+
db) {
|
|
202
|
+
let result;
|
|
203
|
+
try {
|
|
204
|
+
result = compileAgent({
|
|
205
|
+
agentSlug: slug,
|
|
206
|
+
platform: args.platform,
|
|
207
|
+
context: args.context,
|
|
208
|
+
db,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
catch (err) {
|
|
212
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
213
|
+
// Distinguish AGENT_NOT_FOUND / PLATFORM_NOT_FOUND from other errors.
|
|
214
|
+
if (msg.includes('not found') || msg.includes('NOT_FOUND')) {
|
|
215
|
+
die(`Error: ${msg}`);
|
|
216
|
+
}
|
|
217
|
+
die(`Compilation failed for '${slug}' on platform '${args.platform}': ${msg}`);
|
|
218
|
+
}
|
|
219
|
+
// --format json overrides the platform's default header format.
|
|
220
|
+
if (args.formatJson) {
|
|
221
|
+
// If content is already JSON (json_object platforms), return as-is.
|
|
222
|
+
try {
|
|
223
|
+
JSON.parse(result.content);
|
|
224
|
+
return result.content; // already valid JSON
|
|
225
|
+
}
|
|
226
|
+
catch {
|
|
227
|
+
// Wrap markdown in a JSON envelope.
|
|
228
|
+
return JSON.stringify({
|
|
229
|
+
systemPrompt: result.content,
|
|
230
|
+
tools: result.tools,
|
|
231
|
+
componentVersions: result.componentVersions,
|
|
232
|
+
}, null, 2);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return result.content;
|
|
236
|
+
}
|
|
237
|
+
// ──────────────────────────────────────────────
|
|
238
|
+
// Output helper
|
|
239
|
+
// ──────────────────────────────────────────────
|
|
240
|
+
/**
|
|
241
|
+
* Write content either to stdout or to <outDir>/<slug>.<ext>.
|
|
242
|
+
*/
|
|
243
|
+
function writeOutput(slug, content, args) {
|
|
244
|
+
if (args.outDir === null) {
|
|
245
|
+
process.stdout.write(content);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
fs.mkdirSync(args.outDir, { recursive: true });
|
|
249
|
+
const ext = args.formatJson ? 'json' : 'md';
|
|
250
|
+
const dest = path.join(args.outDir, `${slug}.${ext}`);
|
|
251
|
+
fs.writeFileSync(dest, content, 'utf8');
|
|
252
|
+
}
|
|
253
|
+
// ──────────────────────────────────────────────
|
|
254
|
+
// Fatal error helper
|
|
255
|
+
// ──────────────────────────────────────────────
|
|
256
|
+
function die(msg) {
|
|
257
|
+
process.stderr.write(`agent-compiler: ${msg}\n`);
|
|
258
|
+
process.exit(1);
|
|
259
|
+
}
|
|
260
|
+
// ──────────────────────────────────────────────
|
|
261
|
+
// Main
|
|
262
|
+
// ──────────────────────────────────────────────
|
|
263
|
+
function main() {
|
|
264
|
+
const args = parseArgs(process.argv);
|
|
265
|
+
const { conn, db } = openDb(args.dbPath);
|
|
266
|
+
try {
|
|
267
|
+
if (args.all) {
|
|
268
|
+
// Compile every agent in the registry, optionally filtered by category.
|
|
269
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
270
|
+
const agentStore = new AgentStore(db);
|
|
271
|
+
const agents = agentStore.list(args.category ? { category: args.category } : {});
|
|
272
|
+
if (agents.length === 0) {
|
|
273
|
+
const scope = args.category ? ` in category '${args.category}'` : '';
|
|
274
|
+
process.stderr.write(`agent-compiler: no agents found${scope}\n`);
|
|
275
|
+
// Exit 0 — empty category is not an error.
|
|
276
|
+
}
|
|
277
|
+
for (const agent of agents) {
|
|
278
|
+
const content = compileSingle(agent.slug, args, db);
|
|
279
|
+
writeOutput(agent.slug, content, args);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
// Single-slug path.
|
|
284
|
+
// slug is guaranteed non-null here by parseArgs.
|
|
285
|
+
const content = compileSingle(args.slug, args, db);
|
|
286
|
+
writeOutput(args.slug, content, args);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
finally {
|
|
290
|
+
conn.close();
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
main();
|
|
294
|
+
//# sourceMappingURL=compile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.js","sourceRoot":"","sources":["../../../../../../packages/agent/agent-engine-compiler/src/cli/compile.ts"],"names":[],"mappings":";AACA,iDAAiD;AACjD,wEAAwE;AACxE,EAAE;AACF,SAAS;AACT,iDAAiD;AACjD,EAAE;AACF,WAAW;AACX,gEAAgE;AAChE,4DAA4D;AAC5D,wEAAwE;AACxE,+DAA+D;AAC/D,mEAAmE;AACnE,uDAAuD;AACvD,sEAAsE;AACtE,oDAAoD;AACpD,yEAAyE;AACzE,sEAAsE;AACtE,uFAAuF;AACvF,EAAE;AACF,cAAc;AACd,iBAAiB;AACjB,oEAAoE;AACpE,EAAE;AACF,iEAAiE;AACjE,yEAAyE;AACzE,gEAAgE;AAChE,2EAA2E;AAC3E,iDAAiD;AAEjD,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,CAAC,CAAC,CAAC,EAAE,CAAC;gBACrE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,kCAAkC,KAAK,IAAI,CAAC,CAAC;gBAClE,2CAA2C;YAC7C,CAAC;YAED,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;gBAC3B,MAAM,OAAO,GAAG,aAAa,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;gBACpD,WAAW,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;YACzC,CAAC;QACH,CAAC;aAAM,CAAC;YACN,oBAAoB;YACpB,iDAAiD;YACjD,MAAM,OAAO,GAAG,aAAa,CAAC,IAAI,CAAC,IAAc,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;YAC7D,WAAW,CAAC,IAAI,CAAC,IAAc,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;YAAS,CAAC;QACT,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC"}
|
package/src/compile.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';
|
|
2
|
+
import type { CompositionContext } from '@adhd/agent-store-prompts';
|
|
3
|
+
import type { ComponentVersionMap } from './resolve/composition.js';
|
|
4
|
+
import type { StructuredTool } from './emit/json.js';
|
|
5
|
+
/** Input to compileAgent ([def:compile-input]). */
|
|
6
|
+
export interface CompileInput {
|
|
7
|
+
/** Slug of the agent to compile. */
|
|
8
|
+
agentSlug: string;
|
|
9
|
+
/** Target platform id (e.g. 'claude_code', 'claude_api'). */
|
|
10
|
+
platform: string;
|
|
11
|
+
/** Runtime context key/value map for context-conditioned components. */
|
|
12
|
+
context?: CompositionContext;
|
|
13
|
+
/** Shared registry Drizzle handle (all four table prefixes — [inv:one-db-handle]). */
|
|
14
|
+
db: BetterSQLite3Database<any>;
|
|
15
|
+
}
|
|
16
|
+
/** Return value of compileAgent ([def:composed-output]). */
|
|
17
|
+
export interface CompiledAgent {
|
|
18
|
+
/**
|
|
19
|
+
* `composed_prompts` row id (audit/cache handle).
|
|
20
|
+
* The inserted `registry_composed_prompts` row id (on MISS, written by the
|
|
21
|
+
* cache layer) or the existing row id (on HIT, served from the cache).
|
|
22
|
+
* Wired by the composed-prompt-caching state ([def:composed-output]).
|
|
23
|
+
*/
|
|
24
|
+
id: number;
|
|
25
|
+
/** Flat platform artifact (markdown for claude_code, JSON string for claude_api/openai). */
|
|
26
|
+
content: string;
|
|
27
|
+
/**
|
|
28
|
+
* Resolved platform-shaped tools.
|
|
29
|
+
* For claude_code: string[] of aliases (e.g. ['Read','Grep','WebSearch']).
|
|
30
|
+
* For claude_api: StructuredTool[] (EmittedTool[]) shaped for the API.
|
|
31
|
+
* For none-format: [] (platform does not support tool selection).
|
|
32
|
+
*/
|
|
33
|
+
tools: string[] | StructuredTool[];
|
|
34
|
+
/**
|
|
35
|
+
* Map of componentSlug → resolvedVersion for cache-key computation
|
|
36
|
+
* ([def:context-hash]).
|
|
37
|
+
*/
|
|
38
|
+
componentVersions: ComponentVersionMap;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Compile an agent to a flat, platform-shaped artifact.
|
|
42
|
+
*
|
|
43
|
+
* Orchestrates the four resolve layers:
|
|
44
|
+
* 1. body + componentVersions — CompositionStore.resolveComposition (junction order)
|
|
45
|
+
* 2. tools — resolveTools (platform aliases)
|
|
46
|
+
* 3. model — resolveModel (platform binding or canonical fallback)
|
|
47
|
+
* 4. constraints — resolvePolicyConstraints (direct + inherited)
|
|
48
|
+
*
|
|
49
|
+
* Then dispatches on the platform's `header_format` column to the matching
|
|
50
|
+
* emit function. The `id` field is null until `composed-prompt-caching`
|
|
51
|
+
* wires the cache write ([def:composed-output]).
|
|
52
|
+
*
|
|
53
|
+
* @param input - Agent slug, target platform, runtime context, shared DB handle.
|
|
54
|
+
* @returns Compiled platform artifact plus metadata.
|
|
55
|
+
*
|
|
56
|
+
* @throws {AgentError} AGENT_NOT_FOUND — agentSlug not in registry_agents.
|
|
57
|
+
* @throws {CompositionError} REQUIRED_COMPONENT_EXCLUDED — a required component
|
|
58
|
+
* was excluded by the runtime context.
|
|
59
|
+
*/
|
|
60
|
+
export declare function compileAgent(input: CompileInput): CompiledAgent;
|
|
61
|
+
//# sourceMappingURL=compile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../../../../packages/agent/agent-engine-compiler/src/compile.ts"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAGxE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAUpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAUrD,mDAAmD;AACnD,MAAM,WAAW,YAAY;IAC3B,oCAAoC;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,6DAA6D;IAC7D,QAAQ,EAAE,MAAM,CAAC;IACjB,wEAAwE;IACxE,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B,sFAAsF;IAEtF,EAAE,EAAE,qBAAqB,CAAC,GAAG,CAAC,CAAC;CAChC;AAED,4DAA4D;AAC5D,MAAM,WAAW,aAAa;IAC5B;;;;;OAKG;IACH,EAAE,EAAE,MAAM,CAAC;IACX,4FAA4F;IAC5F,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;OAKG;IACH,KAAK,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,CAAC;IACnC;;;OAGG;IACH,iBAAiB,EAAE,mBAAmB,CAAC;CACxC;AA6DD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,YAAY,GAAG,aAAa,CA6N/D"}
|