@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":"compile.js","sourceRoot":"","sources":["../../src/compile.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,sCAAsC;AACtC,EAAE;AACF,2EAA2E;AAC3E,uEAAuE;AACvE,6BAA6B;AAC7B,EAAE;AACF,qEAAqE;AACrE,qCAAqC;AACrC,EAAE;AACF,uDAAuD;AACvD,yEAAyE;AACzE,2DAA2D;AAC3D,EAAE;AACF,yEAAyE;AACzE,kEAAkE;AAClE,8CAA8C;AAC9C,EAAE;AACF,8EAA8E;AAC9E,sEAAsE;AACtE,uEAAuE;AACvE,sFAAsF;AACtF,2EAA2E;AAC3E,8EAA8E;AAC9E,mBAAmB;AACnB,EAAE;AACF,4DAA4D;AAC5D,kEAAkE;AAClE,4EAA4E;AAC5E,wEAAwE;AACxE,4CAA4C;AAC5C,iDAAiD;AAIjD,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAEzE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAGlF,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC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E,EACF,SAAS,EACT,QAAQ,EACR,OAAO,EACP,iBAAiB,EACjB,OAAO,CACR,CAAC;QACF,OAAO,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,CAAC;IAC7E,CAAC;IAED,6EAA6E;IAC7E,+DAA+D;IAC/D,MAAM,SAAS,GAAa,CAAC,GAAG,YAAY,CAAC,CAAC;IAC9C,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;IACD,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IAE9C,2EAA2E;IAC3E,MAAM,OAAO,GAAG,MAAM,CACpB,EAAE,EACF,SAAS,EACT,QAAQ,EACR,OAAO,EACP,iBAAiB,EACjB,OAAO,CACR,CAAC;IACF,OAAO,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,iBAAiB,EAAE,CAAC;AACnE,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { migrate } from 'drizzle-orm/better-sqlite3/migrator';
|
|
2
|
+
/**
|
|
3
|
+
* Folder holding the drizzle-kit generated migrations (../../drizzle relative
|
|
4
|
+
* to this compiled module). Kept here — with no `client.js` import — so test
|
|
5
|
+
* harnesses can reuse the FK-safe runner without dragging in the production
|
|
6
|
+
* singleton connection (which opens a DB file at import time).
|
|
7
|
+
*/
|
|
8
|
+
export declare const MIGRATIONS_FOLDER: string;
|
|
9
|
+
/**
|
|
10
|
+
* Minimal structural type for the bits of a better-sqlite3 connection we need.
|
|
11
|
+
* Avoids importing the better-sqlite3 type just to call `pragma`.
|
|
12
|
+
*/
|
|
13
|
+
interface PragmaConn {
|
|
14
|
+
pragma(source: string, options?: {
|
|
15
|
+
simple: boolean;
|
|
16
|
+
}): unknown;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Run Drizzle migrations against an explicit connection with foreign-key
|
|
20
|
+
* enforcement disabled for the duration of the run.
|
|
21
|
+
*
|
|
22
|
+
* WHY: SQLite ignores `PRAGMA foreign_keys` inside a transaction, and drizzle's
|
|
23
|
+
* migrator wraps each migration file in one. Table-recreate migrations (ALTER
|
|
24
|
+
* TABLE via CREATE-INSERT-DROP-RENAME) fire ON DELETE CASCADE when FK enforcement
|
|
25
|
+
* is ON, wiping child rows. Disabling on the connection *before* migrate() —
|
|
26
|
+
* while no transaction is open — is the only way to make it hold for the whole
|
|
27
|
+
* run; we restore the prior setting afterwards.
|
|
28
|
+
*/
|
|
29
|
+
export declare function runMigrationsOn(conn: PragmaConn, drizzleDb: Parameters<typeof migrate>[0], migrationsFolder?: string): void;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=migrate-runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate-runner.d.ts","sourceRoot":"","sources":["../../../src/db/migrate-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qCAAqC,CAAC;AAE9D;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,QACnB,CAAC;AAEZ;;;GAGG;AACH,UAAU,UAAU;IAClB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC;CAChE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,UAAU,EAChB,SAAS,EAAE,UAAU,CAAC,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC,EACxC,gBAAgB,GAAE,MAA0B,GAC3C,IAAI,CAcN"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { migrate } from 'drizzle-orm/better-sqlite3/migrator';
|
|
2
|
+
/**
|
|
3
|
+
* Folder holding the drizzle-kit generated migrations (../../drizzle relative
|
|
4
|
+
* to this compiled module). Kept here — with no `client.js` import — so test
|
|
5
|
+
* harnesses can reuse the FK-safe runner without dragging in the production
|
|
6
|
+
* singleton connection (which opens a DB file at import time).
|
|
7
|
+
*/
|
|
8
|
+
export const MIGRATIONS_FOLDER = new URL('../../drizzle', import.meta.url)
|
|
9
|
+
.pathname;
|
|
10
|
+
/**
|
|
11
|
+
* Run Drizzle migrations against an explicit connection with foreign-key
|
|
12
|
+
* enforcement disabled for the duration of the run.
|
|
13
|
+
*
|
|
14
|
+
* WHY: SQLite ignores `PRAGMA foreign_keys` inside a transaction, and drizzle's
|
|
15
|
+
* migrator wraps each migration file in one. Table-recreate migrations (ALTER
|
|
16
|
+
* TABLE via CREATE-INSERT-DROP-RENAME) fire ON DELETE CASCADE when FK enforcement
|
|
17
|
+
* is ON, wiping child rows. Disabling on the connection *before* migrate() —
|
|
18
|
+
* while no transaction is open — is the only way to make it hold for the whole
|
|
19
|
+
* run; we restore the prior setting afterwards.
|
|
20
|
+
*/
|
|
21
|
+
export function runMigrationsOn(conn, drizzleDb, migrationsFolder = MIGRATIONS_FOLDER) {
|
|
22
|
+
const fkWasOn = conn.pragma('foreign_keys', { simple: true }) === 1;
|
|
23
|
+
if (fkWasOn) {
|
|
24
|
+
conn.pragma('foreign_keys = OFF');
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
migrate(drizzleDb, { migrationsFolder });
|
|
28
|
+
}
|
|
29
|
+
finally {
|
|
30
|
+
if (fkWasOn) {
|
|
31
|
+
conn.pragma('foreign_keys = ON');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=migrate-runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate-runner.js","sourceRoot":"","sources":["../../../src/db/migrate-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qCAAqC,CAAC;AAE9D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC,eAAe,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;KACvE,QAAQ,CAAC;AAUZ;;;;;;;;;;GAUG;AACH,MAAM,UAAU,eAAe,CAC7B,IAAgB,EAChB,SAAwC,EACxC,mBAA2B,iBAAiB;IAE5C,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC;IAEpE,IAAI,OAAO,EAAE,CAAC;QACZ,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;IACpC,CAAC;IAED,IAAI,CAAC;QACH,OAAO,CAAC,SAAS,EAAE,EAAE,gBAAgB,EAAE,CAAC,CAAC;IAC3C,CAAC;YAAS,CAAC;QACT,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/db/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,OAAO,EACP,UAAU,EACV,WAAW,EACX,IAAI,EACJ,WAAW,EACZ,MAAM,yBAAyB,CAAC;AAuBjC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC"}
|
package/src/db/schema.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { index, integer, primaryKey, sqliteTable, text, uniqueIndex, } from 'drizzle-orm/sqlite-core';
|
|
2
|
+
// ──────────────────────────────────────────────
|
|
3
|
+
// @adhd/agent-engine-compiler — table prefix: compiler_
|
|
4
|
+
//
|
|
5
|
+
// Every table in THIS package MUST be named with the `compiler_` prefix.
|
|
6
|
+
// All registry-family packages share ONE SQLite file, so the prefix is the only
|
|
7
|
+
// thing preventing cross-package table-name collisions. See REGISTRY-PACKAGE-RULES.md.
|
|
8
|
+
//
|
|
9
|
+
// Invariants enforced here (do not break them):
|
|
10
|
+
// • Cross-package keys are LOGICAL ONLY — plain text columns, no .references()
|
|
11
|
+
// across package prefixes. In-package FKs use .references() normally.
|
|
12
|
+
// • Controlled vocabularies are lookup tables (text PK) or plain text columns,
|
|
13
|
+
// NEVER SQL enums — a new value is a new row, no migration.
|
|
14
|
+
// • Composite PKs use `primaryKey({ columns: [...] })`, never a non-unique index().
|
|
15
|
+
// • Bump-don't-delete: if you retain versions, never delete a prior version row.
|
|
16
|
+
//
|
|
17
|
+
// The drizzle-orm/sqlite-core helpers are re-exported so a downstream module can
|
|
18
|
+
// `import { sqliteTable, text } from "@adhd/agent-engine-compiler"` without re-importing the
|
|
19
|
+
// dependency directly, and so this skeleton's import is exercised before any table
|
|
20
|
+
// exists. Define real tables here and add them to the barrel in ../index.ts.
|
|
21
|
+
// ──────────────────────────────────────────────
|
|
22
|
+
export { index, integer, primaryKey, sqliteTable, text, uniqueIndex };
|
|
23
|
+
// Example (delete this comment, add real tables prefixed `compiler_`):
|
|
24
|
+
//
|
|
25
|
+
// export const exampleTable = sqliteTable("compiler_example", {
|
|
26
|
+
// slug: text("slug").primaryKey(),
|
|
27
|
+
// label: text("label").notNull(),
|
|
28
|
+
// createdAt: text("created_at").notNull(),
|
|
29
|
+
// });
|
|
30
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/db/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,OAAO,EACP,UAAU,EACV,WAAW,EACX,IAAI,EACJ,WAAW,GACZ,MAAM,yBAAyB,CAAC;AAEjC,iDAAiD;AACjD,wDAAwD;AACxD,EAAE;AACF,yEAAyE;AACzE,gFAAgF;AAChF,uFAAuF;AACvF,EAAE;AACF,gDAAgD;AAChD,iFAAiF;AACjF,0EAA0E;AAC1E,iFAAiF;AACjF,gEAAgE;AAChE,sFAAsF;AACtF,mFAAmF;AACnF,EAAE;AACF,iFAAiF;AACjF,6FAA6F;AAC7F,mFAAmF;AACnF,6EAA6E;AAC7E,iDAAiD;AAEjD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;AAEtE,uEAAuE;AACvE,EAAE;AACF,gEAAgE;AAChE,uCAAuC;AACvC,sCAAsC;AACtC,+CAA+C;AAC/C,MAAM"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ResolvedTool } from '../resolve/tools.js';
|
|
2
|
+
import type { Constraint } from '../resolve/policy.js';
|
|
3
|
+
/**
|
|
4
|
+
* A structured tool entry in the json_object output.
|
|
5
|
+
*
|
|
6
|
+
* For claude_api / openai this mirrors the standard `{name, description,
|
|
7
|
+
* input_schema}` custom tool shape. Server-side type-tagged tools are
|
|
8
|
+
* emitted with the `{type, name}` shape (no input_schema).
|
|
9
|
+
*
|
|
10
|
+
* The compile layer passes the already-shaped objects from emitToolsForProvider
|
|
11
|
+
* directly — this type covers both discriminated variants.
|
|
12
|
+
*/
|
|
13
|
+
export type StructuredTool = Record<string, unknown>;
|
|
14
|
+
/** Inputs to the json_object emitter. */
|
|
15
|
+
export interface JsonObjectInput {
|
|
16
|
+
/** Agent slug — the `name` key. */
|
|
17
|
+
agentSlug: string;
|
|
18
|
+
/**
|
|
19
|
+
* Body sections in junction order (ascending position), each the raw content
|
|
20
|
+
* of one resolved component. Joined with '\n\n' to form systemPrompt,
|
|
21
|
+
* with the policy block appended (Decision B.2).
|
|
22
|
+
*/
|
|
23
|
+
bodySections: string[];
|
|
24
|
+
/** Effective policy constraints (direct + inherited). */
|
|
25
|
+
constraints: Constraint[];
|
|
26
|
+
/**
|
|
27
|
+
* Resolved platform tools — passed through from resolveTools; used here only
|
|
28
|
+
* to confirm 'unavailable' tools are already absent. The STRUCTURED array
|
|
29
|
+
* passed to `tools` is the caller-supplied `structuredTools`.
|
|
30
|
+
*/
|
|
31
|
+
tools: ResolvedTool[];
|
|
32
|
+
/**
|
|
33
|
+
* Pre-shaped structured tool array produced by emitToolsForProvider (or the
|
|
34
|
+
* compile layer's equivalent). This is what lands in `tools` in the JSON.
|
|
35
|
+
*/
|
|
36
|
+
structuredTools: StructuredTool[];
|
|
37
|
+
/** Resolved full platform model id (e.g. 'claude-sonnet-4-6'), or '' if absent. */
|
|
38
|
+
model: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Emit a `json_object` platform artifact for claude_api / openai / bedrock.
|
|
42
|
+
*
|
|
43
|
+
* Returns a JSON STRING (`content = JSON.stringify(...)`) — callers must not
|
|
44
|
+
* wrap it further. The object shape is frozen per Decision B.2.
|
|
45
|
+
*
|
|
46
|
+
* @param input - Resolved compiler inputs; all fields already platform-shaped.
|
|
47
|
+
* @returns JSON string ready to pass as the API system prompt payload.
|
|
48
|
+
*/
|
|
49
|
+
export declare function emitJsonObject(input: JsonObjectInput): string;
|
|
50
|
+
//# sourceMappingURL=json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../../src/emit/json.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAMvD;;;;;;;;;GASG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAErD,yCAAyC;AACzC,MAAM,WAAW,eAAe;IAC9B,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,yDAAyD;IACzD,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B;;;;OAIG;IACH,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB;;;OAGG;IACH,eAAe,EAAE,cAAc,EAAE,CAAC;IAClC,mFAAmF;IACnF,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,CAuC7D"}
|
package/src/emit/json.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// ──────────────────────────────────────────────
|
|
2
|
+
// json_object emitter (claude_api / openai / bedrock — header_format = 'json_object')
|
|
3
|
+
//
|
|
4
|
+
// Emits a JSON STRING (content = JSON.stringify(...)) — NOT YAML, no '---'.
|
|
5
|
+
//
|
|
6
|
+
// Shape per Decision B.2 (decisions.md):
|
|
7
|
+
//
|
|
8
|
+
// {
|
|
9
|
+
// "name": "<agent.slug>",
|
|
10
|
+
// "systemPrompt": "<flat body: composed sections + policy block, joined '\n\n'>",
|
|
11
|
+
// "model": "<resolveModelId(model_hint, platform)>", // full id
|
|
12
|
+
// "tools": [ /* structured tool array (EmittedTool[]) */ ]
|
|
13
|
+
// }
|
|
14
|
+
//
|
|
15
|
+
// Rules:
|
|
16
|
+
// - `systemPrompt` is the FLAT body (same composed sections as yaml_frontmatter,
|
|
17
|
+
// minus the YAML header; policy constraints folded into the prompt text).
|
|
18
|
+
// - `tools` is a STRUCTURED ARRAY via EmittedTool (from agent-provider's
|
|
19
|
+
// emitToolsForProvider), NOT a comma string.
|
|
20
|
+
// - `model` resolves to the FULL platform id (e.g. 'claude-sonnet-4-6'),
|
|
21
|
+
// distinct from the claude_code alias.
|
|
22
|
+
// - Tools whose platform binding is 'unavailable' are omitted by resolveTools
|
|
23
|
+
// before they reach this emitter — this function does NOT re-filter.
|
|
24
|
+
//
|
|
25
|
+
// [dod.7] audit greps for 'json_object' + 'JSON.stringify' + 'systemPrompt' —
|
|
26
|
+
// all three tokens are present in this file.
|
|
27
|
+
// ──────────────────────────────────────────────
|
|
28
|
+
/**
|
|
29
|
+
* Emit a `json_object` platform artifact for claude_api / openai / bedrock.
|
|
30
|
+
*
|
|
31
|
+
* Returns a JSON STRING (`content = JSON.stringify(...)`) — callers must not
|
|
32
|
+
* wrap it further. The object shape is frozen per Decision B.2.
|
|
33
|
+
*
|
|
34
|
+
* @param input - Resolved compiler inputs; all fields already platform-shaped.
|
|
35
|
+
* @returns JSON string ready to pass as the API system prompt payload.
|
|
36
|
+
*/
|
|
37
|
+
export function emitJsonObject(input) {
|
|
38
|
+
const { agentSlug, bodySections, constraints, structuredTools, model } = input;
|
|
39
|
+
// ── systemPrompt: flat body with policy block folded in ──────────────────
|
|
40
|
+
// Same composition logic as yaml_frontmatter body — sections '\n\n'-joined,
|
|
41
|
+
// policy constraints appended as text (Decision B.2).
|
|
42
|
+
const bodyParts = [...bodySections];
|
|
43
|
+
if (constraints.length > 0) {
|
|
44
|
+
const policyLines = ['## Policies', ''];
|
|
45
|
+
for (const c of constraints) {
|
|
46
|
+
const prefix = c.inheritedFrom
|
|
47
|
+
? `(inherited from ${c.inheritedFrom}) `
|
|
48
|
+
: '';
|
|
49
|
+
policyLines.push(`- ${prefix}${c.text}`);
|
|
50
|
+
}
|
|
51
|
+
bodyParts.push(policyLines.join('\n'));
|
|
52
|
+
}
|
|
53
|
+
const systemPrompt = bodyParts.join('\n\n');
|
|
54
|
+
// ── Assemble the JSON payload ─────────────────────────────────────────────
|
|
55
|
+
// Field order: name → systemPrompt → model → tools.
|
|
56
|
+
// `model` key is always present (empty string when no model_hint).
|
|
57
|
+
const payload = {
|
|
58
|
+
name: agentSlug,
|
|
59
|
+
systemPrompt,
|
|
60
|
+
model,
|
|
61
|
+
tools: structuredTools,
|
|
62
|
+
};
|
|
63
|
+
// json_object format: JSON.stringify the payload (Decision B.2).
|
|
64
|
+
return JSON.stringify(payload);
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../../src/emit/json.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,sFAAsF;AACtF,EAAE;AACF,4EAA4E;AAC5E,EAAE;AACF,yCAAyC;AACzC,EAAE;AACF,MAAM;AACN,sCAAsC;AACtC,sFAAsF;AACtF,6EAA6E;AAC7E,sEAAsE;AACtE,MAAM;AACN,EAAE;AACF,SAAS;AACT,mFAAmF;AACnF,8EAA8E;AAC9E,2EAA2E;AAC3E,iDAAiD;AACjD,2EAA2E;AAC3E,2CAA2C;AAC3C,gFAAgF;AAChF,yEAAyE;AACzE,EAAE;AACF,8EAA8E;AAC9E,6CAA6C;AAC7C,iDAAiD;AAgDjD;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAAC,KAAsB;IACnD,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,KAAK,EAAE,GACpE,KAAK,CAAC;IAER,4EAA4E;IAC5E,4EAA4E;IAC5E,sDAAsD;IACtD,MAAM,SAAS,GAAa,CAAC,GAAG,YAAY,CAAC,CAAC;IAE9C,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,MAAM,YAAY,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE5C,6EAA6E;IAC7E,oDAAoD;IACpD,mEAAmE;IACnE,MAAM,OAAO,GAKT;QACF,IAAI,EAAE,SAAS;QACf,YAAY;QACZ,KAAK;QACL,KAAK,EAAE,eAAe;KACvB,CAAC;IAEF,iEAAiE;IACjE,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -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":["../../../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":["../../../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;I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C,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,18 @@
|
|
|
1
|
+
export { runMigrationsOn, MIGRATIONS_FOLDER } from './db/migrate-runner.js';
|
|
2
|
+
export * from './db/schema.js';
|
|
3
|
+
export { resolveBody } from './resolve/composition.js';
|
|
4
|
+
export type { ResolvedBody, ComponentVersionMap, } from './resolve/composition.js';
|
|
5
|
+
export { resolveTools } from './resolve/tools.js';
|
|
6
|
+
export type { ResolvedTool } from './resolve/tools.js';
|
|
7
|
+
export { resolveModel } from './resolve/model.js';
|
|
8
|
+
export { resolvePolicyConstraints } from './resolve/policy.js';
|
|
9
|
+
export type { Constraint } from './resolve/policy.js';
|
|
10
|
+
export { emitYamlFrontmatter } from './emit/markdown.js';
|
|
11
|
+
export type { YamlFrontmatterInput } from './emit/markdown.js';
|
|
12
|
+
export { emitJsonObject } from './emit/json.js';
|
|
13
|
+
export type { JsonObjectInput, StructuredTool } from './emit/json.js';
|
|
14
|
+
export { compileAgent } from './compile.js';
|
|
15
|
+
export type { CompileInput, CompiledAgent } from './compile.js';
|
|
16
|
+
export { lookup as cacheComposedPromptLookup, write as cacheComposedPromptWrite, computeContextHash, } from './cache/composed-prompt-cache.js';
|
|
17
|
+
export { seedFixtureAgent } from './seed/fixtures.js';
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAIA,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,21 @@
|
|
|
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 { runMigrationsOn, MIGRATIONS_FOLDER } from './db/migrate-runner.js';
|
|
5
|
+
export * from './db/schema.js';
|
|
6
|
+
// composition-resolve state: body assembly from agent-registry junction order
|
|
7
|
+
export { resolveBody } from './resolve/composition.js';
|
|
8
|
+
// tool-header-emit state: platform tool alias resolution from tool_platform_bindings
|
|
9
|
+
export { resolveTools } from './resolve/tools.js';
|
|
10
|
+
// model-and-policy-emit state: model alias + policy constraint resolution
|
|
11
|
+
export { resolveModel } from './resolve/model.js';
|
|
12
|
+
export { resolvePolicyConstraints } from './resolve/policy.js';
|
|
13
|
+
// platform-markdown-emit state: emit functions + top-level compileAgent orchestrator
|
|
14
|
+
export { emitYamlFrontmatter } from './emit/markdown.js';
|
|
15
|
+
export { emitJsonObject } from './emit/json.js';
|
|
16
|
+
export { compileAgent } from './compile.js';
|
|
17
|
+
// composed-prompt-caching state: cache lookup + write for registry_composed_prompts
|
|
18
|
+
export { lookup as cacheComposedPromptLookup, write as cacheComposedPromptWrite, computeContextHash, } from './cache/composed-prompt-cache.js';
|
|
19
|
+
// compile-fixtures-e2e state: real-row fixture seeder for e2e tests
|
|
20
|
+
export { seedFixtureAgent } from './seed/fixtures.js';
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,+EAA+E;AAC/E,8EAA8E;AAE9E,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":["../../../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":["../../../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":["../../../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
|