hammerkit 2.1.0 → 2.2.0-next.2
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/build.schema.json +126 -28
- package/dist/cache/backends/registry/push-credentials.js +50 -0
- package/dist/cache/backends/registry/registry-client.js +41 -10
- package/dist/cache/backends/registry-cache-backend.js +6 -1
- package/dist/cache/cache-inventory.js +3 -0
- package/dist/cli.js +5 -0
- package/dist/dashboard/assets/graph-canvas-D6GMgkoe.js +8 -0
- package/dist/dashboard/assets/index-BNq9j5Jo.js +23 -0
- package/dist/dashboard/assets/index-DP3_hKOe.css +2 -0
- package/dist/dashboard/index.html +2 -2
- package/dist/docker/item-network.js +6 -5
- package/dist/docker/remove-orphaned-containers.js +5 -4
- package/dist/environment/replace-env-variables.js +8 -5
- package/dist/environment/run-source-envs.js +2 -1
- package/dist/executer/archive-task-entry.js +1 -1
- package/dist/executer/check-readiness.js +8 -4
- package/dist/executer/docker-healthcheck.js +73 -0
- package/dist/executer/docker-service.js +21 -15
- package/dist/executer/event-cache.js +7 -1
- package/dist/executer/execute-work-task.js +8 -0
- package/dist/executer/runner-commands.js +36 -0
- package/dist/file/get-file-context.js +4 -7
- package/dist/harness/connect.js +12 -8
- package/dist/harness/reconnect.js +141 -0
- package/dist/harness/sandbox-client.js +241 -33
- package/dist/harness/service-tools.js +11 -2
- package/dist/kubernetes/ensure-kubernetes-deployment-exists.js +62 -14
- package/dist/kubernetes/ensure-persistent-data.js +1 -1
- package/dist/kubernetes/follow-pod-logs.js +8 -5
- package/dist/kubernetes/kept-claims.js +38 -14
- package/dist/kubernetes/sandbox-runner.js +526 -156
- package/dist/kubernetes/store-kubernetes-data.js +18 -3
- package/dist/kubernetes/sync-changes.js +463 -0
- package/dist/kubernetes/volumes.js +23 -1
- package/dist/network/healthcheck-request.js +38 -0
- package/dist/optimizer/get-work-cache-stats.js +7 -0
- package/dist/optimizer/work-task-cache-description.js +5 -3
- package/dist/planner/image-build.js +5 -0
- package/dist/planner/service-definition.js +2 -1
- package/dist/planner/utils/append-work-service.js +12 -4
- package/dist/planner/utils/dependency-outputs.js +7 -6
- package/dist/planner/validate.js +41 -0
- package/dist/planner/work-healthcheck.js +23 -2
- package/dist/planner/work-item-status.js +12 -2
- package/dist/planner/work-runtime-aggregate.js +1 -0
- package/dist/planner/work-runtime-docker.js +33 -6
- package/dist/planner/work-runtime-kubernetes.js +313 -70
- package/dist/planner/work-runtime-local.js +8 -4
- package/dist/planner/work-secret.js +33 -11
- package/dist/planner/work-service-id.js +30 -6
- package/dist/planner/work-service.js +2 -2
- package/dist/program.js +19 -1
- package/dist/remote/annotations.js +8 -2
- package/dist/remote/bundle.js +6 -8
- package/dist/remote/device-login.js +4 -1
- package/dist/remote/remote-commands.js +16 -7
- package/dist/remote/remote-status.js +1 -1
- package/dist/remote/remote-work-commands.js +220 -68
- package/dist/remote/server-client.js +38 -40
- package/dist/schema/build-file-base-task-schema.js +16 -1
- package/dist/schema/build-file-image-build-schema.js +5 -8
- package/dist/schema/build-file-service-container-healthcheck.js +25 -7
- package/dist/schema/reference-parser.js +108 -43
- package/dist/schema/work-scope-parser.js +8 -0
- package/dist/secrets/prefetch-secrets.js +20 -1
- package/dist/server/artifacts-api.js +56 -0
- package/dist/server/borrowed-quota.js +216 -0
- package/dist/server/cache-push.js +50 -0
- package/dist/server/capacity.js +18 -6
- package/dist/server/definitions-api.js +62 -8
- package/dist/server/executor.js +131 -31
- package/dist/server/http.js +4 -1
- package/dist/server/keep-artifacts.js +230 -0
- package/dist/server/kubernetes-backend.js +292 -79
- package/dist/server/kubernetes-sandbox-storage.js +86 -24
- package/dist/server/overview.js +73 -9
- package/dist/server/paging.js +167 -0
- package/dist/server/plan.js +54 -8
- package/dist/server/run-access.js +24 -0
- package/dist/server/run-artifacts.js +171 -0
- package/dist/server/run-logs.js +25 -1
- package/dist/server/run-request.js +11 -0
- package/dist/server/run-source-environment.js +1 -1
- package/dist/server/run-worker.js +305 -40
- package/dist/server/runs.js +531 -105
- package/dist/server/sandbox-files-api.js +27 -12
- package/dist/server/sandbox-files.js +12 -10
- package/dist/server/sandbox-follow.js +54 -0
- package/dist/server/sandbox-pod.js +1 -1
- package/dist/server/sandbox-storage.js +38 -1
- package/dist/server/sandbox-sync.js +392 -0
- package/dist/server/sandboxes-api.js +116 -19
- package/dist/server/sandboxes.js +38 -3
- package/dist/server/server-config.js +133 -2
- package/dist/server/server.js +189 -39
- package/dist/server/task-order.js +56 -0
- package/dist/utils/project-path.js +20 -0
- package/dist/utils/tar-files.js +52 -0
- package/dist/utils/tar.js +37 -1
- package/package.json +1 -1
- package/dist/dashboard/assets/graph-canvas-DtJSpova.js +0 -8
- package/dist/dashboard/assets/index-BndChMep.css +0 -2
- package/dist/dashboard/assets/index-DRSwIRXd.js +0 -17
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArtifactStore = exports.refuseArtifacts = exports.LOCAL_TASKS_REFUSAL = exports.ARTIFACTS_MANIFEST = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const promises_1 = require("fs/promises");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const units_1 = require("../utils/units");
|
|
8
|
+
const plan_1 = require("./plan");
|
|
9
|
+
// What the process of a run kept of the files its tasks generated, written as
|
|
10
|
+
// `artifacts.json` beside the archives once it is done: the server serves only what it lists.
|
|
11
|
+
exports.ARTIFACTS_MANIFEST = 'artifacts.json';
|
|
12
|
+
// Why a host that runs local tasks as the user of the server keeps no outputs: such a task
|
|
13
|
+
// could write the store of them (see server.ts and HostExecutorOptions.localTasksOnHost).
|
|
14
|
+
exports.LOCAL_TASKS_REFUSAL = 'this server runs local tasks as its own user, which could write the outputs it keeps: it keeps none';
|
|
15
|
+
/**
|
|
16
|
+
* Why a run keeps none of the files its tasks generated, or null when it keeps them. Its
|
|
17
|
+
* outputs are handed out as they are, never masked: a task or service of the run that reads
|
|
18
|
+
* a secret or a variable of the server (but the plain ones) can write it into a file, its
|
|
19
|
+
* own or one a task after it reads and copies (an `.npmrc`, a docker `config.json`), as it
|
|
20
|
+
* could print it past the masking with an argument (task-arguments FR-008). So any of them
|
|
21
|
+
* leaves the whole run without artifacts.
|
|
22
|
+
*/
|
|
23
|
+
function refuseArtifacts(plan) {
|
|
24
|
+
for (const [name, item] of Object.entries(plan).sort(([a], [b]) => a.localeCompare(b))) {
|
|
25
|
+
const reads = (0, plan_1.getCredentialReads)(item);
|
|
26
|
+
if (reads.length > 0) {
|
|
27
|
+
return `${name} reads ${reads.join(', ')}: what it writes can reach the outputs of the run, which keeps none`;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
exports.refuseArtifacts = refuseArtifacts;
|
|
33
|
+
// Run ids name the directories: nothing else is taken from the store's folder
|
|
34
|
+
const RUN_DIRECTORY = /^run_[A-Za-z0-9_-]+$/;
|
|
35
|
+
// where a run's process writes the archives before it moves them into place (keepArtifacts)
|
|
36
|
+
const STAGING = '.staging';
|
|
37
|
+
/**
|
|
38
|
+
* The outputs runs kept, a directory per run below `directory`, written by its process
|
|
39
|
+
* (keepArtifacts) or its executor. They stay `keep` from the end of their run, while the
|
|
40
|
+
* registry keeps the run, and the newest runs' only while all together take at most `total`.
|
|
41
|
+
* `localTasksOnHost`: a local task of this host runs as the user of the server and could write
|
|
42
|
+
* the store, so nothing in it is served, whatever it holds, and the store is emptied.
|
|
43
|
+
*/
|
|
44
|
+
class ArtifactStore {
|
|
45
|
+
constructor(directory, options) {
|
|
46
|
+
this.directory = directory;
|
|
47
|
+
this.options = options;
|
|
48
|
+
}
|
|
49
|
+
directoryOf(id) {
|
|
50
|
+
if (!RUN_DIRECTORY.test(id)) {
|
|
51
|
+
throw new Error(`${id} is not a run id`);
|
|
52
|
+
}
|
|
53
|
+
return (0, path_1.join)(this.directory, id);
|
|
54
|
+
}
|
|
55
|
+
// A run that ended; who may read it was checked already.
|
|
56
|
+
async read(run, now) {
|
|
57
|
+
// nothing is read from the store here: a run that ended before planning has no manifest of its own
|
|
58
|
+
if (this.options.localTasksOnHost) {
|
|
59
|
+
return { outputs: [], left: [], reason: exports.LOCAL_TASKS_REFUSAL };
|
|
60
|
+
}
|
|
61
|
+
if (run.up) {
|
|
62
|
+
return { outputs: [], left: [], reason: 'a service run keeps no outputs' };
|
|
63
|
+
}
|
|
64
|
+
const manifest = await this.manifest(run, now);
|
|
65
|
+
if (!manifest) {
|
|
66
|
+
return {
|
|
67
|
+
outputs: [],
|
|
68
|
+
left: [],
|
|
69
|
+
reason: `the server has no outputs of the run: it keeps what tasks export (export: true, or always) for ${(0, units_1.formatDuration)(this.options.keep)}, and ${(0, units_1.formatSize)(this.options.total)} of all runs, the newest`,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
outputs: manifest.outputs.map((output, id) => ({
|
|
74
|
+
id,
|
|
75
|
+
task: output.task,
|
|
76
|
+
path: output.path,
|
|
77
|
+
bytes: output.bytes,
|
|
78
|
+
})),
|
|
79
|
+
left: manifest.left,
|
|
80
|
+
...(manifest.refused ? { reason: manifest.refused } : { expiresAt: this.expiresAt(run).toISOString() }),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
// The archive of one output: a gzipped tar of its paths in the project.
|
|
84
|
+
async open(run, id, now) {
|
|
85
|
+
if (this.options.localTasksOnHost) {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
const output = (await this.manifest(run, now))?.outputs[id];
|
|
89
|
+
if (!output || !/^\d+\.tgz$/.test(output.file)) {
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
const file = (0, path_1.join)(this.directoryOf(run.id), output.file);
|
|
93
|
+
const bytes = (await (0, promises_1.stat)(file).catch(() => undefined))?.size;
|
|
94
|
+
return bytes === undefined ? undefined : { bytes, stream: () => (0, fs_1.createReadStream)(file), read: () => (0, promises_1.readFile)(file) };
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Removes what is over its time, what runs the registry no longer has kept, and of the
|
|
98
|
+
* runs that ended the oldest while all of them take more than `total`. A run that has not
|
|
99
|
+
* ended may still write. What a run's process left in its staging folder after it ended (a
|
|
100
|
+
* crash while it kept the outputs) goes too. Answers the runs it removed the outputs of.
|
|
101
|
+
*/
|
|
102
|
+
async sweep(lookup, now) {
|
|
103
|
+
const names = await (0, promises_1.readdir)(this.directory).catch(() => []);
|
|
104
|
+
if (this.options.localTasksOnHost) {
|
|
105
|
+
// nothing a run keeps is served here, so nothing is kept: whatever is in the store goes
|
|
106
|
+
for (const name of names) {
|
|
107
|
+
await (0, promises_1.rm)((0, path_1.join)(this.directory, name), { recursive: true, force: true });
|
|
108
|
+
}
|
|
109
|
+
return names.filter((name) => RUN_DIRECTORY.test(name));
|
|
110
|
+
}
|
|
111
|
+
const removed = [];
|
|
112
|
+
const ended = [];
|
|
113
|
+
for (const id of names.filter((name) => RUN_DIRECTORY.test(name))) {
|
|
114
|
+
const run = lookup(id);
|
|
115
|
+
if (run && !run.finishedAt) {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (!run || this.expiresAt(run).getTime() <= now) {
|
|
119
|
+
await this.remove(id);
|
|
120
|
+
removed.push(id);
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
await (0, promises_1.rm)((0, path_1.join)(this.directoryOf(id), STAGING), { recursive: true, force: true });
|
|
124
|
+
// what the directory takes, as it is: a file the manifest does not name counts too
|
|
125
|
+
const bytes = await sizeOf(this.directoryOf(id));
|
|
126
|
+
ended.push({ id, finishedAt: Date.parse(run.finishedAt), bytes });
|
|
127
|
+
}
|
|
128
|
+
let total = ended.reduce((sum, run) => sum + run.bytes, 0);
|
|
129
|
+
for (const run of ended.sort((a, b) => a.finishedAt - b.finishedAt)) {
|
|
130
|
+
if (total <= this.options.total) {
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
await this.remove(run.id);
|
|
134
|
+
removed.push(run.id);
|
|
135
|
+
total -= run.bytes;
|
|
136
|
+
}
|
|
137
|
+
return removed;
|
|
138
|
+
}
|
|
139
|
+
expiresAt(run) {
|
|
140
|
+
return new Date(Date.parse(run.finishedAt ?? '') + this.options.keep);
|
|
141
|
+
}
|
|
142
|
+
// what the run kept, while it is kept
|
|
143
|
+
async manifest(run, now) {
|
|
144
|
+
if (!run.finishedAt || this.expiresAt(run).getTime() <= now) {
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
return this.readManifest(run.id);
|
|
148
|
+
}
|
|
149
|
+
async readManifest(id) {
|
|
150
|
+
try {
|
|
151
|
+
return JSON.parse(await (0, promises_1.readFile)((0, path_1.join)(this.directoryOf(id), exports.ARTIFACTS_MANIFEST), 'utf8'));
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
async remove(id) {
|
|
158
|
+
await (0, promises_1.rm)(this.directoryOf(id), { recursive: true, force: true });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
exports.ArtifactStore = ArtifactStore;
|
|
162
|
+
// The bytes of the files below a directory, each as it is on disk (a link counts as itself).
|
|
163
|
+
async function sizeOf(directory) {
|
|
164
|
+
let bytes = 0;
|
|
165
|
+
for (const entry of await (0, promises_1.readdir)(directory, { withFileTypes: true }).catch(() => [])) {
|
|
166
|
+
const path = (0, path_1.join)(directory, entry.name);
|
|
167
|
+
bytes += entry.isDirectory() ? await sizeOf(path) : (await (0, promises_1.lstat)(path).catch(() => undefined))?.size ?? 0;
|
|
168
|
+
}
|
|
169
|
+
return bytes;
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=run-artifacts.js.map
|
package/dist/server/run-logs.js
CHANGED
|
@@ -113,6 +113,23 @@ class LogIndex {
|
|
|
113
113
|
lines(task) {
|
|
114
114
|
return this.taskLines.get(task) ?? [];
|
|
115
115
|
}
|
|
116
|
+
// How many lines of the log, or of one task, the first `count` events hold
|
|
117
|
+
linesBefore(count, task) {
|
|
118
|
+
const lines = task !== undefined ? this.lines(task) : undefined;
|
|
119
|
+
let low = 0;
|
|
120
|
+
let high = lines ? lines.length : this.size;
|
|
121
|
+
// the lines are in the order of their events
|
|
122
|
+
while (low < high) {
|
|
123
|
+
const middle = (low + high) >> 1;
|
|
124
|
+
if (this.lineEvent[lines ? lines[middle] : middle] < count) {
|
|
125
|
+
low = middle + 1;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
high = middle;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return low;
|
|
132
|
+
}
|
|
116
133
|
text(events, line) {
|
|
117
134
|
const event = events[this.lineEvent[line]];
|
|
118
135
|
return { task: event.task, stream: event.stream, text: event.text.slice(this.lineStart[line], this.lineEnd[line]) };
|
|
@@ -145,9 +162,15 @@ class LogIndex {
|
|
|
145
162
|
}
|
|
146
163
|
exports.LogIndex = LogIndex;
|
|
147
164
|
// The lines of the log a query selects, see LogQuery.
|
|
148
|
-
|
|
165
|
+
// `lostAfter`: Run.lostAfter
|
|
166
|
+
function readLogs(events, index, query, truncated, lostAfter) {
|
|
149
167
|
const selected = query.task !== undefined ? index.lines(query.task) : undefined;
|
|
150
168
|
const total = selected ? selected.length : index.size;
|
|
169
|
+
const lost = lostAfter !== undefined
|
|
170
|
+
? index.linesBefore(lostAfter, query.task) + 1
|
|
171
|
+
: query.from !== undefined && query.from > total + 1
|
|
172
|
+
? total + 1
|
|
173
|
+
: undefined;
|
|
151
174
|
const at = (position) => (selected ? selected[position] : position);
|
|
152
175
|
const hits = query.grep !== undefined ? index.matches(events, query.grep, query.ignoreCase) : undefined;
|
|
153
176
|
const toLine = (position) => ({
|
|
@@ -215,6 +238,7 @@ function readLogs(events, index, query, truncated) {
|
|
|
215
238
|
total,
|
|
216
239
|
...(next !== undefined ? { next } : {}),
|
|
217
240
|
truncated,
|
|
241
|
+
...(lost !== undefined ? { lost } : {}),
|
|
218
242
|
};
|
|
219
243
|
}
|
|
220
244
|
exports.readLogs = readLogs;
|
|
@@ -134,6 +134,9 @@ exports.runRequestSchema = zod_1.z
|
|
|
134
134
|
.array(zod_1.z.object({ service: name, port: zod_1.z.number().int().min(1).max(65535) }).strict())
|
|
135
135
|
.max(exports.MAX_ENDPOINTS)
|
|
136
136
|
.default([]),
|
|
137
|
+
// the services that start again with the files of their sandbox after an edit of it; the
|
|
138
|
+
// others keep the files they started with (see ServiceRunSpec.restart)
|
|
139
|
+
restart: zod_1.z.array(name).max(20).optional(),
|
|
137
140
|
// paths of those endpoints that need no sign-in of the server, such as an app's own sign-in
|
|
138
141
|
// for an MCP client; the run they are written for must be the one the run gets (see
|
|
139
142
|
// refusePublicPaths), and the endpoint one the run publishes
|
|
@@ -171,6 +174,14 @@ exports.runRequestSchema = zod_1.z
|
|
|
171
174
|
request.sleepTtl === undefined &&
|
|
172
175
|
request.name === undefined &&
|
|
173
176
|
request.endpoints.length === 0), { message: 'ttl, sleepTtl, name and endpoints are for a run of services', path: ['services'] })
|
|
177
|
+
.refine((request) => (request.restart ?? []).every((service) => request.services.includes(service)), {
|
|
178
|
+
message: 'restart names services the run starts',
|
|
179
|
+
path: ['restart'],
|
|
180
|
+
})
|
|
181
|
+
.refine((request) => !request.restart?.length || request.source.type === 'sandbox', {
|
|
182
|
+
message: 'restart is for a service run from a sandbox, which changes with its files',
|
|
183
|
+
path: ['restart'],
|
|
184
|
+
})
|
|
174
185
|
.refine((request) => new Set(request.endpoints.map((endpoint) => `${endpoint.service}:${endpoint.port}`)).size ===
|
|
175
186
|
request.endpoints.length, { message: 'an endpoint is named twice', path: ['endpoints'] })
|
|
176
187
|
.refine((request) => request.publicPaths.length === 0 || request.services.length > 0, {
|
|
@@ -9,7 +9,7 @@ const COMMIT = /^[0-9a-f]{40}([0-9a-f]{24})?$/i;
|
|
|
9
9
|
// repository, and the branch or tag and the commit it was pinned to, or the repository and the
|
|
10
10
|
// sandbox. None of them is a credential, so a task that reads them still takes arguments and
|
|
11
11
|
// keeps its network (see PLAIN_SERVER_ENVS). A sandbox has no commit: its files may hold
|
|
12
|
-
// changes. A run from an upload has none of them.
|
|
12
|
+
// changes. A run from an upload has none of them. Each is a name of RUN_SOURCE_ENVS.
|
|
13
13
|
function runSourceEnvironment(source) {
|
|
14
14
|
if (source.type === 'ref') {
|
|
15
15
|
return {
|