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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# Finder (MacOS) folder config
.DS_Store

.agentreview
Comment thread
tejaskash marked this conversation as resolved.
2 changes: 1 addition & 1 deletion .oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"categories": {
"correctness": "error"
},
"ignorePatterns": ["dist/", "node_modules/"],
"ignorePatterns": ["dist/", "node_modules/", "src/assets/"],
"overrides": []
}
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ bun.lock
# rewrites the recorded content (e.g. collapsing arrays) and breaks the exact
# comparison the golden tests rely on. Refresh them with RECORD=1 instead.
__fixtures__

*.snap
src/assets
13 changes: 13 additions & 0 deletions bun.lock

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

5 changes: 2 additions & 3 deletions bunfig.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
# frames are plain text (no ANSI color codes) regardless of whether stdout is a
# TTY, keeping frame assertions deterministic across `bun test` and piped runs.
preload = ["./src/testing/setup.ts"]
coveragePathIgnorePatterns = [
"src/testing/**"
]
pathIgnorePatterns = ["src/assets/**"]
coveragePathIgnorePatterns = ["src/testing/**", "src/assets/**"]
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
"dist"
],
"scripts": {
"build": "bun build ./src/index.ts --target node --outdir ./dist --minify",
"build": "bun scripts/build.ts bundle",
"compile": "bun run compile:darwin-x64 && bun run compile:darwin-arm64 && bun run compile:linux-x64 && bun run compile:linux-arm64 && bun run compile:windows-x64 && bun run compile:windows-arm64",
"compile:darwin-x64": "bun build --compile --minify --target=bun-darwin-x64 ./src/index.ts --outfile dist/bin/agentcore-darwin-x64",
"compile:darwin-arm64": "bun build --compile --minify --target=bun-darwin-arm64 ./src/index.ts --outfile dist/bin/agentcore-darwin-arm64",
"compile:linux-x64": "bun build --compile --minify --target=bun-linux-x64 ./src/index.ts --outfile dist/bin/agentcore-linux-x64",
"compile:linux-arm64": "bun build --compile --minify --target=bun-linux-arm64 ./src/index.ts --outfile dist/bin/agentcore-linux-arm64",
"compile:windows-x64": "bun build --compile --minify --target=bun-windows-x64 ./src/index.ts --outfile dist/bin/agentcore-windows-x64",
"compile:windows-arm64": "bun build --compile --minify --target=bun-windows-arm64 ./src/index.ts --outfile dist/bin/agentcore-windows-arm64",
"compile:darwin-x64": "bun scripts/build.ts compile bun-darwin-x64",
"compile:darwin-arm64": "bun scripts/build.ts compile bun-darwin-arm64",
"compile:linux-x64": "bun scripts/build.ts compile bun-linux-x64",
"compile:linux-arm64": "bun scripts/build.ts compile bun-linux-arm64",
"compile:windows-x64": "bun scripts/build.ts compile bun-windows-x64",
"compile:windows-arm64": "bun scripts/build.ts compile bun-windows-arm64",
"start": "bun run src/index.ts",
"test": "bun test",
"typecheck": "tsc --noEmit",
Expand Down Expand Up @@ -64,6 +64,7 @@
"react-router": "^8.3.0",
"winston": "^3.19.0",
"winston-daily-rotate-file": "^5.0.0",
"handlebars": "^4.7.9",
"zod": "^4.4.3"
}
}
99 changes: 99 additions & 0 deletions scripts/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/usr/bin/env bun

import { $ } from "bun";
import { join, resolve } from "node:path";
import { runWithExitCode } from "../src/runnable";

const REPO_ROOT = resolve(import.meta.dir, "..");
const ASSETS_DIR = join(REPO_ROOT, "src", "assets");
const ENTRYPOINT = join(REPO_ROOT, "src", "index.ts");
const DIST = join(REPO_ROOT, "dist");

const ASSET_NAMING = "agentcore-assets/[dir]/[name].[ext]";

// Shrink whitespace/syntax but keep identifiers: minified names make stack
// traces unreadable and erase error names telemetry keys on.
const MINIFY = { whitespace: true, syntax: true, identifiers: false } as const;

