@agentic-kit/pi 0.17.0 → 0.18.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 (136) hide show
  1. package/README.md +5 -7
  2. package/confirm-gate.d.ts +1 -2
  3. package/esm/confirm-gate.d.ts +1 -2
  4. package/esm/host.d.ts +5 -110
  5. package/esm/host.js +5 -18
  6. package/esm/index.d.ts +17 -9
  7. package/esm/index.js +20 -38
  8. package/esm/pi-tool.d.ts +16 -0
  9. package/esm/pi-tool.js +32 -0
  10. package/host.d.ts +5 -110
  11. package/host.js +10 -22
  12. package/index.d.ts +17 -9
  13. package/index.js +47 -62
  14. package/package.json +6 -10
  15. package/pi-tool.d.ts +16 -0
  16. package/pi-tool.js +36 -0
  17. package/app-workspace.d.ts +0 -16
  18. package/app-workspace.js +0 -145
  19. package/context.d.ts +0 -62
  20. package/context.js +0 -282
  21. package/db-probe.d.ts +0 -30
  22. package/db-probe.js +0 -50
  23. package/esm/app-workspace.d.ts +0 -16
  24. package/esm/app-workspace.js +0 -134
  25. package/esm/context.d.ts +0 -62
  26. package/esm/context.js +0 -270
  27. package/esm/db-probe.d.ts +0 -30
  28. package/esm/db-probe.js +0 -47
  29. package/esm/policy/add-policies-to-table.d.ts +0 -26
  30. package/esm/policy/add-policies-to-table.js +0 -66
  31. package/esm/policy/provision-helpers.d.ts +0 -38
  32. package/esm/policy/provision-helpers.js +0 -50
  33. package/esm/provision-database/credential.d.ts +0 -14
  34. package/esm/provision-database/credential.js +0 -19
  35. package/esm/provision-database/env-file.d.ts +0 -37
  36. package/esm/provision-database/env-file.js +0 -85
  37. package/esm/provision-database/manifest.d.ts +0 -10
  38. package/esm/provision-database/manifest.js +0 -48
  39. package/esm/provision-database/pg-fixups.d.ts +0 -16
  40. package/esm/provision-database/pg-fixups.js +0 -132
  41. package/esm/provision-database/preset-match.d.ts +0 -13
  42. package/esm/provision-database/preset-match.js +0 -66
  43. package/esm/provision-database/presets.d.ts +0 -4
  44. package/esm/provision-database/presets.js +0 -13
  45. package/esm/provision-database/request-database.d.ts +0 -61
  46. package/esm/provision-database/request-database.js +0 -130
  47. package/esm/provision-database/resolve.d.ts +0 -27
  48. package/esm/provision-database/resolve.js +0 -49
  49. package/esm/records/meta.d.ts +0 -41
  50. package/esm/records/meta.js +0 -167
  51. package/esm/run-codegen/barrels.d.ts +0 -3
  52. package/esm/run-codegen/barrels.js +0 -48
  53. package/esm/run-codegen/endpoints.d.ts +0 -8
  54. package/esm/run-codegen/endpoints.js +0 -46
  55. package/esm/schema-resolve.d.ts +0 -23
  56. package/esm/schema-resolve.js +0 -69
  57. package/esm/tool-schema.d.ts +0 -3
  58. package/esm/tool-schema.js +0 -10
  59. package/esm/tools/add-policies.d.ts +0 -8
  60. package/esm/tools/add-policies.js +0 -96
  61. package/esm/tools/add-records.d.ts +0 -14
  62. package/esm/tools/add-records.js +0 -124
  63. package/esm/tools/add-relation-schema.d.ts +0 -30
  64. package/esm/tools/add-relation-schema.js +0 -58
  65. package/esm/tools/add-relation.d.ts +0 -10
  66. package/esm/tools/add-relation.js +0 -91
  67. package/esm/tools/create-api-key.d.ts +0 -18
  68. package/esm/tools/create-api-key.js +0 -216
  69. package/esm/tools/describe-schema.d.ts +0 -18
  70. package/esm/tools/describe-schema.js +0 -132
  71. package/esm/tools/manage-entity-types.d.ts +0 -41
  72. package/esm/tools/manage-entity-types.js +0 -203
  73. package/esm/tools/mutations.d.ts +0 -14
  74. package/esm/tools/mutations.js +0 -235
  75. package/esm/tools/provision-blueprint.d.ts +0 -22
  76. package/esm/tools/provision-blueprint.js +0 -111
  77. package/esm/tools/provision-database.d.ts +0 -14
  78. package/esm/tools/provision-database.js +0 -262
  79. package/esm/tools/run-codegen.d.ts +0 -11
  80. package/esm/tools/run-codegen.js +0 -139
  81. package/esm/tools/templates.d.ts +0 -49
  82. package/esm/tools/templates.js +0 -337
  83. package/policy/add-policies-to-table.d.ts +0 -26
  84. package/policy/add-policies-to-table.js +0 -71
  85. package/policy/provision-helpers.d.ts +0 -38
  86. package/policy/provision-helpers.js +0 -58
  87. package/provision-database/credential.d.ts +0 -14
  88. package/provision-database/credential.js +0 -22
  89. package/provision-database/env-file.d.ts +0 -37
  90. package/provision-database/env-file.js +0 -91
  91. package/provision-database/manifest.d.ts +0 -10
  92. package/provision-database/manifest.js +0 -56
  93. package/provision-database/pg-fixups.d.ts +0 -16
  94. package/provision-database/pg-fixups.js +0 -170
  95. package/provision-database/preset-match.d.ts +0 -13
  96. package/provision-database/preset-match.js +0 -70
  97. package/provision-database/presets.d.ts +0 -4
  98. package/provision-database/presets.js +0 -17
  99. package/provision-database/request-database.d.ts +0 -61
  100. package/provision-database/request-database.js +0 -134
  101. package/provision-database/resolve.d.ts +0 -27
  102. package/provision-database/resolve.js +0 -53
  103. package/records/meta.d.ts +0 -41
  104. package/records/meta.js +0 -172
  105. package/run-codegen/barrels.d.ts +0 -3
  106. package/run-codegen/barrels.js +0 -54
  107. package/run-codegen/endpoints.d.ts +0 -8
  108. package/run-codegen/endpoints.js +0 -51
  109. package/schema-resolve.d.ts +0 -23
  110. package/schema-resolve.js +0 -75
  111. package/tool-schema.d.ts +0 -3
  112. package/tool-schema.js +0 -13
  113. package/tools/add-policies.d.ts +0 -8
  114. package/tools/add-policies.js +0 -99
  115. package/tools/add-records.d.ts +0 -14
  116. package/tools/add-records.js +0 -127
  117. package/tools/add-relation-schema.d.ts +0 -30
  118. package/tools/add-relation-schema.js +0 -62
  119. package/tools/add-relation.d.ts +0 -10
  120. package/tools/add-relation.js +0 -94
  121. package/tools/create-api-key.d.ts +0 -18
  122. package/tools/create-api-key.js +0 -222
  123. package/tools/describe-schema.d.ts +0 -18
  124. package/tools/describe-schema.js +0 -135
  125. package/tools/manage-entity-types.d.ts +0 -41
  126. package/tools/manage-entity-types.js +0 -208
  127. package/tools/mutations.d.ts +0 -14
  128. package/tools/mutations.js +0 -238
  129. package/tools/provision-blueprint.d.ts +0 -22
  130. package/tools/provision-blueprint.js +0 -114
  131. package/tools/provision-database.d.ts +0 -14
  132. package/tools/provision-database.js +0 -268
  133. package/tools/run-codegen.d.ts +0 -11
  134. package/tools/run-codegen.js +0 -143
  135. package/tools/templates.d.ts +0 -49
  136. package/tools/templates.js +0 -341
