@agentic-kit/cli 0.19.51 → 0.19.52

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.
package/README.md CHANGED
@@ -12,7 +12,7 @@
12
12
  <a href="https://www.npmjs.com/package/@agentic-kit/cli"><img height="20" src="https://img.shields.io/github/package-json/v/constructive-io/constructive?filename=agentic%2Fcli%2Fpackage.json"/></a>
13
13
  </p>
14
14
 
15
- `agent` — a local, secure-by-default coding agent that builds your frontend and your backend. Skills, a backend harness, and offline-capable skill releases, batteries included.
15
+ `agent` — a local coding agent with Constructive skills, a backend harness, and confirmation for gated database tools. The confirmation gate does not sandbox pi's built-in tools or apply the separate Agentic Kit permissions engine.
16
16
 
17
17
  ```bash
18
18
  npm install -g @agentic-kit/cli
@@ -24,9 +24,9 @@ agent -p "explain this repo" # one-shot print mode
24
24
 
25
25
  On startup, `agent` assembles the harness skill tree and drops you into an interactive terminal session:
26
26
 
27
- 1. **Base layer** — a pinned release of [`constructive-io/constructive-skills`](https://github.com/constructive-io/constructive-skills), fetched as a git tag/branch/SHA tarball into `~/.constructive/data/skills/<version>/` (offline fallback: newest cached release).
27
+ 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).
28
28
  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.
29
- 3. **Typed db tools** — the [`@agentic-kit/pi`](https://www.npmjs.com/package/@agentic-kit/pi) extension (provision_database, provision_blueprint, describe_schema, add_records, run_codegen, … with confirm gating on pi's built-in y/n dialog) is materialized into the agent dir and loaded by pi automatically.
29
+ 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.
30
30
 
31
31
  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.
32
32
 
@@ -35,7 +35,7 @@ The merged tree is materialized into the appstash-owned agent dir, so the sessio
35
35
  | Command | Description |
36
36
  |---------|-------------|
37
37
  | `agent [options...]` | Start an interactive session with the harness skills |
38
- | `agent -p "prompt"` | One-shot print mode |
38
+ | `agent -p "prompt"` | One-shot print mode; gated tools are refused |
39
39
  | `agent init` | Configure the skills source (repo + pin) interactively |
40
40
  | `agent login` | Sign in to the Constructive platform (interactive) |
41
41
  | `agent logout` | Revoke the API key and clear the stored session |
@@ -44,6 +44,8 @@ The merged tree is materialized into the appstash-owned agent dir, so the sessio
44
44
  | `agent skills update` | Re-fetch the base release and re-materialize |
45
45
  | `agent help` | Usage |
46
46
 
47
+ Print mode has no confirmation UI, so it refuses gated database changes and `run_codegen`. Setting a credential does not bypass confirmation. Use the interactive TUI or `agent --mode rpc` with a client that handles pi's approval requests for gated operations. Ungated tools, such as `describe_schema`, can still run in print mode.
48
+
47
49
  ## Configuration
48
50
 
49
51
  `~/.constructive/config/skills-manifest.json`:
@@ -51,7 +53,7 @@ The merged tree is materialized into the appstash-owned agent dir, so the sessio
51
53
  ```json
