@cyanautomation/kaseki-agent 1.45.0 → 1.47.0
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 +101 -1670
- package/dist/artifact-metadata.d.ts.map +1 -1
- package/dist/artifact-metadata.js +37 -0
- package/dist/artifact-metadata.js.map +1 -1
- package/dist/instance-state-derivation.d.ts +1 -0
- package/dist/instance-state-derivation.d.ts.map +1 -1
- package/dist/instance-state-derivation.js +8 -0
- package/dist/instance-state-derivation.js.map +1 -1
- package/dist/job-scheduler.d.ts.map +1 -1
- package/dist/job-scheduler.js +18 -0
- package/dist/job-scheduler.js.map +1 -1
- package/dist/kaseki-api-types.d.ts +39 -0
- package/dist/kaseki-api-types.d.ts.map +1 -1
- package/dist/kaseki-api-types.js +12 -0
- package/dist/kaseki-api-types.js.map +1 -1
- package/dist/kaseki-api-web.d.ts.map +1 -1
- package/dist/kaseki-api-web.js +68 -19
- package/dist/kaseki-api-web.js.map +1 -1
- package/dist/openapi-spec-generators/schemas.d.ts.map +1 -1
- package/dist/openapi-spec-generators/schemas.js +24 -0
- package/dist/openapi-spec-generators/schemas.js.map +1 -1
- package/dist/utils/status-response-builder.d.ts.map +1 -1
- package/dist/utils/status-response-builder.js +3 -1
- package/dist/utils/status-response-builder.js.map +1 -1
- package/kaseki-agent.sh +256 -3
- package/package.json +1 -1
- package/scripts/startup-checks.sh +10 -0
package/README.md
CHANGED
|
@@ -1,1756 +1,187 @@
|
|
|
1
1
|
# Kaseki Agent
|
|
2
2
|
|
|
3
|
-
Kaseki is a proof-of-concept ephemeral coding-agent runner. Each run
|
|
3
|
+
Kaseki is a proof-of-concept ephemeral coding-agent runner. Each run creates a numbered, disposable container instance (kaseki-1, kaseki-2, etc.) that orchestrates the Pi coding-agent with OpenRouter.
|
|
4
4
|
|
|
5
5
|
## Quick Start
|
|
6
6
|
|
|
7
|
-
###
|
|
7
|
+
### 1. Install Setup
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
10
|
# Global install (recommended)
|
|
11
11
|
npm install -g @cyanautomation/kaseki-agent
|
|
12
12
|
|
|
13
|
-
# One-command setup
|
|
14
|
-
|
|
15
|
-
kaseki-agent quickstart
|
|
13
|
+
# One-command setup with auto-detection
|
|
14
|
+
kaseki-agent init
|
|
16
15
|
```
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
Or use Docker:
|
|
20
18
|
```bash
|
|
21
|
-
kaseki-agent
|
|
19
|
+
docker run -it docker.io/cyanautomation/kaseki-agent:latest init
|
|
22
20
|
```
|
|
23
21
|
|
|
24
|
-
|
|
22
|
+
### 2. Configure Authentication
|
|
25
23
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
kaseki-agent run https://github.com/CyanAutomation/crudmapper main "Add input validation to all POST endpoints"
|
|
30
|
-
kaseki-agent list
|
|
31
|
-
kaseki-agent status kaseki-1
|
|
32
|
-
kaseki-agent report kaseki-1
|
|
33
|
-
```
|
|
24
|
+
The setup wizard will guide you through providing:
|
|
25
|
+
- **OpenRouter API Key** (required): `sk-or-...`
|
|
26
|
+
- **GitHub App Credentials** (optional): App ID, Client ID, Private Key
|
|
34
27
|
|
|
35
|
-
|
|
28
|
+
### 3. Run Your First Task
|
|
36
29
|
|
|
37
30
|
```bash
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
### Without Global Install
|
|
31
|
+
# Start API service (Docker Compose recommended)
|
|
32
|
+
docker-compose up -d
|
|
42
33
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
KASEKI_API_URL=http://localhost:8080/api npx kaseki-agent run https://github.com/CyanAutomation/crudmapper main
|
|
34
|
+
# Submit a task
|
|
35
|
+
kaseki-agent run https://github.com/CyanAutomation/crudmapper main \
|
|
36
|
+
"Add input validation to all POST endpoints"
|
|
47
37
|
```
|
|
48
38
|
|
|
49
|
-
###
|
|
50
|
-
|
|
51
|
-
If you prefer to avoid installing Node.js globally:
|
|
39
|
+
### 4. Monitor Results
|
|
52
40
|
|
|
53
41
|
```bash
|
|
54
|
-
#
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
42
|
+
# List all instances
|
|
43
|
+
kaseki-agent list
|
|
44
|
+
|
|
45
|
+
# Get detailed report
|
|
46
|
+
kaseki-agent report kaseki-1
|
|
59
47
|
|
|
60
|
-
#
|
|
61
|
-
|
|
62
|
-
-v ~/.kaseki/secrets:/secrets \
|
|
63
|
-
-v /var/run/docker.sock:/var/run/docker.sock \
|
|
64
|
-
docker.io/cyanautomation/kaseki-agent:latest \
|
|
65
|
-
run https://github.com/CyanAutomation/crudmapper main
|
|
48
|
+
# Live monitoring
|
|
49
|
+
kaseki-agent status kaseki-1
|
|
66
50
|
```
|
|
67
51
|
|
|
52
|
+
---
|
|
53
|
+
|
|
68
54
|
## Overview
|
|
69
55
|
|
|
70
|
-
|
|
56
|
+
Kaseki provides three deployment patterns:
|
|
71
57
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
58
|
+
- **NPM CLI**: Admin/helper workflows and task clients
|
|
59
|
+
- **Docker**: Containerized execution without host Node.js
|
|
60
|
+
- **REST API**: Local/distributed orchestration via `kaseki-agent serve`
|
|
75
61
|
|
|
76
|
-
|
|
62
|
+
Each task execution produces isolated workspace and results for reproducible AI coding workflows.
|
|
77
63
|
|
|
78
64
|
---
|
|
79
65
|
|
|
80
|
-
##
|
|
81
|
-
|
|
82
|
-
### Installation & Setup
|
|
83
|
-
|
|
84
|
-
#### Option A: Global NPM
|
|
66
|
+
## Installation
|
|
85
67
|
|
|
68
|
+
### Global NPM (Recommended)
|
|
86
69
|
```bash
|
|
87
70
|
npm install -g @cyanautomation/kaseki-agent
|
|
88
|
-
kaseki-agent setup
|
|
89
71
|
```
|
|
90
72
|
|
|
91
|
-
|
|
92
|
-
|
|
73
|
+
### Local NPM
|
|
93
74
|
```bash
|
|
94
75
|
npm install @cyanautomation/kaseki-agent
|
|
95
|
-
npx kaseki-agent
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
#### Option C: Docker
|
|
99
|
-
|
|
100
|
-
```bash
|
|
101
|
-
docker run -it \
|
|
102
|
-
-v ~/.kaseki/secrets:/secrets \
|
|
103
|
-
docker.io/cyanautomation/kaseki-agent:latest \
|
|
104
|
-
setup
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
### Verify Installation
|
|
108
|
-
|
|
109
|
-
```bash
|
|
110
|
-
kaseki-agent doctor
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
### Configure Authentication
|
|
114
|
-
|
|
115
|
-
Kaseki needs three sets of credentials. Choose your preferred setup method:
|
|
116
|
-
|
|
117
|
-
#### Option A: Config File (Recommended)
|
|
118
|
-
|
|
119
|
-
Create `~/.kaseki/config.json`:
|
|
120
|
-
|
|
121
|
-
```json
|
|
122
|
-
{
|
|
123
|
-
"auth": {
|
|
124
|
-
"openrouter_api_key_file": "/home/pi/secrets/openrouter_api_key",
|
|
125
|
-
"github_app_id_file": "/home/pi/secrets/github_app_id",
|
|
126
|
-
"github_app_client_id_file": "/home/pi/secrets/github_app_client_id",
|
|
127
|
-
"github_app_private_key_file": "/home/pi/secrets/github_app_private_key"
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
**Advantages:** Persistent, no `sudo -E` needed, works across runs.
|
|
133
|
-
|
|
134
|
-
#### Option B: Environment Variables
|
|
135
|
-
|
|
136
|
-
```bash
|
|
137
|
-
export OPENROUTER_API_KEY_FILE=/path/to/openrouter_key
|
|
138
|
-
export GITHUB_APP_ID_FILE=/path/to/github_app_id
|
|
139
|
-
export GITHUB_APP_CLIENT_ID_FILE=/path/to/github_app_client_id
|
|
140
|
-
export GITHUB_APP_PRIVATE_KEY_FILE=/path/to/github_app_private_key
|
|
141
|
-
|
|
142
|
-
# If using sudo, preserve env vars with -E flag
|
|
143
|
-
sudo -E env KASEKI_API_URL=http://localhost:8080/api kaseki-agent run ...
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
**Advantages:** Works for one-off runs, CI/CD pipelines.
|
|
147
|
-
|
|
148
|
-
#### Option C: Docker Compose
|
|
149
|
-
|
|
150
|
-
See [docs/DEPLOYMENT.md](docs/DEPLOYMENT.md) for setting up the kaseki-api service with Docker Compose (recommended for production).
|
|
151
|
-
|
|
152
|
-
**👉 Full guide:** [docs/AUTH_SETUP.md](docs/AUTH_SETUP.md)
|
|
153
|
-
|
|
154
|
-
### Run Your First API-Backed Task
|
|
155
|
-
|
|
156
|
-
Start or select a Kaseki API controller before using task commands:
|
|
157
|
-
|
|
158
|
-
```bash
|
|
159
|
-
# Local controller
|
|
160
|
-
KASEKI_API_KEYS=sk-dev kaseki-agent serve --port 8080
|
|
161
|
-
|
|
162
|
-
# Or remote controller
|
|
163
|
-
export KASEKI_API_URL=https://controller.example.com/api
|
|
164
|
-
export KASEKI_API_KEY=sk-your-kaseki-api-key
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
Then submit work through the API client:
|
|
168
|
-
|
|
169
|
-
```bash
|
|
170
|
-
# Simple example
|
|
171
|
-
KASEKI_API_KEY=sk-dev kaseki-agent run https://github.com/CyanAutomation/crudmapper main
|
|
172
|
-
|
|
173
|
-
# With custom task prompt
|
|
174
|
-
KASEKI_API_KEY=sk-dev kaseki-agent run https://github.com/CyanAutomation/crudmapper main \
|
|
175
|
-
"Fix the TypeScript errors in src/"
|
|
76
|
+
npx kaseki-agent init
|
|
176
77
|
```
|
|
177
78
|
|
|
178
|
-
###
|
|
179
|
-
|
|
79
|
+
### Docker
|
|
180
80
|
```bash
|
|
181
|
-
|
|
182
|
-
KASEKI_API_KEY=sk-dev kaseki-agent list
|
|
183
|
-
|
|
184
|
-
# View a specific API-backed instance
|
|
185
|
-
KASEKI_API_KEY=sk-dev kaseki-agent report kaseki-1
|
|
81
|
+
docker run -it docker.io/cyanautomation/kaseki-agent:latest init
|
|
186
82
|
```
|
|
187
83
|
|
|
188
84
|
---
|
|
189
85
|
|
|
190
|
-
##
|
|
191
|
-
|
|
192
|
-
#### `setup` — Interactive Configuration Wizard
|
|
193
|
-
|
|
194
|
-
First-time setup to validate environment and store API credentials securely.
|
|
195
|
-
|
|
196
|
-
```bash
|
|
197
|
-
kaseki-agent setup
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
**What it does:**
|
|
201
|
-
|
|
202
|
-
- Validates Docker installation and daemon
|
|
203
|
-
- Checks Node.js v24+ availability
|
|
204
|
-
- Validates git installation
|
|
205
|
-
- Prompts for OpenRouter API key (securely stored in keyring)
|
|
206
|
-
- Saves configuration (project-local or user-global)
|
|
207
|
-
- Runs doctor checks to verify everything works
|
|
208
|
-
|
|
209
|
-
#### `run` — Submit Agent Task Through the API
|
|
210
|
-
|
|
211
|
-
```bash
|
|
212
|
-
kaseki-agent run <REPO_URL> [GIT_REF] [TASK_PROMPT]
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
`run` is an API-backed client command. Start `kaseki-agent serve` locally first, or set `KASEKI_API_URL` to an existing controller. Set `KASEKI_API_KEY` when the service requires bearer authentication.
|
|
216
|
-
|
|
217
|
-
**Examples:**
|
|
218
|
-
|
|
219
|
-
```bash
|
|
220
|
-
# Local API service in another terminal
|
|
221
|
-
KASEKI_API_KEYS=sk-dev kaseki-agent serve --port 8080
|
|
222
|
-
|
|
223
|
-
# Simple API submission (uses main branch)
|
|
224
|
-
KASEKI_API_KEY=sk-dev kaseki-agent run https://github.com/CyanAutomation/crudmapper
|
|
225
|
-
|
|
226
|
-
# Remote controller
|
|
227
|
-
KASEKI_API_URL=https://controller.example.com/api \
|
|
228
|
-
KASEKI_API_KEY=sk-your-kaseki-api-key \
|
|
229
|
-
kaseki-agent run https://github.com/CyanAutomation/crudmapper develop
|
|
230
|
-
|
|
231
|
-
# With custom task prompt
|
|
232
|
-
KASEKI_API_KEY=sk-dev kaseki-agent run https://github.com/CyanAutomation/crudmapper main \
|
|
233
|
-
"Fix all TypeScript errors in src/"
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
**API Flow:**
|
|
237
|
-
|
|
238
|
-
1. Resolve the API base URL from `KASEKI_API_URL`, config `api.base_url`, or `http://localhost:8080/api`.
|
|
239
|
-
2. Include `Authorization: Bearer $KASEKI_API_KEY` when configured.
|
|
240
|
-
3. Submit the task to `POST /api/runs`.
|
|
241
|
-
4. Print the controller-provided run ID and status URL.
|
|
242
|
-
5. Use `status`, `list`, or `report` to inspect the API-backed run.
|
|
243
|
-
|
|
244
|
-
#### `doctor` — Health Check & Validation
|
|
245
|
-
|
|
246
|
-
```bash
|
|
247
|
-
kaseki-agent doctor [--json] [--fix]
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
**Checks:**
|
|
251
|
-
|
|
252
|
-
- Docker daemon availability
|
|
253
|
-
- Node.js v24+ validation
|
|
254
|
-
- npm availability
|
|
255
|
-
- git installation
|
|
256
|
-
- OpenRouter API key configuration
|
|
257
|
-
- Docker image status
|
|
258
|
-
- Disk space availability
|
|
259
|
-
|
|
260
|
-
**Options:**
|
|
261
|
-
|
|
262
|
-
- `--json` — JSON output (useful for scripts)
|
|
263
|
-
- `--fix` — Attempt auto-remediation (pull image, show install hints)
|
|
264
|
-
|
|
265
|
-
#### `list` — Show API-Known Instances
|
|
266
|
-
|
|
267
|
-
```bash
|
|
268
|
-
kaseki-agent list [--status STATE]
|
|
269
|
-
```
|
|
270
|
-
|
|
271
|
-
`list` reads the configured Kaseki API. It requires a local API service or `KASEKI_API_URL`; it does not scan local result directories.
|
|
272
|
-
|
|
273
|
-
**Filter by status:**
|
|
274
|
-
|
|
275
|
-
```bash
|
|
276
|
-
kaseki-agent list --status completed
|
|
277
|
-
kaseki-agent list --status failed
|
|
278
|
-
kaseki-agent list --status running
|
|
279
|
-
```
|
|
280
|
-
|
|
281
|
-
**Output:**
|
|
282
|
-
|
|
283
|
-
- Instance ID
|
|
284
|
-
- Status (running/completed/failed)
|
|
285
|
-
- Creation date
|
|
286
|
-
- Execution duration
|
|
287
|
-
|
|
288
|
-
#### `report` — View API-Backed Instance Results
|
|
289
|
-
|
|
290
|
-
```bash
|
|
291
|
-
kaseki-agent report <INSTANCE_ID>
|
|
292
|
-
```
|
|
293
|
-
|
|
294
|
-
By default, `report` reads status, analysis, artifact, and log endpoints from the configured API. Use `kaseki-agent report <INSTANCE_ID> --from-disk` only when intentionally inspecting local result files without an API.
|
|
295
|
-
|
|
296
|
-
**Shows:**
|
|
297
|
-
|
|
298
|
-
- Instance metadata (repo, branch, model, status)
|
|
299
|
-
- Execution stages with timing
|
|
300
|
-
- Final status and exit code
|
|
301
|
-
- Detailed summary (if available)
|
|
302
|
-
|
|
303
|
-
#### `status` — Poll API Run Status
|
|
304
|
-
|
|
305
|
-
```bash
|
|
306
|
-
kaseki-agent status <INSTANCE_ID> [--json]
|
|
307
|
-
```
|
|
308
|
-
|
|
309
|
-
`status` requires a local API service or configured `KASEKI_API_URL`.
|
|
310
|
-
|
|
311
|
-
#### `stop` / `cancel` — Cancel API-Backed Work
|
|
312
|
-
|
|
313
|
-
```bash
|
|
314
|
-
kaseki-agent stop <INSTANCE_ID>
|
|
315
|
-
kaseki-agent cancel <INSTANCE_ID>
|
|
316
|
-
```
|
|
317
|
-
|
|
318
|
-
Both commands call the configured API to cancel queued or running work.
|
|
319
|
-
|
|
320
|
-
#### `config` — Manage Configuration
|
|
321
|
-
|
|
322
|
-
```bash
|
|
323
|
-
kaseki-agent config <SUBCOMMAND> [OPTIONS]
|
|
324
|
-
```
|
|
325
|
-
|
|
326
|
-
**Subcommands:**
|
|
327
|
-
|
|
328
|
-
```bash
|
|
329
|
-
# Get a value
|
|
330
|
-
kaseki-agent config get agent.timeout_seconds
|
|
331
|
-
|
|
332
|
-
# Set a value (project-local)
|
|
333
|
-
kaseki-agent config set agent.timeout_seconds 1800
|
|
334
|
-
|
|
335
|
-
# Set globally
|
|
336
|
-
kaseki-agent config set agent.timeout_seconds 1800 --global
|
|
337
|
-
|
|
338
|
-
# Show active configuration
|
|
339
|
-
kaseki-agent config show
|
|
340
|
-
|
|
341
|
-
# Show available locations
|
|
342
|
-
kaseki-agent config locations
|
|
343
|
-
```
|
|
344
|
-
|
|
345
|
-
#### `secrets` — Manage Credentials
|
|
346
|
-
|
|
347
|
-
```bash
|
|
348
|
-
kaseki-agent secrets <SUBCOMMAND>
|
|
349
|
-
```
|
|
350
|
-
|
|
351
|
-
**Subcommands:**
|
|
352
|
-
|
|
353
|
-
```bash
|
|
354
|
-
# Initialize keyring
|
|
355
|
-
kaseki-agent secrets init
|
|
356
|
-
|
|
357
|
-
# Store a secret
|
|
358
|
-
kaseki-agent secrets set openrouter-api-key sk-or-...
|
|
359
|
-
|
|
360
|
-
# Retrieve (hidden by default)
|
|
361
|
-
kaseki-agent secrets get openrouter-api-key
|
|
362
|
-
|
|
363
|
-
# Show secret value
|
|
364
|
-
kaseki-agent secrets get openrouter-api-key --show
|
|
365
|
-
|
|
366
|
-
# Delete
|
|
367
|
-
kaseki-agent secrets delete openrouter-api-key
|
|
368
|
-
|
|
369
|
-
# List all keys
|
|
370
|
-
kaseki-agent secrets list
|
|
371
|
-
```
|
|
372
|
-
|
|
373
|
-
**Storage:**
|
|
374
|
-
|
|
375
|
-
- Linux: Uses `pass` (password-store) keyring
|
|
376
|
-
- Headless: Falls back to `~/.kaseki/secrets/` (0600 permissions)
|
|
86
|
+
## Basic Usage
|
|
377
87
|
|
|
378
|
-
|
|
88
|
+
### CLI Commands
|
|
89
|
+
- `kaseki-agent init` - Interactive setup wizard
|
|
90
|
+
- `kaseki-agent doctor` - Health check and diagnostics
|
|
91
|
+
- `kaseki-agent run [repo] [ref] [prompt]` - Execute coding task
|
|
92
|
+
- `kaseki-agent list` - List all instances
|
|
93
|
+
- `kaseki-agent report [instance]` - Detailed results
|
|
94
|
+
- `kaseki-agent status [instance]` - Live status monitoring
|
|
95
|
+
- `kaseki-agent serve` - Start local API service
|
|
379
96
|
|
|
97
|
+
### Task Execution
|
|
380
98
|
```bash
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
**Default port:** 8080
|
|
385
|
-
|
|
386
|
-
```bash
|
|
387
|
-
# Start on default port
|
|
388
|
-
kaseki-agent serve
|
|
99
|
+
# Basic task
|
|
100
|
+
kaseki-agent run https://github.com/owner/repo main "Fix TypeScript errors"
|
|
389
101
|
|
|
390
|
-
#
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
**Interactive API Documentation:**
|
|
102
|
+
# With custom API URL
|
|
103
|
+
KASEKI_API_URL=http://localhost:8080/api \
|
|
104
|
+
kaseki-agent run https://github.com/owner/repo main "Add unit tests"
|
|
395
105
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
```
|
|
399
|
-
http://localhost:8080/docs
|
|
106
|
+
# Monitor progress
|
|
107
|
+
kaseki-agent status kaseki-1 --follow
|
|
400
108
|
```
|
|
401
109
|
|
|
402
|
-
This provides an interactive interface to:
|
|
403
|
-
|
|
404
|
-
- Browse all endpoints organized by category
|
|
405
|
-
- View request/response schemas
|
|
406
|
-
- Test endpoints with "Try it out" feature
|
|
407
|
-
- Authorize with your API key
|
|
408
|
-
- Access the raw OpenAPI specification at `/api/openapi.json`
|
|
409
|
-
|
|
410
|
-
**API Endpoints:**
|
|
411
|
-
|
|
412
|
-
- `GET /health` — Service health check
|
|
413
|
-
- `GET /api/runs` — List instances
|
|
414
|
-
- `POST /api/runs` — Start new run
|
|
415
|
-
- `GET /api/runs/:id` — Get instance status
|
|
416
|
-
- `GET /api/runs/:id/logs` — Stream logs
|
|
417
|
-
- `GET /api/runs/:id/results` — Get results
|
|
418
|
-
|
|
419
|
-
For complete endpoint documentation, see [docs/API.md](docs/API.md).
|
|
420
|
-
|
|
421
110
|
---
|
|
422
111
|
|
|
423
112
|
## Configuration
|
|
424
113
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
3. **`~/.kaseki/config.json`** (user-global)
|
|
430
|
-
4. **Environment variables** (`KASEKI_*`, `OPENROUTER_*`, `GITHUB_*`)
|
|
431
|
-
5. **Built-in defaults**
|
|
432
|
-
|
|
433
|
-
### Example Configuration
|
|
434
|
-
|
|
435
|
-
**Example `kaseki-agent.json`:**
|
|
114
|
+
### Authentication
|
|
115
|
+
- **Config file** (recommended): `~/.kaseki/config.json`
|
|
116
|
+
- **Environment variables**: `OPENROUTER_API_KEY_FILE`, `GITHUB_APP_*_FILE`
|
|
117
|
+
- **Docker secrets**: Mount `/secrets` volume
|
|
436
118
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
"agent": {
|
|
440
|
-
"model": "openrouter/free",
|
|
441
|
-
"timeout_seconds": 10800
|
|
442
|
-
},
|
|
443
|
-
"validation": {
|
|
444
|
-
"allowlist": ["src/lib/", "tests/"],
|
|
445
|
-
"max_diff_bytes": 400000
|
|
446
|
-
},
|
|
447
|
-
"docker": {
|
|
448
|
-
"auto_pull": true
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
```
|
|
452
|
-
|
|
453
|
-
### Common Environment Variables
|
|
454
|
-
|
|
455
|
-
```bash
|
|
456
|
-
# Required
|
|
457
|
-
OPENROUTER_API_KEY_FILE=~/.kaseki/secrets/openrouter_api_key
|
|
119
|
+
### Environment Variables
|
|
120
|
+
See [docs/ENV_VARS.md](docs/ENV_VARS.md) for complete configuration reference.
|
|
458
121
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
# Optional worker/service settings
|
|
464
|
-
KASEKI_ROOT=/agents # Base directory
|
|
465
|
-
KASEKI_MODEL=openrouter/free # AI model
|
|
466
|
-
KASEKI_AGENT_TIMEOUT_SECONDS=10800 # Timeout
|
|
467
|
-
KASEKI_PRE_AGENT_VALIDATION=1 # Validate baseline before Pi
|
|
468
|
-
KASEKI_PRE_AGENT_VALIDATION_COMMANDS="npm run check;npm run test;npm run build"
|
|
469
|
-
KASEKI_VALIDATION_COMMANDS="npm run check;npm run test;npm run build" # Validate final diff after Pi
|
|
470
|
-
KASEKI_STARTUP_CHECK_MODE=boot # boot or baseline-validation for dry-run startup checks
|
|
471
|
-
```
|
|
122
|
+
### Deployment Options
|
|
123
|
+
- **Docker Compose**: Production deployment with persistent API
|
|
124
|
+
- **Single-run**: Ephemeral execution for CI/CD
|
|
125
|
+
- **Local API**: Development and testing
|
|
472
126
|
|
|
473
127
|
---
|
|
474
128
|
|
|
475
|
-
##
|
|
476
|
-
|
|
477
|
-
### Deployment Patterns
|
|
478
|
-
|
|
479
|
-
#### npm CLI (Admin Toolbox + API Client)
|
|
480
|
-
|
|
481
|
-
```bash
|
|
482
|
-
kaseki-agent doctor
|
|
483
|
-
kaseki-agent setup
|
|
484
|
-
kaseki-agent config show
|
|
485
|
-
kaseki-agent run <repo> <ref>
|
|
486
|
-
```
|
|
487
|
-
|
|
488
|
-
- Primary workflows: `doctor`, `setup`, `config`, and `secrets`
|
|
489
|
-
- Task workflows: `run`, `list`, `report`, `status`, and `stop`/`cancel` call the Kaseki API
|
|
490
|
-
- Best for: host setup, diagnostics, and submitting work to a local or remote controller
|
|
491
|
-
|
|
492
|
-
#### REST API (Distributed)
|
|
129
|
+
## API Reference
|
|
493
130
|
|
|
131
|
+
### REST API
|
|
132
|
+
Start local API service:
|
|
494
133
|
```bash
|
|
495
134
|
kaseki-agent serve --port 8080
|
|
496
|
-
# Then: POST /api/runs with repo/ref
|
|
497
|
-
```
|
|
498
|
-
|
|
499
|
-
- Long-running service
|
|
500
|
-
- Async execution
|
|
501
|
-
- Best for: Controllers, distributed systems
|
|
502
|
-
|
|
503
|
-
#### Docker (Self-Contained)
|
|
504
|
-
|
|
505
|
-
```bash
|
|
506
|
-
docker run docker.io/cyanautomation/kaseki-agent:latest run <repo> <ref>
|
|
507
135
|
```
|
|
508
136
|
|
|
509
|
-
|
|
510
|
-
-
|
|
511
|
-
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
**Host layer** — Management and orchestration:
|
|
516
|
-
|
|
517
|
-
- `run-kaseki.sh` — Direct runner (creates workspace, launches container, cleans up)
|
|
518
|
-
- `kaseki-activate.sh` — Remote activation entrypoint (install, deploy, run, status, clean)
|
|
519
|
-
- `kaseki-healthcheck.sh` — Host heartbeat and container status check
|
|
520
|
-
|
|
521
|
-
**Container layer** — Agent execution:
|
|
522
|
-
|
|
523
|
-
- `kaseki-agent.sh` — Inside the container (clones repo, installs deps, runs pre-agent validation, invokes Pi, runs post-agent validation, stores results)
|
|
524
|
-
- `entrypoint.sh` — Container startup orchestrator
|
|
137
|
+
### Programmatic Usage
|
|
138
|
+
- **Live monitoring**: Query running instances
|
|
139
|
+
- **Error detection**: Identify failures and anomalies
|
|
140
|
+
- **Post-run analysis**: Detailed result summaries
|
|
141
|
+
- **Log streaming**: Real-time log consumption
|
|
525
142
|
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
1. Clone the target repo/ref and install dependencies.
|
|
529
|
-
2. Run **pre-agent validation** when `KASEKI_PRE_AGENT_VALIDATION=1` (default). These commands default to `KASEKI_VALIDATION_COMMANDS` through `KASEKI_PRE_AGENT_VALIDATION_COMMANDS` and execute before Pi so Kaseki can detect an already-failing baseline. Inspect `/agents/kaseki-results/kaseki-N/pre-validation.log`, `/agents/kaseki-results/kaseki-N/pre-validation-raw.log`, `/agents/kaseki-results/kaseki-N/pre-validation-env.log`, and `/agents/kaseki-results/kaseki-N/pre-validation-timings.tsv`.
|
|
530
|
-
3. Run Pi in a **scouting** role after baseline validation. It inspects the task and repository without keeping workspace edits, then writes `/agents/kaseki-results/kaseki-N/scouting.json` for the coding agent to read. Set `KASEKI_SCOUTING=0` to skip this phase.
|
|
531
|
-
4. Invoke Pi in the coding role only if baseline validation and scouting succeed.
|
|
532
|
-
5. Restore disallowed changes, run quality gates, then run **post-agent validation** with `KASEKI_VALIDATION_COMMANDS` against the final diff. Inspect `/agents/kaseki-results/kaseki-N/validation.log`, `/agents/kaseki-results/kaseki-N/validation-raw.log`, `/agents/kaseki-results/kaseki-N/validation-env.log`, and `/agents/kaseki-results/kaseki-N/validation-timings.tsv`.
|
|
533
|
-
6. Record phase exit codes and failure reasons in `/agents/kaseki-results/kaseki-N/metadata.json`; `stage-timings.tsv` shows whether the failing phase was `pre-agent validation`, `pi scouting agent`, or `validation`.
|
|
534
|
-
|
|
535
|
-
> **Important:** `kaseki-agent.sh` runs from the Docker image (`/usr/local/bin/kaseki-agent`) and is **not** host-mounted during runs.
|
|
536
|
-
> For Direct CLI mode, the host needs `run-kaseki.sh` (plus `scripts/kaseki-preflight.sh`) and Docker access; the agent script itself stays inside the image.
|
|
537
|
-
|
|
538
|
-
### Supporting Utilities (Node.js)
|
|
539
|
-
|
|
540
|
-
- `pi-event-filter.js` — Filters raw Pi JSONL, strips thinking blocks, emits `pi-events.jsonl` + `pi-summary.json`
|
|
541
|
-
- `kaseki-report.js` — Reads a results directory and prints diagnostic report
|
|
542
|
-
- `kaseki-cli.js` + `kaseki-cli-lib.js` — Live monitoring CLI for external agents
|
|
543
|
-
- `kaseki-api-service.js` — REST API service for remote runs
|
|
544
|
-
- `kaseki-api-client.ts` — TypeScript client for integration
|
|
545
|
-
|
|
546
|
-
### Directory Layout at Runtime
|
|
547
|
-
|
|
548
|
-
```
|
|
549
|
-
/agents/kaseki-template/ # Dockerfile, scripts (this repo)
|
|
550
|
-
/agents/kaseki-agent/ # Checkout (source of truth for controllers)
|
|
551
|
-
/agents/kaseki-runs/kaseki-N/ # Per-run workspace (cloned repo, node_modules)
|
|
552
|
-
/agents/kaseki-results/kaseki-N/ # Artifacts (logs, diff, metadata, summary)
|
|
553
|
-
/agents/kaseki-cache/ # Optional host-level dependency cache (lockfile-first npm keys)
|
|
554
|
-
/cache/git/ # Optional host-mounted bare Git mirrors for target repos
|
|
555
|
-
```
|
|
143
|
+
See [docs/API.md](docs/API.md) and [docs/CLI.md](docs/CLI.md) for complete API and CLI documentation.
|
|
556
144
|
|
|
557
145
|
---
|
|
558
146
|
|
|
559
|
-
##
|
|
560
|
-
|
|
561
|
-
### Direct CLI (run-kaseki.sh)
|
|
562
|
-
|
|
563
|
-
Simplest single-run invocation on a host:
|
|
564
|
-
|
|
565
|
-
```bash
|
|
566
|
-
# Set API key via environment or file
|
|
567
|
-
OPENROUTER_API_KEY_FILE=~/secrets/openrouter_api_key \
|
|
568
|
-
./run-kaseki.sh https://github.com/org/repo main
|
|
569
|
-
```
|
|
147
|
+
## Architecture
|
|
570
148
|
|
|
571
|
-
|
|
149
|
+
Kaseki orchestrates ephemeral coding-agent instances with:
|
|
572
150
|
|
|
573
|
-
**Host
|
|
151
|
+
- **Host layer**: Workspace management, credential resolution, Docker runtime
|
|
152
|
+
- **Container layer**: Git cloning, dependency caching, Pi agent invocation
|
|
153
|
+
- **Result layer**: Artifact collection, validation gates, quality metrics
|
|
154
|
+
- **API layer**: REST service for external orchestration
|
|
574
155
|
|
|
575
|
-
|
|
576
|
-
-
|
|
577
|
-
-
|
|
156
|
+
Each run produces isolated workspace with:
|
|
157
|
+
- Repository clone at target ref
|
|
158
|
+
- Node.js dependency cache
|
|
159
|
+
- Pi agent execution
|
|
160
|
+
- Validation and quality gates
|
|
161
|
+
- Comprehensive result artifacts
|
|
578
162
|
|
|
579
163
|
---
|
|
580
164
|
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
For SSH/controller-driven setup and execution. Used by OpenClaw and similar orchestrators.
|
|
584
|
-
|
|
585
|
-
#### Bootstrap a Remote Host
|
|
586
|
-
|
|
587
|
-
```bash
|
|
588
|
-
# Single SSH command to bootstrap a Pi (install, deploy, doctor)
|
|
589
|
-
ssh pi@192.168.1.100 'tmp=$(mktemp) && \
|
|
590
|
-
curl -fsSL https://raw.githubusercontent.com/CyanAutomation/kaseki-agent/main/scripts/kaseki-install.sh -o "$tmp" && \
|
|
591
|
-
KASEKI_CONTROLLER_MODE=1 sh "$tmp"'
|
|
592
|
-
```
|
|
593
|
-
|
|
594
|
-
Controller bootstrap can install, deploy, and run host diagnostics without an
|
|
595
|
-
OpenRouter key. Actual `run` commands still require `OPENROUTER_API_KEY` or
|
|
596
|
-
`OPENROUTER_API_KEY_FILE`, unless the API container provides the key for
|
|
597
|
-
HTTP-triggered runs.
|
|
598
|
-
|
|
599
|
-
If the host has never run Kaseki before, run the host setup helper first. It
|
|
600
|
-
creates the expected `/agents` directories, verifies writable results storage,
|
|
601
|
-
and bootstraps the template when the checkout is present. It also runs a checkout-freshness probe using the same runtime UID/GID as API preflight, so setup can fail early if `/agents/kaseki-agent/.git` is not readable:
|
|
602
|
-
|
|
603
|
-
```bash
|
|
604
|
-
ssh pi@192.168.1.100 'tmp=$(mktemp) && curl -fsSL https://raw.githubusercontent.com/CyanAutomation/kaseki-agent/main/scripts/kaseki-install.sh -o "$tmp" && KASEKI_CONTROLLER_MODE=1 sh "$tmp"'
|
|
605
|
-
ssh pi@192.168.1.100 '/agents/kaseki-agent/scripts/kaseki-setup-host.sh --fix'
|
|
606
|
-
```
|
|
607
|
-
|
|
608
|
-
If checkout freshness fails, remediation is now specific to the failure mode:
|
|
609
|
-
|
|
610
|
-
- `.git` access failures (for example: `permission denied`, `not a git repository`,
|
|
611
|
-
or inaccessible `.git`) keep permission-focused remediation.
|
|
612
|
-
- UID/GID impersonation failures (for example: unknown user/group or `sudo`/`runuser`
|
|
613
|
-
invocation errors) return remediation that asks you to configure a valid way to
|
|
614
|
-
execute as UID:GID `10000:10000` (or provide passwd/group mappings), then rerun setup.
|
|
615
|
-
|
|
616
|
-
#### Local Activation (No SSH)
|
|
617
|
-
|
|
618
|
-
```bash
|
|
619
|
-
cd /agents/kaseki-agent
|
|
620
|
-
|
|
621
|
-
# Bootstrap: install, deploy, doctor
|
|
622
|
-
./scripts/kaseki-activate.sh --controller bootstrap
|
|
623
|
-
|
|
624
|
-
# Install checkout only
|
|
625
|
-
KASEKI_REPO_URL=https://github.com/org/repo \
|
|
626
|
-
./scripts/kaseki-activate.sh install
|
|
627
|
-
|
|
628
|
-
# Deploy template
|
|
629
|
-
./scripts/kaseki-activate.sh deploy
|
|
630
|
-
|
|
631
|
-
# Health check
|
|
632
|
-
./scripts/kaseki-activate.sh doctor
|
|
633
|
-
|
|
634
|
-
# First-run host setup/repair
|
|
635
|
-
./scripts/kaseki-setup-host.sh --fix
|
|
636
|
-
|
|
637
|
-
# Run a task
|
|
638
|
-
TASK_PROMPT='Fix the bug in parser.ts' \
|
|
639
|
-
OPENROUTER_API_KEY_FILE=~/secrets/openrouter_api_key \
|
|
640
|
-
./scripts/kaseki-activate.sh run https://github.com/org/repo main
|
|
641
|
-
```
|
|
642
|
-
|
|
643
|
-
#### Machine-Readable Output
|
|
644
|
-
|
|
645
|
-
For controller integration, use `--json` or `--jsonl`:
|
|
646
|
-
|
|
647
|
-
```bash
|
|
648
|
-
./scripts/kaseki-activate.sh --json doctor
|
|
649
|
-
|
|
650
|
-
./scripts/kaseki-activate.sh --json run https://github.com/org/repo main
|
|
651
|
-
```
|
|
652
|
-
|
|
653
|
-
Returns newline-delimited JSON for each major step.
|
|
654
|
-
|
|
655
|
-
**When to use:** Controller-driven setup, multi-host management, integration with orchestrators.
|
|
165
|
+
## Resources
|
|
656
166
|
|
|
657
|
-
|
|
167
|
+
### Documentation
|
|
168
|
+
- [Quick Start Guide](docs/QUICK_START.md) - Step-by-step setup
|
|
169
|
+
- [CLI Reference](docs/CLI.md) - Command-line monitoring tools
|
|
170
|
+
- [API Documentation](docs/API.md) - REST API specification
|
|
171
|
+
- [Deployment Guide](docs/DEPLOYMENT.md) - Production deployment
|
|
172
|
+
- [Environment Variables](docs/ENV_VARS.md) - Configuration reference
|
|
173
|
+
- [Advanced Configuration](docs/ADVANCED_CONFIG.md) - Detailed setup options
|
|
174
|
+
- [Troubleshooting](docs/TROUBLESHOOTING.md) - Common issues and solutions
|
|
658
175
|
|
|
659
|
-
|
|
660
|
-
-
|
|
661
|
-
-
|
|
662
|
-
-
|
|
663
|
-
- Comprehensive logging to `$KASEKI_LOG_DIR`
|
|
176
|
+
### Community
|
|
177
|
+
- **Issues**: [GitHub Issues](https://github.com/CyanAutomation/kaseki-agent/issues)
|
|
178
|
+
- **Discussions**: GitHub Discussions
|
|
179
|
+
- **Updates**: Follow for releases and announcements
|
|
664
180
|
|
|
665
181
|
---
|
|
666
182
|
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
Long-running async orchestration service. Ideal for:
|
|
670
|
-
|
|
671
|
-
- **OpenClaw** and similar AI orchestrators
|
|
672
|
-
- **Distributed agents** that need to queue and poll runs
|
|
673
|
-
- **Multi-user environments** with authentication
|
|
674
|
-
- **Webhook integration** and external monitoring
|
|
675
|
-
|
|
676
|
-
#### Quick Start
|
|
677
|
-
|
|
678
|
-
```bash
|
|
679
|
-
# Option A: Docker Compose (Recommended)
|
|
680
|
-
cd /agents/kaseki-template
|
|
681
|
-
export KASEKI_API_KEYS=sk-your-secret-key
|
|
682
|
-
docker build -t kaseki-agent:latest .
|
|
683
|
-
docker-compose up -d
|
|
684
|
-
|
|
685
|
-
# Option B: Node.js Process
|
|
686
|
-
npm install
|
|
687
|
-
KASEKI_API_KEYS=sk-your-secret-key npm run kaseki-api
|
|
688
|
-
|
|
689
|
-
# Option C: Docker directly
|
|
690
|
-
docker run -d --name kaseki-api \
|
|
691
|
-
-p 8080:8080 \
|
|
692
|
-
-e KASEKI_API_KEYS=sk-your-secret-key \
|
|
693
|
-
-v /agents:/agents:rw \
|
|
694
|
-
-v /var/run/docker.sock:/var/run/docker.sock \
|
|
695
|
-
docker.io/:latest api
|
|
696
|
-
|
|
697
|
-
# Option D: systemd Service
|
|
698
|
-
sudo cp scripts/kaseki-api.service /etc/systemd/system/
|
|
699
|
-
sudo systemctl start kaseki-api
|
|
700
|
-
```
|
|
701
|
-
|
|
702
|
-
#### Trigger a Run
|
|
703
|
-
|
|
704
|
-
```bash
|
|
705
|
-
curl -X POST http://localhost:8080/api/runs \
|
|
706
|
-
-H "Authorization: Bearer sk-your-secret-key" \
|
|
707
|
-
-H "Content-Type: application/json" \
|
|
708
|
-
-d '{
|
|
709
|
-
"repoUrl": "https://github.com/org/repo",
|
|
710
|
-
"taskPrompt": "Fix the parser bug",
|
|
711
|
-
"changedFilesAllowlist": ["src/lib/parser.ts"],
|
|
712
|
-
"allowlist": { "include": ["src/lib/parser.ts"] },
|
|
713
|
-
"scouting": { "enabled": true, "model": "openrouter/free", "timeoutSeconds": 900 },
|
|
714
|
-
// Omit "scouting" to use the default enabled behavior; set enabled=false to disable explicitly.
|
|
715
|
-
"validationCommands": ["npm run test", "npm run build"],
|
|
716
|
-
"validation": { "commands": ["npm run test", "npm run build"] }
|
|
717
|
-
}'
|
|
718
|
-
|
|
719
|
-
# Returns: {"id":"kaseki-42","status":"queued","createdAt":"2026-05-02T..."}
|
|
720
|
-
```
|
|
721
|
-
|
|
722
|
-
#### Poll Status
|
|
723
|
-
|
|
724
|
-
```bash
|
|
725
|
-
curl -H "Authorization: Bearer sk-your-secret-key" \
|
|
726
|
-
http://localhost:8080/api/runs/kaseki-42/status
|
|
727
|
-
|
|
728
|
-
# Returns: {"id":"kaseki-42","status":"running","elapsedSeconds":45,"timeoutRiskPercent":4,...}
|
|
729
|
-
```
|
|
730
|
-
|
|
731
|
-
#### Download Results
|
|
732
|
-
|
|
733
|
-
```bash
|
|
734
|
-
curl -H "Authorization: Bearer sk-your-secret-key" \
|
|
735
|
-
http://localhost:8080/api/results/kaseki-42/git.diff -o patch.diff
|
|
736
|
-
|
|
737
|
-
curl -H "Authorization: Bearer sk-your-secret-key" \
|
|
738
|
-
http://localhost:8080/api/runs/kaseki-42/analysis | jq '.'
|
|
739
|
-
```
|
|
740
|
-
|
|
741
|
-
#### Key Endpoints
|
|
742
|
-
|
|
743
|
-
| Method | Endpoint | Purpose |
|
|
744
|
-
|--------|----------|---------|
|
|
745
|
-
| `GET` | `/health` | No-auth health check |
|
|
746
|
-
| `POST` | `/api/runs` | Submit a new task |
|
|
747
|
-
| `GET` | `/api/runs` | List recent runs |
|
|
748
|
-
| `GET` | `/api/runs/:id/status` | Poll run status |
|
|
749
|
-
| `GET` | `/api/runs/:id/progress` | Fetch progress events |
|
|
750
|
-
| `POST` | `/api/runs/:id/cancel` | Cancel queued/running job |
|
|
751
|
-
| `GET` | `/api/runs/:id/analysis` | Comprehensive summary |
|
|
752
|
-
| `GET` | `/api/results/:id/:file` | Download artifact (diff, metadata) |
|
|
753
|
-
|
|
754
|
-
**Full API documentation:** See [docs/API.md](docs/API.md)
|
|
755
|
-
**Deployment guide:** See [docs/DEPLOYMENT.md](docs/DEPLOYMENT.md)
|
|
756
|
-
|
|
757
|
-
**When to use:** Distributed orchestration, external controller integration, multi-user scenarios.
|
|
758
|
-
|
|
759
|
-
---
|
|
760
|
-
|
|
761
|
-
## Common Commands
|
|
762
|
-
|
|
763
|
-
### Direct CLI
|
|
764
|
-
|
|
765
|
-
```bash
|
|
766
|
-
# Basic run (auto-generates kaseki-N)
|
|
767
|
-
OPENROUTER_API_KEY=sk-or-... ./run-kaseki.sh
|
|
768
|
-
|
|
769
|
-
# Explicit instance and repo
|
|
770
|
-
OPENROUTER_API_KEY=sk-or-... ./run-kaseki.sh https://github.com/org/repo feature/branch kaseki-7
|
|
771
|
-
|
|
772
|
-
# API key via secret file
|
|
773
|
-
OPENROUTER_API_KEY_FILE=~/secrets/openrouter_api_key ./run-kaseki.sh
|
|
774
|
-
|
|
775
|
-
# Health/sanity check after deploying the host template
|
|
776
|
-
/agents/kaseki-template/run-kaseki.sh --doctor
|
|
777
|
-
|
|
778
|
-
# Build image locally
|
|
779
|
-
docker build -t kaseki-template:latest .
|
|
780
|
-
|
|
781
|
-
# Generate diagnostic report
|
|
782
|
-
docker run --rm --entrypoint kaseki-report \
|
|
783
|
-
-v /agents/kaseki-results/kaseki-4:/results:ro \
|
|
784
|
-
kaseki-template:latest /results
|
|
785
|
-
```
|
|
786
|
-
|
|
787
|
-
### Remote Activation
|
|
788
|
-
|
|
789
|
-
```bash
|
|
790
|
-
cd /agents/kaseki-agent
|
|
791
|
-
|
|
792
|
-
# Bootstrap remote host via SSH
|
|
793
|
-
ssh pi@host 'curl -fsSL https://raw.githubusercontent.com//main/scripts/kaseki-install.sh | KASEKI_CONTROLLER_MODE=1 sh'
|
|
794
|
-
|
|
795
|
-
# Or locally after cloning
|
|
796
|
-
OPENROUTER_API_KEY_FILE=~/secrets/openrouter_api_key \
|
|
797
|
-
./scripts/kaseki-activate.sh --controller bootstrap
|
|
798
|
-
|
|
799
|
-
# Status check
|
|
800
|
-
./scripts/kaseki-activate.sh status
|
|
801
|
-
|
|
802
|
-
# Run with task
|
|
803
|
-
TASK_PROMPT='Make the requested change' \
|
|
804
|
-
OPENROUTER_API_KEY_FILE=~/secrets/openrouter_api_key \
|
|
805
|
-
./scripts/kaseki-activate.sh run https://github.com/org/repo main
|
|
806
|
-
|
|
807
|
-
# Inspect mode (no diff required)
|
|
808
|
-
KASEKI_TASK_MODE=inspect \
|
|
809
|
-
TASK_PROMPT='Analyze the repo' \
|
|
810
|
-
OPENROUTER_API_KEY_FILE=~/secrets/openrouter_api_key \
|
|
811
|
-
./scripts/kaseki-activate.sh --json run https://github.com/org/repo main
|
|
812
|
-
```
|
|
813
|
-
|
|
814
|
-
### REST API Service
|
|
815
|
-
|
|
816
|
-
```bash
|
|
817
|
-
# Start service
|
|
818
|
-
KASEKI_API_KEYS=sk-dev npm run kaseki-api
|
|
819
|
-
|
|
820
|
-
# In another terminal:
|
|
821
|
-
curl http://localhost:8080/health
|
|
822
|
-
|
|
823
|
-
curl -H "Authorization: Bearer sk-dev" \
|
|
824
|
-
http://localhost:8080/api/preflight
|
|
825
|
-
|
|
826
|
-
curl -X POST http://localhost:8080/api/runs \
|
|
827
|
-
-H "Authorization: Bearer sk-dev" \
|
|
828
|
-
-H "Content-Type: application/json" \
|
|
829
|
-
-d '{"repoUrl":"https://github.com/org/repo","taskPrompt":"Fix bug"}'
|
|
830
|
-
```
|
|
831
|
-
|
|
832
|
-
---
|
|
833
|
-
|
|
834
|
-
## Deploying the Kaseki API Service
|
|
835
|
-
|
|
836
|
-
### ✅ Recommended: Docker Compose
|
|
837
|
-
|
|
838
|
-
```bash
|
|
839
|
-
cd /agents/kaseki-template
|
|
840
|
-
|
|
841
|
-
# Build image
|
|
842
|
-
docker build -t kaseki-agent:latest .
|
|
843
|
-
|
|
844
|
-
# Set API key and start
|
|
845
|
-
export KASEKI_API_KEYS=sk-your-secret-key
|
|
846
|
-
docker-compose up -d
|
|
847
|
-
|
|
848
|
-
# Monitor logs
|
|
849
|
-
docker-compose logs -f kaseki-api
|
|
850
|
-
|
|
851
|
-
# Stop services
|
|
852
|
-
docker-compose down
|
|
853
|
-
```
|
|
854
|
-
|
|
855
|
-
**Features:**
|
|
856
|
-
|
|
857
|
-
- Health checks included
|
|
858
|
-
- Authenticated `/api/preflight` controller readiness diagnostics
|
|
859
|
-
- Log aggregation
|
|
860
|
-
- Volume management for results
|
|
861
|
-
- Automatic restart on host reboot
|
|
862
|
-
|
|
863
|
-
### Alternative: systemd Service
|
|
864
|
-
|
|
865
|
-
```bash
|
|
866
|
-
# 1. Install service file
|
|
867
|
-
sudo cp scripts/kaseki-api.service /etc/systemd/system/
|
|
868
|
-
|
|
869
|
-
# 2. Create environment file
|
|
870
|
-
sudo mkdir -p /etc/kaseki-api
|
|
871
|
-
sudo tee /etc/kaseki-api/kaseki-api.env << EOF
|
|
872
|
-
KASEKI_API_KEYS=sk-your-secret-key
|
|
873
|
-
KASEKI_API_PORT=8080
|
|
874
|
-
KASEKI_RESULTS_DIR=/agents/kaseki-results
|
|
875
|
-
EOF
|
|
876
|
-
sudo chmod 600 /etc/kaseki-api/kaseki-api.env
|
|
877
|
-
|
|
878
|
-
# 3. Start service
|
|
879
|
-
sudo systemctl enable kaseki-api
|
|
880
|
-
sudo systemctl start kaseki-api
|
|
881
|
-
|
|
882
|
-
# 4. Monitor
|
|
883
|
-
sudo journalctl -u kaseki-api -f
|
|
884
|
-
```
|
|
885
|
-
|
|
886
|
-
### Fallback: Node.js Process
|
|
887
|
-
|
|
888
|
-
```bash
|
|
889
|
-
npm install
|
|
890
|
-
KASEKI_API_KEYS=sk-your-secret-key npm run kaseki-api
|
|
891
|
-
```
|
|
892
|
-
|
|
893
|
-
**Full deployment options:** See [docs/DEPLOYMENT.md](docs/DEPLOYMENT.md)
|
|
894
|
-
|
|
895
|
-
---
|
|
896
|
-
|
|
897
|
-
## TypeScript Debt Status
|
|
898
|
-
|
|
899
|
-
Full-project TypeScript checks (`npm run type-check` / `npm run type-check:full`) may surface known unrelated errors while debt burn-down is in progress.
|
|
900
|
-
|
|
901
|
-
For pull requests, `npm run type-check:changed` is the blocking gate.
|
|
902
|
-
|
|
903
|
-
Track and prioritize debt items in [docs/BACKLOG.md](docs/BACKLOG.md).
|
|
904
|
-
|
|
905
|
-
---
|
|
906
|
-
|
|
907
|
-
## Required Host Dependencies
|
|
908
|
-
|
|
909
|
-
`run-kaseki.sh` and `kaseki-activate.sh` validate host binaries via preflight check.
|
|
910
|
-
|
|
911
|
-
**Required:**
|
|
912
|
-
|
|
913
|
-
- `docker`
|
|
914
|
-
|
|
915
|
-
**Optional (validated and reported in `--doctor`):**
|
|
916
|
-
|
|
917
|
-
- `wget`
|
|
918
|
-
- `sshpass`
|
|
919
|
-
- `git`
|
|
920
|
-
- `node`
|
|
921
|
-
- `npm`
|
|
922
|
-
|
|
923
|
-
### Installation
|
|
924
|
-
|
|
925
|
-
**Debian/Ubuntu/Raspberry Pi OS:**
|
|
926
|
-
|
|
927
|
-
```bash
|
|
928
|
-
sudo apt update
|
|
929
|
-
sudo apt install -y wget sshpass docker.io git nodejs npm
|
|
930
|
-
sudo usermod -aG docker $USER && newgrp docker
|
|
931
|
-
```
|
|
932
|
-
|
|
933
|
-
**Fedora/RHEL/CentOS Stream:**
|
|
934
|
-
|
|
935
|
-
```bash
|
|
936
|
-
sudo dnf install -y wget sshpass docker git nodejs npm
|
|
937
|
-
sudo usermod -aG docker $USER && newgrp docker
|
|
938
|
-
```
|
|
939
|
-
|
|
940
|
-
**Arch Linux:**
|
|
941
|
-
|
|
942
|
-
```bash
|
|
943
|
-
sudo pacman -S --needed wget sshpass docker git nodejs npm
|
|
944
|
-
sudo usermod -aG docker $USER && newgrp docker
|
|
945
|
-
```
|
|
946
|
-
|
|
947
|
-
---
|
|
948
|
-
|
|
949
|
-
## Host Logging and Log Rotation
|
|
950
|
-
|
|
951
|
-
Kaseki scripts support mirrored host logs via `KASEKI_LOG_DIR` (default: `/var/log/kaseki`):
|
|
952
|
-
|
|
953
|
-
- `run-kaseki.sh` writes `run-kaseki-<instance>-<timestamp>.log`
|
|
954
|
-
- `kaseki-activate.sh` writes `kaseki-activate-<timestamp>.log`
|
|
955
|
-
- `deploy-pi-template.sh` writes `deploy-pi-template-<timestamp>.log`
|
|
956
|
-
- `cleanup-kaseki.sh` writes `cleanup-kaseki-<timestamp>.log`
|
|
957
|
-
- `kaseki-healthcheck.sh` writes a JSON heartbeat file (`/var/log/kaseki/heartbeat.json`)
|
|
958
|
-
- `kaseki-agent.sh` keeps `/results/stdout.log` and `/results/stderr.log` in container artifacts
|
|
959
|
-
|
|
960
|
-
### Recommended Host Setup
|
|
961
|
-
|
|
962
|
-
```bash
|
|
963
|
-
sudo mkdir -p /var/log/kaseki
|
|
964
|
-
sudo chown root:adm /var/log/kaseki
|
|
965
|
-
sudo chmod 0750 /var/log/kaseki
|
|
966
|
-
```
|
|
967
|
-
|
|
968
|
-
### Strict Mode
|
|
969
|
-
|
|
970
|
-
Set `KASEKI_STRICT_HOST_LOGGING=1` to fail fast when `KASEKI_LOG_DIR` cannot be created or written. Leave unset (or `0`) for graceful degradation.
|
|
971
|
-
|
|
972
|
-
### Log Rotation
|
|
973
|
-
|
|
974
|
-
```bash
|
|
975
|
-
sudo install -m 0644 /agents/kaseki-template/ops/logrotate/kaseki /etc/logrotate.d/kaseki
|
|
976
|
-
sudo logrotate -d /etc/logrotate.d/kaseki
|
|
977
|
-
```
|
|
978
|
-
|
|
979
|
-
---
|
|
980
|
-
|
|
981
|
-
## Heartbeat Healthcheck
|
|
982
|
-
|
|
983
|
-
Use `kaseki-healthcheck.sh` to write a single JSON heartbeat object per run:
|
|
984
|
-
|
|
985
|
-
```bash
|
|
986
|
-
# Write to default target
|
|
987
|
-
/agents/kaseki-template/kaseki-healthcheck.sh
|
|
988
|
-
|
|
989
|
-
# Custom file
|
|
990
|
-
KASEKI_HEARTBEAT_FILE=/tmp/kaseki-heartbeat.json /agents/kaseki-template/kaseki-healthcheck.sh
|
|
991
|
-
|
|
992
|
-
# Disable container status check
|
|
993
|
-
KASEKI_HEALTHCHECK_CONTAINERS=0 /agents/kaseki-template/kaseki-healthcheck.sh
|
|
994
|
-
```
|
|
995
|
-
|
|
996
|
-
### Cron Setup
|
|
997
|
-
|
|
998
|
-
```cron
|
|
999
|
-
*/5 * * * * /agents/kaseki-template/kaseki-healthcheck.sh >/dev/null 2>&1
|
|
1000
|
-
```
|
|
1001
|
-
|
|
1002
|
-
### systemd Timer
|
|
1003
|
-
|
|
1004
|
-
```ini
|
|
1005
|
-
# /etc/systemd/system/kaseki-healthcheck.service
|
|
1006
|
-
[Unit]
|
|
1007
|
-
Description=Kaseki heartbeat healthcheck
|
|
1008
|
-
|
|
1009
|
-
[Service]
|
|
1010
|
-
Type=oneshot
|
|
1011
|
-
ExecStart=/agents/kaseki-template/kaseki-healthcheck.sh
|
|
1012
|
-
```
|
|
1013
|
-
|
|
1014
|
-
```ini
|
|
1015
|
-
# /etc/systemd/system/kaseki-healthcheck.timer
|
|
1016
|
-
[Unit]
|
|
1017
|
-
Description=Run Kaseki heartbeat healthcheck every 5 minutes
|
|
1018
|
-
|
|
1019
|
-
[Timer]
|
|
1020
|
-
OnBootSec=2min
|
|
1021
|
-
OnUnitActiveSec=5min
|
|
1022
|
-
Unit=kaseki-healthcheck.service
|
|
1023
|
-
|
|
1024
|
-
[Install]
|
|
1025
|
-
WantedBy=timers.target
|
|
1026
|
-
```
|
|
1027
|
-
|
|
1028
|
-
```bash
|
|
1029
|
-
sudo systemctl daemon-reload
|
|
1030
|
-
sudo systemctl enable --now kaseki-healthcheck.timer
|
|
1031
|
-
```
|
|
1032
|
-
|
|
1033
|
-
---
|
|
1034
|
-
|
|
1035
|
-
## Image Registries
|
|
1036
|
-
|
|
1037
|
-
**Docker Hub** (recommended):
|
|
1038
|
-
|
|
1039
|
-
```bash
|
|
1040
|
-
docker pull docker.io/:latest
|
|
1041
|
-
```
|
|
1042
|
-
|
|
1043
|
-
**GitHub Container Registry**:
|
|
1044
|
-
|
|
1045
|
-
```bash
|
|
1046
|
-
docker pull ghcr.io/:latest
|
|
1047
|
-
```
|
|
1048
|
-
|
|
1049
|
-
Both are equivalent and receive identical multi-architecture builds for `linux/amd64` and `linux/arm64`.
|
|
1050
|
-
|
|
1051
|
-
### Releasing a New Version
|
|
1052
|
-
|
|
1053
|
-
Releases are fully automated using **semantic-release** and **conventional commits**. Versions are determined automatically based on commit messages.
|
|
1054
|
-
|
|
1055
|
-
**Prerequisites:**
|
|
1056
|
-
|
|
1057
|
-
- All recent commits on `main` follow [conventional commit](CONTRIBUTING.md#6-release-process-and-conventional-commits) format (`feat:`, `fix:`, `chore:`, etc.)
|
|
1058
|
-
- CI/CD checks are passing on `main`
|
|
1059
|
-
|
|
1060
|
-
**Release via GitHub Actions (Recommended):**
|
|
1061
|
-
|
|
1062
|
-
1. Go to the [Actions](https://github.com/CyanAutomation/kaseki-agent/actions) tab → **Release** workflow
|
|
1063
|
-
2. Click **Run workflow**
|
|
1064
|
-
3. Optionally check "Dry-run" to preview without creating tags
|
|
1065
|
-
4. Click **Run workflow**
|
|
1066
|
-
5. The workflow automatically:
|
|
1067
|
-
- Analyzes commits since last release
|
|
1068
|
-
- Determines version bump (major/minor/patch)
|
|
1069
|
-
- Updates `package.json` and `CHANGELOG.md`
|
|
1070
|
-
- Creates GitHub Release with release notes
|
|
1071
|
-
- Triggers Docker multi-arch builds and publishes to registries
|
|
1072
|
-
6. Monitor in Actions tab; verify in [Releases](https://github.com/CyanAutomation/kaseki-agent/releases)
|
|
1073
|
-
|
|
1074
|
-
**Release via Local Command (Alternative):**
|
|
1075
|
-
|
|
1076
|
-
```bash
|
|
1077
|
-
npm run release:dry # Preview (optional)
|
|
1078
|
-
npm run release # Create release
|
|
1079
|
-
```
|
|
1080
|
-
|
|
1081
|
-
See [CONTRIBUTING.md § Release Process](CONTRIBUTING.md#6-release-process-and-conventional-commits) for detailed commit format guidelines and options.
|
|
1082
|
-
|
|
1083
|
-
### Tag Publishing Schedule
|
|
1084
|
-
|
|
1085
|
-
- **Stable version tags** (e.g., `0.1.0`): Published once via version tag push; never overwritten
|
|
1086
|
-
- **`latest` tag**: Updated on every merge to `main`, every version push, and weekly Sunday 00:00 UTC
|
|
1087
|
-
- **Commit tags** (e.g., `main-3278b67abcd1`): Published on every merge to `main`
|
|
1088
|
-
|
|
1089
|
-
**Production guidance:** Pin a stable tag once verified, or use a `main-<sha>` tag for reproducibility.
|
|
1090
|
-
|
|
1091
|
-
### Local Fallback Build
|
|
1092
|
-
|
|
1093
|
-
```bash
|
|
1094
|
-
cd /agents/kaseki-template
|
|
1095
|
-
docker build -t kaseki-template:latest .
|
|
1096
|
-
KASEKI_IMAGE=kaseki-template:latest OPENROUTER_API_KEY_FILE=~/secrets/openrouter_api_key ./run-kaseki.sh --doctor
|
|
1097
|
-
```
|
|
1098
|
-
|
|
1099
|
-
For readable logs over SSH on a Pi:
|
|
1100
|
-
|
|
1101
|
-
```bash
|
|
1102
|
-
docker build --progress=plain -t kaseki-template:latest .
|
|
1103
|
-
```
|
|
1104
|
-
|
|
1105
|
-
---
|
|
1106
|
-
|
|
1107
|
-
## Deployment and Installation
|
|
1108
|
-
|
|
1109
|
-
### Deploy to Host Template Directory
|
|
1110
|
-
|
|
1111
|
-
Use `scripts/deploy-pi-template.sh` to idempotently install the runnable Kaseki template on a host:
|
|
1112
|
-
|
|
1113
|
-
```bash
|
|
1114
|
-
cd /path/to/kaseki-agent
|
|
1115
|
-
sudo ./scripts/deploy-pi-template.sh
|
|
1116
|
-
|
|
1117
|
-
# Optional: override destination (must match guardrails: under /agents/ or $HOME/)
|
|
1118
|
-
sudo KASEKI_TEMPLATE_DIR=~/kaseki-template ./scripts/deploy-pi-template.sh
|
|
1119
|
-
```
|
|
1120
|
-
|
|
1121
|
-
**Guardrails:**
|
|
1122
|
-
|
|
1123
|
-
- Destination must end with `kaseki-template` and be under `/agents/` or `$HOME/`
|
|
1124
|
-
- Existing `run`, `result`, `cache`, and `secrets` directories are preserved
|
|
1125
|
-
- Destination root is deleted and recreated before install
|
|
1126
|
-
|
|
1127
|
-
**Workflow:**
|
|
1128
|
-
|
|
1129
|
-
1. Pulls `KASEKI_IMAGE` by default
|
|
1130
|
-
2. Verifies image contains `/app` template
|
|
1131
|
-
3. Falls back to building from current checkout if registry image is stale or unavailable
|
|
1132
|
-
4. Records selected image and digest in `.kaseki-image` and `.kaseki-image-digest`
|
|
1133
|
-
`.kaseki-image` preserves the configured ref such as `docker.io/cyanautomation/kaseki-agent:latest`,
|
|
1134
|
-
while `.kaseki-image-digest` records the resolved local digest when Docker provides one.
|
|
1135
|
-
|
|
1136
|
-
**Offline deployment:**
|
|
1137
|
-
|
|
1138
|
-
```bash
|
|
1139
|
-
# For Raspberry Pi (avoid builds)
|
|
1140
|
-
KASEKI_BUILD_IMAGE_IF_TEMPLATE_MISSING=0 sudo ./scripts/deploy-pi-template.sh
|
|
1141
|
-
|
|
1142
|
-
# Reuse existing local image
|
|
1143
|
-
KASEKI_IMAGE_PULL_POLICY=missing sudo ./scripts/deploy-pi-template.sh
|
|
1144
|
-
|
|
1145
|
-
# Offline only
|
|
1146
|
-
KASEKI_IMAGE_PULL_POLICY=never sudo ./scripts/deploy-pi-template.sh
|
|
1147
|
-
|
|
1148
|
-
# Dockhand / Portainer style
|
|
1149
|
-
KASEKI_IMAGE=docker.io/cyanautomation/kaseki-agent:latest \
|
|
1150
|
-
KASEKI_IMAGE_PULL_POLICY=always sudo ./scripts/deploy-pi-template.sh
|
|
1151
|
-
```
|
|
1152
|
-
|
|
1153
|
-
---
|
|
1154
|
-
|
|
1155
|
-
## Monitoring Kaseki Runs
|
|
1156
|
-
|
|
1157
|
-
### Live CLI (No Host Node.js Required)
|
|
1158
|
-
|
|
1159
|
-
```bash
|
|
1160
|
-
# List all runs
|
|
1161
|
-
/agents/kaseki-template/kaseki list
|
|
1162
|
-
|
|
1163
|
-
# Get status of specific run
|
|
1164
|
-
/agents/kaseki-template/kaseki status kaseki-1
|
|
1165
|
-
|
|
1166
|
-
# Get comprehensive analysis
|
|
1167
|
-
/agents/kaseki-template/kaseki analysis kaseki-1
|
|
1168
|
-
|
|
1169
|
-
# Follow progress logs
|
|
1170
|
-
/agents/kaseki-template/kaseki follow kaseki-4 --tail=50
|
|
1171
|
-
|
|
1172
|
-
# Show sanitized progress
|
|
1173
|
-
/agents/kaseki-template/kaseki progress kaseki-4 --tail=25
|
|
1174
|
-
```
|
|
1175
|
-
|
|
1176
|
-
The `kaseki` wrapper runs the Node-based CLI inside the configured Kaseki Docker image and mounts `/agents/kaseki-results` read-only.
|
|
1177
|
-
|
|
1178
|
-
### Diagnostic Report
|
|
1179
|
-
|
|
1180
|
-
```bash
|
|
1181
|
-
docker run --rm --entrypoint kaseki-report \
|
|
1182
|
-
-v /agents/kaseki-results/kaseki-4:/results:ro \
|
|
1183
|
-
kaseki-template:latest \
|
|
1184
|
-
/results
|
|
1185
|
-
```
|
|
1186
|
-
|
|
1187
|
-
Includes:
|
|
1188
|
-
|
|
1189
|
-
- Status and exit code
|
|
1190
|
-
- Failed command and detail
|
|
1191
|
-
- Model and duration
|
|
1192
|
-
- Stage timings and validation timings
|
|
1193
|
-
- Dependency cache status
|
|
1194
|
-
- Changed files and secret-scan status
|
|
1195
|
-
- Recommended next diagnostic artifact to inspect
|
|
1196
|
-
|
|
1197
|
-
---
|
|
1198
|
-
|
|
1199
|
-
## Metrics Export
|
|
1200
|
-
|
|
1201
|
-
`run-kaseki.sh` writes a stable metrics artifact at the end of each run:
|
|
1202
|
-
|
|
1203
|
-
- `$RESULT_DIR/metrics.json` (schema `kaseki.metrics.v1`)
|
|
1204
|
-
- Optional centralized stream: `/var/log/kaseki/metrics.jsonl`
|
|
1205
|
-
|
|
1206
|
-
### Generate Metrics Manually
|
|
1207
|
-
|
|
1208
|
-
```bash
|
|
1209
|
-
./kaseki-metrics.sh /agents/kaseki-results/kaseki-4/stage-timings.tsv \
|
|
1210
|
-
/agents/kaseki-results/kaseki-4/metadata.json \
|
|
1211
|
-
/agents/kaseki-results/kaseki-4/metrics.json
|
|
1212
|
-
```
|
|
1213
|
-
|
|
1214
|
-
### Aggregation Examples
|
|
1215
|
-
|
|
1216
|
-
```bash
|
|
1217
|
-
# Inspect one run
|
|
1218
|
-
jq . /agents/kaseki-results/kaseki-4/metrics.json
|
|
1219
|
-
|
|
1220
|
-
# Aggregate JSONL by repo
|
|
1221
|
-
jq -s 'group_by(.repo_url) | map({repo_url: .[0].repo_url, runs: length, total_runtime_seconds: (map(.total_runtime_seconds // 0) | add)})' /var/log/kaseki/metrics.jsonl
|
|
1222
|
-
|
|
1223
|
-
# Prometheus textfile bridge
|
|
1224
|
-
jq -r '"kaseki_total_runtime_seconds{instance=\"" + (.instance // "unknown") + "\"} " + ((.total_runtime_seconds // 0)|tostring)' /agents/kaseki-results/kaseki-4/metrics.json > /var/lib/node_exporter/textfile_collector/kaseki.prom
|
|
1225
|
-
```
|
|
1226
|
-
|
|
1227
|
-
---
|
|
1228
|
-
|
|
1229
|
-
## Host Readiness Check
|
|
1230
|
-
|
|
1231
|
-
Run the doctor command before first use or after host changes:
|
|
1232
|
-
|
|
1233
|
-
```bash
|
|
1234
|
-
/agents/kaseki-template/run-kaseki.sh --doctor
|
|
1235
|
-
```
|
|
1236
|
-
|
|
1237
|
-
Run doctor from the deployed template directory, not directly from a source-only
|
|
1238
|
-
checkout. The deployed template includes generated `lib/*.js` helper payloads
|
|
1239
|
-
extracted from the Docker image.
|
|
1240
|
-
|
|
1241
|
-
For a brand-new host, prefer the setup helper:
|
|
1242
|
-
|
|
1243
|
-
```bash
|
|
1244
|
-
/agents/kaseki-agent/scripts/kaseki-setup-host.sh --fix
|
|
1245
|
-
```
|
|
1246
|
-
|
|
1247
|
-
Checks:
|
|
1248
|
-
|
|
1249
|
-
- Docker availability and daemon accessibility
|
|
1250
|
-
- Writable run/result directories
|
|
1251
|
-
- Image presence and readiness
|
|
1252
|
-
- OpenRouter key availability
|
|
1253
|
-
- Host script/image parity
|
|
1254
|
-
|
|
1255
|
-
### Verify API Key (Non-Exposing)
|
|
1256
|
-
|
|
1257
|
-
```bash
|
|
1258
|
-
OPENROUTER_API_KEY_FILE=~/secrets/openrouter_api_key \
|
|
1259
|
-
KASEKI_VERIFY_OPENROUTER_AUTH=1 \
|
|
1260
|
-
/agents/kaseki-template/run-kaseki.sh --doctor
|
|
1261
|
-
```
|
|
1262
|
-
|
|
1263
|
-
---
|
|
1264
|
-
|
|
1265
|
-
## GitHub App Integration (Optional)
|
|
1266
|
-
|
|
1267
|
-
Kaseki can automatically push changes and create pull requests using a GitHub App.
|
|
1268
|
-
Use file-mounted secrets for the private key. It is acceptable to provide the App ID
|
|
1269
|
-
and Client ID as environment variables, but production deployments should keep all
|
|
1270
|
-
three values in files or Docker secrets and pass only `*_FILE` paths through the
|
|
1271
|
-
container environment.
|
|
1272
|
-
|
|
1273
|
-
### Prerequisites
|
|
1274
|
-
|
|
1275
|
-
1. Create a GitHub App with:
|
|
1276
|
-
- `contents: read & write`
|
|
1277
|
-
- `pull_requests: read & write`
|
|
1278
|
-
- `workflows: read` (optional)
|
|
1279
|
-
|
|
1280
|
-
2. Generate a private key and save locally
|
|
1281
|
-
|
|
1282
|
-
3. Install the app on the target repository
|
|
1283
|
-
|
|
1284
|
-
### Single-line/text PEM private keys
|
|
1285
|
-
|
|
1286
|
-
The preferred approach is to paste the GitHub App private key text into a
|
|
1287
|
-
secret file, then reference that file with `GITHUB_APP_PRIVATE_KEY_FILE`. For
|
|
1288
|
-
example, store the value at `/agents/secrets/github_app_private_key` for
|
|
1289
|
-
container or service deployments, or at `~/secrets/github_app_private_key` for
|
|
1290
|
-
local CLI runs.
|
|
1291
|
-
|
|
1292
|
-
Kaseki normalizes the private key after reading it, so the file may contain the
|
|
1293
|
-
original multi-line PEM, a PEM where newlines are escaped as `\n`, a base64-
|
|
1294
|
-
encoded PEM, or a single-line PEM where spaces are used in place of PEM
|
|
1295
|
-
newlines.
|
|
1296
|
-
|
|
1297
|
-
`GITHUB_APP_PRIVATE_KEY` is only for local `run-kaseki.sh` experiments. Config
|
|
1298
|
-
and API service flows may reject inline private keys because they enforce
|
|
1299
|
-
file-based secrets; use `GITHUB_APP_PRIVATE_KEY_FILE` for those flows.
|
|
1300
|
-
|
|
1301
|
-
> **Security warning:** Never paste real private keys into tickets, prompts,
|
|
1302
|
-
> logs, `.env` files, or source control. If a GitHub App private key is exposed,
|
|
1303
|
-
> regenerate the private key in the GitHub App settings and replace the secret
|
|
1304
|
-
> file everywhere it is used.
|
|
1305
|
-
|
|
1306
|
-
### Setup
|
|
1307
|
-
|
|
1308
|
-
```bash
|
|
1309
|
-
mkdir -p ~/secrets
|
|
1310
|
-
sudo chgrp 10000 ~/secrets
|
|
1311
|
-
chmod 0750 ~/secrets
|
|
1312
|
-
|
|
1313
|
-
echo "YOUR_APP_ID" > ~/secrets/github_app_id
|
|
1314
|
-
echo "YOUR_CLIENT_ID" > ~/secrets/github_app_client_id
|
|
1315
|
-
cp ~/path/to/private-key.pem ~/secrets/github_app_private_key
|
|
1316
|
-
sudo chgrp 10000 ~/secrets/github_app_*
|
|
1317
|
-
chmod 0640 ~/secrets/github_app_*
|
|
1318
|
-
```
|
|
1319
|
-
|
|
1320
|
-
### Usage
|
|
1321
|
-
|
|
1322
|
-
```bash
|
|
1323
|
-
OPENROUTER_API_KEY_FILE=~/secrets/openrouter_api_key \
|
|
1324
|
-
GITHUB_APP_ID_FILE=~/secrets/github_app_id \
|
|
1325
|
-
GITHUB_APP_CLIENT_ID_FILE=~/secrets/github_app_client_id \
|
|
1326
|
-
GITHUB_APP_PRIVATE_KEY_FILE=~/secrets/github_app_private_key \
|
|
1327
|
-
/agents/kaseki-template/run-kaseki.sh https://github.com/org/repo
|
|
1328
|
-
```
|
|
1329
|
-
|
|
1330
|
-
For Docker Compose or Dockhand deployments, mount the secret files under `/agents`
|
|
1331
|
-
and pass paths rather than embedding the PEM in `.env`:
|
|
1332
|
-
|
|
1333
|
-
```yaml
|
|
1334
|
-
environment:
|
|
1335
|
-
GITHUB_APP_ID_FILE: /agents/secrets/github_app_id
|
|
1336
|
-
GITHUB_APP_CLIENT_ID_FILE: /agents/secrets/github_app_client_id
|
|
1337
|
-
GITHUB_APP_PRIVATE_KEY_FILE: /agents/secrets/github_app_private_key
|
|
1338
|
-
volumes:
|
|
1339
|
-
- /agents:/agents:rw
|
|
1340
|
-
```
|
|
1341
|
-
|
|
1342
|
-
`GITHUB_APP_PRIVATE_KEY` is still accepted as a fallback for local
|
|
1343
|
-
`run-kaseki.sh` experiments, including escaped `\n`, base64 PEM, or
|
|
1344
|
-
single-line PEM values after normalization. Avoid inline private keys for shared
|
|
1345
|
-
hosts: environment variables are easier to leak through process inspection,
|
|
1346
|
-
logs, and orchestration UIs, and config/API service flows may reject inline
|
|
1347
|
-
secrets in favor of file-based secret paths.
|
|
1348
|
-
|
|
1349
|
-
### Behavior
|
|
1350
|
-
|
|
1351
|
-
When credentials are configured and publishing is enabled:
|
|
1352
|
-
|
|
1353
|
-
1. After validation passes and diff is non-empty, Kaseki generates a GitHub App installation token
|
|
1354
|
-
2. Creates a feature branch `kaseki/<instance-name>`
|
|
1355
|
-
3. Commits and pushes changes to remote
|
|
1356
|
-
4. Creates a PR against the target branch when `KASEKI_PUBLISH_MODE=pr` or API `publishMode` is `pr` (normal PR), when `KASEKI_PUBLISH_MODE=auto` finds worker credentials (normal PR), or when `KASEKI_PUBLISH_MODE=draft_pr` or API `publishMode` is `draft_pr` (explicit draft PR), with:
|
|
1357
|
-
- Title: `Kaseki: <instance-name>`
|
|
1358
|
-
- Body: Model, duration, validation result, quality checks
|
|
1359
|
-
- Draft: `true` only for explicit `draft_pr` mode; otherwise `false`
|
|
1360
|
-
|
|
1361
|
-
Publishing modes are `auto`, `none`, `branch`, `pr`, and `draft_pr`. Controller
|
|
1362
|
-
requests with omitted `publishMode` default to `pr`, so the normal controller path
|
|
1363
|
-
pushes a branch and creates a normal pull request after validation. The `draft_pr`
|
|
1364
|
-
mode remains available for explicit draft PR creation. Explicit API `publishMode: "auto"`
|
|
1365
|
-
is accepted for graceful worker auto publishing: the worker publishes when
|
|
1366
|
-
credentials are available and skips GitHub operations when they are not. Requests
|
|
1367
|
-
that resolve to `branch`, `pr`, or `draft_pr` fail before queueing unless GitHub
|
|
1368
|
-
App credentials are readable, so orchestrators can surface a clear setup error
|
|
1369
|
-
instead of waiting for a run that cannot publish. Set `publishMode` to `none`
|
|
1370
|
-
to opt out of GitHub publishing for a specific API run.
|
|
1371
|
-
|
|
1372
|
-
### Result Artifacts
|
|
1373
|
-
|
|
1374
|
-
- `git-push.log`: Detailed log of push and PR creation
|
|
1375
|
-
- `metadata.json` includes:
|
|
1376
|
-
- `github_pr_url`: URL of created PR (if successful)
|
|
1377
|
-
- `github_push_exit_code`: Push operation status
|
|
1378
|
-
- `github_pr_exit_code`: PR creation status
|
|
1379
|
-
|
|
1380
|
-
---
|
|
1381
|
-
|
|
1382
|
-
## Environment Variables Reference
|
|
1383
|
-
|
|
1384
|
-
### Core Configuration
|
|
1385
|
-
|
|
1386
|
-
| Variable | Default | Notes |
|
|
1387
|
-
|---|---|---|
|
|
1388
|
-
| `OPENROUTER_API_KEY` | — | Required (or use file) |
|
|
1389
|
-
| `OPENROUTER_API_KEY_FILE` | `~/.kaseki/secrets.json` | Preferred; set by setup wizard |
|
|
1390
|
-
| `REPO_URL` | CyanAutomation/crudmapper | Target repository |
|
|
1391
|
-
| `GIT_REF` | main | Branch/tag/commit |
|
|
1392
|
-
|
|
1393
|
-
### Model and Execution
|
|
1394
|
-
|
|
1395
|
-
| Variable | Default | Notes |
|
|
1396
|
-
|---|---|---|
|
|
1397
|
-
| `KASEKI_MODEL` | openrouter/free | Pi model string |
|
|
1398
|
-
| `KASEKI_AGENT_TIMEOUT_SECONDS` | 10800 | Agent timeout (3 hours) |
|
|
1399
|
-
| `TASK_PROMPT` | *(code fix task)* | Agent instructions |
|
|
1400
|
-
| `KASEKI_TASK_MODE` | patch | `patch` (require diff) or `inspect` (no diff) |
|
|
1401
|
-
| `KASEKI_PUBLISH_MODE` | pr | `pr` (normal PR), `draft_pr` (draft PR), `branch` (branch only), `auto` (legacy: PR if credentials found), or `none` (skip); controller API requests with omitted `publishMode` default to `pr`; direct worker/CLI execution defaults to `pr` if unchanged |
|
|
1402
|
-
| `KASEKI_STARTUP_CHECK_MODE` | boot | Dry-run startup check depth: `boot` or `baseline-validation` |
|
|
1403
|
-
|
|
1404
|
-
### Validation and Quality Gates
|
|
1405
|
-
|
|
1406
|
-
| Variable | Default | Notes |
|
|
1407
|
-
|---|---|---|
|
|
1408
|
-
| `KASEKI_PRE_AGENT_VALIDATION` | `1` | Run validation before Pi to detect a failing baseline repo/ref. Set to `0` only when you intentionally want to skip baseline validation. |
|
|
1409
|
-
| `KASEKI_PRE_AGENT_VALIDATION_COMMANDS` | same as `KASEKI_VALIDATION_COMMANDS` | Semicolon-separated pre-agent validation commands. Logs: `pre-validation.log`, `pre-validation-raw.log`, `pre-validation-env.log`, `pre-validation-timings.tsv`. |
|
|
1410
|
-
| `KASEKI_SCOUTING` | `1` | Run a read-only Pi scouting phase after pre-agent validation and before coding (enabled by default). Its schema-validated JSON handoff is stored as `scouting.json`; use `scouting-summary.json`, `scouting-events.jsonl`, and `scouting-stderr.log` for model/token output and diagnostics. Disable explicitly with `KASEKI_SCOUTING=0` (CLI/env) or `scouting.enabled=false` in API requests. |
|
|
1411
|
-
| `KASEKI_SCOUTING_MODEL` | same as `KASEKI_MODEL` | Optional Pi model override for scouting. API runs may set this with `scouting.model`. |
|
|
1412
|
-
| `KASEKI_SCOUTING_TIMEOUT_SECONDS` | same as `KASEKI_AGENT_TIMEOUT_SECONDS` | Optional scouting timeout. API runs may set this with `scouting.timeoutSeconds`. |
|
|
1413
|
-
| `KASEKI_VALIDATION_COMMANDS` | `npm run check;npm run test;npm run build` | Semicolon-separated post-agent validation commands for the final diff; set to `none` or empty to skip post-agent validation. Missing npm scripts are skipped with a warning (non-fatal). Logs: `validation.log`, `validation-raw.log`, `validation-env.log`, `validation-timings.tsv`. |
|
|
1414
|
-
| `KASEKI_STARTUP_CHECK_MODE` | `boot` | For `KASEKI_DRY_RUN=1`, `boot` performs a container smoke test through `/bin/bash`; `baseline-validation` runs `/usr/local/bin/kaseki-agent` to clone, install dependencies, run pre-agent validation, and skip Pi. |
|
|
1415
|
-
| `KASEKI_BASELINE_VALIDATION_DRY_RUN` | `0` | Internal/API switch set with `baseline-validation` so pre-agent validation runs even though Pi remains disabled. |
|
|
1416
|
-
| `KASEKI_CHANGED_FILES_ALLOWLIST` | `src/lib/parser.ts tests/parser.validation.ts` | Space-separated patterns |
|
|
1417
|
-
| `KASEKI_MAX_DIFF_BYTES` | 400000 | Max diff size (400 KB) |
|
|
1418
|
-
| `KASEKI_ALLOW_EMPTY_DIFF` | 0 | Set to `1` to allow empty diff with `KASEKI_TASK_MODE=patch` |
|
|
1419
|
-
| `KASEKI_AGENT_GUARDRAILS` | 1 | Prepend safety instructions that reserve commit/push/PR actions for Kaseki |
|
|
1420
|
-
| `KASEKI_RESTORE_DISALLOWED_CHANGES` | 1 | Restore changes outside `KASEKI_CHANGED_FILES_ALLOWLIST` before validation and GitHub publishing |
|
|
1421
|
-
| `KASEKI_NPM_OMIT_DEV` | 0 | Set to `1` to omit dev dependencies during `npm ci`; default keeps test/build tools available |
|
|
1422
|
-
|
|
1423
|
-
`KASEKI_CHANGED_FILES_ALLOWLIST` patterns are repo-relative globs. Exact paths match only that path; `*` and `?` match within a single path segment; `**` can span directory separators. A `**/` segment may match zero or more directories, so `src/**/*.ts` matches both `src/index.ts` and nested files such as `src/lib/file-storage.ts`.
|
|
1424
|
-
|
|
1425
|
-
API controllers may send either the direct fields (`changedFilesAllowlist`, `validationCommands`) or the structured aliases (`allowlist.include`, `validation.commands`). The scheduler normalizes both forms before launching the worker.
|
|
1426
|
-
|
|
1427
|
-
Startup checks have two depths. Boot-only startup checks (`startupCheck: true`, `startupCheckMode: "boot"`, or `KASEKI_DRY_RUN=1 KASEKI_STARTUP_CHECK_MODE=boot`) use the minimal container boot path to verify runtime tools, mounts, and secrets without cloning the repository. Baseline validation startup checks (`startupCheckMode: "baseline-validation"`, or a startup check with validation commands) keep dry-run/Pi-skipping behavior but invoke `/usr/local/bin/kaseki-agent` far enough to clone the repository, prepare dependencies, and execute the pre-agent validation commands. A failure in this mode means the requested baseline already failed before any Pi-authored changes existed; inspect `pre-validation.log` and `pre-validation-timings.tsv`.
|
|
1428
|
-
|
|
1429
|
-
### Paths and Caching
|
|
1430
|
-
|
|
1431
|
-
| Variable | Default | Notes |
|
|
1432
|
-
|---|---|---|
|
|
1433
|
-
| `KASEKI_ROOT` | `/agents` | Base directory for runs, results, cache |
|
|
1434
|
-
| `KASEKI_DEPENDENCY_CACHE_DIR` | `/workspace/.kaseki-cache` | Workspace dependency cache, keyed as `npm/<lock_hash>/node-<major>/flags-<flags_hash>` |
|
|
1435
|
-
| `KASEKI_IMAGE_DEPENDENCY_CACHE_DIR` | `/opt/kaseki/workspace-cache` | Image-provided seed cache using the same lockfile-first key layout |
|
|
1436
|
-
| `KASEKI_GIT_CACHE_MODE` | `mirror` | Git object cache mode: `mirror` uses host-mounted bare mirrors under `/cache/git`; `off` keeps the direct shallow clone path |
|
|
1437
|
-
| `KASEKI_REPO_MEMORY_MODE` | `off` | Opt-in repository prompt memory: `off` disables it; `summary` appends a compact prior-context summary when fresh |
|
|
1438
|
-
| `KASEKI_REPO_MEMORY_TTL_DAYS` | `30` | Maximum age for a repository memory summary before it is ignored |
|
|
1439
|
-
| `KASEKI_REPO_MEMORY_MAX_BYTES` | `8000` | Maximum bytes to read/write for the repository memory prompt section |
|
|
1440
|
-
| `KASEKI_REPO_MEMORY_ROOT` | `/cache/repo-memory` | Directory root for repository memory summaries |
|
|
1441
|
-
|
|
1442
|
-
### Docker and Images
|
|
1443
|
-
|
|
1444
|
-
| Variable | Default | Notes |
|
|
1445
|
-
|---|---|---|
|
|
1446
|
-
| `KASEKI_IMAGE` | `docker.io/cyanautomation/kaseki-agent:latest` | Docker image to use |
|
|
1447
|
-
| `KASEKI_CONTAINER_USER` | `$(id -u):$(id -g)` | UID:GID for container process |
|
|
1448
|
-
| `KASEKI_PROVIDER` | `openrouter` | LLM provider |
|
|
1449
|
-
|
|
1450
|
-
### Debugging and Logging
|
|
1451
|
-
|
|
1452
|
-
| Variable | Default | Notes |
|
|
1453
|
-
|---|---|---|
|
|
1454
|
-
| `KASEKI_DEBUG_RAW_EVENTS` | 0 | Keep raw Pi JSONL as `pi-events.raw.jsonl` |
|
|
1455
|
-
| `KASEKI_STREAM_PROGRESS` | 1 | Stream sanitized progress lines |
|
|
1456
|
-
| `KASEKI_LOG_DIR` | `/var/log/kaseki` | Host log mirror directory |
|
|
1457
|
-
| `KASEKI_STRICT_HOST_LOGGING` | 0 | Fail fast if logs can't be written |
|
|
1458
|
-
| `KASEKI_KEEP_WORKSPACE` | 0 | Keep workspace after run (set `1` for debugging) |
|
|
1459
|
-
| `KASEKI_VALIDATE_AFTER_AGENT_FAILURE` | 0 | Run validation even if agent fails |
|
|
1460
|
-
|
|
1461
|
-
### API Service
|
|
1462
|
-
|
|
1463
|
-
| Variable | Default | Notes |
|
|
1464
|
-
|---|---|---|
|
|
1465
|
-
| `KASEKI_API_URL` | `http://localhost:8080/api` | Client-side API base URL for npm task commands |
|
|
1466
|
-
| `KASEKI_API_KEY` | — | Client-side bearer token for npm task commands |
|
|
1467
|
-
| `KASEKI_API_KEYS` | — | Comma-separated API keys accepted by the service |
|
|
1468
|
-
| `KASEKI_API_PORT` | 8080 | HTTP listen port |
|
|
1469
|
-
| `KASEKI_API_LOG_LEVEL` | info | Log verbosity: debug/info/warn/error |
|
|
1470
|
-
| `KASEKI_API_MAX_CONCURRENT_RUNS` | 3 | Max concurrent jobs |
|
|
1471
|
-
| `KASEKI_RESULTS_DIR` | `/agents/kaseki-results` | Results artifact directory |
|
|
1472
|
-
| `GITHUB_APP_ID_FILE` | — | Path to file containing GitHub App ID for PR creation |
|
|
1473
|
-
| `GITHUB_APP_CLIENT_ID_FILE` | — | Path to file containing GitHub App Client ID |
|
|
1474
|
-
| `GITHUB_APP_PRIVATE_KEY_FILE` | — | Path to GitHub App private key file; preferred over inline private key env |
|
|
1475
|
-
|
|
1476
|
-
### Metrics
|
|
1477
|
-
|
|
1478
|
-
| Variable | Default | Notes |
|
|
1479
|
-
|---|---|---|
|
|
1480
|
-
| `KASEKI_APPEND_METRICS_JSONL` | 1 | Append metrics to centralized JSONL stream |
|
|
1481
|
-
| `KASEKI_METRICS_JSONL_PATH` | `/var/log/kaseki/metrics.jsonl` | Centralized metrics stream |
|
|
1482
|
-
|
|
1483
|
-
---
|
|
1484
|
-
|
|
1485
|
-
## Exit Codes
|
|
1486
|
-
|
|
1487
|
-
Kaseki uses specific non-zero exit codes for diagnostic purposes:
|
|
1488
|
-
|
|
1489
|
-
| Code | Reason |
|
|
1490
|
-
|---|---|
|
|
1491
|
-
| 0 | Success |
|
|
1492
|
-
| 2 | Missing required configuration (e.g., `OPENROUTER_API_KEY`) or invalid instance format |
|
|
1493
|
-
| 3 | Empty git diff (no changes made by agent). Set `KASEKI_TASK_MODE=inspect` or `KASEKI_ALLOW_EMPTY_DIFF=1` when expected |
|
|
1494
|
-
| 4 | Diff exceeds `KASEKI_MAX_DIFF_BYTES` |
|
|
1495
|
-
| 5 | Changed file outside `KASEKI_CHANGED_FILES_ALLOWLIST` |
|
|
1496
|
-
| 6 | Secret scan detected credential-like content |
|
|
1497
|
-
| 7 | GitHub push/PR setup failed (missing credentials, invalid key, etc.) |
|
|
1498
|
-
| 8 | Failed to push branch to GitHub |
|
|
1499
|
-
| 9 | Push succeeded but PR creation failed (non-blocking; push result retained) |
|
|
1500
|
-
| 124 | Agent timeout (SIGTERM after `KASEKI_AGENT_TIMEOUT_SECONDS`) |
|
|
1501
|
-
|
|
1502
|
-
Other non-zero codes may propagate from failed steps (clone, install, agent run, validation). Check `/results/metadata.json` for `failed_command` and details.
|
|
1503
|
-
|
|
1504
|
-
---
|
|
1505
|
-
|
|
1506
|
-
## Container Healthcheck
|
|
1507
|
-
|
|
1508
|
-
The image defines a `HEALTHCHECK`:
|
|
1509
|
-
|
|
1510
|
-
```dockerfile
|
|
1511
|
-
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
|
1512
|
-
CMD test -f /results/stdout.log && test -f /results/stderr.log
|
|
1513
|
-
```
|
|
1514
|
-
|
|
1515
|
-
- `/results` is created in the image and again at runtime by `kaseki-agent.sh`
|
|
1516
|
-
- Container is **healthy** after runner initializes result logs
|
|
1517
|
-
- Run completion is tracked by `/results/exit_code`
|
|
1518
|
-
|
|
1519
|
-
---
|
|
1520
|
-
|
|
1521
|
-
## Cleanup
|
|
1522
|
-
|
|
1523
|
-
### Workspace Cleanup
|
|
1524
|
-
|
|
1525
|
-
Remove old per-run workspaces while keeping results:
|
|
1526
|
-
|
|
1527
|
-
```bash
|
|
1528
|
-
KASEKI_CLEANUP_DAYS=1 /agents/kaseki-template/cleanup-kaseki.sh
|
|
1529
|
-
```
|
|
1530
|
-
|
|
1531
|
-
### Docker Cleanup
|
|
1532
|
-
|
|
1533
|
-
Explicit and guarded. Use `--dry-run` first:
|
|
1534
|
-
|
|
1535
|
-
```bash
|
|
1536
|
-
/agents/kaseki-template/cleanup-kaseki.sh --docker --dry-run
|
|
1537
|
-
/agents/kaseki-template/cleanup-kaseki.sh --docker --force
|
|
1538
|
-
```
|
|
1539
|
-
|
|
1540
|
-
Prunes old Docker build cache and dangling images.
|
|
1541
|
-
|
|
1542
|
-
---
|
|
1543
|
-
|
|
1544
|
-
## Help and Usage
|
|
1545
|
-
|
|
1546
|
-
View the full usage guide:
|
|
1547
|
-
|
|
1548
|
-
```bash
|
|
1549
|
-
/agents/kaseki-template/run-kaseki.sh --help
|
|
1550
|
-
```
|
|
1551
|
-
|
|
1552
|
-
Displays all invocation patterns, argument descriptions, environment variables, and examples.
|
|
1553
|
-
|
|
1554
|
-
---
|
|
1555
|
-
|
|
1556
|
-
## Git Object Cache Behavior
|
|
1557
|
-
|
|
1558
|
-
`kaseki-agent.sh` can reuse host-mounted Git object caches before dependency installation:
|
|
1559
|
-
|
|
1560
|
-
1. Build a safe cache key from `REPO_URL` and store the bare mirror at `/cache/git/<repo-key>.git`.
|
|
1561
|
-
2. Serialize mirror population and updates with `flock` on a per-repository lock file.
|
|
1562
|
-
3. On cache hit, refresh the mirror with `git -C <mirror> fetch --prune --tags origin` under a timeout.
|
|
1563
|
-
4. Clone `/workspace/repo` with `git clone --reference-if-able <mirror> --depth 1 --branch "$GIT_REF" "$REPO_URL" /workspace/repo`.
|
|
1564
|
-
5. If the reference clone cannot be used, try cloning from the mirror and then reset the workspace origin back to `REPO_URL`.
|
|
1565
|
-
6. If the mirror is disabled, unavailable, corrupt, or cannot be refreshed/populated, fall back to the existing direct shallow clone.
|
|
1566
|
-
|
|
1567
|
-
Set `KASEKI_GIT_CACHE_MODE=off` to disable Git mirror caching. Clone duration plus cache mode/status/hit/key/strategy data are emitted to `stage-timings.tsv`, `progress.jsonl`, and `metadata.json`.
|
|
1568
|
-
|
|
1569
|
-
### Repository Memory Cache
|
|
1570
|
-
|
|
1571
|
-
Repository memory is disabled by default. Set `KASEKI_REPO_MEMORY_MODE=summary` to opt in to a compact prompt-context cache for the target repository and ref. Kaseki stores this summary at `${KASEKI_REPO_MEMORY_ROOT}/<repo-key>/summary.md`, where `KASEKI_REPO_MEMORY_ROOT` defaults to `/cache/repo-memory` and `<repo-key>` is derived from the repository URL and default ref. Before invoking the agent, Kaseki appends a clearly labeled “Prior repository context” section only when the summary exists, is within `KASEKI_REPO_MEMORY_TTL_DAYS`, and is no larger than `KASEKI_REPO_MEMORY_MAX_BYTES`.
|
|
1572
|
-
|
|
1573
|
-
After a successful run, or an inspect-mode run where the agent completed and the secret scan passed, Kaseki rewrites the summary from bounded, sanitized artifacts: `result-summary.md`, `analysis.md`, `changed-files.txt`, and validation timing/status outcomes. The summary records the repo URL, default ref, commit SHA, and timestamp so stale context is visible to the next agent. Kaseki does not blindly persist raw logs or user prompts, and lines resembling secrets, credentials, API keys, tokens, or prompt text are filtered out before writing memory.
|
|
1574
|
-
|
|
1575
|
-
This memory is an efficiency feature, not an authoritative source of truth. Agents should use it only as hints and must inspect the current repository state before relying on prior context.
|
|
1576
|
-
|
|
1577
|
-
---
|
|
1578
|
-
|
|
1579
|
-
## Dependency Install Behavior
|
|
1580
|
-
|
|
1581
|
-
`kaseki-agent.sh` prepares dependencies in this order:
|
|
1582
|
-
|
|
1583
|
-
1. Skip if no `package.json`
|
|
1584
|
-
2. Skip if `node_modules` exists and the external dependency stamp matches the lock hash
|
|
1585
|
-
3. Try workspace cache hit at `$KASEKI_DEPENDENCY_CACHE_DIR/npm/<lock_hash>/node-<major>/flags-<flags_hash>/node_modules`
|
|
1586
|
-
4. Try image seed cache hit at `$KASEKI_IMAGE_DEPENDENCY_CACHE_DIR/npm/<lock_hash>/node-<major>/flags-<flags_hash>/node_modules`
|
|
1587
|
-
5. Refresh with `npm ci --prefer-offline` plus the active install-mode flags
|
|
1588
|
-
6. Atomically publish `node_modules` back to the workspace cache for reuse
|
|
1589
|
-
|
|
1590
|
-
The primary cache boundary is lockfile-first: `npm/<lock_hash>/node-<major>/flags-<flags_hash>`. The `flags_hash` covers install-mode switches such as `KASEKI_NPM_OMIT_DEV` and `KASEKI_INSTALL_IGNORE_SCRIPTS`, so incompatible installs do not share `node_modules`. Repo/ref information is recorded as metadata in cache logs and `repo-ref-metadata.tsv`, but it is not part of the reuse key; two refs with the same lockfile, Node major version, and install flags can reuse the same dependency cache path.
|
|
1591
|
-
|
|
1592
|
-
The dependency stamp is stored outside the repo, so git status/diff remain focused on target changes.
|
|
1593
|
-
|
|
1594
|
-
---
|
|
1595
|
-
|
|
1596
|
-
## Running Against a Custom Repo
|
|
1597
|
-
|
|
1598
|
-
### Method 1: CLI Arguments (Recommended)
|
|
1599
|
-
|
|
1600
|
-
```bash
|
|
1601
|
-
# Custom repo, auto git-ref
|
|
1602
|
-
OPENROUTER_API_KEY_FILE=~/secrets/openrouter_api_key \
|
|
1603
|
-
./run-kaseki.sh https://github.com/org/repo
|
|
1604
|
-
|
|
1605
|
-
# Custom repo and branch
|
|
1606
|
-
OPENROUTER_API_KEY_FILE=~/secrets/openrouter_api_key \
|
|
1607
|
-
./run-kaseki.sh https://github.com/org/repo feature/my-branch
|
|
1608
|
-
|
|
1609
|
-
# Custom repo, ref, and explicit instance
|
|
1610
|
-
OPENROUTER_API_KEY_FILE=~/secrets/openrouter_api_key \
|
|
1611
|
-
./run-kaseki.sh https://github.com/org/repo develop kaseki-42
|
|
1612
|
-
```
|
|
1613
|
-
|
|
1614
|
-
Arguments are parsed intelligently:
|
|
1615
|
-
|
|
1616
|
-
- Strings with `/` or `.git` → repo URLs
|
|
1617
|
-
- Short strings (`main`, `v1.0.0`) → Git refs
|
|
1618
|
-
- Strings matching `kaseki-N` → explicit instance names
|
|
1619
|
-
- Unspecified → auto-generated
|
|
1620
|
-
|
|
1621
|
-
### Method 2: Environment Variables (Legacy)
|
|
1622
|
-
|
|
1623
|
-
```bash
|
|
1624
|
-
OPENROUTER_API_KEY=... REPO_URL=https://github.com/org/repo GIT_REF=feature/branch ./run-kaseki.sh
|
|
1625
|
-
```
|
|
1626
|
-
|
|
1627
|
-
**Note:** CLI arguments take precedence over environment variables.
|
|
1628
|
-
|
|
1629
|
-
---
|
|
1630
|
-
|
|
1631
|
-
## Useful Links
|
|
1632
|
-
|
|
1633
|
-
- **[API Reference](docs/API.md)** — Complete REST endpoint specifications
|
|
1634
|
-
- **[Deployment Guide](docs/DEPLOYMENT.md)** — systemd, Docker, docker-compose setup
|
|
1635
|
-
- **[Integration Example](docs/INTEGRATION_EXAMPLE.md)** — Real-world usage with TypeScript client
|
|
1636
|
-
- **[CLI Reference](docs/CLI.md)** — Live monitoring CLI (`kaseki` wrapper)
|
|
1637
|
-
- **[Backlog](docs/BACKLOG.md)** — Known TypeScript debt and planned improvements
|
|
1638
|
-
|
|
1639
|
-
---
|
|
1640
|
-
|
|
1641
|
-
## Getting Help
|
|
1642
|
-
|
|
1643
|
-
### Run a Health Check
|
|
1644
|
-
|
|
1645
|
-
```bash
|
|
1646
|
-
./run-kaseki.sh --doctor
|
|
1647
|
-
```
|
|
1648
|
-
|
|
1649
|
-
### Inspect a Completed Run
|
|
1650
|
-
|
|
1651
|
-
```bash
|
|
1652
|
-
docker run --rm --entrypoint kaseki-report \
|
|
1653
|
-
-v /agents/kaseki-results/kaseki-4:/results:ro \
|
|
1654
|
-
kaseki-template:latest \
|
|
1655
|
-
/results
|
|
1656
|
-
```
|
|
1657
|
-
|
|
1658
|
-
### Check Script Permissions
|
|
1659
|
-
|
|
1660
|
-
If scripts aren't executable:
|
|
1661
|
-
|
|
1662
|
-
```bash
|
|
1663
|
-
chmod +x run-kaseki.sh kaseki kaseki-agent.sh scripts/*.sh
|
|
1664
|
-
```
|
|
1665
|
-
|
|
1666
|
-
### Verify Pi in Image
|
|
1667
|
-
|
|
1668
|
-
```bash
|
|
1669
|
-
# Docker Hub
|
|
1670
|
-
docker run --rm --entrypoint pi docker.io/cyanautomation/kaseki-agent:latest --version
|
|
1671
|
-
|
|
1672
|
-
# GitHub Container Registry
|
|
1673
|
-
docker run --rm --entrypoint pi ghcr.io/cyanautomation/kaseki-agent:latest --version
|
|
1674
|
-
```
|
|
1675
|
-
|
|
1676
|
-
---
|
|
1677
|
-
|
|
1678
|
-
## Troubleshooting: Too Many Files Restored?
|
|
1679
|
-
|
|
1680
|
-
When you run kaseki with a targeted task, you might see many files being "restored" (reverted) because they fall outside the allowlist. This is expected behavior—but here's how to fix it:
|
|
1681
|
-
|
|
1682
|
-
### Symptoms
|
|
1683
|
-
|
|
1684
|
-
- Run completes but `restoration-report.md` shows 20+ files were restored
|
|
1685
|
-
- Only a few files were kept in the allowlist
|
|
1686
|
-
- `kaseki-report` shows "Allowlist coverage: 5/25 files (20%)"
|
|
1687
|
-
|
|
1688
|
-
### Quick Fix: Use a Better Template
|
|
1689
|
-
|
|
1690
|
-
1. **Check what type of task you're running:**
|
|
1691
|
-
- Fixing a UI component? Use `templates/allowlist-ui-component.txt`
|
|
1692
|
-
- Fixing an API endpoint? Use `templates/allowlist-api-route.txt`
|
|
1693
|
-
- Fixing a utility function? Use `templates/allowlist-utility.txt`
|
|
1694
|
-
|
|
1695
|
-
2. **Run with the template:**
|
|
1696
|
-
|
|
1697
|
-
```bash
|
|
1698
|
-
KASEKI_CHANGED_FILES_ALLOWLIST="$(cat templates/allowlist-ui-component.txt | tr '\n' ' ')" ./run-kaseki.sh
|
|
1699
|
-
```
|
|
1700
|
-
|
|
1701
|
-
### Deep Dive: Understanding Restoration
|
|
1702
|
-
|
|
1703
|
-
1. **Look at the restoration report:**
|
|
1704
|
-
|
|
1705
|
-
```bash
|
|
1706
|
-
cat /agents/kaseki-results/kaseki-N/restoration-report.md
|
|
1707
|
-
```
|
|
1708
|
-
|
|
1709
|
-
This shows exactly which files were kept vs. restored.
|
|
1710
|
-
|
|
1711
|
-
2. **Auto-generate a better allowlist:**
|
|
1712
|
-
|
|
1713
|
-
```bash
|
|
1714
|
-
./scripts/suggest-allowlist.sh /agents/kaseki-results/kaseki-N
|
|
1715
|
-
```
|
|
1716
|
-
|
|
1717
|
-
This analyzes what files were actually changed and suggests patterns.
|
|
1718
|
-
|
|
1719
|
-
3. **Preview before running:**
|
|
1720
|
-
|
|
1721
|
-
```bash
|
|
1722
|
-
./scripts/dry-run-allowlist.sh --changed-files /agents/kaseki-results/kaseki-N/changed-files.txt \
|
|
1723
|
-
--allowlist "src/lib/** tests/**"
|
|
1724
|
-
```
|
|
1725
|
-
|
|
1726
|
-
This shows what WOULD be restored with a given allowlist.
|
|
1727
|
-
|
|
1728
|
-
### Root Causes
|
|
1729
|
-
|
|
1730
|
-
**Allowlist too narrow:**
|
|
1731
|
-
|
|
1732
|
-
- ❌ `KASEKI_CHANGED_FILES_ALLOWLIST="src/lib/parser.ts"` (single file only)
|
|
1733
|
-
- ✅ `KASEKI_CHANGED_FILES_ALLOWLIST="src/lib/parser.ts tests/**"` (file + tests)
|
|
1734
|
-
|
|
1735
|
-
**TASK_PROMPT too vague:**
|
|
1736
|
-
|
|
1737
|
-
- ❌ "Fix the bug"
|
|
1738
|
-
- ✅ "Fix the null-reference bug in src/lib/parser.ts. Do not modify other files."
|
|
1739
|
-
|
|
1740
|
-
**Task affects multiple files:**
|
|
1741
|
-
|
|
1742
|
-
- Build a better allowlist by running suggest-allowlist.sh
|
|
1743
|
-
- Or use a broader template (allowlist-comprehensive.txt)
|
|
1744
|
-
|
|
1745
|
-
### More Information
|
|
1746
|
-
|
|
1747
|
-
- Full guide: [docs/QUALITY_GATES.md](docs/QUALITY_GATES.md)
|
|
1748
|
-
- Prompt best practices: [docs/TASK_PROMPT_TEMPLATES.md](docs/TASK_PROMPT_TEMPLATES.md)
|
|
1749
|
-
- Auto-generate patterns: `./scripts/suggest-allowlist.sh <results-dir>`
|
|
1750
|
-
- Preview patterns: `./scripts/dry-run-allowlist.sh --help`
|
|
1751
|
-
|
|
1752
|
-
---
|
|
183
|
+
## License
|
|
1753
184
|
|
|
1754
|
-
|
|
185
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
1755
186
|
|
|
1756
|
-
|
|
187
|
+
**CyanAutomation** - Building reliable AI coding workflows
|