Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion agentic/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ On startup, `agent` assembles the harness skill tree and drops you into an inter

1. **Base layer** — [`constructive-io/constructive-skills`](https://github.com/constructive-io/constructive-skills), fetched as a git tag/branch/SHA tarball into `~/.constructive/data/skills/<version>/` (default ref: `main`; offline fallback: newest cached release).
2. **Local overlay** — `~/.constructive/config/skills-overlay/<skill-name>/SKILL.md` (agentskills.io layout), highest precedence: a same-name skill replaces the base skill wholesale.
3. **Typed db tools** — the [`@agentic-kit/pi`](https://www.npmjs.com/package/@agentic-kit/pi) extension (including `provision_database`, `provision_blueprint`, `describe_schema`, and `run_codegen`) is materialized into the agent dir and loaded by pi automatically. The CLI does not register `add_records` or `create_api_key`; it has no tenant sign-in or secret-delivery integration for those tools.
3. **Typed db tools** — the [`@agentic-kit/pi`](https://www.npmjs.com/package/@agentic-kit/pi) extension (including `provision_database`, `provision_blueprint`, `describe_schema`, and `run_codegen`) is materialized into the agent dir and loaded by pi automatically. The CLI does not register `add_records`, `update_records` or `create_api_key`; it has no tenant sign-in or secret-delivery integration for those tools.

The merged tree is materialized into the appstash-owned agent dir, so the session picks the skills up natively. All harness state lives in the [appstash](https://github.com/constructive-io/appstash) `~/.constructive/` layout; project directories are untouched.

Expand Down
4 changes: 3 additions & 1 deletion agentic/cli/__tests__/db-tools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ describe('materializeDbTools', () => {
});
expect(registered).toContain('provision_database');
expect(registered).not.toContain('add_records');
expect(registered).not.toContain('update_records');
expect(registered).not.toContain('create_api_key');
const expected = constructiveDbTools.map((tool) => tool.name).filter((name) => name !== 'add_records' && name !== 'create_api_key');
const excluded = ['add_records', 'update_records', 'create_api_key'];
const expected = constructiveDbTools.map((tool) => tool.name).filter((name) => !excluded.includes(name));
expect(registered.sort()).toEqual(expected.sort());
});

Expand Down
2 changes: 1 addition & 1 deletion agentic/cli/src/db-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = createDbTools({
account: resolveAccount,
backendConfig: resolveBackendConfig,
signInHint: 'Run \`agent login\` to sign in.'
}, { excludeTools: ['add_records', 'create_api_key'] });
}, { excludeTools: ['add_records', 'update_records', 'create_api_key'] });
`;
}

Expand Down
2 changes: 1 addition & 1 deletion agentic/db-tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ npm install @agentic-kit/db-tools

## What's inside

- **25 typed db tools** — `provision_database` / `replace_database`, `provision_blueprint`, `describe_schema`, `add_relation`, `delete_table`, `create_field` / `update_field` / `retype_field` / `delete_field`, `add_policies`, `add_records`, `list_entity_types` / `create_entity_type` / `delete_entity_type`, `create_api_key`, `run_codegen`, the template suite (`list` / `create` / `apply` / `update` / `delete`), the access tools (`explain_access`, `set_access`), and `describe_policy_type`. `constructiveDbTools` is the list, in registration order. Each states one effect (`read`, `write` or `destructive`) for every call; a change whose effect differs is its own tool (`retype_field` beside `update_field`, `replace_database` beside `provision_database`). Every failing call returns a `failure` (code, message, hint) beside the `details` it always had. A message or hint names no tool and no parameter: the calls that help travel as data (`failure.calls`, `result.calls`). Every object of a tool's own input refuses a key it does not have and names the nearest known one, instead of dropping it; Every change that names a table, a field, a template or an entity type finds it, or finds a new name's stored form free, before there is a plan to approve. A call that did only part of what was asked (a field without its unique constraint, some of the rows) returns the code `partial`, and its `details` hold the errors of the part that failed. Backend errors are read by their `extensions.code` and `extensions.class`, then the HTTP status (`extensions.http` first: the server answers HTTP 200 and puts the status there), then a masked internal error with its `errorId`; message text never decides, because the server masks the text it does not mean to show. `failureFromErrors(errors, action, meaning?)` is that mapping, exported for code that sends its own GraphQL (`postGraphQL`, which takes an `operationName`), and `FailureMeaning` names what a unique violation means for the call.
- **26 typed db tools** — `provision_database` / `replace_database`, `provision_blueprint`, `describe_schema`, `add_relation`, `delete_table`, `create_field` / `update_field` / `retype_field` / `delete_field`, `add_policies`, `add_records` / `update_records`, `list_entity_types` / `create_entity_type` / `delete_entity_type`, `create_api_key`, `run_codegen`, the template suite (`list` / `create` / `apply` / `update` / `delete`), the access tools (`explain_access`, `set_access`), and `describe_policy_type`. `constructiveDbTools` is the list, in registration order. Each states one effect (`read`, `write` or `destructive`) for every call; a change whose effect differs is its own tool (`retype_field` beside `update_field`, `replace_database` beside `provision_database`). Every failing call returns a `failure` (code, message, hint) beside the `details` it always had. A message or hint names no tool and no parameter: the calls that help travel as data (`failure.calls`, `result.calls`). Every object of a tool's own input refuses a key it does not have and names the nearest known one, instead of dropping it; Every change that names a table, a field, a template or an entity type finds it, or finds a new name's stored form free, before there is a plan to approve. A call that did only part of what was asked (a field without its unique constraint, some of the rows) returns the code `partial`, and its `details` hold the errors of the part that failed. Backend errors are read by their `extensions.code` and `extensions.class`, then the HTTP status (`extensions.http` first: the server answers HTTP 200 and puts the status there), then a masked internal error with its `errorId`; message text never decides, because the server masks the text it does not mean to show. `failureFromErrors(errors, action, meaning?)` is that mapping, exported for code that sends its own GraphQL (`postGraphQL`, which takes an `operationName`), and `FailureMeaning` names what a unique violation means for the call.

The public `extensions.context` of the error that decided goes into `failure.context`: a query over the backend's request limits (`QUERY_TOO_COSTLY`, `QUERY_TOO_DEEP`, `PAGE_SIZE_TOO_LARGE`, `REQUEST_TOO_LARGE`) is `query-too-large` with its numbers there, for example `{ cost, limit }`. An update or delete that answers with no row in its payload changed nothing: that is how row-level security answers for a row this account cannot see, so every tool that updates or deletes fails `no-rows-changed` there instead of reporting success. A create that answers without the new row fails `no-rows-changed` as well: the row may not exist, or a policy lets the account create it but not read it, and the hint names the call that shows whether it exists. `STEP_UP_REQUIRED` is `step-up-required`: the change needs a recent sign-in.

Expand Down
1 change: 1 addition & 0 deletions agentic/db-tools/__tests__/access-provisioning.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const DATA_ROWS: Array<[string, string[] | 'unknown']> = [
['DataDenormalized', 'unknown'],
['DataDirectOwner', ['owner_id uuid not null']],
['DataEntityMembership', ['entity_id uuid not null']],
['DataFileRef', []],
['DataForceCurrentUser', []],
['DataGenerated', 'unknown'],
['DataHistory', []],
Expand Down
16 changes: 16 additions & 0 deletions agentic/db-tools/__tests__/find-meta-table.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { findMetaTable, type RawMetaTable } from '../src/records/meta';

// People are stored in the SQL table "records"; the GraphQL type Record is stored in "record_entries".
const PERSON: RawMetaTable = { name: 'Person', tableName: 'records', query: { all: 'people', one: 'person' } };
const RECORD: RawMetaTable = { name: 'Record', tableName: 'record_entries', query: { all: 'records', one: 'record' } };

describe('findMetaTable', () => {
it.each([
[[PERSON, RECORD]],
[[RECORD, PERSON]],
])('gives a GraphQL name to its own table before an SQL name of another table claims it', (tables) => {
expect(findMetaTable(tables, 'Record')).toBe(RECORD);
expect(findMetaTable(tables, 'record_entries')).toBe(RECORD);
expect(findMetaTable(tables, 'people')).toBe(PERSON);
});
});
23 changes: 21 additions & 2 deletions agentic/db-tools/__tests__/gate-precondition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { mkdtempSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
import os from 'node:os';
import path from 'node:path';

import { createConfirmGate, createConstructiveGatePolicy, type GateHost, type PlanTarget } from '@agentic-kit/harness';
import { createConfirmGate, createConstructiveGatePolicy, type GateHost, type PlanTarget, rememberApprovedTable } from '@agentic-kit/harness';

import { constructiveDbTools, constructiveGateDeps } from '../src';
import type { RunCommand } from '../src/app-workspace';
Expand Down Expand Up @@ -102,7 +102,7 @@ describe('a gated call never runs unasked', () => {

// What the named things are: the table "posts" (on the control plane and on the app's API) and the template "Blog".
function namedAnswer({ host, query }: SeenRequest): GraphQLAnswer {
if (host.startsWith('api-mydb.')) return { data: { _meta: { tables: [{ name: 'Post', query: { all: 'posts' }, inflection: { tableType: 'Post' }, fields: [] }] } } };
if (host.startsWith('api-mydb.')) return { data: { _meta: { tables: [{ name: 'Post', query: { all: 'posts' }, inflection: { tableType: 'Post' }, fields: [{ name: 'title', columnName: 'title', type: { gqlType: 'String', isArray: false } }] }] } } };
if (/blueprintTemplates/.test(query)) return { data: { blueprintTemplates: { nodes: [{ id: 'tpl-1', displayName: 'Blog', definition: {} }] } } };
if (/uniqueConstraints/.test(query)) return { data: { uniqueConstraints: { nodes: [] } } };
if (/\bfields\b/.test(query)) return { data: { fields: { nodes: [] } } };
Expand Down Expand Up @@ -166,6 +166,25 @@ describe('the plan names what the call acts on', () => {
expect(backend.requests.some(({ query }) => /mutation/.test(query))).toBe(!replaced);
});

it('deletes the table a host approved through its own approval channel', async () => {
await backend.close();
backend = await startFakeBackend(({ query }) => {
if (/mutation/.test(query)) return { data: { deleteTable: { table: { id: 'original' } } } };
if (/\btables\b/.test(query)) return { data: { tables: { nodes: [{ name: 'posts', id: 'original' }] } } };
return projectAnswer(query, 'ME') ?? { data: {} };
});
const tool = constructiveDbTools.find(({ name }) => name === 'delete_table')!;
const event = { toolName: tool.name, toolCallId: 'delete-2', input: { table_name: 'posts' } };
const decision = await createConstructiveGatePolicy(constructiveGateDeps()).resolvePrompt(event, cwd);
if (decision.kind !== 'ask') throw new Error('expected a card');
rememberApprovedTable(event.toolCallId, cwd, decision.prompt.target);

const result = await tool.execute(event.input, { cwd, toolCallId: event.toolCallId });

expect(result.failure).toBeUndefined();
expect(backend.requests.some(({ query }) => /mutation/.test(query))).toBe(true);
});

it('plans saved template access using the schema where each table will be created', async () => {
await backend.close();
backend = await startFakeBackend((request) => {
Expand Down
1 change: 1 addition & 0 deletions agentic/db-tools/__tests__/host.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ describe('constructiveDbTools', () => {
'update_template',
'delete_template',
'add_records',
'update_records',
'list_entity_types',
'create_entity_type',
'delete_entity_type',
Expand Down
Loading
Loading