52
54
  {
53
55
  "repo": "constructive-io/constructive-skills",
54
- "pin": "^1.0.0",
56
+ "pin": "main",
55
57
  "manifest": {
56
58
  "sources": [
57
59
  { "name": "constructive-skills" },
@@ -65,17 +67,18 @@ Env overrides: `AGENT_SKILLS_REPO`, `AGENT_SKILLS_PIN`, `AGENT_HOME` (appstash b
65
67
 
66
68
  ## Authentication
67
69
 
68
- `agent login` signs in to the Constructive platform with email and password. The flow asks for a backend first: `localnet` (a local backend on `*.localhost:3000`), `devnet` (`*.launchql.dev`), or a custom API URL. After sign-in, the CLI mints a 5-year API key for the db tools and checks it on each startup. `agent logout` revokes the key and deletes the session.
70
+ `agent login` signs in to the Constructive platform with email and password. The CLI ships no backend URLs: the flow asks for the backend's API GraphQL endpoint (e.g. `https://api.example.com/graphql`, defaulting to the last one used or `CONSTRUCTIVE_API_ENDPOINT`) and derives the auth, modules, agent and compute endpoints from its host. With no backend chosen the db tools fail and say so; they never fall back to a default host. After sign-in, the CLI mints a 5-year API key for the db tools and checks it on each startup. `agent logout` revokes the key and deletes the session.
69
71
 
70
- Credential files (mode `0600`, plaintext):
72
+ Shared appstash files:
71
73
 
72
- - `~/.constructive/config/agent/account.json` — the signed-in session (user, access token, API key)
73
- - `~/.constructive/config/agent/backend-config.json` — the selected backend endpoints
74
+ - `~/.constructive/config/credentials.json` — the signed-in session (user, access token, API key; mode `0600`, plaintext)
75
+ - `~/.constructive/config/contexts/<name>.json` — endpoints for each backend context
76
+ - `~/.constructive/config/settings.json` — shared settings, including the active context
74
77
 
75
- The db tools read these files on each tool call, so a login mid-session is picked up without a restart. Tokens never enter the environment of child processes.
78
+ The db tools read these files on each tool call, so a login mid-session is picked up without a restart. The CLI does not export stored credentials to child processes.
76
79
 
77
80
  Env overrides for CI and headless use (these win over the stored session; read per tool call):
78
- `CONSTRUCTIVE_USER_ID`, `CONSTRUCTIVE_ACCESS_TOKEN`, `CONSTRUCTIVE_API_KEY` (optional), `CONSTRUCTIVE_API_ENDPOINT`, `CONSTRUCTIVE_MODULES_ENDPOINT` (default to the local backend).
81
+ `CONSTRUCTIVE_USER_ID`, `CONSTRUCTIVE_ACCESS_TOKEN`, `CONSTRUCTIVE_API_KEY` (optional), `CONSTRUCTIVE_API_ENDPOINT` (picks the backend; the other planes derive from it), and `CONSTRUCTIVE_MODULES_ENDPOINT`, `CONSTRUCTIVE_AGENT_ENDPOINT`, `CONSTRUCTIVE_COMPUTE_ENDPOINT` to override one plane (only together with `CONSTRUCTIVE_API_ENDPOINT`).
79
82
 
80
83
  ## Roadmap
81
84
 
package/account-store.js CHANGED
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.loadSession = loadSession;
4
4
  exports.saveSession = saveSession;
5
5
  exports.clearSession = clearSession;
6
- const backend_store_1 = require("./backend-store");
7
6
  /**
8
7
  * Sessions live in the shared Constructive stash, as the credentials of the
9
8
  * active context (the chosen backend). The store owns the file layout, the
@@ -13,9 +12,12 @@ const backend_store_1 = require("./backend-store");
13
12
  function currentContextName(store) {
14
13
  return store.getCurrentContext()?.name ?? null;
15
14
  }
16
- /** The active context, defaulting to localnet the first time one is needed. */
15
+ /** The active context; a session is never filed under a backend nobody chose. */
17
16
  function ensureContextName(store) {
18
- return currentContextName(store) ?? (0, backend_store_1.saveBackendConfig)(store, backend_store_1.BACKEND_PRESETS.localnet);
17
+ const name = currentContextName(store);
18
+ if (!name)
19
+ throw new Error('No backend chosen — run `agent login` first.');
20
+ return name;
19
21
  }
20
22
  function loadSession(store, context) {
21
23
  const contextName = context ?? currentContextName(store);
@@ -1,19 +1,28 @@
1
1
  import { ConfigStore } from 'appstash';
2
+ /** Every Constructive plane the agent talks to, one GraphQL endpoint each. */
2
3
  export interface BackendConfig {
3
4
  apiEndpoint: string;
4
5
  authEndpoint: string;
5
6
  modulesEndpoint: string;
7
+ agentEndpoint: string;
8
+ computeEndpoint: string;
6
9
  }
7
- export declare const BACKEND_PRESETS: Record<string, BackendConfig>;
8
- /** Context name used for endpoints that match no preset. */
9
- export declare const CUSTOM_CONTEXT = "custom";
10
10
  /**
11
- * A chosen backend is a named context in the shared store: the preset name when
12
- * the endpoints match one, `custom` otherwise. Credentials hang off the context,
13
- * so signing in against localnet and devnet keeps two independent sessions.
11
+ * The CLI ships no backend URLs: the user names the api endpoint, and the other
12
+ * planes share its host scheme (api.<apex> -> auth.<apex>, modules.<apex>, ...).
13
+ * Throws on anything that is not an absolute URL.
14
+ */
15
+ export declare function backendFromApiEndpoint(apiEndpoint: string): BackendConfig;
16
+ /**
17
+ * A chosen backend is a named context in the shared store, named after the api
18
+ * endpoint's apex (https://api.example.com/graphql -> example.com). Credentials
19
+ * hang off the context, so each backend keeps an independent session.
14
20
  */
15
21
  export declare function contextNameFor(config: BackendConfig): string;
16
- /** Endpoints of the active context, or null when no backend has been chosen. */
22
+ /**
23
+ * Endpoints of the active context, or null when no backend has been chosen or
24
+ * the context lacks a plane: callers must fail then, never pick a default.
25
+ */
17
26
  export declare function loadBackendConfig(store: ConfigStore): BackendConfig | null;
18
27
  /** Persist the endpoints as a context and make it active. */
19
28
  export declare function saveBackendConfig(store: ConfigStore, config: BackendConfig): string;
package/backend-store.js CHANGED
@@ -1,47 +1,60 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CUSTOM_CONTEXT = exports.BACKEND_PRESETS = void 0;
3
+ exports.backendFromApiEndpoint = backendFromApiEndpoint;
4
4
  exports.contextNameFor = contextNameFor;
5
5
  exports.loadBackendConfig = loadBackendConfig;
6
6
  exports.saveBackendConfig = saveBackendConfig;
7
- exports.BACKEND_PRESETS = {
8
- localnet: {
9
- apiEndpoint: 'http://api.localhost:3000/graphql',
10
- authEndpoint: 'http://auth.localhost:3000/graphql',
11
- modulesEndpoint: 'http://modules.localhost:3000/graphql'
12
- },
13
- devnet: {
14
- apiEndpoint: 'https://api.launchql.dev/graphql',
15
- authEndpoint: 'https://auth.launchql.dev/graphql',
16
- modulesEndpoint: 'https://modules.launchql.dev/graphql'
17
- }
7
+ const pi_1 = require("@agentic-kit/pi");
8
+ const PLANES = ['api', 'auth', 'modules', 'agent', 'compute'];
9
+ const KEY = {
10
+ api: 'apiEndpoint',
11
+ auth: 'authEndpoint',
12
+ modules: 'modulesEndpoint',
13
+ agent: 'agentEndpoint',
14
+ compute: 'computeEndpoint'
18
15
  };
19
- /** Context name used for endpoints that match no preset. */
20
- exports.CUSTOM_CONTEXT = 'custom';
21
16
  /**
22
- * A chosen backend is a named context in the shared store: the preset name when
23
- * the endpoints match one, `custom` otherwise. Credentials hang off the context,
24
- * so signing in against localnet and devnet keeps two independent sessions.
17
+ * The CLI ships no backend URLs: the user names the api endpoint, and the other
18
+ * planes share its host scheme (api.<apex> -> auth.<apex>, modules.<apex>, ...).
19
+ * Throws on anything that is not an absolute URL.
25
20
  */
26
- function contextNameFor(config) {
27
- for (const [name, preset] of Object.entries(exports.BACKEND_PRESETS)) {
28
- if (preset.apiEndpoint === config.apiEndpoint &&
29
- preset.authEndpoint === config.authEndpoint &&
30
- preset.modulesEndpoint === config.modulesEndpoint) {
31
- return name;
32
- }
21
+ function backendFromApiEndpoint(apiEndpoint) {
22
+ const api = apiEndpoint.trim();
23
+ const config = { apiEndpoint: api };
24
+ for (const plane of PLANES) {
25
+ if (plane === 'api')
26
+ continue;
27
+ const endpoint = api ? (0, pi_1.deriveSubdomainEndpoint)(api, plane) : '';
28
+ if (!endpoint)
29
+ throw new Error(`Invalid API endpoint URL: ${api || '(empty)'}`);
30
+ config[KEY[plane]] = endpoint;
33
31
  }
34
- return exports.CUSTOM_CONTEXT;
32
+ return config;
33
+ }
34
+ /**
35
+ * A chosen backend is a named context in the shared store, named after the api
36
+ * endpoint's apex (https://api.example.com/graphql -> example.com). Credentials
37
+ * hang off the context, so each backend keeps an independent session.
38
+ */
39
+ function contextNameFor(config) {
40
+ const { host } = new URL(config.apiEndpoint);
41
+ const apex = host.includes('.') ? host.slice(host.indexOf('.') + 1) : host;
42
+ return apex.toLowerCase().replace(/[^a-z0-9.-]+/g, '-');
35
43
  }
36
44
  function toBackendConfig(targets) {
37
- const apiEndpoint = targets?.api?.endpoint;
38
- const authEndpoint = targets?.auth?.endpoint;
39
- const modulesEndpoint = targets?.modules?.endpoint;
40
- if (!apiEndpoint || !authEndpoint || !modulesEndpoint)
41
- return null;
42
- return { apiEndpoint, authEndpoint, modulesEndpoint };
45
+ const config = {};
46
+ for (const plane of PLANES) {
47
+ const endpoint = targets?.[plane]?.endpoint;
48
+ if (!endpoint)
49
+ return null;
50
+ config[KEY[plane]] = endpoint;
51
+ }
52
+ return config;
43
53
  }
44
- /** Endpoints of the active context, or null when no backend has been chosen. */
54
+ /**
55
+ * Endpoints of the active context, or null when no backend has been chosen or
56
+ * the context lacks a plane: callers must fail then, never pick a default.
57
+ */
45
58
  function loadBackendConfig(store) {
46
59
  const ctx = store.getCurrentContext();
47
60
  if (!ctx)
@@ -51,14 +64,8 @@ function loadBackendConfig(store) {
51
64
  /** Persist the endpoints as a context and make it active. */
52
65
  function saveBackendConfig(store, config) {
53
66
  const name = contextNameFor(config);
54
- store.createContext(name, {
55
- endpoint: config.apiEndpoint,
56
- targets: {
57
- api: { endpoint: config.apiEndpoint },
58
- auth: { endpoint: config.authEndpoint },
59
- modules: { endpoint: config.modulesEndpoint }
60
- }
61
- });
67
+ const targets = Object.fromEntries(PLANES.map((plane) => [plane, { endpoint: config[KEY[plane]] }]));
68
+ store.createContext(name, { endpoint: config.apiEndpoint, targets });
62
69
  store.setCurrentContext(name);
63
70
  return name;
64
71
  }
package/commands.js CHANGED
@@ -7,7 +7,6 @@ exports.login = login;
7
7
  exports.logout = logout;
8
8
  exports.whoami = whoami;
9
9
  exports.usage = usage;
10
- const pi_1 = require("@agentic-kit/pi");
11
10
  const inquirerer_1 = require("inquirerer");
12
11
  const account_store_1 = require("./account-store");
13
12
  const auth_1 = require("./auth");
@@ -65,38 +64,16 @@ async function login(config, argv) {
65
64
  const prompter = new inquirerer_1.Inquirerer({ noTty: !process.stdin.isTTY });
66
65
  try {
67
66
  const answers = await prompter.prompt(argv, [
68
- {
69
- type: 'list',
70
- name: 'backend',
71
- message: 'Backend',
72
- options: [...Object.keys(backend_store_1.BACKEND_PRESETS), 'custom'],
73
- default: saved ? (0, backend_store_1.contextNameFor)(saved) : 'localnet'
74
- },
75
67
  {
76
68
  type: 'text',
77
69
  name: 'apiUrl',
78
70
  message: 'API GraphQL endpoint (e.g. https://api.example.com/graphql)',
79
- default: saved?.apiEndpoint,
80
- when: (a) => a.backend === 'custom'
71
+ default: saved?.apiEndpoint ?? process.env.CONSTRUCTIVE_API_ENDPOINT
81
72
  },
82
73
  { type: 'text', name: 'email', message: 'Email' },
83
74
  { type: 'password', name: 'password', message: 'Password' }
84
75
  ]);
85
- let backend;
86
- if (answers.backend === 'custom') {
87
- const apiUrl = String(answers.apiUrl ?? '').trim();
88
- const authEndpoint = (0, pi_1.deriveSubdomainEndpoint)(apiUrl, 'auth');
89
- const modulesEndpoint = (0, pi_1.deriveSubdomainEndpoint)(apiUrl, 'modules');
90
- if (!apiUrl || !authEndpoint || !modulesEndpoint) {
91
- throw new Error(`Invalid API endpoint URL: ${apiUrl || '(empty)'}`);
92
- }
93
- backend = { apiEndpoint: apiUrl, authEndpoint, modulesEndpoint };
94
- }
95
- else {
96
- backend = backend_store_1.BACKEND_PRESETS[String(answers.backend)];
97
- if (!backend)
98
- throw new Error(`Unknown backend preset: ${answers.backend}`);
99
- }
76
+ const backend = (0, backend_store_1.backendFromApiEndpoint)(String(answers.apiUrl ?? ''));
100
77
  // File the session under the backend's context name, then commit the backend
101
78
  // itself: a failed sign-in must leave neither behind.
102
79
  const contextName = (0, backend_store_1.contextNameFor)(backend);
@@ -123,7 +100,11 @@ async function login(config, argv) {
123
100
  }
124
101
  }
125
102
  async function logout(config) {
126
- const backend = (0, backend_store_1.loadBackendConfig)(config.store) ?? backend_store_1.BACKEND_PRESETS.localnet;
103
+ const backend = (0, backend_store_1.loadBackendConfig)(config.store);
104
+ if (!backend) {
105
+ log('not signed in.');
106
+ return;
107
+ }
127
108
  const wasSignedIn = await (0, auth_1.signOut)({
128
109
  store: config.store,
129
110
  authEndpoint: backend.authEndpoint
package/credentials.d.ts CHANGED
@@ -4,8 +4,10 @@ export type ResolvedAccount = {
4
4
  apiKey?: string;
5
5
  };
6
6
  export type ResolvedBackendConfig = {
7
- apiEndpoint?: string;
8
- modulesEndpoint?: string;
7
+ apiEndpoint: string;
8
+ modulesEndpoint: string;
9
+ agentEndpoint: string;
10
+ computeEndpoint: string;
9
11
  };
10
12
  export declare function resolveAccount(): ResolvedAccount | null;
11
13
  export declare function resolveBackendConfig(): ResolvedBackendConfig | undefined;
package/credentials.js CHANGED
@@ -20,13 +20,30 @@ function resolveAccount() {
20
20
  return null;
21
21
  return { userId: session.userId, accessToken: session.accessToken, apiKey: session.apiKey };
22
22
  }
23
+ // CONSTRUCTIVE_API_ENDPOINT picks the whole backend: the other planes derive
24
+ // from it unless their own CONSTRUCTIVE_*_ENDPOINT is set. A plane override
25
+ // without an api endpoint names no backend, so it is an error, never a partial
26
+ // config the tools would complete with a guess.
23
27
  function resolveBackendConfig() {
24
- const apiEndpoint = process.env.CONSTRUCTIVE_API_ENDPOINT;
25
- const modulesEndpoint = process.env.CONSTRUCTIVE_MODULES_ENDPOINT;
26
- if (apiEndpoint || modulesEndpoint)
27
- return { apiEndpoint, modulesEndpoint };
28
- const stored = (0, backend_store_1.loadBackendConfig)((0, config_1.loadConfig)(process.env.AGENT_HOME).store);
29
- if (!stored)
28
+ const env = process.env;
29
+ const overrides = {
30
+ modulesEndpoint: env.CONSTRUCTIVE_MODULES_ENDPOINT,
31
+ agentEndpoint: env.CONSTRUCTIVE_AGENT_ENDPOINT,
32
+ computeEndpoint: env.CONSTRUCTIVE_COMPUTE_ENDPOINT
33
+ };
34
+ const backend = env.CONSTRUCTIVE_API_ENDPOINT
35
+ ? (0, backend_store_1.backendFromApiEndpoint)(env.CONSTRUCTIVE_API_ENDPOINT)
36
+ : (0, backend_store_1.loadBackendConfig)((0, config_1.loadConfig)(env.AGENT_HOME).store);
37
+ if (!backend) {
38
+ const stray = Object.entries(overrides).find(([, value]) => value);
39
+ if (stray)
40
+ throw new Error('CONSTRUCTIVE_API_ENDPOINT is required when any CONSTRUCTIVE_*_ENDPOINT override is set.');
30
41
  return undefined;
31
- return { apiEndpoint: stored.apiEndpoint, modulesEndpoint: stored.modulesEndpoint };
42
+ }
43
+ return {
44
+ apiEndpoint: backend.apiEndpoint,
45
+ modulesEndpoint: overrides.modulesEndpoint || backend.modulesEndpoint,
46
+ agentEndpoint: overrides.agentEndpoint || backend.agentEndpoint,
47
+ computeEndpoint: overrides.computeEndpoint || backend.computeEndpoint
48
+ };
32
49
  }
package/db-tools.d.ts CHANGED
@@ -3,7 +3,7 @@ import { AgentCliConfig } from './config';
3
3
  * Environment variables that override the stored session at tool-call time.
4
4
  * Without env vars or a stored session the tools load but report "not signed in".
5
5
  */
6
- export declare const HOST_ENV_VARS: readonly ["CONSTRUCTIVE_USER_ID", "CONSTRUCTIVE_ACCESS_TOKEN", "CONSTRUCTIVE_API_KEY", "CONSTRUCTIVE_API_ENDPOINT", "CONSTRUCTIVE_MODULES_ENDPOINT"];
6
+ export declare const HOST_ENV_VARS: readonly ["CONSTRUCTIVE_USER_ID", "CONSTRUCTIVE_ACCESS_TOKEN", "CONSTRUCTIVE_API_KEY", "CONSTRUCTIVE_API_ENDPOINT", "CONSTRUCTIVE_MODULES_ENDPOINT", "CONSTRUCTIVE_AGENT_ENDPOINT", "CONSTRUCTIVE_COMPUTE_ENDPOINT"];
7
7
  /**
8
8
  * Write the db-tools extension entry into pi's agent dir. Returns the file
9
9
  * path, or null when @agentic-kit/pi is not installed alongside the CLI.
package/db-tools.js CHANGED
@@ -47,7 +47,9 @@ exports.HOST_ENV_VARS = [
47
47
  'CONSTRUCTIVE_ACCESS_TOKEN',
48
48
  'CONSTRUCTIVE_API_KEY',
49
49
  'CONSTRUCTIVE_API_ENDPOINT',
50
- 'CONSTRUCTIVE_MODULES_ENDPOINT'
50
+ 'CONSTRUCTIVE_MODULES_ENDPOINT',
51
+ 'CONSTRUCTIVE_AGENT_ENDPOINT',
52
+ 'CONSTRUCTIVE_COMPUTE_ENDPOINT'
51
53
  ];
52
54
  // pi's TUI loads extensions from files under <agentDir>/extensions (via jiti),
53
55
  // not from factories, so the db tools are wired by materializing a small
@@ -66,7 +68,7 @@ module.exports = createDbTools({
66
68
  account: resolveAccount,
67
69
  backendConfig: resolveBackendConfig,
68
70
  signInHint: 'Run \`agent login\` to sign in.'
69
- });
71
+ }, { excludeTools: ['add_records', 'create_api_key'] });
70
72
  `;
71
73
  }
72
74
  /**
@@ -1,4 +1,3 @@
1
- import { BACKEND_PRESETS, saveBackendConfig } from './backend-store';
2
1
  /**
3
2
  * Sessions live in the shared Constructive stash, as the credentials of the
4
3
  * active context (the chosen backend). The store owns the file layout, the
@@ -8,9 +7,12 @@ import { BACKEND_PRESETS, saveBackendConfig } from './backend-store';
8
7
  function currentContextName(store) {
9
8
  return store.getCurrentContext()?.name ?? null;
10
9
  }
11
- /** The active context, defaulting to localnet the first time one is needed. */
10
+ /** The active context; a session is never filed under a backend nobody chose. */
12
11
  function ensureContextName(store) {
13
- return currentContextName(store) ?? saveBackendConfig(store, BACKEND_PRESETS.localnet);
12
+ const name = currentContextName(store);
13
+ if (!name)
14
+ throw new Error('No backend chosen — run `agent login` first.');
15
+ return name;
14
16
  }
15
17
  export function loadSession(store, context) {
16
18
  const contextName = context ?? currentContextName(store);
@@ -1,19 +1,28 @@
1
1
  import { ConfigStore } from 'appstash';
2
+ /** Every Constructive plane the agent talks to, one GraphQL endpoint each. */
2
3
  export interface BackendConfig {
3
4
  apiEndpoint: string;
4
5
  authEndpoint: string;
5
6
  modulesEndpoint: string;
7
+ agentEndpoint: string;
8
+ computeEndpoint: string;
6
9
  }
7
- export declare const BACKEND_PRESETS: Record<string, BackendConfig>;
8
- /** Context name used for endpoints that match no preset. */
9
- export declare const CUSTOM_CONTEXT = "custom";
10
10
  /**
11
- * A chosen backend is a named context in the shared store: the preset name when
12
- * the endpoints match one, `custom` otherwise. Credentials hang off the context,
13
- * so signing in against localnet and devnet keeps two independent sessions.
11
+ * The CLI ships no backend URLs: the user names the api endpoint, and the other
12
+ * planes share its host scheme (api.<apex> -> auth.<apex>, modules.<apex>, ...).
13
+ * Throws on anything that is not an absolute URL.
14
+ */
15
+ export declare function backendFromApiEndpoint(apiEndpoint: string): BackendConfig;
16
+ /**
17
+ * A chosen backend is a named context in the shared store, named after the api
18
+ * endpoint's apex (https://api.example.com/graphql -> example.com). Credentials
19
+ * hang off the context, so each backend keeps an independent session.
14
20
  */
15
21
  export declare function contextNameFor(config: BackendConfig): string;
16
- /** Endpoints of the active context, or null when no backend has been chosen. */
22
+ /**
23
+ * Endpoints of the active context, or null when no backend has been chosen or
24
+ * the context lacks a plane: callers must fail then, never pick a default.
25
+ */
17
26
  export declare function loadBackendConfig(store: ConfigStore): BackendConfig | null;
18
27
  /** Persist the endpoints as a context and make it active. */
19
28
  export declare function saveBackendConfig(store: ConfigStore, config: BackendConfig): string;
@@ -1,41 +1,54 @@
1
- export const BACKEND_PRESETS = {
2
- localnet: {
3
- apiEndpoint: 'http://api.localhost:3000/graphql',
4
- authEndpoint: 'http://auth.localhost:3000/graphql',
5
- modulesEndpoint: 'http://modules.localhost:3000/graphql'
6
- },
7
- devnet: {
8
- apiEndpoint: 'https://api.launchql.dev/graphql',
9
- authEndpoint: 'https://auth.launchql.dev/graphql',
10
- modulesEndpoint: 'https://modules.launchql.dev/graphql'
11
- }
1
+ import { deriveSubdomainEndpoint } from '@agentic-kit/pi';
2
+ const PLANES = ['api', 'auth', 'modules', 'agent', 'compute'];
3
+ const KEY = {
4
+ api: 'apiEndpoint',
5
+ auth: 'authEndpoint',
6
+ modules: 'modulesEndpoint',
7
+ agent: 'agentEndpoint',
8
+ compute: 'computeEndpoint'
12
9
  };
13
- /** Context name used for endpoints that match no preset. */
14
- export const CUSTOM_CONTEXT = 'custom';
15
10
  /**
16
- * A chosen backend is a named context in the shared store: the preset name when
17
- * the endpoints match one, `custom` otherwise. Credentials hang off the context,
18
- * so signing in against localnet and devnet keeps two independent sessions.
11
+ * The CLI ships no backend URLs: the user names the api endpoint, and the other
12
+ * planes share its host scheme (api.<apex> -> auth.<apex>, modules.<apex>, ...).
13
+ * Throws on anything that is not an absolute URL.
19
14
  */
20
- export function contextNameFor(config) {
21
- for (const [name, preset] of Object.entries(BACKEND_PRESETS)) {
22
- if (preset.apiEndpoint === config.apiEndpoint &&
23
- preset.authEndpoint === config.authEndpoint &&
24
- preset.modulesEndpoint === config.modulesEndpoint) {
25
- return name;
26
- }
15
+ export function backendFromApiEndpoint(apiEndpoint) {
16
+ const api = apiEndpoint.trim();
17
+ const config = { apiEndpoint: api };
18
+ for (const plane of PLANES) {
19
+ if (plane === 'api')
20
+ continue;
21
+ const endpoint = api ? deriveSubdomainEndpoint(api, plane) : '';
22
+ if (!endpoint)
23
+ throw new Error(`Invalid API endpoint URL: ${api || '(empty)'}`);
24
+ config[KEY[plane]] = endpoint;
27
25
  }
28
- return CUSTOM_CONTEXT;
26
+ return config;
27
+ }
28
+ /**
29
+ * A chosen backend is a named context in the shared store, named after the api
30
+ * endpoint's apex (https://api.example.com/graphql -> example.com). Credentials
31
+ * hang off the context, so each backend keeps an independent session.
32
+ */
33
+ export function contextNameFor(config) {
34
+ const { host } = new URL(config.apiEndpoint);
35
+ const apex = host.includes('.') ? host.slice(host.indexOf('.') + 1) : host;
36
+ return apex.toLowerCase().replace(/[^a-z0-9.-]+/g, '-');
29
37
  }
30
38
  function toBackendConfig(targets) {
31
- const apiEndpoint = targets?.api?.endpoint;
32
- const authEndpoint = targets?.auth?.endpoint;
33
- const modulesEndpoint = targets?.modules?.endpoint;
34
- if (!apiEndpoint || !authEndpoint || !modulesEndpoint)
35
- return null;
36
- return { apiEndpoint, authEndpoint, modulesEndpoint };
39
+ const config = {};
40
+ for (const plane of PLANES) {
41
+ const endpoint = targets?.[plane]?.endpoint;
42
+ if (!endpoint)
43
+ return null;
44
+ config[KEY[plane]] = endpoint;
45
+ }
46
+ return config;
37
47
  }
38
- /** Endpoints of the active context, or null when no backend has been chosen. */
48
+ /**
49
+ * Endpoints of the active context, or null when no backend has been chosen or
50
+ * the context lacks a plane: callers must fail then, never pick a default.
51
+ */
39
52
  export function loadBackendConfig(store) {
40
53
  const ctx = store.getCurrentContext();
41
54
  if (!ctx)
@@ -45,14 +58,8 @@ export function loadBackendConfig(store) {
45
58
  /** Persist the endpoints as a context and make it active. */
46
59
  export function saveBackendConfig(store, config) {
47
60
  const name = contextNameFor(config);
48
- store.createContext(name, {
49
- endpoint: config.apiEndpoint,
50
- targets: {
51
- api: { endpoint: config.apiEndpoint },
52
- auth: { endpoint: config.authEndpoint },
53
- modules: { endpoint: config.modulesEndpoint }
54
- }
55
- });
61
+ const targets = Object.fromEntries(PLANES.map((plane) => [plane, { endpoint: config[KEY[plane]] }]));
62
+ store.createContext(name, { endpoint: config.apiEndpoint, targets });
56
63
  store.setCurrentContext(name);
57
64
  return name;
58
65
  }
package/esm/commands.js CHANGED
@@ -1,8 +1,7 @@
1
- import { deriveSubdomainEndpoint } from '@agentic-kit/pi';
2
1
  import { Inquirerer } from 'inquirerer';
3
2
  import { loadSession } from './account-store';
4
3
  import { signIn, signOut } from './auth';
5
- import { BACKEND_PRESETS, contextNameFor, loadBackendConfig, saveBackendConfig } from './backend-store';
4
+ import { backendFromApiEndpoint, contextNameFor, loadBackendConfig, saveBackendConfig } from './backend-store';
6
5
  import { defaultManifest, saveManifestFile } from './config';
7
6
  import { assembleSkills } from './skills';
8
7
  const log = (msg) => console.log(`[agent] ${msg}`);
@@ -56,38 +55,16 @@ export async function login(config, argv) {
56
55
  const prompter = new Inquirerer({ noTty: !process.stdin.isTTY });
57
56
  try {
58
57
  const answers = await prompter.prompt(argv, [
59
- {
60
- type: 'list',
61
- name: 'backend',
62
- message: 'Backend',
63
- options: [...Object.keys(BACKEND_PRESETS), 'custom'],
64
- default: saved ? contextNameFor(saved) : 'localnet'
65
- },
66
58
  {
67
59
  type: 'text',
68
60
  name: 'apiUrl',
69
61
  message: 'API GraphQL endpoint (e.g. https://api.example.com/graphql)',
70
- default: saved?.apiEndpoint,
71
- when: (a) => a.backend === 'custom'
62
+ default: saved?.apiEndpoint ?? process.env.CONSTRUCTIVE_API_ENDPOINT
72
63
  },
73
64
  { type: 'text', name: 'email', message: 'Email' },
74
65
  { type: 'password', name: 'password', message: 'Password' }
75
66
  ]);
76
- let backend;
77
- if (answers.backend === 'custom') {
78
- const apiUrl = String(answers.apiUrl ?? '').trim();
79
- const authEndpoint = deriveSubdomainEndpoint(apiUrl, 'auth');
80
- const modulesEndpoint = deriveSubdomainEndpoint(apiUrl, 'modules');
81
- if (!apiUrl || !authEndpoint || !modulesEndpoint) {
82
- throw new Error(`Invalid API endpoint URL: ${apiUrl || '(empty)'}`);
83
- }
84
- backend = { apiEndpoint: apiUrl, authEndpoint, modulesEndpoint };
85
- }
86
- else {
87
- backend = BACKEND_PRESETS[String(answers.backend)];
88
- if (!backend)
89
- throw new Error(`Unknown backend preset: ${answers.backend}`);
90
- }
67
+ const backend = backendFromApiEndpoint(String(answers.apiUrl ?? ''));
91
68
  // File the session under the backend's context name, then commit the backend
92
69
  // itself: a failed sign-in must leave neither behind.
93
70
  const contextName = contextNameFor(backend);
@@ -114,7 +91,11 @@ export async function login(config, argv) {
114
91
  }
115
92
  }
116
93
  export async function logout(config) {
117
- const backend = loadBackendConfig(config.store) ?? BACKEND_PRESETS.localnet;
94
+ const backend = loadBackendConfig(config.store);
95
+ if (!backend) {
96
+ log('not signed in.');
97
+ return;
98
+ }
118
99
  const wasSignedIn = await signOut({
119
100
  store: config.store,
120
101
  authEndpoint: backend.authEndpoint
@@ -4,8 +4,10 @@ export type ResolvedAccount = {
4
4
  apiKey?: string;
5
5
  };
6
6
  export type ResolvedBackendConfig = {
7
- apiEndpoint?: string;
8
- modulesEndpoint?: string;
7
+ apiEndpoint: string;
8
+ modulesEndpoint: string;
9
+ agentEndpoint: string;
10
+ computeEndpoint: string;
9
11
  };
10
12
  export declare function resolveAccount(): ResolvedAccount | null;
11
13
  export declare function resolveBackendConfig(): ResolvedBackendConfig | undefined;
@@ -1,5 +1,5 @@
1
1
  import { loadSession } from './account-store';
2
- import { loadBackendConfig } from './backend-store';
2
+ import { backendFromApiEndpoint, loadBackendConfig } from './backend-store';
3
3
  import { loadConfig } from './config';
4
4
  // Both resolvers run on every tool call and re-read the store, so a login or
5
5
  // logout mid-session is picked up without a restart. CONSTRUCTIVE_* env vars
@@ -16,13 +16,30 @@ export function resolveAccount() {
16
16
  return null;
17
17
  return { userId: session.userId, accessToken: session.accessToken, apiKey: session.apiKey };
18
18
  }
19
+ // CONSTRUCTIVE_API_ENDPOINT picks the whole backend: the other planes derive
20
+ // from it unless their own CONSTRUCTIVE_*_ENDPOINT is set. A plane override
21
+ // without an api endpoint names no backend, so it is an error, never a partial
22
+ // config the tools would complete with a guess.
19
23
  export function resolveBackendConfig() {
20
- const apiEndpoint = process.env.CONSTRUCTIVE_API_ENDPOINT;
21
- const modulesEndpoint = process.env.CONSTRUCTIVE_MODULES_ENDPOINT;
22
- if (apiEndpoint || modulesEndpoint)
23
- return { apiEndpoint, modulesEndpoint };
24
- const stored = loadBackendConfig(loadConfig(process.env.AGENT_HOME).store);
25
- if (!stored)
24
+ const env = process.env;
25
+ const overrides = {
26
+ modulesEndpoint: env.CONSTRUCTIVE_MODULES_ENDPOINT,
27
+ agentEndpoint: env.CONSTRUCTIVE_AGENT_ENDPOINT,
28
+ computeEndpoint: env.CONSTRUCTIVE_COMPUTE_ENDPOINT
29
+ };
30
+ const backend = env.CONSTRUCTIVE_API_ENDPOINT
31
+ ? backendFromApiEndpoint(env.CONSTRUCTIVE_API_ENDPOINT)
32
+ : loadBackendConfig(loadConfig(env.AGENT_HOME).store);
33
+ if (!backend) {
34
+ const stray = Object.entries(overrides).find(([, value]) => value);
35
+ if (stray)
36
+ throw new Error('CONSTRUCTIVE_API_ENDPOINT is required when any CONSTRUCTIVE_*_ENDPOINT override is set.');
26
37
  return undefined;
27
- return { apiEndpoint: stored.apiEndpoint, modulesEndpoint: stored.modulesEndpoint };
38
+ }
39
+ return {
40
+ apiEndpoint: backend.apiEndpoint,
41
+ modulesEndpoint: overrides.modulesEndpoint || backend.modulesEndpoint,
42
+ agentEndpoint: overrides.agentEndpoint || backend.agentEndpoint,
43
+ computeEndpoint: overrides.computeEndpoint || backend.computeEndpoint
44
+ };
28
45
  }
package/esm/db-tools.d.ts CHANGED
@@ -3,7 +3,7 @@ import { AgentCliConfig } from './config';
3
3
  * Environment variables that override the stored session at tool-call time.
4
4
  * Without env vars or a stored session the tools load but report "not signed in".
5
5
  */
6
- export declare const HOST_ENV_VARS: readonly ["CONSTRUCTIVE_USER_ID", "CONSTRUCTIVE_ACCESS_TOKEN", "CONSTRUCTIVE_API_KEY", "CONSTRUCTIVE_API_ENDPOINT", "CONSTRUCTIVE_MODULES_ENDPOINT"];
6
+ export declare const HOST_ENV_VARS: readonly ["CONSTRUCTIVE_USER_ID", "CONSTRUCTIVE_ACCESS_TOKEN", "CONSTRUCTIVE_API_KEY", "CONSTRUCTIVE_API_ENDPOINT", "CONSTRUCTIVE_MODULES_ENDPOINT", "CONSTRUCTIVE_AGENT_ENDPOINT", "CONSTRUCTIVE_COMPUTE_ENDPOINT"];
7
7
  /**
8
8
  * Write the db-tools extension entry into pi's agent dir. Returns the file
9
9
  * path, or null when @agentic-kit/pi is not installed alongside the CLI.
package/esm/db-tools.js CHANGED
@@ -10,7 +10,9 @@ export const HOST_ENV_VARS = [
10
10
  'CONSTRUCTIVE_ACCESS_TOKEN',
11
11
  'CONSTRUCTIVE_API_KEY',
12
12
  'CONSTRUCTIVE_API_ENDPOINT',
13
- 'CONSTRUCTIVE_MODULES_ENDPOINT'
13
+ 'CONSTRUCTIVE_MODULES_ENDPOINT',
14
+ 'CONSTRUCTIVE_AGENT_ENDPOINT',
15
+ 'CONSTRUCTIVE_COMPUTE_ENDPOINT'
14
16
  ];
15
17
  // pi's TUI loads extensions from files under <agentDir>/extensions (via jiti),
16
18
  // not from factories, so the db tools are wired by materializing a small
@@ -29,7 +31,7 @@ module.exports = createDbTools({
29
31
  account: resolveAccount,
30
32
  backendConfig: resolveBackendConfig,
31
33
  signInHint: 'Run \`agent login\` to sign in.'
32
- });
34
+ }, { excludeTools: ['add_records', 'create_api_key'] });
33
35
  `;
34
36
  }
35
37
  /**
package/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { refreshApiKeyIfNeeded } from './auth';
3
- import { BACKEND_PRESETS, loadBackendConfig } from './backend-store';
3
+ import { loadBackendConfig } from './backend-store';
4
4
  import { init, login, logout, skillsList, skillsUpdate, usage, whoami } from './commands';
5
5
  import { loadConfig } from './config';
6
6
  import { materializeDbTools } from './db-tools';
@@ -46,13 +46,15 @@ async function run(args) {
46
46
  materializeDbTools(config, log);
47
47
  // Fire-and-forget: keep the stored API key fresh (<7 days to expiry re-mints)
48
48
  // without ever blocking startup. Only an expired login session gets a line.
49
- const backend = loadBackendConfig(config.store) ?? BACKEND_PRESETS.localnet;
50
- void refreshApiKeyIfNeeded({ store: config.store, authEndpoint: backend.authEndpoint })
51
- .then((status) => {
52
- if (status === 'reauth-required')
53
- log('API key expired — run `agent login`');
54
- })
55
- .catch(() => { });
49
+ const backend = loadBackendConfig(config.store);
50
+ if (backend) {
51
+ void refreshApiKeyIfNeeded({ store: config.store, authEndpoint: backend.authEndpoint })
52
+ .then((status) => {
53
+ if (status === 'reauth-required')
54
+ log('API key expired — run `agent login`');
55
+ })
56
+ .catch(() => { });
57
+ }
56
58
  // pi is ESM-only; tsc's CJS output would downlevel a plain `await import()`
57
59
  // into `require()`, which cannot load it. Indirect the import so it survives
58
60
  // transpilation in the CJS build.
package/index.js CHANGED
@@ -53,13 +53,15 @@ async function run(args) {
53
53
  (0, db_tools_1.materializeDbTools)(config, log);
54
54
  // Fire-and-forget: keep the stored API key fresh (<7 days to expiry re-mints)
55
55
  // without ever blocking startup. Only an expired login session gets a line.
56
- const backend = (0, backend_store_1.loadBackendConfig)(config.store) ?? backend_store_1.BACKEND_PRESETS.localnet;
57
- void (0, auth_1.refreshApiKeyIfNeeded)({ store: config.store, authEndpoint: backend.authEndpoint })
58
- .then((status) => {
59
- if (status === 'reauth-required')
60
- log('API key expired — run `agent login`');
61
- })
62
- .catch(() => { });
56
+ const backend = (0, backend_store_1.loadBackendConfig)(config.store);
57
+ if (backend) {
58
+ void (0, auth_1.refreshApiKeyIfNeeded)({ store: config.store, authEndpoint: backend.authEndpoint })
59
+ .then((status) => {
60
+ if (status === 'reauth-required')
61
+ log('API key expired — run `agent login`');
62
+ })
63
+ .catch(() => { });
64
+ }
63
65
  // pi is ESM-only; tsc's CJS output would downlevel a plain `await import()`
64
66
  // into `require()`, which cannot load it. Indirect the import so it survives
65
67
  // transpilation in the CJS build.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentic-kit/cli",
3
- "version": "0.19.51",
3
+ "version": "0.19.52",
4
4
  "author": "Dan Lynch <pyramation@gmail.com>",
5
5
  "description": "agent — the pi coding agent with the Constructive harness baked in, purely a shell",
6
6
  "main": "index.js",
@@ -26,9 +26,9 @@
26
26
  "@earendil-works/pi-coding-agent": "1.4.0",
27
27
  "appstash": "^0.8.0",
28
28
  "inquirerer": "^4.9.4",
29
- "@agentic-kit/pi": "0.28.51",
30
- "@constructive-io/sdk": "^1.21.49",
31
- "@agentic-kit/harness": "0.18.2"
29
+ "@agentic-kit/harness": "0.18.2",
30
+ "@agentic-kit/pi": "0.28.52",
31
+ "@constructive-io/sdk": "^1.21.50"
32
32
  },
33
33
  "keywords": [
34
34
  "agentic-kit",