@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
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ResolvedTool } from '../resolve/tools.js';
|
|
2
|
+
import type { Constraint } from '../resolve/policy.js';
|
|
3
|
+
/** Inputs to the yaml_frontmatter emitter. */
|
|
4
|
+
export interface YamlFrontmatterInput {
|
|
5
|
+
/** Agent slug — the `name:` frontmatter field. */
|
|
6
|
+
agentSlug: string;
|
|
7
|
+
/** Agent description — the `description:` frontmatter field. */
|
|
8
|
+
description: string;
|
|
9
|
+
/** Resolved platform tool aliases (e.g. ['Read', 'Grep', 'WebSearch']). */
|
|
10
|
+
tools: ResolvedTool[];
|
|
11
|
+
/** Resolved platform model alias (e.g. 'opus'), or '' when absent. */
|
|
12
|
+
model: string;
|
|
13
|
+
/**
|
|
14
|
+
* Body sections in junction order (ascending position), each being the
|
|
15
|
+
* raw content of one resolved component. Joined with '\n\n' between
|
|
16
|
+
* sections per Decision B.1.
|
|
17
|
+
*/
|
|
18
|
+
bodySections: string[];
|
|
19
|
+
/** Effective policy constraints (direct + inherited). */
|
|
20
|
+
constraints: Constraint[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Emit a claude_code `yaml_frontmatter` platform artifact.
|
|
24
|
+
*
|
|
25
|
+
* Returns a string that STARTS with `---` (the opening YAML fence), followed
|
|
26
|
+
* by the frozen field set, the closing fence, a blank line, then the composed
|
|
27
|
+
* markdown body (sections joined with '\n\n') with an appended `## Policies`
|
|
28
|
+
* block when policy constraints exist.
|
|
29
|
+
*
|
|
30
|
+
* @param input - Resolved compiler inputs; all fields already platform-shaped.
|
|
31
|
+
* @returns Flat markdown string ready to write to a `.md` file or emit to
|
|
32
|
+
* stdout as the claude_code system prompt.
|
|
33
|
+
*/
|
|
34
|
+
export declare function emitYamlFrontmatter(input: YamlFrontmatterInput): string;
|
|
35
|
+
//# sourceMappingURL=markdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../../../../../packages/agent/agent-engine-compiler/src/emit/markdown.ts"],"names":[],"mappings":"AAqCA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD,8CAA8C;AAC9C,MAAM,WAAW,oBAAoB;IACnC,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC;IAClB,gEAAgE;IAChE,WAAW,EAAE,MAAM,CAAC;IACpB,2EAA2E;IAC3E,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,sEAAsE;IACtE,KAAK,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,yDAAyD;IACzD,WAAW,EAAE,UAAU,EAAE,CAAC;CAC3B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,oBAAoB,GAAG,MAAM,CAkDvE"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// ──────────────────────────────────────────────
|
|
2
|
+
// yaml_frontmatter emitter (claude_code / header_format = 'yaml_frontmatter')
|
|
3
|
+
//
|
|
4
|
+
// Renders the YAML frontmatter block then the composed markdown body.
|
|
5
|
+
//
|
|
6
|
+
// Field set and ordering are FROZEN per Decision B.1 (decisions.md):
|
|
7
|
+
//
|
|
8
|
+
// ---
|
|
9
|
+
// name: <agent.slug>
|
|
10
|
+
// description: <agent.description>
|
|
11
|
+
// tools: <comma-joined resolved platform aliases, in agent_tools grant order>
|
|
12
|
+
// model: <resolved platform model alias>
|
|
13
|
+
// ---
|
|
14
|
+
//
|
|
15
|
+
// <body: resolveComposition sections joined in junction order, "\n\n" between>
|
|
16
|
+
//
|
|
17
|
+
// Rules:
|
|
18
|
+
// - `tools:` — comma-joined platformAlias values from resolveTools (never
|
|
19
|
+
// canonical names); OMITTED entirely when the resolved list is empty
|
|
20
|
+
// (Decision B.1: "no tools: line").
|
|
21
|
+
// - `model:` — OMITTED when resolveModel returns '' (no model_hint).
|
|
22
|
+
// - Policy constraints — rendered as a `## Policies` section APPENDED to the
|
|
23
|
+
// body (claude_code frontmatter has no policy field); the text is the
|
|
24
|
+
// resolved Constraint.text (template description). When there are no
|
|
25
|
+
// constraints, no section is added.
|
|
26
|
+
// - `description:` — sourced from the agent row's description; rendered as an
|
|
27
|
+
// empty string if the agent has no description (never omitted — Claude Code
|
|
28
|
+
// surfaces this field in the picker UI).
|
|
29
|
+
//
|
|
30
|
+
// [inv:platform-shaped-observable] — the consumer-visible observable is the
|
|
31
|
+
// frontmatter `tools:` line equalling the resolved aliases; a canonical-name
|
|
32
|
+
// leak makes the frontmatter.tools assertion go red.
|
|
33
|
+
//
|
|
34
|
+
// [def:junction-order] — sections emitted in the returned array order
|
|
35
|
+
// (ascending position), never re-sorted here.
|
|
36
|
+
// ──────────────────────────────────────────────
|
|
37
|
+
/**
|
|
38
|
+
* Emit a claude_code `yaml_frontmatter` platform artifact.
|
|
39
|
+
*
|
|
40
|
+
* Returns a string that STARTS with `---` (the opening YAML fence), followed
|
|
41
|
+
* by the frozen field set, the closing fence, a blank line, then the composed
|
|
42
|
+
* markdown body (sections joined with '\n\n') with an appended `## Policies`
|
|
43
|
+
* block when policy constraints exist.
|
|
44
|
+
*
|
|
45
|
+
* @param input - Resolved compiler inputs; all fields already platform-shaped.
|
|
46
|
+
* @returns Flat markdown string ready to write to a `.md` file or emit to
|
|
47
|
+
* stdout as the claude_code system prompt.
|
|
48
|
+
*/
|
|
49
|
+
export function emitYamlFrontmatter(input) {
|
|
50
|
+
const { agentSlug, description, tools, model, bodySections, constraints } = input;
|
|
51
|
+
// ── Frontmatter fields ────────────────────────────────────────────────────
|
|
52
|
+
const lines = ['---'];
|
|
53
|
+
lines.push(`name: ${agentSlug}`);
|
|
54
|
+
lines.push(`description: ${description}`);
|
|
55
|
+
// tools: — only emitted when there is at least one resolved alias.
|
|
56
|
+
// Decision B.1: "An agent with no grants emits no tools: line (NOT tools: empty)".
|
|
57
|
+
if (tools.length > 0) {
|
|
58
|
+
const aliasLine = tools.map((t) => t.platformAlias).join(', ');
|
|
59
|
+
lines.push(`tools: ${aliasLine}`);
|
|
60
|
+
}
|
|
61
|
+
// model: — omitted when model resolves to '' (no model_hint or no binding).
|
|
62
|
+
if (model) {
|
|
63
|
+
lines.push(`model: ${model}`);
|
|
64
|
+
}
|
|
65
|
+
lines.push('---');
|
|
66
|
+
// ── Body ──────────────────────────────────────────────────────────────────
|
|
67
|
+
// Sections joined with '\n\n' per Decision B.1.
|
|
68
|
+
// bodySections contains already-rendered component content in junction order
|
|
69
|
+
// — the compiler must NOT re-sort or re-filter here.
|
|
70
|
+
const bodyParts = [...bodySections];
|
|
71
|
+
// ── Policy block ──────────────────────────────────────────────────────────
|
|
72
|
+
// Constraints fold into the BODY (not frontmatter) for claude_code.
|
|
73
|
+
// Rendered as '## Policies' followed by bullet items.
|
|
74
|
+
// [def:policy-constraint], Decision B.1: "policy constraint block appended to the body"
|
|
75
|
+
if (constraints.length > 0) {
|
|
76
|
+
const policyLines = ['## Policies', ''];
|
|
77
|
+
for (const c of constraints) {
|
|
78
|
+
const prefix = c.inheritedFrom
|
|
79
|
+
? `(inherited from ${c.inheritedFrom}) `
|
|
80
|
+
: '';
|
|
81
|
+
policyLines.push(`- ${prefix}${c.text}`);
|
|
82
|
+
}
|
|
83
|
+
bodyParts.push(policyLines.join('\n'));
|
|
84
|
+
}
|
|
85
|
+
// Join sections with '\n\n' (Decision B.1).
|
|
86
|
+
const body = bodyParts.join('\n\n');
|
|
87
|
+
// Final artifact: frontmatter block + blank line + body.
|
|
88
|
+
return lines.join('\n') + '\n\n' + body + '\n';
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=markdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../../../../../packages/agent/agent-engine-compiler/src/emit/markdown.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,8EAA8E;AAC9E,EAAE;AACF,sEAAsE;AACtE,EAAE;AACF,qEAAqE;AACrE,EAAE;AACF,QAAQ;AACR,uBAAuB;AACvB,qCAAqC;AACrC,gFAAgF;AAChF,2CAA2C;AAC3C,QAAQ;AACR,EAAE;AACF,iFAAiF;AACjF,EAAE;AACF,SAAS;AACT,4EAA4E;AAC5E,yEAAyE;AACzE,wCAAwC;AACxC,uEAAuE;AACvE,+EAA+E;AAC/E,0EAA0E;AAC1E,0EAA0E;AAC1E,wCAAwC;AACxC,gFAAgF;AAChF,gFAAgF;AAChF,6CAA6C;AAC7C,EAAE;AACF,4EAA4E;AAC5E,6EAA6E;AAC7E,qDAAqD;AACrD,EAAE;AACF,sEAAsE;AACtE,8CAA8C;AAC9C,iDAAiD;AAyBjD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAA2B;IAC7D,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,GACvE,KAAK,CAAC;IAER,6EAA6E;IAC7E,MAAM,KAAK,GAAa,CAAC,KAAK,CAAC,CAAC;IAEhC,KAAK,CAAC,IAAI,CAAC,SAAS,SAAS,EAAE,CAAC,CAAC;IACjC,KAAK,CAAC,IAAI,CAAC,gBAAgB,WAAW,EAAE,CAAC,CAAC;IAE1C,mEAAmE;IACnE,mFAAmF;IACnF,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrB,MAAM,SAAS,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/D,KAAK,CAAC,IAAI,CAAC,UAAU,SAAS,EAAE,CAAC,CAAC;IACpC,CAAC;IAED,4EAA4E;IAC5E,IAAI,KAAK,EAAE,CAAC;QACV,KAAK,CAAC,IAAI,CAAC,UAAU,KAAK,EAAE,CAAC,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAElB,6EAA6E;IAC7E,gDAAgD;IAChD,6EAA6E;IAC7E,qDAAqD;IACrD,MAAM,SAAS,GAAa,CAAC,GAAG,YAAY,CAAC,CAAC;IAE9C,6EAA6E;IAC7E,oEAAoE;IACpE,sDAAsD;IACtD,wFAAwF;IACxF,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3B,MAAM,WAAW,GAAG,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;QACxC,KAAK,MAAM,CAAC,IAAI,WAAW,EAAE,CAAC;YAC5B,MAAM,MAAM,GAAG,CAAC,CAAC,aAAa;gBAC5B,CAAC,CAAC,mBAAmB,CAAC,CAAC,aAAa,IAAI;gBACxC,CAAC,CAAC,EAAE,CAAC;YACP,WAAW,CAAC,IAAI,CAAC,KAAK,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAC3C,CAAC;QACD,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACzC,CAAC;IAED,4CAA4C;IAC5C,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAEpC,yDAAyD;IACzD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;AACjD,CAAC"}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { sqlite, db } from './db/client.js';
|
|
2
|
+
export { runMigrations } from './db/migrate.js';
|
|
3
|
+
export { runMigrationsOn, MIGRATIONS_FOLDER } from './db/migrate-runner.js';
|
|
4
|
+
export * from './db/schema.js';
|
|
5
|
+
export { resolveBody } from './resolve/composition.js';
|
|
6
|
+
export type { ResolvedBody, ComponentVersionMap, } from './resolve/composition.js';
|
|
7
|
+
export { resolveTools } from './resolve/tools.js';
|
|
8
|
+
export type { ResolvedTool } from './resolve/tools.js';
|
|
9
|
+
export { resolveModel } from './resolve/model.js';
|
|
10
|
+
export { resolvePolicyConstraints } from './resolve/policy.js';
|
|
11
|
+
export type { Constraint } from './resolve/policy.js';
|
|
12
|
+
export { emitYamlFrontmatter } from './emit/markdown.js';
|
|
13
|
+
export type { YamlFrontmatterInput } from './emit/markdown.js';
|
|
14
|
+
export { emitJsonObject } from './emit/json.js';
|
|
15
|
+
export type { JsonObjectInput, StructuredTool } from './emit/json.js';
|
|
16
|
+
export { compileAgent } from './compile.js';
|
|
17
|
+
export type { CompileInput, CompiledAgent } from './compile.js';
|
|
18
|
+
export { lookup as cacheComposedPromptLookup, write as cacheComposedPromptWrite, computeContextHash, } from './cache/composed-prompt-cache.js';
|
|
19
|
+
export { seedFixtureAgent } from './seed/fixtures.js';
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/agent/agent-engine-compiler/src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC5E,cAAc,gBAAgB,CAAC;AAG/B,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,YAAY,EACV,YAAY,EACZ,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGvD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,YAAY,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,YAAY,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAGhE,OAAO,EACL,MAAM,IAAI,yBAAyB,EACnC,KAAK,IAAI,wBAAwB,EACjC,kBAAkB,GACnB,MAAM,kCAAkC,CAAC;AAG1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// @adhd/agent-engine-compiler — public barrel.
|
|
2
|
+
// Export each new store + schema table here as it is added (mirror the shipped
|
|
3
|
+
// registry packages: every state that adds a table also extends this barrel).
|
|
4
|
+
export { sqlite, db } from './db/client.js';
|
|
5
|
+
export { runMigrations } from './db/migrate.js';
|
|
6
|
+
export { runMigrationsOn, MIGRATIONS_FOLDER } from './db/migrate-runner.js';
|
|
7
|
+
export * from './db/schema.js';
|
|
8
|
+
// composition-resolve state: body assembly from agent-registry junction order
|
|
9
|
+
export { resolveBody } from './resolve/composition.js';
|
|
10
|
+
// tool-header-emit state: platform tool alias resolution from tool_platform_bindings
|
|
11
|
+
export { resolveTools } from './resolve/tools.js';
|
|
12
|
+
// model-and-policy-emit state: model alias + policy constraint resolution
|
|
13
|
+
export { resolveModel } from './resolve/model.js';
|
|
14
|
+
export { resolvePolicyConstraints } from './resolve/policy.js';
|
|
15
|
+
// platform-markdown-emit state: emit functions + top-level compileAgent orchestrator
|
|
16
|
+
export { emitYamlFrontmatter } from './emit/markdown.js';
|
|
17
|
+
export { emitJsonObject } from './emit/json.js';
|
|
18
|
+
export { compileAgent } from './compile.js';
|
|
19
|
+
// composed-prompt-caching state: cache lookup + write for registry_composed_prompts
|
|
20
|
+
export { lookup as cacheComposedPromptLookup, write as cacheComposedPromptWrite, computeContextHash, } from './cache/composed-prompt-cache.js';
|
|
21
|
+
// compile-fixtures-e2e state: real-row fixture seeder for e2e tests
|
|
22
|
+
export { seedFixtureAgent } from './seed/fixtures.js';
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/agent/agent-engine-compiler/src/index.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,+EAA+E;AAC/E,8EAA8E;AAE9E,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC5E,cAAc,gBAAgB,CAAC;AAE/B,8EAA8E;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAMvD,qFAAqF;AACrF,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,0EAA0E;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAG/D,qFAAqF;AACrF,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C,oFAAoF;AACpF,OAAO,EACL,MAAM,IAAI,yBAAyB,EACnC,KAAK,IAAI,wBAAwB,EACjC,kBAAkB,GACnB,MAAM,kCAAkC,CAAC;AAE1C,oEAAoE;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';
|
|
2
|
+
import { type CompositionContext } from '@adhd/agent-store-prompts';
|
|
3
|
+
/** Map of component slug to its resolved version number, used to key the cache. */
|
|
4
|
+
export type ComponentVersionMap = Record<string, number>;
|
|
5
|
+
/** Return value of resolveBody. */
|
|
6
|
+
export interface ResolvedBody {
|
|
7
|
+
/** Component content sections concatenated in ascending junction position order. */
|
|
8
|
+
body: string;
|
|
9
|
+
/** Map of componentSlug → resolvedVersion for cache-key computation. */
|
|
10
|
+
componentVersions: ComponentVersionMap;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Assemble the flat prompt body for an agent + runtime context.
|
|
14
|
+
*
|
|
15
|
+
* Delegates ordering, version-pin resolution, and context-condition filtering
|
|
16
|
+
* entirely to {@link CompositionStore.resolveComposition} — this function does
|
|
17
|
+
* NOT re-implement `ORDER BY position` or the context predicate evaluator.
|
|
18
|
+
*
|
|
19
|
+
* @param db - The shared registry Drizzle handle (all four prefixes).
|
|
20
|
+
* @param agentSlug - Slug of the agent to compile.
|
|
21
|
+
* @param context - Runtime context key/value map for context-conditioned components.
|
|
22
|
+
* @returns Flat ordered body string and per-component version map.
|
|
23
|
+
*
|
|
24
|
+
* @throws {CompositionError} AGENT_NOT_FOUND | COMPONENT_VERSION_NOT_FOUND |
|
|
25
|
+
* REQUIRED_COMPONENT_EXCLUDED — propagated unchanged from CompositionStore.
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveBody(db: BetterSQLite3Database<any>, agentSlug: string, context?: CompositionContext): ResolvedBody;
|
|
28
|
+
//# sourceMappingURL=composition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composition.d.ts","sourceRoot":"","sources":["../../../../../../packages/agent/agent-engine-compiler/src/resolve/composition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAExE,OAAO,EAEL,KAAK,kBAAkB,EACxB,MAAM,2BAA2B,CAAC;AAqBnC,mFAAmF;AACnF,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEzD,mCAAmC;AACnC,MAAM,WAAW,YAAY;IAC3B,oFAAoF;IACpF,IAAI,EAAE,MAAM,CAAC;IACb,wEAAwE;IACxE,iBAAiB,EAAE,mBAAmB,CAAC;CACxC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAEzB,EAAE,EAAE,qBAAqB,CAAC,GAAG,CAAC,EAC9B,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,kBAAuB,GAC/B,YAAY,CAiBd"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { CompositionStore, } from '@adhd/agent-store-prompts';
|
|
2
|
+
/**
|
|
3
|
+
* Assemble the flat prompt body for an agent + runtime context.
|
|
4
|
+
*
|
|
5
|
+
* Delegates ordering, version-pin resolution, and context-condition filtering
|
|
6
|
+
* entirely to {@link CompositionStore.resolveComposition} — this function does
|
|
7
|
+
* NOT re-implement `ORDER BY position` or the context predicate evaluator.
|
|
8
|
+
*
|
|
9
|
+
* @param db - The shared registry Drizzle handle (all four prefixes).
|
|
10
|
+
* @param agentSlug - Slug of the agent to compile.
|
|
11
|
+
* @param context - Runtime context key/value map for context-conditioned components.
|
|
12
|
+
* @returns Flat ordered body string and per-component version map.
|
|
13
|
+
*
|
|
14
|
+
* @throws {CompositionError} AGENT_NOT_FOUND | COMPONENT_VERSION_NOT_FOUND |
|
|
15
|
+
* REQUIRED_COMPONENT_EXCLUDED — propagated unchanged from CompositionStore.
|
|
16
|
+
*/
|
|
17
|
+
export function resolveBody(
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
|
+
db, agentSlug, context = {}) {
|
|
20
|
+
// Single delegated call — ordering + version-pin + context filtering happen
|
|
21
|
+
// here and nowhere else ([inv:context-precedence-consumed]).
|
|
22
|
+
const store = new CompositionStore(db);
|
|
23
|
+
const resolved = store.resolveComposition(agentSlug, context);
|
|
24
|
+
const componentVersions = {};
|
|
25
|
+
const sections = [];
|
|
26
|
+
for (const rc of resolved) {
|
|
27
|
+
sections.push(rc.component.content);
|
|
28
|
+
componentVersions[rc.componentSlug] = rc.resolvedVersion;
|
|
29
|
+
}
|
|
30
|
+
const body = sections.join('\n');
|
|
31
|
+
return { body, componentVersions };
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=composition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composition.js","sourceRoot":"","sources":["../../../../../../packages/agent/agent-engine-compiler/src/resolve/composition.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,gBAAgB,GAEjB,MAAM,2BAA2B,CAAC;AAgCnC;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,WAAW;AACzB,8DAA8D;AAC9D,EAA8B,EAC9B,SAAiB,EACjB,UAA8B,EAAE;IAEhC,4EAA4E;IAC5E,6DAA6D;IAC7D,MAAM,KAAK,GAAG,IAAI,gBAAgB,CAAC,EAAE,CAAC,CAAC;IACvC,MAAM,QAAQ,GAAG,KAAK,CAAC,kBAAkB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAE9D,MAAM,iBAAiB,GAAwB,EAAE,CAAC;IAClD,MAAM,QAAQ,GAAa,EAAE,CAAC;IAE9B,KAAK,MAAM,EAAE,IAAI,QAAQ,EAAE,CAAC;QAC1B,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QACpC,iBAAiB,CAAC,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC,eAAe,CAAC;IAC3D,CAAC;IAED,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEjC,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';
|
|
2
|
+
/**
|
|
3
|
+
* Resolve an agent's `model_hint` to the platform-specific model string.
|
|
4
|
+
*
|
|
5
|
+
* Algorithm:
|
|
6
|
+
* 1. `AgentStore.read(agentSlug)` — fetch the agent row (includes `model_hint`).
|
|
7
|
+
* 2. If `model_hint` is null/empty → return `''` (caller omits `model:` line).
|
|
8
|
+
* 3. `ModelStore.resolveModelId(modelHint, platform)` — reuse the provider's
|
|
9
|
+
* binding lookup; the platform filter is applied in ModelStore, not here.
|
|
10
|
+
* 4. If no binding row exists → fall back to the canonical id and mark the decision
|
|
11
|
+
* (see fallback note below).
|
|
12
|
+
*
|
|
13
|
+
* The platform filter is the [dod.2] negative-control invariant: if ModelStore were
|
|
14
|
+
* called without the platform argument, both platforms would resolve to the same id.
|
|
15
|
+
*
|
|
16
|
+
* @param db - The shared registry Drizzle handle (all table prefixes).
|
|
17
|
+
* @param agentSlug - Slug of the agent whose model to resolve.
|
|
18
|
+
* @param platform - Target platform id (e.g. 'claude_code', 'claude_api').
|
|
19
|
+
* @returns Platform-specific model string, or '' if the agent has no model_hint.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveModel(db: BetterSQLite3Database<any>, agentSlug: string, platform: string): string;
|
|
22
|
+
//# sourceMappingURL=model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../../../../packages/agent/agent-engine-compiler/src/resolve/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAwBxE;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAE1B,EAAE,EAAE,qBAAqB,CAAC,GAAG,CAAC,EAC9B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,MAAM,CA8BR"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { AgentStore } from '@adhd/agent-store-prompts';
|
|
2
|
+
import { ModelStore, ModelStoreError } from '@adhd/agent-core-provider';
|
|
3
|
+
// ──────────────────────────────────────────────
|
|
4
|
+
// resolveModel — resolve an agent's model_hint to a platform-specific model id.
|
|
5
|
+
//
|
|
6
|
+
// Reads the agent's `model_hint` from `registry_agents` via AgentStore.read, then
|
|
7
|
+
// calls ModelStore.resolveModelId(modelHint, platform) to look up the binding row
|
|
8
|
+
// in `provider_model_platform_bindings` for the target platform.
|
|
9
|
+
//
|
|
10
|
+
// Reuses ModelStore.resolveModelId ([ref:store-read]); does NOT re-implement the
|
|
11
|
+
// SQL join or the platform filter. The platform filter (`WHERE platform = ?`) lives
|
|
12
|
+
// exclusively in ModelStore — removing it collapses both platforms to the first
|
|
13
|
+
// binding row, which is the [dod.2] negative-control scenario.
|
|
14
|
+
//
|
|
15
|
+
// Fallback: if the agent has a model_hint but no binding exists for the (hint,
|
|
16
|
+
// platform) pair, the canonical model id (the model_hint itself) is returned and the
|
|
17
|
+
// decision is recorded in decisions.md. If the agent has no model_hint, an empty
|
|
18
|
+
// string is returned (callers must handle the "no model" case — Decision B of
|
|
19
|
+
// decisions.md says the `model:` frontmatter line is OMITTED when model_hint is null).
|
|
20
|
+
// ──────────────────────────────────────────────
|
|
21
|
+
/**
|
|
22
|
+
* Resolve an agent's `model_hint` to the platform-specific model string.
|
|
23
|
+
*
|
|
24
|
+
* Algorithm:
|
|
25
|
+
* 1. `AgentStore.read(agentSlug)` — fetch the agent row (includes `model_hint`).
|
|
26
|
+
* 2. If `model_hint` is null/empty → return `''` (caller omits `model:` line).
|
|
27
|
+
* 3. `ModelStore.resolveModelId(modelHint, platform)` — reuse the provider's
|
|
28
|
+
* binding lookup; the platform filter is applied in ModelStore, not here.
|
|
29
|
+
* 4. If no binding row exists → fall back to the canonical id and mark the decision
|
|
30
|
+
* (see fallback note below).
|
|
31
|
+
*
|
|
32
|
+
* The platform filter is the [dod.2] negative-control invariant: if ModelStore were
|
|
33
|
+
* called without the platform argument, both platforms would resolve to the same id.
|
|
34
|
+
*
|
|
35
|
+
* @param db - The shared registry Drizzle handle (all table prefixes).
|
|
36
|
+
* @param agentSlug - Slug of the agent whose model to resolve.
|
|
37
|
+
* @param platform - Target platform id (e.g. 'claude_code', 'claude_api').
|
|
38
|
+
* @returns Platform-specific model string, or '' if the agent has no model_hint.
|
|
39
|
+
*/
|
|
40
|
+
export function resolveModel(
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
|
+
db, agentSlug, platform) {
|
|
43
|
+
// Step 1: fetch agent to get model_hint.
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
|
+
const agentStore = new AgentStore(db);
|
|
46
|
+
const agent = agentStore.read(agentSlug);
|
|
47
|
+
const modelHint = agent.modelHint;
|
|
48
|
+
// Step 2: no model_hint — caller omits the model: frontmatter line (Decision B).
|
|
49
|
+
if (!modelHint) {
|
|
50
|
+
return '';
|
|
51
|
+
}
|
|
52
|
+
// Step 3: resolve via ModelStore — the platform filter lives here, not in resolveModel.
|
|
53
|
+
const modelStore = new ModelStore(db);
|
|
54
|
+
try {
|
|
55
|
+
return modelStore.resolveModelId(modelHint, platform);
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
if (err instanceof ModelStoreError &&
|
|
59
|
+
err.code === 'MODEL_BINDING_NOT_FOUND') {
|
|
60
|
+
// Step 4: no binding for (modelHint, platform) — fall back to canonical id.
|
|
61
|
+
// Decision: fallback recorded in docs/plan/agent-compiler/decisions.md.
|
|
62
|
+
// The caller still gets a usable (if un-aliased) string; the compile does not
|
|
63
|
+
// fail for a missing binding.
|
|
64
|
+
return modelHint;
|
|
65
|
+
}
|
|
66
|
+
throw err;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../../../../../packages/agent/agent-engine-compiler/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":["../../../../../../packages/agent/agent-engine-compiler/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":["../../../../../../packages/agent/agent-engine-compiler/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":["../../../../../../packages/agent/agent-engine-compiler/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":["../../../../../../packages/agent/agent-engine-compiler/src/resolve/tools.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,cAAc,EACd,YAAY,GAEb,MAAM,yBAAyB,CAAC;AAoCjC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,YAAY;AAC1B,8DAA8D;AAC9D,EAA8B,EAC9B,SAAiB,EACjB,QAAgB;IAEhB,MAAM,cAAc,GAAG,IAAI,cAAc,CAAC,EAAE,CAAC,CAAC;IAC9C,MAAM,YAAY,GAAG,IAAI,YAAY,CAAC,EAAE,CAAC,CAAC;IAE1C,6EAA6E;IAC7E,MAAM,MAAM,GAAG,cAAc,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;IAEtD,6EAA6E;IAC7E,yEAAyE;IACzE,MAAM,gBAAgB,GACpB,YAAY,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;IAEzC,kEAAkE;IAClE,gFAAgF;IAChF,MAAM,aAAa,GAAG,IAAI,GAAG,CAC3B,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAC7C,CAAC;IAEF,6EAA6E;IAC7E,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,MAAM,OAAO,GAAmB,EAAE,CAAC;IAEnC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC7B,SAAS,CAAC,uEAAuE;QACnF,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAEzB,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAElD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,iEAAiE;YACjE,SAAS;QACX,CAAC;QAED,IAAI,OAAO,CAAC,YAAY,KAAK,aAAa,EAAE,CAAC;YAC3C,4EAA4E;YAC5E,gDAAgD;YAChD,SAAS;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":["../../../../../../packages/agent/agent-engine-compiler/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"}
|