hammerkit 2.1.0-next.9 → 2.2.0-next.1

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 (70) hide show
  1. package/dist/dashboard/assets/{graph-canvas-BFnEN5i0.js → graph-canvas-D6GMgkoe.js} +1 -1
  2. package/dist/dashboard/assets/index-BNq9j5Jo.js +23 -0
  3. package/dist/dashboard/assets/{index-Dt3ITvRO.css → index-DP3_hKOe.css} +1 -1
  4. package/dist/dashboard/index.html +2 -2
  5. package/dist/executer/archive-task-entry.js +1 -1
  6. package/dist/executer/deadline.js +63 -10
  7. package/dist/executer/event-cache.js +5 -1
  8. package/dist/executer/execute-work-task.js +15 -3
  9. package/dist/executer/runner-commands.js +36 -0
  10. package/dist/file/get-file-context.js +4 -7
  11. package/dist/harness/connect.js +12 -8
  12. package/dist/harness/reconnect.js +141 -0
  13. package/dist/harness/sandbox-client.js +242 -33
  14. package/dist/harness/service-tools.js +36 -3
  15. package/dist/kubernetes/cluster-state.js +48 -14
  16. package/dist/kubernetes/ensure-persistent-data.js +15 -4
  17. package/dist/kubernetes/follow-pod-logs.js +8 -5
  18. package/dist/kubernetes/kept-claims.js +26 -5
  19. package/dist/kubernetes/resources.js +5 -1
  20. package/dist/kubernetes/sandbox-runner.js +526 -156
  21. package/dist/kubernetes/store-kubernetes-data.js +18 -3
  22. package/dist/kubernetes/sync-changes.js +463 -0
  23. package/dist/kubernetes/volumes.js +23 -1
  24. package/dist/optimizer/get-work-cache-stats.js +7 -0
  25. package/dist/planner/work-item-status.js +12 -2
  26. package/dist/planner/work-runtime-aggregate.js +1 -0
  27. package/dist/planner/work-runtime-docker.js +9 -5
  28. package/dist/planner/work-runtime-kubernetes.js +277 -55
  29. package/dist/planner/work-runtime-local.js +8 -4
  30. package/dist/remote/annotations.js +29 -3
  31. package/dist/remote/bundle.js +6 -8
  32. package/dist/remote/collect-bundle.js +3 -2
  33. package/dist/remote/device-login.js +4 -1
  34. package/dist/remote/remote-commands.js +16 -7
  35. package/dist/remote/remote-work-commands.js +265 -72
  36. package/dist/remote/server-client.js +38 -40
  37. package/dist/server/artifacts-api.js +56 -0
  38. package/dist/server/definitions-api.js +62 -8
  39. package/dist/server/endpoints.js +52 -32
  40. package/dist/server/executor.js +117 -30
  41. package/dist/server/http.js +4 -1
  42. package/dist/server/keep-artifacts.js +230 -0
  43. package/dist/server/kubernetes-backend.js +186 -59
  44. package/dist/server/kubernetes-sandbox-storage.js +83 -22
  45. package/dist/server/overview.js +67 -9
  46. package/dist/server/paging.js +167 -0
  47. package/dist/server/plan.js +8 -1
  48. package/dist/server/public-paths.js +52 -0
  49. package/dist/server/run-access.js +24 -0
  50. package/dist/server/run-artifacts.js +171 -0
  51. package/dist/server/run-logs.js +25 -1
  52. package/dist/server/run-request.js +63 -1
  53. package/dist/server/run-retry.js +6 -0
  54. package/dist/server/run-worker.js +267 -33
  55. package/dist/server/runs.js +527 -99
  56. package/dist/server/sandbox-files.js +9 -8
  57. package/dist/server/sandbox-follow.js +54 -0
  58. package/dist/server/sandbox-storage.js +38 -1
  59. package/dist/server/sandbox-sync.js +392 -0
  60. package/dist/server/sandboxes-api.js +54 -8
  61. package/dist/server/sandboxes.js +19 -0
  62. package/dist/server/server-config.js +14 -0
  63. package/dist/server/server.js +189 -46
  64. package/dist/server/service-runs.js +41 -8
  65. package/dist/server/task-order.js +56 -0
  66. package/dist/utils/project-path.js +20 -0
  67. package/dist/utils/tar-files.js +52 -0
  68. package/dist/utils/tar.js +37 -1
  69. package/package.json +1 -1
  70. package/dist/dashboard/assets/index-CE5PSB3y.js +0 -23
@@ -3,23 +3,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.registerWorkCommands = exports.describePlan = exports.describeApproval = exports.keepRuns = exports.describeListedRun = exports.describeRunEnd = void 0;
6
+ exports.registerWorkCommands = exports.describeArtifacts = exports.selectArtifacts = exports.keptProjectOutputs = exports.isProjectPath = exports.describePlan = exports.describeApproval = exports.keepRuns = exports.describeListedRun = exports.describeRunEnd = void 0;
7
7
  const commander_1 = require("commander");
8
8
  const colors_1 = __importDefault(require("colors"));
9
- const token_source_1 = require("./token-source");
10
9
  const collect_bundle_1 = require("./collect-bundle");
11
10
  const bundle_1 = require("./bundle");
12
11
  const annotations_1 = require("./annotations");
12
+ const repo_1 = require("../server/repo");
13
13
  const server_client_1 = require("./server-client");
14
14
  const bundle_text_1 = require("./bundle-text");
15
15
  const sandbox_client_1 = require("../harness/sandbox-client");
16
16
  const units_1 = require("../utils/units");
17
17
  const service_tools_1 = require("../harness/service-tools");
18
+ const reconnect_1 = require("../harness/reconnect");
18
19
  const path_1 = require("path");
20
+ const promises_1 = require("fs/promises");
21
+ const os_1 = require("os");
22
+ const tar_1 = require("../utils/tar");
19
23
  const check_keys_1 = require("../optimizer/check-keys");
20
24
  const remote_status_1 = require("./remote-status");
21
25
  const timings_1 = require("../server/timings");
22
26
  const terminal_prompt_1 = require("../utils/terminal-prompt");
27
+ const project_path_1 = require("../utils/project-path");
23
28
  function describeOutcome(planned) {
24
29
  switch (planned.outcome) {
25
30
  case 'published':
@@ -169,35 +174,151 @@ function describePlan(plan) {
169
174
  ]);
170
175
  }
171
176
  exports.describePlan = describePlan;
