constructor-research-mcp 0.6.5 → 0.6.7-beta.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 +25 -4
- package/dist/agents.d.ts +2 -1
- package/dist/agents.js +3 -1
- package/dist/config.d.ts +4 -0
- package/dist/config.js +4 -0
- package/dist/deployment.d.ts +12 -0
- package/dist/deployment.js +210 -22
- package/dist/diagnose.d.ts +57 -0
- package/dist/diagnose.js +183 -0
- package/dist/logs.d.ts +16 -0
- package/dist/logs.js +51 -3
- package/dist/runtime.js +8 -2
- package/dist/schemas.js +1 -2
- package/dist/server.js +11 -6
- package/dist/store.d.ts +25 -0
- package/dist/text.d.ts +6 -0
- package/dist/text.js +208 -0
- package/dist/wait.d.ts +6 -3
- package/dist/wait.js +8 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Constructor Research MCP
|
|
2
2
|
|
|
3
|
+
> **0.6.7-beta.0** (npm `beta`; install with `npx -y constructor-research-mcp@beta install`, which keeps the agents on `beta`): every result's text carries what an agent acts on, for clients that show only text (OpenCode): project, application and service IDs, statuses, volumes and public URLs; per build its status, elapsed time, log coverage and step durations; on failure every error found in the whole kept build log, its cause (compile, transient, unknown), and whether each service runs the image this deployment built. A compile error is no longer rebuilt automatically. `update_app` without `project_id` finds the project from `application_id` when exactly one project has it. Lines written together with one timestamp are no longer dropped from kept logs, and secrets are masked in them. Includes 0.6.6 (IDs in the discovery and waiter text), which was not published.
|
|
4
|
+
>
|
|
3
5
|
> **0.6.5:** inside a Constructor desk, the MCP uses the access key the desk provides (`RESEARCH_ACCESS_KEY`), so the user needs no key of their own (once Research sets it); the Codex entry passes the desk's variables on to the MCP.
|
|
4
6
|
>
|
|
5
7
|
> **0.6.4:** with no project or desk named (and not inside a desk), `deploy_app` creates a new project from a short `project_name` and deploys there.
|
|
@@ -277,8 +279,15 @@ All required builds must succeed before existing services are changed. The MCP s
|
|
|
277
279
|
Learned from live runs (28 Oct 2026):
|
|
278
280
|
|
|
279
281
|
- **Upload settle.** A build started right after its Dockerfile was uploaded failed every time; with a pause it built first time. After any upload to a disk, builds on that disk wait until 30 s have passed (status `preparing`, message says so). `CONSTRUCTOR_UPLOAD_SETTLE_SECONDS` changes it; 0 disables.
|
|
280
|
-
- **Confirmed failure, one automatic rebuild.** The platform briefly reports `error` and then `in_progress` again, so an error counts only when seen twice for the same image. The
|
|
281
|
-
-
|
|
282
|
+
- **Confirmed failure, at most one automatic rebuild.** The platform briefly reports `error` and then `in_progress` again, so an error counts only when seen twice for the same image. The MCP then waits (up to 5 s) for the build log to end and classifies the failure from the whole kept log (`build_attempts`, with `cause` and `reason`):
|
|
283
|
+
- `compile`: compiler errors (`error[E…]` from rustc, `error TS…`, `file.go:3: error`, …). Not rebuilt: the same sources fail the same way. Fix them and repeat the call with `deployment_id` and that service's build.
|
|
284
|
+
- `transient`: pulling, registry, network or builder trouble, or files that had not reached the builder (`COPY failed`). Rebuilt once under a new image name, after re-uploading `local_path` sources and re-checking the Dockerfile on the disk.
|
|
285
|
+
- `unknown`: no log, or nothing the MCP recognises. Rebuilt once, and the result says the cause is uncertain.
|
|
286
|
+
|
|
287
|
+
`build_retried` names the image that was rebuilt.
|
|
288
|
+
|
|
289
|
+
- **Actionable failure.** A failed build returns `failure.image_id`, `image_name`, `desk_link`, `cause` and `cause_reason`, `diagnostics` (every error block found in the whole kept log with its location lines, bounded to about 4000 characters, first and last errors kept when some are left out, counted in `diagnostics_found`/`diagnostics_omitted`), `log_tail` (the last 20 lines), `log_coverage` (`complete`: the MCP followed the build to its end; `partial`; `live`; `none`) and `logs_hint` (`get_logs` with the image ID). With no log captured, the message says how to see it: Constructor does not keep build logs, so rebuild that Dockerfile from the UI and watch it live.
|
|
290
|
+
- **What runs now.** A deployment's services show the image each one runs and the image this deployment attempted (`attempted_image_id`, `runs_attempted_image`): after a failed build the old version keeps running, and the text says so instead of calling the app updated.
|
|
282
291
|
- **Readiness check.** After start, the MCP requests each public URL until it answers (any HTTP status below 500) or 60 s pass (status `verifying`). `readiness` is then `http_ok`, `not_responding` (with `readiness_checks` and a hint; services of the deployment that printed nothing since starting are named, with an ordered checklist: entrypoint not executable, wrong entrypoint path, nginx IPv6 listen, wrong listen address or port), or `no_public_url`. `CONSTRUCTOR_READINESS_SECONDS` changes the window; 0 disables.
|
|
283
292
|
|
|
284
293
|
## State and recovery
|
|
@@ -291,6 +300,16 @@ Terminal states: `built`, `started`, `stopped`, `failed`, `needs_reconciliation`
|
|
|
291
300
|
|
|
292
301
|
For `needs_reconciliation`, inspect the possible remote mutation before submitting a new operation. The server never blindly repeats an uncertain create. A `.lock` left by a process that no longer exists (a server killed or restarted mid-step) is removed automatically on the next operation; a lock held by a live process returns `busy`. Checkpoints remain available. No rollback or resource deletion is automated.
|
|
293
302
|
|
|
303
|
+
## What an agent reads (text results)
|
|
304
|
+
|
|
305
|
+
Some clients pass the agent only the text of a tool result, never `structuredContent` (OpenCode does). So the text carries everything needed to act; `structuredContent` is unchanged and has the full data.
|
|
306
|
+
|
|
307
|
+
- `get_deployment` with no arguments: every project with deployment on, each application with `application_id`, each service with `service_id`, status, `image_id`, volumes and public URL, and how to call `update_app`. With `project_id` or `desk_url`: the same for one project, plus desks and images.
|
|
308
|
+
- Deployments (`deploy_app`, `update_app`, `build_image`, `start_app`, `stop_app`, `get_deployment` with `deployment_id`, the wait command): status and elapsed time (`running for` or `took`), project and application IDs, each service with its ID, status, the image it runs (and whether that is the image this deployment attempted), volumes, public URL and readiness answer; each build with image ID, status, log coverage and the build steps with their durations; earlier failed attempts with cause and what the MCP did; the failure with its errors; the next step.
|
|
309
|
+
- A value Constructor did not return reads `unavailable`. Long lists are cut with a count; a text is at most 12,000 characters.
|
|
310
|
+
|
|
311
|
+
What Constructor does not report, and the MCP therefore cannot show: build start and end times (elapsed time is counted from the request; build age from the image's `created_at`), build stages (image pull, compile, push, rollout; the step durations come from the timestamps of the kept log lines and include pulling a step's base image), build attempt IDs separate from image IDs, and when a service changed image. A build log the MCP did not follow while the build ran is gone (Constructor answers "not found" after the build).
|
|
312
|
+
|
|
294
313
|
## Logs
|
|
295
314
|
|
|
296
315
|
Constructor serves logs only live, as a stream: a build log while the build runs, a service log for the service's current container. Each connection replays the log from the start, then streams. Nothing is kept afterwards: a finished build has no log, and a restarted container starts with an empty one, so a crash-looping service shows no log at all. The MCP therefore follows every build and service it starts and keeps the last 2000 lines of each in `logs/` in the state directory, where other MCP processes, the wait command and a restarted agent read them too. Files untouched for 14 days are deleted, and the oldest go first when all of them pass 100 MB.
|
|
@@ -300,12 +319,14 @@ Constructor serves logs only live, as a stream: a build log while the build runs
|
|
|
300
319
|
- Restarts: Constructor reports no restart count, so the MCP detects them in the stream. When a new container starts (the platform's "Container is waiting to start" line after the container's own lines, or a reconnect that begins with newer lines than were kept), it inserts `--- new container (restart N) ---` and keeps the old container's last lines above it, which usually show why it stopped. `get_logs` and the services in `get_deployment` report `restarts_seen` and `restarted_at`.
|
|
301
320
|
- `get_deployment` services also carry `status_changes`: the native statuses this MCP process saw, with times, once a service has had more than one.
|
|
302
321
|
- Lines that are only a timestamp are dropped, and identical consecutive lines are collapsed into one with a count (`(×5)`).
|
|
303
|
-
- A failed build or start puts the last 20 lines into `failure.log_tail`.
|
|
322
|
+
- A failed build or start puts the last 20 lines into `failure.log_tail` and the errors from the whole kept log into `failure.diagnostics`.
|
|
323
|
+
- Kept lines are masked: access keys (`rk-…`), bearer tokens, passwords in URLs and `NAME=value` pairs whose name says token, secret, password or key.
|
|
324
|
+
- Several lines written at once can carry the same timestamp; all of them are kept, and a reconnect skips exactly the ones already kept.
|
|
304
325
|
- `get_logs` takes `image_id`, `service_id` or `deployment_id` (all its builds and services) and `lines` (10–500, default 20). It also reads builds and services this MCP did not start, but only while they run.
|
|
305
326
|
|
|
306
327
|
## Waiting for long builds
|
|
307
328
|
|
|
308
|
-
Builds can run for many minutes. The MCP keeps executing in the background, but an agent that has ended its turn is not told when they finish. `dist/wait.js` (bin `constructor-research-wait`) blocks until the given deployments, or all in-progress ones when no ID is given, finish, and prints
|
|
329
|
+
Builds can run for many minutes. The MCP keeps executing in the background, but an agent that has ended its turn is not told when they finish. `dist/wait.js` (bin `constructor-research-wait`) blocks until the given deployments, or all in-progress ones when no ID is given, finish, and prints for each the same text `get_deployment` returns: status and elapsed time, services with IDs and public URLs, builds, failure with errors, next step. Exit codes: `0` finished, `2` needs the user (failed, key, upload, volume confirmation), `3` still running at `--max-minutes` (default 60), `4` nothing in progress. Do not pipe it into `tail` or `head`: a pipeline returns the last command's exit code, so a failure reads as success. If you must, run `set -o pipefail` first.
|
|
309
330
|
|
|
310
331
|
```sh
|
|
311
332
|
npx -y -p constructor-research-mcp@latest constructor-research-wait <deployment_id>
|
package/dist/agents.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare const SERVER = "constructor-research";
|
|
2
|
-
|
|
2
|
+
/** A beta stays on beta: its installer must not point agents back at latest. */
|
|
3
|
+
export declare const PACKAGE_SPEC: string;
|
|
3
4
|
export type Scope = "project" | "global";
|
|
4
5
|
export type Kind = "claude" | "codex" | "opencode" | "cline" | "jcode" | "mcpServers";
|
|
5
6
|
export interface Spec {
|
package/dist/agents.js
CHANGED
|
@@ -13,8 +13,10 @@ import { basename, dirname, join } from "node:path";
|
|
|
13
13
|
import { isDeepStrictEqual } from "node:util";
|
|
14
14
|
import { parse as parseToml } from "smol-toml";
|
|
15
15
|
import { DESK_ENV } from "./desk.js";
|
|
16
|
+
import { CHANNEL } from "./config.js";
|
|
16
17
|
export const SERVER = "constructor-research";
|
|
17
|
-
|
|
18
|
+
/** A beta stays on beta: its installer must not point agents back at latest. */
|
|
19
|
+
export const PACKAGE_SPEC = `constructor-research-mcp@${CHANNEL}`;
|
|
18
20
|
/** The command every agent runs. On Windows npx is a .cmd script, which agents start through cmd. */
|
|
19
21
|
export function mcpCommand(platform = process.platform) {
|
|
20
22
|
return platform === "win32"
|
package/dist/config.d.ts
CHANGED
|
@@ -36,8 +36,12 @@ export declare function configFromEnv(env?: NodeJS.ProcessEnv): Config;
|
|
|
36
36
|
export declare const DEFAULT_KEY_FILE = "~/.config/constructor-research/access-key.json";
|
|
37
37
|
/** Shell command that waits for deployments, carrying the settings that differ from the defaults. */
|
|
38
38
|
export declare function waitCommand(config: Config, ids: string[]): string;
|
|
39
|
+
/** The npm dist-tag this version is published under: a prerelease (0.6.7-beta.0) goes to beta. */
|
|
40
|
+
export declare const channel: (version: string) => "beta" | "latest";
|
|
39
41
|
/** This package's version, as published; the server reports it on connect. */
|
|
40
42
|
export declare const VERSION: string;
|
|
43
|
+
/** Where agents and hooks set up by this version get the MCP from: the same channel. */
|
|
44
|
+
export declare const CHANNEL: string;
|
|
41
45
|
/**
|
|
42
46
|
* How to run the wait CLI of this very version. Run through npx, the MCP lives in npx's
|
|
43
47
|
* cache, whose folder npm may replace at any time, so the hint names the package instead.
|
package/dist/config.js
CHANGED
|
@@ -83,8 +83,12 @@ export function waitCommand(config, ids) {
|
|
|
83
83
|
.join("");
|
|
84
84
|
return `${env}${waitProgram()} ${ids.join(" ")}`;
|
|
85
85
|
}
|
|
86
|
+
/** The npm dist-tag this version is published under: a prerelease (0.6.7-beta.0) goes to beta. */
|
|
87
|
+
export const channel = (version) => version.includes("-") ? "beta" : "latest";
|
|
86
88
|
/** This package's version, as published; the server reports it on connect. */
|
|
87
89
|
export const VERSION = JSON.parse(readFileSync(join(fileURLToPath(import.meta.url), "..", "..", "package.json"), "utf8")).version;
|
|
90
|
+
/** Where agents and hooks set up by this version get the MCP from: the same channel. */
|
|
91
|
+
export const CHANNEL = channel(VERSION);
|
|
88
92
|
/**
|
|
89
93
|
* How to run the wait CLI of this very version. Run through npx, the MCP lives in npx's
|
|
90
94
|
* cache, whose folder npm may replace at any time, so the hint names the package instead.
|
package/dist/deployment.d.ts
CHANGED
|
@@ -153,6 +153,12 @@ export declare class DeploymentEngine {
|
|
|
153
153
|
private supersede;
|
|
154
154
|
private resume;
|
|
155
155
|
observe(id: string): Promise<any>;
|
|
156
|
+
/**
|
|
157
|
+
* The project of an application, for an update that names only application_id. Earlier
|
|
158
|
+
* deployments on this machine are asked first, then every project with deployment on; the
|
|
159
|
+
* answer is used only when exactly one project has the application. Never by name.
|
|
160
|
+
*/
|
|
161
|
+
locateApplication(applicationId: string): Promise<string>;
|
|
156
162
|
/** Map of every deployment-enabled project with its applications and services. */
|
|
157
163
|
private overview;
|
|
158
164
|
get(raw: unknown): Promise<any>;
|
|
@@ -198,6 +204,12 @@ export declare class DeploymentEngine {
|
|
|
198
204
|
}> | undefined;
|
|
199
205
|
message: string;
|
|
200
206
|
};
|
|
207
|
+
/**
|
|
208
|
+
* The builds of this operation: each service's current image with its status, name and
|
|
209
|
+
* age, plus what the kept build log shows (coverage, steps with their durations, the step
|
|
210
|
+
* running now). Constructor reports only build_status; the rest comes from the log stamps.
|
|
211
|
+
*/
|
|
212
|
+
private buildViews;
|
|
201
213
|
private view;
|
|
202
214
|
}
|
|
203
215
|
/**
|
package/dist/deployment.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { randomUUID, createHash } from "node:crypto";
|
|
2
2
|
import { setTimeout as delay } from "node:timers/promises";
|
|
3
3
|
import { ToolError, segment as e } from "./api.js";
|
|
4
|
+
import { classify, diagnostics, steps } from "./diagnose.js";
|
|
4
5
|
import { deployInput, updateInput, buildInput, listInput, lifecycleInput, getInput, deleteInput, } from "./schemas.js";
|
|
5
6
|
const NOTICE = "Start requested; application readiness is unverified. Initial small deployments usually take 1–2 minutes; updates often take tens of seconds. These are estimates.";
|
|
6
7
|
export const terminal = new Set([
|
|
@@ -236,8 +237,32 @@ export class DeploymentEngine {
|
|
|
236
237
|
op.errorSeen[key] = image.id;
|
|
237
238
|
return "wait";
|
|
238
239
|
}
|
|
239
|
-
|
|
240
|
+
// Confirmed: read what the build printed to its end before deciding anything.
|
|
241
|
+
const log = await this.logs?.settle(image.id, "build");
|
|
242
|
+
const cause = classify(log?.lines ?? []);
|
|
243
|
+
op.attempts ??= {};
|
|
244
|
+
const attempts = (op.attempts[key] ??= []);
|
|
245
|
+
let attempt = attempts.find((a) => a.image_id === image.id);
|
|
246
|
+
if (!attempt) {
|
|
247
|
+
attempt = {
|
|
248
|
+
image_id: image.id,
|
|
249
|
+
image_name: image.name,
|
|
250
|
+
result: "error",
|
|
251
|
+
cause: cause.kind,
|
|
252
|
+
reason: cause.reason,
|
|
253
|
+
};
|
|
254
|
+
attempts.push(attempt);
|
|
255
|
+
}
|
|
256
|
+
if (op.retried[key]) {
|
|
257
|
+
attempt.next = "not rebuilt again: one automatic rebuild per service";
|
|
258
|
+
return "fail";
|
|
259
|
+
}
|
|
260
|
+
// The same sources fail the same way: a second identical build only costs minutes.
|
|
261
|
+
if (cause.kind === "compile") {
|
|
262
|
+
attempt.next =
|
|
263
|
+
"not rebuilt automatically: the sources do not compile, and an identical rebuild fails the same way";
|
|
240
264
|
return "fail";
|
|
265
|
+
}
|
|
241
266
|
op.retried[key] = image.name ?? image.id;
|
|
242
267
|
delete op.errorSeen[key];
|
|
243
268
|
if (this.files && source.local_path)
|
|
@@ -257,16 +282,36 @@ export class DeploymentEngine {
|
|
|
257
282
|
const pre = await this.files.preflight(op.project_id, [
|
|
258
283
|
{ service: key, ...source, ports: [] },
|
|
259
284
|
]);
|
|
260
|
-
if (pre.missing.length)
|
|
285
|
+
if (pre.missing.length) {
|
|
286
|
+
attempt.next = "not rebuilt: the Dockerfile is no longer on the disk";
|
|
261
287
|
return "fail";
|
|
288
|
+
}
|
|
262
289
|
}
|
|
263
290
|
delete op.images[key];
|
|
264
|
-
|
|
291
|
+
attempt.next =
|
|
292
|
+
cause.kind === "transient"
|
|
293
|
+
? "rebuilt once under a new name after re-checking the source files (likely transient)"
|
|
294
|
+
: "rebuilt once under a new name after re-checking the source files (cause uncertain)";
|
|
295
|
+
op.message = `Build for ${key} failed (${cause.kind === "transient" ? "likely transient" : "cause uncertain"}); the MCP re-checked the source files and is rebuilding once under a new name.`;
|
|
265
296
|
return "retry";
|
|
266
297
|
}
|
|
267
298
|
async buildFailed(op, key, image, deskId, dockerfile, service) {
|
|
268
299
|
const link = this.deskLink(op.project_id, deskId);
|
|
269
300
|
const first = op.retried?.[key];
|
|
301
|
+
const log = await this.logs?.settle(image.id, "build");
|
|
302
|
+
const lines = log?.lines ?? [];
|
|
303
|
+
const found = diagnostics(lines);
|
|
304
|
+
const attempt = op.attempts?.[key]?.find((a) => a.image_id === image.id);
|
|
305
|
+
const cause = attempt
|
|
306
|
+
? { kind: attempt.cause, reason: attempt.reason }
|
|
307
|
+
: classify(lines);
|
|
308
|
+
const coverage = !log
|
|
309
|
+
? "none"
|
|
310
|
+
: log.complete
|
|
311
|
+
? "complete"
|
|
312
|
+
: log.state === "live"
|
|
313
|
+
? "live"
|
|
314
|
+
: "partial";
|
|
270
315
|
op.status = "failed";
|
|
271
316
|
op.failure = {
|
|
272
317
|
stage: "build",
|
|
@@ -276,13 +321,45 @@ export class DeploymentEngine {
|
|
|
276
321
|
image_name: image.name,
|
|
277
322
|
first_image_name: first,
|
|
278
323
|
desk_link: link,
|
|
324
|
+
...(lines.length ? { log_tail: lines.slice(-20) } : {}),
|
|
325
|
+
...(found.lines.length
|
|
326
|
+
? {
|
|
327
|
+
diagnostics: found.lines,
|
|
328
|
+
diagnostics_found: found.found,
|
|
329
|
+
diagnostics_omitted: found.omitted,
|
|
330
|
+
}
|
|
331
|
+
: {}),
|
|
332
|
+
log_coverage: coverage,
|
|
333
|
+
log_lines_kept: lines.length,
|
|
334
|
+
cause: cause.kind,
|
|
335
|
+
cause_reason: cause.reason,
|
|
336
|
+
...(lines.length
|
|
337
|
+
? {
|
|
338
|
+
logs_hint: `get_logs with image_id ${image.id} shows up to 500 of the ${lines.length} kept lines.`,
|
|
339
|
+
}
|
|
340
|
+
: {}),
|
|
279
341
|
};
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
? "The
|
|
285
|
-
:
|
|
342
|
+
const tries = first
|
|
343
|
+
? ` twice (${first}, then ${image.name} after re-checking the files)`
|
|
344
|
+
: ` (${image.name})`;
|
|
345
|
+
const covered = coverage === "complete"
|
|
346
|
+
? "The MCP followed the build log to its end."
|
|
347
|
+
: coverage === "partial"
|
|
348
|
+
? "The kept build log may be incomplete (the connection broke or the MCP joined late)."
|
|
349
|
+
: coverage === "live"
|
|
350
|
+
? "The build log was still streaming when this was written; it may be incomplete."
|
|
351
|
+
: `No build log was captured: Constructor serves build logs only while the build runs. To see the error, open the desk (${link}), rebuild ${dockerfile} from the UI and watch the live log.`;
|
|
352
|
+
const why = cause.kind === "compile"
|
|
353
|
+
? `Cause: the sources do not compile${attempt?.next?.startsWith("not rebuilt automatically") ? "; not rebuilt automatically, because an identical rebuild fails the same way" : ""}.`
|
|
354
|
+
: cause.kind === "transient"
|
|
355
|
+
? `Likely cause: ${cause.reason}.`
|
|
356
|
+
: `Cause unknown: ${cause.reason}.`;
|
|
357
|
+
const errors = found.lines.length
|
|
358
|
+
? ` failure.diagnostics has ${found.found} error${found.found === 1 ? "" : "s"} from the build log${found.omitted ? ` (${found.omitted} left out)` : ""}; failure.log_tail has its last lines.`
|
|
359
|
+
: lines.length
|
|
360
|
+
? " The log shows no error the MCP recognises; failure.log_tail has its last lines."
|
|
361
|
+
: "";
|
|
362
|
+
op.message = `Image build${service ? ` for ${service}` : ""} failed${tries}. ${why}${errors} ${covered} Fix the Dockerfile or source, then repeat the call with deployment_id and this service with its build (builds that succeeded are kept).`;
|
|
286
363
|
}
|
|
287
364
|
/** Poll public URLs after start until they answer or readinessSeconds pass. */
|
|
288
365
|
async ready(op, appId) {
|
|
@@ -864,6 +941,49 @@ export class DeploymentEngine {
|
|
|
864
941
|
bad("Deployment ID not found.");
|
|
865
942
|
return this.view(op, false);
|
|
866
943
|
}
|
|
944
|
+
/**
|
|
945
|
+
* The project of an application, for an update that names only application_id. Earlier
|
|
946
|
+
* deployments on this machine are asked first, then every project with deployment on; the
|
|
947
|
+
* answer is used only when exactly one project has the application. Never by name.
|
|
948
|
+
*/
|
|
949
|
+
async locateApplication(applicationId) {
|
|
950
|
+
const check = async (project) => {
|
|
951
|
+
try {
|
|
952
|
+
return (await this.apps(project)).some((a) => a.id === applicationId);
|
|
953
|
+
}
|
|
954
|
+
catch (err) {
|
|
955
|
+
if (err instanceof ToolError && err.code === "needs_key")
|
|
956
|
+
throw err;
|
|
957
|
+
return false;
|
|
958
|
+
}
|
|
959
|
+
};
|
|
960
|
+
const known = new Set();
|
|
961
|
+
for (const id of await this.store.ids()) {
|
|
962
|
+
const op = await this.store.load(id).catch(() => undefined);
|
|
963
|
+
if (op?.application_id === applicationId &&
|
|
964
|
+
op.project_id &&
|
|
965
|
+
op.endpoint === this.store.endpoint)
|
|
966
|
+
known.add(op.project_id);
|
|
967
|
+
}
|
|
968
|
+
for (const p of known)
|
|
969
|
+
if (await check(p))
|
|
970
|
+
return p;
|
|
971
|
+
const projects = (await this.rows("/projects")).filter((p) => p.deployment_enabled);
|
|
972
|
+
const found = [];
|
|
973
|
+
let next = 0;
|
|
974
|
+
await Promise.all(Array.from({ length: Math.min(6, projects.length) }, async () => {
|
|
975
|
+
while (next < projects.length) {
|
|
976
|
+
const p = projects[next++];
|
|
977
|
+
if (await check(p.id))
|
|
978
|
+
found.push({ id: p.id, name: p.name });
|
|
979
|
+
}
|
|
980
|
+
}));
|
|
981
|
+
if (found.length === 1)
|
|
982
|
+
return found[0].id;
|
|
983
|
+
bad(found.length
|
|
984
|
+
? `Application ${applicationId} is in several projects (${found.map((p) => `${p.name}: ${p.id}`).join(", ")}). Repeat update_app with the right project_id.`
|
|
985
|
+
: `Application ${applicationId} was not found in any project with deployment on. Call get_deployment with no arguments: it lists every application with its project_id and service IDs. Then repeat update_app with project_id (or desk_url), application_id and the services.`);
|
|
986
|
+
}
|
|
867
987
|
/** Map of every deployment-enabled project with its applications and services. */
|
|
868
988
|
async overview() {
|
|
869
989
|
const all = await this.rows("/projects");
|
|
@@ -886,6 +1006,11 @@ export class DeploymentEngine {
|
|
|
886
1006
|
status: v.status,
|
|
887
1007
|
image_id: v.image_id,
|
|
888
1008
|
public_url: v.public_url,
|
|
1009
|
+
volumes: (v.volumes ?? []).map((x) => ({
|
|
1010
|
+
name: x.name,
|
|
1011
|
+
mount_point: x.mount_point,
|
|
1012
|
+
size_gb: x.size_gb,
|
|
1013
|
+
})),
|
|
889
1014
|
ports: (v.ports ?? []).map((x) => ({
|
|
890
1015
|
number: x.number,
|
|
891
1016
|
public: !!x.expose_to_internet,
|
|
@@ -1062,9 +1187,21 @@ export class DeploymentEngine {
|
|
|
1062
1187
|
};
|
|
1063
1188
|
op.message = `${op.failure.stage} failed${op.failure.service ? ` for ${op.failure.service}` : ""}. Please check the logs in Constructor.`;
|
|
1064
1189
|
const id = op.failure.service && op.services[op.failure.service];
|
|
1065
|
-
const log = id && (await this.logs?.peek(id, "service",
|
|
1190
|
+
const log = id && (await this.logs?.peek(id, "service", 200));
|
|
1066
1191
|
if (log) {
|
|
1067
|
-
|
|
1192
|
+
const found = diagnostics(log.lines);
|
|
1193
|
+
op.failure = {
|
|
1194
|
+
...op.failure,
|
|
1195
|
+
log_tail: log.lines.slice(-20),
|
|
1196
|
+
...(found.lines.length
|
|
1197
|
+
? {
|
|
1198
|
+
diagnostics: found.lines,
|
|
1199
|
+
diagnostics_found: found.found,
|
|
1200
|
+
diagnostics_omitted: found.omitted,
|
|
1201
|
+
}
|
|
1202
|
+
: {}),
|
|
1203
|
+
logs_hint: `get_logs with service_id ${id} shows up to 500 lines.`,
|
|
1204
|
+
};
|
|
1068
1205
|
op.message = `${op.failure.stage} failed for ${op.failure.service}. The last service log lines are in failure.log_tail (get_logs with the service ID shows up to 500).`;
|
|
1069
1206
|
}
|
|
1070
1207
|
}
|
|
@@ -1540,43 +1677,94 @@ export class DeploymentEngine {
|
|
|
1540
1677
|
readiness_checks: names.length ? checks : undefined,
|
|
1541
1678
|
message: op.message ??
|
|
1542
1679
|
(readiness === "http_ok"
|
|
1543
|
-
? `Started; the public URL answers (${names.map((n) => `${n}: HTTP ${checks[n].status}`).join(", ")}).`
|
|
1680
|
+
? `Started; the public URL answers (${names.map((n) => `${n} ${checks[n].url}: HTTP ${checks[n].status}`).join(", ")}).`
|
|
1544
1681
|
: readiness === "no_public_url"
|
|
1545
1682
|
? "Started. No public port, so readiness was not checked over HTTP."
|
|
1546
1683
|
: `Started, but ${failing.map((n) => `${n} (${checks[n].url}: ${checks[n].status === null ? "no answer" : `HTTP ${checks[n].status}`})`).join(", ")} did not answer within ${this.api.config.readinessSeconds ?? 60} s. ${silentHint(op.readiness.silent)}`),
|
|
1547
1684
|
};
|
|
1548
1685
|
}
|
|
1686
|
+
/**
|
|
1687
|
+
* The builds of this operation: each service's current image with its status, name and
|
|
1688
|
+
* age, plus what the kept build log shows (coverage, steps with their durations, the step
|
|
1689
|
+
* running now). Constructor reports only build_status; the rest comes from the log stamps.
|
|
1690
|
+
*/
|
|
1691
|
+
async buildViews(op, all) {
|
|
1692
|
+
const views = [];
|
|
1693
|
+
for (const [service, id] of Object.entries(op.images)) {
|
|
1694
|
+
const im = all.find((x) => x.id === id);
|
|
1695
|
+
const log = await this.logs
|
|
1696
|
+
?.peek(id, "build", 2000)
|
|
1697
|
+
.catch(() => undefined);
|
|
1698
|
+
const lines = log?.lines ?? [];
|
|
1699
|
+
const st = steps(lines);
|
|
1700
|
+
views.push({
|
|
1701
|
+
service,
|
|
1702
|
+
id,
|
|
1703
|
+
name: im?.name,
|
|
1704
|
+
build_status: im?.build_status ?? "unknown",
|
|
1705
|
+
...(im?.created_at ? { requested_at: im.created_at } : {}),
|
|
1706
|
+
log: {
|
|
1707
|
+
coverage: !log
|
|
1708
|
+
? "none"
|
|
1709
|
+
: log.complete
|
|
1710
|
+
? "complete"
|
|
1711
|
+
: log.state === "live"
|
|
1712
|
+
? "live"
|
|
1713
|
+
: "partial",
|
|
1714
|
+
lines_kept: lines.length,
|
|
1715
|
+
...(log?.last_received_at
|
|
1716
|
+
? { last_line_at: log.last_received_at }
|
|
1717
|
+
: {}),
|
|
1718
|
+
...(st.length ? { steps: st } : {}),
|
|
1719
|
+
},
|
|
1720
|
+
});
|
|
1721
|
+
}
|
|
1722
|
+
return views;
|
|
1723
|
+
}
|
|
1549
1724
|
async view(op, cache = true) {
|
|
1550
1725
|
let services = [];
|
|
1551
1726
|
let images = [];
|
|
1552
1727
|
try {
|
|
1553
|
-
if (op.project_id && Object.keys(op.images).length)
|
|
1554
|
-
|
|
1555
|
-
images = Object.entries(op.images).map(([service, id]) => ({
|
|
1556
|
-
service,
|
|
1557
|
-
id,
|
|
1558
|
-
build_status: all.find((x) => x.id === id)?.build_status ?? "unknown",
|
|
1559
|
-
}));
|
|
1560
|
-
}
|
|
1728
|
+
if (op.project_id && Object.keys(op.images).length)
|
|
1729
|
+
images = await this.buildViews(op, await this.images(op.project_id));
|
|
1561
1730
|
if (op.application_id && op.project_id) {
|
|
1562
1731
|
const a = await this.app(op.project_id, op.application_id);
|
|
1563
|
-
services = a.services.map((s) =>
|
|
1732
|
+
services = a.services.map((s) => {
|
|
1733
|
+
const v = this.observed(publicService(s, op.project_id, op.application_id));
|
|
1734
|
+
const failed = op.failure?.service === s.name;
|
|
1735
|
+
const attempted = (failed && op.failure?.image_id) || op.images[s.name];
|
|
1736
|
+
// Whether the service runs what this operation built: never assume it does.
|
|
1737
|
+
return attempted
|
|
1738
|
+
? {
|
|
1739
|
+
...v,
|
|
1740
|
+
attempted_image_id: attempted,
|
|
1741
|
+
runs_attempted_image: v.image_id === attempted,
|
|
1742
|
+
}
|
|
1743
|
+
: v;
|
|
1744
|
+
});
|
|
1564
1745
|
}
|
|
1565
1746
|
}
|
|
1566
1747
|
catch (err) {
|
|
1567
1748
|
if (!(err instanceof ToolError))
|
|
1568
1749
|
throw err;
|
|
1569
1750
|
}
|
|
1751
|
+
const end = terminal.has(op.status)
|
|
1752
|
+
? Date.parse(op.updated_at)
|
|
1753
|
+
: Date.now();
|
|
1570
1754
|
const result = {
|
|
1571
1755
|
deployment_id: op.id,
|
|
1572
1756
|
operation: op.kind,
|
|
1573
1757
|
status: op.status,
|
|
1574
1758
|
project_id: op.project_id,
|
|
1575
1759
|
application_id: op.application_id,
|
|
1760
|
+
application_name: op.input?.application_name,
|
|
1761
|
+
created_at: op.created_at,
|
|
1762
|
+
elapsed_seconds: Math.max(0, Math.round((end - Date.parse(op.created_at)) / 1000)),
|
|
1576
1763
|
images,
|
|
1577
1764
|
services,
|
|
1578
1765
|
failure: op.failure,
|
|
1579
1766
|
build_retried: op.retried,
|
|
1767
|
+
...(op.attempts ? { build_attempts: op.attempts } : {}),
|
|
1580
1768
|
replaced: op.replaced,
|
|
1581
1769
|
volumes_to_wipe: op.volumes_to_wipe,
|
|
1582
1770
|
...this.readinessView(op),
|
|
@@ -1591,7 +1779,7 @@ export class DeploymentEngine {
|
|
|
1591
1779
|
}
|
|
1592
1780
|
: {}),
|
|
1593
1781
|
next_action: op.status === "failed"
|
|
1594
|
-
? "Tell the user which stage/service failed and pass on the message. failure.
|
|
1782
|
+
? "Tell the user which stage/service failed and pass on the message. The text lists the errors found in the log (failure.diagnostics) or its last lines (failure.log_tail), with how much of the log was captured; get_logs with the image or service ID shows more. Do not use browser or other tools to investigate."
|
|
1595
1783
|
: terminal.has(op.status)
|
|
1596
1784
|
? undefined
|
|
1597
1785
|
: op.status === "needs_key"
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Masks what looks like a secret in a log line: access keys, bearer tokens, credentials in
|
|
3
|
+
* URLs and NAME=value pairs whose name says token, secret, password or key. Applied to every
|
|
4
|
+
* line the MCP keeps, so neither tool output nor the files in the state directory carry them.
|
|
5
|
+
*/
|
|
6
|
+
export declare function redact(line: string): string;
|
|
7
|
+
/** The time of a kept line, if stamped. */
|
|
8
|
+
export declare const stampOf: (line: string) => string | undefined;
|
|
9
|
+
/** A kept line without its time stamp. */
|
|
10
|
+
export declare const text: (line: string) => string;
|
|
11
|
+
export interface Diagnostics {
|
|
12
|
+
/** Error excerpts, oldest first, at most `blocks` blocks and `chars` characters. */
|
|
13
|
+
lines: string[];
|
|
14
|
+
/** Error blocks found, and how many were left out to keep the excerpt short. */
|
|
15
|
+
found: number;
|
|
16
|
+
omitted: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Every error the log shows, not only the last lines: compiler errors with their location
|
|
20
|
+
* lines, failed Dockerfile steps, tracebacks. Bounded, so a long log cannot flood the reply;
|
|
21
|
+
* when blocks are left out, the first and the last ones are kept (the first error is usually
|
|
22
|
+
* the cause, the last says which step failed).
|
|
23
|
+
*/
|
|
24
|
+
export declare function diagnostics(lines: string[], { blocks, perBlock, chars }?: {
|
|
25
|
+
blocks?: number | undefined;
|
|
26
|
+
chars?: number | undefined;
|
|
27
|
+
perBlock?: number | undefined;
|
|
28
|
+
}): Diagnostics;
|
|
29
|
+
/**
|
|
30
|
+
* Why a build failed, as far as its log tells:
|
|
31
|
+
* - compile: the sources do not build (compiler errors). A rebuild of the same sources fails
|
|
32
|
+
* the same way, so the MCP does not rebuild on its own.
|
|
33
|
+
* - transient: pulling, network or builder trouble, or files that had not reached the
|
|
34
|
+
* builder yet. One automatic rebuild may help.
|
|
35
|
+
* - unknown: no log, or nothing in it the MCP recognises.
|
|
36
|
+
*/
|
|
37
|
+
export type FailureKind = "compile" | "transient" | "unknown";
|
|
38
|
+
export declare function classify(lines: string[]): {
|
|
39
|
+
kind: FailureKind;
|
|
40
|
+
reason: string;
|
|
41
|
+
};
|
|
42
|
+
export interface Step {
|
|
43
|
+
step: string;
|
|
44
|
+
at: string;
|
|
45
|
+
/** Seconds until the next step started, or until the last line for the last step. */
|
|
46
|
+
seconds: number;
|
|
47
|
+
/** The last step ran until the log ended (its duration may be cut short). */
|
|
48
|
+
last?: boolean;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Build steps and how long each took, from the stamps of the kept lines: "STEP 2/9: RUN …"
|
|
52
|
+
* (buildah), "Step 2/9 : RUN …" (docker) and "#7 [2/9] RUN …" (BuildKit). An estimate:
|
|
53
|
+
* Constructor reports no build stages, and a step's time includes pulling its base image.
|
|
54
|
+
*/
|
|
55
|
+
export declare function steps(lines: string[], max?: number): Step[];
|
|
56
|
+
/** "5m 11s", "42s", "1h 3m". */
|
|
57
|
+
export declare function duration(seconds: number): string;
|