@replayio/app-building 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,92 +1,124 @@
1
- # app-building
1
+ # @replayio/app-building
2
2
 
3
- Simple and extensible platform for dark factory agentic app building: creating apps
4
- according to a spec without human involvement along the way. Example use cases:
3
+ Library for managing agentic app-building containers. Start and stop containers locally (Docker) or remotely (Fly.io), communicate with the in-container HTTP server, and track container state via a local registry.
5
4
 
6
- * `npm run agent -- -p "Build me an app XYZ based on this spec: ..."`
7
- * `npm run agent -- -p "Continue maintaining app XYZ and fix these bugs: ..."`
8
- * `npm run agent -- -i` for interactive access to the agent.
9
-
10
- Core ideas:
11
-
12
- * The agent runs within a docker container that clones the target repo and exposes an HTTP server for control.
13
- * The host communicates with the container via HTTP — sending prompts, polling events/logs, and managing lifecycle.
14
- * The agent builds by following a set of skill documents with guides
15
- for breaking its work down into jobs and directives for performing those tasks.
16
- * The agent commits logs for it to review later and improve its skills.
17
- * All code changes are committed and pushed back to the remote from inside the container.
18
-
19
- Containers can run locally or remotely.
20
-
21
- ## Setup
5
+ ## Install
22
6
 
23
7
  ```bash
24
- npm install
8
+ npm install @replayio/app-building
25
9
  ```
26
10
 
27
- Copy `.env.example` to `.env` and fill in all required API keys.
11
+ ## Usage
12
+
13
+ ```ts
14
+ import {
15
+ loadDotEnv,
16
+ ContainerRegistry,
17
+ type ContainerConfig,
18
+ type RepoOptions,
19
+ startContainer,
20
+ startRemoteContainer,
21
+ stopRemoteContainer,
22
+ httpGet,
23
+ httpPost,
24
+ httpOptsFor,
25
+ } from "@replayio/app-building";
26
+
27
+ // Assemble config once at startup
28
+ const envVars = loadDotEnv("/path/to/project");
29
+ const config: ContainerConfig = {
30
+ projectRoot: "/path/to/project",
31
+ envVars,
32
+ registry: new ContainerRegistry("/path/to/.container-registry.jsonl"),
33
+ flyToken: envVars.FLY_API_TOKEN,
34
+ flyApp: envVars.FLY_APP_NAME,
35
+ };
36
+
37
+ // Start a remote container
38
+ const repo: RepoOptions = { repoUrl: "https://github.com/...", cloneBranch: "main", pushBranch: "main" };
39
+ const state = await startRemoteContainer(config, repo);
40
+
41
+ // Send a prompt and wait for completion
42
+ const httpOpts = httpOptsFor(state);
43
+ const { id } = await httpPost(`${state.baseUrl}/message`, { prompt: "Build the app" }, httpOpts);
44
+
45
+ // Check status
46
+ const status = await httpGet(`${state.baseUrl}/status`, httpOpts);
47
+
48
+ // Query the registry
49
+ const alive = await config.registry.findAlive();
50
+
51
+ // Clean up
52
+ await stopRemoteContainer(config, state);
53
+ ```
28
54
 
29
- ## Running the Agent
55
+ ## Exported API
30
56
 
31
- `npm run agent` starts a new container with the running agent. By default the container is local, add `--remote` to spawn the container remotely. This requires FLY_API_TOKEN in .env
57
+ ### Domain objects
32
58
 
33
- ### Detached mode
59
+ | Export | Description |
60
+ |---|---|
61
+ | `ContainerConfig` | Interface bundling all external state: `projectRoot`, `envVars`, `registry`, optional `flyToken`/`flyApp`/`imageRef`. |
62
+ | `RepoOptions` | Per-invocation git settings: `repoUrl`, `cloneBranch`, `pushBranch`. |
63
+ | `ContainerRegistry` | Class encapsulating `.container-registry.jsonl` persistence. Methods: `log`, `markStopped`, `clearStopped`, `getRecent`, `find`, `findAlive`. |
34
64
 
35
- ```bash
36
- npm run agent
37
- npm run agent -- -p "<prompt>"
38
- npm run agent -- --branch dev --push-branch feature/xyz -p "<prompt>"
39
- ```
65
+ ### Container lifecycle
40
66
 
41
- Starts a container, optionally queues a prompt, then detaches. The container processes the prompt followed by any pending tasks, commits and pushes results, then exits.
67
+ | Export | Description |
68
+ |---|---|
69
+ | `startContainer(config, repo)` | Build the Docker image locally and start a container with `--network host`. Returns `AgentState`. |
70
+ | `startRemoteContainer(config, repo)` | Create a Fly.io machine using the GHCR image. Requires `config.flyToken` and `config.flyApp`. Returns `AgentState`. |
71
+ | `stopContainer(config, containerName)` | Stop a local Docker container by name. |
72
+ | `stopRemoteContainer(config, state)` | Destroy the Fly.io machine for a remote container. Requires `config.flyToken`. |
73
+ | `buildImage(config)` | Build the Docker image locally (called automatically by `startContainer`). |
74
+ | `spawnTestContainer(config)` | Start an interactive (`-it`) container with the repo mounted at `/repo`. |
75
+ | `loadDotEnv(projectRoot)` | Parse a `.env` file and return key-value pairs. |
42
76
 
43
- ### Interactive mode
77
+ **Types:** `AgentState`, `ContainerConfig`, `RepoOptions`
44
78
 
