@agentic-kit/db-tools 0.15.1 → 0.16.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 (74) hide show
  1. package/README.md +4 -4
  2. package/blueprint/blueprint-schema.js +3 -1
  3. package/context.d.ts +9 -9
  4. package/context.js +92 -54
  5. package/db-probe.js +2 -2
  6. package/esm/blueprint/blueprint-schema.js +3 -1
  7. package/esm/context.d.ts +9 -9
  8. package/esm/context.js +91 -54
  9. package/esm/db-probe.js +2 -2
  10. package/esm/failure.d.ts +1 -1
  11. package/esm/failure.js +2 -2
  12. package/esm/gate.js +1 -1
  13. package/esm/graphql-http.d.ts +3 -2
  14. package/esm/graphql-http.js +26 -7
  15. package/esm/host.d.ts +20 -7
  16. package/esm/host.js +7 -2
  17. package/esm/index.d.ts +175 -14
  18. package/esm/index.js +5 -15
  19. package/esm/project-file.d.ts +72 -0
  20. package/esm/project-file.js +161 -0
  21. package/esm/provision-database/provision.d.ts +8 -3
  22. package/esm/provision-database/provision.js +63 -94
  23. package/esm/ready.d.ts +7 -3
  24. package/esm/ready.js +3 -3
  25. package/esm/records/rows.d.ts +1 -0
  26. package/esm/records/rows.js +9 -6
  27. package/esm/tools/access.js +1 -1
  28. package/esm/tools/create-api-key.js +2 -2
  29. package/esm/tools/delete-records.d.ts +1 -1
  30. package/esm/tools/delete-records.js +7 -7
  31. package/esm/tools/index.d.ts +195 -2
  32. package/esm/tools/index.js +25 -15
  33. package/esm/tools/mutations.js +7 -6
  34. package/esm/tools/provision-database.js +4 -4
  35. package/esm/tools/run-codegen.d.ts +2 -2
  36. package/esm/tools/run-codegen.js +10 -11
  37. package/esm/tools/update-records.js +1 -1
  38. package/failure.d.ts +1 -1
  39. package/failure.js +2 -2
  40. package/gate.js +1 -1
  41. package/graphql-http.d.ts +3 -2
  42. package/graphql-http.js +26 -7
  43. package/host.d.ts +20 -7
  44. package/host.js +7 -2
  45. package/index.d.ts +175 -14
  46. package/index.js +9 -45
  47. package/package.json +19 -16
  48. package/project-file.d.ts +72 -0
  49. package/project-file.js +178 -0
  50. package/provision-database/provision.d.ts +8 -3
  51. package/provision-database/provision.js +66 -96
  52. package/ready.d.ts +7 -3
  53. package/ready.js +3 -3
  54. package/records/rows.d.ts +1 -0
  55. package/records/rows.js +8 -5
  56. package/tools/access.js +1 -1
  57. package/tools/create-api-key.js +2 -2
  58. package/tools/delete-records.d.ts +1 -1
  59. package/tools/delete-records.js +8 -8
  60. package/tools/index.d.ts +195 -2
  61. package/tools/index.js +53 -43
  62. package/tools/mutations.js +6 -5
  63. package/tools/provision-database.js +5 -5
  64. package/tools/run-codegen.d.ts +2 -2
  65. package/tools/run-codegen.js +8 -9
  66. package/tools/update-records.js +1 -1
  67. package/esm/provision-database/env-file.d.ts +0 -62
  68. package/esm/provision-database/env-file.js +0 -170
  69. package/esm/provision-database/pending-ticket.d.ts +0 -33
  70. package/esm/provision-database/pending-ticket.js +0 -63
  71. package/provision-database/env-file.d.ts +0 -62
  72. package/provision-database/env-file.js +0 -179
  73. package/provision-database/pending-ticket.d.ts +0 -33
  74. package/provision-database/pending-ticket.js +0 -72
@@ -1,12 +1,205 @@
1
- import type { AnyHarnessTool, ConfirmPreview, PlanTableAccess, PlanTarget } from '@agentic-kit/harness';
1
+ import { type AnyHarnessTool, type ConfirmPreview, type PlanTableAccess, type PlanTarget } from '@agentic-kit/harness';
2
2
  import type { Result } from '../failure';
3
3
  /**
4
4
  * The Constructive database tools, in registration order.
5
5
  *
6
6
  * Plain `HarnessTool`s: a harness gets them by mapping them into its own tool
7
7
  * shape, which is the adapter's job, so this package stays free of any harness
8
- * dependency (see `toPiTool` in `@agentic-kit/pi` for that binding).
8
+ * dependency (see `toPiTool` in `@agentic-kit/pi` for that binding). Each tool
9
+ * that changes something checks at apply that its plan is still the one the
10
+ * person approved (`requireApproval`), when a gated host gives it a call id.
9
11
  */
