@agentic-kit/harness 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +176 -0
  3. package/blueprint/blueprint-defaults.d.ts +2 -0
  4. package/blueprint/blueprint-defaults.js +123 -0
  5. package/blueprint/blueprint-schema.d.ts +138 -0
  6. package/blueprint/blueprint-schema.js +86 -0
  7. package/blueprint/field-type.d.ts +25 -0
  8. package/blueprint/field-type.js +99 -0
  9. package/blueprint/internal-policies.d.ts +2 -0
  10. package/blueprint/internal-policies.js +14 -0
  11. package/blueprint/policy-provisioning.d.ts +79 -0
  12. package/blueprint/policy-provisioning.js +570 -0
  13. package/esm/blueprint/blueprint-defaults.d.ts +2 -0
  14. package/esm/blueprint/blueprint-defaults.js +120 -0
  15. package/esm/blueprint/blueprint-schema.d.ts +138 -0
  16. package/esm/blueprint/blueprint-schema.js +83 -0
  17. package/esm/blueprint/field-type.d.ts +25 -0
  18. package/esm/blueprint/field-type.js +94 -0
  19. package/esm/blueprint/internal-policies.d.ts +2 -0
  20. package/esm/blueprint/internal-policies.js +10 -0
  21. package/esm/blueprint/policy-provisioning.d.ts +79 -0
  22. package/esm/blueprint/policy-provisioning.js +553 -0
  23. package/esm/gating/confirm-gate.d.ts +46 -0
  24. package/esm/gating/confirm-gate.js +55 -0
  25. package/esm/gating/decline-guard.d.ts +7 -0
  26. package/esm/gating/decline-guard.js +48 -0
  27. package/esm/gating/preview.d.ts +37 -0
  28. package/esm/gating/preview.js +5 -0
  29. package/esm/gating/prompts.d.ts +8 -0
  30. package/esm/gating/prompts.js +175 -0
  31. package/esm/index.d.ts +20 -0
  32. package/esm/index.js +20 -0
  33. package/esm/skills/fetch.d.ts +31 -0
  34. package/esm/skills/fetch.js +84 -0
  35. package/esm/skills/frontmatter.d.ts +7 -0
  36. package/esm/skills/frontmatter.js +28 -0
  37. package/esm/skills/integrity.d.ts +8 -0
  38. package/esm/skills/integrity.js +28 -0
  39. package/esm/skills/manifest.d.ts +39 -0
  40. package/esm/skills/manifest.js +36 -0
  41. package/esm/skills/materialize.d.ts +13 -0
  42. package/esm/skills/materialize.js +26 -0
  43. package/esm/skills/overlay.d.ts +11 -0
  44. package/esm/skills/overlay.js +25 -0
  45. package/esm/skills/registry.d.ts +36 -0
  46. package/esm/skills/registry.js +30 -0
  47. package/esm/skills/source.d.ts +21 -0
  48. package/esm/skills/source.js +51 -0
  49. package/esm/skills/update-check.d.ts +36 -0
  50. package/esm/skills/update-check.js +74 -0
  51. package/esm/stash.d.ts +20 -0
  52. package/esm/stash.js +19 -0
  53. package/esm/types.d.ts +60 -0
  54. package/esm/types.js +8 -0
  55. package/gating/confirm-gate.d.ts +46 -0
  56. package/gating/confirm-gate.js +58 -0
  57. package/gating/decline-guard.d.ts +7 -0
  58. package/gating/decline-guard.js +52 -0
  59. package/gating/preview.d.ts +37 -0
  60. package/gating/preview.js +6 -0
  61. package/gating/prompts.d.ts +8 -0
  62. package/gating/prompts.js +179 -0
  63. package/index.d.ts +20 -0
  64. package/index.js +36 -0
  65. package/package.json +42 -0
  66. package/skills/fetch.d.ts +31 -0
  67. package/skills/fetch.js +122 -0
  68. package/skills/frontmatter.d.ts +7 -0
  69. package/skills/frontmatter.js +31 -0
  70. package/skills/integrity.d.ts +8 -0
  71. package/skills/integrity.js +64 -0
  72. package/skills/manifest.d.ts +39 -0
  73. package/skills/manifest.js +40 -0
  74. package/skills/materialize.d.ts +13 -0
  75. package/skills/materialize.js +62 -0
  76. package/skills/overlay.d.ts +11 -0
  77. package/skills/overlay.js +28 -0
  78. package/skills/registry.d.ts +36 -0
  79. package/skills/registry.js +34 -0
  80. package/skills/source.d.ts +21 -0
  81. package/skills/source.js +88 -0
  82. package/skills/update-check.d.ts +36 -0
  83. package/skills/update-check.js +110 -0
  84. package/stash.d.ts +20 -0
  85. package/stash.js +55 -0
  86. package/types.d.ts +60 -0
  87. package/types.js +9 -0