package/README.md CHANGED
@@ -12,13 +12,14 @@
12
12
  <a href="https://www.npmjs.com/package/@agentic-kit/pi"><img height="20" src="https://img.shields.io/github/package-json/v/constructive-io/constructive?filename=agentic%2Fpi%2Fpackage.json"/></a>
13
13
  </p>
14
14
 
15
- The **one** [pi coding agent](https://github.com/badlogic/pi-mono) adapter for **agentic-kit**: the Constructive typed database tools, and everything that attaches a platform run to a pi session — the run gate, the run log, the metering gateway and usage reporting — for any host to register: Constructive Desktop, the [`agent` CLI](https://www.npmjs.com/package/@agentic-kit/cli), or your own pi-based agent.
15
+ The **one** [pi coding agent](https://github.com/badlogic/pi-mono) adapter for **agentic-kit**: everything that attaches a platform run to a pi session — the Constructive db tools bound to pi's tool shape, the run gate, the run log, the metering gateway and usage reporting — for any host to register: Constructive Desktop, the [`agent` CLI](https://www.npmjs.com/package/@agentic-kit/cli), or your own pi-based agent.
16
16
 
17
17
  What a run *does* is harness-neutral and lives elsewhere; only its attachment to pi lives here.
18
18
 
19
19
  ```
20
20
  neutral contracts this package pi
21
21
  ──────────────────────────────────── ───────────────────────── ────────────────────
22
+ @agentic-kit/db-tools (18 db tools) toPiTool ─► ToolDefinition pi.registerTool
22
23
  @agentic-kit/harness (gate, adapter) tool_call ─► RunGate pi.on('tool_call')
23
24
  @agentic-kit/metering (gateway, usage) MeteredGateway ─► provider pi.registerProvider
24
25
  @agentic-kit/run-log (append-only) SessionMirror pi's session manager
@@ -32,7 +33,7 @@ npm install @agentic-kit/pi
32
33
 
33
34
  ## What's inside
34
35
 
35
- - **16 typed db tools** — `provision_database`, `provision_blueprint`, `describe_schema`, `add_relation`, `delete_table`, `create_field` / `update_field` / `delete_field`, `add_policies`, `add_records`, `run_codegen`, and the template suite (`list` / `create` / `apply` / `update` / `delete`). Tool schemas are authored in [zod](https://zod.dev) and emitted as plain JSON Schema at pi's tool boundary.
36
+ - **The db tools, bound to pi** — the 18 typed Constructive tools live in [`@agentic-kit/db-tools`](https://www.npmjs.com/package/@agentic-kit/db-tools) as neutral `HarnessTool`s (zod parameters, `execute(params, { cwd, signal })`, no pi import); `toPiTool()` binds each one to pi's `ToolDefinition` — JSON Schema parameters, pi's execute arity, `ctx.cwd` forwarded — and `dbTools` registers the whole list plus the confirm gate. That conversion is the whole of what pi asks of a tool, so a sibling adapter writes its own `toXTool()` and registers the same tools unchanged. The tools' own surface (host contract, project context, provisioning) is re-exported here so a pi host keeps one import.
36
37
  - **Confirm gate** — the harness's host-neutral gate wired to pi's `tool_call` events. Hosts with a rich confirm surface (Desktop) expose `confirmTool`/`notifyToolSkipped` on `ctx.ui`; everyone else gets pi's built-in `ui.confirm` dialog.
37
38
  - **Run lanes** — `composeRun` / `startRun` build a pi session with the run's lanes attached: `createRunLogExtension` mirrors pi's session entries into the run log under `transcriptFormat: 'pi'`, `createMeteredModelExtension` points pi at the Constructive gateway so usage cannot be under-reported, `createUsageReportExtension` self-reports usage when the host owns the provider keys, and `createGateExtension` suspends a gated tool call until a human answers.
38
39
  - **`piHarness`** — the `HarnessAdapter` face of the above: an `id`, the `transcriptFormat` its entries are written under, and `startRun`.
@@ -90,7 +91,7 @@ For local development, the cold path and the warm pool depend on the backend's j
90
91
 
91
92
  ## Host contract
92
93
 
93
- `PiToolsHost` is the only integration surface:
94
+ `ToolsHost` (from `@agentic-kit/db-tools`, re-exported here) is the only integration surface:
94
95
 
95
96
  | Member | Purpose |
96
97
  | --- | --- |
@@ -102,16 +103,13 @@ For local development, the cold path and the warm pool depend on the backend's j
102
103
 
103
104
  ## Related
104
105
 
106
+ - [`@agentic-kit/db-tools`](https://www.npmjs.com/package/@agentic-kit/db-tools) — the Constructive db tools, harness-neutral
105
107
  - [`@agentic-kit/harness`](https://www.npmjs.com/package/@agentic-kit/harness) — host-neutral skills, gating, blueprint core, and the `HarnessAdapter` contract
106
108
  - [`@agentic-kit/metering`](https://www.npmjs.com/package/@agentic-kit/metering) — the metered gateway and usage reporting
107
109
  - [`@agentic-kit/run-log`](https://www.npmjs.com/package/@agentic-kit/run-log) — the append-only run log
108
110
  - [`@agentic-kit/cli`](https://www.npmjs.com/package/@agentic-kit/cli) — `agent`, a local secure-by-default coding agent
109
111
  - [`agentic-kit`](https://www.npmjs.com/package/agentic-kit) — the umbrella package
110
112
 
111
- ## Credits
112
-
113
- Built on the excellent [pi coding agent](https://github.com/badlogic/pi-mono) by Mario Zechner.
114
-
115
113
  ---
116
114
 
117
115
  ## Education and Tutorials
package/confirm-gate.d.ts CHANGED
@@ -1,7 +1,6 @@
1
+ import type { createTemplatePreviewTables, resolveDataToken, resolveProjectContext } from '@agentic-kit/db-tools';
1
2
  import { type GatePolicy } from '@agentic-kit/harness';
2
3
  import type { ExtensionContext, ToolCallEvent, ToolCallEventResult } from '@earendil-works/pi-coding-agent';
3
- import type { resolveDataToken, resolveProjectContext } from './context';
4
- import type { createTemplatePreviewTables } from './tools/templates';
5
4
  export type ConfirmGateDeps = {
6
5
  resolveProjectContext: typeof resolveProjectContext;
7
6
  resolveDataToken: typeof resolveDataToken;
@@ -1,7 +1,6 @@
1
+ import type { createTemplatePreviewTables, resolveDataToken, resolveProjectContext } from '@agentic-kit/db-tools';
1
2
  import { type GatePolicy } from '@agentic-kit/harness';
2
3
  import type { ExtensionContext, ToolCallEvent, ToolCallEventResult } from '@earendil-works/pi-coding-agent';
3
- import type { resolveDataToken, resolveProjectContext } from './context';
4
- import type { createTemplatePreviewTables } from './tools/templates';
5
4
  export type ConfirmGateDeps = {
6
5
  resolveProjectContext: typeof resolveProjectContext;
7
6
  resolveDataToken: typeof resolveDataToken;
package/esm/host.d.ts CHANGED
@@ -1,112 +1,7 @@
1
1
  /**
2
- * Host contract for the pi-hosted Constructive tools.
3
- *
4
- * The typed db tools were extracted from Constructive Desktop, where they read
5
- * an Electron-side `runtime` singleton (account store, backend config, data-auth
6
- * broker, preview token). Hosts now inject the same surface here once at
7
- * startup (`configureHost`); the tool modules stay module-level `ToolDefinition`
8
- * consts and read it lazily via `getHost()`.
2
+ * Deep-import compatibility: the host contract moved to
3
+ * `@agentic-kit/db-tools`, where it belongs — nothing about it is pi-specific.
4
+ * Hosts that import `@agentic-kit/pi/host` keep working; new code should
5
+ * import from `@agentic-kit/db-tools`.
9
6
  */
10
- export type HostAccount = {
11
- userId: string;
12
- accessToken: string;
13
- apiKey?: string;
14
- };
15
- export type HostBackendConfig = {
16
- apiEndpoint?: string;
17
- modulesEndpoint?: string;
18
- };
19
- export type ActiveDataToken = {
20
- token: string;
21
- userId?: string;
22
- expiresAt: number;
23
- origin?: string;
24
- };
25
- /**
26
- * Optional data-plane token broker: remembers per-database end-user tokens
27
- * across tool calls and invalidates declined/expired ones. Hosts without a
28
- * broker fall back to the preview-token harvest on every call.
29
- */
30
- export interface DataAuthBroker {
31
- getActiveToken(databaseId: string): ActiveDataToken | undefined | null;
32
- isInvalidToken(databaseId: string, token: string): boolean;
33
- adoptToken(databaseId: string, token: ActiveDataToken): void;
34
- }
35
- /** Token harvested from the host's app preview (end-user sign-in). */
36
- export type PreviewToken = {
37
- accessToken: string;
38
- accessTokenExpiresAt?: string;
39
- userId?: string;
40
- };
41
- /**
42
- * Overlay layered over the pinned base preset when provisioning a database.
43
- * Structurally the `ProvisionOverlay` from `provision-database/resolve`; typed
44
- * loosely here to keep `host.ts` free of provision-internal imports.
45
- */
46
- export interface HostProvisionOverlay {
47
- preset?: string;
48
- add?: (string | [string, Record<string, unknown>])[];
49
- remove?: string[];
50
- }
51
- /**
52
- * A minted secret handed to the host for out-of-band delivery (.env write +
53
- * one-time reveal). The plaintext never enters tool results or the transcript;
54
- * pi forgets it after this call.
55
- */
56
- export type SecretDelivery = {
57
- databaseId: string;
58
- /** Project directory whose `.env` receives the key. */
59
- cwd: string;
60
- envVar: string;
61
- plaintext: string;
62
- keyId: string;
63
- expiresAt?: string;
64
- };
65
- /**
66
- * Context for a host-side step-up: enough to derive the per-database auth
67
- * endpoint and look up the app session without re-resolving the project.
68
- */
69
- export type StepUpRequest = {
70
- databaseId: string;
71
- databaseName: string;
72
- apiEndpoint: string;
73
- };
74
- export interface PiToolsHost {
75
- /** Signed-in platform account, or null/undefined when signed out. */
76
- account(): HostAccount | null | undefined;
77
- /** Host-configured backend endpoints (env-aware). */
78
- backendConfig(): HostBackendConfig | null | undefined;
79
- /** Optional data-plane token broker (see DataAuthBroker). */
80
- dataAuthBroker?: DataAuthBroker;
81
- /**
82
- * Host-specific sign-in instruction, substituted into signed-out failure
83
- * reasons (e.g. the CLI's "Run `agent login` to sign in."). Absent hosts get
84
- * the desktop wording.
85
- */
86
- signInHint?: string;
87
- /** Harvest an end-user token from the host's app preview, if it has one. */
88
- previewToken?(): Promise<PreviewToken | null>;
89
- /** Treat tokens expiring within this window as already expired. Default 30s. */
90
- dataTokenSkewMs?: number;
91
- /**
92
- * Optional provision overlay: pick a base preset and/or layer module
93
- * add/remove on top of it. The base module list always comes from the pinned
94
- * `node-type-registry` preset — this only customizes it. Distributed as data
95
- * (e.g. materialized from appstash / a pinned git ref), never as code.
96
- */
97
- provisionOverlay?(): HostProvisionOverlay | null | undefined | Promise<HostProvisionOverlay | null | undefined>;
98
- /**
99
- * Complete MFA step-up for the database's app session in the host's own
100
- * process (password dialog + verifyPassword). The password never passes
101
- * through pi or the model. Resolve true when step-up succeeded.
102
- */
103
- requestStepUp?(request: StepUpRequest): Promise<boolean>;
104
- /**
105
- * Deliver a minted secret to the user (.env write + one-time reveal).
106
- * Required for create_api_key — without it the tool refuses to mint.
107
- */
108
- deliverSecret?(delivery: SecretDelivery): Promise<void>;
109
- }
110
- export declare const DEFAULT_DATA_TOKEN_SKEW_MS = 30000;
111
- export declare function configureHost(host: PiToolsHost): void;
112
- export declare function getHost(): PiToolsHost;
7
+ export { type ActiveDataToken, configureHost, type DataAuthBroker, DEFAULT_DATA_TOKEN_SKEW_MS, getHost, type HostAccount, type HostBackendConfig, type HostProvisionOverlay, type PreviewToken, type SecretDelivery, type StepUpRequest, type ToolsHost, } from '@agentic-kit/db-tools';
package/esm/host.js CHANGED
@@ -1,20 +1,7 @@
1
1
  /**
2
- * Host contract for the pi-hosted Constructive tools.
3
- *
4
- * The typed db tools were extracted from Constructive Desktop, where they read
5
- * an Electron-side `runtime` singleton (account store, backend config, data-auth
6
- * broker, preview token). Hosts now inject the same surface here once at
7
- * startup (`configureHost`); the tool modules stay module-level `ToolDefinition`
8
- * consts and read it lazily via `getHost()`.
2
+ * Deep-import compatibility: the host contract moved to
3
+ * `@agentic-kit/db-tools`, where it belongs — nothing about it is pi-specific.
4
+ * Hosts that import `@agentic-kit/pi/host` keep working; new code should
5
+ * import from `@agentic-kit/db-tools`.
9
6
  */
10
- export const DEFAULT_DATA_TOKEN_SKEW_MS = 30_000;
11
- let currentHost = null;
12
- export function configureHost(host) {
13
- currentHost = host;
14
- }
15
- export function getHost() {
16
- if (!currentHost) {
17
- throw new Error('@agentic-kit/pi host not configured. Call configureHost() (or createDbTools(host)) before using the db tools.');
18
- }
19
- return currentHost;
20
- }
7
+ export { configureHost, DEFAULT_DATA_TOKEN_SKEW_MS, getHost, } from '@agentic-kit/db-tools';
package/esm/index.d.ts CHANGED
@@ -1,10 +1,17 @@
1
+ import { type ToolsHost } from '@agentic-kit/db-tools';
1
2
  import type { ExtensionFactory } from '@earendil-works/pi-coding-agent';
2
- import { type PiToolsHost } from './host';
3
+ /**
4
+ * The Constructive db tools bound to pi.
5
+ *
6
+ * The tools themselves live in `@agentic-kit/db-tools` and know nothing about
7
+ * pi; this is the binding — `toPiTool` per tool, plus the confirm gate on pi's
8
+ * `tool_call` event. A sibling adapter writes its own equivalent of this file
9
+ * and registers the same `constructiveDbTools`.
10
+ */
3
11
  export declare const dbTools: ExtensionFactory;
4
12
  /** Configure the host and get the extension in one call. */
5
- export declare function createDbTools(host: PiToolsHost): ExtensionFactory;
13
+ export declare function createDbTools(host: ToolsHost): ExtensionFactory;
6
14
  export { type ConfirmGate, type ConfirmGateDeps, type ConfirmGateOptions, createConfirmGate, } from './confirm-gate';
7
- export { CONTEXT_ENV_KEYS, CONTEXT_ENV_PREFIX, type ContextEnvKey, type ContextSource, deriveSubdomainEndpoint, fromEnvFile, fromEnvironment, type ModulesClient, type ProjectContext, type ProjectContextFailureCode, resolveDataToken, resolveProjectContext, } from './context';
8
15
  export { type ComposedLanes, type ComposedRun, composeRun, type ComposeRunOptions, type GateLane, type MeteringLane, type RunLogLane, } from './embed/lanes';
9
16
  export { type CreateResourceLoader, type EmbeddedRun, type PiModule, type ResourceLoaderRequest, startRun, type StartRunOptions, } from './embed/session';
10
17
  export { createGateExtension, type GateExtension, type GateExtensionOptions, } from './extensions/gate';
@@ -12,10 +19,11 @@ export { createMeteredModelExtension, type MeteredModelExtension, type MeteredMo
12
19
  export { createRunLogExtension, MIRROR_EVENTS, type MirrorEvent, type RunLogExtension, type RunLogExtensionOptions, } from './extensions/run-log';
13
20
  export { createUsageReportExtension, type UsageReportExtension, type UsageReportExtensionOptions, } from './extensions/usage-report';
14
21
  export { PI_HARNESS_ID, piHarness, type PiHarnessRun } from './harness';
15
- export { type ActiveDataToken, configureHost, type DataAuthBroker, getHost, type HostAccount, type HostBackendConfig, type HostProvisionOverlay, type PiToolsHost, type PreviewToken, } from './host';
16
- export { loadProvisionManifest, parseProvisionManifest, PROVISION_MANIFEST_FILE, type ProvisionManifest, } from './provision-database/manifest';
17
- export { allModulePresets, DEFAULT_PROVISION_PRESET, getModulePreset, type ModulePreset, type ProvisionModule, } from './provision-database/presets';
18
- export { moduleKey, type ProvisionOverlay, resolveProvisionModules, } from './provision-database/resolve';
19
- export { toolSchema } from './tool-schema';
20
- export { createTemplatePreviewTables } from './tools/templates';
22
+ export { toPiTool, toPiTools } from './pi-tool';
23
+ /**
24
+ * The db tools' own surface, re-exported so a pi host keeps one import. The
25
+ * package to depend on directly is `@agentic-kit/db-tools`.
26
+ */
27
+ export { type ActiveDataToken, configureHost, constructiveDbTools, CONTEXT_ENV_KEYS, CONTEXT_ENV_PREFIX, type ContextEnvKey, type ContextSource, createTemplatePreviewTables, type DataAuthBroker, DEFAULT_PROVISION_PRESET, deriveSubdomainEndpoint, fromEnvFile, fromEnvironment, getHost, type HostAccount, type HostBackendConfig, type HostProvisionOverlay, loadProvisionManifest, moduleKey, type ModulePreset, type ModulesClient, parseProvisionManifest, type PreviewToken, type ProjectContext, type ProjectContextFailureCode, PROVISION_MANIFEST_FILE, type ProvisionManifest, type ProvisionModule, type ProvisionOverlay, resolveDataToken, resolveProjectContext, resolveProvisionModules, type SecretDelivery, type StepUpRequest, toolSchema, type ToolsHost, } from '@agentic-kit/db-tools';
28
+ export { allModulePresets, getModulePreset } from '@agentic-kit/db-tools';
21
29
  export default dbTools;
package/esm/index.js CHANGED
@@ -1,36 +1,18 @@
1
+ import { configureHost, constructiveDbTools, createTemplatePreviewTables, resolveDataToken, resolveProjectContext, } from '@agentic-kit/db-tools';
1
2
  import { createConfirmGate } from './confirm-gate';
2
- import { resolveDataToken, resolveProjectContext } from './context';
3
- import { configureHost } from './host';
4
- import { addPoliciesTool } from './tools/add-policies';
5
- import { addRecordsTool } from './tools/add-records';
6
- import { addRelationTool } from './tools/add-relation';
7
- import { createApiKeyTool } from './tools/create-api-key';
8
- import { describeSchemaTool } from './tools/describe-schema';
9
- import { manageEntityTypesTool } from './tools/manage-entity-types';
10
- import { createFieldTool, deleteFieldTool, deleteTableTool, updateFieldTool } from './tools/mutations';
11
- import { provisionBlueprintTool } from './tools/provision-blueprint';
12
- import { provisionDatabaseTool } from './tools/provision-database';
13
- import { runCodegenTool } from './tools/run-codegen';
14
- import { applyTemplateTool, createTemplatePreviewTables, createTemplateTool, deleteTemplateTool, listTemplatesTool, updateTemplateTool, } from './tools/templates';
3
+ import { toPiTool } from './pi-tool';
4
+ /**
5
+ * The Constructive db tools bound to pi.
6
+ *
7
+ * The tools themselves live in `@agentic-kit/db-tools` and know nothing about
8
+ * pi; this is the binding — `toPiTool` per tool, plus the confirm gate on pi's
9
+ * `tool_call` event. A sibling adapter writes its own equivalent of this file
10
+ * and registers the same `constructiveDbTools`.
11
+ */
15
12
  export const dbTools = (pi) => {
16
- pi.registerTool(provisionDatabaseTool);
17
- pi.registerTool(describeSchemaTool);
18
- pi.registerTool(listTemplatesTool);
19
- pi.registerTool(provisionBlueprintTool);
20
- pi.registerTool(addRelationTool);
21
- pi.registerTool(deleteTableTool);
22
- pi.registerTool(createFieldTool);
23
- pi.registerTool(updateFieldTool);
24
- pi.registerTool(deleteFieldTool);
25
- pi.registerTool(addPoliciesTool);
26
- pi.registerTool(applyTemplateTool);
27
- pi.registerTool(createTemplateTool);
28
- pi.registerTool(updateTemplateTool);
29
- pi.registerTool(deleteTemplateTool);
30
- pi.registerTool(addRecordsTool);
31
- pi.registerTool(manageEntityTypesTool);
32
- pi.registerTool(createApiKeyTool);
33
- pi.registerTool(runCodegenTool);
13
+ for (const tool of constructiveDbTools) {
14
+ pi.registerTool(toPiTool(tool));
15
+ }
34
16
  const gate = createConfirmGate({
35
17
  resolveProjectContext,
36
18
  resolveDataToken,
@@ -45,7 +27,6 @@ export function createDbTools(host) {
45
27
  return dbTools;
46
28
  }
47
29
  export { createConfirmGate, } from './confirm-gate';
48
- export { CONTEXT_ENV_KEYS, CONTEXT_ENV_PREFIX, deriveSubdomainEndpoint, fromEnvFile, fromEnvironment, resolveDataToken, resolveProjectContext, } from './context';
49
30
  export { composeRun, } from './embed/lanes';
50
31
  export { startRun, } from './embed/session';
51
32
  export { createGateExtension, } from './extensions/gate';
@@ -53,10 +34,11 @@ export { createMeteredModelExtension, piProviderConfig, } from './extensions/met
53
34
  export { createRunLogExtension, MIRROR_EVENTS, } from './extensions/run-log';
54
35
  export { createUsageReportExtension, } from './extensions/usage-report';
55
36
  export { PI_HARNESS_ID, piHarness } from './harness';
56
- export { configureHost, getHost, } from './host';
57
- export { loadProvisionManifest, parseProvisionManifest, PROVISION_MANIFEST_FILE, } from './provision-database/manifest';
58
- export { allModulePresets, DEFAULT_PROVISION_PRESET, getModulePreset, } from './provision-database/presets';
59
- export { moduleKey, resolveProvisionModules, } from './provision-database/resolve';
60
- export { toolSchema } from './tool-schema';
61
- export { createTemplatePreviewTables } from './tools/templates';
37
+ export { toPiTool, toPiTools } from './pi-tool';
38
+ /**
39
+ * The db tools' own surface, re-exported so a pi host keeps one import. The
40
+ * package to depend on directly is `@agentic-kit/db-tools`.
41
+ */
42
+ export { configureHost, constructiveDbTools, CONTEXT_ENV_KEYS, CONTEXT_ENV_PREFIX, createTemplatePreviewTables, DEFAULT_PROVISION_PRESET, deriveSubdomainEndpoint, fromEnvFile, fromEnvironment, getHost, loadProvisionManifest, moduleKey, parseProvisionManifest, PROVISION_MANIFEST_FILE, resolveDataToken, resolveProjectContext, resolveProvisionModules, toolSchema, } from '@agentic-kit/db-tools';
43
+ export { allModulePresets, getModulePreset } from '@agentic-kit/db-tools';
62
44
  export default dbTools;
@@ -0,0 +1,16 @@
1
+ import type { AnyHarnessTool, HarnessTool } from '@agentic-kit/harness';
2
+ import type { ToolDefinition } from '@earendil-works/pi-coding-agent';
3
+ import type { z } from 'zod';
4
+ /**
5
+ * Bind a neutral `HarnessTool` to pi's `ToolDefinition`.
6
+ *
7
+ * This is the whole of what pi wants that a tool does not state: parameters as
8
+ * a typebox schema rather than zod, and an execute arity carrying pi's tool
9
+ * call id, update callback and `ExtensionContext`. Everything a Constructive
10
+ * tool actually reads out of that context is `cwd` and the abort signal, so
11
+ * that is all this forwards — the rest stops here, which is the point of the
12
+ * seam: another harness writes its own binding and the tools do not change.
13
+ */
14
+ export declare function toPiTool<TParams extends z.ZodType, TDetails>(tool: HarnessTool<TParams, TDetails>): ToolDefinition<any, TDetails>;
15
+ /** Bind a whole tool set, in registration order. */
16
+ export declare function toPiTools(tools: readonly AnyHarnessTool[]): ToolDefinition<any, any>[];
package/esm/pi-tool.js ADDED
@@ -0,0 +1,32 @@
1
+ import { toolSchema } from '@agentic-kit/db-tools';
2
+ /**
3
+ * Bind a neutral `HarnessTool` to pi's `ToolDefinition`.
4
+ *
5
+ * This is the whole of what pi wants that a tool does not state: parameters as
6
+ * a typebox schema rather than zod, and an execute arity carrying pi's tool
7
+ * call id, update callback and `ExtensionContext`. Everything a Constructive
8
+ * tool actually reads out of that context is `cwd` and the abort signal, so
9
+ * that is all this forwards — the rest stops here, which is the point of the
10
+ * seam: another harness writes its own binding and the tools do not change.
11
+ */
12
+ export function toPiTool(tool) {
13
+ return {
14
+ name: tool.name,
15
+ label: tool.label,
16
+ description: tool.description,
17
+ ...(tool.promptSnippet === undefined ? {} : { promptSnippet: tool.promptSnippet }),
18
+ ...(tool.promptGuidelines === undefined ? {} : { promptGuidelines: tool.promptGuidelines }),
19
+ parameters: toolSchema(tool.parameters),
20
+ async execute(_toolCallId, params, signal, _onUpdate, ctx) {
21
+ const result = await tool.execute(params, {
22
+ cwd: ctx.cwd,
23
+ signal,
24
+ });
25
+ return result;
26
+ },
27
+ };
28
+ }
29
+ /** Bind a whole tool set, in registration order. */
30
+ export function toPiTools(tools) {
31
+ return tools.map((tool) => toPiTool(tool));
32
+ }
package/host.d.ts CHANGED
@@ -1,112 +1,7 @@
1
1
  /**
2
- * Host contract for the pi-hosted Constructive tools.
3
- *
4
- * The typed db tools were extracted from Constructive Desktop, where they read
5
- * an Electron-side `runtime` singleton (account store, backend config, data-auth
6
- * broker, preview token). Hosts now inject the same surface here once at
7
- * startup (`configureHost`); the tool modules stay module-level `ToolDefinition`
8
- * consts and read it lazily via `getHost()`.
2
+ * Deep-import compatibility: the host contract moved to
3
+ * `@agentic-kit/db-tools`, where it belongs — nothing about it is pi-specific.
4
+ * Hosts that import `@agentic-kit/pi/host` keep working; new code should
5
+ * import from `@agentic-kit/db-tools`.
9
6
  */
10
- export type HostAccount = {
11
- userId: string;
12
- accessToken: string;
13
- apiKey?: string;
14
- };
15
- export type HostBackendConfig = {
16
- apiEndpoint?: string;
17
- modulesEndpoint?: string;
18
- };
19
- export type ActiveDataToken = {
20
- token: string;
21
- userId?: string;
22
- expiresAt: number;
23
- origin?: string;
24
- };
25
- /**
26
- * Optional data-plane token broker: remembers per-database end-user tokens
27
- * across tool calls and invalidates declined/expired ones. Hosts without a
28
- * broker fall back to the preview-token harvest on every call.
29
- */
30
- export interface DataAuthBroker {
31
- getActiveToken(databaseId: string): ActiveDataToken | undefined | null;
32
- isInvalidToken(databaseId: string, token: string): boolean;
33
- adoptToken(databaseId: string, token: ActiveDataToken): void;
34
- }
35
- /** Token harvested from the host's app preview (end-user sign-in). */
36
- export type PreviewToken = {
37
- accessToken: string;
38
- accessTokenExpiresAt?: string;
39
- userId?: string;
40
- };
41
- /**
42
- * Overlay layered over the pinned base preset when provisioning a database.
43
- * Structurally the `ProvisionOverlay` from `provision-database/resolve`; typed
44
- * loosely here to keep `host.ts` free of provision-internal imports.
45
- */
46
- export interface HostProvisionOverlay {
47
- preset?: string;
48
- add?: (string | [string, Record<string, unknown>])[];
49
- remove?: string[];
50
- }
51
- /**
52
- * A minted secret handed to the host for out-of-band delivery (.env write +
53
- * one-time reveal). The plaintext never enters tool results or the transcript;
54
- * pi forgets it after this call.
55
- */
56
- export type SecretDelivery = {
57
- databaseId: string;
58
- /** Project directory whose `.env` receives the key. */
59
- cwd: string;
60
- envVar: string;
61
- plaintext: string;
62
- keyId: string;
63
- expiresAt?: string;
64
- };
65
- /**
66
- * Context for a host-side step-up: enough to derive the per-database auth
67
- * endpoint and look up the app session without re-resolving the project.
68
- */
69
- export type StepUpRequest = {
70
- databaseId: string;
71
- databaseName: string;
72
- apiEndpoint: string;
73
- };
74
- export interface PiToolsHost {
75
- /** Signed-in platform account, or null/undefined when signed out. */
76
- account(): HostAccount | null | undefined;
77
- /** Host-configured backend endpoints (env-aware). */
78
- backendConfig(): HostBackendConfig | null | undefined;
79
- /** Optional data-plane token broker (see DataAuthBroker). */
80
- dataAuthBroker?: DataAuthBroker;
81
- /**
82
- * Host-specific sign-in instruction, substituted into signed-out failure
83
- * reasons (e.g. the CLI's "Run `agent login` to sign in."). Absent hosts get
84
- * the desktop wording.
85
- */
86
- signInHint?: string;
87
- /** Harvest an end-user token from the host's app preview, if it has one. */
88
- previewToken?(): Promise<PreviewToken | null>;
89
- /** Treat tokens expiring within this window as already expired. Default 30s. */
90
- dataTokenSkewMs?: number;
91
- /**
92
- * Optional provision overlay: pick a base preset and/or layer module
93
- * add/remove on top of it. The base module list always comes from the pinned
94
- * `node-type-registry` preset — this only customizes it. Distributed as data
95
- * (e.g. materialized from appstash / a pinned git ref), never as code.
96
- */
97
- provisionOverlay?(): HostProvisionOverlay | null | undefined | Promise<HostProvisionOverlay | null | undefined>;
98
- /**
99
- * Complete MFA step-up for the database's app session in the host's own
100
- * process (password dialog + verifyPassword). The password never passes
101
- * through pi or the model. Resolve true when step-up succeeded.
102
- */
103
- requestStepUp?(request: StepUpRequest): Promise<boolean>;
104
- /**
105
- * Deliver a minted secret to the user (.env write + one-time reveal).
106
- * Required for create_api_key — without it the tool refuses to mint.
107
- */
108
- deliverSecret?(delivery: SecretDelivery): Promise<void>;
109
- }
110
- export declare const DEFAULT_DATA_TOKEN_SKEW_MS = 30000;
111
- export declare function configureHost(host: PiToolsHost): void;
112
- export declare function getHost(): PiToolsHost;
7
+ export { type ActiveDataToken, configureHost, type DataAuthBroker, DEFAULT_DATA_TOKEN_SKEW_MS, getHost, type HostAccount, type HostBackendConfig, type HostProvisionOverlay, type PreviewToken, type SecretDelivery, type StepUpRequest, type ToolsHost, } from '@agentic-kit/db-tools';
package/host.js CHANGED
@@ -1,25 +1,13 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getHost = exports.DEFAULT_DATA_TOKEN_SKEW_MS = exports.configureHost = void 0;
2
4
  /**
3
- * Host contract for the pi-hosted Constructive tools.
4
- *
5
- * The typed db tools were extracted from Constructive Desktop, where they read
6
- * an Electron-side `runtime` singleton (account store, backend config, data-auth
7
- * broker, preview token). Hosts now inject the same surface here once at
8
- * startup (`configureHost`); the tool modules stay module-level `ToolDefinition`
9
- * consts and read it lazily via `getHost()`.
5
+ * Deep-import compatibility: the host contract moved to
6
+ * `@agentic-kit/db-tools`, where it belongs — nothing about it is pi-specific.
7
+ * Hosts that import `@agentic-kit/pi/host` keep working; new code should
8
+ * import from `@agentic-kit/db-tools`.
10
9
  */
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.DEFAULT_DATA_TOKEN_SKEW_MS = void 0;
13
- exports.configureHost = configureHost;
14
- exports.getHost = getHost;
15
- exports.DEFAULT_DATA_TOKEN_SKEW_MS = 30_000;
16
- let currentHost = null;
17
- function configureHost(host) {
18
- currentHost = host;
19
- }
20
- function getHost() {
21
- if (!currentHost) {
22
- throw new Error('@agentic-kit/pi host not configured. Call configureHost() (or createDbTools(host)) before using the db tools.');
23
- }
24
- return currentHost;
25
- }
10
+ var db_tools_1 = require("@agentic-kit/db-tools");
11
+ Object.defineProperty(exports, "configureHost", { enumerable: true, get: function () { return db_tools_1.configureHost; } });
12
+ Object.defineProperty(exports, "DEFAULT_DATA_TOKEN_SKEW_MS", { enumerable: true, get: function () { return db_tools_1.DEFAULT_DATA_TOKEN_SKEW_MS; } });
13
+ Object.defineProperty(exports, "getHost", { enumerable: true, get: function () { return db_tools_1.getHost; } });
package/index.d.ts CHANGED
@@ -1,10 +1,17 @@
1
+ import { type ToolsHost } from '@agentic-kit/db-tools';
1
2
  import type { ExtensionFactory } from '@earendil-works/pi-coding-agent';
2
- import { type PiToolsHost } from './host';
3
+ /**
4
+ * The Constructive db tools bound to pi.
5
+ *
6
+ * The tools themselves live in `@agentic-kit/db-tools` and know nothing about
7
+ * pi; this is the binding — `toPiTool` per tool, plus the confirm gate on pi's
8
+ * `tool_call` event. A sibling adapter writes its own equivalent of this file
9
+ * and registers the same `constructiveDbTools`.
10
+ */
3
11
  export declare const dbTools: ExtensionFactory;
4
12
  /** Configure the host and get the extension in one call. */
5
- export declare function createDbTools(host: PiToolsHost): ExtensionFactory;
13
+ export declare function createDbTools(host: ToolsHost): ExtensionFactory;
6
14
  export { type ConfirmGate, type ConfirmGateDeps, type ConfirmGateOptions, createConfirmGate, } from './confirm-gate';
7
- export { CONTEXT_ENV_KEYS, CONTEXT_ENV_PREFIX, type ContextEnvKey, type ContextSource, deriveSubdomainEndpoint, fromEnvFile, fromEnvironment, type ModulesClient, type ProjectContext, type ProjectContextFailureCode, resolveDataToken, resolveProjectContext, } from './context';
8
15
  export { type ComposedLanes, type ComposedRun, composeRun, type ComposeRunOptions, type GateLane, type MeteringLane, type RunLogLane, } from './embed/lanes';
9
16
  export { type CreateResourceLoader, type EmbeddedRun, type PiModule, type ResourceLoaderRequest, startRun, type StartRunOptions, } from './embed/session';
10
17
  export { createGateExtension, type GateExtension, type GateExtensionOptions, } from './extensions/gate';
@@ -12,10 +19,11 @@ export { createMeteredModelExtension, type MeteredModelExtension, type MeteredMo
12
19
  export { createRunLogExtension, MIRROR_EVENTS, type MirrorEvent, type RunLogExtension, type RunLogExtensionOptions, } from './extensions/run-log';
13
20
  export { createUsageReportExtension, type UsageReportExtension, type UsageReportExtensionOptions, } from './extensions/usage-report';
14
21
  export { PI_HARNESS_ID, piHarness, type PiHarnessRun } from './harness';
15
- export { type ActiveDataToken, configureHost, type DataAuthBroker, getHost, type HostAccount, type HostBackendConfig, type HostProvisionOverlay, type PiToolsHost, type PreviewToken, } from './host';
16
- export { loadProvisionManifest, parseProvisionManifest, PROVISION_MANIFEST_FILE, type ProvisionManifest, } from './provision-database/manifest';
17
- export { allModulePresets, DEFAULT_PROVISION_PRESET, getModulePreset, type ModulePreset, type ProvisionModule, } from './provision-database/presets';
18
- export { moduleKey, type ProvisionOverlay, resolveProvisionModules, } from './provision-database/resolve';
19
- export { toolSchema } from './tool-schema';
20
- export { createTemplatePreviewTables } from './tools/templates';
22
+ export { toPiTool, toPiTools } from './pi-tool';
23
+ /**
24
+ * The db tools' own surface, re-exported so a pi host keeps one import. The
25
+ * package to depend on directly is `@agentic-kit/db-tools`.
26
+ */
27
+ export { type ActiveDataToken, configureHost, constructiveDbTools, CONTEXT_ENV_KEYS, CONTEXT_ENV_PREFIX, type ContextEnvKey, type ContextSource, createTemplatePreviewTables, type DataAuthBroker, DEFAULT_PROVISION_PRESET, deriveSubdomainEndpoint, fromEnvFile, fromEnvironment, getHost, type HostAccount, type HostBackendConfig, type HostProvisionOverlay, loadProvisionManifest, moduleKey, type ModulePreset, type ModulesClient, parseProvisionManifest, type PreviewToken, type ProjectContext, type ProjectContextFailureCode, PROVISION_MANIFEST_FILE, type ProvisionManifest, type ProvisionModule, type ProvisionOverlay, resolveDataToken, resolveProjectContext, resolveProvisionModules, type SecretDelivery, type StepUpRequest, toolSchema, type ToolsHost, } from '@agentic-kit/db-tools';
28
+ export { allModulePresets, getModulePreset } from '@agentic-kit/db-tools';
21
29
  export default dbTools;