12
+ export declare const servedTools: {
13
+ provisionDatabaseTool: import("@agentic-kit/harness").HarnessTool<import("zod").ZodObject<{
14
+ database_name: import("zod").ZodString;
15
+ }, import("zod/v4/core").$strict>, import("./provision-database").ProvisionDatabaseDetails>;
16
+ replaceDatabaseTool: import("@agentic-kit/harness").HarnessTool<import("zod").ZodObject<{
17
+ database_name: import("zod").ZodString;
18
+ }, import("zod/v4/core").$strict>, import("./provision-database").ProvisionDatabaseDetails>;
19
+ describeSchemaTool: import("@agentic-kit/harness").HarnessTool<import("zod").ZodObject<{}, import("zod/v4/core").$strict>, import("./describe-schema").DescribeSchemaDetails>;
20
+ listTemplatesTool: import("@agentic-kit/harness").HarnessTool<import("zod").ZodObject<{}, import("zod/v4/core").$strict>, import("./templates").ListTemplatesDetails>;
21
+ provisionBlueprintTool: import("@agentic-kit/harness").HarnessTool<import("zod").ZodObject<{
22
+ name: import("zod").ZodString;
23
+ description: import("zod").ZodString;
24
+ definition: import("zod").ZodObject<{
25
+ tables: import("zod").ZodArray<import("zod").ZodObject<{
26
+ table_name: import("zod").ZodOptional<import("zod").ZodString>;
27
+ fields: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
28
+ name: import("zod").ZodString;
29
+ }, import("zod/v4/core").$loose>>>;
30
+ }, import("zod/v4/core").$loose>>;
31
+ }, import("zod/v4/core").$loose>;
32
+ categories: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
33
+ tags: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
34
+ }, import("zod/v4/core").$strict>, import("./provision-blueprint").ProvisionBlueprintDetails>;
35
+ addRelationTool: import("@agentic-kit/harness").HarnessTool<import("zod").ZodObject<{
36
+ relation_type: import("zod").ZodOptional<import("zod").ZodEnum<{
37
+ belongs_to: "belongs_to";
38
+ many_to_many: "many_to_many";
39
+ }>>;
40
+ source_table: import("zod").ZodString;
41
+ target_table: import("zod").ZodString;
42
+ field_name: import("zod").ZodOptional<import("zod").ZodString>;
43
+ junction_table_name: import("zod").ZodOptional<import("zod").ZodString>;
44
+ delete_action: import("zod").ZodOptional<import("zod").ZodEnum<{
45
+ c: "c";
46
+ n: "n";
47
+ r: "r";
48
+ a: "a";
49
+ d: "d";
50
+ }>>;
51
+ is_required: import("zod").ZodOptional<import("zod").ZodBoolean>;
52
+ }, import("zod/v4/core").$strict>, import("./add-relation").AddRelationDetails>;
53
+ deleteTableTool: import("@agentic-kit/harness").HarnessTool<import("zod").ZodObject<{
54
+ table_name: import("zod").ZodString;
55
+ }, import("zod/v4/core").$strict>, import("./mutations").MutationDetails>;
56
+ createFieldTool: import("@agentic-kit/harness").HarnessTool<import("zod").ZodObject<{
57
+ table_name: import("zod").ZodString;
58
+ field_name: import("zod").ZodString;
59
+ type: import("zod").ZodString;
60
+ is_required: import("zod").ZodOptional<import("zod").ZodBoolean>;
61
+ default_value: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodNumber, import("zod").ZodBoolean, import("zod").ZodNull]>>;
62
+ is_unique: import("zod").ZodOptional<import("zod").ZodBoolean>;
63
+ }, import("zod/v4/core").$strict>, import("./mutations").MutationDetails>;
64
+ updateFieldTool: import("@agentic-kit/harness").HarnessTool<import("zod").ZodObject<{
65
+ table_name: import("zod").ZodString;
66
+ field_name: import("zod").ZodString;
67
+ new_name: import("zod").ZodOptional<import("zod").ZodString>;
68
+ is_required: import("zod").ZodOptional<import("zod").ZodBoolean>;
69
+ default_value: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodNumber, import("zod").ZodBoolean, import("zod").ZodNull]>>;
70
+ is_unique: import("zod").ZodOptional<import("zod").ZodBoolean>;
71
+ }, import("zod/v4/core").$strict>, import("./mutations").MutationDetails>;
72
+ retypeFieldTool: import("@agentic-kit/harness").HarnessTool<import("zod").ZodObject<{
73
+ table_name: import("zod").ZodString;
74
+ field_name: import("zod").ZodString;
75
+ type: import("zod").ZodString;
76
+ }, import("zod/v4/core").$strict>, import("./mutations").MutationDetails>;
77
+ deleteFieldTool: import("@agentic-kit/harness").HarnessTool<import("zod").ZodObject<{
78
+ table_name: import("zod").ZodString;
79
+ field_name: import("zod").ZodString;
80
+ }, import("zod/v4/core").$strict>, import("./mutations").MutationDetails>;
81
+ addPoliciesTool: import("@agentic-kit/harness").HarnessTool<import("zod").ZodObject<{
82
+ table_name: import("zod").ZodString;
83
+ policies: import("zod").ZodArray<import("zod").ZodObject<{
84
+ $type: import("zod").ZodString;
85
+ privileges: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
86
+ permissive: import("zod").ZodOptional<import("zod").ZodBoolean>;
87
+ policy_role: import("zod").ZodOptional<import("zod").ZodString>;
88
+ policy_name: import("zod").ZodOptional<import("zod").ZodString>;
89
+ data: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnknown>>;
90
+ }, import("zod/v4/core").$loose>>;
91
+ }, import("zod/v4/core").$strict>, import("./add-policies").AddPoliciesDetails>;
92
+ applyTemplateTool: import("@agentic-kit/harness").HarnessTool<import("zod").ZodObject<{
93
+ templateName: import("zod").ZodString;
94
+ nameOverride: import("zod").ZodOptional<import("zod").ZodString>;
95
+ }, import("zod/v4/core").$strict>, import("./templates").TemplateDetails>;
96
+ createTemplateTool: import("@agentic-kit/harness").HarnessTool<import("zod").ZodObject<{
97
+ displayName: import("zod").ZodString;
98
+ blueprintName: import("zod").ZodOptional<import("zod").ZodString>;
99
+ description: import("zod").ZodOptional<import("zod").ZodString>;
100
+ categories: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
101
+ }, import("zod/v4/core").$strict>, import("./templates").CreateTemplateDetails>;
102
+ updateTemplateTool: import("@agentic-kit/harness").HarnessTool<import("zod").ZodObject<{
103
+ templateName: import("zod").ZodString;
104
+ patch: import("zod").ZodObject<{
105
+ displayName: import("zod").ZodOptional<import("zod").ZodString>;
106
+ description: import("zod").ZodOptional<import("zod").ZodString>;
107
+ categories: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
108
+ tags: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
109
+ visibility: import("zod").ZodOptional<import("zod").ZodEnum<{
110
+ public: "public";
111
+ private: "private";
112
+ }>>;
113
+ }, import("zod/v4/core").$strict>;
114
+ }, import("zod/v4/core").$strict>, import("./templates").TemplateDetails>;
115
+ deleteTemplateTool: import("@agentic-kit/harness").HarnessTool<import("zod").ZodObject<{
116
+ templateName: import("zod").ZodString;
117
+ }, import("zod/v4/core").$strict>, import("./templates").TemplateDetails>;
118
+ addRecordsTool: import("@agentic-kit/harness").HarnessTool<import("zod").ZodObject<{
119
+ table_name: import("zod").ZodString;
120
+ records: import("zod").ZodArray<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnknown>>;
121
+ }, import("zod/v4/core").$strict>, import("..").RecordsDetails>;
122
+ updateRecordsTool: import("@agentic-kit/harness").HarnessTool<import("zod").ZodObject<{
123
+ table_name: import("zod").ZodString;
124
+ records: import("zod").ZodArray<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnknown>>;
125
+ }, import("zod/v4/core").$strict>, import("..").RecordsDetails>;
126
+ deleteRecordsTool: import("@agentic-kit/harness").HarnessTool<import("zod").ZodObject<{
127
+ tables: import("zod").ZodArray<import("zod").ZodObject<{
128
+ table_name: import("zod").ZodString;
129
+ rows: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodNumber]>>>;
130
+ where: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnknown>>;
131
+ sample: import("zod").ZodOptional<import("zod").ZodLiteral<true>>;
132
+ all: import("zod").ZodOptional<import("zod").ZodLiteral<true>>;
133
+ }, import("zod/v4/core").$strict>>;
134
+ }, import("zod/v4/core").$strict>, import("./delete-records").DeleteRecordsDetails>;
135
+ listEntityTypesTool: import("@agentic-kit/harness").HarnessTool<import("zod").ZodObject<{}, import("zod/v4/core").$strict>, import("./entity-types").EntityTypesDetails>;
136
+ createEntityTypeTool: import("@agentic-kit/harness").HarnessTool<import("zod").ZodObject<{
137
+ name: import("zod").ZodString;
138
+ description: import("zod").ZodOptional<import("zod").ZodString>;
139
+ prefix: import("zod").ZodOptional<import("zod").ZodString>;
140
+ parent_entity: import("zod").ZodOptional<import("zod").ZodString>;
141
+ is_visible: import("zod").ZodOptional<import("zod").ZodBoolean>;
142
+ has_invites: import("zod").ZodOptional<import("zod").ZodBoolean>;
143
+ has_profiles: import("zod").ZodOptional<import("zod").ZodBoolean>;
144
+ has_limits: import("zod").ZodOptional<import("zod").ZodBoolean>;
145
+ has_levels: import("zod").ZodOptional<import("zod").ZodBoolean>;
146
+ has_storage: import("zod").ZodOptional<import("zod").ZodBoolean>;
147
+ }, import("zod/v4/core").$strict>, import("./entity-types").EntityTypesDetails>;
148
+ deleteEntityTypeTool: import("@agentic-kit/harness").HarnessTool<import("zod").ZodObject<{
149
+ entity_type_id: import("zod").ZodGUID;
150
+ }, import("zod/v4/core").$strict>, import("./entity-types").EntityTypesDetails>;
151
+ createApiKeyTool: import("@agentic-kit/harness").HarnessTool<import("zod").ZodObject<{
152
+ key_name: import("zod").ZodString;
153
+ principal_name: import("zod").ZodOptional<import("zod").ZodString>;
154
+ entity_ids: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodGUID>>;
155
+ read_only: import("zod").ZodOptional<import("zod").ZodBoolean>;
156
+ expires_in_days: import("zod").ZodOptional<import("zod").ZodNumber>;
157
+ }, import("zod/v4/core").$strict>, import("./create-api-key").CreateApiKeyDetails>;
158
+ runCodegenTool: import("@agentic-kit/harness").HarnessTool<import("zod").ZodObject<{}, import("zod/v4/core").$strict>, import("./run-codegen").RunCodegenDetails>;
159
+ explainAccessTool: import("@agentic-kit/harness").HarnessTool<import("zod").ZodObject<{
160
+ table_name: import("zod").ZodOptional<import("zod").ZodString>;
161
+ }, import("zod/v4/core").$strict>, {
162
+ tables: import("./access").ExplainedTable[];
163
+ }>;
164
+ setAccessTool: import("@agentic-kit/harness").HarnessTool<import("zod").ZodObject<{
165
+ table_name: import("zod").ZodString;
166
+ policies: import("zod").ZodArray<import("zod").ZodObject<{
167
+ $type: import("zod").ZodString;
168
+ privileges: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
169
+ permissive: import("zod").ZodOptional<import("zod").ZodBoolean>;
170
+ policy_role: import("zod").ZodOptional<import("zod").ZodString>;
171
+ policy_name: import("zod").ZodOptional<import("zod").ZodString>;
172
+ data: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnknown>>;
173
+ }, import("zod/v4/core").$loose>>;
174
+ }, import("zod/v4/core").$strict>, {
175
+ success: boolean;
176
+ message: string;
177
+ table?: string;
178
+ access?: import("./access").ExplainedTable;
179
+ }>;
180
+ describePolicyTypeTool: import("@agentic-kit/harness").HarnessTool<import("zod").ZodObject<{
181
+ type: import("zod").ZodOptional<import("zod").ZodEnum<{
182
+ [x: string]: string;
183
+ }>>;
184
+ }, import("zod/v4/core").$strict>, {
185
+ types?: {
186
+ name: string;
187
+ summary?: string;
188
+ tableKind?: string;
189
+ }[];
190
+ type?: {
191
+ name: string;
192
+ summary?: string;
193
+ tableKind?: string;
194
+ } & {
195
+ parameterSchema: unknown;
196
+ useWhen: string[];
197
+ avoidWhen: string[];
198
+ risks: string[];
199
+ dataNode?: unknown;
200
+ };
201
+ }>;
202
+ };
10
203
  export declare const constructiveDbTools: readonly AnyHarnessTool[];
