hammerkit 2.1.0-next.15 → 2.1.0-next.16

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.
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ /**
3
+ * The commands of a run in the runner of a sandbox (see kubernetes/sandbox-runner.ts), as the
4
+ * process of the run and the registry of the server know them. A command runs apart from the
5
+ * process that started it, with its output and exit code in a directory of the sandbox's
6
+ * files, so a run that resumes after a restart of the server takes it up again.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.isRunnerCommandsPath = exports.createRunnerCommands = exports.MAX_OUTPUT_COMMANDS = exports.COMMAND_ID_PATTERN = exports.RUNNER_COMMANDS_DIRECTORY = void 0;
10
+ const path_1 = require("path");
11
+ // Where the directories of the commands are, relative to the root of the sandbox's files:
12
+ // hammerkit's run state, which changes, pushes, the files API and the sources of tasks leave out
13
+ exports.RUNNER_COMMANDS_DIRECTORY = '.hammerkit/commands';
14
+ // the name of the directory of a run's commands, and of each command in it
15
+ exports.COMMAND_ID_PATTERN = /^[0-9a-f]{24}$/;
16
+ // the commands of a run the registry keeps a record of; past it, the records of the commands
17
+ // that ended make way
18
+ exports.MAX_OUTPUT_COMMANDS = 1000;
19
+ function createRunnerCommands(options = {}) {
20
+ // a task of a run that resumes goes on with the execution it was at: the one in flight when
21
+ // the server stopped, or the last one, which ended
22
+ const executions = new Map();
23
+ for (const record of Object.values(options.resumed ?? {})) {
24
+ executions.set(record.task, Math.max(executions.get(record.task) ?? 0, record.execution));
25
+ }
26
+ return { ...options, executions, inUse: new Set() };
27
+ }
28
+ exports.createRunnerCommands = createRunnerCommands;
29
+ // Whether a path is in the directory of the commands of the sandbox whose files are at `root`:
30
+ // only that one, at the root of the files, not a folder of the same name deeper in them
31
+ function isRunnerCommandsPath(path, root) {
32
+ const directory = (0, path_1.join)(root, ...exports.RUNNER_COMMANDS_DIRECTORY.split('/'));
33
+ return path === directory || path.startsWith(`${directory}${path_1.sep}`);
34
+ }
35
+ exports.isRunnerCommandsPath = isRunnerCommandsPath;
36
+ //# sourceMappingURL=runner-commands.js.map