hammerkit 1.27.0-next.3 → 1.27.0-next.30

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 (119) hide show
  1. package/build.schema.json +188 -0
  2. package/dist/cache/backends/local-cache-backend.js +6 -0
  3. package/dist/cache/backends/registry-cache-backend.js +2 -2
  4. package/dist/cache/explain.js +17 -0
  5. package/dist/cli.js +2 -0
  6. package/dist/docker/item-network.js +13 -5
  7. package/dist/executer/deadline.js +17 -3
  8. package/dist/executer/deferred-restore.js +36 -0
  9. package/dist/executer/docker-service.js +30 -8
  10. package/dist/executer/docker-task.js +21 -1
  11. package/dist/executer/event-cache.js +20 -2
  12. package/dist/executer/execute-work-service.js +2 -0
  13. package/dist/executer/execute-work-task.js +10 -3
  14. package/dist/executer/execution-steps.js +25 -4
  15. package/dist/executer/reset-work-tree.js +4 -0
  16. package/dist/executer/scheduler/enqueue-next.js +57 -6
  17. package/dist/executer/scheduler/state-key.js +42 -5
  18. package/dist/executer/watch-loop.js +4 -1
  19. package/dist/harness/connect.js +20 -6
  20. package/dist/harness/mcp-command.js +22 -6
  21. package/dist/harness/mcp.js +63 -114
  22. package/dist/harness/opencode.js +158 -50
  23. package/dist/harness/pi.js +29 -0
  24. package/dist/harness/sandbox-client.js +168 -17
  25. package/dist/harness/service-tools.js +141 -0
  26. package/dist/harness/task-tools.js +221 -0
  27. package/dist/kubernetes/apply.js +27 -16
  28. package/dist/kubernetes/await-running-state.js +59 -13
  29. package/dist/kubernetes/claim-layout.js +71 -0
  30. package/dist/kubernetes/cluster-state.js +245 -0
  31. package/dist/kubernetes/ensure-http-route.js +1 -1
  32. package/dist/kubernetes/ensure-kubernetes-deployment-exists.js +35 -12
  33. package/dist/kubernetes/ensure-kubernetes-persistent-volume-claim-exists.js +1 -1
  34. package/dist/kubernetes/ensure-kubernetes-service-exists.js +6 -9
  35. package/dist/kubernetes/ensure-persistent-data.js +30 -20
  36. package/dist/kubernetes/follow-pod-logs.js +182 -0
  37. package/dist/kubernetes/get-service-ip.js +2 -2
  38. package/dist/kubernetes/job-placement.js +36 -12
  39. package/dist/kubernetes/job-secrets.js +33 -19
  40. package/dist/kubernetes/kept-claims.js +22 -10
  41. package/dist/kubernetes/network-policy.js +85 -27
  42. package/dist/kubernetes/remove-persistent-data.js +3 -1
  43. package/dist/kubernetes/resources.js +25 -3
  44. package/dist/kubernetes/restore-kubernetes-data.js +9 -3
  45. package/dist/kubernetes/sandbox-runner.js +628 -0
  46. package/dist/kubernetes/secrets.js +7 -11
  47. package/dist/kubernetes/volumes.js +6 -3
  48. package/dist/main.js +2 -0
  49. package/dist/network/egress-proxy.js +45 -6
  50. package/dist/optimizer/calculate-checksum.js +3 -2
  51. package/dist/optimizer/check-key.js +94 -0
  52. package/dist/optimizer/check-keys.js +64 -0
  53. package/dist/optimizer/get-work-cache-stats.js +17 -3
  54. package/dist/optimizer/work-task-cache-description.js +51 -1
  55. package/dist/planner/utils/append-work-dependencies.js +10 -5
  56. package/dist/planner/utils/append-work-service.js +19 -1
  57. package/dist/planner/utils/append-work-task.js +18 -3
  58. package/dist/planner/utils/get-work-runtime.js +6 -1
  59. package/dist/planner/utils/normalize-path.js +19 -1
  60. package/dist/planner/utils/parse-work-mount.js +7 -1
  61. package/dist/planner/utils/parse-work-port.js +4 -1
  62. package/dist/planner/utils/task-arguments.js +3 -0
  63. package/dist/planner/validate.js +22 -0
  64. package/dist/planner/work-network.js +3 -1
  65. package/dist/planner/work-runtime-aggregate.js +32 -0
  66. package/dist/planner/work-runtime-docker.js +2 -1
  67. package/dist/planner/work-runtime-kubernetes.js +124 -48
  68. package/dist/planner/work-runtime-local.js +2 -1
  69. package/dist/planner/work-task.js +6 -1
  70. package/dist/program.js +31 -10
  71. package/dist/remote/device-login.js +7 -2
  72. package/dist/remote/host-config.js +69 -3
  73. package/dist/remote/remote-commands.js +30 -7
  74. package/dist/remote/remote-work-commands.js +426 -45
  75. package/dist/remote/server-client.js +15 -2
  76. package/dist/remote/token-source.js +64 -26
  77. package/dist/run-program.js +9 -0
  78. package/dist/schema/build-file-base-task-schema.js +8 -1
  79. package/dist/schema/build-file-container-service-schema.js +12 -0
  80. package/dist/schema/build-file-container-task-schema.js +16 -1
  81. package/dist/schema/build-file-include-schema.js +18 -4
  82. package/dist/schema/build-file-kubernetes-service-schema.js +2 -0
  83. package/dist/schema/build-file-task-schema.js +5 -1
  84. package/dist/schema/capabilities-schema.js +56 -0
  85. package/dist/schema/reference-parser.js +120 -11
  86. package/dist/schema/schema-parser.js +92 -41
  87. package/dist/schema/work-scope-parser.js +33 -10
  88. package/dist/secrets/command-secret-provider.js +3 -1
  89. package/dist/secrets/github-app-token-command.js +3 -1
  90. package/dist/secrets/secret-catalog.js +43 -19
  91. package/dist/server/accounts-api.js +3 -1
  92. package/dist/server/approvals-api.js +1 -1
  93. package/dist/server/checks-api.js +83 -0
  94. package/dist/server/checks.js +116 -0
  95. package/dist/server/definitions-api.js +66 -3
  96. package/dist/server/endpoints.js +739 -0
  97. package/dist/server/executor.js +57 -5
  98. package/dist/server/kubernetes-backend.js +367 -65
  99. package/dist/server/kubernetes-sandbox-storage.js +48 -3
  100. package/dist/server/oauth.js +12 -1
  101. package/dist/server/plan.js +188 -103
  102. package/dist/server/policy.js +32 -2
  103. package/dist/server/repo-access.js +5 -0
  104. package/dist/server/run-plan.js +50 -19
  105. package/dist/server/run-request.js +58 -3
  106. package/dist/server/run-worker.js +245 -12
  107. package/dist/server/runs.js +410 -27
  108. package/dist/server/sandbox-pod.js +28 -0
  109. package/dist/server/sandbox-storage.js +23 -0
  110. package/dist/server/sandboxes-api.js +10 -4
  111. package/dist/server/sandboxes.js +8 -0
  112. package/dist/server/server-command.js +39 -20
  113. package/dist/server/server-config.js +255 -14
  114. package/dist/server/server.js +269 -15
  115. package/dist/server/service-runs.js +82 -0
  116. package/dist/utils/abort-on-signals.js +46 -6
  117. package/dist/utils/tar.js +36 -0
  118. package/dist/utils/terminal-prompt.js +53 -0
  119. package/package.json +1 -1
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HostExecutor = exports.volumeScope = exports.cacheNamespace = exports.defaultWorker = void 0;
4
4
  const child_process_1 = require("child_process");
5
5
  const crypto_1 = require("crypto");
6
+ const checks_1 = require("./checks");
6
7
  const fs_1 = require("fs");
7
8
  const promises_1 = require("fs/promises");
8
9
  const path_1 = require("path");
@@ -35,9 +36,18 @@ exports.defaultWorker = defaultWorker;
35
36
  // share one, those of an upload or a sandbox only their owner's. Somebody who can only
36
37
  // upload, or an agent on a sandbox, can not leave an entry for a run from a reviewed
37
38
  // repository to find.
39
+ //
40
+ // A check on a sandbox runs on a copy of the files a commit of them would hold, so it is a
41
+ // run of the repository like a ref run of that commit, and shares its cache: what its
42
+ // owner may write in the sandbox is not part of it. It leaves entries a run from main can
43
+ // find, keyed by the files it ran on, as a ref run of a branch does: so only a caller who
44
+ // may push a branch of the repository and run from it may check (server.ts).
38
45
  function cacheNamespace(run) {
39
- const key = run.source.type === 'ref' ? `ref\0${run.source.repo}` : `${run.source.type}\0${run.owner.iss}\0${run.owner.sub}`;
40
- return `${run.source.type}-${(0, crypto_1.createHash)('sha256').update(key).digest('hex').slice(0, 24)}`;
46
+ const repository = run.source.type === 'ref' || (run.source.type === 'sandbox' && run.source.check);
47
+ const key = repository
48
+ ? `ref\0${run.source.repo}`
49
+ : `${run.source.type}\0${run.owner.iss}\0${run.owner.sub}`;
50
+ return `${repository ? 'ref' : run.source.type}-${(0, crypto_1.createHash)('sha256').update(key).digest('hex').slice(0, 24)}`;
41
51
  }
