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/dist/diagnose.js
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// What a build or service log says, for an agent that reads only text: the errors in it, how
|
|
2
|
+
// long each build step took, and whether a rebuild could help. Everything here works on the
|
|
3
|
+
// lines the MCP kept (LogFollower); Constructor itself reports no stages, timings or causes.
|
|
4
|
+
const STAMP = /^(\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d+)?Z) ?/;
|
|
5
|
+
/**
|
|
6
|
+
* Masks what looks like a secret in a log line: access keys, bearer tokens, credentials in
|
|
7
|
+
* URLs and NAME=value pairs whose name says token, secret, password or key. Applied to every
|
|
8
|
+
* line the MCP keeps, so neither tool output nor the files in the state directory carry them.
|
|
9
|
+
*/
|
|
10
|
+
export function redact(line) {
|
|
11
|
+
return line
|
|
12
|
+
.replace(/\brk-[A-Za-z0-9_-]{6,}/g, "rk-…")
|
|
13
|
+
.replace(/\b(Bearer|Basic)\s+[A-Za-z0-9._~+/=-]{8,}/gi, "$1 …")
|
|
14
|
+
.replace(/(:\/\/[^\s/:@]+):[^\s/@]+@/g, "$1:…@")
|
|
15
|
+
.replace(/\b([A-Za-z0-9_.-]*(?:TOKEN|SECRET|PASSWORD|PASSWD|PWD|API_?KEY|ACCESS_?KEY|PRIVATE_?KEY|CREDENTIALS?)[A-Za-z0-9_.-]*)(\s*[:=]\s*)("[^"]*"|'[^']*'|[^\s,;]+)/gi, "$1$2…");
|
|
16
|
+
}
|
|
17
|
+
/** The time of a kept line, if stamped. */
|
|
18
|
+
export const stampOf = (line) => STAMP.exec(line)?.[1];
|
|
19
|
+
/** A kept line without its time stamp. */
|
|
20
|
+
export const text = (line) => line.replace(STAMP, "").replace(/^#\d+ \d+(\.\d+)? /, "");
|
|
21
|
+
/** Where an error block starts; the lines after it, up to a blank one or the next block, belong to it. */
|
|
22
|
+
const START = [
|
|
23
|
+
/^error(\[E\d+\])?: /, // rustc, cargo
|
|
24
|
+
/^error: could not compile/,
|
|
25
|
+
/\berror TS\d+:/, // tsc
|
|
26
|
+
/^(npm (ERR!|error)|ERR_PNPM_|error Command failed|yarn error)/i,
|
|
27
|
+
/^Traceback \(most recent call last\):/,
|
|
28
|
+
/^(SyntaxError|TypeError|ReferenceError|ModuleNotFoundError|ImportError|NameError): /,
|
|
29
|
+
/^[\w./-]+\.(go|py|ts|tsx|js|java|kt|c|cc|cpp|h|cs|rb|php):\d+(:\d+)?: (fatal )?error/i,
|
|
30
|
+
/^\S+\.java:\d+: error:/,
|
|
31
|
+
/\b(FATAL|ERROR)\b[: ]/,
|
|
32
|
+
/\b(failed to solve|did not complete successfully|returned a non-zero code|exit code: [1-9]\d*|exit status [1-9]\d*|executor failed running)/i,
|
|
33
|
+
/^Error: /,
|
|
34
|
+
/^(COPY|ADD) failed|failed to compute cache key|no such file or directory/i,
|
|
35
|
+
];
|
|
36
|
+
/** Lines that continue a block: compiler context, code frames and notes. */
|
|
37
|
+
const CONTINUE = /^(\s+|-->|\s*\||\s*= (note|help)|\s*\^|\s*at\s|\d+ \|)/;
|
|
38
|
+
const NOISE = /^(warning(\[\w+\])?: |\s*Compiling |\s*Downloaded |\s*Downloading )/;
|
|
39
|
+
/**
|
|
40
|
+
* Every error the log shows, not only the last lines: compiler errors with their location
|
|
41
|
+
* lines, failed Dockerfile steps, tracebacks. Bounded, so a long log cannot flood the reply;
|
|
42
|
+
* when blocks are left out, the first and the last ones are kept (the first error is usually
|
|
43
|
+
* the cause, the last says which step failed).
|
|
44
|
+
*/
|
|
45
|
+
export function diagnostics(lines, { blocks = 12, perBlock = 8, chars = 4000 } = {}) {
|
|
46
|
+
const all = [];
|
|
47
|
+
let current;
|
|
48
|
+
const seen = new Set();
|
|
49
|
+
for (const raw of lines) {
|
|
50
|
+
const line = text(raw).trimEnd();
|
|
51
|
+
if (!line.trim()) {
|
|
52
|
+
current = undefined;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (NOISE.test(line)) {
|
|
56
|
+
current = undefined;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (START.some((r) => r.test(line))) {
|
|
60
|
+
const key = line.replace(/\s+/g, " ");
|
|
61
|
+
if (seen.has(key)) {
|
|
62
|
+
current = undefined;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
seen.add(key);
|
|
66
|
+
current = [line];
|
|
67
|
+
all.push(current);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (current && CONTINUE.test(line) && current.length < perBlock)
|
|
71
|
+
current.push(line);
|
|
72
|
+
else if (current && !CONTINUE.test(line))
|
|
73
|
+
current = undefined;
|
|
74
|
+
}
|
|
75
|
+
// Keep the first blocks and the last two when there are too many.
|
|
76
|
+
let kept = all;
|
|
77
|
+
if (all.length > blocks)
|
|
78
|
+
kept = [...all.slice(0, blocks - 2), ...all.slice(-2)];
|
|
79
|
+
const out = [];
|
|
80
|
+
let size = 0;
|
|
81
|
+
let used = 0;
|
|
82
|
+
for (const block of kept) {
|
|
83
|
+
const cost = block.reduce((n, l) => n + l.length + 1, 0);
|
|
84
|
+
if (size + cost > chars && used)
|
|
85
|
+
break;
|
|
86
|
+
out.push(...block.map((l) => (l.length > 400 ? l.slice(0, 400) + "…" : l)));
|
|
87
|
+
size += cost;
|
|
88
|
+
used++;
|
|
89
|
+
}
|
|
90
|
+
return { lines: out, found: all.length, omitted: all.length - used };
|
|
91
|
+
}
|
|
92
|
+
const TRANSIENT = [
|
|
93
|
+
/spurious network error|failed to (download|fetch)|could ?n[o']t resolve host|ETIMEDOUT|ECONNRESET|EAI_AGAIN/i,
|
|
94
|
+
/i\/o timeout|connection (reset|refused)|TLS handshake timeout|context deadline exceeded|temporary failure in name resolution|no such host/i,
|
|
95
|
+
/toomanyrequests|rate limit|\b50[234]\b.*(Service Unavailable|Bad Gateway|Gateway Time-?out)|unexpected EOF/i,
|
|
96
|
+
/registries\.conf|error (pulling|initializing) image|failed to pull|pull access denied|manifest unknown|error creating overlay mount|no space left on device/i,
|
|
97
|
+
/(COPY|ADD) failed|failed to compute cache key|"\/[^"]+": not found|stat .*: no such file or directory/i,
|
|
98
|
+
];
|
|
99
|
+
const COMPILE = [
|
|
100
|
+
/^error\[E\d+\]: /, // rustc; a bare "error:" is also cargo's network trouble
|
|
101
|
+
/\berror TS\d+:/,
|
|
102
|
+
/^[\w./-]+\.(go|java|kt|c|cc|cpp|h|cs|ts|tsx|js):\d+(:\d+)?: (fatal )?error/i,
|
|
103
|
+
/^\S+\.java:\d+: error:/,
|
|
104
|
+
/^(SyntaxError|TypeError|ReferenceError): /,
|
|
105
|
+
/Failed to compile|Build failed with \d+ errors?|error: could not compile/i,
|
|
106
|
+
];
|
|
107
|
+
export function classify(lines) {
|
|
108
|
+
if (!lines.length)
|
|
109
|
+
return {
|
|
110
|
+
kind: "unknown",
|
|
111
|
+
reason: "no build log was captured, so the cause is unknown",
|
|
112
|
+
};
|
|
113
|
+
const plain = lines.map(text);
|
|
114
|
+
const hit = (patterns) => plain.find((l) => patterns.some((r) => r.test(l)));
|
|
115
|
+
const compile = hit(COMPILE);
|
|
116
|
+
if (compile)
|
|
117
|
+
return {
|
|
118
|
+
kind: "compile",
|
|
119
|
+
reason: `the log shows a compile error (${compile.trim().slice(0, 160)})`,
|
|
120
|
+
};
|
|
121
|
+
const transient = hit(TRANSIENT);
|
|
122
|
+
if (transient)
|
|
123
|
+
return {
|
|
124
|
+
kind: "transient",
|
|
125
|
+
reason: `the log points to a pull, network, builder or file-transfer problem (${transient.trim().slice(0, 160)})`,
|
|
126
|
+
};
|
|
127
|
+
return {
|
|
128
|
+
kind: "unknown",
|
|
129
|
+
reason: plain.some((l) => START.some((r) => r.test(l)))
|
|
130
|
+
? "the log shows errors, but not whether a rebuild could help"
|
|
131
|
+
: "the log shows no error the MCP recognises",
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Build steps and how long each took, from the stamps of the kept lines: "STEP 2/9: RUN …"
|
|
136
|
+
* (buildah), "Step 2/9 : RUN …" (docker) and "#7 [2/9] RUN …" (BuildKit). An estimate:
|
|
137
|
+
* Constructor reports no build stages, and a step's time includes pulling its base image.
|
|
138
|
+
*/
|
|
139
|
+
export function steps(lines, max = 15) {
|
|
140
|
+
const found = [];
|
|
141
|
+
const header = /^(STEP \d+\/\d+: .*|Step \d+\/\d+ : .*|#\d+ \[(?:[\w-]+ )?\d+\/\d+\] .*)$/;
|
|
142
|
+
let lastStamp;
|
|
143
|
+
for (const raw of lines) {
|
|
144
|
+
const at = stampOf(raw);
|
|
145
|
+
if (at)
|
|
146
|
+
lastStamp = at;
|
|
147
|
+
const line = text(raw).trim();
|
|
148
|
+
if (!at || !header.test(line))
|
|
149
|
+
continue;
|
|
150
|
+
const step = line.replace(/^#\d+ /, "");
|
|
151
|
+
if (found.some((f) => f.step === step))
|
|
152
|
+
continue;
|
|
153
|
+
found.push({
|
|
154
|
+
step: step.length > 120 ? step.slice(0, 120) + "…" : step,
|
|
155
|
+
at,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
const out = found.map((f, n) => {
|
|
159
|
+
const end = found[n + 1]?.at ?? lastStamp ?? f.at;
|
|
160
|
+
return {
|
|
161
|
+
...f,
|
|
162
|
+
seconds: Math.max(0, Math.round((Date.parse(end) - Date.parse(f.at)) / 1000)),
|
|
163
|
+
...(n === found.length - 1 ? { last: true } : {}),
|
|
164
|
+
};
|
|
165
|
+
});
|
|
166
|
+
// The longest steps matter most when there are many.
|
|
167
|
+
if (out.length <= max)
|
|
168
|
+
return out;
|
|
169
|
+
const keep = new Set([...out]
|
|
170
|
+
.sort((a, b) => b.seconds - a.seconds)
|
|
171
|
+
.slice(0, max)
|
|
172
|
+
.map((s) => s.at + s.step));
|
|
173
|
+
return out.filter((s) => keep.has(s.at + s.step));
|
|
174
|
+
}
|
|
175
|
+
/** "5m 11s", "42s", "1h 3m". */
|
|
176
|
+
export function duration(seconds) {
|
|
177
|
+
const s = Math.max(0, Math.round(seconds));
|
|
178
|
+
if (s < 60)
|
|
179
|
+
return `${s}s`;
|
|
180
|
+
if (s < 3600)
|
|
181
|
+
return `${Math.floor(s / 60)}m ${s % 60}s`;
|
|
182
|
+
return `${Math.floor(s / 3600)}h ${Math.floor((s % 3600) / 60)}m`;
|
|
183
|
+
}
|
package/dist/logs.d.ts
CHANGED
|
@@ -22,6 +22,14 @@ export interface LogView {
|
|
|
22
22
|
restarted_at?: string[];
|
|
23
23
|
/** When the MCP followed this log; lines printed outside these periods were never seen. */
|
|
24
24
|
watched?: Period[];
|
|
25
|
+
/**
|
|
26
|
+
* A build log the MCP followed to its end without a connection problem: these lines are all
|
|
27
|
+
* the build printed (but for `dropped` older ones). False while live, after an error, or
|
|
28
|
+
* without lines.
|
|
29
|
+
*/
|
|
30
|
+
complete?: boolean;
|
|
31
|
+
/** Older lines dropped to keep the last KEEP. */
|
|
32
|
+
dropped?: number;
|
|
25
33
|
message?: string;
|
|
26
34
|
}
|
|
27
35
|
/**
|
|
@@ -55,6 +63,14 @@ export declare class LogFollower {
|
|
|
55
63
|
follow(id: string, kind?: LogKind): void;
|
|
56
64
|
/** Last `count` lines, following first if the build or service may still be running. */
|
|
57
65
|
tail(id: string, kind?: LogKind, count?: number, waitMs?: number): Promise<LogView>;
|
|
66
|
+
/** How long settle() waits for a build log to end; tests shorten it. */
|
|
67
|
+
settleMs: number;
|
|
68
|
+
/**
|
|
69
|
+
* All kept lines of a build that just ended, after waiting (up to settleMs) for its stream
|
|
70
|
+
* to deliver the last lines and close: a failure is read from the final log, not an early
|
|
71
|
+
* live one. Undefined when the MCP has no lines.
|
|
72
|
+
*/
|
|
73
|
+
settle(id: string, kind?: LogKind): Promise<LogView | undefined>;
|
|
58
74
|
/** Kept lines without contacting the platform. */
|
|
59
75
|
peek(id: string, kind?: LogKind, count?: number): Promise<LogView | undefined>;
|
|
60
76
|
close(): Promise<void>;
|
package/dist/logs.js
CHANGED
|
@@ -2,6 +2,7 @@ import { mkdir, readdir, readFile, rm, stat, writeFile, } from "node:fs/promises
|
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { setTimeout as delay } from "node:timers/promises";
|
|
4
4
|
import { ToolError, segment } from "./api.js";
|
|
5
|
+
import { redact } from "./diagnose.js";
|
|
5
6
|
/** Lines kept per build or service, in memory and in its file. */
|
|
6
7
|
export const KEEP = 2000;
|
|
7
8
|
/** The most lines get_logs returns at once. */
|
|
@@ -71,6 +72,7 @@ export class LogFollower {
|
|
|
71
72
|
restarts: [],
|
|
72
73
|
state: "live",
|
|
73
74
|
saved: 0,
|
|
75
|
+
total: 0,
|
|
74
76
|
watched: [],
|
|
75
77
|
};
|
|
76
78
|
this.logs.set(`${kind}:${id}`, log);
|
|
@@ -110,6 +112,25 @@ export class LogFollower {
|
|
|
110
112
|
}
|
|
111
113
|
return this.view(id, log, count);
|
|
112
114
|
}
|
|
115
|
+
/** How long settle() waits for a build log to end; tests shorten it. */
|
|
116
|
+
settleMs = 5000;
|
|
117
|
+
/**
|
|
118
|
+
* All kept lines of a build that just ended, after waiting (up to settleMs) for its stream
|
|
119
|
+
* to deliver the last lines and close: a failure is read from the final log, not an early
|
|
120
|
+
* live one. Undefined when the MCP has no lines.
|
|
121
|
+
*/
|
|
122
|
+
async settle(id, kind = "build") {
|
|
123
|
+
let log = this.logs.get(`${kind}:${id}`) ?? (await this.load(id, kind));
|
|
124
|
+
if (!log)
|
|
125
|
+
return undefined;
|
|
126
|
+
if (!log.reader && log.state !== "finished")
|
|
127
|
+
this.follow(id, kind);
|
|
128
|
+
log = this.logs.get(`${kind}:${id}`);
|
|
129
|
+
const deadline = Date.now() + this.settleMs;
|
|
130
|
+
while (log.reader && Date.now() < deadline)
|
|
131
|
+
await delay(100);
|
|
132
|
+
return log.lines.length ? this.view(id, log, KEEP) : undefined;
|
|
133
|
+
}
|
|
113
134
|
/** Kept lines without contacting the platform. */
|
|
114
135
|
async peek(id, kind = "build", count = 20) {
|
|
115
136
|
const log = this.logs.get(`${kind}:${id}`) ?? (await this.load(id, kind));
|
|
@@ -152,12 +173,19 @@ export class LogFollower {
|
|
|
152
173
|
const more = log.lines.length > lines.length
|
|
153
174
|
? `${log.lines.length} lines are kept; ask for more with lines (up to ${SHOW}).`
|
|
154
175
|
: undefined;
|
|
176
|
+
const dropped = Math.max(0, log.total - log.lines.length);
|
|
155
177
|
return {
|
|
156
178
|
kind: log.kind,
|
|
157
179
|
id,
|
|
158
180
|
state: log.state,
|
|
159
181
|
lines,
|
|
160
182
|
last_received_at: log.received,
|
|
183
|
+
...(service
|
|
184
|
+
? {}
|
|
185
|
+
: {
|
|
186
|
+
complete: log.state === "finished" && !log.error && log.lines.length > 0,
|
|
187
|
+
}),
|
|
188
|
+
...(dropped ? { dropped } : {}),
|
|
161
189
|
...(restarts
|
|
162
190
|
? { restarts_seen: restarts, restarted_at: log.restarts }
|
|
163
191
|
: {}),
|
|
@@ -197,6 +225,8 @@ export class LogFollower {
|
|
|
197
225
|
failures = 0;
|
|
198
226
|
log.fresh = true;
|
|
199
227
|
log.pending = [];
|
|
228
|
+
log.replaying = !!log.last;
|
|
229
|
+
log.replaySame = 0;
|
|
200
230
|
let partial = "";
|
|
201
231
|
const decoder = new TextDecoder();
|
|
202
232
|
for await (const chunk of response.body) {
|
|
@@ -276,9 +306,21 @@ export class LogFollower {
|
|
|
276
306
|
this.keep(log, h);
|
|
277
307
|
}
|
|
278
308
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
log.last
|
|
309
|
+
// A reconnect replays what is kept: skip up to the last line seen, counting lines that
|
|
310
|
+
// share its stamp. On a live stream equal stamps are new lines, never repeats.
|
|
311
|
+
if (log.replaying && log.last) {
|
|
312
|
+
if (stamp < log.last)
|
|
313
|
+
return;
|
|
314
|
+
if (stamp === log.last && ++log.replaySame <= (log.lastCount ?? 1))
|
|
315
|
+
return;
|
|
316
|
+
log.replaying = false;
|
|
317
|
+
}
|
|
318
|
+
if (stamp === log.last)
|
|
319
|
+
log.lastCount = (log.lastCount ?? 1) + 1;
|
|
320
|
+
else {
|
|
321
|
+
log.last = stamp;
|
|
322
|
+
log.lastCount = 1;
|
|
323
|
+
}
|
|
282
324
|
// A line that is only a timestamp carries nothing to show.
|
|
283
325
|
if (line.length > stamp.length)
|
|
284
326
|
this.keep(log, line);
|
|
@@ -295,6 +337,7 @@ export class LogFollower {
|
|
|
295
337
|
}
|
|
296
338
|
keep(log, line) {
|
|
297
339
|
log.received = new Date().toISOString();
|
|
340
|
+
line = redact(line);
|
|
298
341
|
if (line === log.previous && log.lines.length) {
|
|
299
342
|
log.repeats = (log.repeats ?? 1) + 1;
|
|
300
343
|
log.lines[log.lines.length - 1] = `${line} (×${log.repeats})`;
|
|
@@ -302,6 +345,7 @@ export class LogFollower {
|
|
|
302
345
|
}
|
|
303
346
|
log.previous = line;
|
|
304
347
|
log.repeats = 1;
|
|
348
|
+
log.total++;
|
|
305
349
|
log.lines.push(line.length > WIDTH ? line.slice(0, WIDTH) + "…" : line);
|
|
306
350
|
if (log.lines.length > KEEP)
|
|
307
351
|
log.lines.shift();
|
|
@@ -317,10 +361,12 @@ export class LogFollower {
|
|
|
317
361
|
state: log.reader && !force ? "live" : log.state,
|
|
318
362
|
lines: log.lines,
|
|
319
363
|
last: log.last,
|
|
364
|
+
last_count: log.lastCount,
|
|
320
365
|
restarts: log.restarts,
|
|
321
366
|
received: log.received,
|
|
322
367
|
error: log.error,
|
|
323
368
|
watched: log.watched,
|
|
369
|
+
total: log.total,
|
|
324
370
|
}), { mode: 0o600 });
|
|
325
371
|
if (Date.now() - this.rotated > 60 * 60 * 1000)
|
|
326
372
|
await this.rotate();
|
|
@@ -339,10 +385,12 @@ export class LogFollower {
|
|
|
339
385
|
lines: Array.isArray(kept.lines) ? kept.lines.slice(-KEEP) : [],
|
|
340
386
|
state: kept.state === "finished" ? "finished" : "unavailable",
|
|
341
387
|
last: kept.last,
|
|
388
|
+
lastCount: Number.isInteger(kept.last_count) ? kept.last_count : 1,
|
|
342
389
|
restarts: Array.isArray(kept.restarts) ? kept.restarts : [],
|
|
343
390
|
received: kept.received,
|
|
344
391
|
error: kept.error,
|
|
345
392
|
saved: 0,
|
|
393
|
+
total: Number.isInteger(kept.total) ? kept.total : 0,
|
|
346
394
|
watched: Array.isArray(kept.watched)
|
|
347
395
|
? kept.watched.filter((p) => typeof p?.from === "string")
|
|
348
396
|
: [],
|
package/dist/runtime.js
CHANGED
|
@@ -194,6 +194,12 @@ export class DeploymentRuntime {
|
|
|
194
194
|
status: op.status,
|
|
195
195
|
project_id: op.project_id,
|
|
196
196
|
application_id: op.application_id,
|
|
197
|
+
created_at: op.created_at,
|
|
198
|
+
elapsed_seconds: Math.max(0, Math.round(((terminal.has(op.status) || paused.has(op.status)
|
|
199
|
+
? Date.parse(op.updated_at)
|
|
200
|
+
: Date.now()) -
|
|
201
|
+
Date.parse(op.created_at)) /
|
|
202
|
+
1000)),
|
|
197
203
|
readiness: ready.readiness,
|
|
198
204
|
readiness_checks: ready.readiness_checks,
|
|
199
205
|
message: [ready.message ?? op.result?.message, replacedNote(op.replaced)]
|
|
@@ -209,7 +215,7 @@ export class DeploymentRuntime {
|
|
|
209
215
|
? "paused"
|
|
210
216
|
: "background",
|
|
211
217
|
next_action: op.status === "failed"
|
|
212
|
-
? "Tell the user which stage/service failed and pass on the message. failure.
|
|
218
|
+
? "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 investigate using browser or other tools."
|
|
213
219
|
: op.status === "needs_key"
|
|
214
220
|
? `${this.engine.api.keyHelp("Constructor rejected the access key, or none is set.")} Then check this deployment again.`
|
|
215
221
|
: op.status === "needs_upload"
|
|
@@ -220,7 +226,7 @@ export class DeploymentRuntime {
|
|
|
220
226
|
? "Inspect the uncertain mutation in Constructor before submitting a new operation."
|
|
221
227
|
: terminal.has(op.status)
|
|
222
228
|
? undefined
|
|
223
|
-
: `NOT FINISHED: do not answer the user yet. Run now, in the foreground: \`${waitCommand(this.engine.api.config, [op.id])}\`. It returns when the deployment ends and prints the public URL or what failed. No shell: call get_deployment with this deployment_id and wait_seconds=45 again, until it is finished.`,
|
|
229
|
+
: `NOT FINISHED: do not answer the user yet. Run now, in the foreground: \`${waitCommand(this.engine.api.config, [op.id])}\`. It returns when the deployment ends and prints the public URL or what failed; do not pipe it (\`| tail\` hides its exit code: 0 finished, 2 failed or needs the user, 3 still running). No shell: call get_deployment with this deployment_id and wait_seconds=45 again, until it is finished.`,
|
|
224
230
|
};
|
|
225
231
|
}
|
|
226
232
|
async wait(id, milliseconds) {
|
package/dist/schemas.js
CHANGED
|
@@ -168,8 +168,7 @@ export const deployInput = z
|
|
|
168
168
|
.refine((x) => !!x.deployment_id || (!!x.application_name && !!x.services), "New deployments require application_name and services. To resume, provide deployment_id and optional service overrides.");
|
|
169
169
|
export const updateInput = z
|
|
170
170
|
.strictObject({ ...deploymentShape, application_id: id.optional() })
|
|
171
|
-
.refine((x) => !!x.deployment_id ||
|
|
172
|
-
((!!x.project_id || !!x.desk_url) && !!x.application_id && !!x.services), "Updates require desk_url or project_id, plus application_id and services, or deployment_id to resume.");
|
|
171
|
+
.refine((x) => !!x.deployment_id || (!!x.application_id && !!x.services), "update_app needs application_id and services (or deployment_id to resume). Get the IDs with get_deployment: with no arguments it lists every application with its project_id, application_id and service IDs. Pass project_id or desk_url too; without them the MCP looks the project up from application_id.");
|
|
173
172
|
export const lifecycleInput = z.strictObject({
|
|
174
173
|
project_id: id,
|
|
175
174
|
application_id: id,
|
package/dist/server.js
CHANGED
|
@@ -31,6 +31,7 @@ const DESK_DEFAULT = new Set([
|
|
|
31
31
|
]);
|
|
32
32
|
import { ZodError } from "zod";
|
|
33
33
|
import { buildInput, listInput, deployInput, updateInput, lifecycleInput, deleteInput, getInput, logsInput, listFilesInput, createFolderInput, syncFilesInput, movePathInput, deletePathInput, } from "./schemas.js";
|
|
34
|
+
import { render } from "./text.js";
|
|
34
35
|
async function main() {
|
|
35
36
|
const config = configFromEnv();
|
|
36
37
|
const api = new PlatformApi(config);
|
|
@@ -54,6 +55,13 @@ async function main() {
|
|
|
54
55
|
};
|
|
55
56
|
const prepared = async (fn, single, a, notes) => {
|
|
56
57
|
const begun = Date.now();
|
|
58
|
+
// An update with only application_id: the project that has it, when exactly one does.
|
|
59
|
+
if (!single && !a.project_id && !a.deployment_id && a.application_id) {
|
|
60
|
+
const project = await engine.locateApplication(a.application_id);
|
|
61
|
+
notes.push(`Used project_id ${project}, the only project with application ${a.application_id}; pass project_id next time.`);
|
|
62
|
+
const { project_name: _n, ...rest } = a;
|
|
63
|
+
a = { ...rest, project_id: project };
|
|
64
|
+
}
|
|
57
65
|
// No target anywhere: a new project, named by the agent, or a clear ask for that name.
|
|
58
66
|
if (!single && !a.project_id && !a.deployment_id && a.services) {
|
|
59
67
|
if (!a.project_name?.trim())
|
|
@@ -248,7 +256,7 @@ async function main() {
|
|
|
248
256
|
? text.replace(/Where to act: use the project or desk the user named.*?is created for the app\. /, deskInstructions(config.localDesk) + " ")
|
|
249
257
|
: text;
|
|
250
258
|
const server = new McpServer({ name: "constructor-research", version: VERSION }, {
|
|
251
|
-
instructions: withDesk(`Access: the MCP works with one Constructor and the user's personal access key for it, set up outside the chat. When a tool returns needs_key, pass its instructions on to the user; never ask for the key in the chat. Never read the key file or call Constructor's API yourself (curl, scripts): everything goes through these tools, and if they cannot do something, tell the user. Where to act: use the project or desk the user named, now or earlier in the conversation; a desk link (the browser address of a desk, with /projects/<project>/desks/<desk>) goes in desk_url. Do not pick an existing project yourself. When the user named none, do not ask: call deploy_app with project_name, a short name (one to three words, from the app), and the MCP creates a new project with deployment on; tell the user a new Constructor project with that name is created for the app. Given a project only (project_id), the MCP uses its only desk, or creates one for a deploy when there is none; when the project has several desks it returns desk_choice_required with their names and links: ask the user which one. Ask the user only before replacing, renaming or deleting files on a disk, once per request for the whole list (the tools return confirm_required); creating folders and uploading new files need no question. ${RULES} For a local app, pass build.local_path (the folder with the Dockerfile) and deploy_app uploads it first. A service can also take image: a public registry reference (repo:tag) that runs unchanged. The MCP uses the copy in the project when there is one (list_images shows source and reference), otherwise adds it to the project as an external image, with no desk and no build; if Constructor refuses it (image_refused), tell the user the reason. Hardware: leave it out; the default is used. Set hardware minimums only when the app cannot run without a GPU or a lot of RAM. Use deploy_app/update_app once for the WHOLE application. The MCP builds, resolves service URLs, configures and starts services in the background. IDs are automatic. To wait, run the wait command that next_action names (with a shell), or call get_deployment(wait_seconds=45) again until it is finished; never perform the deployment steps yourself. Never end the turn while a deployment the user asked for is still running. When the user asks to deploy or build, wait until the deployment is finished before answering, then give the public URL or what failed. On failure, tell the user the failed stage/service
|
|
259
|
+
instructions: withDesk(`Access: the MCP works with one Constructor and the user's personal access key for it, set up outside the chat. When a tool returns needs_key, pass its instructions on to the user; never ask for the key in the chat. Never read the key file or call Constructor's API yourself (curl, scripts): everything goes through these tools, and if they cannot do something, tell the user. Where to act: use the project or desk the user named, now or earlier in the conversation; a desk link (the browser address of a desk, with /projects/<project>/desks/<desk>) goes in desk_url. Do not pick an existing project yourself. When the user named none, do not ask: call deploy_app with project_name, a short name (one to three words, from the app), and the MCP creates a new project with deployment on; tell the user a new Constructor project with that name is created for the app. Given a project only (project_id), the MCP uses its only desk, or creates one for a deploy when there is none; when the project has several desks it returns desk_choice_required with their names and links: ask the user which one. Ask the user only before replacing, renaming or deleting files on a disk, once per request for the whole list (the tools return confirm_required); creating folders and uploading new files need no question. ${RULES} For a local app, pass build.local_path (the folder with the Dockerfile) and deploy_app uploads it first. A service can also take image: a public registry reference (repo:tag) that runs unchanged. The MCP uses the copy in the project when there is one (list_images shows source and reference), otherwise adds it to the project as an external image, with no desk and no build; if Constructor refuses it (image_refused), tell the user the reason. Hardware: leave it out; the default is used. Set hardware minimums only when the app cannot run without a GPU or a lot of RAM. Use deploy_app/update_app once for the WHOLE application. The MCP builds, resolves service URLs, configures and starts services in the background. IDs are automatic. To wait, run the wait command that next_action names (with a shell), or call get_deployment(wait_seconds=45) again until it is finished; never perform the deployment steps yourself. Never end the turn while a deployment the user asked for is still running. When the user asks to deploy or build, wait until the deployment is finished before answering, then give the public URL or what failed. On failure, tell the user the failed stage/service and the errors the result lists (taken from the whole kept log, with how much of it was captured); get_logs shows more. Do not use browser or debugging tools. To remove applications, services or images, use delete_resources (it asks the user first). For source files: sync_files to the desk before building (the MCP checks each Dockerfile on the disk and reports warnings); after a needs_upload pause, sync and call get_deployment with files_uploaded=true. Started is not readiness.`),
|
|
252
260
|
});
|
|
253
261
|
const register = (name, description, schema, fn, readOnly = false, budget = 20000, scope) => {
|
|
254
262
|
const here = config.localDesk && DESK_DEFAULT.has(name) ? config.localDesk : undefined;
|
|
@@ -294,10 +302,7 @@ async function main() {
|
|
|
294
302
|
content: [
|
|
295
303
|
{
|
|
296
304
|
type: "text",
|
|
297
|
-
text: result
|
|
298
|
-
(result.status
|
|
299
|
-
? `${result.status}${result.deployment_id ? ` (${result.deployment_id})` : ""}${result.message ? `: ${result.message}` : ""}${result.execution === "background" && result.next_action ? `\n${result.next_action}` : ""}`
|
|
300
|
-
: `Discovery result: ${result.total !== undefined ? result.total + " images" : Object.keys(result).join(", ")}. See structuredContent for details.`),
|
|
305
|
+
text: render(result),
|
|
301
306
|
},
|
|
302
307
|
],
|
|
303
308
|
// A preformatted text (build logs) is not repeated in structuredContent.
|
|
@@ -342,7 +347,7 @@ async function main() {
|
|
|
342
347
|
register("deploy_app", "Deploy the WHOLE app in one request: prepare project/disk, build or reuse all images, resolve internal/public service references, configure and start. Runs in the background. IDs are automatic. To resume a failure, send deployment_id and service overrides (for example replacement image_id); successful builds are preserved. On failure, failure.log_tail and get_logs show what the build or service printed." +
|
|
343
348
|
" " +
|
|
344
349
|
RULES, deployInput, checked((a) => runtime.deploy(a)), false, 60000, "deploy");
|
|
345
|
-
register("update_app", "Update/add selected services in one request; preserve omitted settings. MCP handles builds, links and restarts in the background. Environment variables merge; supplied port/volume lists replace their lists. Resume a failed update using deployment_id and service overrides. The Dockerfile rules in deploy_app apply.", updateInput, checked((a) => runtime.update(a)), false, 60000, "deploy");
|
|
350
|
+
register("update_app", "Update/add selected services of an existing application in one request; preserve omitted settings. Needs project_id (or desk_url), application_id and services: get_deployment with no arguments lists every application with its project_id, application_id and service IDs (without project_id the MCP looks it up from application_id, only when one project has it). Name existing services by service_id or their current name; they keep their IDs and volumes. MCP handles builds, links and restarts in the background. Environment variables merge; supplied port/volume lists replace their lists. Resume a failed update using deployment_id and service overrides. The Dockerfile rules in deploy_app apply.", updateInput, checked((a) => runtime.update(a)), false, 60000, "deploy");
|
|
346
351
|
register("start_app", "Start all or selected services as one operation. MCP handles all requests. Waits up to wait_seconds (default 20); remaining execution continues in the background. Started does not mean ready.", lifecycleInput, (a) => runtime.lifecycle("start", a), false, 20000, "project");
|
|
347
352
|
register("stop_app", "Stop all or selected services as one operation. MCP handles all requests. Waits up to wait_seconds (default 20). Stopped means stop requests accepted, not verified teardown.", lifecycleInput, (a) => runtime.lifecycle("stop", a), false, 20000, "project");
|
|
348
353
|
register("delete_resources", "Delete applications (each with all its services), single services, or images of one project, in one call for the whole request. Without confirm it returns what would be deleted (confirm_required), with public URLs and volumes whose data is lost, for the user to approve once; repeat with confirm=true. An image a remaining service uses is kept. Unfinished deployments of affected applications are ended first. Cannot be undone.", deleteInput, (a) => engine.deleteResources(a), false, 60000, "project");
|
package/dist/store.d.ts
CHANGED
|
@@ -32,6 +32,8 @@ export interface Operation {
|
|
|
32
32
|
errorSeen?: Record<string, string>;
|
|
33
33
|
/** Name of the failed image per build that was already rebuilt once. */
|
|
34
34
|
retried?: Record<string, string>;
|
|
35
|
+
/** Every build this operation started per service, with what its log said when it failed. */
|
|
36
|
+
attempts?: Record<string, BuildAttempt[]>;
|
|
35
37
|
/** Public-URL checks after start. */
|
|
36
38
|
readiness?: {
|
|
37
39
|
since: number;
|
|
@@ -59,8 +61,31 @@ export interface Operation {
|
|
|
59
61
|
desk_link?: string;
|
|
60
62
|
/** Last build log lines, when the MCP followed the build. */
|
|
61
63
|
log_tail?: string[];
|
|
64
|
+
/** Error excerpts from the whole kept log (diagnose.ts), bounded and with secrets masked. */
|
|
65
|
+
diagnostics?: string[];
|
|
66
|
+
/** Error blocks found in the log, and how many the excerpt leaves out. */
|
|
67
|
+
diagnostics_found?: number;
|
|
68
|
+
diagnostics_omitted?: number;
|
|
69
|
+
/** What the kept log covers: complete (followed to the end), partial, live or none. */
|
|
70
|
+
log_coverage?: "complete" | "partial" | "live" | "none";
|
|
71
|
+
log_lines_kept?: number;
|
|
72
|
+
/** compile / transient / unknown, and why (diagnose.ts classify). */
|
|
73
|
+
cause?: string;
|
|
74
|
+
cause_reason?: string;
|
|
75
|
+
/** How to read the whole kept log. */
|
|
76
|
+
logs_hint?: string;
|
|
62
77
|
};
|
|
63
78
|
}
|
|
79
|
+
/** One build of a service within an operation. */
|
|
80
|
+
export interface BuildAttempt {
|
|
81
|
+
image_id: string;
|
|
82
|
+
image_name?: string;
|
|
83
|
+
result: "error";
|
|
84
|
+
cause: string;
|
|
85
|
+
reason: string;
|
|
86
|
+
/** What the MCP did next: rebuilt once, or not, and why. */
|
|
87
|
+
next?: string;
|
|
88
|
+
}
|
|
64
89
|
export declare class StateStore {
|
|
65
90
|
readonly config: Config;
|
|
66
91
|
constructor(config: Config);
|
package/dist/text.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Longest text for one result; lists beyond it are cut with a count. */
|
|
2
|
+
export declare const MAX_TEXT = 12000;
|
|
3
|
+
/** deploy_app, update_app, build_image, start/stop and get_deployment(deployment_id). */
|
|
4
|
+
export declare function deployment(r: any): string;
|
|
5
|
+
/** The text an agent reads for a tool's result. */
|
|
6
|
+
export declare function render(result: any): string;
|