Skip to content

Commit 79cb66f

Browse files
committed
feat: HyperAgent v0.1.0 — AI agent with sandboxed JS execution
Hyperlight micro-VM sandboxed JavaScript agent powered by the GitHub Copilot SDK. - Sandboxed ES2023 runtime in Hyperlight micro-VMs (KVM/MSHV/WHP) - Plugin system with security auditing (fs-read, fs-write, fetch) - Builtin modules: PPTX generation, ZIP, HTML, Markdown, image processing - Skills and patterns framework for task-specific guidance - Native Rust code validator via NAPI addon - CLI with profiles, skills, auto-approve, debug/transcript logging - Docker support with KVM passthrough - Standalone binary builds via pkg Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
0 parents  commit 79cb66f

File tree

233 files changed

+93173
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

233 files changed

+93173
-0
lines changed

.claude/CLAUDE.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Hyperagent - Claude Code Instructions
2+
3+
## Generated Files - DO NOT EDIT DIRECTLY
4+
5+
These files are auto-generated. Editing them directly will cause test failures.
6+
7+
### builtin-modules/*.js and *.d.ts
8+
9+
Generated from `builtin-modules/src/*.ts` by TypeScript compiler.
10+
11+
- **To modify**: Edit source in `builtin-modules/src/*.ts`
12+
- **To regenerate**: Run `npm run build:modules`
13+
- **Enforced by**: `tests/dts-sync.test.ts` compares compiled output to committed files
14+
15+
### src/code-validator/guest/index.d.ts
16+
17+
Generated from Rust source. Do not edit.
18+
19+
## Plugins - TypeScript Only
20+
21+
Plugins MUST be TypeScript files. The test suite enforces this.
22+
23+
- **Plugin source**: `plugins/<name>/index.ts`
24+
- **Shared utilities**: `plugins/shared/*.ts`
25+
- **Test fixtures**: `tests/fixtures/<name>/index.ts`
26+
- **Enforced by**: `tests/plugin-source.test.ts` fails if `.js` files exist
27+
28+
### Current plugins:
29+
- `plugins/fs-read/index.ts` - Read-only filesystem access
30+
- `plugins/fs-write/index.ts` - Write-only filesystem access
31+
- `plugins/fetch/index.ts` - Secure HTTPS fetching
32+
33+
## Build & Test
34+
35+
Use `just` commands for development (preferred) or npm scripts:
36+
37+
```bash
38+
# ── Development ──
39+
just setup # First-time setup: clone deps, build native addons, npm install
40+
just build # Rebuild native addons and install deps
41+
just start # Run agent (tsx src/agent/index.ts)
42+
43+
# ── Testing ──
44+
just test # Run TypeScript tests
45+
just test-rust # Run Rust tests (analysis-guest)
46+
just test-all # Run all tests (TS + Rust)
47+
48+
# ── Formatting ──
49+
just fmt # Format TypeScript/JavaScript
50+
just fmt-rust # Format Rust (analysis-guest)
51+
just fmt-runtime # Format Rust (sandbox/runtime)
52+
just fmt-all # Format all code
53+
54+
# ── Linting ──
55+
just lint # TypeScript: fmt-check + typecheck
56+
just lint-rust # Rust: clippy + fmt-check (analysis-guest)
57+
just lint-runtime # Rust: clippy + fmt-check (runtime)
58+
just lint-all # All lints
59+
60+
# ── Quality Gate ──
61+
just check # Full quality gate: lint-all + test-all
62+
63+
# ── npm equivalents ──
64+
npm run start # Run agent (tsx src/agent/index.ts)
65+
npm run test # Run TypeScript tests
66+
npm run typecheck # TypeScript type checking
67+
npm run fmt # Format with Prettier
68+
npm run check # fmt:check + typecheck + test
69+
```

.dockerignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Root node_modules (dev deps, huge)
2+
node_modules/
3+
4+
# Git
5+
.git/
6+
**/.git/
7+
8+
# Logs and docs
9+
*.log
10+
working_docs/
11+
working-docs/
12+
tests/
13+
.claude/
14+
15+
# Rust build artifacts (huge - 9GB+)
16+
deps/hyperlight-js/target/
17+
src/hyperlight-analysis-guest/target/
18+
**/target/
19+
20+
# KEEP dist/lib/node_modules (bundled @github/copilot SDK)
21+
# Only exclude root node_modules

