@adhd/agent-core-env 0.0.1

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/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # agent-agent-core-env
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build agent-agent-core-env` to build the library.
8
+
9
+ ## Running unit tests
10
+
11
+ Run `nx test agent-agent-core-env` to execute the unit tests via [Vitest](https://vitest.dev/).
package/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("@adhd/environment"),i=require("node:fs"),o=require("node:path"),y=require("better-sqlite3"),u=require("drizzle-orm/better-sqlite3"),d="agent-registry",a={namespaces:["production"],dirs:{data:{kind:"data",scope:"global"}},files:{registry:{in:"data",name:"registry.db"}},config:{}};function c(r={}){if(r.registryDbPath)return r.registryDbPath;const t=process.env.ADHD_AGENT_REGISTRY_DB_PATH;if(t)return t;const n=process.env.REGISTRY_DATABASE_PATH;if(n)return n;const e=process.env.DATABASE_PATH;return e||new g.Environment("agent-registry",a,r.scope?{scope:r.scope}:{}).files.registry}function D(r={}){const t=o.resolve(c({registryDbPath:r.registryDbPath})),n=o.dirname(t);i.existsSync(n)||i.mkdirSync(n,{recursive:!0});const e=new y(t);e.pragma("journal_mode = WAL"),e.pragma("foreign_keys = ON");const s=u.drizzle(e);return{sqlite:e,db:s}}exports.AGENT_REGISTRY_PROJECT_ID=d;exports.agentRegistryEnvironmentSpec=a;exports.openRegistryDb=D;exports.resolveRegistryDbPath=c;
package/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export { resolveRegistryDbPath } from './resolve-registry-db-path.js';
2
+ export type { ResolveRegistryDbPathOpts } from './resolve-registry-db-path.js';
3
+ export { openRegistryDb } from './open-registry-db.js';
4
+ export type { OpenRegistryDbOpts, RegistryDbHandle } from './open-registry-db.js';
5
+ export { agentRegistryEnvironmentSpec, AGENT_REGISTRY_PROJECT_ID } from './spec.js';
6
+ export type { AgentRegistryEnvConfig } from './spec.js';
package/index.js ADDED
@@ -0,0 +1,45 @@
1
+ import { Environment as a } from "@adhd/environment";
2
+ import o from "node:fs";
3
+ import i from "node:path";
4
+ import c from "better-sqlite3";
5
+ import { drizzle as g } from "drizzle-orm/better-sqlite3";
6
+ const b = "agent-registry", m = {
7
+ namespaces: ["production"],
8
+ dirs: {
9
+ data: { kind: "data", scope: "global" }
10
+ },
11
+ files: {
12
+ registry: { in: "data", name: "registry.db" }
13
+ },
14
+ config: {}
15
+ };
16
+ function f(e = {}) {
17
+ if (e.registryDbPath)
18
+ return e.registryDbPath;
19
+ const t = process.env.ADHD_AGENT_REGISTRY_DB_PATH;
20
+ if (t)
21
+ return t;
22
+ const n = process.env.REGISTRY_DATABASE_PATH;
23
+ if (n)
24
+ return n;
25
+ const r = process.env.DATABASE_PATH;
26
+ return r || new a(
27
+ "agent-registry",
28
+ m,
29
+ e.scope ? { scope: e.scope } : {}
30
+ ).files.registry;
31
+ }
32
+ function u(e = {}) {
33
+ const t = i.resolve(f({ registryDbPath: e.registryDbPath })), n = i.dirname(t);
34
+ o.existsSync(n) || o.mkdirSync(n, { recursive: !0 });
35
+ const r = new c(t);
36
+ r.pragma("journal_mode = WAL"), r.pragma("foreign_keys = ON");
37
+ const s = g(r);
38
+ return { sqlite: r, db: s };
39
+ }
40
+ export {
41
+ b as AGENT_REGISTRY_PROJECT_ID,
42
+ m as agentRegistryEnvironmentSpec,
43
+ u as openRegistryDb,
44
+ f as resolveRegistryDbPath
45
+ };
@@ -0,0 +1,28 @@
1
+ import { BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';
2
+ import { default as Database } from 'better-sqlite3';
3
+
4
+ export interface OpenRegistryDbOpts {
5
+ /** Explicit path override — forwarded to `resolveRegistryDbPath()`. When
6
+ * absent, the full precedence chain (function arg / env vars / canonical
7
+ * default) resolves the path. */
8
+ registryDbPath?: string;
9
+ }
10
+ export interface RegistryDbHandle {
11
+ /** The raw `better-sqlite3` connection — WAL mode + `foreign_keys = ON`
12
+ * already set, matching every existing family client's pragmas. */
13
+ sqlite: Database.Database;
14
+ /** A schema-less Drizzle instance over `sqlite`. Each family package
15
+ * binds its OWN schema-typed Drizzle instance against this same
16
+ * connection (`drizzle(handle.sqlite, { schema })`) — this package owns
17
+ * no registry-family schema itself. */
18
+ db: BetterSQLite3Database;
19
+ }
20
+ /**
21
+ * Opens (and, if needed, creates) the shared registry SQLite file, applying
22
+ * the same pragmas every existing family client already applied
23
+ * (`journal_mode = WAL`, `foreign_keys = ON`) and `mkdir -p`'ing the parent
24
+ * directory first. Safe to call more than once — each call opens its own
25
+ * connection (matching the pre-migration behavior of `db/client.ts`, which
26
+ * every consumer already expected to be a single connection per process).
27
+ */
28
+ export declare function openRegistryDb(opts?: OpenRegistryDbOpts): RegistryDbHandle;
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@adhd/agent-core-env",
3
+ "version": "0.0.1",
4
+ "description": "Shared @adhd/environment-backed resolver for the agent-registry family's one shared SQLite file (agent-store-prompts/-tools, agent-core-policy/-provider, agent-engine-compiler) — resolveRegistryDbPath() + lazy openRegistryDb(), no import-time DB open.",
5
+ "type": "module",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "exports": {
10
+ ".": {
11
+ "types": "./index.d.ts",
12
+ "default": "./index.js"
13
+ }
14
+ },
15
+ "dependencies": {
16
+ "@adhd/environment": "^0.0.1",
17
+ "better-sqlite3": "12.10.0",
18
+ "drizzle-orm": "0.45.2"
19
+ },
20
+ "license": "MIT",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/PseudoSky/adhd.git",
24
+ "directory": "packages/agent/agent-core-env"
25
+ },
26
+ "homepage": "https://github.com/PseudoSky/adhd/tree/main/packages/agent/agent-core-env#readme",
27
+ "bugs": {
28
+ "url": "https://github.com/PseudoSky/adhd/issues"
29
+ }
30
+ }
@@ -0,0 +1,37 @@
1
+ import { Scope } from '@adhd/environment';
2
+
3
+ export interface ResolveRegistryDbPathOpts {
4
+ /** Explicit override — highest precedence. Callers (e.g. tests) that know
5
+ * exactly which file they want should pass this instead of relying on
6
+ * env vars. */
7
+ registryDbPath?: string;
8
+ /** Forces the active `Environment` scope, bypassing the pinned `'global'`
9
+ * default on `dirs.data` (see `spec.ts`) — equivalent to setting
10
+ * `ADHD_ENV_SCOPE` for just this call. */
11
+ scope?: Scope;
12
+ }
13
+ /**
14
+ * Resolves the registry database path with the following precedence
15
+ * (highest → lowest), exactly as specified in
16
+ * `docs/environment/agent-base-env/DESIGN.md` Decision 4:
17
+ *
18
+ * 1. `opts.registryDbPath` — explicit caller-supplied override.
19
+ * 2. `ADHD_AGENT_REGISTRY_DB_PATH` — agent-mcp's current,
20
+ * `ADHD_AGENT_*`-prefixed convention.
21
+ * 3. `REGISTRY_DATABASE_PATH` — the more specific of the two legacy
22
+ * family env-var names (`agent-store-prompts`/`agent-engine-compiler`
23
+ * `db/client.ts`).
24
+ * 4. `DATABASE_PATH` — the generic legacy name (all 5 clients accepted it
25
+ * as a fallback).
26
+ * 5. The `@adhd/environment`-resolved canonical default —
27
+ * `~/.adhd/agent-registry/production/data/registry.db` (or under
28
+ * `ADHD_ENV_SCOPE=project`'s project root, or `opts.scope`).
29
+ *
30
+ * This precedence lives as explicit code (not a single `FieldSpec.env`
31
+ * mapping) because 3 independent legacy env-var names must all keep
32
+ * resolving — `FieldSpec` only carries one explicit env name per field.
33
+ *
34
+ * Never auto-migrates or copies any file that happens to already exist at
35
+ * a legacy path — it only computes where the canonical file should live.
36
+ */
37
+ export declare function resolveRegistryDbPath(opts?: ResolveRegistryDbPathOpts): string;
package/spec.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { EnvironmentSpec } from '@adhd/environment';
2
+
3
+ /** The resolved, nested `env.config` shape for the `'agent-registry'`
4
+ * `Environment` instance. Empty — see module doc above. */
5
+ export interface AgentRegistryEnvConfig {
6
+ }
7
+ /** Logical `Environment` project id shared by every registry-family package. */
8
+ export declare const AGENT_REGISTRY_PROJECT_ID = "agent-registry";
9
+ export declare const agentRegistryEnvironmentSpec: EnvironmentSpec<AgentRegistryEnvConfig>;