@agentic-kit/cli 0.22.0 → 0.23.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.
- package/README.md +10 -11
- package/commands.d.ts +3 -1
- package/commands.js +80 -47
- package/config.d.ts +2 -9
- package/config.js +5 -12
- package/db-tools.d.ts +0 -5
- package/db-tools.js +10 -24
- package/esm/commands.d.ts +3 -1
- package/esm/commands.js +79 -47
- package/esm/config.d.ts +2 -9
- package/esm/config.js +4 -11
- package/esm/db-tools.d.ts +0 -5
- package/esm/db-tools.js +10 -23
- package/esm/index.d.ts +1 -1
- package/esm/index.js +12 -16
- package/index.d.ts +1 -1
- package/index.js +11 -16
- package/package.json +16 -15
- package/account-store.d.ts +0 -19
- package/account-store.js +0 -61
- package/api-key.d.ts +0 -51
- package/api-key.js +0 -96
- package/auth-error.d.ts +0 -4
- package/auth-error.js +0 -114
- package/auth.d.ts +0 -28
- package/auth.js +0 -119
- package/backend-store.d.ts +0 -28
- package/backend-store.js +0 -71
- package/credentials.d.ts +0 -13
- package/credentials.js +0 -49
- package/esm/account-store.d.ts +0 -19
- package/esm/account-store.js +0 -56
- package/esm/api-key.d.ts +0 -51
- package/esm/api-key.js +0 -88
- package/esm/auth-error.d.ts +0 -4
- package/esm/auth-error.js +0 -108
- package/esm/auth.d.ts +0 -28
- package/esm/auth.js +0 -114
- package/esm/backend-store.d.ts +0 -28
- package/esm/backend-store.js +0 -65
- package/esm/credentials.d.ts +0 -13
- package/esm/credentials.js +0 -45
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ On startup, `agent` assembles the harness skill tree and drops you into an inter
|
|
|
26
26
|
|
|
27
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 (including `provision_database`, `provision_blueprint`, `describe_schema`, and `
|
|
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`, `run_codegen`, and the access tools `describe_policy_type`, `explain_access` and `set_access`) 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.
|
|
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,16 +35,16 @@ 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; every database tool that changes something is refused, and pi's own tools still run |
|
|
39
39
|
| `agent init` | Configure the skills source (repo + pin) interactively |
|
|
40
40
|
| `agent login` | Sign in to the Constructive platform (interactive) |
|
|
41
|
-
| `agent logout` | Revoke the API key and clear the stored session |
|
|
42
|
-
| `agent whoami` | Show the signed-in account, backend, and masked API key |
|
|
41
|
+
| `agent logout` | Revoke the API key at the backend that issued it and clear the stored session; a session from the environment is not stored, so there is nothing to remove |
|
|
42
|
+
| `agent whoami` | Show the signed-in account, backend, and masked API key, and ask the backend whether it still accepts the credential |
|
|
43
43
|
| `agent skills list` | Resolve and list the effective skill set per layer |
|
|
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
|
|
47
|
+
Print mode has no confirmation UI, so it refuses every database tool whose effect is a write or a destructive change, `run_codegen` included. 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. Database tools that only read, such as `describe_schema`, still run in print mode, and so do pi's own tools (`bash`, `edit`, `write`): the gate covers the database tools only.
|
|
48
48
|
|
|
49
49
|
## Configuration
|
|
50
50
|
|
|
@@ -63,22 +63,21 @@ Print mode has no confirmation UI, so it refuses gated database changes and `run
|
|
|
63
63
|
}
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
Env overrides: `AGENT_SKILLS_REPO`, `AGENT_SKILLS_PIN`, `
|
|
66
|
+
Env overrides: `AGENT_SKILLS_REPO`, `AGENT_SKILLS_PIN`, `CONSTRUCTIVE_STASH_DIR` (base directory that replaces `~` for `~/.constructive/`, shared with the session store and Constructive Desktop), `GITHUB_TOKEN` (private skills repos).
|
|
67
67
|
|
|
68
68
|
## Authentication
|
|
69
69
|
|
|
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
|
|
70
|
+
`agent login` signs in to the Constructive platform with email and password, through [`@agentic-kit/session`](https://www.npmjs.com/package/@agentic-kit/session), the sign-in every Constructive binary shares. 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 backend the session resolves to: the one `CONSTRUCTIVE_*` names, else the current context. Given that backend's own api endpoint, it signs in with all of that backend's planes, as `constructive login` does; any other endpoint is a new backend whose auth, modules, agent and compute endpoints are derived from its host. An account with a second factor is then asked for its code: the one the backend emails or texts, or the one an authenticator app shows. With no backend chosen the db tools fail and say so; they never fall back to a default host. After sign-in, the CLI asks for a 30-day API key for the db tools, then ends the password sign-in on the backend, so the key is the only credential it keeps. If no key can be made, the sign-in fails and nothing is stored; at the account's key limit, run `agent logout` first, which revokes this computer's key, or revoke a key in the app. When the key is within 7 days of its end, each startup asks you to run `agent login` again, which signs you in and mints a new key; nothing renews it on its own. `agent logout` deletes the session and revokes its key, and says so when the revoke fails.
|
|
71
71
|
|
|
72
|
-
Shared appstash files:
|
|
72
|
+
Shared appstash files (with `CONSTRUCTIVE_STASH_DIR` set, each `~/.constructive/` below is `$CONSTRUCTIVE_STASH_DIR/.constructive/`):
|
|
73
73
|
|
|
74
|
-
- `~/.constructive/config/credentials.json` — the signed-in session (user
|
|
74
|
+
- `~/.constructive/config/credentials.json` — the signed-in session (user and API key; mode `0600`, plaintext)
|
|
75
75
|
- `~/.constructive/config/contexts/<name>.json` — endpoints for each backend context
|
|
76
76
|
- `~/.constructive/config/settings.json` — shared settings, including the active context
|
|
77
77
|
|
|
78
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.
|
|
79
79
|
|
|
80
|
-
Env overrides for CI and headless use (
|
|
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`).
|
|
80
|
+
Env overrides for CI and headless use (read per tool call): `CONSTRUCTIVE_USER_ID`, `CONSTRUCTIVE_ACCESS_TOKEN` and `CONSTRUCTIVE_API_KEY` (optional) give the credential, and need `CONSTRUCTIVE_API_ENDPOINT` to name its backend. `CONSTRUCTIVE_API_ENDPOINT` alone picks a backend; the stored session is used with it only when it names the backend of the active context. `CONSTRUCTIVE_AUTH_ENDPOINT`, `CONSTRUCTIVE_MODULES_ENDPOINT`, `CONSTRUCTIVE_AGENT_ENDPOINT` and `CONSTRUCTIVE_COMPUTE_ENDPOINT` give one plane each (only together with `CONSTRUCTIVE_API_ENDPOINT`); the planes are derived only from an api host that starts with `api.`. An incomplete or wrong set is reported at startup, and every db tool call fails with that cause (for example `no-backend` naming `CONSTRUCTIVE_API_ENDPOINT`) in place of a sign-in prompt. See [`@agentic-kit/session`](https://www.npmjs.com/package/@agentic-kit/session) for the rules.
|
|
82
81
|
|
|
83
82
|
## Roadmap
|
|
84
83
|
|
package/commands.d.ts
CHANGED
|
@@ -4,5 +4,7 @@ export declare function skillsUpdate(config: AgentCliConfig): Promise<void>;
|
|
|
4
4
|
export declare function init(config: AgentCliConfig, argv: Record<string, unknown>): Promise<void>;
|
|
5
5
|
export declare function login(config: AgentCliConfig, argv: Record<string, unknown>): Promise<void>;
|
|
6
6
|
export declare function logout(config: AgentCliConfig): Promise<void>;
|
|
7
|
-
|
|
7
|
+
/** The `agent` command that stores a complete backend context. */
|
|
8
|
+
export declare const REPAIR_HINT = "Run `agent login` to store a complete backend.";
|
|
9
|
+
export declare function whoami(config: AgentCliConfig): Promise<void>;
|
|
8
10
|
export declare function usage(): void;
|
package/commands.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REPAIR_HINT = void 0;
|
|
3
4
|
exports.skillsList = skillsList;
|
|
4
5
|
exports.skillsUpdate = skillsUpdate;
|
|
5
6
|
exports.init = init;
|
|
@@ -7,10 +8,8 @@ exports.login = login;
|
|
|
7
8
|
exports.logout = logout;
|
|
8
9
|
exports.whoami = whoami;
|
|
9
10
|
exports.usage = usage;
|
|
11
|
+
const session_1 = require("@agentic-kit/session");
|
|
10
12
|
const inquirerer_1 = require("inquirerer");
|
|
11
|
-
const account_store_1 = require("./account-store");
|
|
12
|
-
const auth_1 = require("./auth");
|
|
13
|
-
const backend_store_1 = require("./backend-store");
|
|
14
13
|
const config_1 = require("./config");
|
|
15
14
|
const skills_1 = require("./skills");
|
|
16
15
|
const log = (msg) => console.log(`[agent] ${msg}`);
|
|
@@ -56,11 +55,17 @@ function maskKey(token) {
|
|
|
56
55
|
return '****';
|
|
57
56
|
return `${token.slice(0, 6)}...${token.slice(-4)}`;
|
|
58
57
|
}
|
|
58
|
+
const CODE_PROMPT = {
|
|
59
|
+
email: 'Code from your email',
|
|
60
|
+
sms: 'Code from your text message',
|
|
61
|
+
totp: 'Code from your authenticator app, or a backup code'
|
|
62
|
+
};
|
|
59
63
|
async function login(config, argv) {
|
|
60
64
|
if (!process.stdin.isTTY && !(argv.email && argv.password)) {
|
|
61
|
-
throw new Error('agent login is interactive and needs a terminal. For headless use, set CONSTRUCTIVE_USER_ID, CONSTRUCTIVE_ACCESS_TOKEN, and CONSTRUCTIVE_API_KEY.');
|
|
65
|
+
throw new Error('agent login is interactive and needs a terminal. For headless use, set CONSTRUCTIVE_API_ENDPOINT, CONSTRUCTIVE_USER_ID, CONSTRUCTIVE_ACCESS_TOKEN, and CONSTRUCTIVE_API_KEY.');
|
|
62
66
|
}
|
|
63
|
-
|
|
67
|
+
// The backend the session resolves to (CONSTRUCTIVE_* first, else the current context) is the default.
|
|
68
|
+
const resolved = (0, session_1.signInTarget)({ store: config.store });
|
|
64
69
|
const prompter = new inquirerer_1.Inquirerer({ noTty: !process.stdin.isTTY });
|
|
65
70
|
try {
|
|
66
71
|
const answers = await prompter.prompt(argv, [
|
|
@@ -68,72 +73,100 @@ async function login(config, argv) {
|
|
|
68
73
|
type: 'text',
|
|
69
74
|
name: 'apiUrl',
|
|
70
75
|
message: 'API GraphQL endpoint (e.g. https://api.example.com/graphql)',
|
|
71
|
-
default:
|
|
76
|
+
default: resolved.kind === 'target' ? resolved.backend.apiEndpoint : undefined
|
|
72
77
|
},
|
|
73
78
|
{ type: 'text', name: 'email', message: 'Email' },
|
|
74
79
|
{ type: 'password', name: 'password', message: 'Password' }
|
|
75
80
|
]);
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
81
|
+
const target = (0, session_1.signInTarget)({ store: config.store, api: String(answers.apiUrl ?? '') });
|
|
82
|
+
const email = String(answers.email ?? '');
|
|
83
|
+
const signInWith = (proof) => (0, session_1.signIn)({ store: config.store, backend: target.backend, ...(target.context ? { context: target.context } : {}), email, ...proof });
|
|
84
|
+
let result;
|
|
85
|
+
try {
|
|
86
|
+
result = await signInWith({ password: String(answers.password ?? '') });
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
// The password was accepted, and the account has a second factor: its code finishes the same sign-in.
|
|
90
|
+
if (!(error instanceof session_1.SecondFactorRequired))
|
|
91
|
+
throw error;
|
|
92
|
+
const { code } = await prompter.prompt(argv, [{ type: 'password', name: 'code', message: CODE_PROMPT[error.challenge.method] }]);
|
|
93
|
+
result = await signInWith({ challenge: error.challenge, code: String(code ?? '') });
|
|
94
|
+
}
|
|
95
|
+
const { session, context, previousKey } = result;
|
|
88
96
|
log(`signed in as ${session.email}`);
|
|
89
|
-
log(`backend: ${backend.apiEndpoint}`);
|
|
97
|
+
log(`backend: ${target.backend.apiEndpoint}`);
|
|
90
98
|
if (session.apiKey) {
|
|
91
99
|
log(`API key ${maskKey(session.apiKey)} (expires ${session.apiKeyExpiresAt ?? 'unknown'})`);
|
|
92
100
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
log(`session stored in context ${
|
|
101
|
+
const replaced = previousKeyWarning(previousKey);
|
|
102
|
+
if (replaced)
|
|
103
|
+
log(`warning: ${replaced}`);
|
|
104
|
+
log(`session stored in context ${context}`);
|
|
97
105
|
}
|
|
98
106
|
finally {
|
|
99
107
|
prompter.close();
|
|
100
108
|
}
|
|
101
109
|
}
|
|
110
|
+
function previousKeyWarning(previousKey) {
|
|
111
|
+
if (previousKey.kind !== 'failed')
|
|
112
|
+
return null;
|
|
113
|
+
return `the API key ${previousKey.keyId} of the replaced session could not be revoked (${previousKey.reason}); it stays valid until it expires.`;
|
|
114
|
+
}
|
|
102
115
|
async function logout(config) {
|
|
103
|
-
const
|
|
104
|
-
if (
|
|
116
|
+
const result = await (0, session_1.signOut)({ store: config.store, session: (0, session_1.resolveSession)({ store: config.store }) });
|
|
117
|
+
if (result.kind === 'not-signed-in') {
|
|
105
118
|
log('not signed in.');
|
|
106
119
|
return;
|
|
107
120
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
121
|
+
if (result.kind === 'from-environment') {
|
|
122
|
+
log('nothing to sign out of: the session comes from the environment (CONSTRUCTIVE_USER_ID, CONSTRUCTIVE_ACCESS_TOKEN). Unset them to sign out.');
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
switch (result.key.kind) {
|
|
126
|
+
case 'revoked':
|
|
127
|
+
log('signed out — API key revoked and session cleared.');
|
|
128
|
+
break;
|
|
129
|
+
case 'absent':
|
|
130
|
+
log('signed out — session cleared (it had no API key).');
|
|
131
|
+
break;
|
|
132
|
+
case 'failed':
|
|
133
|
+
log(`signed out — session cleared, but the API key ${result.key.keyId} could not be revoked (${result.key.reason}); it stays valid until it expires.`);
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
116
136
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
137
|
+
/** The `agent` command that stores a complete backend context. */
|
|
138
|
+
exports.REPAIR_HINT = 'Run `agent login` to store a complete backend.';
|
|
139
|
+
async function whoami(config) {
|
|
140
|
+
const session = (0, session_1.resolveSession)({ store: config.store });
|
|
141
|
+
if (session.kind !== 'signed-in') {
|
|
142
|
+
log((0, session_1.sessionProblem)(session, exports.REPAIR_HINT) ?? 'not signed in — run `agent login`');
|
|
121
143
|
process.exitCode = 1;
|
|
122
144
|
return;
|
|
123
145
|
}
|
|
124
|
-
const backend =
|
|
125
|
-
log(`signed in as ${
|
|
126
|
-
log(`user id: ${
|
|
127
|
-
log(`backend: ${backend
|
|
128
|
-
if (
|
|
129
|
-
log(`API key: ${maskKey(
|
|
146
|
+
const { account, backend } = session;
|
|
147
|
+
log(`signed in as ${account.email ?? `user ${account.userId}`}${session.source === 'env' ? ' (from the environment)' : ''}`);
|
|
148
|
+
log(`user id: ${account.userId}`);
|
|
149
|
+
log(`backend: ${backend.apiEndpoint}`);
|
|
150
|
+
if (account.key.kind === 'active') {
|
|
151
|
+
log(`API key: ${maskKey(account.key.apiKey)} (expires ${account.key.expiresAt ?? 'unknown'})`);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
log('API key: none — commands use the access token until it ends. Run `agent login` for a 30-day key.');
|
|
155
|
+
}
|
|
156
|
+
if (account.key.kind === 'none' && account.accessTokenExpiresAt)
|
|
157
|
+
log(`access token expires: ${account.accessTokenExpiresAt}`);
|
|
158
|
+
log(`context: ${session.context ?? 'none'}`);
|
|
159
|
+
const check = await (0, session_1.verifySession)(session);
|
|
160
|
+
if (check.kind === 'accepted') {
|
|
161
|
+
log('credential: accepted by the backend');
|
|
162
|
+
}
|
|
163
|
+
else if (check.kind === 'rejected') {
|
|
164
|
+
log(`credential: rejected — ${check.reason} Run \`agent login\` to sign in again.`);
|
|
165
|
+
process.exitCode = 1;
|
|
130
166
|
}
|
|
131
167
|
else {
|
|
132
|
-
log(
|
|
168
|
+
log(`credential: not checked — ${check.reason}`);
|
|
133
169
|
}
|
|
134
|
-
if (session.accessTokenExpiresAt)
|
|
135
|
-
log(`access token expires: ${session.accessTokenExpiresAt}`);
|
|
136
|
-
log(`context: ${config.store.getCurrentContext()?.name ?? 'none'}`);
|
|
137
170
|
}
|
|
138
171
|
function usage() {
|
|
139
172
|
console.log(`agent — the pi coding agent with the Constructive harness baked in
|
package/config.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { FetchLike, HarnessDirs, SkillsManifest } from '@agentic-kit/harness';
|
|
2
|
-
import { ConfigStore } from '
|
|
2
|
+
import { ConfigStore } from '@agentic-kit/session';
|
|
3
3
|
export declare const DEFAULT_SKILLS_REPO = "constructive-io/constructive-skills";
|
|
4
|
-
/**
|
|
5
|
-
* Directory identity shared with the csdk CLI and the desktop app, so a sign-in
|
|
6
|
-
* here is a sign-in there. `agent` is only the tool's own name (env prefixes,
|
|
7
|
-
* help text).
|
|
8
|
-
*/
|
|
9
|
-
export declare const STASH_NAME = "constructive";
|
|
10
|
-
export declare const TOOL_NAME = "agent";
|
|
11
4
|
export declare const DEFAULT_SKILLS_PIN = "main";
|
|
12
5
|
/** Layer names understood by the assembler. */
|
|
13
6
|
export declare const BASE_LAYER = "constructive-skills";
|
|
@@ -38,6 +31,6 @@ interface ManifestFile {
|
|
|
38
31
|
manifest?: SkillsManifest;
|
|
39
32
|
}
|
|
40
33
|
export declare function defaultManifest(): SkillsManifest;
|
|
41
|
-
export declare function loadConfig(baseDir?: string): AgentCliConfig;
|
|
34
|
+
export declare function loadConfig(baseDir?: string | undefined): AgentCliConfig;
|
|
42
35
|
export declare function saveManifestFile(config: AgentCliConfig, file: ManifestFile): void;
|
|
43
36
|
export {};
|
package/config.js
CHANGED
|
@@ -33,22 +33,15 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.OVERLAY_LAYER = exports.BASE_LAYER = exports.DEFAULT_SKILLS_PIN = exports.
|
|
36
|
+
exports.OVERLAY_LAYER = exports.BASE_LAYER = exports.DEFAULT_SKILLS_PIN = exports.DEFAULT_SKILLS_REPO = void 0;
|
|
37
37
|
exports.defaultManifest = defaultManifest;
|
|
38
38
|
exports.loadConfig = loadConfig;
|
|
39
39
|
exports.saveManifestFile = saveManifestFile;
|
|
40
40
|
const harness_1 = require("@agentic-kit/harness");
|
|
41
|
-
const
|
|
41
|
+
const session_1 = require("@agentic-kit/session");
|
|
42
42
|
const fs = __importStar(require("fs"));
|
|
43
43
|
const path = __importStar(require("path"));
|
|
44
44
|
exports.DEFAULT_SKILLS_REPO = 'constructive-io/constructive-skills';
|
|
45
|
-
/**
|
|
46
|
-
* Directory identity shared with the csdk CLI and the desktop app, so a sign-in
|
|
47
|
-
* here is a sign-in there. `agent` is only the tool's own name (env prefixes,
|
|
48
|
-
* help text).
|
|
49
|
-
*/
|
|
50
|
-
exports.STASH_NAME = 'constructive';
|
|
51
|
-
exports.TOOL_NAME = 'agent';
|
|
52
45
|
exports.DEFAULT_SKILLS_PIN = 'main';
|
|
53
46
|
/** Layer names understood by the assembler. */
|
|
54
47
|
exports.BASE_LAYER = 'constructive-skills';
|
|
@@ -58,12 +51,12 @@ function defaultManifest() {
|
|
|
58
51
|
sources: [{ name: exports.BASE_LAYER }, { name: exports.OVERLAY_LAYER }]
|
|
59
52
|
};
|
|
60
53
|
}
|
|
61
|
-
function loadConfig(baseDir) {
|
|
62
|
-
const dirs = (0, harness_1.harnessDirs)(
|
|
54
|
+
function loadConfig(baseDir = (0, session_1.stashBaseDir)()) {
|
|
55
|
+
const dirs = (0, harness_1.harnessDirs)(session_1.STASH_NAME, baseDir);
|
|
63
56
|
const agentDir = path.join(dirs.stash.data, 'agent');
|
|
64
57
|
const overlayDir = path.join(dirs.stash.config, 'skills-overlay');
|
|
65
58
|
const manifestFile = path.join(dirs.stash.config, 'skills-manifest.json');
|
|
66
|
-
const store = (0,
|
|
59
|
+
const store = (0, session_1.openStore)(baseDir);
|
|
67
60
|
fs.mkdirSync(agentDir, { recursive: true });
|
|
68
61
|
fs.mkdirSync(overlayDir, { recursive: true });
|
|
69
62
|
let file = {};
|
package/db-tools.d.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import { AgentCliConfig } from './config';
|
|
2
|
-
/**
|
|
3
|
-
* Environment variables that override the stored session at tool-call time.
|
|
4
|
-
* Without env vars or a stored session the tools load but report "not signed in".
|
|
5
|
-
*/
|
|
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
2
|
/**
|
|
8
3
|
* Write the db-tools extension entry into pi's agent dir. Returns the file
|
|
9
4
|
* path, or null when @agentic-kit/pi is not installed alongside the CLI.
|
package/db-tools.js
CHANGED
|
@@ -33,42 +33,28 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.HOST_ENV_VARS = void 0;
|
|
37
36
|
exports.materializeDbTools = materializeDbTools;
|
|
38
37
|
const fs = __importStar(require("fs"));
|
|
39
38
|
const path = __importStar(require("path"));
|
|
39
|
+
const commands_1 = require("./commands");
|
|
40
40
|
const EXTENSION_FILE = 'constructive-db-tools.js';
|
|
41
|
-
/**
|
|
42
|
-
* Environment variables that override the stored session at tool-call time.
|
|
43
|
-
* Without env vars or a stored session the tools load but report "not signed in".
|
|
44
|
-
*/
|
|
45
|
-
exports.HOST_ENV_VARS = [
|
|
46
|
-
'CONSTRUCTIVE_USER_ID',
|
|
47
|
-
'CONSTRUCTIVE_ACCESS_TOKEN',
|
|
48
|
-
'CONSTRUCTIVE_API_KEY',
|
|
49
|
-
'CONSTRUCTIVE_API_ENDPOINT',
|
|
50
|
-
'CONSTRUCTIVE_MODULES_ENDPOINT',
|
|
51
|
-
'CONSTRUCTIVE_AGENT_ENDPOINT',
|
|
52
|
-
'CONSTRUCTIVE_COMPUTE_ENDPOINT'
|
|
53
|
-
];
|
|
54
41
|
// pi's TUI loads extensions from files under <agentDir>/extensions (via jiti),
|
|
55
42
|
// not from factories, so the db tools are wired by materializing a small
|
|
56
43
|
// generated entry there. Both entry paths are resolved from THIS package at
|
|
57
44
|
// assembly time and baked in, because node resolution from the appstash agent
|
|
58
45
|
// dir would not find them.
|
|
59
|
-
function extensionSource(pkgEntry,
|
|
46
|
+
function extensionSource(pkgEntry, sessionEntry) {
|
|
60
47
|
return `// Generated by @agentic-kit/cli — do not edit (rewritten on every \`agent\` run).
|
|
61
48
|
// Registers the Constructive typed db tools + confirm gate (@agentic-kit/pi)
|
|
62
49
|
// with credentials resolved on each call: CONSTRUCTIVE_* env vars first, then
|
|
63
|
-
// the
|
|
50
|
+
// the shared session store (@agentic-kit/session).
|
|
64
51
|
const { createDbTools } = require(${JSON.stringify(pkgEntry)});
|
|
65
|
-
const {
|
|
52
|
+
const { sessionToolsHost } = require(${JSON.stringify(sessionEntry)});
|
|
66
53
|
|
|
67
|
-
module.exports = createDbTools(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}, { excludeTools: ['add_records', 'update_records', 'delete_records', 'create_api_key'] });
|
|
54
|
+
module.exports = createDbTools(
|
|
55
|
+
sessionToolsHost({ signInHint: 'Run \`agent login\` to sign in.', repairHint: ${JSON.stringify(commands_1.REPAIR_HINT)} }),
|
|
56
|
+
{ excludeTools: ['add_records', 'update_records', 'delete_records', 'create_api_key'] }
|
|
57
|
+
);
|
|
72
58
|
`;
|
|
73
59
|
}
|
|
74
60
|
/**
|
|
@@ -84,10 +70,10 @@ function materializeDbTools(config, log) {
|
|
|
84
70
|
log('db tools unavailable (@agentic-kit/pi not installed) — continuing without them');
|
|
85
71
|
return null;
|
|
86
72
|
}
|
|
87
|
-
const
|
|
73
|
+
const sessionEntry = require.resolve('@agentic-kit/session');
|
|
88
74
|
const dir = path.join(config.agentDir, 'extensions');
|
|
89
75
|
fs.mkdirSync(dir, { recursive: true });
|
|
90
76
|
const file = path.join(dir, EXTENSION_FILE);
|
|
91
|
-
fs.writeFileSync(file, extensionSource(pkgEntry,
|
|
77
|
+
fs.writeFileSync(file, extensionSource(pkgEntry, sessionEntry));
|
|
92
78
|
return file;
|
|
93
79
|
}
|
package/esm/commands.d.ts
CHANGED
|
@@ -4,5 +4,7 @@ export declare function skillsUpdate(config: AgentCliConfig): Promise<void>;
|
|
|
4
4
|
export declare function init(config: AgentCliConfig, argv: Record<string, unknown>): Promise<void>;
|
|
5
5
|
export declare function login(config: AgentCliConfig, argv: Record<string, unknown>): Promise<void>;
|
|
6
6
|
export declare function logout(config: AgentCliConfig): Promise<void>;
|
|
7
|
-
|
|
7
|
+
/** The `agent` command that stores a complete backend context. */
|
|
8
|
+
export declare const REPAIR_HINT = "Run `agent login` to store a complete backend.";
|
|
9
|
+
export declare function whoami(config: AgentCliConfig): Promise<void>;
|
|
8
10
|
export declare function usage(): void;
|
package/esm/commands.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
+
import { resolveSession, SecondFactorRequired, sessionProblem, signIn, signInTarget, signOut, verifySession } from '@agentic-kit/session';
|
|
1
2
|
import { Inquirerer } from 'inquirerer';
|
|
2
|
-
import { loadSession } from './account-store';
|
|
3
|
-
import { signIn, signOut } from './auth';
|
|
4
|
-
import { backendFromApiEndpoint, contextNameFor, loadBackendConfig, saveBackendConfig } from './backend-store';
|
|
5
3
|
import { defaultManifest, saveManifestFile } from './config';
|
|
6
4
|
import { assembleSkills } from './skills';
|
|
7
5
|
const log = (msg) => console.log(`[agent] ${msg}`);
|
|
@@ -47,11 +45,17 @@ function maskKey(token) {
|
|
|
47
45
|
return '****';
|
|
48
46
|
return `${token.slice(0, 6)}...${token.slice(-4)}`;
|
|
49
47
|
}
|
|
48
|
+
const CODE_PROMPT = {
|
|
49
|
+
email: 'Code from your email',
|
|
50
|
+
sms: 'Code from your text message',
|
|
51
|
+
totp: 'Code from your authenticator app, or a backup code'
|
|
52
|
+
};
|
|
50
53
|
export async function login(config, argv) {
|
|
51
54
|
if (!process.stdin.isTTY && !(argv.email && argv.password)) {
|
|
52
|
-
throw new Error('agent login is interactive and needs a terminal. For headless use, set CONSTRUCTIVE_USER_ID, CONSTRUCTIVE_ACCESS_TOKEN, and CONSTRUCTIVE_API_KEY.');
|
|
55
|
+
throw new Error('agent login is interactive and needs a terminal. For headless use, set CONSTRUCTIVE_API_ENDPOINT, CONSTRUCTIVE_USER_ID, CONSTRUCTIVE_ACCESS_TOKEN, and CONSTRUCTIVE_API_KEY.');
|
|
53
56
|
}
|
|
54
|
-
|
|
57
|
+
// The backend the session resolves to (CONSTRUCTIVE_* first, else the current context) is the default.
|
|
58
|
+
const resolved = signInTarget({ store: config.store });
|
|
55
59
|
const prompter = new Inquirerer({ noTty: !process.stdin.isTTY });
|
|
56
60
|
try {
|
|
57
61
|
const answers = await prompter.prompt(argv, [
|
|
@@ -59,72 +63,100 @@ export async function login(config, argv) {
|
|
|
59
63
|
type: 'text',
|
|
60
64
|
name: 'apiUrl',
|
|
61
65
|
message: 'API GraphQL endpoint (e.g. https://api.example.com/graphql)',
|
|
62
|
-
default:
|
|
66
|
+
default: resolved.kind === 'target' ? resolved.backend.apiEndpoint : undefined
|
|
63
67
|
},
|
|
64
68
|
{ type: 'text', name: 'email', message: 'Email' },
|
|
65
69
|
{ type: 'password', name: 'password', message: 'Password' }
|
|
66
70
|
]);
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
71
|
+
const target = signInTarget({ store: config.store, api: String(answers.apiUrl ?? '') });
|
|
72
|
+
const email = String(answers.email ?? '');
|
|
73
|
+
const signInWith = (proof) => signIn({ store: config.store, backend: target.backend, ...(target.context ? { context: target.context } : {}), email, ...proof });
|
|
74
|
+
let result;
|
|
75
|
+
try {
|
|
76
|
+
result = await signInWith({ password: String(answers.password ?? '') });
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
// The password was accepted, and the account has a second factor: its code finishes the same sign-in.
|
|
80
|
+
if (!(error instanceof SecondFactorRequired))
|
|
81
|
+
throw error;
|
|
82
|
+
const { code } = await prompter.prompt(argv, [{ type: 'password', name: 'code', message: CODE_PROMPT[error.challenge.method] }]);
|
|
83
|
+
result = await signInWith({ challenge: error.challenge, code: String(code ?? '') });
|
|
84
|
+
}
|
|
85
|
+
const { session, context, previousKey } = result;
|
|
79
86
|
log(`signed in as ${session.email}`);
|
|
80
|
-
log(`backend: ${backend.apiEndpoint}`);
|
|
87
|
+
log(`backend: ${target.backend.apiEndpoint}`);
|
|
81
88
|
if (session.apiKey) {
|
|
82
89
|
log(`API key ${maskKey(session.apiKey)} (expires ${session.apiKeyExpiresAt ?? 'unknown'})`);
|
|
83
90
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
log(`session stored in context ${
|
|
91
|
+
const replaced = previousKeyWarning(previousKey);
|
|
92
|
+
if (replaced)
|
|
93
|
+
log(`warning: ${replaced}`);
|
|
94
|
+
log(`session stored in context ${context}`);
|
|
88
95
|
}
|
|
89
96
|
finally {
|
|
90
97
|
prompter.close();
|
|
91
98
|
}
|
|
92
99
|
}
|
|
100
|
+
function previousKeyWarning(previousKey) {
|
|
101
|
+
if (previousKey.kind !== 'failed')
|
|
102
|
+
return null;
|
|
103
|
+
return `the API key ${previousKey.keyId} of the replaced session could not be revoked (${previousKey.reason}); it stays valid until it expires.`;
|
|
104
|
+
}
|
|
93
105
|
export async function logout(config) {
|
|
94
|
-
const
|
|
95
|
-
if (
|
|
106
|
+
const result = await signOut({ store: config.store, session: resolveSession({ store: config.store }) });
|
|
107
|
+
if (result.kind === 'not-signed-in') {
|
|
96
108
|
log('not signed in.');
|
|
97
109
|
return;
|
|
98
110
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
111
|
+
if (result.kind === 'from-environment') {
|
|
112
|
+
log('nothing to sign out of: the session comes from the environment (CONSTRUCTIVE_USER_ID, CONSTRUCTIVE_ACCESS_TOKEN). Unset them to sign out.');
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
switch (result.key.kind) {
|
|
116
|
+
case 'revoked':
|
|
117
|
+
log('signed out — API key revoked and session cleared.');
|
|
118
|
+
break;
|
|
119
|
+
case 'absent':
|
|
120
|
+
log('signed out — session cleared (it had no API key).');
|
|
121
|
+
break;
|
|
122
|
+
case 'failed':
|
|
123
|
+
log(`signed out — session cleared, but the API key ${result.key.keyId} could not be revoked (${result.key.reason}); it stays valid until it expires.`);
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
107
126
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
127
|
+
/** The `agent` command that stores a complete backend context. */
|
|
128
|
+
export const REPAIR_HINT = 'Run `agent login` to store a complete backend.';
|
|
129
|
+
export async function whoami(config) {
|
|
130
|
+
const session = resolveSession({ store: config.store });
|
|
131
|
+
if (session.kind !== 'signed-in') {
|
|
132
|
+
log(sessionProblem(session, REPAIR_HINT) ?? 'not signed in — run `agent login`');
|
|
112
133
|
process.exitCode = 1;
|
|
113
134
|
return;
|
|
114
135
|
}
|
|
115
|
-
const backend =
|
|
116
|
-
log(`signed in as ${
|
|
117
|
-
log(`user id: ${
|
|
118
|
-
log(`backend: ${backend
|
|
119
|
-
if (
|
|
120
|
-
log(`API key: ${maskKey(
|
|
136
|
+
const { account, backend } = session;
|
|
137
|
+
log(`signed in as ${account.email ?? `user ${account.userId}`}${session.source === 'env' ? ' (from the environment)' : ''}`);
|
|
138
|
+
log(`user id: ${account.userId}`);
|
|
139
|
+
log(`backend: ${backend.apiEndpoint}`);
|
|
140
|
+
if (account.key.kind === 'active') {
|
|
141
|
+
log(`API key: ${maskKey(account.key.apiKey)} (expires ${account.key.expiresAt ?? 'unknown'})`);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
log('API key: none — commands use the access token until it ends. Run `agent login` for a 30-day key.');
|
|
145
|
+
}
|
|
146
|
+
if (account.key.kind === 'none' && account.accessTokenExpiresAt)
|
|
147
|
+
log(`access token expires: ${account.accessTokenExpiresAt}`);
|
|
148
|
+
log(`context: ${session.context ?? 'none'}`);
|
|
149
|
+
const check = await verifySession(session);
|
|
150
|
+
if (check.kind === 'accepted') {
|
|
151
|
+
log('credential: accepted by the backend');
|
|
152
|
+
}
|
|
153
|
+
else if (check.kind === 'rejected') {
|
|
154
|
+
log(`credential: rejected — ${check.reason} Run \`agent login\` to sign in again.`);
|
|
155
|
+
process.exitCode = 1;
|
|
121
156
|
}
|
|
122
157
|
else {
|
|
123
|
-
log(
|
|
158
|
+
log(`credential: not checked — ${check.reason}`);
|
|
124
159
|
}
|
|
125
|
-
if (session.accessTokenExpiresAt)
|
|
126
|
-
log(`access token expires: ${session.accessTokenExpiresAt}`);
|
|
127
|
-
log(`context: ${config.store.getCurrentContext()?.name ?? 'none'}`);
|
|
128
160
|
}
|
|
129
161
|
export function usage() {
|
|
130
162
|
console.log(`agent — the pi coding agent with the Constructive harness baked in
|
package/esm/config.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { FetchLike, HarnessDirs, SkillsManifest } from '@agentic-kit/harness';
|
|
2
|
-
import { ConfigStore } from '
|
|
2
|
+
import { ConfigStore } from '@agentic-kit/session';
|
|
3
3
|
export declare const DEFAULT_SKILLS_REPO = "constructive-io/constructive-skills";
|
|
4
|
-
/**
|
|
5
|
-
* Directory identity shared with the csdk CLI and the desktop app, so a sign-in
|
|
6
|
-
* here is a sign-in there. `agent` is only the tool's own name (env prefixes,
|
|
7
|
-
* help text).
|
|
8
|
-
*/
|
|
9
|
-
export declare const STASH_NAME = "constructive";
|
|
10
|
-
export declare const TOOL_NAME = "agent";
|
|
11
4
|
export declare const DEFAULT_SKILLS_PIN = "main";
|
|
12
5
|
/** Layer names understood by the assembler. */
|
|
13
6
|
export declare const BASE_LAYER = "constructive-skills";
|
|
@@ -38,6 +31,6 @@ interface ManifestFile {
|
|
|
38
31
|
manifest?: SkillsManifest;
|
|
39
32
|
}
|
|
40
33
|
export declare function defaultManifest(): SkillsManifest;
|
|
41
|
-
export declare function loadConfig(baseDir?: string): AgentCliConfig;
|
|
34
|
+
export declare function loadConfig(baseDir?: string | undefined): AgentCliConfig;
|
|
42
35
|
export declare function saveManifestFile(config: AgentCliConfig, file: ManifestFile): void;
|
|
43
36
|
export {};
|