11
204
  /**
12
205
  * What a plan names that the tool's check resolved: its target, the access of the tables it creates or changes, what
@@ -1,3 +1,4 @@
1
+ import { requireApproval } from '@agentic-kit/harness';
1
2
  import { tablePolicyFromBlueprint } from '../access';
2
3
  import { fieldTypeToTypeName, toFieldDefault } from '../blueprint/field-type';
3
4
  import { provisionDatabaseReady } from '../provision-database/provision';
@@ -24,9 +25,11 @@ import { updateRecordsReady, updateRecordsTool } from './update-records';
24
25
  *
25
26
  * Plain `HarnessTool`s: a harness gets them by mapping them into its own tool
26
27
  * shape, which is the adapter's job, so this package stays free of any harness
27
- * dependency (see `toPiTool` in `@agentic-kit/pi` for that binding).
28
+ * dependency (see `toPiTool` in `@agentic-kit/pi` for that binding). Each tool
29
+ * that changes something checks at apply that its plan is still the one the
30
+ * person approved (`requireApproval`), when a gated host gives it a call id.
28
31
  */
29
- export const constructiveDbTools = [
32
+ export const servedTools = gated({
30
33
  provisionDatabaseTool,
31
34
  replaceDatabaseTool,
32
35
  describeSchemaTool,
@@ -54,7 +57,12 @@ export const constructiveDbTools = [
54
57
  explainAccessTool,
55
58
  setAccessTool,
56
59
  describePolicyTypeTool,
57
- ];
60
+ });
61
+ export const constructiveDbTools = Object.values(servedTools);
62
+ /** The tools by name, each that changes something wrapped by `requireApproval`, so no unwrapped one leaves the package. */
63
+ function gated(tools) {
64
+ return Object.fromEntries(Object.entries(tools).map(([name, tool]) => [name, requireApproval(tool)]));
65
+ }
58
66
  /** A tool's first check, with what it resolved turned into what its plan names. */
59
67
  function targeting(check, target, access, notes) {
60
68
  return async (params, cwd) => {
@@ -109,6 +117,11 @@ const blueprintAccess = ({ definition, related }) => definition.tables.flatMap((
109
117
  });
110
118
  const project = (_params, cwd) => projectReady(cwd);
111
119
  const onDatabase = (check) => targeting(check, (context) => databaseTarget(context));
120
+ // A call on an existing table (and field) names it by id, so a plan made for one cannot apply to one that replaced it.
121
+ const onTable = ({ context, table, field }) => ({
122
+ ...databaseTarget(context),
123
+ table: { id: table.id, schemaId: context.schemaId, ...(field ? { fieldId: field.id } : {}) },
124
+ });
112
125
  /**
113
126
  * The check each db tool runs first, before it changes anything, by tool name,
114
127
  * for the gate to run on the same parsed params; its target is what the plan
@@ -123,21 +136,18 @@ export const toolPreconditions = new Map([
123
136
  [listTemplatesTool.name, targeting(project, accountTarget)],
124
137
  [provisionBlueprintTool.name, targeting(provisionBlueprintReady, (context) => databaseTarget(context), blueprintAccess)],
125
138
  [addRelationTool.name, targeting(addRelationReady, (context) => databaseTarget(context), undefined, newRelationNotes)],
126
- [deleteTableTool.name, targeting(deleteTableReady, ({ context, table }) => ({
127
- ...databaseTarget(context),
128
- table: { id: table.id, schemaId: context.schemaId },
129
- }))],
130
- [createFieldTool.name, targeting(createFieldReady, ({ context }) => databaseTarget(context), undefined, newFieldNote)],
131
- [updateFieldTool.name, targeting(updateFieldReady, ({ context }) => databaseTarget(context))],
132
- [retypeFieldTool.name, targeting(retypeFieldReady, ({ context }) => databaseTarget(context))],
133
- [deleteFieldTool.name, targeting(deleteFieldReady, ({ context }) => databaseTarget(context))],
134
- [addPoliciesTool.name, targeting(addPoliciesReady, ({ context }) => databaseTarget(context), addPoliciesPlan)],
139
+ [deleteTableTool.name, targeting(deleteTableReady, onTable)],
140
+ [createFieldTool.name, targeting(createFieldReady, onTable, undefined, newFieldNote)],
141
+ [updateFieldTool.name, targeting(updateFieldReady, onTable)],
142
+ [retypeFieldTool.name, targeting(retypeFieldReady, onTable)],
143
+ [deleteFieldTool.name, targeting(deleteFieldReady, onTable)],
144
+ [addPoliciesTool.name, targeting(addPoliciesReady, onTable, addPoliciesPlan)],
135
145
  [applyTemplateTool.name, targeting(applyTemplateReady, ({ context }) => databaseTarget(context), blueprintAccess)],
136
146
  [createTemplateTool.name, targeting((_params, cwd) => ownedProjectReady(cwd), accountTarget)],
137
147
  [updateTemplateTool.name, targeting(templateReady, ({ context }) => accountTarget(context))],
138
148
  [deleteTemplateTool.name, targeting(templateReady, ({ context }) => accountTarget(context))],
139
- [addRecordsTool.name, targeting(addRecordsReady, ({ context, userId }) => databaseTarget(context, userId))],
140
- [updateRecordsTool.name, targeting(updateRecordsReady, ({ context, userId }) => databaseTarget(context, userId))],
149
+ [addRecordsTool.name, targeting(addRecordsReady, (ready) => databaseTarget(ready.context, ready))],
150
+ [updateRecordsTool.name, targeting(updateRecordsReady, (ready) => databaseTarget(ready.context, ready))],
141
151
  [
142
152
  deleteRecordsTool.name,
143
153
  async (params, cwd) => {
@@ -160,5 +170,5 @@ export const toolPreconditions = new Map([
160
170
  },
161
171
  ],
162
172
  [explainAccessTool.name, onDatabase(project)],
163
- [setAccessTool.name, targeting(setAccessReady, ({ context }) => databaseTarget(context), setAccessPlan)],
173
+ [setAccessTool.name, targeting(setAccessReady, onTable, setAccessPlan)],
164
174
  ]);
@@ -1,4 +1,4 @@
1
- import { identifierParam, strictObject, takeApprovedTable, textParam } from '@agentic-kit/harness';
1
+ import { identifierParam, strictObject, textParam } from '@agentic-kit/harness';
2
2
  import { z } from 'zod';
3
3
  import { toFieldDefault, toFieldType } from '../blueprint/field-type';
4
4
  import { DESCRIBE_SCHEMA, failedResult, failureFromError, failureText, noRowCreated, noRowsChanged, suggest } from '../failure';
@@ -59,16 +59,17 @@ export const deleteTableTool = {
59
59
  parameters: DeleteTableZod,
60
60
  effect: 'destructive',
61
61
  async execute(params, ctx) {
62
- const approved = ctx.toolCallId ? takeApprovedTable(ctx.toolCallId, ctx.cwd) : undefined;
63
62
  const ready = await deleteTableReady(params, ctx.cwd);
64
63
  if (ready.kind === 'failed')
65
64
  return fail(ready.failure);
66
65
  const { context, table } = ready.value;
67
- if (ctx.toolCallId && (!approved || approved.database.id !== context.databaseId || approved.apiEndpoint !== context.controlApiEndpoint ||
68
- approved.account.userId !== context.accountUserId || approved.account.agent?.principalId !== context.accountAgent?.principalId ||
69
- approved.table?.schemaId !== context.schemaId || approved.table.id !== table.id)) {
66
+ const approved = ctx.approved;
67
+ if ((ctx.toolCallId || approved) && (approved?.kind !== 'database' || approved.database.id !== context.databaseId ||
68
+ approved.apiEndpoint !== context.controlApiEndpoint || approved.account.userId !== context.accountUserId ||
69
+ approved.account.agent?.principalId !== context.accountAgent?.principalId ||
70
+ approved.table?.schemaId !== context.schemaId || approved.table?.id !== table.id)) {
70
71
  return fail({
71
- code: 'failed',
72
+ code: 'plan-changed',
72
73
  message: 'The current table and project do not match the approved delete target.',
73
74
  hint: 'Review the current target and approve a new request.',
74
75
  });
@@ -1,7 +1,7 @@
1
1
  import { strictObject } from '@agentic-kit/harness';
2
2
  import { z } from 'zod';
3
3
  import { run } from '../app-workspace';
4
- import { DATABASE_NAME_PATTERN } from '../provision-database/env-file';
4
+ import { DATABASE_NAME_PATTERN } from '../project-file';
5
5
  import { boundDatabaseId, provisionFromTool, } from '../provision-database/provision';
6
6
  const ProvisionDatabaseZod = strictObject('the input', {
7
7
  database_name: z
@@ -16,8 +16,8 @@ export function createProvisionDatabaseTool(exec = run) {
16
16
  return {
17
17
  name: 'provision_database',
18
18
  label: 'Provision database',
19
- description: 'Bootstrap a new Constructive database for the project under your account: provision the standard module set and write the database binding (DATABASE_ID, DATABASE_NAME, etc.) to the project .env. Run this ONCE before the schema and record tools. If the project is already bound to a live database under the signed-in account it skips. If a call returns while the database is still provisioning, call it again with the same name to keep waiting; a different name starts a second database.',
20
- promptSnippet: 'provision_database: one-time bootstrap of the project database (owner + modules + .env), before any schema change. Skips when the existing binding is live under the signed-in account. Gated.',
19
+ description: 'Bootstrap a new Constructive database for the project under your account: provision the standard module set and write the database binding to .constructive/project.json in the project. Run this ONCE before the schema and record tools. If the project is already bound to a live database under the signed-in account it skips. If a call returns while the database is still provisioning, call it again with the same name to keep waiting; a different name starts a second database.',
20
+ promptSnippet: 'provision_database: one-time bootstrap of the project database (owner + modules + binding), before any schema change. Skips when the existing binding is live under the signed-in account. Gated.',
21
21
  parameters: ProvisionDatabaseZod,
22
22
  effect: 'write',
23
23
  async execute(params, ctx) {
@@ -31,7 +31,7 @@ export function createReplaceDatabaseTool(exec = run) {
31
31
  return {
32
32
  name: 'replace_database',
33
33
  label: 'Replace database',
34
- description: 'Bind the project to a new, empty database in place of the one it is bound to: for a bound database that no longer exists on this backend, one that belongs to another account, or a clean rebuild the user asks for. The old .env keys are archived as comments and the old database is kept on the backend; the schema must be built again in the new one, and records do not carry over. Destructive.',
34
+ description: 'Bind the project to a new, empty database in place of the one it is bound to: for a bound database that no longer exists on this backend, one that belongs to another account, or a clean rebuild the user asks for. The old binding is archived in .constructive/project.json and the old database is kept on the backend; the schema must be built again in the new one, and records do not carry over. Destructive.',
35
35
  promptSnippet: 'replace_database: bind the project to a new, empty database in place of a dead, foreign-account or unwanted one (old keys archived, old database kept). Destructive — gated.',
36
36
  parameters: ProvisionDatabaseZod,
37
37
  effect: 'destructive',
@@ -42,8 +42,8 @@ export type RunCodegenReady = {
42
42
  /**
43
43
  * What run_codegen checks before it changes anything: the project's database
44
44
  * on the data plane (codegen reads the app's own API, as the Preview does), by
45
- * name, and the app in packages/app. Its API endpoint is the .env pin when
46
- * there is one, as the data plane resolves it. A host that prepares no app
45
+ * name, and the app in packages/app. Its API endpoint is the one the data
46
+ * plane resolves. A host that prepares no app
47
47
  * (`prewarmApp: false`) needs an app there, installed when it is composed.
48
48
  */
49
49
  export declare function runCodegenReady(cwd: string): Promise<Result<RunCodegenReady>>;
@@ -1,9 +1,9 @@
1
1
  import { existsSync } from 'node:fs';
2
2
  import { rm, writeFile } from 'node:fs/promises';
3
3
  import path from 'node:path';
4
- import { strictObject } from '@agentic-kit/harness';
4
+ import { plural, strictObject } from '@agentic-kit/harness';
5
5
  import { composedInstallComplete, detectAppKind, ensureAppScaffold, ensureComposedInstall, ensureWorkspaceConfig, IGNORED_BUILDS_RE, pinCodegenLatest, prewarmAppWorkspace, run, settlePrewarm, } from '../app-workspace';
6
- import { failedResult, failureText, suggest } from '../failure';
6
+ import { failedResult, failureText } from '../failure';
7
7
  import { classifyBackendErrors, postGraphQL } from '../graphql-http';
8
8
  import { getHost } from '../host';
9
9
  import { projectReady } from '../ready';
@@ -35,8 +35,8 @@ function appStepsOf(app, scaffolded) {
35
35
  ];
36
36
  }
37
37
  /**
38
- * The endpoints codegen reads, from the API endpoint the session trusts: never from an API_ENDPOINT pin in the
39
- * project's .env, since the schema at the endpoint decides the code that lands in the project.
38
+ * The endpoints codegen reads, from the API endpoint the session trusts: never from an injected API_ENDPOINT pin, since
39
+ * the schema at the endpoint decides the code that lands in the project.
40
40
  */
41
41
  const planesOf = (context) => derivePlaneEndpoints(context.controlApiEndpoint, context.databaseName);
42
42
  // The app data plane endpoint codegen reads: the per-database api host.
@@ -51,8 +51,8 @@ function noApp(context, message, hint) {
51
51
  /**
52
52
  * What run_codegen checks before it changes anything: the project's database
53
53
  * on the data plane (codegen reads the app's own API, as the Preview does), by
54
- * name, and the app in packages/app. Its API endpoint is the .env pin when
55
- * there is one, as the data plane resolves it. A host that prepares no app
54
+ * name, and the app in packages/app. Its API endpoint is the one the data
55
+ * plane resolves. A host that prepares no app
56
56
  * (`prewarmApp: false`) needs an app there, installed when it is composed.
57
57
  */
58
58
  export async function runCodegenReady(cwd) {
@@ -68,9 +68,8 @@ export async function runCodegenReady(cwd) {
68
68
  kind: 'failed',
69
69
  failure: {
70
70
  code: 'missing-credentials',
71
- message: 'DATABASE_NAME is missing from .env, and the backend reported no name for the database.',
72
- hint: "Add DATABASE_NAME with the database's name to .env, then call again.",
73
- calls: [suggest('run_codegen', {}, 'Generate the SDK once DATABASE_NAME is in .env')],
71
+ message: 'The project context names no database, and the backend reported no name for it.',
72
+ hint: 'Give the context the database name, or bind this directory to its database again, then call again.',
74
73
  },
75
74
  };
76
75
  }
@@ -267,11 +266,11 @@ export function createRunCodegenTool(exec = run) {
267
266
  if (generatedSubmodules.length === 0) {
268
267
  return fail({
269
268
  code: 'failed',
270
- message: `Codegen ran, but no app submodules (hooks/orm/types) were generated — the database may have no entity tables yet. Normalized ${barrelsRewritten} barrel file(s).`,
269
+ message: `Codegen ran, but no app submodules (hooks/orm/types) were generated — the database may have no entity tables yet. Normalized ${plural(barrelsRewritten, 'barrel file')}.`,
271
270
  hint: 'Create tables first, then generate the SDK again.',
272
271
  }, { barrelsRewritten, generatedSubmodules, ...stepDetails() });
273
272
  }
274
- const message = `Codegen complete. Generated app submodules: ${generatedSubmodules.join(', ')}. Normalized ${barrelsRewritten} barrel file(s).`;
273
+ const message = `Codegen complete. Generated app submodules: ${generatedSubmodules.join(', ')}. Normalized ${plural(barrelsRewritten, 'barrel file')}.`;
275
274
  return {
276
275
  content: [{ type: 'text', text: message }],
277
276
  details: {
@@ -42,7 +42,7 @@ export const updateRecordsTool = {
42
42
  description: "Set columns on rows that are already in the project's app database, each row named by its primary key. Use it to link rows, for example a key column of a row add_records made to a sample row seeded when the app was built.",
43
43
  promptSnippet: 'update_records: set columns on existing rows by primary key, such as linking rows. Gated.',
44
44
  parameters: UpdateRecordsZod,
45
- effect: 'write',
45
+ effect: 'destructive',
46
46
  async execute(params, ctx) {
47
47
  const ready = await updateRecordsReady(params, ctx.cwd);
48
48
  if (ready.kind === 'failed')
package/failure.d.ts CHANGED
@@ -42,7 +42,7 @@ export declare function noRowCreated(action: string, check?: ToolCallSuggestion)
42
42
  * A project binding with values that are not of their form (`keys`, in `where`): none of them is used, sent or shown,
43
43
  * so the project acts as bound to no database until the person fixes them.
44
44
  */
45
- export declare function invalidBinding(keys: readonly string[], where?: string): ToolFailure;
45
+ export declare function invalidBinding(keys: readonly string[], where: string): ToolFailure;
46
46
  export declare const MISSING_OWNER: ToolFailure;
47
47
  /**
48
48
  * What the call means, when it knows. `taken` names a unique value that is
package/failure.js CHANGED
@@ -77,7 +77,7 @@ function noRowCreated(action, check) {
77
77
  * A project binding with values that are not of their form (`keys`, in `where`): none of them is used, sent or shown,
78
78
  * so the project acts as bound to no database until the person fixes them.
79
79
  */
80
- function invalidBinding(keys, where = '.env') {
80
+ function invalidBinding(keys, where) {
81
81
  return {
82
82
  code: 'missing-credentials',
83
83
  message: `The project's database entry is not valid: ${(0, harness_1.listed)(keys.map((key) => `${key} in ${where}`))} ${keys.length === 1 ? 'does' : 'do'} not hold a value ` +
@@ -88,7 +88,7 @@ function invalidBinding(keys, where = '.env') {
88
88
  // provision_database fills a missing OWNER_ID when it keeps a live binding.
89
89
  exports.MISSING_OWNER = {
90
90
  code: 'missing-credentials',
91
- message: 'The project binding has no owner: OWNER_ID is missing from .env and the backend reported none.',
91
+ message: 'The project binding has no owner, and the backend reported none.',
92
92
  hint: "Bind the directory again under the project's database name to refresh the binding, then retry.",
93
93
  calls: [(0, exports.suggest)('provision_database', {}, "Refresh the binding: give the project's database name", ['database_name'])],
94
94
  };
package/gate.js CHANGED
@@ -27,7 +27,7 @@ async function toolPrecondition(toolName, input, cwd) {
27
27
  return blocked(invalidInput(parsed.error));
28
28
  try {
29
29
  const ready = await check(parsed.data, cwd);
30
- return ready.kind === 'ok' ? { kind: 'ready', ...ready.value } : blocked(ready.failure);
30
+ return ready.kind === 'ok' ? { kind: 'ready', ...ready.value, input: parsed.data } : blocked(ready.failure);
31
31
  }
32
32
  catch (err) {
33
33
  // A check that cannot finish blocks the call rather than let it through.
package/graphql-http.d.ts CHANGED
@@ -48,8 +48,9 @@ export declare const answersSignedOut: (err: unknown) => boolean;
48
48
  export declare function classifyBackendErrors(errors: readonly GraphQLError[]): BackendErrorKind;
49
49
  /**
50
50
  * What a failed answer was, in fixed words: each error's public code, HTTP status or error id. The text a server writes
51
- * is never in them, since a server can pass the database's own text through, with internal table names and error
52
- * codes. Only a request that got no answer keeps its text, which postGraphQL made from the local fetch failure.
51
+ * is left out, since a server can pass the database's own text through, with internal table names and error codes.
52
+ * Two texts are kept: a refused query's, which GraphQL writes about the query before it reads any data, and a request
53
+ * that got no answer, whose text postGraphQL made from the local fetch failure.
53
54
  */
54
55
  export declare function answerText(errors: readonly GraphQLError[]): string;
55
56
  /** A thrown error in words that hold no server text: an SDK error by its GraphQL errors, any other by its own message. */
package/graphql-http.js CHANGED
@@ -15,6 +15,7 @@ exports.classifyBackendErrors = classifyBackendErrors;
15
15
  exports.answerText = answerText;
16
16
  exports.thrownText = thrownText;
17
17
  const harness_1 = require("@agentic-kit/harness");
18
+ const errors_1 = require("@constructive-io/errors");
18
19
  const runtime_1 = require("@constructive-io/graphql-query/runtime");
19
20
  const errorText = (err) => (err instanceof Error ? err.message : String(err));
20
21
  async function postGraphQL(args) {
@@ -187,21 +188,39 @@ function classifyBackendErrors(errors) {
187
188
  // A code a server means for its caller is a word in capitals (FORBIDDEN, UNIQUE_VIOLATION). A database error's own
188
189
  // code has a digit in its first word, so it is never named.
189
190
  const PUBLIC_CODE = /^[A-Z]+(?:_[A-Z0-9]+)*$/;
190
- // One error in fixed words: a logged error by its id, else its public code, else its HTTP status.
191
+ // GraphQL refuses a query it cannot run before it reads any data, with a location in the query and no field path. Its
192
+ // words describe the caller's own query, so they are shown.
193
+ const queryLocation = (error) => {
194
+ const [first] = error.locations ?? [];
195
+ return first && !error.path && !error.extensions?.errorId && !codeOf(error) ? first : undefined;
196
+ };
197
+ // One error in fixed words: a logged error by its id, else the words of a refused query, else the words the backend's
198
+ // error registry (@constructive-io/errors) ships for a public code, written for the person who sees them, else its
199
+ // public code, else its HTTP status.
191
200
  function errorWords(error) {
192
201
  const id = error?.extensions?.errorId;
193
202
  if (typeof id === 'string')
194
- return `an internal error (error id ${id})`;
203
+ return `with an internal error (error id ${id})`;
204
+ const at = queryLocation(error);
205
+ if (at)
206
+ return `with the query error at line ${at.line}, column ${at.column} (${error.message})`;
195
207
  const code = codeOf(error);
208
+ if (code && (0, errors_1.getDefinition)(code)?.class === 'public')
209
+ return `"${(0, errors_1.format)(code, contextOf(error)).replace(/\.$/, '')}"`;
196
210
  if (code && PUBLIC_CODE.test(code))
197
- return `the code ${code}`;
211
+ return `with the code ${code}`;
198
212
  const status = statusOf(error);
199
- return status === undefined || status === 200 ? 'an error without a public code' : `HTTP ${status}`;
213
+ return status === undefined || status === 200 ? 'with an error without a public code' : `with HTTP ${status}`;
200
214
  }
215
+ const contextOf = (error) => {
216
+ const context = error?.extensions?.context;
217
+ return context && typeof context === 'object' ? context : {};
218
+ };
201
219
  /**
202
220
  * What a failed answer was, in fixed words: each error's public code, HTTP status or error id. The text a server writes
203
- * is never in them, since a server can pass the database's own text through, with internal table names and error
204
- * codes. Only a request that got no answer keeps its text, which postGraphQL made from the local fetch failure.
221
+ * is left out, since a server can pass the database's own text through, with internal table names and error codes.
222
+ * Two texts are kept: a refused query's, which GraphQL writes about the query before it reads any data, and a request
223
+ * that got no answer, whose text postGraphQL made from the local fetch failure.
205
224
  */
206
225
  function answerText(errors) {
207
226
  const list = errors ?? [];
@@ -209,7 +228,7 @@ function answerText(errors) {
209
228
  if (unanswered)
210
229
  return `the backend did not answer (${unanswered.message || 'no response'})`;
211
230
  const words = [...new Set(list.map(errorWords))];
212
- return `the backend answered with ${words.length ? (0, harness_1.listed)(words) : 'an error without a public code'}`;
231
+ return `the backend answered ${words.length ? (0, harness_1.listed)(words) : 'with an error without a public code'}`;
213
232
  }
214
233
  /** A thrown error in words that hold no server text: an SDK error by its GraphQL errors, any other by its own message. */
215
234
  function thrownText(err) {