45
- ```bash
46
- npm run agent -- -i
47
- ```
48
-
49
- Chat with the agent inside a container. Output is streamed via event polling. Press ESC to interrupt the current message. On exit, the container is detached and finishes any remaining work.
79
+ ### Container registry (`ContainerRegistry` class)
50
80
 
51
- ### Checking status
81
+ | Method | Description |
82
+ |---|---|
83
+ | `log(state)` | Append a new entry to the registry. |
84
+ | `markStopped(name?)` | Mark a container as stopped. |
85
+ | `clearStopped(name)` | Clear the stopped flag (container came back alive). |
86
+ | `getRecent(limit?)` | Read the most recent registry entries. |
87
+ | `find(name)` | Find a specific container by name. |
88
+ | `findAlive()` | Probe recent entries and return those that are alive. Reconciles stopped flags. |
52
89
 
53
- ```bash
54
- npm run status
55
- ```
90
+ **Types:** `RegistryEntry`
56
91
 
57
- Connects to the running container's HTTP API and shows state, revision, queue depth, cost, and recent log output. Tails logs in real-time (Ctrl+C to stop). Errors if no agent is running.
92
+ ### HTTP client
58
93
 
59
- ### Stopping the agent
60
-
61
- ```bash
62
- npm run stop
63
- npm run stop -- <containerName>
64
- ```
94
+ | Export | Description |
95
+ |---|---|
96
+ | `httpGet(url, opts?)` | GET with retries and timeout. Returns parsed JSON. |
97
+ | `httpPost(url, body?, opts?)` | POST with retries and timeout. Returns parsed JSON. |
65
98
 
66
- Sends an HTTP stop signal. Without arguments, finds and stops all running containers. Pass a container name to stop a specific one.
99
+ **Types:** `HttpOptions`
67
100
 
68
- ## Skills
101
+ ### Container utilities
69
102
 
70
- The provided skill documents emphasize a structured approach for autonomously building
71
- high quality, well tested apps from the initial spec. During the initial app build
72
- it does the following:
103
+ | Export | Description |
104
+ |---|---|
105
+ | `httpOptsFor(state)` | Return `HttpOptions` for a container (adds `fly-force-instance-id` header for remote containers). |
106
+ | `probeAlive(entry)` | Check if a container is responding to `/status`. |
73
107
 
74
- 1. Designs a comprehensive test specification based on the initial spec.
75
- 2. Builds the app and writes tests to match the spec.
76
- 3. Gets all the tests to pass, deploys to production, and does further testing.
108
+ ### Fly.io machines
77
109
 
78
- The initial build will not come out perfect. The agent can followup with maintenance passes
79
- where it checks to make sure it closely followed the spec and skill directives and fixes
80
- any issues it finds. It will also fix reported bugs and update the skills to avoid
81
- similar problems in the future.
110
+ | Export | Description |
111
+ |---|---|
112
+ | `createApp(token, name, org?)` | Create a Fly app and allocate IPs. |
113
+ | `createMachine(app, token, image, env, name)` | Create a Fly machine. Returns machine ID. |
114
+ | `waitForMachine(app, token, machineId, timeout?)` | Wait for a machine to reach `started` state. |
115
+ | `destroyMachine(app, token, machineId)` | Force-destroy a machine. |
116
+ | `listMachines(app, token)` | List all machines for an app. |
82
117
 
83
- As long as each individual step the agent takes is within its capabilities (it can usually
84
- do it but not always) the agent will converge on an app that follows the initial spec
85
- and skill directives.
118
+ **Types:** `FlyMachineInfo`
86
119
 
87
- Key things to watch out for:
120
+ ### Image ref
88
121
 
89
- * Best suited for CRUD and API-calling apps up to a medium level of complexity.
90
- Overly complicated or specialized apps will not work as well yet.
91
- * Make sure to get a Replay API key and configure it. The agent will use Replay to identify
92
- and debug problems it encounters in tests or the deployed app.
122
+ | Export | Description |
123
+ |---|---|
124
+ | `getImageRef()` | Returns `CONTAINER_IMAGE_REF` env var, or `ghcr.io/replayio/app-building:latest` by default. Used by `startRemoteContainer`. |
package/package.json CHANGED
@@ -1,35 +1,18 @@
1
1
  {
2
2
  "name": "@replayio/app-building",
3
- "version": "1.0.1",
4
- "description": "Simple agent loop for building apps with Claude Code CLI",
3
+ "version": "1.0.3",
4
+ "description": "Library for managing agentic app-building containers",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
8
- "import": "./dist/package/index.js",
9
- "types": "./dist/package/index.d.ts"
8
+ "import": "./dist/index.js",
9
+ "types": "./dist/index.d.ts"
10
10
  }
11
11
  },
12
12
  "files": [
13
- "dist/package"
13
+ "dist"
14
14
  ],
15
- "readme": "src/package/README.md",
16
15
  "scripts": {
17
- "agent": "tsx src/agent.ts",
18
- "status": "tsx src/status.ts",
19
- "read-log": "tsx src/read-log.ts",
20
- "reset-app": "tsx src/reset-app.ts",
21
- "docker:build": "docker build --no-cache --network=host -t app-building .",
22
- "test-container": "tsx src/test-container.ts",
23
- "stop": "tsx src/stop.ts",
24
- "fly-machines": "tsx src/fly-machines.ts",
25
- "add-task": "tsx scripts/add-task.ts"
26
- },
27
- "devDependencies": {
28
- "@types/node": "^25.3.0",
29
- "tsx": "^4.19.0",
30
- "typescript": "^5.5.0"
31
- },
32
- "dependencies": {
33
- "commander": "^14.0.3"
16
+ "prepublishOnly": "tsc -p tsconfig.json"
34
17
  }
35
18
  }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes