@adhd/agent-engine-compiler 2.1.7 → 2.1.9

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.
Files changed (55) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/drizzle/meta/_journal.json +5 -0
  3. package/package.json +6 -28
  4. package/src/cache/composed-prompt-cache.d.ts +60 -0
  5. package/src/cache/composed-prompt-cache.d.ts.map +1 -0
  6. package/src/cache/composed-prompt-cache.js +120 -0
  7. package/src/cache/composed-prompt-cache.js.map +1 -0
  8. package/src/cli/compile.d.ts +3 -0
  9. package/src/cli/compile.d.ts.map +1 -0
  10. package/src/cli/compile.js +300 -0
  11. package/src/cli/compile.js.map +1 -0
  12. package/src/compile.d.ts +61 -0
  13. package/src/compile.d.ts.map +1 -0
  14. package/src/compile.js +279 -0
  15. package/src/compile.js.map +1 -0
  16. package/src/db/migrate-runner.d.ts +31 -0
  17. package/src/db/migrate-runner.d.ts.map +1 -0
  18. package/src/db/migrate-runner.js +35 -0
  19. package/src/db/migrate-runner.js.map +1 -0
  20. package/src/db/schema.d.ts +3 -0
  21. package/src/db/schema.d.ts.map +1 -0
  22. package/src/db/schema.js +30 -0
  23. package/src/db/schema.js.map +1 -0
  24. package/src/emit/json.d.ts +50 -0
  25. package/src/emit/json.d.ts.map +1 -0
  26. package/src/emit/json.js +66 -0
  27. package/src/emit/json.js.map +1 -0
  28. package/src/emit/markdown.d.ts +35 -0
  29. package/src/emit/markdown.d.ts.map +1 -0
  30. package/src/emit/markdown.js +90 -0
  31. package/src/emit/markdown.js.map +1 -0
  32. package/src/index.d.ts +18 -0
  33. package/src/index.d.ts.map +1 -0
  34. package/src/index.js +21 -0
  35. package/src/index.js.map +1 -0
  36. package/src/resolve/composition.d.ts +28 -0
  37. package/src/resolve/composition.d.ts.map +1 -0
  38. package/src/resolve/composition.js +33 -0
  39. package/src/resolve/composition.js.map +1 -0
  40. package/src/resolve/model.d.ts +22 -0
  41. package/src/resolve/model.d.ts.map +1 -0
  42. package/src/resolve/model.js +69 -0
  43. package/src/resolve/model.js.map +1 -0
  44. package/src/resolve/policy.d.ts +34 -0
  45. package/src/resolve/policy.d.ts.map +1 -0
  46. package/src/resolve/policy.js +44 -0
  47. package/src/resolve/policy.js.map +1 -0
  48. package/src/resolve/tools.d.ts +33 -0
  49. package/src/resolve/tools.d.ts.map +1 -0
  50. package/src/resolve/tools.js +62 -0
  51. package/src/resolve/tools.js.map +1 -0
  52. package/src/seed/fixtures.d.ts +52 -0
  53. package/src/seed/fixtures.d.ts.map +1 -0
  54. package/src/seed/fixtures.js +148 -0
  55. package/src/seed/fixtures.js.map +1 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,35 @@
