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/text.js
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// The text content of every tool result. Some clients (OpenCode) show the agent only this
|
|
2
|
+
// text, never structuredContent, so it must carry what the agent acts on: real IDs, public
|
|
3
|
+
// URLs, statuses, what failed and how to read more. structuredContent stays as it was.
|
|
4
|
+
// Values Constructor did not return read "unavailable"; nothing is guessed.
|
|
5
|
+
import { duration } from "./diagnose.js";
|
|
6
|
+
/** Longest text for one result; lists beyond it are cut with a count. */
|
|
7
|
+
export const MAX_TEXT = 12000;
|
|
8
|
+
const NA = "unavailable";
|
|
9
|
+
const val = (v) => v === undefined || v === null || v === "" ? NA : String(v);
|
|
10
|
+
/** Joins lines and cuts the result to MAX_TEXT, saying so. */
|
|
11
|
+
function finish(lines) {
|
|
12
|
+
const out = lines.filter((l) => !!l).join("\n");
|
|
13
|
+
if (out.length <= MAX_TEXT)
|
|
14
|
+
return out;
|
|
15
|
+
const cut = out.slice(0, MAX_TEXT);
|
|
16
|
+
const end = cut.lastIndexOf("\n");
|
|
17
|
+
return `${end > 0 ? cut.slice(0, end) : cut}\n… cut to ${MAX_TEXT} characters; structuredContent has the rest.`;
|
|
18
|
+
}
|
|
19
|
+
/** Up to `max` items of a list, then a line saying how many more there are. */
|
|
20
|
+
function some(items, max, line) {
|
|
21
|
+
const out = items.slice(0, max).flatMap(line);
|
|
22
|
+
if (items.length > max)
|
|
23
|
+
out.push(` … and ${items.length - max} more; structuredContent has all of them.`);
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
function volumes(s) {
|
|
27
|
+
const v = (s.volumes ?? []).map((x) => `${x.mount_point ?? x.name}${x.size_gb ? ` (${x.size_gb} GB)` : ""}`);
|
|
28
|
+
return v.length ? ` volumes: ${v.join(", ")};` : "";
|
|
29
|
+
}
|
|
30
|
+
/** One line for a service of an application, as get_deployment returns it. */
|
|
31
|
+
function serviceLine(s) {
|
|
32
|
+
const id = s.id ?? s.service_id;
|
|
33
|
+
const name = s.name ?? s.service_name;
|
|
34
|
+
return ` - service ${val(name)} (service_id: ${val(id)}): status ${val(s.status)}; image_id ${val(s.image_id)};${volumes(s)} public URL: ${s.public_url ?? "none (no public port)"}`;
|
|
35
|
+
}
|
|
36
|
+
/** An application with its services; for update_app the agent needs all of these IDs. */
|
|
37
|
+
function applicationLines(a, project) {
|
|
38
|
+
const id = a.id ?? a.application_id;
|
|
39
|
+
const name = a.name ?? a.application_name;
|
|
40
|
+
return [
|
|
41
|
+
`- application ${val(name)} (application_id: ${val(id)}${project ? `, project_id: ${project}` : ""})`,
|
|
42
|
+
...((a.services ?? []).length
|
|
43
|
+
? some(a.services, 30, (s) => [serviceLine(s)])
|
|
44
|
+
: [" - no services"]),
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
const UPDATE_HINT = "To change an application, call update_app with project_id (or desk_url), application_id and the services to change; existing services keep their IDs and volumes.";
|
|
48
|
+
/** get_deployment with no arguments: every project with deployment on. */
|
|
49
|
+
function overview(r) {
|
|
50
|
+
return finish([
|
|
51
|
+
r.summary,
|
|
52
|
+
...some(r.projects ?? [], 40, (p) => [
|
|
53
|
+
`Project ${val(p.project_name)} (project_id: ${val(p.project_id)})${p.error ? `: applications could not be loaded (${p.error})` : ""}`,
|
|
54
|
+
...(p.applications ?? []).flatMap((a) => applicationLines(a)),
|
|
55
|
+
...(p.applications && !p.applications.length
|
|
56
|
+
? ["- no applications"]
|
|
57
|
+
: []),
|
|
58
|
+
]),
|
|
59
|
+
r.projects_without_deployment?.length
|
|
60
|
+
? `Projects without deployment: ${r.projects_without_deployment.length}.`
|
|
61
|
+
: undefined,
|
|
62
|
+
UPDATE_HINT,
|
|
63
|
+
]);
|
|
64
|
+
}
|
|
65
|
+
/** get_deployment with a project: its desks, images and applications. */
|
|
66
|
+
function project(r) {
|
|
67
|
+
return finish([
|
|
68
|
+
`Project ${r.project_id}.`,
|
|
69
|
+
`Applications (${r.applications.length}):`,
|
|
70
|
+
...(r.applications.length
|
|
71
|
+
? some(r.applications, 30, (a) => applicationLines(a))
|
|
72
|
+
: ["- none"]),
|
|
73
|
+
r.desks?.length
|
|
74
|
+
? `Desks: ${r.desks.map((d) => `${val(d.name)} (desk_id: ${val(d.id)}, ${val(d.state)})`).join("; ")}.`
|
|
75
|
+
: undefined,
|
|
76
|
+
r.images?.length
|
|
77
|
+
? `Images (${r.images.length}): ${r.images
|
|
78
|
+
.slice(0, 30)
|
|
79
|
+
.map((i) => `${val(i.name)} (image_id: ${val(i.id)}, ${val(i.build_status)})`)
|
|
80
|
+
.join("; ")}${r.images.length > 30 ? `; … ${r.images.length - 30} more` : ""}.`
|
|
81
|
+
: undefined,
|
|
82
|
+
UPDATE_HINT,
|
|
83
|
+
]);
|
|
84
|
+
}
|
|
85
|
+
/** get_deployment with project and application_id. */
|
|
86
|
+
function application(r) {
|
|
87
|
+
return finish([
|
|
88
|
+
`Project ${val(r.project_id)}.`,
|
|
89
|
+
...applicationLines(r),
|
|
90
|
+
UPDATE_HINT,
|
|
91
|
+
]);
|
|
92
|
+
}
|
|
93
|
+
function images(r) {
|
|
94
|
+
return finish([
|
|
95
|
+
`${r.total} image${r.total === 1 ? "" : "s"}:`,
|
|
96
|
+
...some(r.results ?? [], 60, (i) => [
|
|
97
|
+
`- ${val(i.name)} (image_id: ${val(i.id)}): ${val(i.build_status)}${i.source === "external" ? `, external ${val(i.reference)}` : i.dockerfile ? `, ${i.dockerfile}${i.desk_name ? ` on desk ${i.desk_name}` : ""}` : ""}`,
|
|
98
|
+
]),
|
|
99
|
+
]);
|
|
100
|
+
}
|
|
101
|
+
/** A build of this deployment: status, age, log coverage and steps with their durations. */
|
|
102
|
+
function buildLines(b, running) {
|
|
103
|
+
const age = running && b.requested_at
|
|
104
|
+
? `, requested ${duration((Date.now() - Date.parse(b.requested_at)) / 1000)} ago`
|
|
105
|
+
: "";
|
|
106
|
+
const log = b.log ?? {};
|
|
107
|
+
const coverage = log.coverage === "complete"
|
|
108
|
+
? `build log followed to its end (${log.lines_kept} lines kept)`
|
|
109
|
+
: log.coverage === "live"
|
|
110
|
+
? `build log live (${log.lines_kept} lines so far)`
|
|
111
|
+
: log.coverage === "partial"
|
|
112
|
+
? `build log may be incomplete (${log.lines_kept} lines kept)`
|
|
113
|
+
: "no build log captured";
|
|
114
|
+
const out = [
|
|
115
|
+
` - build ${val(b.service)}: image ${val(b.name)} (image_id: ${val(b.id)}) ${val(b.build_status)}${age}; ${coverage}.`,
|
|
116
|
+
];
|
|
117
|
+
const st = log.steps ?? [];
|
|
118
|
+
if (st.length)
|
|
119
|
+
out.push(` steps (from log timestamps; estimates, pull time included): ${st
|
|
120
|
+
.map((s) => `${s.step} ${s.last && running ? `running for ${duration(s.seconds)} so far` : duration(s.seconds)}`)
|
|
121
|
+
.join(" | ")}`);
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
/** deploy_app, update_app, build_image, start/stop and get_deployment(deployment_id). */
|
|
125
|
+
export function deployment(r) {
|
|
126
|
+
const running = r.execution === "background" || r.status === "building";
|
|
127
|
+
const elapsed = typeof r.elapsed_seconds === "number"
|
|
128
|
+
? `${running ? "running for" : "took"} ${duration(r.elapsed_seconds)}`
|
|
129
|
+
: undefined;
|
|
130
|
+
const f = r.failure;
|
|
131
|
+
const lines = [
|
|
132
|
+
`Deployment ${r.deployment_id} (${val(r.operation)}): ${r.status}${elapsed ? `, ${elapsed}` : ""}.`,
|
|
133
|
+
r.operation === "build"
|
|
134
|
+
? `Project ${val(r.project_id)}.`
|
|
135
|
+
: `Project ${val(r.project_id)}; application ${r.application_name ? `${r.application_name} ` : ""}(application_id: ${r.application_id ?? "not created yet"}).`,
|
|
136
|
+
r.message,
|
|
137
|
+
];
|
|
138
|
+
const svcs = r.services ?? [];
|
|
139
|
+
if (svcs.length) {
|
|
140
|
+
lines.push("Services (as Constructor reports them now):");
|
|
141
|
+
for (const s of svcs.slice(0, 30)) {
|
|
142
|
+
const image = s.attempted_image_id === undefined
|
|
143
|
+
? `image_id ${val(s.image_id)}`
|
|
144
|
+
: s.runs_attempted_image
|
|
145
|
+
? `runs the image this deployment built (${s.image_id})`
|
|
146
|
+
: `runs image ${val(s.image_id)}, NOT the image this deployment attempted (${s.attempted_image_id})`;
|
|
147
|
+
const ready = r.readiness_checks?.[s.name];
|
|
148
|
+
lines.push(` - ${val(s.name)} (service_id: ${val(s.id)}): ${val(s.status)}; ${image};${volumes(s)} public URL: ${s.public_url ?? "none (no public port)"}${ready ? `; answered ${ready.status === null ? "nothing" : `HTTP ${ready.status}`}` : ""}${s.restarts_seen ? `; ${s.restarts_seen} restart(s) seen` : ""}`);
|
|
149
|
+
}
|
|
150
|
+
if (svcs.length > 30)
|
|
151
|
+
lines.push(` … and ${svcs.length - 30} more services.`);
|
|
152
|
+
}
|
|
153
|
+
else if (r.application_id)
|
|
154
|
+
lines.push("Services: unavailable (Constructor did not return the application).");
|
|
155
|
+
const builds = r.images ?? [];
|
|
156
|
+
if (builds.length) {
|
|
157
|
+
lines.push("Builds of this deployment:");
|
|
158
|
+
for (const b of builds)
|
|
159
|
+
lines.push(...buildLines(b, running));
|
|
160
|
+
}
|
|
161
|
+
const attempts = Object.entries(r.build_attempts ?? {});
|
|
162
|
+
// Earlier attempts; the current image's outcome is in the build list and the failure.
|
|
163
|
+
const current = new Set(builds.map((b) => b.id));
|
|
164
|
+
for (const [service, list] of attempts)
|
|
165
|
+
for (const a of list.filter((a) => !current.has(a.image_id)))
|
|
166
|
+
lines.push(` - failed build of ${service}: ${val(a.image_name)} (image_id: ${a.image_id}), cause ${a.cause}: ${a.reason}${a.next ? `; ${a.next}` : ""}.`);
|
|
167
|
+
if (f) {
|
|
168
|
+
lines.push(`Failure: stage ${val(f.stage)}${f.service ? `, service ${f.service}` : ""}${f.image_id ? `, image ${val(f.image_name)} (image_id: ${f.image_id})` : ""}${f.dockerfile ? `, Dockerfile ${f.dockerfile}` : ""}${f.cause ? `; cause ${f.cause}${f.cause_reason ? ` (${f.cause_reason})` : ""}` : ""}.`);
|
|
169
|
+
if (f.diagnostics?.length) {
|
|
170
|
+
lines.push(`Errors from the ${f.stage === "build" ? "build" : "service"} log (${f.diagnostics_found} found${f.diagnostics_omitted ? `, ${f.diagnostics_omitted} left out` : ""}):`, ...f.diagnostics.map((l) => ` ${l}`));
|
|
171
|
+
}
|
|
172
|
+
else if (f.log_tail?.length)
|
|
173
|
+
lines.push("Last log lines:", ...f.log_tail.slice(-20).map((l) => ` ${l}`));
|
|
174
|
+
if (f.log_coverage)
|
|
175
|
+
lines.push(`Log coverage: ${f.log_coverage}${f.log_coverage === "complete" ? "" : f.log_coverage === "none" ? " (nothing was captured)" : " (diagnostics may be missing lines)"}.`);
|
|
176
|
+
if (f.logs_hint)
|
|
177
|
+
lines.push(f.logs_hint);
|
|
178
|
+
}
|
|
179
|
+
if (r.volumes_to_wipe?.length)
|
|
180
|
+
lines.push(`Volumes that would lose data: ${r.volumes_to_wipe.join("; ")}.`);
|
|
181
|
+
if (r.status === "started" && r.readiness)
|
|
182
|
+
lines.push(`Readiness: ${r.readiness}.`);
|
|
183
|
+
if (r.next_action)
|
|
184
|
+
lines.push(`Next: ${r.next_action}`);
|
|
185
|
+
return finish(lines);
|
|
186
|
+
}
|
|
187
|
+
/** The text an agent reads for a tool's result. */
|
|
188
|
+
export function render(result) {
|
|
189
|
+
if (typeof result?.text === "string")
|
|
190
|
+
return result.text;
|
|
191
|
+
if (result?.deployment_id && result.status)
|
|
192
|
+
return deployment(result);
|
|
193
|
+
if (Array.isArray(result?.projects))
|
|
194
|
+
return overview(result);
|
|
195
|
+
if (result?.project_id && Array.isArray(result.applications))
|
|
196
|
+
return project(result);
|
|
197
|
+
if (result?.id && result.project_id && Array.isArray(result.services))
|
|
198
|
+
return application(result);
|
|
199
|
+
if (Array.isArray(result?.results) && typeof result.total === "number")
|
|
200
|
+
return images(result);
|
|
201
|
+
if (result?.status)
|
|
202
|
+
return finish([
|
|
203
|
+
`${result.status}${result.message ? `: ${result.message}` : ""}`,
|
|
204
|
+
result.next_action ? `Next: ${result.next_action}` : undefined,
|
|
205
|
+
]);
|
|
206
|
+
// Anything else: the data itself, bounded, rather than a pointer to structuredContent.
|
|
207
|
+
return finish([JSON.stringify(result, null, 1)]);
|
|
208
|
+
}
|
package/dist/wait.d.ts
CHANGED
|
@@ -22,7 +22,10 @@ export interface WaitResult {
|
|
|
22
22
|
/** Deployments still in progress that were touched in the last two hours. */
|
|
23
23
|
export declare function active(store: StateStore): Promise<string[]>;
|
|
24
24
|
export declare function waitFor(runtime: DeploymentRuntime, ids: string[], { maxMs, staleMs, pollMs }: WaitOptions): Promise<WaitResult>;
|
|
25
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* What the waiter prints: the same text get_deployment returns for each deployment (text.ts),
|
|
27
|
+
* so both say the same thing.
|
|
28
|
+
*/
|
|
26
29
|
export declare function summary({ results, running }: WaitResult): string;
|
|
27
30
|
declare const HOOKS: {
|
|
28
31
|
readonly codex: {
|
|
@@ -31,7 +34,7 @@ declare const HOOKS: {
|
|
|
31
34
|
readonly entry: {
|
|
32
35
|
readonly hooks: readonly [{
|
|
33
36
|
readonly type: "command";
|
|
34
|
-
readonly command:
|
|
37
|
+
readonly command: `${string} --hook codex`;
|
|
35
38
|
readonly timeout: 600;
|
|
36
39
|
readonly statusMessage: "Waiting for Constructor deployments";
|
|
37
40
|
}];
|
|
@@ -45,7 +48,7 @@ declare const HOOKS: {
|
|
|
45
48
|
readonly matcher: "mcp__constructor-research__(deploy_app|update_app|build_image|start_app|stop_app|get_deployment)";
|
|
46
49
|
readonly hooks: readonly [{
|
|
47
50
|
readonly type: "command";
|
|
48
|
-
readonly command:
|
|
51
|
+
readonly command: `${string} --hook claude-code`;
|
|
49
52
|
readonly asyncRewake: true;
|
|
50
53
|
}];
|
|
51
54
|
};
|
package/dist/wait.js
CHANGED
|
@@ -12,13 +12,14 @@ import { homedir } from "node:os";
|
|
|
12
12
|
import { mkdir } from "node:fs/promises";
|
|
13
13
|
import { realpathSync } from "node:fs";
|
|
14
14
|
import { fileURLToPath } from "node:url";
|
|
15
|
-
import { configFromEnv } from "./config.js";
|
|
15
|
+
import { CHANNEL, configFromEnv } from "./config.js";
|
|
16
16
|
import { PlatformApi } from "./api.js";
|
|
17
17
|
import { StateStore } from "./store.js";
|
|
18
18
|
import { DeploymentEngine, terminal } from "./deployment.js";
|
|
19
19
|
import { DeploymentRuntime, paused } from "./runtime.js";
|
|
20
20
|
import { FileManager } from "./files.js";
|
|
21
21
|
import { LogFollower } from "./logs.js";
|
|
22
|
+
import { deployment } from "./text.js";
|
|
22
23
|
const ok = new Set(["started", "stopped", "built"]);
|
|
23
24
|
const ID = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi;
|
|
24
25
|
export const EXIT = {
|
|
@@ -87,21 +88,12 @@ export async function waitFor(runtime, ids, { maxMs, staleMs = 60000, pollMs = 5
|
|
|
87
88
|
: EXIT.done,
|
|
88
89
|
};
|
|
89
90
|
}
|
|
90
|
-
/**
|
|
91
|
+
/**
|
|
92
|
+
* What the waiter prints: the same text get_deployment returns for each deployment (text.ts),
|
|
93
|
+
* so both say the same thing.
|
|
94
|
+
*/
|
|
91
95
|
export function summary({ results, running }) {
|
|
92
|
-
const lines = results.map((r) =>
|
|
93
|
-
const services = (r.services ?? [])
|
|
94
|
-
.map((s) => `${s.name} ${s.status ?? ""}${s.public_url ? ` ${s.public_url}` : ""}`.trim())
|
|
95
|
-
.join(", ");
|
|
96
|
-
return [
|
|
97
|
-
`Deployment ${r.deployment_id}: ${r.status}.`,
|
|
98
|
-
r.message,
|
|
99
|
-
services && `Services: ${services}.`,
|
|
100
|
-
r.next_action && `Next: ${r.next_action}`,
|
|
101
|
-
]
|
|
102
|
-
.filter(Boolean)
|
|
103
|
-
.join(" ");
|
|
104
|
-
});
|
|
96
|
+
const lines = results.map((r) => deployment(r) + "\n");
|
|
105
97
|
for (const id of running)
|
|
106
98
|
lines.push(`Deployment ${id}: still in progress. Run the wait command again to keep waiting.`);
|
|
107
99
|
return lines.join("\n");
|
|
@@ -132,7 +124,7 @@ async function claim(dir, id) {
|
|
|
132
124
|
return () => unlink(file).catch(() => { });
|
|
133
125
|
}
|
|
134
126
|
/** The hook entry each client needs, as in examples/ (claude-hooks.json, codex-hooks.json). */
|
|
135
|
-
const HOOK =
|
|
127
|
+
const HOOK = `npx -y -p constructor-research-mcp@${CHANNEL} constructor-research-wait`;
|
|
136
128
|
const HOOKS = {
|
|
137
129
|
codex: {
|
|
138
130
|
file: () => join(process.env.CODEX_HOME ?? join(homedir(), ".codex"), "hooks.json"),
|