Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions LOCAL_DEV_SETUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Local Development Setup

This guide explains how to set up the agentcore-cli for local development when the L3 constructs package is not yet published to npm.

## Prerequisites

- Node.js >= 20
- npm
- Both packages cloned as siblings:
```
workspace/
├── agentcore-cli/
└── agentcore-l3-cdk-constructs/
```

## Setup Steps

### 1. Install and Build the L3 Constructs Package

```bash
cd agentcore-l3-cdk-constructs
npm install
npm run build
```

### 2. Create Global npm Link

```bash
npm link
```

This creates a global symlink that makes `@aws/agentcore-l3-cdk-constructs` available to other local projects.

### 3. Build the CLI

```bash
cd ../agentcore-cli
npm install
npm run build
```

### 4. Create a Test Project

```bash
npm run cli create
```

Follow the prompts to create a new project.

### 5. Link the L3 Constructs in the Generated Project

The generated CDK project includes a postinstall script that automatically attempts to link `@aws/agentcore-l3-cdk-constructs`. However, if npm install was run before you created the global link, you may need to manually link it:

```bash
cd <your-project>/agentcore/cdk
npm link @aws/agentcore-l3-cdk-constructs
```

Alternatively, you can re-run npm install to trigger the postinstall script:

```bash
npm install
```

### 6. Build and Test

```bash
npm run build
```

## How npm link Works

1. `npm link` in the L3 package creates a global symlink
2. `npm link @aws/agentcore-l3-cdk-constructs` in the CDK project creates a local symlink to the global one
3. Changes to the L3 package are immediately reflected (after rebuilding)

## Troubleshooting

### "Cannot find module" errors

Make sure you've built the L3 constructs package:
```bash
cd agentcore-l3-cdk-constructs
npm run build
```

### Link not working

Re-create the links:
```bash
# In L3 constructs
npm unlink
npm link

# In generated CDK project
npm unlink @aws/agentcore-l3-cdk-constructs
npm link @aws/agentcore-l3-cdk-constructs
```

### Changes not reflected

Rebuild the L3 constructs package:
```bash
cd agentcore-l3-cdk-constructs
npm run build
```

## Alternative: Using LOCAL_L3_PATH

If you prefer, you can set the `LOCAL_L3_PATH` environment variable before running create:

```bash
# Windows PowerShell
$env:LOCAL_L3_PATH = "C:\path\to\agentcore-l3-cdk-constructs"
npm run cli create

# Windows CMD
set LOCAL_L3_PATH=C:\path\to\agentcore-l3-cdk-constructs
npm run cli create
```

This will automatically use `file:` protocol in package.json instead of requiring npm link.
42 changes: 23 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"build": "npm run build:lib && npm run build:cli && npm run build:assets",
"build:lib": "tsc -p tsconfig.build.json",
"build:cli": "node esbuild.config.mjs",
"build:assets": "rsync -a --exclude='/AGENTS.md' src/assets/ dist/assets/",
"build:assets": "node scripts/copy-assets.mjs",
"cli": "npx tsx src/cli/index.ts",
"typecheck": "tsc --noEmit",
"lint": "eslint src/",
Expand All @@ -29,7 +29,7 @@
"format:check": "prettier --check .",
"secrets:check": "secretlint '**/*'",
"security:audit": "npm audit --audit-level=high",
"clean": "rm -rf dist",
"clean": "node -e \"require('fs').rmSync('dist', {recursive: true, force: true})\"",
"prepare": "husky",
"test": "vitest run",
"test:watch": "vitest",
Expand Down
50 changes: 50 additions & 0 deletions scripts/copy-assets.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import * as fs from 'fs';
import * as path from 'path';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const srcDir = path.join(__dirname, '..', 'src', 'assets');
const destDir = path.join(__dirname, '..', 'dist', 'assets');

/**
* Recursively copy directory contents, excluding specified files at root level only
* @param {string} src - Source directory
* @param {string} dest - Destination directory
* @param {string[]} excludeAtRoot - Files to exclude only at the root level (e.g., 'AGENTS.md')
* @param {boolean} isRoot - Whether this is the root level call
*/
function copyDir(src, dest, excludeAtRoot = [], isRoot = true) {
// Create destination directory if it doesn't exist
if (!fs.existsSync(dest)) {
fs.mkdirSync(dest, { recursive: true });
}

const entries = fs.readdirSync(src, { withFileTypes: true });

for (const entry of entries) {
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);

// Skip excluded files only at root level
if (isRoot && excludeAtRoot.includes(entry.name)) {
continue;
}

if (entry.isDirectory()) {
copyDir(srcPath, destPath, excludeAtRoot, false);
} else {
fs.copyFileSync(srcPath, destPath);
}
}
}

try {
console.log('Copying assets...');
copyDir(srcDir, destDir, ['AGENTS.md']);
console.log('Assets copied successfully!');
} catch (error) {
console.error('Error copying assets:', error);
process.exit(1);
}
Loading