hammerkit 1.27.0-next.16 → 1.27.0-next.18

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.
Files changed (37) hide show
  1. package/dist/executer/execution-steps.js +5 -2
  2. package/dist/executer/scheduler/state-key.js +37 -5
  3. package/dist/harness/mcp.js +2 -1
  4. package/dist/harness/opencode.js +9 -2
  5. package/dist/harness/pi.js +15 -0
  6. package/dist/harness/sandbox-client.js +26 -2
  7. package/dist/harness/task-tools.js +12 -1
  8. package/dist/optimizer/calculate-checksum.js +3 -2
  9. package/dist/optimizer/check-key.js +94 -0
  10. package/dist/optimizer/check-keys.js +64 -0
  11. package/dist/optimizer/get-work-cache-stats.js +17 -3
  12. package/dist/optimizer/work-task-cache-description.js +49 -1
  13. package/dist/planner/utils/normalize-path.js +19 -1
  14. package/dist/planner/utils/parse-work-mount.js +7 -1
  15. package/dist/planner/validate.js +22 -0
  16. package/dist/remote/remote-work-commands.js +70 -0
  17. package/dist/remote/server-client.js +15 -2
  18. package/dist/run-program.js +9 -0
  19. package/dist/schema/reference-parser.js +8 -1
  20. package/dist/secrets/github-app-token-command.js +3 -1
  21. package/dist/server/accounts-api.js +1 -0
  22. package/dist/server/checks-api.js +83 -0
  23. package/dist/server/checks.js +116 -0
  24. package/dist/server/executor.js +41 -3
  25. package/dist/server/kubernetes-backend.js +1 -1
  26. package/dist/server/kubernetes-sandbox-storage.js +41 -1
  27. package/dist/server/plan.js +103 -78
  28. package/dist/server/policy.js +10 -2
  29. package/dist/server/run-request.js +12 -1
  30. package/dist/server/run-worker.js +16 -2
  31. package/dist/server/runs.js +18 -0
  32. package/dist/server/sandbox-pod.js +28 -0
  33. package/dist/server/sandbox-storage.js +23 -0
  34. package/dist/server/sandboxes.js +8 -0
  35. package/dist/server/server-config.js +14 -1
  36. package/dist/server/server.js +46 -3
  37. package/package.json +1 -1
@@ -9,6 +9,7 @@ const server_config_1 = require("./server-config");
9
9
  const discovery_1 = require("./discovery");
10
10
  const oauth_1 = require("./oauth");
11
11
  const policy_1 = require("./policy");
12
+ const repo_1 = require("./repo");
12
13
  const run_store_1 = require("./run-store");
13
14
  const runs_1 = require("./runs");
14
15
  const git_checkout_1 = require("./git-checkout");
@@ -39,6 +40,8 @@ const units_1 = require("../utils/units");
39
40
  const run_logs_1 = require("./run-logs");
40
41
  const get_cache_directory_1 = require("../optimizer/get-cache-directory");
41
42
  const path_1 = require("path");
43
+ const checks_1 = require("./checks");
44
+ const checks_api_1 = require("./checks-api");
42
45
  var discovery_2 = require("./discovery");
43
46
  Object.defineProperty(exports, "DISCOVERY_PATH", { enumerable: true, get: function () { return discovery_2.DISCOVERY_PATH; } });
44
47
  Object.defineProperty(exports, "SERVER_PROTOCOL", { enumerable: true, get: function () { return discovery_2.SERVER_PROTOCOL; } });
@@ -67,6 +70,8 @@ const HEARTBEAT_MS = 15000;
67
70
  // the longest `?wait=` of a run: below the 60 seconds after which a proxy in front of the
68
71
  // server (nginx by default) closes a connection that says nothing
69
72
  const MAX_WAIT_MS = 50000;
73
+ // how often checks older than `runs.checksKeep` are removed
74
+ const CHECK_SWEEP_MS = 6 * 60 * 60 * 1000;
70
75
  // Server-sent events: `id` is the sequence number, so a client that lost the
71
76
  // connection continues with Last-Event-ID (or ?after=) and misses nothing.
72
77
  function streamEvents(registry, config, principal, id, req, res, url) {
@@ -357,6 +362,24 @@ async function submitRun(config, registry, definitions, sources, sandboxes, plan
357
362
  (0, http_2.send)(res, 413, { error: over });
358
363
  return;
359
364
  }
365
+ // a check counts like a run from a commit of the repository, and leaves what it made in
366
+ // the repository's cache, which runs from main restore from: the caller must be allowed
367
+ // to start runs from it, and to push a branch of it, which with a run from that branch
368
+ // leaves the same
369
+ if (request.source.check && !(0, repo_1.matchesAnyRepo)(grant.repos, sandbox.repo)) {
370
+ log(`refuse run iss=${principal.iss} sub=${principal.sub}: check on ${sandbox.repo} without the repository`);
371
+ (0, http_2.send)(res, 403, {
372
+ error: `a check counts like a run from ${sandbox.repo}, which no entitlement of yours lists in repos`,
373
+ });
374
+ return;
375
+ }
376
+ if (request.source.check && (0, policy_1.sandboxPushBranches)(grant, sandbox.repo).length === 0) {
377
+ log(`refuse run iss=${principal.iss} sub=${principal.sub}: check on ${sandbox.repo} without a branch to push`);
378
+ (0, http_2.send)(res, 403, {
379
+ error: `a check counts like a run from a branch you pushed, and you may push no branch of ${sandbox.repo}`,
380
+ });
381
+ return;
382
+ }
360
383
  }
361
384
  // the accounts of a run are read from the files it is pinned to, with the engine
