Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
88cbc42
feat(harness): add the delete-records card and the rows of an approve…
yyyyaaa Nov 30, 2026
7b42a28
feat(db-tools): add delete_records, which deletes the exact rows the …
yyyyaaa Nov 30, 2026
0e5bcc9
feat(cli): leave delete_records out with the other app-sign-in record…
yyyyaaa Nov 30, 2026
144a214
test(pi): count delete_records among the registered db tools
yyyyaaa Nov 30, 2026
4826fcd
fix(db-tools): say a left-out table was unticked or had no rows to de…
yyyyaaa Nov 30, 2026
c9c5bbc
fix(db-tools): leave search chunk tables out of the delete effects an…
yyyyaaa Nov 30, 2026
ed40feb
fix(db-tools): find an approved table by its exact SQL name
yyyyaaa Nov 30, 2026
49a1b28
fix(db-tools): count the delete's effects on the rows it does not sel…
yyyyaaa Nov 30, 2026
1014a00
fix(db-tools): follow a delete's cascades through tables the call doe…
yyyyaaa Nov 30, 2026
db3f896
fix(db-tools): delete nothing when the approved rows reach rows of a …
yyyyaaa Nov 30, 2026
b2c7f1c
feat: name the keys between the tables of a records delete on its card
yyyyaaa Nov 30, 2026
24d56b9
fix(db-tools): name only the columns a set-null key clears
yyyyaaa Nov 30, 2026
29a1c08
fix(db-tools): count the rows of a child table with no single-column key
yyyyaaa Nov 30, 2026
e02a274
fix(db-tools): follow keys on a unique column, and say when a key's r…
yyyyaaa Nov 30, 2026
c59762d
fix(db-tools): delete nothing when an unchecked effect could reach a …
yyyyaaa Nov 30, 2026
8fb6f0b
fix(db-tools): count the rows a set-default key changes
yyyyaaa Nov 30, 2026
9716bab
fix(db-tools): leave uncounted a keyless table with two keys to the d…
yyyyaaa Nov 30, 2026
52e169b
fix(db-tools): delete nothing when a records delete has no approved t…
yyyyaaa Nov 30, 2026
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`, `update_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`, `delete_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
3 changes: 2 additions & 1 deletion agentic/cli/__tests__/db-tools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ describe('materializeDbTools', () => {
expect(registered).toContain('provision_database');
expect(registered).not.toContain('add_records');
expect(registered).not.toContain('update_records');
expect(registered).not.toContain('delete_records');
expect(registered).not.toContain('create_api_key');
const excluded = ['add_records', 'update_records', 'create_api_key'];
const excluded = ['add_records', 'update_records', 'delete_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', 'update_records', 'create_api_key'] });
}, { excludeTools: ['add_records', 'update_records', 'delete_records', 'create_api_key'] });
`;
}

Expand Down
6 changes: 3 additions & 3 deletions agentic/db-tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ npm install @agentic-kit/db-tools

## What's inside

- **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.
- **27 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` / `delete_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.

`constructiveGateDeps().precondition` runs each tool's own first check and returns the plan's target from what it resolved (`toolPreconditions`, one per tool, provision_database included), and for a change to a table's access the access before and after; a tool the map does not hold is blocked as `unsupported`.
`constructiveGateDeps().precondition` runs each tool's own first check and returns the plan's target from what it resolved (`toolPreconditions`, one per tool, provision_database included), and for a change to a table's access the access before and after; a tool the map does not hold is blocked as `unsupported`. For `delete_records` the check resolves the exact rows once, as the person signed in to the app: each table's rows by key, by column values (`where`), its sample rows still there, or all its rows, at most 500 in all, ordered so a row goes before the rows it points at, with what the delete does to the rows it does not select: the rows that point at them, counted on the app API by the foreign keys and followed through each cascade (search chunk tables left out). The target names those rows (`rows`) and the card's preview shows them (`delete-records`). The tool then deletes only the rows the approved target names (`takeApprovedTable`). When a host leaves tables out of the target, the tool counts the effects of the approved rows again first, and deletes nothing when they would delete, clear or be blocked by rows of a table the person kept, or when it can't count or follow the rows that could reach one (too many related rows, a table with no single-column key, a key it can't read).

**Access.** The access of a table is its stored rules, grants and row security (`readTables`), and nothing here says who can or cannot reach a row. `explain_access` gives one plain sentence per stored rule (`explainPolicy`, from the words of the rule's Authz node), the grants, row security and the structural findings (`accessFindings`), each of which says what may happen. It and `describe_schema` return each stored rule through `asWritten`, in the one shape a caller writes (`{ $type, privileges, permissive, policy_role, data, with_check? }`), with every key the node's closed `parameter_schema` marks `readOnly` left out, nested nodes included, so a read carries no part the closed world refuses. A plan's rules use the same keys, with `words` in place of `data`. `set_access` replaces every rule of a table in one change with `owns: ['policies']`; the grants stay, and the Data nodes the rules need add their columns when the table lacks them. `add_policies` adds rules without replacing any. Both take rules only in the registry's blueprint shape (`{ $type, privileges, permissive, policy_role, policy_name, data }`, `AccessPolicyZod`), check each rule's shape against the registry's `BlueprintPolicy`, and check its data with `checkRule` (ajv over the node's closed `parameter_schema`, and the rule shapes these tools do not support) and its role before any plan. Every tool that sends rules, `provision_blueprint` included, sends them through `rulesToSend`: rules of one policy type, role, kind and data become one rule with all their privileges, and a rule the backend would skip (the same policy type and data as another) or refuse (a second policy row of one role, privilege and name) is refused before the plan. The plan holds the rules, grants and row security now and after, one sentence per rule, the findings the change adds and removes, the columns it adds (name, type, required, default) and the ones it reuses as they are. A reused column of another type than its Data node needs is blocked before the change (`conflict`, with `retype_field` and `delete_field`). When the person signed in to the app sees a row, a change that adds a required column with no value for the rows is blocked before anything is sent; otherwise the backend's refused NOT NULL comes back as a `conflict` with the `create_field` call that adds the column as optional first. After the change, the table is read back and compared with the plan by meaning (`policyDifference`); a difference is a `conflict`, and a read that fails is `unverified`. A refusal on the rows of an app table (`add_records`) suggests the read of its rules; a refusal on the control plane does not, because it is about the account's rights on the database.

Expand Down Expand Up @@ -76,7 +76,7 @@ const result = await describeSchemaTool.execute({ database_name: 'my-app' }, { c

Only `missing` means the database is gone. On a backend without `hash`, the probe retries once without it and `hash` is undefined. `resolveProjectContext` reports the same states as `db-missing`, `db-suspended`, `account-mismatch` and `backend-unreachable` (with `cause`), and a resolved context carries `hash`.

Tenant APIs answer `ACCESS_SUSPENDED` (a 403 with a JSON body) for a deleted or suspended database. The SDK's `FetchAdapter` drops that body, so `postGraphQL` and `statusAdapter` (a drop-in ORM adapter) keep each error's `extensions.code` and HTTP status, and `classifyBackendErrors` sorts them into `suspended`, `network`, `server`, `auth`, `forbidden` or `graphql`. `add_records`, `run_codegen` and `create_api_key` return `details.code: 'database-unavailable'` on `ACCESS_SUSPENDED`, and `run_codegen` doesn't retry a refused introspection.
Tenant APIs answer `ACCESS_SUSPENDED` (a 403 with a JSON body) for a deleted or suspended database. The SDK's `FetchAdapter` drops that body, so `postGraphQL` and `statusAdapter` (a drop-in ORM adapter) keep each error's `extensions.code` and HTTP status, and `classifyBackendErrors` sorts them into `suspended`, `network`, `server`, `auth`, `forbidden` or `graphql`. `add_records`, `update_records`, `delete_records`, `run_codegen` and `create_api_key` return `details.code: 'database-unavailable'` on `ACCESS_SUSPENDED`, and `run_codegen` doesn't retry a refused introspection.

## The live schema

Expand Down
Loading
Loading