1
+ ## 2.1.9 (2026-07-26)
2
+
3
+ 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.
4
+
5
+ ## 2.1.8 (2026-07-26)
6
+
7
+ This was a version bump only for agent-engine-compiler to align it with other projects, there were no code changes.
8
+
9
+ ## 2.1.7 (2026-07-25)
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.6 (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.5 (2026-07-24)
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.4 (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.3 (2026-07-23)
26
+
27
+
28
+ ### 🚀 Features
29
+
30
+ - **agent-core-env:** shared registry-DB resolver + DI kills import-time DB-open side effect
31
+
32
+
33
+ ### ❤️ Thank You
34
+
35
+ - pseudosky
@@ -0,0 +1,5 @@
1
+ {
2
+ "version": "7",
3
+ "dialect": "sqlite",
4
+ "entries": []
5
+ }
package/package.json CHANGED
@@ -1,30 +1,20 @@
1
1
  {
2
2
  "name": "@adhd/agent-engine-compiler",
3
- "version": "2.1.7",
3
+ "version": "2.1.9",
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": "./dist/src/cli/compile.js"
10
+ "agent-compiler": "src/cli/compile.js"
15
11
  },
16
12
  "exports": {
17
13
  ".": {
18
- "types": "./dist/src/index.d.ts",
19
- "default": "./dist/src/index.js"
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",
@@ -32,17 +22,7 @@
32
22
  "@adhd/agent-store-tools": "^2.1.9",
33
23
  "@adhd/agent-core-provider": "^2.1.9",
34
24
  "@adhd/agent-core-policy": "^2.1.9",
35
- "@adhd/agent-core-env": "^0.0.7"
36
- },
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"
25
+ "@adhd/agent-core-env": "^0.0.8"
46
26
  },
47
27
  "license": "MIT",
48
28
  "repository": {
@@ -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;AAC3D,yGAAyG;AACzG,EAAE;AACF,8BAA8B;AAC9B,iFAAiF;AACjF,gFAAgF;AAChF,yDAAyD;AACzD,kFAAkF;AAClF,EAAE;AACF,iFAAiF;AACjF,uEAAuE;AACvE,oDAAoD;AACpD,EAAE;AACF,sEAAsE;AACtE,6EAA6E;AAC7E,6EAA6E;AAC7E,mBAAmB;AACnB,EAAE;AACF,qFAAqF;AACrF,yEAAyE;AACzE,kFAAkF;AAClF,iDAAiD;AAEjD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAIzC,OAAO,EACL,mBAAmB,EACnB,WAAW,IAAI,mBAAmB,GACnC,MAAM,2BAA2B,CAAC;AAInC,iDAAiD;AACjD,0BAA0B;AAC1B,iDAAiD;AAEjD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,kBAAkB,CAChC,OAA+B,EAC/B,iBAAsC,EACtC,QAAgB;IAEhB,6EAA6E;IAC7E,MAAM,WAAW,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAC;IAEjD,kFAAkF;IAClF,MAAM,cAAc,GAAG,MAAM,CAAC,WAAW,CACvC,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC;SAC3B,IAAI,EAAE;SACN,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAA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L=compile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../../src/cli/compile.ts"],"names":[],"mappings":""}
@@ -0,0 +1,300 @@
1
+ #!/usr/bin/env node
2
+ // ──────────────────────────────────────────────
3
+ // cli/compile.ts — argv parser + dispatcher for the agent-compiler bin.
4
+ //
5
+ // Usage:
6
+ // node cli/compile.js compile <slug> [options]
7
+ //
8
+ // Options:
9
+ // --platform <p> Target platform (default: claude_code).
10
+ // Must match a row in tool_platforms.
11
+ // --context '<json>' Runtime context key/value object (JSON string).
12
+ // --format json Emit JSON instead of platform default.
13
+ // --out-dir <d> Write <slug>.md (or <slug>.json) under <d>
14
+ // instead of printing to stdout.
15
+ // --all Compile every agent in the registry (use with
16
+ // --category to limit scope).
17
+ // --category <c> Filter to agents in this taxonomy category slug.
18
+ // --db <path> Path to the SQLite registry file. Defaults to
19
+ // AGENT_REGISTRY_DB env var, then ~/.agent-registry/registry.db.
20
+ //
21
+ // Exit codes:
22
+ // 0 — success
23
+ // 1 — unknown slug / unknown platform / bad argument / I/O error
24
+ //
25
+ // [ref:cli-bin] — mirrors agent-mcp's bin entry in package.json;
26
+ // parses compile <slug> ... and writes content to stdout or --out-dir.
27
+ // [inv:platform-node] — no browser imports; pure Node + SQLite.
28
+ // [inv:one-db-handle] — opens ONE better-sqlite3 handle for the shared DB.
29
+ // ──────────────────────────────────────────────
30
+ import fs from 'node:fs';
31
+ import path from 'node:path';
32
+ import process from 'node:process';
33
+ import { fileURLToPath } from 'node:url';
34
+ import Database from 'better-sqlite3';
35
+ import { drizzle } from 'drizzle-orm/better-sqlite3';
36
+ import { migrate } from 'drizzle-orm/better-sqlite3/migrator';
37
+ import { resolveRegistryDbPath } from '@adhd/agent-core-env';
38
+ import { AgentStore } from '@adhd/agent-store-prompts';
39
+ import { compileAgent } from '../compile.js';
40
+ // ── Migration folders ─────────────────────────────────────────────────────
41
+ //
42
+ // Resolved relative to this compiled file's __dirname at runtime so the bin
43
+ // works from the dist layout without referencing source paths.
44
+ //
45
+ // dist/packages/agent/agent-engine-compiler/src/cli/compile.js
46
+ // → ../../ = dist/packages/agent/agent-engine-compiler/
47
+ // → ../../../ = dist/packages/agent/
48
+ // → ../../../<pkg>/drizzle = dist/packages/agent/<pkg>/drizzle
49
+ //
50
+ // Timestamp order (ascending) matters so Drizzle's journal bookkeeping
51
+ // doesn't skip a migration set:
52
+ // provider (1750*) → registry (1782193*) → tool-registry (1782250*)
53
+ // → policy (1782256*) → compiler (18*)
54
+ //
55
+ // This mirrors the migration order in compile-agent.test.ts.
56
+ const __dirname = fileURLToPath(new URL('.', import.meta.url));
57
+ const AI_DIST = path.resolve(__dirname, '../../../');
58
+ const PROVIDER_MIGRATIONS = path.join(AI_DIST, 'agent-core-provider/drizzle');
59
+ const REGISTRY_MIGRATIONS = path.join(AI_DIST, 'agent-store-prompts/drizzle');
60
+ const TOOL_REGISTRY_MIGRATIONS = path.join(AI_DIST, 'agent-store-tools/drizzle');
61
+ const POLICY_MIGRATIONS = path.join(AI_DIST, 'agent-core-policy/drizzle');
62
+ const COMPILER_MIGRATIONS = path.join(AI_DIST, 'agent-engine-compiler/drizzle');
63
+ // ──────────────────────────────────────────────
64
+ // argv parser
65
+ // ──────────────────────────────────────────────
66
+ /**
67
+ * Parse process.argv into a CliArgs object.
68
+ * Exits 1 with a usage message on any parse error.
69
+ */
70
+ function parseArgs(argv) {
71
+ // argv: [ node, compile.js, 'compile', <slug?>, ...flags ]
72
+ const args = argv.slice(2); // strip node + script path
73
+ if (args[0] !== 'compile') {
74
+ die(`Expected sub-command 'compile', got: ${args[0] ?? '(nothing)'}`);
75
+ }
76
+ let slug = null;
77
+ let platform = 'claude_code';
78
+ let context = {};
79
+ let formatJson = false;
80
+ let outDir = null;
81
+ let all = false;
82
+ let category = null;
83
+ // AGENT_REGISTRY_DB is this CLI's own pre-existing, bin-specific legacy
84
+ // override (kept for back-compat) — it wins over the shared resolver's
85
+ // canonical default but not over an explicit --db flag (applied below).
86
+ // resolveRegistryDbPath() itself still checks the 3 documented
87
+ // registry-family env vars (ADHD_AGENT_REGISTRY_DB_PATH,
88
+ // REGISTRY_DATABASE_PATH, DATABASE_PATH) before falling back to the
89
+ // @adhd/environment-resolved canonical default.
90
+ let dbPath = process.env['AGENT_REGISTRY_DB'] ?? resolveRegistryDbPath();
91
+ const flags = args.slice(1); // everything after 'compile'
92
+ let i = 0;
93
+ while (i < flags.length) {
94
+ const tok = flags[i];
95
+ if (tok === '--platform') {
96
+ platform = requireNext(flags, i, '--platform');
97
+ i += 2;
98
+ }
99
+ else if (tok === '--context') {
100
+ const raw = requireNext(flags, i, '--context');
101
+ try {
102
+ // Parse as unknown first, then cast to CompositionContext (Record<string, string>).
103
+ // The runtime contract is that --context values are string-keyed, string-valued.
104
+ context = JSON.parse(raw);
105
+ }
106
+ catch {
107
+ die(`--context must be valid JSON; got: ${raw}`);
108
+ }
109
+ i += 2;
110
+ }
111
+ else if (tok === '--format') {
112
+ const fmt = requireNext(flags, i, '--format');
113
+ if (fmt !== 'json') {
114
+ die(`--format only supports 'json'; got: '${fmt}'`);
115
+ }
116
+ formatJson = true;
117
+ i += 2;
118
+ }
119
+ else if (tok === '--out-dir') {
120
+ outDir = requireNext(flags, i, '--out-dir');
121
+ i += 2;
122
+ }
123
+ else if (tok === '--all') {
124
+ all = true;
125
+ i++;
126
+ }
127
+ else if (tok === '--category') {
128
+ category = requireNext(flags, i, '--category');
129
+ i += 2;
130
+ }
131
+ else if (tok === '--db') {
132
+ dbPath = requireNext(flags, i, '--db');
133
+ i += 2;
134
+ }
135
+ else if (tok != null && !tok.startsWith('-')) {
136
+ // Positional slug — only accepted once.
137
+ if (slug !== null) {
138
+ die(`Unexpected extra positional argument: '${tok}'`);
139
+ }
140
+ slug = tok;
141
+ i++;
142
+ }
143
+ else {
144
+ die(`Unknown flag: '${tok}'`);
145
+ }
146
+ }
147
+ if (!all && slug === null) {
148
+ die('Provide a slug (compile <slug>) or use --all [--category <c>]');
149
+ }
150
+ if (all && slug !== null) {
151
+ die('--all and a positional slug are mutually exclusive');
152
+ }
153
+ return { slug, platform, context, formatJson, outDir, all, category, dbPath };
154
+ }
155
+ function requireNext(flags, i, flag) {
156
+ const val = flags[i + 1];
157
+ if (val == null || val.startsWith('-')) {
158
+ die(`${flag} requires a value`);
159
+ }
160
+ return val;
161
+ }
162
+ // ──────────────────────────────────────────────
163
+ // DB open helper
164
+ // ──────────────────────────────────────────────
165
+ /**
166
+ * Open the shared SQLite registry file and apply migrations so the schema is
167
+ * always current ([inv:one-db-handle]).
168
+ *
169
+ * Runs all five migration sets in ascending timestamp order so Drizzle's
170
+ * journal does not skip any set.
171
+ */
172
+ function openDb(dbPath) {
173
+ if (!fs.existsSync(dbPath)) {
174
+ const parent = path.dirname(dbPath);
175
+ if (!fs.existsSync(parent)) {
176
+ fs.mkdirSync(parent, { recursive: true });
177
+ }
178
+ }
179
+ const conn = new Database(dbPath);
180
+ conn.pragma('journal_mode = WAL');
181
+ conn.pragma('foreign_keys = OFF');
182
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
183
+ const db = drizzle(conn, { schema: {} });
184
+ // Migrate in ascending timestamp order — same pattern as the test suite.
185
+ for (const folder of [
186
+ PROVIDER_MIGRATIONS,
187
+ REGISTRY_MIGRATIONS,
188
+ TOOL_REGISTRY_MIGRATIONS,
189
+ POLICY_MIGRATIONS,
190
+ COMPILER_MIGRATIONS,
191
+ ]) {
192
+ if (fs.existsSync(folder)) {
193
+ migrate(db, { migrationsFolder: folder });
194
+ }
195
+ else {
196
+ process.stderr.write(`agent-compiler: warning: migration folder not found: ${folder}\n`);
197
+ }
198
+ }
199
+ conn.pragma('foreign_keys = ON');
200
+ return { conn, db };
201
+ }
202
+ // ──────────────────────────────────────────────
203
+ // Compile a single agent → string artifact
204
+ // ──────────────────────────────────────────────
205
+ function compileSingle(slug, args,
206
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
207
+ db) {
208
+ let result;
209
+ try {
210
+ result = compileAgent({
211
+ agentSlug: slug,
212
+ platform: args.platform,
213
+ context: args.context,
214
+ db,
215
+ });
216
+ }
217
+ catch (err) {
218
+ const msg = err instanceof Error ? err.message : String(err);
219
+ // Distinguish AGENT_NOT_FOUND / PLATFORM_NOT_FOUND from other errors.
220
+ if (msg.includes('not found') || msg.includes('NOT_FOUND')) {
221
+ die(`Error: ${msg}`);
222
+ }
223
+ die(`Compilation failed for '${slug}' on platform '${args.platform}': ${msg}`);
224
+ }
225
+ // --format json overrides the platform's default header format.
226
+ if (args.formatJson) {
227
+ // If content is already JSON (json_object platforms), return as-is.
228
+ try {
229
+ JSON.parse(result.content);
230
+ return result.content; // already valid JSON
231
+ }
232
+ catch {
233
+ // Wrap markdown in a JSON envelope.
234
+ return JSON.stringify({
235
+ systemPrompt: result.content,
236
+ tools: result.tools,
237
+ componentVersions: result.componentVersions,
238
+ }, null, 2);
239
+ }
240
+ }
241
+ return result.content;
242
+ }
243
+ // ──────────────────────────────────────────────
244
+ // Output helper
245
+ // ──────────────────────────────────────────────
246
+ /**
247
+ * Write content either to stdout or to <outDir>/<slug>.<ext>.
248
+ */
249
+ function writeOutput(slug, content, args) {
250
+ if (args.outDir === null) {
251
+ process.stdout.write(content);
252
+ return;
253
+ }
254
+ fs.mkdirSync(args.outDir, { recursive: true });
255
+ const ext = args.formatJson ? 'json' : 'md';
256
+ const dest = path.join(args.outDir, `${slug}.${ext}`);
257
+ fs.writeFileSync(dest, content, 'utf8');
258
+ }
259
+ // ──────────────────────────────────────────────
260
+ // Fatal error helper
261
+ // ──────────────────────────────────────────────
262
+ function die(msg) {
263
+ process.stderr.write(`agent-compiler: ${msg}\n`);
264
+ process.exit(1);
265
+ }
266
+ // ──────────────────────────────────────────────
267
+ // Main
268
+ // ──────────────────────────────────────────────
269
+ function main() {
270
+ const args = parseArgs(process.argv);
271
+ const { conn, db } = openDb(args.dbPath);
272
+ try {
273
+ if (args.all) {
274
+ // Compile every agent in the registry, optionally filtered by category.
275
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
276
+ const agentStore = new AgentStore(db);
277
+ const agents = agentStore.list(args.category ? { category: args.category } : {});
278
+ if (agents.length === 0) {
279
+ const scope = args.category ? ` in category '${args.category}'` : '';
280
+ process.stderr.write(`agent-compiler: no agents found${scope}\n`);
281
+ // Exit 0 — empty category is not an error.
282
+ }
283
+ for (const agent of agents) {
284
+ const content = compileSingle(agent.slug, args, db);
285
+ writeOutput(agent.slug, content, args);
286
+ }
287
+ }
288
+ else {
289
+ // Single-slug path.
290
+ // slug is guaranteed non-null here by parseArgs.
291
+ const content = compileSingle(args.slug, args, db);
292
+ writeOutput(args.slug, content, args);
293
+ }
294
+ }
295
+ finally {
296
+ conn.close();
297
+ }
298
+ }
299
+ main();
300
+ //# sourceMappingURL=compile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile.js","sourceRoot":"","sources":["../../../src/cli/compile.ts"],"names":[],"mappings":";AACA,iDAAiD;AACjD,wEAAwE;AACxE,EAAE;AACF,SAAS;AACT,iDAAiD;AACjD,EAAE;AACF,WAAW;AACX,gEAAgE;AAChE,4DAA4D;AAC5D,wEAAwE;AACxE,+DAA+D;AAC/D,mEAAmE;AACnE,uDAAuD;AACvD,sEAAsE;AACtE,oDAAoD;AACpD,yEAAyE;AACzE,sEAAsE;AACtE,uFAAuF;AACvF,EAAE;AACF,cAAc;AACd,iBAAiB;AACjB,oEAAoE;AACpE,EAAE;AACF,iEAAiE;AACjE,yEAAyE;AACzE,gEAAgE;AAChE,2EAA2E;AAC3E,iDAAiD;AAEjD,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAA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