package/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Dan Lynch <pyramation@gmail.com>
4
+ Copyright (c) 2025 Constructive <developers@constructive.io>
5
+ Copyright (c) 2020-present, Interweb, Inc.
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,176 @@
1
+ # @agentic-kit/harness
2
+
3
+ Host-agnostic core of the **Constructive harness** — the layer that turns a
4
+ generic coding agent into a Constructive app builder. Code only: **no skills
5
+ are bundled in this package**. Skills are pulled at runtime from
6
+ [`constructive-skills`](https://github.com/constructive-io/constructive-skills)
7
+ (plus optional overlays), so guidance stays fresh without a host release.
8
+
9
+ Planning: [constructive-planning#1273](https://github.com/constructive-io/constructive-planning/issues/1273)
10
+ (extraction) and [#1274](https://github.com/constructive-io/constructive-planning/issues/1274)
11
+ (skills consolidation).
12
+
13
+ ## Layering
14
+
15
+ ```
16
+ @agentic-kit/protocol → agentic-kit → @agentic-kit/agent (LLM/runtime substrate)
17
+ ↓
18
+ @agentic-kit/harness (this package)
19
+ ↓
20
+ pi/Electron desktop adapter | terminal CLI | MCP server | exports
21
+ ```
22
+
23
+ Hosts inject a `HarnessContext` (cwd, endpoints, credentials, confirm gate);
24
+ the core owns everything host-neutral.
25
+
26
+ ## What's here today
27
+
28
+ - `HarnessContext` / `HarnessCredentials` / `GateRequest` — the injection
29
+ contracts identified in the desktop extraction research.
30
+ - `harnessDirs()` — on-disk layout via [`appstash`](https://www.npmjs.com/package/appstash)
31
+ (`~/.constructive/{config,cache,data,logs}` with XDG/tmp fallbacks):
32
+ downloaded skill releases under `data/skills/<version>`, the merged tree
33
+ under `cache/skills-materialized`, update-check metadata in `cache/`.
34
+ - Release fetching + freshness:
35
+ - `fetchSkillsRelease()` — resolves a pin (exact version, semver range, or
36
+ dist-tag) against the npm registry, downloads the tarball, verifies its
37
+ SRI integrity, and unpacks it to `data/skills/<version>/`. Already
38
+ downloaded releases are reused without network (offline fallback;
39
+ `latestLocalRelease()` picks the newest local one when the registry is
40
+ unreachable).
41
+ - `checkForSkillsUpdate()` — registry update check cached in
42
+ `cache/skills-update-check.json` (TTL, default 24h); only recommends
43
+ releases inside `compatibleSkillsRange`, and flags
44
+ `harnessUpgradeRequired` when newer skills need newer tool code. Never
45
+ throws — falls back to cache or "no update" offline.
46
+ - Ordered-overlay skill resolution:
47
+ - `SkillsManifest` — ordered source layers, each with its own version pin
48
+ and include/exclude filters, plus `compatibleSkillsRange` so updaters
49
+ never adopt a skills release the installed tool code doesn't support.
50
+ - `DirectorySkillSource` — loads the agentskills.io layout
51
+ (`<skill>/SKILL.md` + references/scripts).
52
+ - `resolveSkills()` — last-write-wins merge across layers (hardened base →
53
+ team overlays → private known-gaps overlay).
54
+ - `materializeSkills()` — writes the merged tree with `{{VAR}}`
55
+ substitution (e.g. `HARNESS_TEMPLATES_DIR`).
56
+
57
+ - Tool-call gating (`src/gating/`, extracted from `constructive-desktop`):
58
+ - `createConfirmGate()` — host-neutral confirm gate for the mutating db
59
+ tools: per-run decline memory (a declined call re-issued with equivalent
60
+ args is auto-blocked without re-prompting), runnable-project/token
61
+ short-circuits, and blueprint/records/policy previews. Hosts inject a
62
+ `GateHost` (confirm UI + skip notification); the pi adapter maps pi's
63
+ `tool_call` extension event onto `GateToolCallEvent`/`GateResult` 1:1.
64
+ - `buildConfirmPrompt()` / `MUTATING_DB_TOOLS` / `ConfirmPreview` — the
65
+ per-tool confirmation copy and structured previews hosts render.
66
+ - Blueprint domain logic (`src/blueprint/`): `expandBlueprintDefaults()`
67
+ (derive Data* nodes, default grants, policy field defaults),
68
+ `BlueprintDefinitionSchema` (typebox), field type/default parsing, and the
69
+ vendored policy-provisioning config tables.
70
+
71
+ ## Roadmap (per #1273)
72
+
73
+ - Typed db-tools (`provision_database`, `provision_blueprint`, `run_codegen`,
74
+ …) extracted from `constructive-desktop` against `HarnessContext` (needs
75
+ the generated modules ORM published or generated in-package).
76
+ - pi adapter, terminal CLI, and `.claude`/MCP export surfaces.
77
+
78
+ ```ts
79
+ import {
80
+ DirectorySkillSource,
81
+ harnessDirs,
82
+ materializeSkills,
83
+ resolveSkills,
84
+ } from '@agentic-kit/harness';
85
+
86
+ const dirs = harnessDirs();
87
+ const skills = await resolveSkills(
88
+ {
89
+ sources: [
90
+ { name: 'constructive-skills', pin: '1.2.0' },
91
+ { name: 'known-gaps', pin: 'abc1234' },
92
+ ],
93
+ compatibleSkillsRange: '^1.2.0',
94
+ },
95
+ [
96
+ new DirectorySkillSource('constructive-skills', dirs.skillsVersionDir('1.2.0')),
97
+ new DirectorySkillSource('known-gaps', '/path/to/private/overlay'),
98
+ ]
99
+ );
100
+ materializeSkills(dirs.materializedDir, skills, {
101
+ templateVars: { HARNESS_TEMPLATES_DIR: '/path/to/templates' },
102
+ });
103
+ ```
104
+
105
+ ---
106
+
107
+ ## Education and Tutorials
108
+
109
+ 1. 🚀 [Quickstart: Getting Up and Running](https://constructive.io/learn/quickstart)
110
+ Get started with modular databases in minutes. Install prerequisites and deploy your first module.
111
+
112
+ 2. 📦 [Modular PostgreSQL Development with Database Packages](https://constructive.io/learn/modular-postgres)
113
+ Learn to organize PostgreSQL projects with pgpm workspaces and reusable database modules.
114
+
115
+ 3. ✏️ [Authoring Database Changes](https://constructive.io/learn/authoring-database-changes)
116
+ Master the workflow for adding, organizing, and managing database changes with pgpm.
117
+
118
+ 4. 🧪 [End-to-End PostgreSQL Testing with TypeScript](https://constructive.io/learn/e2e-postgres-testing)
119
+ Master end-to-end PostgreSQL testing with ephemeral databases, RLS testing, and CI/CD automation.
120
+
121
+ 5. ⚡ [Supabase Testing](https://constructive.io/learn/supabase)
122
+ Use TypeScript-first tools to test Supabase projects with realistic RLS, policies, and auth contexts.
123
+
124
+ 6. 💧 [Drizzle ORM Testing](https://constructive.io/learn/drizzle-testing)
125
+ Run full-stack tests with Drizzle ORM, including database setup, teardown, and RLS enforcement.
126
+
127
+ 7. 🔧 [Troubleshooting](https://constructive.io/learn/troubleshooting)
128
+ Common issues and solutions for pgpm, PostgreSQL, and testing.
129
+
130
+ ## Related Constructive Tooling
131
+
132
+ ### 📦 Package Management
133
+
134
+ * [pgpm](https://github.com/constructive-io/constructive/tree/main/pgpm/pgpm): **🖥️ PostgreSQL Package Manager** for modular Postgres development. Works with database workspaces, scaffolding, migrations, seeding, and installing database packages.
135
+
136
+ ### 🧪 Testing
137
+
138
+ * [pgsql-test](https://github.com/constructive-io/constructive/tree/main/postgres/pgsql-test): **📊 Isolated testing environments** with per-test transaction rollbacks—ideal for integration tests, complex migrations, and RLS simulation.
139
+ * [pgsql-seed](https://github.com/constructive-io/constructive/tree/main/postgres/pgsql-seed): **🌱 PostgreSQL seeding utilities** for CSV, JSON, SQL data loading, and pgpm deployment.
140
+ * [supabase-test](https://github.com/constructive-io/constructive/tree/main/postgres/supabase-test): **🧪 Supabase-native test harness** preconfigured for the local Supabase stack—per-test rollbacks, JWT/role context helpers, and CI/GitHub Actions ready.
141
+ * [graphile-test](https://github.com/constructive-io/constructive/tree/main/graphile/graphile-test): **🔐 Authentication mocking** for Graphile-focused test helpers and emulating row-level security contexts.
142
+ * [pg-query-context](https://github.com/constructive-io/constructive/tree/main/postgres/pg-query-context): **🔒 Session context injection** to add session-local context (e.g., `SET LOCAL`) into queries—ideal for setting `role`, `jwt.claims`, and other session settings.
143
+
144
+ ### 🧠 Parsing & AST
145
+
146
+ * [pgsql-parser](https://www.npmjs.com/package/pgsql-parser): **🔄 SQL conversion engine** that interprets and converts PostgreSQL syntax.
147
+ * [libpg-query-node](https://www.npmjs.com/package/libpg-query): **🌉 Node.js bindings** for `libpg_query`, converting SQL into parse trees.
148
+ * [pg-proto-parser](https://www.npmjs.com/package/pg-proto-parser): **📦 Protobuf parser** for parsing PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
149
+ * [@pgsql/enums](https://www.npmjs.com/package/@pgsql/enums): **🏷️ TypeScript enums** for PostgreSQL AST for safe and ergonomic parsing logic.
150
+ * [@pgsql/types](https://www.npmjs.com/package/@pgsql/types): **📝 Type definitions** for PostgreSQL AST nodes in TypeScript.
151
+ * [@pgsql/utils](https://www.npmjs.com/package/@pgsql/utils): **🛠️ AST utilities** for constructing and transforming PostgreSQL syntax trees.
152
+
153
+ ### 📚 Documentation & Skills
154
+
155
+ * [constructive-skills](https://github.com/constructive-io/constructive-skills): **📖 Platform documentation and AI agent skills** — feature catalog, blueprint reference, SDK guides (i18n, billing, limits, events, uploads, security, entities, search, AI), and deployment guides.
156
+
157
+ Install skills for AI coding agents:
158
+
159
+ ```bash
160
+ # All platform skills (security, blueprints, codegen, billing, etc.)
161
+ npx skills add constructive-io/constructive-skills
162
+
163
+ # Individual repo skills (pgpm, testing, CLI, search, etc.)
164
+ npx skills add https://github.com/constructive-io/constructive --skill pgpm
165
+ npx skills add https://github.com/constructive-io/constructive --skill constructive-testing
166
+ ```
167
+
168
+ ## Credits
169
+
170
+ **🛠 Built by the [Constructive](https://constructive.io) team — creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on [GitHub](https://github.com/constructive-io).**
171
+
172
+ ## Disclaimer
173
+
174
+ AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
175
+
176
+ No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
@@ -0,0 +1,2 @@
1
+ import type { BlueprintDefinition } from './blueprint-schema';
2
+ export declare function expandBlueprintDefaults(definition: BlueprintDefinition): Record<string, unknown>;
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.expandBlueprintDefaults = expandBlueprintDefaults;
4
+ const field_type_1 = require("./field-type");
5
+ const policy_provisioning_1 = require("./policy-provisioning");
6
+ const DEFAULT_GRANTS = [
7
+ {
8
+ roles: ['authenticated'],
9
+ privileges: [
10
+ ['select', '*'],
11
+ ['insert', '*'],
12
+ ['update', '*'],
13
+ ['delete', '*'],
14
+ ],
15
+ },
16
+ ];
17
+ const ALL_PRIVILEGES = ['select', 'insert', 'update', 'delete'];
18
+ function expandBlueprintDefaults(definition) {
19
+ const tables = definition.tables.map((table) => {
20
+ let nodes = table.nodes;
21
+ if (!nodes || nodes.length === 0) {
22
+ const derived = ['DataId'];
23
+ for (const policy of table.policies) {
24
+ const config = (0, policy_provisioning_1.getPolicyProvisioningConfig)(policy.$type);
25
+ if (config?.dataNodeType) {
26
+ const defaults = (0, policy_provisioning_1.getPolicyFieldDefaults)(policy.$type);
27
+ const policyData = { ...defaults, ...(policy.data ?? {}) };
28
+ const nodeData = (0, policy_provisioning_1.buildNodeData)(policy.$type, policyData);
29
+ const entry = {
30
+ $type: config.dataNodeType,
31
+ };
32
+ if (Object.keys(nodeData).length > 0)
33
+ entry.data = nodeData;
34
+ derived.push(entry);
35
+ }
36
+ }
37
+ derived.push('DataTimestamps');
38
+ nodes = derived;
39
+ }
40
+ else {
41
+ const getType = (n) => (typeof n === 'string' ? n : n.$type);
42
+ const existingTypes = new Set(nodes.map(getType));
43
+ if (!existingTypes.has('DataId')) {
44
+ nodes = ['DataId', ...nodes];
45
+ existingTypes.add('DataId');
46
+ }
47
+ else if (getType(nodes[0]) !== 'DataId') {
48
+ nodes = ['DataId', ...nodes.filter((n) => getType(n) !== 'DataId')];
49
+ }
50
+ const missing = [];
51
+ for (const policy of table.policies) {
52
+ const config = (0, policy_provisioning_1.getPolicyProvisioningConfig)(policy.$type);
53
+ if (config?.dataNodeType && !existingTypes.has(config.dataNodeType)) {
54
+ const defaults = (0, policy_provisioning_1.getPolicyFieldDefaults)(policy.$type);
55
+ const policyData = { ...defaults, ...(policy.data ?? {}) };
56
+ const nodeData = (0, policy_provisioning_1.buildNodeData)(policy.$type, policyData);
57
+ const entry = {
58
+ $type: config.dataNodeType,
59
+ };
60
+ if (Object.keys(nodeData).length > 0)
61
+ entry.data = nodeData;
62
+ missing.push(entry);
63
+ existingTypes.add(config.dataNodeType);
64
+ }
65
+ }
66
+ if (!existingTypes.has('DataTimestamps')) {
67
+ nodes = [...nodes, ...missing, 'DataTimestamps'];
68
+ }
69
+ else if (missing.length > 0) {
70
+ const tsIdx = nodes.findIndex((n) => getType(n) === 'DataTimestamps');
71
+ if (tsIdx >= 0) {
72
+ nodes = [...nodes.slice(0, tsIdx), ...missing, ...nodes.slice(tsIdx)];
73
+ }
74
+ else {
75
+ nodes = [...nodes, ...missing];
76
+ }
77
+ }
78
+ }
79
+ const policies = table.policies.map((p) => {
80
+ const defaults = (0, policy_provisioning_1.getPolicyFieldDefaults)(p.$type);
81
+ const data = Object.keys(defaults).length > 0
82
+ ? { ...defaults, ...(p.data ?? {}) }
83
+ : p.data;
84
+ return {
85
+ ...p,
86
+ ...(data && { data }),
87
+ privileges: p.privileges ?? ALL_PRIVILEGES,
88
+ policy_role: p.policy_role ?? 'authenticated',
89
+ permissive: p.permissive ?? true,
90
+ };
91
+ });
92
+ const autoFields = new Set(['id']);
93
+ for (const node of nodes) {
94
+ const nodeType = typeof node === 'string' ? node : node.$type;
95
+ for (const f of policy_provisioning_1.DATA_NODE_GENERATED_FIELDS[nodeType] ?? []) {
96
+ autoFields.add(f.name);
97
+ }
98
+ }
99
+ const fields = table.fields
100
+ ?.filter((f) => !autoFields.has(f.name))
101
+ .map((f) => {
102
+ const out = { name: f.name, type: (0, field_type_1.toFieldType)(f.type) };
103
+ if (f.is_required)
104
+ out.is_required = true;
105
+ const def = (0, field_type_1.toFieldDefault)(f.default);
106
+ if (def !== undefined)
107
+ out.default = def;
108
+ return out;
109
+ });
110
+ return {
111
+ table_name: table.table_name,
112
+ use_rls: true,
113
+ grants: DEFAULT_GRANTS,
114
+ nodes,
115
+ policies,
116
+ ...(fields && fields.length > 0 && { fields }),
117
+ };
118
+ });
119
+ return {
120
+ tables,
121
+ ...(definition.relations && definition.relations.length > 0 && { relations: definition.relations }),
122
+ };
123
+ }
@@ -0,0 +1,138 @@
1
+ import { type Static, Type } from 'typebox';
2
+ declare const FieldBlueprint: Type.TObject<{
3
+ name: Type.TString;
4
+ type: Type.TString;
5
+ is_required: Type.TOptional<Type.TBoolean>;
6
+ default: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
7
+ }>;
8
+ declare const PolicyBlueprint: Type.TObject<{
9
+ $type: Type.TString;
10
+ data: Type.TOptional<Type.TRecord<"^.*$", Type.TUnknown>>;
11
+ privileges: Type.TOptional<Type.TArray<Type.TString>>;
12
+ policy_role: Type.TOptional<Type.TString>;
13
+ permissive: Type.TOptional<Type.TBoolean>;
14
+ }>;
15
+ declare const NodeBlueprint: Type.TUnion<[Type.TString, Type.TObject<{
16
+ $type: Type.TString;
17
+ data: Type.TOptional<Type.TRecord<"^.*$", Type.TUnknown>>;
18
+ }>]>;
19
+ declare const RelationBlueprint: Type.TUnion<[Type.TObject<{
20
+ $type: Type.TLiteral<"RelationBelongsTo">;
21
+ source_table: Type.TString;
22
+ target_table: Type.TString;
23
+ field_name: Type.TString;
24
+ delete_action: Type.TOptional<Type.TUnion<[Type.TLiteral<"c">, Type.TLiteral<"r">, Type.TLiteral<"n">, Type.TLiteral<"a">, Type.TLiteral<"d">]>>;
25
+ is_required: Type.TOptional<Type.TBoolean>;
26
+ }>, Type.TObject<{
27
+ $type: Type.TLiteral<"RelationManyToMany">;
28
+ source_table: Type.TString;
29
+ target_table: Type.TString;
30
+ junction_table_name: Type.TString;
31
+ delete_action: Type.TOptional<Type.TUnion<[Type.TLiteral<"c">, Type.TLiteral<"r">, Type.TLiteral<"n">, Type.TLiteral<"a">, Type.TLiteral<"d">]>>;
32
+ }>]>;
33
+ declare const TableBlueprint: Type.TObject<{
34
+ table_name: Type.TString;
35
+ nodes: Type.TOptional<Type.TArray<Type.TUnion<[Type.TString, Type.TObject<{
36
+ $type: Type.TString;
37
+ data: Type.TOptional<Type.TRecord<"^.*$", Type.TUnknown>>;
38
+ }>]>>>;
39
+ fields: Type.TOptional<Type.TArray<Type.TObject<{
40
+ name: Type.TString;
41
+ type: Type.TString;
42
+ is_required: Type.TOptional<Type.TBoolean>;
43
+ default: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
44
+ }>>>;
45
+ policies: Type.TArray<Type.TObject<{
46
+ $type: Type.TString;
47
+ data: Type.TOptional<Type.TRecord<"^.*$", Type.TUnknown>>;
48
+ privileges: Type.TOptional<Type.TArray<Type.TString>>;
49
+ policy_role: Type.TOptional<Type.TString>;
50
+ permissive: Type.TOptional<Type.TBoolean>;
51
+ }>>;
52
+ }>;
53
+ export declare const BlueprintDefinitionSchema: Type.TObject<{
54
+ tables: Type.TArray<Type.TObject<{
55
+ table_name: Type.TString;
56
+ nodes: Type.TOptional<Type.TArray<Type.TUnion<[Type.TString, Type.TObject<{
57
+ $type: Type.TString;
58
+ data: Type.TOptional<Type.TRecord<"^.*$", Type.TUnknown>>;
59
+ }>]>>>;
60
+ fields: Type.TOptional<Type.TArray<Type.TObject<{
61
+ name: Type.TString;
62
+ type: Type.TString;
63
+ is_required: Type.TOptional<Type.TBoolean>;
64
+ default: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
65
+ }>>>;
66
+ policies: Type.TArray<Type.TObject<{
67
+ $type: Type.TString;
68
+ data: Type.TOptional<Type.TRecord<"^.*$", Type.TUnknown>>;
69
+ privileges: Type.TOptional<Type.TArray<Type.TString>>;
70
+ policy_role: Type.TOptional<Type.TString>;
71
+ permissive: Type.TOptional<Type.TBoolean>;
72
+ }>>;
73
+ }>>;
74
+ relations: Type.TOptional<Type.TArray<Type.TUnion<[Type.TObject<{
75
+ $type: Type.TLiteral<"RelationBelongsTo">;
76
+ source_table: Type.TString;
77
+ target_table: Type.TString;
78
+ field_name: Type.TString;
79
+ delete_action: Type.TOptional<Type.TUnion<[Type.TLiteral<"c">, Type.TLiteral<"r">, Type.TLiteral<"n">, Type.TLiteral<"a">, Type.TLiteral<"d">]>>;
80
+ is_required: Type.TOptional<Type.TBoolean>;
81
+ }>, Type.TObject<{
82
+ $type: Type.TLiteral<"RelationManyToMany">;
83
+ source_table: Type.TString;
84
+ target_table: Type.TString;
85
+ junction_table_name: Type.TString;
86
+ delete_action: Type.TOptional<Type.TUnion<[Type.TLiteral<"c">, Type.TLiteral<"r">, Type.TLiteral<"n">, Type.TLiteral<"a">, Type.TLiteral<"d">]>>;
87
+ }>]>>>;
88
+ }>;
89
+ export declare const BlueprintSchema: Type.TObject<{
90
+ name: Type.TString;
91
+ description: Type.TString;
92
+ definition: Type.TObject<{
93
+ tables: Type.TArray<Type.TObject<{
94
+ table_name: Type.TString;
95
+ nodes: Type.TOptional<Type.TArray<Type.TUnion<[Type.TString, Type.TObject<{
96
+ $type: Type.TString;
97
+ data: Type.TOptional<Type.TRecord<"^.*$", Type.TUnknown>>;
98
+ }>]>>>;
99
+ fields: Type.TOptional<Type.TArray<Type.TObject<{
100
+ name: Type.TString;
101
+ type: Type.TString;
102
+ is_required: Type.TOptional<Type.TBoolean>;
103
+ default: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
104
+ }>>>;
105
+ policies: Type.TArray<Type.TObject<{
106
+ $type: Type.TString;
107
+ data: Type.TOptional<Type.TRecord<"^.*$", Type.TUnknown>>;
108
+ privileges: Type.TOptional<Type.TArray<Type.TString>>;
109
+ policy_role: Type.TOptional<Type.TString>;
110
+ permissive: Type.TOptional<Type.TBoolean>;
111
+ }>>;
112
+ }>>;
113
+ relations: Type.TOptional<Type.TArray<Type.TUnion<[Type.TObject<{
114
+ $type: Type.TLiteral<"RelationBelongsTo">;
115
+ source_table: Type.TString;
116
+ target_table: Type.TString;
117
+ field_name: Type.TString;
118
+ delete_action: Type.TOptional<Type.TUnion<[Type.TLiteral<"c">, Type.TLiteral<"r">, Type.TLiteral<"n">, Type.TLiteral<"a">, Type.TLiteral<"d">]>>;
119
+ is_required: Type.TOptional<Type.TBoolean>;
120
+ }>, Type.TObject<{
121
+ $type: Type.TLiteral<"RelationManyToMany">;
122
+ source_table: Type.TString;
123
+ target_table: Type.TString;
124
+ junction_table_name: Type.TString;
125
+ delete_action: Type.TOptional<Type.TUnion<[Type.TLiteral<"c">, Type.TLiteral<"r">, Type.TLiteral<"n">, Type.TLiteral<"a">, Type.TLiteral<"d">]>>;
126
+ }>]>>>;
127
+ }>;
128
+ categories: Type.TOptional<Type.TArray<Type.TString>>;
129
+ tags: Type.TOptional<Type.TArray<Type.TString>>;
130
+ }>;
131
+ export type Blueprint = Static<typeof BlueprintSchema>;
132
+ export type BlueprintDefinition = Static<typeof BlueprintDefinitionSchema>;
133
+ export type TableBlueprint = Static<typeof TableBlueprint>;
134
+ export type FieldBlueprint = Static<typeof FieldBlueprint>;
135
+ export type PolicyBlueprint = Static<typeof PolicyBlueprint>;
136
+ export type RelationBlueprint = Static<typeof RelationBlueprint>;
137
+ export type NodeBlueprint = Static<typeof NodeBlueprint>;
138
+ export {};
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BlueprintSchema = exports.BlueprintDefinitionSchema = void 0;
4
+ const typebox_1 = require("typebox");
5
+ const FieldBlueprint = typebox_1.Type.Object({
6
+ name: typebox_1.Type.String({ description: 'Field name in snake_case' }),
7
+ type: typebox_1.Type.String({
8
+ description: 'PostgreSQL type: uuid, text, integer, smallint, numeric, boolean, date, timestamp, timestamptz, time, json, jsonb, inet, citext, email, url, image, upload',
9
+ }),
10
+ is_required: typebox_1.Type.Optional(typebox_1.Type.Boolean({ description: 'Whether the field is NOT NULL' })),
11
+ default: typebox_1.Type.Optional(typebox_1.Type.Union([typebox_1.Type.String(), typebox_1.Type.Null()], {
12
+ description: 'SQL default expression, e.g. "uuidv7()", "now()", "\'draft\'"',
13
+ })),
14
+ });
15
+ const PolicyBlueprint = typebox_1.Type.Object({
16
+ $type: typebox_1.Type.String({
17
+ description: 'Policy type: AuthzDirectOwner, AuthzEntityMembership, AuthzAllowAll, AuthzPublishable, AuthzAppMembership',
18
+ }),
19
+ data: typebox_1.Type.Optional(typebox_1.Type.Record(typebox_1.Type.String(), typebox_1.Type.Unknown(), { description: 'Policy config overrides' })),
20
+ privileges: typebox_1.Type.Optional(typebox_1.Type.Array(typebox_1.Type.String(), {
21
+ description: 'SQL privileges this policy applies to, lowercase, e.g. ["select","insert","update","delete"]. Defaults to all.',
22
+ })),
23
+ policy_role: typebox_1.Type.Optional(typebox_1.Type.String({ description: 'Role name. Defaults to "authenticated".' })),
24
+ permissive: typebox_1.Type.Optional(typebox_1.Type.Boolean({
25
+ description: 'Whether permissive (true) or restrictive (false). Defaults to true.',
26
+ })),
27
+ });
28
+ const NodeBlueprint = typebox_1.Type.Union([
29
+ typebox_1.Type.String({ description: 'Node type shorthand, e.g. "DataTimestamps"' }),
30
+ typebox_1.Type.Object({
31
+ $type: typebox_1.Type.String({ description: 'Node type, e.g. "DataDirectOwner"' }),
32
+ data: typebox_1.Type.Optional(typebox_1.Type.Record(typebox_1.Type.String(), typebox_1.Type.Unknown(), { description: 'Node configuration data' })),
33
+ }),
34
+ ]);
35
+ const DeleteAction = typebox_1.Type.Union([
36
+ typebox_1.Type.Literal('c'),
37
+ typebox_1.Type.Literal('r'),
38
+ typebox_1.Type.Literal('n'),
39
+ typebox_1.Type.Literal('a'),
40
+ typebox_1.Type.Literal('d'),
41
+ ], {
42
+ description: 'FK delete action: c=CASCADE, r=RESTRICT, n=SET NULL, a=NO ACTION (default), d=SET DEFAULT',
43
+ });
44
+ const BelongsToRelation = typebox_1.Type.Object({
45
+ $type: typebox_1.Type.Literal('RelationBelongsTo'),
46
+ source_table: typebox_1.Type.String({ description: 'Source table name' }),
47
+ target_table: typebox_1.Type.String({ description: 'Target table name' }),
48
+ field_name: typebox_1.Type.String({ description: 'FK column name on the source table, e.g. "author_id"' }),
49
+ delete_action: typebox_1.Type.Optional(DeleteAction),
50
+ is_required: typebox_1.Type.Optional(typebox_1.Type.Boolean({ description: 'Whether the FK is NOT NULL (default: true)' })),
51
+ });
52
+ const ManyToManyRelation = typebox_1.Type.Object({
53
+ $type: typebox_1.Type.Literal('RelationManyToMany'),
54
+ source_table: typebox_1.Type.String({ description: 'Source table name' }),
55
+ target_table: typebox_1.Type.String({ description: 'Target table name' }),
56
+ junction_table_name: typebox_1.Type.String({ description: 'Junction table name, e.g. "post_tags"' }),
57
+ delete_action: typebox_1.Type.Optional(DeleteAction),
58
+ });
59
+ const RelationBlueprint = typebox_1.Type.Union([BelongsToRelation, ManyToManyRelation]);
60
+ const TableBlueprint = typebox_1.Type.Object({
61
+ table_name: typebox_1.Type.String({ description: 'PostgreSQL table name in snake_case, plural' }),
62
+ nodes: typebox_1.Type.Optional(typebox_1.Type.Array(NodeBlueprint, {
63
+ description: 'Data behavior nodes (e.g. DataTimestamps, DataSoftDelete). DataId and DataTimestamps are auto-included.',
64
+ })),
65
+ fields: typebox_1.Type.Optional(typebox_1.Type.Array(FieldBlueprint, {
66
+ description: 'Custom fields only — do NOT include id, timestamps, or node-generated fields (owner_id, entity_id, is_published, published_at)',
67
+ })),
68
+ policies: typebox_1.Type.Array(PolicyBlueprint, {
69
+ description: 'RLS policies for this table. At least one required.',
70
+ }),
71
+ });
72
+ exports.BlueprintDefinitionSchema = typebox_1.Type.Object({
73
+ tables: typebox_1.Type.Array(TableBlueprint, { description: 'Tables to create' }),
74
+ relations: typebox_1.Type.Optional(typebox_1.Type.Array(RelationBlueprint, { description: 'Relations between tables' })),
75
+ });
76
+ exports.BlueprintSchema = typebox_1.Type.Object({
77
+ name: typebox_1.Type.String({ description: 'Blueprint name in snake_case' }),
78
+ description: typebox_1.Type.String({ description: 'Brief description of what this schema is for' }),
79
+ definition: exports.BlueprintDefinitionSchema,
80
+ categories: typebox_1.Type.Optional(typebox_1.Type.Array(typebox_1.Type.String(), {
81
+ description: 'Template categories if saved as template, e.g. ["e-commerce", "healthcare"]',
82
+ })),
83
+ tags: typebox_1.Type.Optional(typebox_1.Type.Array(typebox_1.Type.String(), {
84
+ description: 'Freeform search tags if saved as template, e.g. ["products", "orders"]',
85
+ })),
86
+ });
@@ -0,0 +1,25 @@
1
+ export interface FieldType {
2
+ name: string;
3
+ schema?: string;
4
+ args?: (string | number | boolean)[];
5
+ array_dimensions?: number;
6
+ range?: string[];
7
+ }
8
+ export type FieldDefault = {
9
+ value: string | number | boolean | null | unknown[] | Record<string, unknown>;
10
+ cast?: FieldType;
11
+ } | {
12
+ function: string;
13
+ schema?: string;
14
+ args?: (FieldDefault | string | number | boolean | null)[];
15
+ cast?: FieldType;
16
+ } | {
17
+ operator: '+' | '-';
18
+ left: FieldDefault;
19
+ right: FieldDefault;
20
+ } | {
21
+ sql_keyword: string;
22
+ };
23
+ export declare function fieldTypeToTypeName(t: unknown): string;
24
+ export declare function toFieldType(typeName: string): FieldType;
25
+ export declare function toFieldDefault(def?: string | null): FieldDefault | undefined;