@adhd/agent-engine-compiler 2.1.8 → 2.1.10
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 +39 -0
- package/README.md +72 -0
- package/drizzle/meta/_journal.json +5 -0
- package/package.json +9 -31
- 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 +300 -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/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/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 +18 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +21 -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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../../src/resolve/model.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAExE,iDAAiD;AACjD,gFAAgF;AAChF,EAAE;AACF,kFAAkF;AAClF,kFAAkF;AAClF,iEAAiE;AACjE,EAAE;AACF,iFAAiF;AACjF,qFAAqF;AACrF,gFAAgF;AAChF,+DAA+D;AAC/D,EAAE;AACF,+EAA+E;AAC/E,qFAAqF;AACrF,kFAAkF;AAClF,8EAA8E;AAC9E,uFAAuF;AACvF,iDAAiD;AAEjD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,YAAY;AAC1B,8DAA8D;AAC9D,EAA8B,EAC9B,SAAiB,EACjB,QAAgB;IAEhB,yCAAyC;IACzC,8DAA8D;IAC9D,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,EAAS,CAAC,CAAC;IAC7C,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAEzC,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;IAElC,iFAAiF;IACjF,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,wFAAwF;IACxF,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IACtC,IAAI,CAAC;QACH,OAAO,UAAU,CAAC,cAAc,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IACxD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IACE,GAAG,YAAY,eAAe;YAC9B,GAAG,CAAC,IAAI,KAAK,yBAAyB,EACtC,CAAC;YACD,4EAA4E;YAC5E,wEAAwE;YACxE,8EAA8E;YAC9E,8BAA8B;YAC9B,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';
|
|
2
|
+
/** A resolved policy constraint ready for header/body rendering. */
|
|
3
|
+
export interface Constraint {
|
|
4
|
+
/** The policy template slug (e.g. 'no-credentials'). */
|
|
5
|
+
policySlug: string;
|
|
6
|
+
/** The human-readable constraint text rendered into the compiled output. */
|
|
7
|
+
text: string;
|
|
8
|
+
/** True when this constraint is mandatory (cannot be overridden). */
|
|
9
|
+
isMandatory: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Category slug this constraint was inherited from, or null for direct-attach.
|
|
12
|
+
* Surfaces the provenance of inherited constraints in compiled output.
|
|
13
|
+
*/
|
|
14
|
+
inheritedFrom: string | null;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Resolve all effective policy constraints for an agent (direct + inherited).
|
|
18
|
+
*
|
|
19
|
+
* Delegates the full 3-query merge (direct rows + category memberships + category
|
|
20
|
+
* policies) to {@link AgentPolicyStore.resolveForAgent} — this function does NOT
|
|
21
|
+
* re-implement the inheritance join. The [dod.3] negative-control is:
|
|
22
|
+
* "return empty constraints when no agent_policy rows exist" — the constraint block
|
|
23
|
+
* is keyed exclusively on the agent_policy table.
|
|
24
|
+
*
|
|
25
|
+
* Each resolved row is joined to its template via {@link PolicyTemplateStore.read}
|
|
26
|
+
* and rendered as a {@link Constraint}. The constraint text = the template's
|
|
27
|
+
* `description`, which is the human-readable summary the compiler emits.
|
|
28
|
+
*
|
|
29
|
+
* @param db - The shared registry Drizzle handle (all table prefixes).
|
|
30
|
+
* @param agentSlug - Slug of the agent whose policy constraints to resolve.
|
|
31
|
+
* @returns Ordered list of constraints (direct first, then inherited by category).
|
|
32
|
+
*/
|
|
33
|
+
export declare function resolvePolicyConstraints(db: BetterSQLite3Database<any>, agentSlug: string): Constraint[];
|
|
34
|
+
//# sourceMappingURL=policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../../src/resolve/policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAwBxE,oEAAoE;AACpE,MAAM,WAAW,UAAU;IACzB,wDAAwD;IACxD,UAAU,EAAE,MAAM,CAAC;IACnB,4EAA4E;IAC5E,IAAI,EAAE,MAAM,CAAC;IACb,qEAAqE;IACrE,WAAW,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,wBAAwB,CAEtC,EAAE,EAAE,qBAAqB,CAAC,GAAG,CAAC,EAC9B,SAAS,EAAE,MAAM,GAChB,UAAU,EAAE,CA2Bd"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { AgentPolicyStore, PolicyTemplateStore } from '@adhd/agent-core-policy';
|
|
2
|
+
/**
|
|
3
|
+
* Resolve all effective policy constraints for an agent (direct + inherited).
|
|
4
|
+
*
|
|
5
|
+
* Delegates the full 3-query merge (direct rows + category memberships + category
|
|
6
|
+
* policies) to {@link AgentPolicyStore.resolveForAgent} — this function does NOT
|
|
7
|
+
* re-implement the inheritance join. The [dod.3] negative-control is:
|
|
8
|
+
* "return empty constraints when no agent_policy rows exist" — the constraint block
|
|
9
|
+
* is keyed exclusively on the agent_policy table.
|
|
10
|
+
*
|
|
11
|
+
* Each resolved row is joined to its template via {@link PolicyTemplateStore.read}
|
|
12
|
+
* and rendered as a {@link Constraint}. The constraint text = the template's
|
|
13
|
+
* `description`, which is the human-readable summary the compiler emits.
|
|
14
|
+
*
|
|
15
|
+
* @param db - The shared registry Drizzle handle (all table prefixes).
|
|
16
|
+
* @param agentSlug - Slug of the agent whose policy constraints to resolve.
|
|
17
|
+
* @returns Ordered list of constraints (direct first, then inherited by category).
|
|
18
|
+
*/
|
|
19
|
+
export function resolvePolicyConstraints(
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
+
db, agentSlug) {
|
|
22
|
+
// Step 1: full effective policy set — direct + inherited.
|
|
23
|
+
// resolveForAgent is the SINGLE place the 3-query merge lives ([ref:store-read]).
|
|
24
|
+
const agentPolicyStore = new AgentPolicyStore(db);
|
|
25
|
+
const rows = agentPolicyStore.resolveForAgent(agentSlug);
|
|
26
|
+
// Step 2: for each row, read the policy template and render the constraint text.
|
|
27
|
+
const templateStore = new PolicyTemplateStore(db);
|
|
28
|
+
const constraints = [];
|
|
29
|
+
for (const row of rows) {
|
|
30
|
+
const template = templateStore.read(row.policySlug);
|
|
31
|
+
// Constraint text = the template's description.
|
|
32
|
+
// This is the consumer-visible text the compiler renders into the header/body
|
|
33
|
+
// ([def:policy-constraint], [inv:platform-shaped-observable]).
|
|
34
|
+
const text = template.description;
|
|
35
|
+
constraints.push({
|
|
36
|
+
policySlug: row.policySlug,
|
|
37
|
+
text,
|
|
38
|
+
isMandatory: row.isMandatory,
|
|
39
|
+
inheritedFrom: row.inheritedFrom,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return constraints;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../../../src/resolve/policy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAqChF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,wBAAwB;AACtC,8DAA8D;AAC9D,EAA8B,EAC9B,SAAiB;IAEjB,0DAA0D;IAC1D,kFAAkF;IAClF,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,CAAC,EAAE,CAAC,CAAC;IAClD,MAAM,IAAI,GAAG,gBAAgB,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;IAEzD,iFAAiF;IACjF,MAAM,aAAa,GAAG,IAAI,mBAAmB,CAAC,EAAE,CAAC,CAAC;IAClD,MAAM,WAAW,GAAiB,EAAE,CAAC;IAErC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,QAAQ,GAAG,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAEpD,gDAAgD;QAChD,8EAA8E;QAC9E,+DAA+D;QAC/D,MAAM,IAAI,GAAG,QAAQ,CAAC,WAAW,CAAC;QAElC,WAAW,CAAC,IAAI,CAAC;YACf,UAAU,EAAE,GAAG,CAAC,UAAU;YAC1B,IAAI;YACJ,WAAW,EAAE,GAAG,CAAC,WAAW;YAC5B,aAAa,EAAE,GAAG,CAAC,aAAa;SACjC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';
|
|
2
|
+
/** A resolved platform alias for one canonical tool grant. */
|
|
3
|
+
export interface ResolvedTool {
|
|
4
|
+
/** Canonical tool name (e.g. 'file_read', 'shell_exec'). */
|
|
5
|
+
canonicalName: string;
|
|
6
|
+
/** Platform-specific alias (e.g. 'Read' on claude_code, 'read_file' on claude_api). */
|
|
7
|
+
platformAlias: string;
|
|
8
|
+
/** Availability on this platform: 'available' | 'restricted' | 'requires_permission'. */
|
|
9
|
+
availability: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Resolve an agent's tool grants to ordered, de-duplicated platform aliases.
|
|
13
|
+
*
|
|
14
|
+
* Algorithm:
|
|
15
|
+
* 1. `AgentToolStore.listForAgent(agentSlug)` — fetch all `tool_*` grants.
|
|
16
|
+
* 2. `BindingStore.listForPlatform(platform)` — one platform-keyed query;
|
|
17
|
+
* index `idx_bindings_platform` makes this O(1) vs. the catalog size.
|
|
18
|
+
* 3. For each grant, look up its binding row in the result set.
|
|
19
|
+
* - No row → skip (tool has no binding for this platform).
|
|
20
|
+
* - `availability = 'unavailable'` → drop (e.g. `human_input` on `claude_api`).
|
|
21
|
+
* - Otherwise → emit `platformToolName` as the resolved alias.
|
|
22
|
+
*
|
|
23
|
+
* The platform filter is applied to BOTH the listForPlatform call AND the
|
|
24
|
+
* Map lookup so the result is always platform-shaped, never canonical-named.
|
|
25
|
+
* This is the invariant the [dod.1] negative-control tests.
|
|
26
|
+
*
|
|
27
|
+
* @param db - The shared registry Drizzle handle (all table prefixes).
|
|
28
|
+
* @param agentSlug - Slug of the agent whose tool grants to resolve.
|
|
29
|
+
* @param platform - Target platform id (e.g. 'claude_code', 'claude_api').
|
|
30
|
+
* @returns Ordered, de-duplicated `ResolvedTool[]` ready for header emission.
|
|
31
|
+
*/
|
|
32
|
+
export declare function resolveTools(db: BetterSQLite3Database<any>, agentSlug: string, platform: string): ResolvedTool[];
|
|
33
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../../src/resolve/tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAgCxE,8DAA8D;AAC9D,MAAM,WAAW,YAAY;IAC3B,4DAA4D;IAC5D,aAAa,EAAE,MAAM,CAAC;IACtB,uFAAuF;IACvF,aAAa,EAAE,MAAM,CAAC;IACtB,yFAAyF;IACzF,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,YAAY,CAE1B,EAAE,EAAE,qBAAqB,CAAC,GAAG,CAAC,EAC9B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,YAAY,EAAE,CAiDhB"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { AgentToolStore, BindingStore, } from '@adhd/agent-store-tools';
|
|
2
|
+
/**
|
|
3
|
+
* Resolve an agent's tool grants to ordered, de-duplicated platform aliases.
|
|
4
|
+
*
|
|
5
|
+
* Algorithm:
|
|
6
|
+
* 1. `AgentToolStore.listForAgent(agentSlug)` — fetch all `tool_*` grants.
|
|
7
|
+
* 2. `BindingStore.listForPlatform(platform)` — one platform-keyed query;
|
|
8
|
+
* index `idx_bindings_platform` makes this O(1) vs. the catalog size.
|
|
9
|
+
* 3. For each grant, look up its binding row in the result set.
|
|
10
|
+
* - No row → skip (tool has no binding for this platform).
|
|
11
|
+
* - `availability = 'unavailable'` → drop (e.g. `human_input` on `claude_api`).
|
|
12
|
+
* - Otherwise → emit `platformToolName` as the resolved alias.
|
|
13
|
+
*
|
|
14
|
+
* The platform filter is applied to BOTH the listForPlatform call AND the
|
|
15
|
+
* Map lookup so the result is always platform-shaped, never canonical-named.
|
|
16
|
+
* This is the invariant the [dod.1] negative-control tests.
|
|
17
|
+
*
|
|
18
|
+
* @param db - The shared registry Drizzle handle (all table prefixes).
|
|
19
|
+
* @param agentSlug - Slug of the agent whose tool grants to resolve.
|
|
20
|
+
* @param platform - Target platform id (e.g. 'claude_code', 'claude_api').
|
|
21
|
+
* @returns Ordered, de-duplicated `ResolvedTool[]` ready for header emission.
|
|
22
|
+
*/
|
|
23
|
+
export function resolveTools(
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
+
db, agentSlug, platform) {
|
|
26
|
+
const agentToolStore = new AgentToolStore(db);
|
|
27
|
+
const bindingStore = new BindingStore(db);
|
|
28
|
+
// Step 1: all grants for this agent (tool_* prefix, logical agent_slug key).
|
|
29
|
+
const grants = agentToolStore.listForAgent(agentSlug);
|
|
30
|
+
// Step 2: one platform-keyed query — reuses BindingStore ([ref:store-read]).
|
|
31
|
+
// Index idx_bindings_platform keeps this O(catalog-size), not O(grants).
|
|
32
|
+
const platformBindings = bindingStore.listForPlatform(platform);
|
|
33
|
+
// Build a Map<canonicalToolName, binding> for O(1) grant lookups.
|
|
34
|
+
// Platform is already baked in — the Map only holds bindings for THIS platform.
|
|
35
|
+
const bindingByTool = new Map(platformBindings.map((b) => [b.toolName, b]));
|
|
36
|
+
// Step 3: walk grants in their stored order; de-duplicate by canonical name.
|
|
37
|
+
const seen = new Set();
|
|
38
|
+
const results = [];
|
|
39
|
+
for (const grant of grants) {
|
|
40
|
+
if (seen.has(grant.toolName)) {
|
|
41
|
+
continue; // de-duplicate (should not occur with a well-formed DB, but defensive)
|
|
42
|
+
}
|
|
43
|
+
seen.add(grant.toolName);
|
|
44
|
+
const binding = bindingByTool.get(grant.toolName);
|
|
45
|
+
if (!binding) {
|
|
46
|
+
// No binding row for this tool on this platform — skip silently.
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (binding.availability === 'unavailable') {
|
|
50
|
+
// Explicitly unavailable on this platform (e.g. human_input on claude_api).
|
|
51
|
+
// [def:tools-header]: drop these — do not emit.
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
results.push({
|
|
55
|
+
canonicalName: grant.toolName,
|
|
56
|
+
platformAlias: binding.platformToolName,
|
|
57
|
+
availability: binding.availability,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return results;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../../src/resolve/tools.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,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AAS;QACX,CAAC;QAED,OAAO,CAAC,IAAI,CAAC;YACX,aAAa,EAAE,KAAK,CAAC,QAAQ;YAC7B,aAAa,EAAE,OAAO,CAAC,gBAAgB;YACvC,YAAY,EAAE,OAAO,CAAC,YAAY;SACnC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fixtures.ts — real-row fixture seeder for agent-compiler e2e tests.
|
|
3
|
+
*
|
|
4
|
+
* Exports `seedFixtureAgent(db)` which seeds the `api-design-reviewer` fixture
|
|
5
|
+
* agent (modelled after SEED_DATA.md §14 `code-reviewer`) into a shared SQLite
|
|
6
|
+
* DB handle that already has all four package migrations applied.
|
|
7
|
+
*
|
|
8
|
+
* Seed coverage:
|
|
9
|
+
* - registry prefix : taxonomy category, agent, components, junction rows
|
|
10
|
+
* - tool prefix : agent tool grants (file_read, file_grep, web_search)
|
|
11
|
+
* - provider prefix : model_hint = claude_sonnet_4_6 (seeded by seedProvider)
|
|
12
|
+
* - policy prefix : no-credentials policy template + direct attachment
|
|
13
|
+
*
|
|
14
|
+
* The two `success_criteria` junction rows are conditioned:
|
|
15
|
+
* position=4 → code-review-criteria (no context condition — general/review)
|
|
16
|
+
* position=5 → security-audit-criteria (context_condition={ticket_type:"security"})
|
|
17
|
+
*
|
|
18
|
+
* This mirrors the exact pattern from SEED_DATA.md §14 (code-reviewer, positions
|
|
19
|
+
* 5+6) and USAGE.md "Context-Conditional Composition".
|
|
20
|
+
*
|
|
21
|
+
* [inv:one-db-handle] — caller passes ONE shared DB handle, all four prefixes.
|
|
22
|
+
* [inv:real-rows-not-mocks] — this function seeds real rows; no mocks needed.
|
|
23
|
+
*/
|
|
24
|
+
import type { BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';
|
|
25
|
+
/** Slug of the seeded fixture agent. */
|
|
26
|
+
export declare const FIXTURE_AGENT_SLUG = "api-design-reviewer-e2e";
|
|
27
|
+
export declare const FIXTURE_CATEGORY_SLUG = "e2e-api-specialists";
|
|
28
|
+
export declare const COMP_ROLE = "generic-reviewer-role";
|
|
29
|
+
export declare const COMP_IDENTITY = "reviewer-identity";
|
|
30
|
+
export declare const COMP_RULE = "default-skeptic";
|
|
31
|
+
export declare const COMP_REVIEW_CRITERIA = "code-review-criteria";
|
|
32
|
+
export declare const COMP_SECURITY_CRITERIA = "security-audit-criteria";
|
|
33
|
+
export declare const TOOL_FILE_READ = "file_read";
|
|
34
|
+
export declare const TOOL_FILE_GREP = "file_grep";
|
|
35
|
+
export declare const TOOL_WEB_SEARCH = "web_search";
|
|
36
|
+
/**
|
|
37
|
+
* Seed the `api-design-reviewer-e2e` fixture agent into `db`.
|
|
38
|
+
*
|
|
39
|
+
* Prerequisites (caller must have already run against `db`):
|
|
40
|
+
* - All four package migrations applied.
|
|
41
|
+
* - seedRegistry(db) — for components (generic-reviewer-role etc.)
|
|
42
|
+
* - seedToolRegistry(db) — for tool catalog + platform bindings
|
|
43
|
+
* - seedProvider(db) — for model_platform_bindings (claude_sonnet_4_6)
|
|
44
|
+
* - seedPolicy(db) — for policy_policy_types + no-credentials template
|
|
45
|
+
*
|
|
46
|
+
* Idempotence: NOT idempotent — call once per test DB. Tests create a fresh
|
|
47
|
+
* temp file per suite so re-seed is never needed.
|
|
48
|
+
*
|
|
49
|
+
* @param db - The shared Drizzle handle (all four table prefixes).
|
|
50
|
+
*/
|
|
51
|
+
export declare function seedFixtureAgent(db: BetterSQLite3Database<any>): void;
|
|
52
|
+
//# sourceMappingURL=fixtures.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixtures.d.ts","sourceRoot":"","sources":["../../../src/seed/fixtures.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAYxE,wCAAwC;AACxC,eAAO,MAAM,kBAAkB,4BAA4B,CAAC;AAC5D,eAAO,MAAM,qBAAqB,wBAAwB,CAAC;AAI3D,eAAO,MAAM,SAAS,0BAA0B,CAAC;AACjD,eAAO,MAAM,aAAa,sBAAsB,CAAC;AACjD,eAAO,MAAM,SAAS,oBAAoB,CAAC;AAC3C,eAAO,MAAM,oBAAoB,yBAAyB,CAAC;AAC3D,eAAO,MAAM,sBAAsB,4BAA4B,CAAC;AAGhE,eAAO,MAAM,cAAc,cAAc,CAAC;AAC1C,eAAO,MAAM,cAAc,cAAc,CAAC;AAC1C,eAAO,MAAM,eAAe,eAAe,CAAC;AAI5C;;;;;;;;;;;;;;GAcG;AAEH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,qBAAqB,CAAC,GAAG,CAAC,GAAG,IAAI,CAsGrE"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fixtures.ts — real-row fixture seeder for agent-compiler e2e tests.
|
|
3
|
+
*
|
|
4
|
+
* Exports `seedFixtureAgent(db)` which seeds the `api-design-reviewer` fixture
|
|
5
|
+
* agent (modelled after SEED_DATA.md §14 `code-reviewer`) into a shared SQLite
|
|
6
|
+
* DB handle that already has all four package migrations applied.
|
|
7
|
+
*
|
|
8
|
+
* Seed coverage:
|
|
9
|
+
* - registry prefix : taxonomy category, agent, components, junction rows
|
|
10
|
+
* - tool prefix : agent tool grants (file_read, file_grep, web_search)
|
|
11
|
+
* - provider prefix : model_hint = claude_sonnet_4_6 (seeded by seedProvider)
|
|
12
|
+
* - policy prefix : no-credentials policy template + direct attachment
|
|
13
|
+
*
|
|
14
|
+
* The two `success_criteria` junction rows are conditioned:
|
|
15
|
+
* position=4 → code-review-criteria (no context condition — general/review)
|
|
16
|
+
* position=5 → security-audit-criteria (context_condition={ticket_type:"security"})
|
|
17
|
+
*
|
|
18
|
+
* This mirrors the exact pattern from SEED_DATA.md §14 (code-reviewer, positions
|
|
19
|
+
* 5+6) and USAGE.md "Context-Conditional Composition".
|
|
20
|
+
*
|
|
21
|
+
* [inv:one-db-handle] — caller passes ONE shared DB handle, all four prefixes.
|
|
22
|
+
* [inv:real-rows-not-mocks] — this function seeds real rows; no mocks needed.
|
|
23
|
+
*/
|
|
24
|
+
import { AgentStore, TaxonomyStore, CompositionStore, } from '@adhd/agent-store-prompts';
|
|
25
|
+
import { AgentToolStore } from '@adhd/agent-store-tools';
|
|
26
|
+
import { AgentPolicyStore } from '@adhd/agent-core-policy';
|
|
27
|
+
// ── exported fixture constants ─────────────────────────────────────────────
|
|
28
|
+
/** Slug of the seeded fixture agent. */
|
|
29
|
+
export const FIXTURE_AGENT_SLUG = 'api-design-reviewer-e2e';
|
|
30
|
+
export const FIXTURE_CATEGORY_SLUG = 'e2e-api-specialists';
|
|
31
|
+
// Component slugs from the shared registry seed (SEED_DATA.md §8).
|
|
32
|
+
// These must exist after seedRegistry() has run against the same DB.
|
|
33
|
+
export const COMP_ROLE = 'generic-reviewer-role'; // position 1
|
|
34
|
+
export const COMP_IDENTITY = 'reviewer-identity'; // position 2
|
|
35
|
+
export const COMP_RULE = 'default-skeptic'; // position 3
|
|
36
|
+
export const COMP_REVIEW_CRITERIA = 'code-review-criteria'; // position 4 – general
|
|
37
|
+
export const COMP_SECURITY_CRITERIA = 'security-audit-criteria'; // position 5 – {ticket_type:security}
|
|
38
|
+
// Tool slugs granted to the fixture agent.
|
|
39
|
+
export const TOOL_FILE_READ = 'file_read';
|
|
40
|
+
export const TOOL_FILE_GREP = 'file_grep';
|
|
41
|
+
export const TOOL_WEB_SEARCH = 'web_search';
|
|
42
|
+
// ── seedFixtureAgent ───────────────────────────────────────────────────────
|
|
43
|
+
/**
|
|
44
|
+
* Seed the `api-design-reviewer-e2e` fixture agent into `db`.
|
|
45
|
+
*
|
|
46
|
+
* Prerequisites (caller must have already run against `db`):
|
|
47
|
+
* - All four package migrations applied.
|
|
48
|
+
* - seedRegistry(db) — for components (generic-reviewer-role etc.)
|
|
49
|
+
* - seedToolRegistry(db) — for tool catalog + platform bindings
|
|
50
|
+
* - seedProvider(db) — for model_platform_bindings (claude_sonnet_4_6)
|
|
51
|
+
* - seedPolicy(db) — for policy_policy_types + no-credentials template
|
|
52
|
+
*
|
|
53
|
+
* Idempotence: NOT idempotent — call once per test DB. Tests create a fresh
|
|
54
|
+
* temp file per suite so re-seed is never needed.
|
|
55
|
+
*
|
|
56
|
+
* @param db - The shared Drizzle handle (all four table prefixes).
|
|
57
|
+
*/
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
|
+
export function seedFixtureAgent(db) {
|
|
60
|
+
// ── 1. Taxonomy category ────────────────────────────────────────────────
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
62
|
+
const taxonomyStore = new TaxonomyStore(db);
|
|
63
|
+
taxonomyStore.createCategory({
|
|
64
|
+
slug: FIXTURE_CATEGORY_SLUG,
|
|
65
|
+
name: 'E2E API Specialists',
|
|
66
|
+
position: 99,
|
|
67
|
+
});
|
|
68
|
+
// ── 2. Agent (model_hint = claude_sonnet_4_6, per spec) ─────────────────
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
70
|
+
const agentStore = new AgentStore(db);
|
|
71
|
+
agentStore.create({
|
|
72
|
+
slug: FIXTURE_AGENT_SLUG,
|
|
73
|
+
displayName: 'API Design Reviewer (E2E Fixture)',
|
|
74
|
+
description: 'Reviews REST and GraphQL API designs for correctness, security, and usability',
|
|
75
|
+
modelHint: 'claude_sonnet_4_6',
|
|
76
|
+
taxonomyCategory: FIXTURE_CATEGORY_SLUG,
|
|
77
|
+
});
|
|
78
|
+
// ── 3. Junction rows — ORDERED, context-conditioned ([def:junction-order]) ─
|
|
79
|
+
//
|
|
80
|
+
// Position layout (mirrors SEED_DATA.md §14 code-reviewer):
|
|
81
|
+
// 1 generic-reviewer-role — always included (role)
|
|
82
|
+
// 2 reviewer-identity — always included (identity)
|
|
83
|
+
// 3 default-skeptic — always included (rule)
|
|
84
|
+
// 4 code-review-criteria — always included (success_criteria, general/review)
|
|
85
|
+
// 5 security-audit-criteria — {ticket_type:"security"} only (success_criteria)
|
|
86
|
+
//
|
|
87
|
+
// No version_pin on any row — resolve latest at compile time.
|
|
88
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
89
|
+
const compositionStore = new CompositionStore(db);
|
|
90
|
+
compositionStore.attach({
|
|
91
|
+
agentSlug: FIXTURE_AGENT_SLUG,
|
|
92
|
+
componentSlug: COMP_ROLE,
|
|
93
|
+
position: 1,
|
|
94
|
+
});
|
|
95
|
+
compositionStore.attach({
|
|
96
|
+
agentSlug: FIXTURE_AGENT_SLUG,
|
|
97
|
+
componentSlug: COMP_IDENTITY,
|
|
98
|
+
position: 2,
|
|
99
|
+
});
|
|
100
|
+
compositionStore.attach({
|
|
101
|
+
agentSlug: FIXTURE_AGENT_SLUG,
|
|
102
|
+
componentSlug: COMP_RULE,
|
|
103
|
+
position: 3,
|
|
104
|
+
});
|
|
105
|
+
// General success criteria — no context condition (always included).
|
|
106
|
+
// This is the "review" path: present when context is empty OR {ticket_type:"review"}.
|
|
107
|
+
compositionStore.attach({
|
|
108
|
+
agentSlug: FIXTURE_AGENT_SLUG,
|
|
109
|
+
componentSlug: COMP_REVIEW_CRITERIA,
|
|
110
|
+
position: 4,
|
|
111
|
+
contextCondition: null,
|
|
112
|
+
});
|
|
113
|
+
// Security success criteria — only included when {ticket_type:"security"}.
|
|
114
|
+
compositionStore.attach({
|
|
115
|
+
agentSlug: FIXTURE_AGENT_SLUG,
|
|
116
|
+
componentSlug: COMP_SECURITY_CRITERIA,
|
|
117
|
+
position: 5,
|
|
118
|
+
contextCondition: JSON.stringify({ ticket_type: 'security' }),
|
|
119
|
+
});
|
|
120
|
+
// ── 4. Tool grants (registry prefix — [up:tools]) ───────────────────────
|
|
121
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
122
|
+
const agentToolStore = new AgentToolStore(db);
|
|
123
|
+
agentToolStore.grant({
|
|
124
|
+
agentSlug: FIXTURE_AGENT_SLUG,
|
|
125
|
+
toolName: TOOL_FILE_READ,
|
|
126
|
+
permission: 'read_only',
|
|
127
|
+
});
|
|
128
|
+
agentToolStore.grant({
|
|
129
|
+
agentSlug: FIXTURE_AGENT_SLUG,
|
|
130
|
+
toolName: TOOL_FILE_GREP,
|
|
131
|
+
permission: 'read_only',
|
|
132
|
+
});
|
|
133
|
+
agentToolStore.grant({
|
|
134
|
+
agentSlug: FIXTURE_AGENT_SLUG,
|
|
135
|
+
toolName: TOOL_WEB_SEARCH,
|
|
136
|
+
permission: 'full',
|
|
137
|
+
});
|
|
138
|
+
// ── 5. Policy attachment — no-credentials (direct attach) ───────────────
|
|
139
|
+
// The policy template is in the seed data already (seedPolicy ran above).
|
|
140
|
+
// Direct attach: inheritedFrom = null ([def:policy-constraint]).
|
|
141
|
+
const agentPolicyStore = new AgentPolicyStore(db);
|
|
142
|
+
agentPolicyStore.attach({
|
|
143
|
+
agentSlug: FIXTURE_AGENT_SLUG,
|
|
144
|
+
policySlug: 'no-credentials',
|
|
145
|
+
isMandatory: true,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=fixtures.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixtures.js","sourceRoot":"","sources":["../../../src/seed/fixtures.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAIH,OAAO,EACL,UAAU,EACV,aAAa,EACb,gBAAgB,GACjB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,8EAA8E;AAE9E,wCAAwC;AACxC,MAAM,CAAC,MAAM,kBAAkB,GAAG,yBAAyB,CAAC;AAC5D,MAAM,CAAC,MAAM,qBAAqB,GAAG,qBAAqB,CAAC;AAE3D,mEAAmE;AAC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