/** Absolute paths of every asset file. dot:true so hidden files (.prettierrc) are included. */
function discoverAssets(): string[] {
const files = [...new Bun.Glob("**/*").scanSync({ cwd: ASSETS_DIR, onlyFiles: true, dot: true })];
return files.sort().map((relativePath) => join(ASSETS_DIR, relativePath));
}

/** Force asset files through the file loader so template .ts/.js are embedded as bytes, not compiled. */
function assetLoaderPlugin(): Bun.BunPlugin {
return {
name: "asset-file-loader",
setup(build) {
build.onLoad({ filter: /src[/\\]assets[/\\]/ }, async ({ path }) => ({
contents: await Bun.file(path).bytes(),
loader: "file",
}));
},
};
}

/** Fail loudly on a non-UTF-8 asset — the source reads every asset as text. */
async function assertAssetsAreText(assets: string[]): Promise<void> {
const decoder = new TextDecoder("utf-8", { fatal: true });
for (const path of assets) {
try {
decoder.decode(await Bun.file(path).bytes());
} catch {
throw new Error(`Asset is not valid UTF-8: ${path}`);
}
}
}

// Bun.build rejects with an AggregateError on failure (throw defaults to true),
// so build errors propagate to runWithExitCode like any other.
async function bundle(): Promise<void> {
await Bun.build({
entrypoints: [ENTRYPOINT],
outdir: DIST,
target: "node",
minify: MINIFY,
});

// Mirror assets beside the emitted module for resolveAssetsRoot().
const distAssets = join(DIST, "assets");
await $`rm -rf ${distAssets}`;
await $`cp -R ${ASSETS_DIR} ${distAssets}`;
console.log(`Bundled to ${join(DIST, "index.js")} with assets/`);
}

async function compile(target: string): Promise<void> {
const assets = discoverAssets();
await assertAssetsAreText(assets);

const outfile = join(DIST, "bin", `agentcore-${target.replace(/^bun-/, "")}`);
await $`mkdir -p ${join(DIST, "bin")}`;

await Bun.build({
entrypoints: [ENTRYPOINT, ...assets],
compile: { target: target as Bun.Build.CompileTarget, outfile },
minify: MINIFY,
root: REPO_ROOT,
naming: { asset: ASSET_NAMING },
plugins: [assetLoaderPlugin()],
});
console.log(`Compiled ${target} → ${outfile} (${assets.length} assets embedded)`);
}

process.exit(
await runWithExitCode(async () => {
const [command, target] = process.argv.slice(2);

if (command === "bundle") {
await bundle();
} else if (command === "compile") {
if (!target) {
throw new Error("Usage: bun scripts/build.ts compile <bun-target>");
}
await compile(target);
} else {
throw new Error("Usage: bun scripts/build.ts <bundle|compile <target>>");
}
}),
);
8 changes: 8 additions & 0 deletions src/assets/cdk/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"trailingComma": "es5",
"printWidth": 120,
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"arrowParens": "avoid"
}
29 changes: 29 additions & 0 deletions src/assets/cdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# AgentCore CDK Project

This CDK project is managed by the AgentCore CLI. It deploys your agent infrastructure into AWS using the `@aws/agentcore-cdk` L3 constructs.

## Structure

- `bin/cdk.ts` — Entry point. Reads project configuration from `agentcore/` and creates a stack per deployment target.
- `lib/cdk-stack.ts` — Defines `AgentCoreStack`, which wraps the `AgentCoreApplication` L3 construct.
- `test/cdk.test.ts` — Unit tests for stack synthesis.

## Useful commands

- `npm run build` compile TypeScript to JavaScript
- `npm run test` run unit tests
- `npx cdk synth` emit the synthesized CloudFormation template
- `npx cdk deploy` deploy this stack to your default AWS account/region
- `npx cdk diff` compare deployed stack with current state

## Usage

You typically don't need to interact with this directory directly. The AgentCore CLI handles synthesis and deployment:

<!-- TODO: revisit these commands once the project CLI surface is final —
they may need a project prefix (e.g. --project / cwd) to disambiguate. -->

```bash
Comment thread
tejaskash marked this conversation as resolved.
agentcore deploy # synthesizes and deploys via CDK
agentcore status # checks deployment status
```
Loading
Loading