|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +This repository ("Roboppi" / package name: `agentcore`) is a Bun + TypeScript (ESM) |
| 4 | +codebase that implements an execution-control runtime for agentic workers. |
| 5 | + |
| 6 | +## Build / Lint / Test |
| 7 | + |
| 8 | +Prefer `make` targets (CI uses them), but `bun` equivalents work. |
| 9 | + |
| 10 | +### Install |
| 11 | + |
| 12 | +```bash |
| 13 | +bun install |
| 14 | +bun install --frozen-lockfile # CI |
| 15 | +``` |
| 16 | + |
| 17 | +CI currently uses Bun 1.3.8 (see `.github/workflows/ci.yml`). |
| 18 | + |
| 19 | +### Typecheck (acts as "lint") |
| 20 | + |
| 21 | +There is no ESLint/Prettier/Biome config today; use TypeScript strict checks + tests. |
| 22 | + |
| 23 | +```bash |
| 24 | +make typecheck |
| 25 | +# or |
| 26 | +bun run typecheck |
| 27 | +``` |
| 28 | + |
| 29 | +### Tests |
| 30 | + |
| 31 | +```bash |
| 32 | +make test # bun test |
| 33 | +make test-unit # bun test test/unit |
| 34 | +make test-integration # bun test test/integration |
| 35 | +make test-at # bun test tests/at |
| 36 | +make test-branch # bash tests/branch/run-branch-verification.sh |
| 37 | +make test-all # CI: typecheck + test + test-branch |
| 38 | +``` |
| 39 | + |
| 40 | +Acceptance test helper runner: |
| 41 | + |
| 42 | +```bash |
| 43 | +bash scripts/run-at.sh # typecheck + tests/at |
| 44 | +bash scripts/run-at.sh --full # + bun test |
| 45 | +``` |
| 46 | + |
| 47 | +### Run A Single Test |
| 48 | + |
| 49 | +```bash |
| 50 | +bun test test/unit/ipc/protocol.test.ts |
| 51 | +bun test test/unit/ipc/protocol.test.ts -t "routes submit_job" # regex on test name |
| 52 | +bun test -t "routes submit_job" # match across all tests |
| 53 | +bun test --only # only test.only/describe.only |
| 54 | +bun test --timeout 20000 test/integration # per-test timeout (ms) |
| 55 | +bun test --watch test/unit # watch mode |
| 56 | +``` |
| 57 | + |
| 58 | +### Build |
| 59 | + |
| 60 | +Builds a native executable `./agentcore` (gitignored). |
| 61 | + |
| 62 | +```bash |
| 63 | +make build # or: bun run build |
| 64 | +make install # /usr/local/bin/agentcore |
| 65 | +make uninstall |
| 66 | +``` |
| 67 | + |
| 68 | +### Dev / Run |
| 69 | + |
| 70 | +```bash |
| 71 | +make dev # bun run src/cli.ts |
| 72 | +bun run dev # bun run src/index.ts |
| 73 | +bun run dev:scheduler # bun run src/scheduler/index.ts |
| 74 | +``` |
| 75 | + |
| 76 | +## Project Layout (high-level) |
| 77 | + |
| 78 | +- Runtime entrypoints: `src/cli.ts` (bin), `src/index.ts` (Core process) |
| 79 | +- Core safety mechanisms: `src/core/**` |
| 80 | +- IPC JSONL protocol/transport: `src/ipc/**` |
| 81 | +- Daemon entrypoints: `src/daemon/**` |
| 82 | +- Worker adapters + process mgmt: `src/worker/**` |
| 83 | +- Workflow runner/executor: `src/workflow/**` |
| 84 | +- Scheduler layer: `src/scheduler/**` |
| 85 | +- Design notes: `docs/**` |
| 86 | +- Unit/integration tests: `test/**` |
| 87 | +- Acceptance + branch-safety tests: `tests/**` |
| 88 | + |
| 89 | +## Code Style Guidelines |
| 90 | + |
| 91 | +### TypeScript / Module System |
| 92 | + |
| 93 | +- ESM everywhere (`package.json` has `"type": "module"`). |
| 94 | +- Relative imports for local modules MUST include the `.js` extension. |
| 95 | + - Example: `import { AgentCore } from "./core/agentcore.js";` |
| 96 | +- Use `node:` specifiers for built-in modules. |
| 97 | + - Example: `import { readFile } from "node:fs/promises";` |
| 98 | +- Use `import type { ... }` for type-only imports. |
| 99 | +- Avoid the `@/*` path alias unless you confirm runtime resolution; prefer relative imports. |
| 100 | + |
| 101 | +### Formatting |
| 102 | + |
| 103 | +- 2-space indentation, semicolons, trailing commas in multiline constructs. |
| 104 | +- Keep changes minimal: no repo-wide reformatting sweeps (no formatter is enforced). |
| 105 | + |
| 106 | +### Imports |
| 107 | + |
| 108 | +- No enforced ordering; keep import groups consistent within the file you touch. |
| 109 | +- Keep `import ...` statements at the top of the file. |
| 110 | +- Prefer `../types/index.js` barrel exports for shared types/enums. |
| 111 | +- Avoid default exports for local modules; use named exports (existing pattern). |
| 112 | + |
| 113 | +### Types |
| 114 | + |
| 115 | +- `tsconfig.json` is strict (`noUncheckedIndexedAccess`, `noUnusedLocals/Parameters`, etc.). |
| 116 | +- Avoid `any` in `src/**`. |
| 117 | + - Use `unknown` in `catch` and narrow via `instanceof Error`, `typeof`, etc. |
| 118 | +- Add explicit return types for exported functions and public class methods. |
| 119 | +- Prefer small discriminated unions / string enums for protocol/state machines. |
| 120 | + |
| 121 | +### Naming |
| 122 | + |
| 123 | +- Files: `kebab-case.ts` (e.g., `json-lines-transport.ts`). |
| 124 | +- Classes/types/interfaces/enums: `PascalCase`. |
| 125 | +- Functions/locals: `camelCase`. |
| 126 | +- Constants: `SCREAMING_SNAKE_CASE`. |
| 127 | +- IDs are UUID strings: use `generateId()` / `crypto.randomUUID()`. |
| 128 | + |
| 129 | +### Error Handling |
| 130 | + |
| 131 | +- Throw `Error` (or subclasses), never strings. |
| 132 | +- Set `err.name` on custom error classes; attach `cause` when useful. |
| 133 | +- When surfacing errors across boundaries (IPC/worker/workflow), include context: `requestId`, `jobId`, `permitId`, `stepId`. |
| 134 | +- Use `ErrorClass` for retryability when returning `WorkerResult`-style failures. |
| 135 | + |
| 136 | +### Cancellation / Timeouts / Cleanup |
| 137 | + |
| 138 | +- If a function can block (IO, process spawn, long loop), accept an `AbortSignal` |
| 139 | + and stop promptly when aborted. |
| 140 | +- Always clear timers and remove event listeners in `finally` blocks. |
| 141 | +- When spawning subprocesses, prefer `ProcessManager` (abort, timeout, best-effort process-group termination). |
| 142 | + |
| 143 | +### IPC Safety |
| 144 | + |
| 145 | +- IPC is JSON Lines over stdout. In server/Core mode, NEVER write non-JSON to stdout (use stderr/loggers). |
| 146 | +- Validate message shape before acting (see `src/ipc/protocol.ts`). |
| 147 | + |
| 148 | +### Tests |
| 149 | + |
| 150 | +- Use `bun:test` (`describe`, `test`/`it`, `expect`). |
| 151 | +- Keep tests deterministic; avoid network and real worker CLIs in unit tests. |
| 152 | +- Use temp dirs for filesystem work; clean up after. |
| 153 | + |
| 154 | +## Cursor / Copilot Rules |
| 155 | + |
| 156 | +- No `.cursor/rules/`, `.cursorrules`, or `.github/copilot-instructions.md` found in this repo. |
0 commit comments