|
| 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 |
0 commit comments