@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
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
## 2.1.10 (2026-07-26)
|
|
2
|
+
|
|
3
|
+
Re-publish fixing 2.1.9's own defects: an unsatisfiable `@adhd/agent-store-tools: ^2.1.9` dependency range (captured during a transient phantom-version-bump window on agent-store-tools that was later reverted — the real max published is 2.1.8) and a missing `README.md` in the published tarball (BUG-BUILD-ASSETS-CACHE-STALE-AFTER-CLEAN-001) — no code changes to this package itself.
|
|
4
|
+
|
|
5
|
+
## 2.1.9 (2026-07-26)
|
|
6
|
+
|
|
7
|
+
Re-publish fixing an empty (1-file) tarball at 2.1.8, caused by BUG-BUILD-PUBLISH-DISTMANIFEST-CLOBBERED-001 in the shared `@adhd/nx-build:publish`/`:version` executors (see tools/nx-plugins/build/executors/publish/impl.js and .../version/impl.js) — no code changes to this package itself.
|
|
8
|
+
|
|
9
|
+
## 2.1.8 (2026-07-26)
|
|
10
|
+
|
|
11
|
+
This was a version bump only for agent-engine-compiler to align it with other projects, there were no code changes.
|
|
12
|
+
|
|
13
|
+
## 2.1.7 (2026-07-25)
|
|
14
|
+
|
|
15
|
+
This was a version bump only for agent-engine-compiler to align it with other projects, there were no code changes.
|
|
16
|
+
|
|
17
|
+
## 2.1.6 (2026-07-25)
|
|
18
|
+
|
|
19
|
+
This was a version bump only for agent-engine-compiler to align it with other projects, there were no code changes.
|
|
20
|
+
|
|
21
|
+
## 2.1.5 (2026-07-24)
|
|
22
|
+
|
|
23
|
+
This was a version bump only for agent-engine-compiler to align it with other projects, there were no code changes.
|
|
24
|
+
|
|
25
|
+
## 2.1.4 (2026-07-24)
|
|
26
|
+
|
|
27
|
+
This was a version bump only for agent-engine-compiler to align it with other projects, there were no code changes.
|
|
28
|
+
|
|
29
|
+
## 2.1.3 (2026-07-23)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
### 🚀 Features
|
|
33
|
+
|
|
34
|
+
- **agent-core-env:** shared registry-DB resolver + DI kills import-time DB-open side effect
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
### ❤️ Thank You
|
|
38
|
+
|
|
39
|
+
- pseudosky
|
package/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# @adhd/agent-engine-compiler
|
|
2
|
+
|
|
3
|
+
Compiles agent configurations from the registry into runtime-ready manifests. Resolves component compositions, tool bindings, policy constraints, and model specifications. Part of the agent registry family.
|
|
4
|
+
|
|
5
|
+
**Status:** Shipped v2.1.2
|
|
6
|
+
**Platform:** `platform:node` (runs in Node/CLI, not browser)
|
|
7
|
+
**Consumers:** `@adhd/agent-mcp`, `@adhd/dispatch-cli`
|
|
8
|
+
|
|
9
|
+
## What it does
|
|
10
|
+
|
|
11
|
+
- **Body Resolution** — Assembles agent components from the registry composition store into a complete prompt body
|
|
12
|
+
- **Tool Resolution** — Resolves tool aliases and platform-specific bindings (HTTP, MCP, CLI, etc.)
|
|
13
|
+
- **Model Resolution** — Looks up model capabilities and configurations
|
|
14
|
+
- **Policy Constraint Resolution** — Evaluates effective authorization policies
|
|
15
|
+
- **Output Emission** — Compiles agent definitions into YAML frontmatter, JSON objects, or Markdown documents
|
|
16
|
+
- **Database Migrations** — Runs schema setup via `runMigrationsOn(db)`
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
First, resolve the shared registry database path:
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { resolveRegistryDbPath } from '@adhd/agent-core-env';
|
|
24
|
+
import Database from 'better-sqlite3';
|
|
25
|
+
import { runMigrationsOn, compileAgent } from '@adhd/agent-engine-compiler';
|
|
26
|
+
|
|
27
|
+
const dbPath = resolveRegistryDbPath(); // e.g., ~/.adhd/agent-registry/production/data/registry.db
|
|
28
|
+
const db = new Database(dbPath);
|
|
29
|
+
|
|
30
|
+
// Run migrations
|
|
31
|
+
await runMigrationsOn(db);
|
|
32
|
+
|
|
33
|
+
// Compile an agent from the registry
|
|
34
|
+
const compiled = await compileAgent(db, {
|
|
35
|
+
agentId: 'my-agent',
|
|
36
|
+
platform: 'mcp', // or 'http', 'cli', 'json'
|
|
37
|
+
models: modelStore,
|
|
38
|
+
tools: toolStore,
|
|
39
|
+
policies: policyStore,
|
|
40
|
+
composition: compositionStore,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Emit as YAML or JSON
|
|
44
|
+
const yaml = emitYamlFrontmatter({
|
|
45
|
+
agentId: compiled.agentId,
|
|
46
|
+
tools: compiled.tools,
|
|
47
|
+
modelAlias: compiled.modelAlias,
|
|
48
|
+
policyConstraints: compiled.policyConstraints,
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Key exports
|
|
53
|
+
|
|
54
|
+
| Export | Purpose |
|
|
55
|
+
|--------|---------|
|
|
56
|
+
| `resolveBody(db, ...)` | Assemble component composition into prompt body |
|
|
57
|
+
| `resolveTools(db, ...)` | Resolve tools and platform bindings |
|
|
58
|
+
| `resolveModel(db, ...)` | Look up model and capabilities |
|
|
59
|
+
| `resolvePolicyConstraints(db, ...)` | Resolve effective policies |
|
|
60
|
+
| `compileAgent(db, input)` | Complete compilation orchestrator |
|
|
61
|
+
| `emitYamlFrontmatter(input)` | Emit as YAML frontmatter + body |
|
|
62
|
+
| `emitJsonObject(input)` | Emit as JSON (e.g., for REST API) |
|
|
63
|
+
| `runMigrationsOn(db)` | Initialize database schema |
|
|
64
|
+
|
|
65
|
+
## Architecture
|
|
66
|
+
|
|
67
|
+
- **Tier**: `engine` (depends on base + core + stores)
|
|
68
|
+
- **Consumption**: Reads from all registry family stores (prompts, tools, policy, provider)
|
|
69
|
+
- **No import-time side effects** — DB path and connection are external (via `agent-core-env`)
|
|
70
|
+
- **Part of agent registry family**: `agent-store-prompts` + `agent-store-tools` + `agent-core-policy` + `agent-core-provider` + `agent-engine-compiler`
|
|
71
|
+
|
|
72
|
+
See `/entrypoint/agent-mcp/` for the agent MCP server (primary consumer).
|
package/package.json
CHANGED
|
@@ -1,49 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adhd/agent-engine-compiler",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.10",
|
|
4
4
|
"description": "Registry-family store for agent-compiler: drizzle-backed SQLite tables sharing the one registry database.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
9
|
-
"files": [
|
|
10
|
-
"dist",
|
|
11
|
-
"CHANGELOG.md"
|
|
12
|
-
],
|
|
13
9
|
"bin": {
|
|
14
|
-
"agent-compiler": "
|
|
10
|
+
"agent-compiler": "src/cli/compile.js"
|
|
15
11
|
},
|
|
16
12
|
"exports": {
|
|
17
13
|
".": {
|
|
18
|
-
"types": "./
|
|
19
|
-
"default": "./
|
|
14
|
+
"types": "./src/index.d.ts",
|
|
15
|
+
"default": "./src/index.js"
|
|
20
16
|
}
|
|
21
17
|
},
|
|
22
|
-
"scripts": {
|
|
23
|
-
"build": "nx build agent-compiler",
|
|
24
|
-
"typecheck": "tsc -p tsconfig.lib.json --noEmit",
|
|
25
|
-
"db:generate": "drizzle-kit generate",
|
|
26
|
-
"db:migrate": "drizzle-kit migrate"
|
|
27
|
-
},
|
|
28
18
|
"dependencies": {
|
|
29
19
|
"better-sqlite3": "12.10.0",
|
|
30
20
|
"drizzle-orm": "0.45.2",
|
|
31
|
-
"@adhd/agent-store-prompts": "^2.1.
|
|
32
|
-
"@adhd/agent-store-tools": "^2.1.
|
|
33
|
-
"@adhd/agent-core-provider": "^2.1.
|
|
34
|
-
"@adhd/agent-core-policy": "^2.1.
|
|
21
|
+
"@adhd/agent-store-prompts": "^2.1.7",
|
|
22
|
+
"@adhd/agent-store-tools": "^2.1.8",
|
|
23
|
+
"@adhd/agent-core-provider": "^2.1.9",
|
|
24
|
+
"@adhd/agent-core-policy": "^2.1.9",
|
|
35
25
|
"@adhd/agent-core-env": "^0.0.8"
|
|
36
26
|
},
|
|
37
|
-
"devDependencies": {
|
|
38
|
-
"@types/better-sqlite3": "^7.6.13",
|
|
39
|
-
"@vitest/coverage-v8": "^1.0.4",
|
|
40
|
-
"drizzle-kit": "^0.31.10",
|
|
41
|
-
"tslib": "^2.6.0",
|
|
42
|
-
"typescript": "^5.5.0",
|
|
43
|
-
"vite": "~5.0.13",
|
|
44
|
-
"vite-plugin-dts": "~3.8.3",
|
|
45
|
-
"vitest": "^1.6.0"
|
|
46
|
-
},
|
|
47
27
|
"license": "MIT",
|
|
48
28
|
"repository": {
|
|
49
29
|
"type": "git",
|
|
@@ -53,7 +33,5 @@
|
|
|
53
33
|
"homepage": "https://github.com/PseudoSky/adhd/tree/main/packages/agent/agent-engine-compiler#readme",
|
|
54
34
|
"bugs": {
|
|
55
35
|
"url": "https://github.com/PseudoSky/adhd/issues"
|
|
56
|
-
}
|
|
57
|
-
"module": "./src/index.js",
|
|
58
|
-
"main": "./src/index.js"
|
|
36
|
+
}
|
|
59
37
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';
|
|
2
|
+
import type { ComposedPrompt } from '@adhd/agent-store-prompts';
|
|
3
|
+
import type { ComponentVersionMap } from '../resolve/composition.js';
|
|
4
|
+
/**
|
|
5
|
+
* Compute the combined `context_hash` for the `registry_composed_prompts` cache.
|
|
6
|
+
*
|
|
7
|
+
* Decision D (decisions.md): `context_hash = SHA-256(sortedJSON(context) + " " +
|
|
8
|
+
* sortedJSON(componentVersions) + " " + platform)`.
|
|
9
|
+
*
|
|
10
|
+
* The `registryContextHash` (from @adhd/agent-registry) handles sorted-key JSON
|
|
11
|
+
* canonicalization of the context part. We apply the same sorted-key approach to
|
|
12
|
+
* `componentVersions` and append the `platform` string as a third field so that any
|
|
13
|
+
* of the three inputs changing produces a distinct hash.
|
|
14
|
+
*
|
|
15
|
+
* A ` ` (space) field separator is used between parts — plain JSON can never contain
|
|
16
|
+
* an unescaped space at the top level, so the three blobs cannot collide by
|
|
17
|
+
* concatenation.
|
|
18
|
+
*
|
|
19
|
+
* @param context - Runtime context key/value map (e.g. `{ticket_type:"security"}`).
|
|
20
|
+
* @param componentVersions - Resolved component-version map from `resolveComposition`.
|
|
21
|
+
* @param platform - Target platform id (e.g. `claude_code`, `claude_api`).
|
|
22
|
+
* @returns 64-character lowercase hex SHA-256 string.
|
|
23
|
+
*/
|
|
24
|
+
export declare function computeContextHash(context: Record<string, string>, componentVersions: ComponentVersionMap, platform: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Look up a `registry_composed_prompts` row by `(agentSlug, platform, context_hash)`.
|
|
27
|
+
*
|
|
28
|
+
* The `context_hash` encodes `(context, componentVersions, platform)` per Decision D.
|
|
29
|
+
* Returns the cached row (with its `id`) on a HIT, or `null` on a MISS.
|
|
30
|
+
*
|
|
31
|
+
* A cache hit means `compileAgent` can return the persisted `{id, content}` WITHOUT
|
|
32
|
+
* re-running the resolve layers (the assembly step is bypassed). This is the
|
|
33
|
+
* `[dod.4]` negative-control guarantee: removing this SELECT before assembly causes
|
|
34
|
+
* a duplicate row on every compile.
|
|
35
|
+
*
|
|
36
|
+
* @param db - Shared Drizzle handle (all four table prefixes).
|
|
37
|
+
* @param agentSlug - Agent to look up.
|
|
38
|
+
* @param platform - Target platform id.
|
|
39
|
+
* @param context - Runtime context key/value map.
|
|
40
|
+
* @param componentVersions - Resolved component-version map from `resolveComposition`.
|
|
41
|
+
* @returns The cached `ComposedPrompt` row on a HIT, or `null` on a MISS.
|
|
42
|
+
*/
|
|
43
|
+
export declare function lookup(db: BetterSQLite3Database<any>, agentSlug: string, platform: string, context: Record<string, string>, componentVersions: ComponentVersionMap): ComposedPrompt | null;
|
|
44
|
+
/**
|
|
45
|
+
* Write a new `registry_composed_prompts` row for `(agentSlug, platform, context_hash)`.
|
|
46
|
+
*
|
|
47
|
+
* Called on a cache MISS: after assembly is complete, persists the composed prompt
|
|
48
|
+
* so subsequent compiles can hit the cache. Returns the inserted row, including the
|
|
49
|
+
* generated `id` (the [def:composed-output].id audit/cache handle).
|
|
50
|
+
*
|
|
51
|
+
* @param db - Shared Drizzle handle (all four table prefixes).
|
|
52
|
+
* @param agentSlug - Agent the row belongs to.
|
|
53
|
+
* @param platform - Target platform id (folded into the hash).
|
|
54
|
+
* @param context - Runtime context key/value map used for assembly.
|
|
55
|
+
* @param componentVersions - Resolved component-version map (audit trail).
|
|
56
|
+
* @param content - The assembled platform artifact (markdown, JSON, etc.).
|
|
57
|
+
* @returns The inserted `ComposedPrompt` row with its generated `id`.
|
|
58
|
+
*/
|
|
59
|
+
export declare function write(db: BetterSQLite3Database<any>, agentSlug: string, platform: string, context: Record<string, string>, componentVersions: ComponentVersionMap, content: string): ComposedPrompt;
|
|
60
|
+
//# sourceMappingURL=composed-prompt-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composed-prompt-cache.d.ts","sourceRoot":"","sources":["../../../src/cache/composed-prompt-cache.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAMxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAMrE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,iBAAiB,EAAE,mBAAmB,EACtC,QAAQ,EAAE,MAAM,GACf,MAAM,CAiBR;AAMD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,MAAM,CAEpB,EAAE,EAAE,qBAAqB,CAAC,GAAG,CAAC,EAC9B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,iBAAiB,EAAE,mBAAmB,GACrC,cAAc,GAAG,IAAI,CAIvB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,KAAK,CAEnB,EAAE,EAAE,qBAAqB,CAAC,GAAG,CAAC,EAC9B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,iBAAiB,EAAE,mBAAmB,EACtC,OAAO,EAAE,MAAM,GACd,cAAc,CAShB"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// ──────────────────────────────────────────────
|
|
2
|
+
// composed-prompt-cache — cache lookup + write for the composed_prompts table.
|
|
3
|
+
//
|
|
4
|
+
// Implements Decision D (decisions.md [def:context-hash]):
|
|
5
|
+
// context_hash = SHA-256( sortedJSON(context) + " " + sortedJSON(componentVersions) + " " + platform )
|
|
6
|
+
//
|
|
7
|
+
// The three-part key encodes:
|
|
8
|
+
// 1. The runtime context (any key/value change → different hash → cache miss).
|
|
9
|
+
// 2. The resolved component-version set (an unpinned component advancing to a
|
|
10
|
+
// new latest → different componentVersions → miss).
|
|
11
|
+
// 3. The target platform (different platform → different content shape → miss).
|
|
12
|
+
//
|
|
13
|
+
// The "context part" reuses @adhd/agent-registry's exported `contextHash` helper
|
|
14
|
+
// for consistent sorted-key JSON canonicalization — do NOT reimplement
|
|
15
|
+
// ([ref:store-read], decisions.md Decision D note).
|
|
16
|
+
//
|
|
17
|
+
// The composed_prompts table comes from @adhd/agent-registry (plan 1,
|
|
18
|
+
// `registry_composed_prompts`). We use the existing table via the shared DB
|
|
19
|
+
// handle passed by `compileAgent` ([inv:one-db-handle]). No duplicate table
|
|
20
|
+
// is created here.
|
|
21
|
+
//
|
|
22
|
+
// [def:context-hash] — the combined cache key algorithm (decisions.md Decision D)
|
|
23
|
+
// [inv:one-db-handle] — shared Drizzle handle, all four table prefixes
|
|
24
|
+
// [inv:reopen-proves-cache] — persistence proven by CLOSE+REOPEN (test invariant)
|
|
25
|
+
// ──────────────────────────────────────────────
|
|
26
|
+
import { createHash } from 'node:crypto';
|
|
27
|
+
import { ComposedPromptStore, contextHash as registryContextHash, } from '@adhd/agent-store-prompts';
|
|
28
|
+
// ──────────────────────────────────────────────
|
|
29
|
+
// Combined cache-key hash
|
|
30
|
+
// ──────────────────────────────────────────────
|
|
31
|
+
/**
|
|
32
|
+
* Compute the combined `context_hash` for the `registry_composed_prompts` cache.
|
|
33
|
+
*
|
|
34
|
+
* Decision D (decisions.md): `context_hash = SHA-256(sortedJSON(context) + " " +
|
|
35
|
+
* sortedJSON(componentVersions) + " " + platform)`.
|
|
36
|
+
*
|
|
37
|
+
* The `registryContextHash` (from @adhd/agent-registry) handles sorted-key JSON
|
|
38
|
+
* canonicalization of the context part. We apply the same sorted-key approach to
|
|
39
|
+
* `componentVersions` and append the `platform` string as a third field so that any
|
|
40
|
+
* of the three inputs changing produces a distinct hash.
|
|
41
|
+
*
|
|
42
|
+
* A ` ` (space) field separator is used between parts — plain JSON can never contain
|
|
43
|
+
* an unescaped space at the top level, so the three blobs cannot collide by
|
|
44
|
+
* concatenation.
|
|
45
|
+
*
|
|
46
|
+
* @param context - Runtime context key/value map (e.g. `{ticket_type:"security"}`).
|
|
47
|
+
* @param componentVersions - Resolved component-version map from `resolveComposition`.
|
|
48
|
+
* @param platform - Target platform id (e.g. `claude_code`, `claude_api`).
|
|
49
|
+
* @returns 64-character lowercase hex SHA-256 string.
|
|
50
|
+
*/
|
|
51
|
+
export function computeContextHash(context, componentVersions, platform) {
|
|
52
|
+
// Part 1: sorted-key JSON of context (reuse the upstream helper for parity).
|
|
53
|
+
const contextPart = registryContextHash(context);
|
|
54
|
+
// Part 2: sorted-key JSON of componentVersions (apply the same canonicalization).
|
|
55
|
+
const sortedVersions = Object.fromEntries(Object.keys(componentVersions)
|
|
56
|
+
.sort()
|
|
57
|
+
.map((k) => [k, componentVersions[k]]));
|
|
58
|
+
const versionPart = JSON.stringify(sortedVersions);
|
|
59
|
+
// Combined: context_hash(context) + " " + sortedJSON(componentVersions) + " " + platform
|
|
60
|
+
// Field separator is a bare space — JSON strings never contain unescaped spaces
|
|
61
|
+
// at the outermost level, so the three segments cannot collide.
|
|
62
|
+
const combined = `${contextPart} ${versionPart} ${platform}`;
|
|
63
|
+
return createHash('sha256').update(combined, 'utf8').digest('hex');
|
|
64
|
+
}
|
|
65
|
+
// ──────────────────────────────────────────────
|
|
66
|
+
// Cache operations
|
|
67
|
+
// ──────────────────────────────────────────────
|
|
68
|
+
/**
|
|
69
|
+
* Look up a `registry_composed_prompts` row by `(agentSlug, platform, context_hash)`.
|
|
70
|
+
*
|
|
71
|
+
* The `context_hash` encodes `(context, componentVersions, platform)` per Decision D.
|
|
72
|
+
* Returns the cached row (with its `id`) on a HIT, or `null` on a MISS.
|
|
73
|
+
*
|
|
74
|
+
* A cache hit means `compileAgent` can return the persisted `{id, content}` WITHOUT
|
|
75
|
+
* re-running the resolve layers (the assembly step is bypassed). This is the
|
|
76
|
+
* `[dod.4]` negative-control guarantee: removing this SELECT before assembly causes
|
|
77
|
+
* a duplicate row on every compile.
|
|
78
|
+
*
|
|
79
|
+
* @param db - Shared Drizzle handle (all four table prefixes).
|
|
80
|
+
* @param agentSlug - Agent to look up.
|
|
81
|
+
* @param platform - Target platform id.
|
|
82
|
+
* @param context - Runtime context key/value map.
|
|
83
|
+
* @param componentVersions - Resolved component-version map from `resolveComposition`.
|
|
84
|
+
* @returns The cached `ComposedPrompt` row on a HIT, or `null` on a MISS.
|
|
85
|
+
*/
|
|
86
|
+
export function lookup(
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
88
|
+
db, agentSlug, platform, context, componentVersions) {
|
|
89
|
+
const hash = computeContextHash(context, componentVersions, platform);
|
|
90
|
+
const store = new ComposedPromptStore(db);
|
|
91
|
+
return store.lookup(agentSlug, hash);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Write a new `registry_composed_prompts` row for `(agentSlug, platform, context_hash)`.
|
|
95
|
+
*
|
|
96
|
+
* Called on a cache MISS: after assembly is complete, persists the composed prompt
|
|
97
|
+
* so subsequent compiles can hit the cache. Returns the inserted row, including the
|
|
98
|
+
* generated `id` (the [def:composed-output].id audit/cache handle).
|
|
99
|
+
*
|
|
100
|
+
* @param db - Shared Drizzle handle (all four table prefixes).
|
|
101
|
+
* @param agentSlug - Agent the row belongs to.
|
|
102
|
+
* @param platform - Target platform id (folded into the hash).
|
|
103
|
+
* @param context - Runtime context key/value map used for assembly.
|
|
104
|
+
* @param componentVersions - Resolved component-version map (audit trail).
|
|
105
|
+
* @param content - The assembled platform artifact (markdown, JSON, etc.).
|
|
106
|
+
* @returns The inserted `ComposedPrompt` row with its generated `id`.
|
|
107
|
+
*/
|
|
108
|
+
export function write(
|
|
109
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
110
|
+
db, agentSlug, platform, context, componentVersions, content) {
|
|
111
|
+
const hash = computeContextHash(context, componentVersions, platform);
|
|
112
|
+
const store = new ComposedPromptStore(db);
|
|
113
|
+
return store.write({
|
|
114
|
+
agentSlug,
|
|
115
|
+
contextHash: hash,
|
|
116
|
+
content,
|
|
117
|
+
componentVersions,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=composed-prompt-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composed-prompt-cache.js","sourceRoot":"","sources":["../../../src/cache/composed-prompt-cache.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,+EAA+E;AAC/E,EAAE;AACF,2DAA2D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