177
+ // A path in the project, as the server names an output: relative, `/` separated, no `.` or
178
+ // `..` in it. A file is written at it.
179
+ function isProjectPath(path) {
180
+ return (0, project_path_1.isRelativePath)(path, 4096);
181
+ }
182
+ exports.isProjectPath = isProjectPath;
183
+ // `--path` as written: `./app/screenshots/` is `app/screenshots`
184
+ function projectPath(value) {
185
+ const path = path_1.posix
186
+ .normalize(value.replace(/\\/g, '/'))
187
+ .replace(/^(\.\/)+/, '')
188
+ .replace(/\/+$/, '');
189
+ if (!isProjectPath(path)) {
190
+ throw new Error('--path is a path in the project, such as app/cypress/screenshots');
191
+ }
192
+ return path;
193
+ }
194
+ // The outputs a server names that are paths in the project: one that is not is written nowhere,
195
+ // whatever the server says of it.
196
+ function keptProjectOutputs(outputs) {
197
+ return outputs.filter((output) => isProjectPath(output.path));
198
+ }
199
+ exports.keptProjectOutputs = keptProjectOutputs;
200
+ /**
201
+ * The outputs `remote artifacts` takes, each with what of it: of one task, and the output at a
202
+ * path, the outputs below it, or the files below it of the output it is in.
203
+ */
204
+ function selectArtifacts(outputs, options) {
205
+ return outputs
206
+ .filter((output) => options.task === undefined || output.task === options.task)
207
+ .flatMap((output) => {
208
+ const path = options.path;
209
+ if (path === undefined || output.path.startsWith(`${path}/`)) {
210
+ return [{ output, below: output.path }];
211
+ }
212
+ return path === output.path || path.startsWith(`${output.path}/`) ? [{ output, below: path }] : [];
213
+ });
214
+ }
215
+ exports.selectArtifacts = selectArtifacts;
216
+ // Writes the chosen outputs into `out`, each at its paths in the project. Only entries of the
217
+ // output, or of the path asked for, are written, and no link out of them: the archives come
218
+ // from a server.
219
+ async function downloadArtifacts(connection, id, chosen, out, write) {
220
+ const staging = await (0, promises_1.mkdtemp)((0, path_1.join)((0, os_1.tmpdir)(), 'hammerkit-artifacts-'));
221
+ try {
222
+ await (0, promises_1.mkdir)(out, { recursive: true });
223
+ for (const { output, below } of chosen) {
224
+ const file = (0, path_1.join)(staging, `${output.id}.tgz`);
225
+ await (0, sandbox_client_1.downloadRunArtifact)(connection, id, output.id, file);
226
+ await (0, tar_1.extractOutput)(file, out, below, true);
227
+ write(`${(0, server_client_1.printable)(below)} of ${(0, server_client_1.printable)(output.task)} -> ${(0, path_1.join)(out, below)}`);
228
+ }
229
+ }
230
+ finally {
231
+ await (0, promises_1.rm)(staging, { recursive: true, force: true });
232
+ }
233
+ }
234
+ function describeArtifacts(id, serverName, kept, outputs) {
235
+ const left = kept.left.map((output) => `did not keep ${(0, server_client_1.printable)(output.path)} of ${(0, server_client_1.printable)(output.task)}: ${(0, server_client_1.printable)(output.reason)}`);
236
+ if (outputs.length === 0) {
237
+ return [
238
+ `${(0, server_client_1.printable)(id)} on ${serverName} kept no outputs${kept.reason ? `: ${(0, server_client_1.printable)(kept.reason)}` : ''}`,
239
+ ...left,
240
+ ];
241
+ }
242
+ const tasks = Math.max(...outputs.map((output) => (0, server_client_1.printable)(output.task).length));
243
+ const paths = Math.max(...outputs.map((output) => (0, server_client_1.printable)(output.path).length));
244
+ return [
245
+ `${(0, server_client_1.printable)(id)} on ${serverName} kept ${outputs.length} ${outputs.length === 1 ? 'output' : 'outputs'}, until ${(0, server_client_1.printable)(kept.expiresAt ?? '-')}:`,
246
+ ...outputs.map((output) => ` ${(0, server_client_1.printable)(output.task).padEnd(tasks)} ${(0, server_client_1.printable)(output.path).padEnd(paths)} ${(0, units_1.formatSize)(output.bytes)}`),
247
+ ...left,
248
+ `download them with: hammerkit remote artifacts ${(0, server_client_1.printable)(id)} --out <dir>`,
249
+ ];
250
+ }
251
+ exports.describeArtifacts = describeArtifacts;
252
+ // The ref of a detached checkout: the one branch or tag of origin at its commit. The server
253
+ // would also fetch the commit itself, but an account limited to some branches (`refs`) never
254
+ // runs for a commit, and the run would not say where its code comes from. A branch and a tag
255
+ // of the same name are two heads, which the server can not tell apart by the name.
256
+ function onlyHead(heads) {
257
+ return heads?.length === 1 ? heads[0].name : undefined;
258
+ }
259
+ // why the ref of a run is not known, and what to do
260
+ function describeMissingRef(repo, ours, checkout) {
261
+ if (!checkout.commit) {
262
+ return `name the branch or tag of ${(0, server_client_1.printable)(repo)} with --ref, there is no commit checked out here`;
263
+ }
264
+ if (!ours) {
265
+ return `name the branch or tag of ${(0, server_client_1.printable)(repo)} with --ref, the checkout here is on no branch and ${checkout.repo ? `of ${(0, server_client_1.printable)(checkout.repo)}` : 'has no origin it can be told by'}`;
266
+ }
267
+ const heads = checkout.heads ?? [];
268
+ if (heads.length === 0) {
269
+ return (`the checkout here is on no branch, and no branch or tag of origin is at its commit ${checkout.commit}: ` +
270
+ 'name the branch or tag with --ref');
271
+ }
272
+ const names = heads.map((head) => `${head.kind} ${(0, server_client_1.printable)(head.name)}`);
273
+ const twice = heads.find((head, i) => heads.findIndex((other) => other.name === head.name) !== i);
274
+ return (`the checkout here is on no branch, and its commit ${checkout.commit} is the head of ` +
275
+ `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]} of origin: ` +
276
+ (twice
277
+ ? `${(0, server_client_1.printable)(twice.name)} is a branch and a tag, which --ref can not tell apart: ` +
278
+ `name another, or the commit with --ref ${checkout.commit}`
279
+ : 'name one with --ref'));
280
+ }
281
+ // A call the server refused, said as `callServer` says it: by the server and what it answered
282
+ function describeRefusal(url, e) {
283
+ if (!(e instanceof sandbox_client_1.SandboxClientError) || e.status === undefined || e.status === 401) {
284
+ return e;
285
+ }
286
+ const said = e.message.startsWith(`${(0, reconnect_1.showUrl)(url)} answered`) ? '' : `: ${(0, server_client_1.printable)(e.message)}`;
287
+ return new server_client_1.ServerError(`${(0, reconnect_1.showUrl)(url)} answered ${e.status}${said}`, e.status);
288
+ }
172
289
  function registerWorkCommands(remote, context) {
173
290
  const { environment, buildFile, getServer, guarded, passthrough, fail } = context;
174
291
  // the ref a run starts from: what the options name, else the checkout here
175
292
  const refSource = async (options) => {
176
293
  const checkout = options.repo && options.ref ? {} : await (0, annotations_1.readCheckout)((0, path_1.dirname)(buildFile));
177
294
  const repo = options.repo ?? checkout.repo;
178
- const ref = options.ref ?? checkout.branch;
179
- // the commit checked out here is the code meant, when the ref is the branch it is on
180
- const commit = options.commit ?? (options.ref ? undefined : checkout.commit);
181
295
  if (!repo) {
182
296
  throw new Error('name the repository with --repo, the checkout here has no origin it can be told by');
183
297
  }
298
+ // the heads of origin name refs of the repository of the run only when origin is that one
299
+ const ours = !!checkout.repo && (0, repo_1.normalizeRepo)(repo) === checkout.repo;
300
+ const ref = options.ref ?? checkout.branch ?? (ours ? onlyHead(checkout.heads) : undefined);
184
301
  if (!ref) {
185
- throw new Error('name the branch or tag with --ref, the checkout here is on no branch');
302
+ throw new Error(describeMissingRef(repo, ours, checkout));
186
303
  }
304
+ // the commit checked out here is the code meant, when the ref is the branch it is on, or
305
+ // the one branch or tag of a detached checkout: when it moved since, the server refuses the run
306
+ const commit = options.commit ?? (options.ref ? undefined : checkout.commit);
187
307
  return { type: 'ref', repo, ref, ...(commit ? { commit } : {}) };
188
308
  };
309
+ // the server to call: its token is read for each call, a CI job or an agent brings its own, a
310
+ // person signs in
189
311
  const connect = async (name, how) => {
190
312
  const chosen = await getServer(name, how);
191
- // a CI job or an agent brings its own token, a person signs in
192
- const token = await (0, token_source_1.getTokenSource)(environment, chosen.name, chosen.server).token();
193
- return { ...chosen, token };
313
+ return { ...chosen, connection: (0, sandbox_client_1.getServerConnection)(environment, chosen.name, chosen.server) };
194
314
  };
195
315
  // publishes the bundle with where it comes from and says what it is now: published,
196
316
  // already published, or only proposed
197
- const publishBundle = async (serverName, server, token, bundle, annotations) => {
198
- const answer = await (0, server_client_1.callServer)(server, token, 'POST', '/v1/definitions', {
199
- ...bundle,
200
- annotations,
317
+ const publishBundle = async (serverName, connection, bundle, annotations) => {
318
+ // what is published already changes nothing and is said so: sent again, it is the same
319
+ const answer = await (0, server_client_1.callServer)(connection, 'POST', '/v1/definitions', {
320
+ body: { ...bundle, annotations },
321
+ repeat: 'always',
201
322
  });
202
323
  const version = answer.body;
203
324
  const files = Object.keys(bundle.files).length;
@@ -222,9 +343,13 @@ function registerWorkCommands(remote, context) {
222
343
  return { version, proposed };
223
344
  };
224
345
  // what publishing the bundle would do, undefined from a server that can't say (before 2.0)
225
- const planBundle = async (server, token, bundle) => {
346
+ const planBundle = async (connection, bundle) => {
226
347
  try {
227
- return (await (0, server_client_1.callServer)(server, token, 'POST', '/v1/definitions/plan', bundle)).body;
348
+ // a plan stores nothing, so it is sent again as often as the server does not answer
349
+ return (await (0, server_client_1.callServer)(connection, 'POST', '/v1/definitions/plan', {
350
+ body: bundle,
351
+ repeat: 'always',
352
+ })).body;
228
353
  }
229
354
  catch (e) {
230
355
  if (e instanceof server_client_1.ServerError && e.status === 404) {
@@ -246,7 +371,11 @@ function registerWorkCommands(remote, context) {
246
371
  }
247
372
  return { definition: named };
248
373
  }
249
- const local = await (0, collect_bundle_1.collectBundle)(buildFile, environment);
374
+ const local = await (0, collect_bundle_1.collectBundle)(buildFile, environment, {
375
+ // most often run in another folder than the checkout meant
376
+ missing: 'Run this in the checkout whose build file the server has, ' +
377
+ 'or name a published version with --build <hash>, listed by: hammerkit remote versions',
378
+ });
250
379
  return { definition: (0, bundle_1.hashBundle)(local), local };
251
380
  };
252
381
  // Submits a run of a published version. When the server does not have the build file
@@ -254,7 +383,7 @@ function registerWorkCommands(remote, context) {
254
383
  // terminal says so. Without a terminal and without --publish the run fails and says how
255
384
  // to publish it, so CI never waits on a question.
256
385
  const submitPublishing = async (target, request, local, publish) => {
257
- const { serverName, server, connection } = target;
386
+ const { serverName, connection } = target;
258
387
  try {
259
388
  return await (0, sandbox_client_1.submitRun)(connection, request);
260
389
  }
@@ -266,14 +395,13 @@ function registerWorkCommands(remote, context) {
266
395
  }
267
396
  const definition = request.definition;
268
397
  const notPublished = `the build file here is not published on ${serverName} (${definition})`;
269
- const token = await connection.token();
270
398
  if (!publish) {
271
399
  if (!environment.prompt) {
272
400
  throw new Error(`${notPublished}, publish it first with: hammerkit remote publish ${serverName}, or pass --publish`);
273
401
  }
274
402
  // a server before 2.0 can't say what publishing would do: it is asked all the same,
275
403
  // and refuses then what the caller may not do
276
- const planned = await planBundle(server, token, local);
404
+ const planned = await planBundle(connection, local);
277
405
  if (planned && planned.outcome === null) {
278
406
  throw new Error(`${notPublished}, and you may only run published build files (builds: run): ` +
279
407
  `somebody who may publish publishes it with: hammerkit remote publish ${serverName}`);
@@ -299,7 +427,7 @@ function registerWorkCommands(remote, context) {
299
427
  }
300
428
  }
301
429
  const annotations = await (0, annotations_1.collectAnnotations)(buildFile, Object.keys(local.files));
302
- const { version, proposed } = await publishBundle(serverName, server, token, local, annotations).catch((e) => {
430
+ const { version, proposed } = await publishBundle(serverName, connection, local, annotations).catch((e) => {
303
431
  throw e instanceof server_client_1.ServerError && e.status === 403 ? new Error(`${notPublished}, ${e.message}`) : e;
304
432
  });
305
433
  if (version.hash !== definition) {
@@ -319,8 +447,11 @@ function registerWorkCommands(remote, context) {
319
447
  .action(guarded('Remote publish was not successful', async (name, options) => {
320
448
  const bundle = await (0, collect_bundle_1.collectBundle)(buildFile, environment);
321
449
  if (options.dryRun) {
322
- const { name: serverName, server, token } = await connect(name);
323
- const answer = await (0, server_client_1.callServer)(server, token, 'POST', '/v1/definitions/plan', bundle).catch((e) => {
450
+ const { name: serverName, connection } = await connect(name);
451
+ const answer = await (0, server_client_1.callServer)(connection, 'POST', '/v1/definitions/plan', {
452
+ body: bundle,
453
+ repeat: 'always',
454
+ }).catch((e) => {
324
455
  throw e instanceof server_client_1.ServerError && e.status === 404
325
456
  ? new Error(`${serverName} can't check a build file without publishing it, it needs hammerkit 2.0`)
326
457
  : e;
@@ -334,8 +465,8 @@ function registerWorkCommands(remote, context) {
334
465
  return;
335
466
  }
336
467
  const annotations = (0, annotations_1.applyAnnotations)(await (0, annotations_1.collectAnnotations)(buildFile, Object.keys(bundle.files)), options.annotation ?? []);
337
- const { name: serverName, server, token } = await connect(name);
338
- await publishBundle(serverName, server, token, bundle, annotations);
468
+ const { name: serverName, connection } = await connect(name);
469
+ await publishBundle(serverName, connection, bundle, annotations);
339
470
  }));
340
471
  remote
341
472
  .command('run <tasks...>')
@@ -343,7 +474,8 @@ function registerWorkCommands(remote, context) {
343
474
  .addOption(new commander_1.Option('--server <name>', 'the server to run on; when left out, the default of remote use or the only registered server'))
344
475
  .addOption(new commander_1.Option('--build <hash>', 'the published version to run (sha256:...), or HAMMERKIT_BUILD; the hash of the build file here when left out'))
345
476
  .addOption(new commander_1.Option('--repo <host/path>', 'the repository, such as github.com/corp/payments; origin of the checkout here when left out'))
346
- .addOption(new commander_1.Option('--ref <ref>', 'the branch or tag to run; the branch checked out here when left out'))
477
+ .addOption(new commander_1.Option('--ref <ref>', 'the branch or tag to run; the branch checked out here when left out, ' +
478
+ 'or the one branch or tag of origin at the commit of a detached checkout'))
347
479
  .addOption(new commander_1.Option('--commit <sha>', 'the commit the ref has to be at, else the run is refused; the commit checked out here when --ref is left out'))
348
480
  .addOption(new commander_1.Option('--env <name>', 'the environment of the build file, as --env of run'))
349
481
  .addOption(new commander_1.Option('--cache <method>', 'as --cache of run').choices(['checksum', 'modify-date', 'none']))
@@ -356,7 +488,7 @@ function registerWorkCommands(remote, context) {
356
488
  const source = await refSource(options);
357
489
  const ref = source.ref;
358
490
  const { name: serverName, server } = await getServer(options.server, 'with --server <name>');
359
- const connection = { url: server.url, ...(0, token_source_1.getTokenSource)(environment, serverName, server) };
491
+ const connection = (0, sandbox_client_1.getServerConnection)(environment, serverName, server);
360
492
  const runOptions = {};
361
493
  for (const key of ['env', 'cache', 'timeout', 'maxTimeout']) {
362
494
  if (options[key] !== undefined) {
@@ -366,7 +498,7 @@ function registerWorkCommands(remote, context) {
366
498
  if (passthrough.length > 0) {
367
499
  runOptions.args = passthrough;
368
500
  }
369
- const submitted = await submitPublishing({ serverName, server, connection }, { definition, tasks, source, options: runOptions }, local, !!options.publish);
501
+ const submitted = await submitPublishing({ serverName, connection }, { definition, tasks, source, options: runOptions }, local, !!options.publish);
370
502
  const at = submitted.source.type === 'ref' ? ` at ${(0, server_client_1.printable)(submitted.source.commit)}` : '';
371
503
  environment.stdout.write(`${(0, server_client_1.printable)(submitted.id)} on ${serverName}: ${tasks.map(server_client_1.printable).join(', ')} from ${(0, server_client_1.printable)(ref)}${at}\n`);
372
504
  if (options.detach) {
@@ -409,6 +541,8 @@ function registerWorkCommands(remote, context) {
409
541
  'with their endpoints at addresses of their own behind the sign-in of the server')
410
542
  .addOption(new commander_1.Option('--server <name>', 'the server to run on; when left out, the default of remote use or the only registered server'))
411
543
  .addOption(new commander_1.Option('--endpoint <service:port>', 'publish this port of a service, such as web:8080; may be given more than once').argParser(collectOption))
544
+ .addOption(new commander_1.Option('--public-path <run:service:port=paths>', 'paths of an endpoint that need no sign-in of the server, for an app that signs in on its own, such as ' +
545
+ 'preview:web:8080=/mcp,/.well-known; the run is the --name of this run; may be given more than once').argParser(collectOption))
412
546
  .addOption(new commander_1.Option('--ttl <duration>', 'how long they stay once ready, such as 2h, then they are removed; the server default when left out'))
413
547
  .addOption(new commander_1.Option('--sleep-ttl <duration>', 'how long they stay up without a request, such as 30m, then they sleep until the next request wakes them; ' +
414
548
  'the server default when left out'))
@@ -416,20 +550,23 @@ function registerWorkCommands(remote, context) {
416
550
  'starts other services or another build file; the addresses stay; the branch when left out'))
417
551
  .addOption(new commander_1.Option('--build <hash>', 'the published version to run (sha256:...), or HAMMERKIT_BUILD; the hash of the build file here when left out'))
418
552
  .addOption(new commander_1.Option('--repo <host/path>', 'the repository; origin of the checkout here when left out'))
419
- .addOption(new commander_1.Option('--ref <ref>', 'the branch or tag to start; the branch checked out here when left out'))
553
+ .addOption(new commander_1.Option('--ref <ref>', 'the branch or tag to start; the branch checked out here when left out, ' +
554
+ 'or the one branch or tag of origin at the commit of a detached checkout'))
420
555
  .addOption(new commander_1.Option('--commit <sha>', 'the commit the ref has to be at; the commit checked out here when --ref is left out'))
421
556
  .addOption(new commander_1.Option('--env <name>', 'the environment of the build file, as --env of run'))
422
557
  .addOption(new commander_1.Option('--publish', 'publish the build file here first when the server does not have it, without asking; for CI and scripts'))
423
558
  .action(guarded('Remote up was not successful', async (services, options) => {
424
559
  const { definition, local } = await runDefinition(options);
425
560
  const endpoints = (options.endpoint ?? []).map(service_tools_1.parseEndpoint);
561
+ const publicPaths = (options.publicPath ?? []).map(service_tools_1.parsePublicPath);
426
562
  const source = await refSource(options);
427
563
  const { name: serverName, server } = await getServer(options.server, 'with --server <name>');
428
- const connection = { url: server.url, ...(0, token_source_1.getTokenSource)(environment, serverName, server) };
429
- const submitted = await submitPublishing({ serverName, server, connection }, {
564
+ const connection = (0, sandbox_client_1.getServerConnection)(environment, serverName, server);
565
+ const submitted = await submitPublishing({ serverName, connection }, {
430
566
  definition,
431
567
  services,
432
568
  endpoints,
569
+ ...(publicPaths.length > 0 ? { publicPaths } : {}),
433
570
  ...(options.ttl ? { ttl: options.ttl } : {}),
434
571
  ...(options.sleepTtl ? { sleepTtl: options.sleepTtl } : {}),
435
572
  ...(options.name ? { name: options.name } : {}),
@@ -485,8 +622,8 @@ function registerWorkCommands(remote, context) {
485
622
  .description('show how a server stands for you: the places that run, the queue and why each run in it waits, your limits and the runs that count against them, your service runs')
486
623
  .addOption(new commander_1.Option('--json', 'print the overview as the server answers it, for scripts and agents'))
487
624
  .action(guarded('Remote status was not successful', async (name, options) => {
488
- const { name: serverName, server, token } = await connect(name);
489
- const overview = (await (0, server_client_1.callServer)(server, token, 'GET', '/v1/overview')).body;
625
+ const { name: serverName, connection } = await connect(name);
626
+ const overview = (await (0, server_client_1.callServer)(connection, 'GET', '/v1/overview')).body;
490
627
  if (options.json) {
491
628
  environment.stdout.write(`${JSON.stringify(overview, null, 2)}\n`);
492
629
  return;
@@ -495,7 +632,8 @@ function registerWorkCommands(remote, context) {
495
632
  environment.stdout.write(`${line}\n`);
496
633
  }
497
634
  // a server from before /v1/capacity, or one that can not read it, prints without
498
- const capacity = await (0, server_client_1.callServer)(server, token, 'GET', '/v1/capacity').catch(() => undefined);
635
+ // best effort, printed after the overview: it is not waited for, the overview is already out
636
+ const capacity = await (0, server_client_1.callServer)(connection, 'GET', '/v1/capacity', { reconnectMs: 0 }).catch(() => undefined);
499
637
  if (capacity) {
500
638
  for (const line of (0, remote_status_1.describeCapacity)(capacity.body, true)) {
501
639
  environment.stdout.write(`${line}\n`);
@@ -507,8 +645,8 @@ function registerWorkCommands(remote, context) {
507
645
  .description('show what the machines of a server have and what its runs take: CPU and memory requested and in use, per namespace on Kubernetes')
508
646
  .addOption(new commander_1.Option('--json', 'print it as the server answers it'))
509
647
  .action(guarded('Remote capacity was not successful', async (name, options) => {
510
- const { server, token } = await connect(name);
511
- const capacity = (await (0, server_client_1.callServer)(server, token, 'GET', '/v1/capacity')).body;
648
+ const { connection } = await connect(name);
649
+ const capacity = (await (0, server_client_1.callServer)(connection, 'GET', '/v1/capacity')).body;
512
650
  if (options.json) {
513
651
  environment.stdout.write(`${JSON.stringify(capacity, null, 2)}\n`);
514
652
  return;
@@ -525,7 +663,7 @@ function registerWorkCommands(remote, context) {
525
663
  .addOption(new commander_1.Option('--until <when>', 'only the runs created until then: back from now, or a time'))
526
664
  .addOption(new commander_1.Option('--json', 'print it as the server answers it'))
527
665
  .action(guarded('Remote tasks was not successful', async (name, options) => {
528
- const { name: serverName, server, token } = await connect(name);
666
+ const { name: serverName, connection } = await connect(name);
529
667
  const query = new URLSearchParams({ scope: options.mine ? 'mine' : 'visible' });
530
668
  if (options.since) {
531
669
  query.set('since', options.since);
@@ -533,7 +671,7 @@ function registerWorkCommands(remote, context) {
533
671
  if (options.until) {
534
672
  query.set('until', options.until);
535
673
  }
536
- const { tasks } = (await (0, server_client_1.callServer)(server, token, 'GET', `/v1/tasks?${query}`)).body;
674
+ const { tasks } = (await (0, server_client_1.callServer)(connection, 'GET', `/v1/tasks?${query}`)).body;
537
675
  if (options.json) {
538
676
  environment.stdout.write(`${JSON.stringify(tasks, null, 2)}\n`);
539
677
  return;
@@ -551,7 +689,10 @@ function registerWorkCommands(remote, context) {
551
689
  .description('print the address of the dashboard of a server, the pages of remote status, services, runs and logs')
552
690
  .action(guarded('Remote dashboard was not successful', async (name) => {
553
691
  const { name: serverName, server } = await getServer(name);
554
- const discovery = await (0, server_client_1.getDiscovery)(server);
692
+ const discovery = await (0, server_client_1.getDiscovery)(server, {
693
+ say: (line) => environment.stderr.write(`${line}\n`),
694
+ signal: environment.abortCtrl.signal,
695
+ });
555
696
  if (!discovery.dashboard) {
556
697
  throw new Error(`${serverName} has no dashboard: it needs endpoints with a login in its config, see https://hammerkit.dev/docs/remote-compute/status#dashboard`);
557
698
  }
@@ -562,10 +703,11 @@ function registerWorkCommands(remote, context) {
562
703
  .description('list the service runs that are starting, up or asleep: yours, and those whose endpoints you may open, with their addresses and when they end or sleep')
563
704
  .addOption(new commander_1.Option('--ended', 'also the ones that ended, as long as the server keeps them'))
564
705
  .action(guarded('Remote services was not successful', async (name, options) => {
565
- const { name: serverName, server, token } = await connect(name);
706
+ const { name: serverName, connection } = await connect(name);
566
707
  const open = ['awaiting-approval', 'queued', 'running', 'up', 'asleep'];
567
708
  const states = options.ended ? '' : `&state=${open.join(',')}`;
568
- const runs = keepRuns((await (0, server_client_1.callServer)(server, token, 'GET', `/v1/runs?scope=visible&kind=services${states}`)).body.runs, options.ended ? undefined : open, 'services');
709
+ const runs = keepRuns((await (0, server_client_1.callServer)(connection, 'GET', `/v1/runs?scope=visible&kind=services${states}`))
710
+ .body.runs, options.ended ? undefined : open, 'services');
569
711
  if (runs.length === 0) {
570
712
  environment.stdout.write(`${serverName}: no service runs${options.ended ? '' : ' are starting, up or asleep'}\n`);
571
713
  return;
@@ -599,9 +741,9 @@ function registerWorkCommands(remote, context) {
599
741
  if (options.services || options.tasks) {
600
742
  query.set('kind', options.services ? 'services' : 'tasks');
601
743
  }
602
- const { name: serverName, server, token } = await connect(name);
744
+ const { name: serverName, connection } = await connect(name);
603
745
  const path = `/v1/runs${query.toString() ? `?${query}` : ''}`;
604
- const runs = keepRuns((await (0, server_client_1.callServer)(server, token, 'GET', path)).body.runs, options.state ? String(options.state).split(',') : undefined, options.services ? 'services' : options.tasks ? 'tasks' : undefined);
746
+ const runs = keepRuns((await (0, server_client_1.callServer)(connection, 'GET', path)).body.runs, options.state ? String(options.state).split(',') : undefined, options.services ? 'services' : options.tasks ? 'tasks' : undefined);
605
747
  if (runs.length === 0) {
606
748
  environment.stdout.write(`${serverName}: ${query.toString() ? 'no runs it keeps are like that' : 'you have no runs it still keeps'}\n`);
607
749
  return;
@@ -632,7 +774,7 @@ function registerWorkCommands(remote, context) {
632
774
  throw new Error('--follow prints the whole log, leave --tail out');
633
775
  }
634
776
  const { name: serverName, server } = await getServer(name);
635
- const connection = { url: server.url, ...(0, token_source_1.getTokenSource)(environment, serverName, server) };
777
+ const connection = (0, sandbox_client_1.getServerConnection)(environment, serverName, server);
636
778
  const found = await (0, sandbox_client_1.getRun)(connection, id);
637
779
  if (!found) {
638
780
  throw new Error(`${serverName} keeps no run ${(0, server_client_1.printable)(id)} you may see, list them with: hammerkit remote runs`);
@@ -663,6 +805,41 @@ function registerWorkCommands(remote, context) {
663
805
  environment.stdout.write(`${(0, server_client_1.printable)(run.id)} is ${(0, server_client_1.printable)(run.state)}, follow it with --follow\n`);
664
806
  }
665
807
  }));
808
+ remote
809
+ .command('artifacts <run> [server]')
810
+ .description('list or download the outputs the tasks of a run that ended export (generates with export: true, ' +
811
+ 'or export: always also of a task that failed); none of a run in which anything reads a secret')
812
+ .addOption(new commander_1.Option('--task <name>', 'only the outputs of this task'))
813
+ .addOption(new commander_1.Option('--path <path>', 'only the output at this path in the project, or the files of one below it'))
814
+ .addOption(new commander_1.Option('--out <dir>', 'download them into this directory, at their paths in the project; else they are listed'))
815
+ .action(guarded('Remote artifacts was not successful', async (id, name, options) => {
816
+ if (!RUN_ID.test(id)) {
817
+ throw new Error(`${(0, server_client_1.printable)(id)} is not a run id (run_...), list them with: hammerkit remote runs`);
818
+ }
819
+ const path = options.path === undefined ? undefined : projectPath(options.path);
820
+ const { name: serverName, server } = await getServer(name);
821
+ const connection = (0, sandbox_client_1.getServerConnection)(environment, serverName, server);
822
+ const kept = await (0, sandbox_client_1.getRunArtifacts)(connection, id);
823
+ if (!kept) {
824
+ throw new Error(`${serverName} keeps no run ${(0, server_client_1.printable)(id)} you may see, list them with: hammerkit remote runs`);
825
+ }
826
+ const outputs = keptProjectOutputs(kept.outputs);
827
+ const chosen = selectArtifacts(outputs, { task: options.task, path });
828
+ const selecting = options.task !== undefined || path !== undefined;
829
+ if (chosen.length === 0 && selecting) {
830
+ const all = outputs.map((output) => (0, server_client_1.printable)(output.path)).join(' and ') || 'nothing';
831
+ throw new Error(`the run kept nothing ${path !== undefined ? `at or below ${(0, server_client_1.printable)(path)}` : `of ${(0, server_client_1.printable)(options.task)}`}, it kept ${all}`);
832
+ }
833
+ // nothing to download (or no --out): the listing, before anything is made
834
+ if (options.out === undefined || chosen.length === 0) {
835
+ const shown = selecting ? chosen.map(({ output }) => output) : outputs;
836
+ for (const line of describeArtifacts(id, serverName, kept, shown)) {
837
+ environment.stdout.write(`${line}\n`);
838
+ }
839
+ return;
840
+ }
841
+ await downloadArtifacts(connection, id, chosen, (0, path_1.resolve)(environment.cwd, options.out), (line) => environment.stdout.write(`${line}\n`));
842
+ }));
666
843
  remote
667
844
  .command('extend <run> <ttl> [server]')
668
845
  .description('keep a service run that is up for this long from now, such as 8h, at most the maxTtl of the server')
@@ -670,8 +847,10 @@ function registerWorkCommands(remote, context) {
670
847
  if (!RUN_ID.test(id)) {
671
848
  throw new Error(`${(0, server_client_1.printable)(id)} is not a run id (run_...)`);
672
849
  }
673
- const { name: serverName, server, token } = await connect(name);
674
- const run = (await (0, server_client_1.callServer)(server, token, 'POST', `/v1/runs/${id}/extend`, { ttl })).body;
850
+ const { name: serverName, connection } = await connect(name);
851
+ // the end becomes this long from now, and never sooner than it was: a repeat sent late ends the
852
+ // run at most a retry window later than the first one did
853
+ const run = (await (0, server_client_1.callServer)(connection, 'POST', `/v1/runs/${id}/extend`, { body: { ttl }, repeat: 'always' })).body;
675
854
  environment.stdout.write(`${(0, server_client_1.printable)(run.id)} on ${serverName} stays up until ${(0, server_client_1.printable)(run.expiresAt ?? '-')}\n`);
676
855
  }));
677
856
  remote
@@ -681,8 +860,9 @@ function registerWorkCommands(remote, context) {
681
860
  if (!RUN_ID.test(id)) {
682
861
  throw new Error(`${(0, server_client_1.printable)(id)} is not a run id (run_...)`);
683
862
  }
684
- const { name: serverName, server, token } = await connect(name);
685
- const run = (await (0, server_client_1.callServer)(server, token, 'POST', `/v1/runs/${id}/cancel`)).body;
863
+ const { name: serverName, connection } = await connect(name);
864
+ // a run that is over stays so: sent again, the stop answers the same
865
+ const run = (await (0, server_client_1.callServer)(connection, 'POST', `/v1/runs/${id}/cancel`, { repeat: 'always' })).body;
686
866
  environment.stdout.write(`${(0, server_client_1.printable)(run.id)} on ${serverName}: ${run.state === 'up' || run.state === 'running' ? 'stopping' : (0, server_client_1.printable)(run.state)}\n`);
687
867
  }));
688
868
  remote
@@ -692,8 +872,9 @@ function registerWorkCommands(remote, context) {
692
872
  if (!RUN_ID.test(id)) {
693
873
  throw new Error(`${(0, server_client_1.printable)(id)} is not a run id (run_...)`);
694
874
  }
695
- const { name: serverName, server, token } = await connect(name);
696
- const run = (await (0, server_client_1.callServer)(server, token, 'POST', `/v1/runs/${id}/retry`)).body;
875
+ const { name: serverName, connection } = await connect(name);
876
+ // each retry starts a run of its own: sent again only when the server did not take it
877
+ const run = (await (0, server_client_1.callServer)(connection, 'POST', `/v1/runs/${id}/retry`, { repeat: 'unsent' })).body;
697
878
  environment.stdout.write(`${(0, server_client_1.printable)(run.id)} on ${serverName} retries ${(0, server_client_1.printable)(id)}: ${(0, server_client_1.printable)(run.state)}, ` +
698
879
  `follow it with hammerkit remote logs ${(0, server_client_1.printable)(run.id)} --follow\n`);
699
880
  }));
@@ -723,15 +904,17 @@ function registerWorkCommands(remote, context) {
723
904
  keys.push({ task, key: found.key });
724
905
  }
725
906
  }
726
- const { name: serverName, server, token } = await connect(options.server, 'with --server <name>');
907
+ const { name: serverName, server } = await getServer(options.server, 'with --server <name>');
727
908
  const answer = keys.length > 0
728
- ? await (0, server_client_1.callServer)(server, token, 'POST', '/v1/checks/lookup', { repo, keys })
729
- : { body: { checks: [] } };
909
+ ? await (0, sandbox_client_1.lookupChecks)((0, sandbox_client_1.getServerConnection)(environment, serverName, server), repo, keys).catch((e) => {
910
+ throw describeRefusal(server.url, e);
911
+ })
912
+ : { checks: [] };
730
913
  const missing = [];
731
914
  // by what was asked, never by what was answered: a task the answer leaves out, or
732
915
  // answers for another key, is not verified
733
916
  for (const { task, key } of keys) {
734
- const check = answer.body.checks.find((answered) => answered.task === task && answered.key === key);
917
+ const check = answer.checks.find((answered) => answered.task === task && answered.key === key);
735
918
  if (check?.passed) {
736
919
  environment.stdout.write(`${(0, server_client_1.printable)(task)}: ${(0, server_client_1.printable)(describePassed(check.passed))}\n`);
737
920
  }
@@ -766,9 +949,9 @@ function registerWorkCommands(remote, context) {
766
949
  }
767
950
  query.append(filter.slice(0, index), filter.slice(index + 1));
768
951
  }
769
- const { name: serverName, server, token } = await connect(name);
952
+ const { name: serverName, connection } = await connect(name);
770
953
  const path = `/v1/definitions${query.toString() !== '' ? `?${query}` : ''}`;
771
- const { body } = await (0, server_client_1.callServer)(server, token, 'GET', path);
954
+ const { body } = await (0, server_client_1.callServer)(connection, 'GET', path);
772
955
  if (body.definitions.length === 0) {
773
956
  environment.stdout.write(`${serverName}: no published versions${query.toString() !== '' ? ' match' : ''}\n`);
774
957
  return;
@@ -793,8 +976,8 @@ function registerWorkCommands(remote, context) {
793
976
  .command('approvals [server]')
794
977
  .description('list the runs on a server that wait for your approval')
795
978
  .action(guarded('Remote approvals was not successful', async (name) => {
796
- const { name: serverName, server, token } = await connect(name);
797
- const { body } = await (0, server_client_1.callServer)(server, token, 'GET', '/v1/approvals');
979
+ const { name: serverName, connection } = await connect(name);
980
+ const { body } = await (0, server_client_1.callServer)(connection, 'GET', '/v1/approvals');
798
981
  if (body.approvals.length === 0) {
799
982
  environment.stdout.write(`${serverName}: no runs wait for your approval\n`);
800
983
  return;
@@ -807,11 +990,11 @@ function registerWorkCommands(remote, context) {
807
990
  }
808
991
  }));
809
992
  // A version that is published: who published it, what its tasks do and every file.
810
- const showPublished = async (hash, serverName, server, token) => {
993
+ const showPublished = async (hash, serverName, connection) => {
811
994
  const path = `/v1/definitions/${hash}`;
812
995
  let version;
813
996
  try {
814
- version = (await (0, server_client_1.callServer)(server, token, 'GET', path)).body;
997
+ version = (await (0, server_client_1.callServer)(connection, 'GET', path)).body;
815
998
  }
816
999
  catch (e) {
817
1000
  if (e instanceof server_client_1.ServerError && e.status === 404) {
@@ -819,7 +1002,7 @@ function registerWorkCommands(remote, context) {
819
1002
  }
820
1003
  throw e;
821
1004
  }
822
- const files = (await (0, server_client_1.callServer)(server, token, 'GET', `${path}/files`)).body;
1005
+ const files = (await (0, server_client_1.callServer)(connection, 'GET', `${path}/files`)).body;
823
1006
  environment.stdout.write(`${colors_1.default.bold((0, server_client_1.printable)(version.hash))} on ${serverName}, published by ${(0, server_client_1.printable)(version.publishedBy.sub)} (${(0, server_client_1.printable)(version.publishedBy.iss)}) at ${(0, server_client_1.printable)(version.publishedAt)}${version.approvedBy ? `, approved by ${(0, server_client_1.printable)(version.approvedBy.sub)}` : ''}\n`);
824
1007
  for (const line of [
825
1008
  ...yankLines(version),
@@ -838,22 +1021,22 @@ function registerWorkCommands(remote, context) {
838
1021
  if (!RUN_ID.test(target) && !bundle_1.HASH_PATTERN.test(target)) {
839
1022
  throw new Error(`${(0, server_client_1.printable)(target)} is not a run id or a version, list them with: hammerkit remote approvals, remote proposals or remote versions`);
840
1023
  }
841
- const { name: serverName, server, token } = await connect(name);
1024
+ const { name: serverName, connection } = await connect(name);
842
1025
  if (bundle_1.HASH_PATTERN.test(target)) {
843
1026
  const path = `/v1/proposals/${target}`;
844
1027
  let proposal;
845
1028
  try {
846
- proposal = (await (0, server_client_1.callServer)(server, token, 'GET', path)).body;
1029
+ proposal = (await (0, server_client_1.callServer)(connection, 'GET', path)).body;
847
1030
  }
848
1031
  catch (e) {
849
1032
  if (e instanceof server_client_1.ServerError && e.status === 404) {
850
- await showPublished(target, serverName, server, token);
1033
+ await showPublished(target, serverName, connection);
851
1034
  return;
852
1035
  }
853
1036
  throw e;
854
1037
  }
855
1038
  if (proposal.state === 'approved') {
856
- await showPublished(target, serverName, server, token);
1039
+ await showPublished(target, serverName, connection);
857
1040
  return;
858
1041
  }
859
1042
  if (proposal.state !== 'waiting') {
@@ -865,7 +1048,7 @@ function registerWorkCommands(remote, context) {
865
1048
  environment.stdout.write(' its files are not kept once it is decided\n');
866
1049
  return;
867
1050
  }
868
- const files = (await (0, server_client_1.callServer)(server, token, 'GET', `${path}/files`)).body;
1051
+ const files = (await (0, server_client_1.callServer)(connection, 'GET', `${path}/files`)).body;
869
1052
  environment.stdout.write(`${colors_1.default.bold((0, server_client_1.printable)(proposal.hash))} on ${serverName}, proposed by ${(0, server_client_1.printable)(proposal.proposedBy.sub)} (${(0, server_client_1.printable)(proposal.proposedBy.iss)}), ${(0, server_client_1.printable)(proposal.state)}\n`);
870
1053
  for (const line of [
871
1054
  ...annotationLines(proposal.annotations),
@@ -877,7 +1060,7 @@ function registerWorkCommands(remote, context) {
877
1060
  }
878
1061
  return;
879
1062
  }
880
- const view = (await (0, server_client_1.callServer)(server, token, 'GET', `/v1/approvals/${target}`)).body;
1063
+ const view = (await (0, server_client_1.callServer)(connection, 'GET', `/v1/approvals/${target}`)).body;
881
1064
  for (const line of describeApproval(view)) {
882
1065
  environment.stdout.write(`${line}\n`);
883
1066
  }
@@ -887,8 +1070,8 @@ function registerWorkCommands(remote, context) {
887
1070
  .command('proposals [server]')
888
1071
  .description('list the proposed versions of build files you made or may approve')
889
1072
  .action(guarded('Remote proposals was not successful', async (name) => {
890
- const { name: serverName, server, token } = await connect(name);
891
- const { body } = await (0, server_client_1.callServer)(server, token, 'GET', '/v1/proposals');
1073
+ const { name: serverName, connection } = await connect(name);
1074
+ const { body } = await (0, server_client_1.callServer)(connection, 'GET', '/v1/proposals');
892
1075
  if (body.proposals.length === 0) {
893
1076
  environment.stdout.write(`${serverName}: no proposed versions\n`);
894
1077
  return;
@@ -930,8 +1113,13 @@ function registerWorkCommands(remote, context) {
930
1113
  if (!bundle_1.HASH_PATTERN.test(target)) {
931
1114
  throw new Error(`${(0, server_client_1.printable)(target)} is not a version, name it by its hash: sha256:...`);
932
1115
  }
933
- const { name: serverName, server, token } = await connect(name);
934
- await (0, server_client_1.callServer)(server, token, 'POST', `/v1/definitions/${target}/${action}`, options.reason ? { reason: options.reason } : undefined);
1116
+ const { name: serverName, connection } = await connect(name);
1117
+ // a yank sent again after a lost answer ends the same, unless somebody let the version go on
1118
+ // in between. An unyank is not repeated then: it would let a version go on that somebody yanked
1119
+ await (0, server_client_1.callServer)(connection, 'POST', `/v1/definitions/${target}/${action}`, {
1120
+ body: options.reason ? { reason: options.reason } : undefined,
1121
+ repeat: action === 'yank' ? 'always' : 'unsent',
1122
+ });
935
1123
  environment.stdout.write(`${action === 'yank' ? 'yanked' : 'let go on'} ${(0, server_client_1.printable)(target)} on ${serverName}\n`);
936
1124
  }));
937
1125
  }
@@ -947,9 +1135,14 @@ function registerWorkCommands(remote, context) {
947
1135
  if (!proposal && !RUN_ID.test(target)) {
948
1136
  throw new Error(`${(0, server_client_1.printable)(target)} is not a run id or a proposed version, list them with: hammerkit remote approvals or remote proposals`);
949
1137
  }
950
- const { name: serverName, server, token } = await connect(name);
1138
+ const { name: serverName, connection } = await connect(name);
951
1139
  const path = proposal ? `/v1/proposals/${target}/${action}` : `/v1/approvals/${target}/${action}`;
952
- const { body } = await (0, server_client_1.callServer)(server, token, 'POST', path, options.reason ? { reason: options.reason } : undefined);
1140
+ // a decision taken twice is refused the second time (409): sent again only when the
1141
+ // server did not take it
1142
+ const { body } = await (0, server_client_1.callServer)(connection, 'POST', path, {
1143
+ body: options.reason ? { reason: options.reason } : undefined,
1144
+ repeat: 'unsent',
1145
+ });
953
1146
  const rejected = body.state === 'rejected';
954
1147
  environment.stdout.write(proposal
955
1148
  ? rejected