.github/copilot-instructions.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Hyperagent — Copilot Instructions
2+
3+
## Project Overview
4+
5+
HyperAgent is an AI agent with a sandboxed JavaScript executor, powered by Hyperlight micro-VMs and the GitHub Copilot SDK. It is a TypeScript + Rust project using ESM modules, strict TypeScript, Vitest for testing, Prettier for formatting, and `just` as the task runner.
6+
7+
**Prerequisites**: Node.js 22+, Rust toolchain, Linux with KVM (hardware virtualisation required for Hyperlight micro-VMs).
8+
9+
## Source Structure
10+
11+
```
12+
src/
13+
├── agent/ # CLI agent — REPL, commands, UI (entry: index.ts)
14+
├── plugin-system/ # Plugin lifecycle (manager.ts, auditor.ts, types.ts, schema-types.ts)
15+
├── sandbox/ # Sandbox tool (tool.js, tool.d.ts) + Rust runtime
16+
└── code-validator/ # Rust NAPI addon for code validation
17+
```
18+
19+
Runtime content at root (not compiled source):
20+
- `plugins/` — Plugin implementations (fs-read, fs-write, fetch)
21+
- `builtin-modules/` — Sandbox ES modules (generated from `builtin-modules/src/*.ts`)
22+
- `skills/` — AI skill definitions (SKILL.md files)
23+
- `patterns/` — Workflow patterns (PATTERN.md files)
24+
25+
Key config files at root: `package.json`, `tsconfig.json`, `vitest.config.ts`, `Justfile`, `Dockerfile`.
26+
27+
## Build, Test & Validate
28+
29+
Always use these commands in this order for a clean build:
30+
31+
```bash
32+
just setup # First-time only: clone deps, build native addons, npm install
33+
just build # Rebuild native addons and install deps (run after Rust changes)
34+
```
35+
36+
Before committing changes, always run the full quality gate:
37+
38+
```bash
39+
just check # Runs: lint-all (fmt-check + typecheck + clippy) + test-all (TS + Rust)
40+
```
41+
42+
Individual commands:
43+
44+
| Command | What it does | When to use |
45+
|---------|-------------|-------------|
46+
| `just fmt` | Format TS/JS with Prettier | Before committing |
47+
| `just lint` | `fmt-check` + `tsc --noEmit` | Quick validation |
48+
| `just test` | Run Vitest suite (30 test files, ~1700 tests) | After TS changes |
49+
| `just test-rust` | Run Rust tests in code-validator | After Rust changes |
50+
| `just test-all` | Both TS + Rust tests | Full validation |
51+
| `just start` | Run agent with `tsx` (no build needed) | Dev/testing |
52+
| `just binary-release` | Build standalone binary to `dist/bin/hyperagent` | Release builds |
53+
54+
npm equivalents: `npm run fmt`, `npm run typecheck`, `npm test`, `npm run check`.
55+
56+
**Important**: Always run `just build` (or `just setup` on first run) before running tests — the native Rust addons must be compiled first.
57+
58+
## Generated Files — DO NOT EDIT DIRECTLY
59+
60+
These are auto-generated. Editing them directly causes test failures.
61+
62+
- `builtin-modules/*.js` and `builtin-modules/*.d.ts` — Generated from `builtin-modules/src/*.ts`. Edit the source, then run `npm run build:modules`. Enforced by `tests/dts-sync.test.ts`.
63+
- `src/code-validator/guest/index.d.ts` — Generated from Rust source.
64+
- `plugins/*/index.d.ts` — Generated from plugin TypeScript source.
65+
- `plugins/host-modules.d.ts` — Generated by `scripts/generate-host-modules-dts.ts`.
66+
67+
## Plugins — TypeScript Only
68+
69+
Plugins MUST be TypeScript `.ts` files, not JavaScript. The test suite enforces this (`tests/plugin-source.test.ts`).
70+
71+
- Plugin source: `plugins/<name>/index.ts`
72+
- Shared utilities: `plugins/shared/*.ts`
73+
- Test fixtures: `tests/fixtures/<name>/index.ts`
74+
75+
Current plugins:
76+
- `plugins/fs-read/index.ts` — Read-only filesystem access
77+
- `plugins/fs-write/index.ts` — Write-only filesystem access
78+
- `plugins/fetch/index.ts` — Secure HTTPS fetching
79+
80+
## Coding Conventions
81+
82+
- **ESM only** — The project uses `"type": "module"`. All imports use `.js` extensions in specifiers (e.g. `import { foo } from "./bar.js"`).
83+
- **Strict TypeScript**`strict: true` in tsconfig. Zero type errors enforced.
84+
- **No `expect`/`unwrap`/`assert` in production code** — Handle errors properly.
85+
- **Format with Prettier** before committing — `just fmt` or `npm run fmt`.
86+
- **All log files write to `~/.hyperagent/logs/`** — Debug, timing, code, tune, transcript, and crash reports all go there.
87+
- **Disk cache at `~/.hyperagent/fetch-cache/`** — The fetch plugin's persistent HTTP cache.
88+
- **User data at `~/.hyperagent/`** — Modules, profiles, history, approval store.
89+
90+
## Validation Checklist
91+
92+
Before considering a change complete:
93+
1. `just fmt` — all code formatted
94+
2. `just lint` — TypeScript compiles with zero errors
95+
3. `just test` — all ~1700 tests pass
96+
4. If Rust code was changed: `just test-rust` passes
97+
5. No new `expect`/`unwrap`/`assert` in production TS code
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
applyTo: "builtin-modules/**"
3+
---
4+
5+
# Builtin Modules
6+
7+
Modules that run inside the Hyperlight sandbox, available to guest JavaScript via `require("ha:<module>")`.
8+
9+
## Rules
10+
11+
- **Source files** — Edit only `src/*.ts` files
12+
- **Generated files**`*.js` and `*.d.ts` in the root are auto-generated
13+
- **Regenerate** — Run `npm run build:modules` after editing source
14+
- **Enforced by**`tests/dts-sync.test.ts` compares compiled output to committed files
15+
16+
## Module Header Format
17+
18+
Each module should have a standard header comment:
19+
20+
```typescript
21+
// @module <name>
22+
// @description <description>
23+
// @created <ISO date>
24+
// @modified <ISO date>
25+
// @mutable false
26+
// @author system
27+
```
28+
29+
## Current Modules
30+
31+
| Module | Purpose |
32+
|--------|---------|
33+
| `base64` | Base64 encode/decode for Uint8Array |
34+
| `crc32` | CRC32 checksum calculation |
35+
| `xml-escape` | XML entity escaping |
36+
| `zip-format` | ZIP file creation |
37+
| `str-bytes` | String/bytes conversion |
38+
| `ooxml-core` | Core OOXML utilities |
39+
| `pptx` | PowerPoint generation |
40+
| `pptx-charts` | Chart support for PPTX |
41+
| `pptx-tables` | Table support for PPTX |
42+
| `shared-state` | Cross-handler state management |
43+
44+
## Workflow
45+
46+
1. Edit `src/<module>.ts`
47+
2. Run `npm run build:modules`
48+
3. Commit both source and generated files
49+
4. Test via `just test`
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
applyTo: "patterns/**"
3+
---
4+
5+
# Patterns
6+
7+
Reusable implementation patterns for common sandbox workflows. Skills reference patterns via their `patterns:` frontmatter.
8+
9+
## Pattern Structure
10+
11+
```
12+
patterns/<pattern-name>/
13+
└── PATTERN.md # Pattern definition with frontmatter + steps
14+
```
15+
16+
## PATTERN.md Format
17+
18+
```yaml
19+
---
20+
name: pattern-name
21+
description: One-line description
22+
modules: [module1, module2] # ha:* modules needed
23+
plugins: [plugin1] # host:* plugins needed (optional)
24+
profiles: [profile-name] # Resource profiles to apply (optional)
25+
config: # Config overrides (optional)
26+
heapMb: 64
27+
cpuTimeoutMs: 30000
28+
---
29+
30+
1. First implementation step
31+
2. Second implementation step
32+
3. ...
33+
```
34+
35+
## Current Patterns
36+
37+
| Pattern | Purpose |
38+
|---------|---------|
39+
| `two-handler-pipeline` | Research → Build using ha:shared-state |
40+
| `fetch-and-process` | Fetch external data and process it |
41+
| `file-generation` | Generate output files |
42+
| `image-embed` | Embed images in output |
43+
| `data-extraction` | Extract structured data |
44+
| `data-transformation` | Transform data between formats |
45+
46+
## Adding a Pattern
47+
48+
1. Create `patterns/<name>/PATTERN.md`
49+
2. Add YAML frontmatter with required modules/plugins
50+
3. Write numbered implementation steps in the body
51+
4. Reference from skills via `patterns: [<name>]`
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
applyTo: "plugins/**"
3+
---
4+
5+
# Plugins
6+
7+
Plugins extend the Hyperlight sandbox with host functions that guest JavaScript imports via `require("host:<module>")`.
8+
9+
## Rules
10+
11+
- **TypeScript only** — All plugins must be `.ts` files. No `.js` files allowed.
12+
- **Enforced by**`tests/plugin-source.test.ts` fails if `.js` files exist
13+
- Each plugin lives in its own directory with `index.ts` and `plugin.json`
14+
15+
## Structure
16+
17+
```
18+
plugins/
19+
├── fs-read/index.ts # Read-only filesystem (jailed to base directory)
20+
├── fs-write/index.ts # Write-only filesystem (jailed to base directory)
21+
├── fetch/index.ts # Secure HTTPS fetching
22+
├── shared/ # Shared utilities (not a plugin)
23+
│ └── path-jail.ts # Path validation for fs plugins
24+
└── plugin-schema-types.ts
25+
```
26+
27+
## Security Model
28+
29+
- Plugins are security boundaries — guest code cannot escape the sandbox
30+
- Path traversal attacks are blocked via `shared/path-jail.ts`
31+
- Symlinks are rejected outright
32+
- Dotfiles are always blocked
33+
- Error messages are sanitised (no raw OS paths leak to guest)
34+
35+
## Adding a New Plugin
36+
37+
1. Create `plugins/<name>/index.ts` with plugin implementation
38+
2. Create `plugins/<name>/plugin.json` with manifest
39+
3. Export functions that will be available to guest JS
40+
4. Run `just test` to verify TypeScript requirement is met
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
applyTo: "skills/**"
3+
---
4+
5+
# Skills
6+
7+
Skills are domain-specific expertise modules that the agent can invoke. Each skill is defined by a `SKILL.md` file with YAML frontmatter.
8+
9+
## Skill Structure
10+
11+
```
12+
skills/<skill-name>/
13+
└── SKILL.md # Skill definition with frontmatter + instructions
14+
```
15+
16+
## SKILL.md Format
17+
18+
```yaml
19+
---
20+
name: skill-name
21+
description: One-line description
22+
triggers:
23+
- keyword1
24+
- keyword2
25+
patterns:
26+
- pattern-name
27+
antiPatterns:
28+
- "Don't do X"
29+
allowed-tools:
30+
- tool_name
31+
---
32+
33+
# Skill Title
34+
35+
Detailed instructions for the LLM when this skill is active.
36+
```
37+
38+
## Current Skills
39+
40+
| Skill | Purpose |
41+
|-------|---------|
42+
| `pptx-expert` | PowerPoint presentation building |
43+
| `research-synthesiser` | Research and synthesis |
44+
| `data-processor` | Data processing workflows |
45+
| `web-scraper` | Web scraping |
46+
| `report-builder` | Report generation |
47+
| `api-explorer` | API exploration |
48+
49+
## Triggers
50+
51+
Skills are activated when user input matches trigger keywords. Multiple skills can match — the agent decides which to use.
52+
53+
## Allowed Tools
54+
55+
The `allowed-tools` frontmatter restricts which tools the skill can use. This provides a security boundary for domain-specific operations.

0 commit comments

Comments
 (0)