@agentic-kit/cli 0.2.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/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Dan Lynch <pyramation@gmail.com>
4
+ Copyright (c) 2025 Constructive <developers@constructive.io>
5
+ Copyright (c) 2020-present, Interweb, Inc.
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,138 @@
1
+ # @agentic-kit/cli
2
+
3
+ <p align="center" width="100%">
4
+ <img height="250" src="https://raw.githubusercontent.com/constructive-io/constructive/refs/heads/main/assets/outline-logo.svg" />
5
+ </p>
6
+
7
+ `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.
8
+
9
+ ```bash
10
+ npm install -g @agentic-kit/cli
11
+ agent # interactive TUI session in the current project
12
+ agent -p "explain this repo" # one-shot print mode
13
+ ```
14
+
15
+ ## What it does
16
+
17
+ On startup, `agent` assembles the harness skill tree and drops you into an interactive terminal session:
18
+
19
+ 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).
20
+ 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.
21
+ 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.
22
+
23
+ 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.
24
+
25
+ ## Commands
26
+
27
+ | Command | Description |
28
+ |---------|-------------|
29
+ | `agent [options...]` | Start an interactive session with the harness skills |
30
+ | `agent -p "prompt"` | One-shot print mode |
31
+ | `agent init` | Configure the skills source (repo + pin) interactively |
32
+ | `agent skills list` | Resolve and list the effective skill set per layer |
33
+ | `agent skills update` | Re-fetch the base release and re-materialize |
34
+ | `agent help` | Usage |
35
+
36
+ ## Configuration
37
+
38
+ `~/.constructive/config/skills-manifest.json`:
39
+
40
+ ```json
41
+ {
42
+ "repo": "constructive-io/constructive-skills",
43
+ "pin": "^1.0.0",
44
+ "manifest": {
45
+ "sources": [
46
+ { "name": "constructive-skills" },
47
+ { "name": "local-overlay" }
48
+ ]
49
+ }
50
+ }
51
+ ```
52
+
53
+ Env overrides: `AGENT_SKILLS_REPO`, `AGENT_SKILLS_PIN`, `AGENT_HOME` (appstash base dir), `GITHUB_TOKEN` (private skills repos).
54
+
55
+ Db-tool credentials (read per tool call; without them the tools respond "not signed in"):
56
+ `CONSTRUCTIVE_USER_ID`, `CONSTRUCTIVE_ACCESS_TOKEN`, `CONSTRUCTIVE_API_KEY` (optional), `CONSTRUCTIVE_API_ENDPOINT`, `CONSTRUCTIVE_MODULES_ENDPOINT` (default to the local backend).
57
+
58
+ ## Roadmap
59
+
60
+ - `agent login` — sign in to a Constructive backend and persist credentials in appstash instead of env vars.
61
+ - Harness system-prompt section + templates/prompts materialization, shared with constructive-desktop via a common adapter package.
62
+
63
+ ## Credits
64
+
65
+ The interactive session is powered by the excellent [pi coding agent](https://github.com/badlogic/pi-mono) — thank you! `agent` layers the Constructive harness (skill releases, overlays, backend tooling) on top.
66
+
67
+ ---
68
+
69
+ ## Education and Tutorials
70
+
71
+ 1. 🚀 [Quickstart: Getting Up and Running](https://constructive.io/learn/quickstart)
72
+ Get started with modular databases in minutes. Install prerequisites and deploy your first module.
73
+
74
+ 2. 📦 [Modular PostgreSQL Development with Database Packages](https://constructive.io/learn/modular-postgres)
75
+ Learn to organize PostgreSQL projects with pgpm workspaces and reusable database modules.
76
+
77
+ 3. ✏️ [Authoring Database Changes](https://constructive.io/learn/authoring-database-changes)
78
+ Master the workflow for adding, organizing, and managing database changes with pgpm.
79
+
80
+ 4. 🧪 [End-to-End PostgreSQL Testing with TypeScript](https://constructive.io/learn/e2e-postgres-testing)
81
+ Master end-to-end PostgreSQL testing with ephemeral databases, RLS testing, and CI/CD automation.
82
+
83
+ 5. ⚡ [Supabase Testing](https://constructive.io/learn/supabase)
84
+ Use TypeScript-first tools to test Supabase projects with realistic RLS, policies, and auth contexts.
85
+
86
+ 6. 💧 [Drizzle ORM Testing](https://constructive.io/learn/drizzle-testing)
87
+ Run full-stack tests with Drizzle ORM, including database setup, teardown, and RLS enforcement.
88
+
89
+ 7. 🔧 [Troubleshooting](https://constructive.io/learn/troubleshooting)
90
+ Common issues and solutions for pgpm, PostgreSQL, and testing.
91
+
92
+ ## Related Constructive Tooling
93
+
94
+ ### 📦 Package Management
95
+
96
+ * [pgpm](https://github.com/constructive-io/constructive/tree/main/pgpm/pgpm): **🖥️ PostgreSQL Package Manager** for modular Postgres development. Works with database workspaces, scaffolding, migrations, seeding, and installing database packages.
97
+
98
+ ### 🧪 Testing
99
+
100
+ * [pgsql-test](https://github.com/constructive-io/constructive/tree/main/postgres/pgsql-test): **📊 Isolated testing environments** with per-test transaction rollbacks—ideal for integration tests, complex migrations, and RLS simulation.
101
+ * [pgsql-seed](https://github.com/constructive-io/constructive/tree/main/postgres/pgsql-seed): **🌱 PostgreSQL seeding utilities** for CSV, JSON, SQL data loading, and pgpm deployment.
102
+ * [supabase-test](https://github.com/constructive-io/constructive/tree/main/postgres/supabase-test): **🧪 Supabase-native test harness** preconfigured for the local Supabase stack—per-test rollbacks, JWT/role context helpers, and CI/GitHub Actions ready.
103
+ * [graphile-test](https://github.com/constructive-io/constructive/tree/main/graphile/graphile-test): **🔐 Authentication mocking** for Graphile-focused test helpers and emulating row-level security contexts.
104
+ * [pg-query-context](https://github.com/constructive-io/constructive/tree/main/postgres/pg-query-context): **🔒 Session context injection** to add session-local context (e.g., `SET LOCAL`) into queries—ideal for setting `role`, `jwt.claims`, and other session settings.
105
+
106
+ ### 🧠 Parsing & AST
107
+
108
+ * [pgsql-parser](https://www.npmjs.com/package/pgsql-parser): **🔄 SQL conversion engine** that interprets and converts PostgreSQL syntax.
109
+ * [libpg-query-node](https://www.npmjs.com/package/libpg-query): **🌉 Node.js bindings** for `libpg_query`, converting SQL into parse trees.
110
+ * [pg-proto-parser](https://www.npmjs.com/package/pg-proto-parser): **📦 Protobuf parser** for parsing PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
111
+ * [@pgsql/enums](https://www.npmjs.com/package/@pgsql/enums): **🏷️ TypeScript enums** for PostgreSQL AST for safe and ergonomic parsing logic.
112
+ * [@pgsql/types](https://www.npmjs.com/package/@pgsql/types): **📝 Type definitions** for PostgreSQL AST nodes in TypeScript.
113
+ * [@pgsql/utils](https://www.npmjs.com/package/@pgsql/utils): **🛠️ AST utilities** for constructing and transforming PostgreSQL syntax trees.
114
+
115
+ ### 📚 Documentation & Skills
116
+
117
+ * [constructive-skills](https://github.com/constructive-io/constructive-skills): **📖 Platform documentation and AI agent skills** — feature catalog, blueprint reference, SDK guides (i18n, billing, limits, events, uploads, security, entities, search, AI), and deployment guides.
118
+
119
+ Install skills for AI coding agents:
120
+
121
+ ```bash
122
+ # All platform skills (security, blueprints, codegen, billing, etc.)
123
+ npx skills add constructive-io/constructive-skills
124
+
125
+ # Individual repo skills (pgpm, testing, CLI, search, etc.)
126
+ npx skills add https://github.com/constructive-io/constructive --skill pgpm
127
+ npx skills add https://github.com/constructive-io/constructive --skill constructive-testing
128
+ ```
129
+
130
+ ## Credits
131
+
132
+ **🛠 Built by the [Constructive](https://constructive.io) team — creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on [GitHub](https://github.com/constructive-io).**
133
+
134
+ ## Disclaimer
135
+
136
+ AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
137
+
138
+ No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
package/commands.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { AgentCliConfig } from './config';
2
+ export declare function skillsList(config: AgentCliConfig): Promise<void>;
3
+ export declare function skillsUpdate(config: AgentCliConfig): Promise<void>;
4
+ export declare function init(config: AgentCliConfig, argv: Record<string, unknown>): Promise<void>;
5
+ export declare function usage(): void;
package/commands.js ADDED
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.skillsList = skillsList;
4
+ exports.skillsUpdate = skillsUpdate;
5
+ exports.init = init;
6
+ exports.usage = usage;
7
+ const inquirerer_1 = require("inquirerer");
8
+ const config_1 = require("./config");
9
+ const skills_1 = require("./skills");
10
+ const log = (msg) => console.log(`[agent] ${msg}`);
11
+ async function skillsList(config) {
12
+ const resolved = await (0, skills_1.assembleSkills)(config, log);
13
+ if (resolved.length === 0) {
14
+ console.log('No skills resolved.');
15
+ return;
16
+ }
17
+ for (const skill of resolved) {
18
+ console.log(`${skill.name} [${skill.sourceName}] ${skill.description}`);
19
+ }
20
+ }
21
+ async function skillsUpdate(config) {
22
+ await (0, skills_1.assembleSkills)(config, log);
23
+ }
24
+ async function init(config, argv) {
25
+ const prompter = new inquirerer_1.Inquirerer({ noTty: !process.stdin.isTTY });
26
+ const answers = await prompter.prompt(argv, [
27
+ {
28
+ type: 'text',
29
+ name: 'repo',
30
+ message: 'Skills repository (owner/repo)',
31
+ default: config.skillsRepo
32
+ },
33
+ {
34
+ type: 'text',
35
+ name: 'pin',
36
+ message: 'Skills pin (tag, semver range, SHA, or branch)',
37
+ default: config.skillsPin
38
+ }
39
+ ]);
40
+ (0, config_1.saveManifestFile)(config, {
41
+ repo: answers.repo,
42
+ pin: answers.pin,
43
+ manifest: (0, config_1.defaultManifest)()
44
+ });
45
+ log(`wrote ${config.manifestFile}`);
46
+ log(`local overlay dir (highest precedence): ${config.overlayDir}`);
47
+ }
48
+ function usage() {
49
+ console.log(`agent — the pi coding agent with the Constructive harness baked in
50
+
51
+ Usage:
52
+ agent [pi options...] start an interactive session (pi TUI)
53
+ agent -p "prompt" one-shot print mode (pi)
54
+ agent init configure the skills source (repo + pin)
55
+ agent skills list resolve + list the effective skill set
56
+ agent skills update re-fetch the base release and re-materialize
57
+ agent help show this help
58
+
59
+ Skills layering (later wins by skill name, wholesale):
60
+ 1. ${'constructive-skills'} release (git tag/branch/SHA pin, offline fallback)
61
+ 2. local overlay: <config>/skills-overlay/<skill-name>/SKILL.md
62
+ `);
63
+ }
package/config.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ import { HarnessDirs, SkillsManifest } from '@agentic-kit/harness';
2
+ export declare const DEFAULT_SKILLS_REPO = "constructive-io/constructive-skills";
3
+ export declare const DEFAULT_SKILLS_PIN = "main";
4
+ /** Layer names understood by the assembler. */
5
+ export declare const BASE_LAYER = "constructive-skills";
6
+ export declare const OVERLAY_LAYER = "local-overlay";
7
+ export interface AgentCliConfig {
8
+ dirs: HarnessDirs;
9
+ /** pi's agent dir (PI_CODING_AGENT_DIR): `<data>/agent`. */
10
+ agentDir: string;
11
+ /** Highest-precedence local skills: `<config>/skills-overlay/`. */
12
+ overlayDir: string;
13
+ /** Path of the user-editable manifest: `<config>/skills-manifest.json`. */
14
+ manifestFile: string;
15
+ manifest: SkillsManifest;
16
+ skillsRepo: string;
17
+ skillsPin: string;
18
+ }
19
+ interface ManifestFile {
20
+ repo?: string;
21
+ pin?: string;
22
+ manifest?: SkillsManifest;
23
+ }
24
+ export declare function defaultManifest(): SkillsManifest;
25
+ export declare function loadConfig(baseDir?: string): AgentCliConfig;
26
+ export declare function saveManifestFile(config: AgentCliConfig, file: ManifestFile): void;
27
+ export {};
package/config.js ADDED
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.OVERLAY_LAYER = exports.BASE_LAYER = exports.DEFAULT_SKILLS_PIN = exports.DEFAULT_SKILLS_REPO = void 0;
37
+ exports.defaultManifest = defaultManifest;
38
+ exports.loadConfig = loadConfig;
39
+ exports.saveManifestFile = saveManifestFile;
40
+ const fs = __importStar(require("fs"));
41
+ const path = __importStar(require("path"));
42
+ const harness_1 = require("@agentic-kit/harness");
43
+ exports.DEFAULT_SKILLS_REPO = 'constructive-io/constructive-skills';
44
+ exports.DEFAULT_SKILLS_PIN = 'main';
45
+ /** Layer names understood by the assembler. */
46
+ exports.BASE_LAYER = 'constructive-skills';
47
+ exports.OVERLAY_LAYER = 'local-overlay';
48
+ function defaultManifest() {
49
+ return {
50
+ sources: [{ name: exports.BASE_LAYER }, { name: exports.OVERLAY_LAYER }]
51
+ };
52
+ }
53
+ function loadConfig(baseDir) {
54
+ const dirs = (0, harness_1.harnessDirs)('constructive', baseDir);
55
+ const agentDir = path.join(dirs.stash.data, 'agent');
56
+ const overlayDir = path.join(dirs.stash.config, 'skills-overlay');
57
+ const manifestFile = path.join(dirs.stash.config, 'skills-manifest.json');
58
+ fs.mkdirSync(agentDir, { recursive: true });
59
+ fs.mkdirSync(overlayDir, { recursive: true });
60
+ let file = {};
61
+ if (fs.existsSync(manifestFile)) {
62
+ file = JSON.parse(fs.readFileSync(manifestFile, 'utf8'));
63
+ }
64
+ return {
65
+ dirs,
66
+ agentDir,
67
+ overlayDir,
68
+ manifestFile,
69
+ manifest: file.manifest ?? defaultManifest(),
70
+ skillsRepo: process.env.AGENT_SKILLS_REPO ?? file.repo ?? exports.DEFAULT_SKILLS_REPO,
71
+ skillsPin: process.env.AGENT_SKILLS_PIN ?? file.pin ?? exports.DEFAULT_SKILLS_PIN
72
+ };
73
+ }
74
+ function saveManifestFile(config, file) {
75
+ fs.mkdirSync(path.dirname(config.manifestFile), { recursive: true });
76
+ fs.writeFileSync(config.manifestFile, JSON.stringify(file, null, 2) + '\n');
77
+ }
package/db-tools.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { AgentCliConfig } from './config';
2
+ /**
3
+ * Environment variables the generated extension reads at tool-call time.
4
+ * Without CONSTRUCTIVE_ACCESS_TOKEN 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"];
7
+ /**
8
+ * Write the db-tools extension entry into pi's agent dir. Returns the file
9
+ * path, or null when @agentic-kit/pi is not installed alongside the CLI.
10
+ */
11
+ export declare function materializeDbTools(config: AgentCliConfig, log: (msg: string) => void): string | null;
package/db-tools.js ADDED
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.HOST_ENV_VARS = void 0;
37
+ exports.materializeDbTools = materializeDbTools;
38
+ const fs = __importStar(require("fs"));
39
+ const path = __importStar(require("path"));
40
+ const EXTENSION_FILE = 'constructive-db-tools.js';
41
+ /**
42
+ * Environment variables the generated extension reads at tool-call time.
43
+ * Without CONSTRUCTIVE_ACCESS_TOKEN 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
+ ];
52
+ // pi's TUI loads extensions from files under <agentDir>/extensions (via jiti),
53
+ // not from factories, so the db tools are wired by materializing a small
54
+ // generated entry there. The @agentic-kit/pi entry path is resolved from THIS
55
+ // package at assembly time and baked in, because node resolution from the
56
+ // appstash agent dir would not find it.
57
+ function extensionSource(pkgEntry) {
58
+ return `// Generated by @agentic-kit/cli — do not edit (rewritten on every \`agent\` run).
59
+ // Registers the Constructive typed db tools + confirm gate (@agentic-kit/pi)
60
+ // with credentials read from the environment on each call.
61
+ const { createDbTools } = require(${JSON.stringify(pkgEntry)});
62
+
63
+ module.exports = createDbTools({
64
+ account: () => {
65
+ const userId = process.env.CONSTRUCTIVE_USER_ID;
66
+ const accessToken = process.env.CONSTRUCTIVE_ACCESS_TOKEN;
67
+ if (!userId || !accessToken) return null;
68
+ return { userId, accessToken, apiKey: process.env.CONSTRUCTIVE_API_KEY };
69
+ },
70
+ backendConfig: () => ({
71
+ apiEndpoint: process.env.CONSTRUCTIVE_API_ENDPOINT,
72
+ modulesEndpoint: process.env.CONSTRUCTIVE_MODULES_ENDPOINT
73
+ })
74
+ });
75
+ `;
76
+ }
77
+ /**
78
+ * Write the db-tools extension entry into pi's agent dir. Returns the file
79
+ * path, or null when @agentic-kit/pi is not installed alongside the CLI.
80
+ */
81
+ function materializeDbTools(config, log) {
82
+ let pkgEntry;
83
+ try {
84
+ pkgEntry = require.resolve('@agentic-kit/pi');
85
+ }
86
+ catch {
87
+ log('db tools unavailable (@agentic-kit/pi not installed) — continuing without them');
88
+ return null;
89
+ }
90
+ const dir = path.join(config.agentDir, 'extensions');
91
+ fs.mkdirSync(dir, { recursive: true });
92
+ const file = path.join(dir, EXTENSION_FILE);
93
+ fs.writeFileSync(file, extensionSource(pkgEntry));
94
+ return file;
95
+ }
@@ -0,0 +1,5 @@
1
+ import { AgentCliConfig } from './config';
2
+ export declare function skillsList(config: AgentCliConfig): Promise<void>;
3
+ export declare function skillsUpdate(config: AgentCliConfig): Promise<void>;
4
+ export declare function init(config: AgentCliConfig, argv: Record<string, unknown>): Promise<void>;
5
+ export declare function usage(): void;
@@ -0,0 +1,57 @@
1
+ import { Inquirerer } from 'inquirerer';
2
+ import { defaultManifest, saveManifestFile } from './config';
3
+ import { assembleSkills } from './skills';
4
+ const log = (msg) => console.log(`[agent] ${msg}`);
5
+ export async function skillsList(config) {
6
+ const resolved = await assembleSkills(config, log);
7
+ if (resolved.length === 0) {
8
+ console.log('No skills resolved.');
9
+ return;
10
+ }
11
+ for (const skill of resolved) {
12
+ console.log(`${skill.name} [${skill.sourceName}] ${skill.description}`);
13
+ }
14
+ }
15
+ export async function skillsUpdate(config) {
16
+ await assembleSkills(config, log);
17
+ }
18
+ export async function init(config, argv) {
19
+ const prompter = new Inquirerer({ noTty: !process.stdin.isTTY });
20
+ const answers = await prompter.prompt(argv, [
21
+ {
22
+ type: 'text',
23
+ name: 'repo',
24
+ message: 'Skills repository (owner/repo)',
25
+ default: config.skillsRepo
26
+ },
27
+ {
28
+ type: 'text',
29
+ name: 'pin',
30
+ message: 'Skills pin (tag, semver range, SHA, or branch)',
31
+ default: config.skillsPin
32
+ }
33
+ ]);
34
+ saveManifestFile(config, {
35
+ repo: answers.repo,
36
+ pin: answers.pin,
37
+ manifest: defaultManifest()
38
+ });
39
+ log(`wrote ${config.manifestFile}`);
40
+ log(`local overlay dir (highest precedence): ${config.overlayDir}`);
41
+ }
42
+ export function usage() {
43
+ console.log(`agent — the pi coding agent with the Constructive harness baked in
44
+
45
+ Usage:
46
+ agent [pi options...] start an interactive session (pi TUI)
47
+ agent -p "prompt" one-shot print mode (pi)
48
+ agent init configure the skills source (repo + pin)
49
+ agent skills list resolve + list the effective skill set
50
+ agent skills update re-fetch the base release and re-materialize
51
+ agent help show this help
52
+
53
+ Skills layering (later wins by skill name, wholesale):
54
+ 1. ${'constructive-skills'} release (git tag/branch/SHA pin, offline fallback)
55
+ 2. local overlay: <config>/skills-overlay/<skill-name>/SKILL.md
56
+ `);
57
+ }
@@ -0,0 +1,27 @@
1
+ import { HarnessDirs, SkillsManifest } from '@agentic-kit/harness';
2
+ export declare const DEFAULT_SKILLS_REPO = "constructive-io/constructive-skills";
3
+ export declare const DEFAULT_SKILLS_PIN = "main";
4
+ /** Layer names understood by the assembler. */
5
+ export declare const BASE_LAYER = "constructive-skills";
6
+ export declare const OVERLAY_LAYER = "local-overlay";
7
+ export interface AgentCliConfig {
8
+ dirs: HarnessDirs;
9
+ /** pi's agent dir (PI_CODING_AGENT_DIR): `<data>/agent`. */
10
+ agentDir: string;
11
+ /** Highest-precedence local skills: `<config>/skills-overlay/`. */
12
+ overlayDir: string;
13
+ /** Path of the user-editable manifest: `<config>/skills-manifest.json`. */
14
+ manifestFile: string;
15
+ manifest: SkillsManifest;
16
+ skillsRepo: string;
17
+ skillsPin: string;
18
+ }
19
+ interface ManifestFile {
20
+ repo?: string;
21
+ pin?: string;
22
+ manifest?: SkillsManifest;
23
+ }
24
+ export declare function defaultManifest(): SkillsManifest;
25
+ export declare function loadConfig(baseDir?: string): AgentCliConfig;
26
+ export declare function saveManifestFile(config: AgentCliConfig, file: ManifestFile): void;
27
+ export {};
package/esm/config.js ADDED
@@ -0,0 +1,38 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import { harnessDirs } from '@agentic-kit/harness';
4
+ export const DEFAULT_SKILLS_REPO = 'constructive-io/constructive-skills';
5
+ export const DEFAULT_SKILLS_PIN = 'main';
6
+ /** Layer names understood by the assembler. */
7
+ export const BASE_LAYER = 'constructive-skills';
8
+ export const OVERLAY_LAYER = 'local-overlay';
9
+ export function defaultManifest() {
10
+ return {
11
+ sources: [{ name: BASE_LAYER }, { name: OVERLAY_LAYER }]
12
+ };
13
+ }
14
+ export function loadConfig(baseDir) {
15
+ const dirs = harnessDirs('constructive', baseDir);
16
+ const agentDir = path.join(dirs.stash.data, 'agent');
17
+ const overlayDir = path.join(dirs.stash.config, 'skills-overlay');
18
+ const manifestFile = path.join(dirs.stash.config, 'skills-manifest.json');
19
+ fs.mkdirSync(agentDir, { recursive: true });
20
+ fs.mkdirSync(overlayDir, { recursive: true });
21
+ let file = {};
22
+ if (fs.existsSync(manifestFile)) {
23
+ file = JSON.parse(fs.readFileSync(manifestFile, 'utf8'));
24
+ }
25
+ return {
26
+ dirs,
27
+ agentDir,
28
+ overlayDir,
29
+ manifestFile,
30
+ manifest: file.manifest ?? defaultManifest(),
31
+ skillsRepo: process.env.AGENT_SKILLS_REPO ?? file.repo ?? DEFAULT_SKILLS_REPO,
32
+ skillsPin: process.env.AGENT_SKILLS_PIN ?? file.pin ?? DEFAULT_SKILLS_PIN
33
+ };
34
+ }
35
+ export function saveManifestFile(config, file) {
36
+ fs.mkdirSync(path.dirname(config.manifestFile), { recursive: true });
37
+ fs.writeFileSync(config.manifestFile, JSON.stringify(file, null, 2) + '\n');
38
+ }
@@ -0,0 +1,11 @@
1
+ import { AgentCliConfig } from './config';
2
+ /**
3
+ * Environment variables the generated extension reads at tool-call time.
4
+ * Without CONSTRUCTIVE_ACCESS_TOKEN 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"];
7
+ /**
8
+ * Write the db-tools extension entry into pi's agent dir. Returns the file
9
+ * path, or null when @agentic-kit/pi is not installed alongside the CLI.
10
+ */
11
+ export declare function materializeDbTools(config: AgentCliConfig, log: (msg: string) => void): string | null;
@@ -0,0 +1,58 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ const EXTENSION_FILE = 'constructive-db-tools.js';
4
+ /**
5
+ * Environment variables the generated extension reads at tool-call time.
6
+ * Without CONSTRUCTIVE_ACCESS_TOKEN the tools load but report "not signed in".
7
+ */
8
+ export const HOST_ENV_VARS = [
9
+ 'CONSTRUCTIVE_USER_ID',
10
+ 'CONSTRUCTIVE_ACCESS_TOKEN',
11
+ 'CONSTRUCTIVE_API_KEY',
12
+ 'CONSTRUCTIVE_API_ENDPOINT',
13
+ 'CONSTRUCTIVE_MODULES_ENDPOINT'
14
+ ];
15
+ // pi's TUI loads extensions from files under <agentDir>/extensions (via jiti),
16
+ // not from factories, so the db tools are wired by materializing a small
17
+ // generated entry there. The @agentic-kit/pi entry path is resolved from THIS
18
+ // package at assembly time and baked in, because node resolution from the
19
+ // appstash agent dir would not find it.
20
+ function extensionSource(pkgEntry) {
21
+ return `// Generated by @agentic-kit/cli — do not edit (rewritten on every \`agent\` run).
22
+ // Registers the Constructive typed db tools + confirm gate (@agentic-kit/pi)
23
+ // with credentials read from the environment on each call.
24
+ const { createDbTools } = require(${JSON.stringify(pkgEntry)});
25
+
26
+ module.exports = createDbTools({
27
+ account: () => {
28
+ const userId = process.env.CONSTRUCTIVE_USER_ID;
29
+ const accessToken = process.env.CONSTRUCTIVE_ACCESS_TOKEN;
30
+ if (!userId || !accessToken) return null;
31
+ return { userId, accessToken, apiKey: process.env.CONSTRUCTIVE_API_KEY };
32
+ },
33
+ backendConfig: () => ({
34
+ apiEndpoint: process.env.CONSTRUCTIVE_API_ENDPOINT,
35
+ modulesEndpoint: process.env.CONSTRUCTIVE_MODULES_ENDPOINT
36
+ })
37
+ });
38
+ `;
39
+ }
40
+ /**
41
+ * Write the db-tools extension entry into pi's agent dir. Returns the file
42
+ * path, or null when @agentic-kit/pi is not installed alongside the CLI.
43
+ */
44
+ export function materializeDbTools(config, log) {
45
+ let pkgEntry;
46
+ try {
47
+ pkgEntry = require.resolve('@agentic-kit/pi');
48
+ }
49
+ catch {
50
+ log('db tools unavailable (@agentic-kit/pi not installed) — continuing without them');
51
+ return null;
52
+ }
53
+ const dir = path.join(config.agentDir, 'extensions');
54
+ fs.mkdirSync(dir, { recursive: true });
55
+ const file = path.join(dir, EXTENSION_FILE);
56
+ fs.writeFileSync(file, extensionSource(pkgEntry));
57
+ return file;
58
+ }
package/esm/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ export { assembleSkills } from './skills';
3
+ export { AgentCliConfig, loadConfig } from './config';
4
+ export { HOST_ENV_VARS, materializeDbTools } from './db-tools';
package/esm/index.js ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env node
2
+ import { loadConfig } from './config';
3
+ import { init, skillsList, skillsUpdate, usage } from './commands';
4
+ import { materializeDbTools } from './db-tools';
5
+ import { assembleSkills } from './skills';
6
+ export { assembleSkills } from './skills';
7
+ export { loadConfig } from './config';
8
+ export { HOST_ENV_VARS, materializeDbTools } from './db-tools';
9
+ async function run(args) {
10
+ const config = loadConfig(process.env.AGENT_HOME);
11
+ // pi resolves its agent dir (skills, sessions, auth) from this env var;
12
+ // point it at the appstash-owned dir before the SDK loads.
13
+ process.env.PI_CODING_AGENT_DIR ??= config.agentDir;
14
+ const [first, second] = args;
15
+ if (first === 'help' || first === '--help-agent') {
16
+ usage();
17
+ return;
18
+ }
19
+ if (first === 'init') {
20
+ await init(config, {});
21
+ return;
22
+ }
23
+ if (first === 'skills') {
24
+ if (second === 'update')
25
+ await skillsUpdate(config);
26
+ else
27
+ await skillsList(config);
28
+ return;
29
+ }
30
+ const log = (msg) => console.log(`[agent] ${msg}`);
31
+ await assembleSkills(config, log);
32
+ materializeDbTools(config, log);
33
+ // pi is ESM-only; tsc's CJS output would downlevel a plain `await import()`
34
+ // into `require()`, which cannot load it. Indirect the import so it survives
35
+ // transpilation in the CJS build.
36
+ const dynamicImport = new Function('specifier', 'return import(specifier)');
37
+ const { main } = await dynamicImport('@earendil-works/pi-coding-agent');
38
+ await main(args);
39
+ }
40
+ if (require.main === module) {
41
+ run(process.argv.slice(2)).catch((error) => {
42
+ console.error(error instanceof Error ? error.message : error);
43
+ process.exit(1);
44
+ });
45
+ }
@@ -0,0 +1,8 @@
1
+ import { HarnessSkill } from '@agentic-kit/harness';
2
+ import { AgentCliConfig } from './config';
3
+ /**
4
+ * Assemble the effective skill tree (fetched base + local overlay, later
5
+ * layer wins wholesale by skill name) into pi's agent dir so the session
6
+ * picks it up as regular skills.
7
+ */
8
+ export declare function assembleSkills(config: AgentCliConfig, log?: (msg: string) => void): Promise<HarnessSkill[]>;
package/esm/skills.js ADDED
@@ -0,0 +1,59 @@
1
+ import * as path from 'path';
2
+ import { DirectorySkillSource, fetchSkillsFromGit, latestLocalRelease, materializeSkills, resolveSkills } from '@agentic-kit/harness';
3
+ import { BASE_LAYER, OVERLAY_LAYER } from './config';
4
+ /** An empty layer so a missing/unavailable source never breaks assembly. */
5
+ class EmptySkillSource {
6
+ name;
7
+ constructor(name) {
8
+ this.name = name;
9
+ }
10
+ async load() {
11
+ return [];
12
+ }
13
+ }
14
+ async function baseSource(config, log) {
15
+ try {
16
+ const release = await fetchSkillsFromGit({
17
+ repo: config.skillsRepo,
18
+ pin: config.skillsPin,
19
+ skillsRoot: config.dirs.skillsRoot,
20
+ token: process.env.GITHUB_TOKEN
21
+ });
22
+ log(`skills base: ${config.skillsRepo}@${release.version}${release.fromCache ? ' (cached)' : ''}`);
23
+ return new DirectorySkillSource(BASE_LAYER, release.skillsDir);
24
+ }
25
+ catch (error) {
26
+ const local = latestLocalRelease(config.dirs.skillsRoot);
27
+ if (local) {
28
+ log(`skills base: offline fallback to local release ${local.version} (${error.message})`);
29
+ return new DirectorySkillSource(BASE_LAYER, local.skillsDir);
30
+ }
31
+ log(`skills base: unavailable, continuing without it (${error.message})`);
32
+ return new EmptySkillSource(BASE_LAYER);
33
+ }
34
+ }
35
+ /**
36
+ * Assemble the effective skill tree (fetched base + local overlay, later
37
+ * layer wins wholesale by skill name) into pi's agent dir so the session
38
+ * picks it up as regular skills.
39
+ */
40
+ export async function assembleSkills(config, log = () => undefined) {
41
+ const sources = [];
42
+ for (const ref of config.manifest.sources) {
43
+ if (ref.name === BASE_LAYER) {
44
+ sources.push(await baseSource(config, log));
45
+ }
46
+ else if (ref.name === OVERLAY_LAYER) {
47
+ sources.push(new DirectorySkillSource(OVERLAY_LAYER, config.overlayDir));
48
+ }
49
+ else {
50
+ throw new Error(`Unknown manifest source: ${ref.name}`);
51
+ }
52
+ }
53
+ const resolved = await resolveSkills(config.manifest, sources, {
54
+ onMissingRequire: (skill, required) => log(`skill ${skill} requires missing skill ${required}`)
55
+ });
56
+ materializeSkills(path.join(config.agentDir, 'skills'), resolved);
57
+ log(`skills materialized: ${resolved.map((s) => s.name).join(', ') || '(none)'}`);
58
+ return resolved;
59
+ }
package/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ export { assembleSkills } from './skills';
3
+ export { AgentCliConfig, loadConfig } from './config';
4
+ export { HOST_ENV_VARS, materializeDbTools } from './db-tools';
package/index.js ADDED
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.materializeDbTools = exports.HOST_ENV_VARS = exports.loadConfig = exports.assembleSkills = void 0;
5
+ const config_1 = require("./config");
6
+ const commands_1 = require("./commands");
7
+ const db_tools_1 = require("./db-tools");
8
+ const skills_1 = require("./skills");
9
+ var skills_2 = require("./skills");
10
+ Object.defineProperty(exports, "assembleSkills", { enumerable: true, get: function () { return skills_2.assembleSkills; } });
11
+ var config_2 = require("./config");
12
+ Object.defineProperty(exports, "loadConfig", { enumerable: true, get: function () { return config_2.loadConfig; } });
13
+ var db_tools_2 = require("./db-tools");
14
+ Object.defineProperty(exports, "HOST_ENV_VARS", { enumerable: true, get: function () { return db_tools_2.HOST_ENV_VARS; } });
15
+ Object.defineProperty(exports, "materializeDbTools", { enumerable: true, get: function () { return db_tools_2.materializeDbTools; } });
16
+ async function run(args) {
17
+ const config = (0, config_1.loadConfig)(process.env.AGENT_HOME);
18
+ // pi resolves its agent dir (skills, sessions, auth) from this env var;
19
+ // point it at the appstash-owned dir before the SDK loads.
20
+ process.env.PI_CODING_AGENT_DIR ??= config.agentDir;
21
+ const [first, second] = args;
22
+ if (first === 'help' || first === '--help-agent') {
23
+ (0, commands_1.usage)();
24
+ return;
25
+ }
26
+ if (first === 'init') {
27
+ await (0, commands_1.init)(config, {});
28
+ return;
29
+ }
30
+ if (first === 'skills') {
31
+ if (second === 'update')
32
+ await (0, commands_1.skillsUpdate)(config);
33
+ else
34
+ await (0, commands_1.skillsList)(config);
35
+ return;
36
+ }
37
+ const log = (msg) => console.log(`[agent] ${msg}`);
38
+ await (0, skills_1.assembleSkills)(config, log);
39
+ (0, db_tools_1.materializeDbTools)(config, log);
40
+ // pi is ESM-only; tsc's CJS output would downlevel a plain `await import()`
41
+ // into `require()`, which cannot load it. Indirect the import so it survives
42
+ // transpilation in the CJS build.
43
+ const dynamicImport = new Function('specifier', 'return import(specifier)');
44
+ const { main } = await dynamicImport('@earendil-works/pi-coding-agent');
45
+ await main(args);
46
+ }
47
+ if (require.main === module) {
48
+ run(process.argv.slice(2)).catch((error) => {
49
+ console.error(error instanceof Error ? error.message : error);
50
+ process.exit(1);
51
+ });
52
+ }
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@agentic-kit/cli",
3
+ "version": "0.2.0",
4
+ "author": "Dan Lynch <pyramation@gmail.com>",
5
+ "description": "agent — the pi coding agent with the Constructive harness baked in, purely a shell",
6
+ "main": "index.js",
7
+ "module": "esm/index.js",
8
+ "types": "index.d.ts",
9
+ "bin": {
10
+ "agent": "index.js"
11
+ },
12
+ "homepage": "https://github.com/constructive-io/constructive",
13
+ "license": "SEE LICENSE IN LICENSE",
14
+ "publishConfig": {
15
+ "access": "public",
16
+ "directory": "dist"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/constructive-io/constructive"
21
+ },
22
+ "bugs": {
23
+ "url": "https://github.com/constructive-io/constructive/issues"
24
+ },
25
+ "scripts": {
26
+ "clean": "makage clean",
27
+ "prepack": "npm run build",
28
+ "build": "makage build",
29
+ "build:dev": "makage build --dev",
30
+ "lint": "eslint . --fix",
31
+ "test": "jest",
32
+ "test:watch": "jest --watch"
33
+ },
34
+ "dependencies": {
35
+ "@agentic-kit/harness": "0.3.0",
36
+ "@agentic-kit/pi": "0.2.0",
37
+ "@earendil-works/pi-coding-agent": "0.79.6",
38
+ "inquirerer": "^4.9.1"
39
+ },
40
+ "keywords": [
41
+ "agentic-kit",
42
+ "coding-agent",
43
+ "pi",
44
+ "harness"
45
+ ],
46
+ "gitHead": "31f7cd3d3cc28cf069056eae5b2a0d4198d154a1"
47
+ }
package/skills.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { HarnessSkill } from '@agentic-kit/harness';
2
+ import { AgentCliConfig } from './config';
3
+ /**
4
+ * Assemble the effective skill tree (fetched base + local overlay, later
5
+ * layer wins wholesale by skill name) into pi's agent dir so the session
6
+ * picks it up as regular skills.
7
+ */
8
+ export declare function assembleSkills(config: AgentCliConfig, log?: (msg: string) => void): Promise<HarnessSkill[]>;
package/skills.js ADDED
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.assembleSkills = assembleSkills;
37
+ const path = __importStar(require("path"));
38
+ const harness_1 = require("@agentic-kit/harness");
39
+ const config_1 = require("./config");
40
+ /** An empty layer so a missing/unavailable source never breaks assembly. */
41
+ class EmptySkillSource {
42
+ name;
43
+ constructor(name) {
44
+ this.name = name;
45
+ }
46
+ async load() {
47
+ return [];
48
+ }
49
+ }
50
+ async function baseSource(config, log) {
51
+ try {
52
+ const release = await (0, harness_1.fetchSkillsFromGit)({
53
+ repo: config.skillsRepo,
54
+ pin: config.skillsPin,
55
+ skillsRoot: config.dirs.skillsRoot,
56
+ token: process.env.GITHUB_TOKEN
57
+ });
58
+ log(`skills base: ${config.skillsRepo}@${release.version}${release.fromCache ? ' (cached)' : ''}`);
59
+ return new harness_1.DirectorySkillSource(config_1.BASE_LAYER, release.skillsDir);
60
+ }
61
+ catch (error) {
62
+ const local = (0, harness_1.latestLocalRelease)(config.dirs.skillsRoot);
63
+ if (local) {
64
+ log(`skills base: offline fallback to local release ${local.version} (${error.message})`);
65
+ return new harness_1.DirectorySkillSource(config_1.BASE_LAYER, local.skillsDir);
66
+ }
67
+ log(`skills base: unavailable, continuing without it (${error.message})`);
68
+ return new EmptySkillSource(config_1.BASE_LAYER);
69
+ }
70
+ }
71
+ /**
72
+ * Assemble the effective skill tree (fetched base + local overlay, later
73
+ * layer wins wholesale by skill name) into pi's agent dir so the session
74
+ * picks it up as regular skills.
75
+ */
76
+ async function assembleSkills(config, log = () => undefined) {
77
+ const sources = [];
78
+ for (const ref of config.manifest.sources) {
79
+ if (ref.name === config_1.BASE_LAYER) {
80
+ sources.push(await baseSource(config, log));
81
+ }
82
+ else if (ref.name === config_1.OVERLAY_LAYER) {
83
+ sources.push(new harness_1.DirectorySkillSource(config_1.OVERLAY_LAYER, config.overlayDir));
84
+ }
85
+ else {
86
+ throw new Error(`Unknown manifest source: ${ref.name}`);
87
+ }
88
+ }
89
+ const resolved = await (0, harness_1.resolveSkills)(config.manifest, sources, {
90
+ onMissingRequire: (skill, required) => log(`skill ${skill} requires missing skill ${required}`)
91
+ });
92
+ (0, harness_1.materializeSkills)(path.join(config.agentDir, 'skills'), resolved);
93
+ log(`skills materialized: ${resolved.map((s) => s.name).join(', ') || '(none)'}`);
94
+ return resolved;
95
+ }