@amodalai/amodal 0.3.27 → 0.3.28
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/CHANGELOG.md +20 -0
- package/dist/src/commands/dev.d.ts.map +1 -1
- package/dist/src/commands/dev.js +28 -11
- package/dist/src/commands/dev.js.map +1 -1
- package/dist/src/commands/eval.d.ts.map +1 -1
- package/dist/src/commands/eval.js +4 -2
- package/dist/src/commands/eval.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -7
- package/src/commands/dev.ts +31 -11
- package/src/commands/eval.ts +4 -2
- package/src/e2e-commands.test.ts +9 -291
- package/src/e2e-subprocess.test.ts +153 -0
- package/dist/src/fixtures/incident-response.d.ts +0 -92
- package/dist/src/fixtures/incident-response.d.ts.map +0 -1
- package/dist/src/fixtures/incident-response.js +0 -209
- package/dist/src/fixtures/incident-response.js.map +0 -1
- package/dist/src/shared/find-free-port.d.ts +0 -21
- package/dist/src/shared/find-free-port.d.ts.map +0 -1
- package/dist/src/shared/find-free-port.js +0 -62
- package/dist/src/shared/find-free-port.js.map +0 -1
- package/src/e2e-automations.test.ts +0 -305
- package/src/e2e-incident-response.test.ts +0 -345
- package/src/e2e-plugin-connections.test.ts +0 -407
- package/src/e2e-plugins.test.ts +0 -491
- package/src/e2e.test.ts +0 -493
- package/src/fixtures/incident-response.ts +0 -233
- package/src/shared/find-free-port.ts +0 -67
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2025 Amodal Labs, Inc.
|
|
4
|
-
* SPDX-License-Identifier: MIT
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Fixture data for the incident response e2e test.
|
|
9
|
-
*
|
|
10
|
-
* Four content types:
|
|
11
|
-
* 1. Connection: statuspage API (mock)
|
|
12
|
-
* 2. Skill: incident triage methodology
|
|
13
|
-
* 3. Knowledge: oncall runbook
|
|
14
|
-
* 4. Automation: daily health check
|
|
15
|
-
*
|
|
16
|
-
* The mock API returns deterministic data so we can assert on the
|
|
17
|
-
* agent's response content.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
import http from 'node:http';
|
|
21
|
-
|
|
22
|
-
// ---------------------------------------------------------------------------
|
|
23
|
-
// amodal.json
|
|
24
|
-
// ---------------------------------------------------------------------------
|
|
25
|
-
|
|
26
|
-
export const CONFIG = {
|
|
27
|
-
name: 'incident-response-agent',
|
|
28
|
-
version: '1.0.0',
|
|
29
|
-
description: 'Monitors services and triages incidents',
|
|
30
|
-
models: {
|
|
31
|
-
main: {provider: 'anthropic', model: 'claude-sonnet-4-20250514'},
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
// ---------------------------------------------------------------------------
|
|
36
|
-
// Connection: statuspage
|
|
37
|
-
// ---------------------------------------------------------------------------
|
|
38
|
-
|
|
39
|
-
export const STATUSPAGE_SPEC = {
|
|
40
|
-
baseUrl: 'https://statuspage.example.com/api/v1',
|
|
41
|
-
specUrl: 'https://statuspage.example.com/api/v1/openapi.json',
|
|
42
|
-
format: 'openapi' as const,
|
|
43
|
-
auth: {
|
|
44
|
-
type: 'bearer',
|
|
45
|
-
header: 'Authorization',
|
|
46
|
-
prefix: 'Bearer',
|
|
47
|
-
token: 'env:STATUSPAGE_TOKEN',
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export const STATUSPAGE_ACCESS = {
|
|
52
|
-
endpoints: {
|
|
53
|
-
'GET /components': {returns: ['id', 'name', 'status', 'updated_at']},
|
|
54
|
-
'GET /incidents': {returns: ['id', 'name', 'status', 'impact', 'created_at']},
|
|
55
|
-
'GET /incidents/:id': {returns: ['id', 'name', 'status', 'impact', 'body', 'components']},
|
|
56
|
-
'POST /incidents': {returns: ['id'], confirm: 'review' as const},
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export const STATUSPAGE_SURFACE = `## Included
|
|
61
|
-
|
|
62
|
-
### GET /components
|
|
63
|
-
List all monitored components and their current status
|
|
64
|
-
|
|
65
|
-
### GET /incidents
|
|
66
|
-
List recent incidents
|
|
67
|
-
|
|
68
|
-
### GET /incidents/:id
|
|
69
|
-
Get incident details
|
|
70
|
-
|
|
71
|
-
## Excluded
|
|
72
|
-
|
|
73
|
-
### POST /incidents
|
|
74
|
-
Create a new incident (requires confirmation)
|
|
75
|
-
`;
|
|
76
|
-
|
|
77
|
-
// ---------------------------------------------------------------------------
|
|
78
|
-
// Skill: incident-triage
|
|
79
|
-
// ---------------------------------------------------------------------------
|
|
80
|
-
|
|
81
|
-
export const TRIAGE_SKILL = `---
|
|
82
|
-
name: incident-triage
|
|
83
|
-
description: Methodology for triaging service incidents based on component status
|
|
84
|
-
trigger: When the user asks about service health, incidents, or outages
|
|
85
|
-
---
|
|
86
|
-
|
|
87
|
-
## Incident Triage
|
|
88
|
-
|
|
89
|
-
Follow this methodology when assessing service health:
|
|
90
|
-
|
|
91
|
-
1. **Check component status** — Query GET /components to see current state of all services
|
|
92
|
-
2. **Identify degraded components** — Any component not in "operational" status needs attention
|
|
93
|
-
3. **Assess severity** — Use the severity matrix from the oncall runbook
|
|
94
|
-
4. **Check recent incidents** — Query GET /incidents for correlated issues
|
|
95
|
-
5. **Recommend action** — Based on severity, recommend the appropriate response from the runbook
|
|
96
|
-
|
|
97
|
-
Always report the exact component names and their statuses. Never fabricate status data.
|
|
98
|
-
`;
|
|
99
|
-
|
|
100
|
-
// ---------------------------------------------------------------------------
|
|
101
|
-
// Knowledge: oncall-runbook
|
|
102
|
-
// ---------------------------------------------------------------------------
|
|
103
|
-
|
|
104
|
-
export const ONCALL_RUNBOOK = `# On-Call Runbook
|
|
105
|
-
|
|
106
|
-
## Severity Matrix
|
|
107
|
-
|
|
108
|
-
| Level | Criteria | Response Time | Escalation |
|
|
109
|
-
|-------|----------|---------------|------------|
|
|
110
|
-
| SEV1 | Multiple components down | 5 min | Page on-call lead immediately |
|
|
111
|
-
| SEV2 | Single component degraded | 15 min | Notify #incidents channel |
|
|
112
|
-
| SEV3 | Performance degradation | 1 hour | Create ticket |
|
|
113
|
-
| SEV4 | Cosmetic or minor | Next business day | Log for review |
|
|
114
|
-
|
|
115
|
-
## Key Contacts
|
|
116
|
-
|
|
117
|
-
- **On-call lead**: Alice (alice@example.com)
|
|
118
|
-
- **Platform team**: Bob (bob@example.com)
|
|
119
|
-
- **Database team**: Charlie (charlie@example.com)
|
|
120
|
-
|
|
121
|
-
## Components
|
|
122
|
-
|
|
123
|
-
- **api-gateway**: Main API entry point. SEV1 if down.
|
|
124
|
-
- **auth-service**: Authentication. SEV1 if down.
|
|
125
|
-
- **database-primary**: Primary Postgres. SEV1 if down.
|
|
126
|
-
- **worker-pool**: Background jobs. SEV2 if degraded.
|
|
127
|
-
- **cdn**: Static assets. SEV3 if degraded.
|
|
128
|
-
`;
|
|
129
|
-
|
|
130
|
-
// ---------------------------------------------------------------------------
|
|
131
|
-
// Automation: health-check
|
|
132
|
-
// ---------------------------------------------------------------------------
|
|
133
|
-
|
|
134
|
-
export const HEALTH_CHECK_AUTOMATION = `# Automation: Daily Health Check
|
|
135
|
-
|
|
136
|
-
Schedule: 0 8 * * *
|
|
137
|
-
|
|
138
|
-
## Check
|
|
139
|
-
Query the statuspage API for current component status. Report any components not in "operational" state.
|
|
140
|
-
|
|
141
|
-
## Output
|
|
142
|
-
Summary of component statuses with severity assessment per the oncall runbook.
|
|
143
|
-
|
|
144
|
-
## Delivery
|
|
145
|
-
Post to #ops-daily channel.
|
|
146
|
-
`;
|
|
147
|
-
|
|
148
|
-
// ---------------------------------------------------------------------------
|
|
149
|
-
// Mock StatusPage API
|
|
150
|
-
// ---------------------------------------------------------------------------
|
|
151
|
-
|
|
152
|
-
/** Deterministic mock data the API returns. */
|
|
153
|
-
export const MOCK_COMPONENTS = [
|
|
154
|
-
{id: 'comp-1', name: 'api-gateway', status: 'operational', updated_at: '2026-03-18T08:00:00Z'},
|
|
155
|
-
{id: 'comp-2', name: 'auth-service', status: 'operational', updated_at: '2026-03-18T08:00:00Z'},
|
|
156
|
-
{id: 'comp-3', name: 'database-primary', status: 'degraded_performance', updated_at: '2026-03-18T09:15:00Z'},
|
|
157
|
-
{id: 'comp-4', name: 'worker-pool', status: 'operational', updated_at: '2026-03-18T08:00:00Z'},
|
|
158
|
-
{id: 'comp-5', name: 'cdn', status: 'operational', updated_at: '2026-03-18T08:00:00Z'},
|
|
159
|
-
];
|
|
160
|
-
|
|
161
|
-
export const MOCK_INCIDENTS = [
|
|
162
|
-
{
|
|
163
|
-
id: 'inc-42',
|
|
164
|
-
name: 'Database latency spike',
|
|
165
|
-
status: 'investigating',
|
|
166
|
-
impact: 'minor',
|
|
167
|
-
created_at: '2026-03-18T09:10:00Z',
|
|
168
|
-
body: 'We are investigating elevated query latency on the primary database cluster.',
|
|
169
|
-
components: ['database-primary'],
|
|
170
|
-
},
|
|
171
|
-
];
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Create a mock StatusPage API server that returns deterministic data.
|
|
175
|
-
* Returns a handle with start/stop methods.
|
|
176
|
-
*/
|
|
177
|
-
export function createMockStatusPageApi() {
|
|
178
|
-
const requests: Array<{method: string; url: string}> = [];
|
|
179
|
-
|
|
180
|
-
const server = http.createServer((req, res) => {
|
|
181
|
-
const url = req.url ?? '';
|
|
182
|
-
const method = req.method ?? '';
|
|
183
|
-
requests.push({method, url});
|
|
184
|
-
|
|
185
|
-
const json = (data: unknown) => {
|
|
186
|
-
res.writeHead(200, {'Content-Type': 'application/json'});
|
|
187
|
-
res.end(JSON.stringify(data));
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
if (method === 'GET' && url === '/components') {
|
|
191
|
-
json(MOCK_COMPONENTS);
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if (method === 'GET' && url === '/incidents') {
|
|
196
|
-
json(MOCK_INCIDENTS);
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const incidentMatch = /^\/incidents\/([^/]+)$/.exec(url);
|
|
201
|
-
if (method === 'GET' && incidentMatch) {
|
|
202
|
-
const incident = MOCK_INCIDENTS.find((i) => i.id === incidentMatch[1]);
|
|
203
|
-
if (incident) {
|
|
204
|
-
json(incident);
|
|
205
|
-
} else {
|
|
206
|
-
res.writeHead(404);
|
|
207
|
-
res.end(JSON.stringify({error: 'Not found'}));
|
|
208
|
-
}
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
res.writeHead(404);
|
|
213
|
-
res.end(JSON.stringify({error: 'Not found'}));
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
let port = 0;
|
|
217
|
-
|
|
218
|
-
return {
|
|
219
|
-
server,
|
|
220
|
-
requests,
|
|
221
|
-
get port() { return port; },
|
|
222
|
-
start: () => new Promise<number>((resolve) => {
|
|
223
|
-
server.listen(0, '127.0.0.1', () => {
|
|
224
|
-
const addr = server.address();
|
|
225
|
-
port = typeof addr === 'object' && addr ? addr.port : 0;
|
|
226
|
-
resolve(port);
|
|
227
|
-
});
|
|
228
|
-
}),
|
|
229
|
-
stop: () => new Promise<void>((resolve, reject) => {
|
|
230
|
-
server.close((err) => (err ? reject(err) : resolve()));
|
|
231
|
-
}),
|
|
232
|
-
};
|
|
233
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2026 Amodal Labs, Inc.
|
|
4
|
-
* SPDX-License-Identifier: MIT
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import {createServer} from 'node:net';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Find a free TCP port, starting from `preferred`. If `preferred` is taken,
|
|
11
|
-
* tries incrementally higher ports up to `preferred + maxAttempts`.
|
|
12
|
-
*
|
|
13
|
-
* Uses the "bind then close" technique: creates a TCP server on the candidate
|
|
14
|
-
* port, reads the actual assigned port, then closes the server. This avoids
|
|
15
|
-
* TOCTOU races better than simply checking if a port is open — the OS reserves
|
|
16
|
-
* the port for the brief lifetime of the server.
|
|
17
|
-
*/
|
|
18
|
-
export async function findFreePort(preferred: number, maxAttempts = 10): Promise<number> {
|
|
19
|
-
for (let offset = 0; offset < maxAttempts; offset++) {
|
|
20
|
-
const candidate = preferred + offset;
|
|
21
|
-
const port = await tryPort(candidate);
|
|
22
|
-
if (port !== null) return port;
|
|
23
|
-
}
|
|
24
|
-
// Fallback: let the OS pick any available port
|
|
25
|
-
const port = await tryPort(0);
|
|
26
|
-
if (port !== null) return port;
|
|
27
|
-
throw new PortAllocationError(preferred, maxAttempts);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Attempt to bind a TCP server to the given port. Returns the port number on
|
|
32
|
-
* success, or null if the port is in use.
|
|
33
|
-
*/
|
|
34
|
-
function tryPort(port: number): Promise<number | null> {
|
|
35
|
-
return new Promise((resolve) => {
|
|
36
|
-
const server = createServer();
|
|
37
|
-
server.once('error', () => {
|
|
38
|
-
resolve(null);
|
|
39
|
-
});
|
|
40
|
-
server.listen(port, '127.0.0.1', () => {
|
|
41
|
-
const addr = server.address();
|
|
42
|
-
const assignedPort = typeof addr === 'object' && addr !== null ? addr.port : null;
|
|
43
|
-
server.close(() => {
|
|
44
|
-
resolve(assignedPort);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// ---------------------------------------------------------------------------
|
|
51
|
-
// Error
|
|
52
|
-
// ---------------------------------------------------------------------------
|
|
53
|
-
|
|
54
|
-
export class PortAllocationError extends Error {
|
|
55
|
-
readonly preferred: number;
|
|
56
|
-
readonly maxAttempts: number;
|
|
57
|
-
|
|
58
|
-
constructor(preferred: number, maxAttempts: number) {
|
|
59
|
-
super(
|
|
60
|
-
`Failed to find a free port starting from ${String(preferred)} ` +
|
|
61
|
-
`after ${String(maxAttempts)} attempts`,
|
|
62
|
-
);
|
|
63
|
-
this.name = 'PortAllocationError';
|
|
64
|
-
this.preferred = preferred;
|
|
65
|
-
this.maxAttempts = maxAttempts;
|
|
66
|
-
}
|
|
67
|
-
}
|