362
385
  const bundle = version.plan ? await definitions.files(version) : undefined;
@@ -475,9 +498,10 @@ async function submitRun(config, registry, definitions, sources, sandboxes, plan
475
498
  commit: state.commit,
476
499
  tree: state.tree,
477
500
  clean: state.clean,
501
+ ...(request.source.type === 'sandbox' && request.source.check ? { check: true } : {}),
478
502
  });
479
503
  });
480
- log(`run ${run.id} iss=${principal.iss} sub=${principal.sub} accounts=[${planned.accounts.join(',')}] source=${run.source.type}${run.source.type === 'sandbox' ? ` sandbox=${run.source.id}` : ''} tasks=${run.tasks.length}${run.up
504
+ log(`run ${run.id} iss=${principal.iss} sub=${principal.sub} accounts=[${planned.accounts.join(',')}] source=${run.source.type}${run.source.type === 'sandbox' ? ` sandbox=${run.source.id}${run.source.check ? ' check' : ''}` : ''} tasks=${run.tasks.length}${run.up
481
505
  ? ` services=[${run.up.services.join(',')}] name=${run.up.name} endpoints=${run.up.endpoints.length}`
482
506
  : ''}${approvals.length > 0 ? ` approval=[${approvals.join(',')}]` : ''}`);
483
507
  (0, http_2.send)(res, 202, toRunResponse(run));
@@ -516,7 +540,7 @@ async function authenticate(verifier, log, req, res) {
516
540
  return null;
517
541
  }
518
542
  }
519
- async function handle(config, registry, gateway, definitions, proposals, sources, sandboxes, planning, repos, verifier, log, req, res) {
543
+ async function handle(config, registry, gateway, definitions, proposals, sources, sandboxes, planning, repos, checks, verifier, log, req, res) {
520
544
  // the hosts of endpoints are the apps of service runs, not the API
521
545
  const label = gateway?.hostOf(req);
522
546
  if (gateway && label) {
@@ -558,6 +582,9 @@ async function handle(config, registry, gateway, definitions, proposals, sources
558
582
  if (await (0, proposals_api_1.handleProposals)(config, definitions, proposals, log, principal, req, res, url)) {
559
583
  return;
560
584
  }
585
+ if (await (0, checks_api_1.handleChecks)(config, checks, definitions, log, principal, req, res, url)) {
586
+ return;
587
+ }
561
588
  (0, http_2.send)(res, 404, { error: 'not found' });
562
589
  }
563
590
  async function startServer(config, environment, options = {}) {
@@ -657,6 +684,11 @@ async function startServer(config, environment, options = {}) {
657
684
  ? new kubernetes_backend_1.KubernetesExecutor({ ...config, backend }, environment.processEnvs, executorOptions)
658
685
  : new executor_1.HostExecutor(executorOptions));
659
686
  const sources = new sources_1.SourceStore((0, path_1.join)(storage, 'sources'));
687
+ const checks = new checks_1.CheckStore((0, path_1.join)(storage, 'checks'), { keep: (0, units_1.parseDuration)(config.runs.checksKeep) });
688
+ const sweepChecks = () => checks.sweep().catch((e) => log(`the old checks could not be removed: ${e instanceof Error ? e.message : e}`));
689
+ void sweepChecks();
690
+ const sweeping = setInterval(sweepChecks, CHECK_SWEEP_MS);
691
+ sweeping.unref();
660
692
  const registry = new runs_1.RunRegistry({
661
693
  executor,
662
694
  maxConcurrent: config.runs.maxConcurrent,
@@ -672,6 +704,16 @@ async function startServer(config, environment, options = {}) {
672
704
  total: config.runs.up.total,
673
705
  },
674
706
  store: new run_store_1.FileRunStore((0, path_1.join)(storage, 'records')),
707
+ // what a check run passed, for `remote verify` to find
708
+ onFinished: (run, keys) => {
709
+ const passed = (0, checks_1.getCheckRecords)(run, keys);
710
+ if (passed.length > 0) {
711
+ checks
712
+ .save(passed)
713
+ .then(() => log(`checks run=${run.id} passed=[${passed.map((record) => record.task).join(',')}]`))
714
+ .catch((e) => log(`the checks of run ${run.id} were not kept: ${e instanceof Error ? e.message : e}`));
715
+ }
716
+ },
675
717
  log,
676
718
  });
677
719
  await registry.restore();
@@ -704,7 +746,7 @@ async function startServer(config, environment, options = {}) {
704
746
  cooldown: (0, units_1.parseDuration)(config.approvals.cooldown),
705
747
  });
706
748
  const listener = (req, res) => {
707
- handle(config, registry, gateway, definitions, proposals, sources, sandboxes, planning, repos, verifier, log, req, res).catch((e) => {
749
+ handle(config, registry, gateway, definitions, proposals, sources, sandboxes, planning, repos, checks, verifier, log, req, res).catch((e) => {
708
750
  if (e instanceof http_2.HttpError) {
709
751
  (0, http_2.send)(res, e.status, { error: e.message });
710
752
  return;
@@ -795,6 +837,7 @@ async function startServer(config, environment, options = {}) {
795
837
  return { restart };
796
838
  },
797
839
  close: async () => {
840
+ clearInterval(sweeping);
798
841
  proposals.close();
799
842
  await registry.close();
800
843
  await new Promise((resolve, reject) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hammerkit",
3
3
  "description": "Containerized build tool with incremental caching that runs the same build file locally, in Docker and on Kubernetes.",
4
- "version": "1.27.0-next.16",
4
+ "version": "1.27.0-next.18",
5
5
  "keywords": [
6
6
  "build",
7
7
  "build-tool",