42
52
  exports.cacheNamespace = cacheNamespace;
43
53
  // The docker volumes of a run's services are its caller's, within the cache's source trust:
@@ -100,7 +110,7 @@ class HostExecutor {
100
110
  if (extra.length > 0) {
101
111
  throw new Error(`the run would use ${extra.join(', ')}, which it was not admitted for`);
102
112
  }
103
- const refused = (0, run_plan_1.refuseArguments)(run, planned.plan);
113
+ const refused = (0, run_plan_1.refuseArguments)(run, planned.plan, policy);
104
114
  if (refused) {
105
115
  throw new Error(refused);
106
116
  }
@@ -121,13 +131,42 @@ class HostExecutor {
121
131
  let claim;
122
132
  // the files of the sandbox the tasks work on
123
133
  let work;
124
- if (source.type === 'ref') {
134
+ if (source.type === 'sandbox' && source.check) {
135
+ // a check works on the files a push of the sandbox commits, copied out of it: never
136
+ // on the sandbox, whose ignored files (node_modules, outputs) its owner writes
137
+ const { registry, network } = sandboxes;
138
+ cwd = (0, path_1.join)(root, 'source');
139
+ try {
140
+ await registry.exportTree(source.id, source.tree, cwd, abortCtrl.signal);
141
+ }
142
+ catch (e) {
143
+ throw new Error(`the files of the sandbox ${source.id} could not be copied for the check, submit it again: ${e instanceof Error ? e.message : String(e)}`);
144
+ }
145
+ // a repository of its own, as a checkout of the commit is: the root of the project,
146
+ // which the paths of the tasks' keys are relative to, is the one of git
147
+ await (0, git_checkout_1.git)(['init', '--quiet', cwd], {}, abortCtrl.signal, `the check of sandbox ${source.id}`, 'init');
148
+ context.emit({
149
+ type: 'log',
150
+ task: 'hammerkit',
151
+ stream: 'stdout',
152
+ text: `check of sandbox ${source.id} of ${source.repo}: files ${source.tree}, fetched at ${source.commit}`,
153
+ });
154
+ await this.writeBundle(cwd, bundle.files);
155
+ input = {
156
+ entry: (0, path_1.join)(cwd, version.entry),
157
+ ...(planning.policy.network ? { network: (0, work_network_1.toNetworkSchema)(planning.policy.network) } : {}),
158
+ sandboxNetwork: network,
159
+ };
160
+ }
161
+ else if (source.type === 'ref') {
125
162
  cwd = (0, path_1.join)(root, 'source');
126
163
  const { repo, ref, commit: pinned } = source;
127
164
  const credentials = await repos.credentials(repo);
128
165
  let commit;
129
166
  try {
130
- commit = await (0, git_checkout_1.checkoutRef)(repos.url(repo), ref, cwd, credentials.env, abortCtrl.signal, pinned);
167
+ // a woken service run starts the commit it started first, where the ref is now or not
168
+ const fetched = run.wakes ? pinned : ref;
169
+ commit = await (0, git_checkout_1.checkoutRef)(repos.url(repo), fetched, cwd, credentials.env, abortCtrl.signal, pinned);
131
170
  }
132
171
  catch (e) {
133
172
  throw repos.scrub(e, credentials.values);
@@ -188,8 +227,18 @@ class HostExecutor {
188
227
  options: run.options,
189
228
  accounts: run.accounts,
190
229
  volumeScope: volumeScope(run),
230
+ ...((0, checks_1.isCheckRun)(run) ? { check: true } : {}),
191
231
  catalog: planning.environment.hosted?.catalog,
232
+ ...(run.up
233
+ ? {
234
+ up: {
235
+ services: run.up.services,
236
+ endpoints: run.up.endpoints.map(({ service, port }) => ({ service, port })),
237
+ },
238
+ }
239
+ : {}),
192
240
  ...(placed ? { kubernetes: placed.kubernetes } : {}),
241
+ ...(!placed && this.options.capabilityRuntime ? { capabilityRuntime: this.options.capabilityRuntime } : {}),
193
242
  }, cwd, { ...this.processEnvironment(home, cache), ...placed?.env }, context, abortCtrl.signal);
194
243
  }
195
244
  finally {
@@ -282,6 +331,9 @@ class HostExecutor {
282
331
  if (message.kind === 'event') {
283
332
  context.emit(message.event);
284
333
  }
334
+ else if (message.kind === 'up') {
335
+ context.up?.(message.targets);
336
+ }
285
337
  else if (message.kind === 'result') {
286
338
  result = message;
287
339
  // nothing left to tell the process