hammerkit 2.1.0-next.2 → 2.1.0-next.21

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 (87) hide show
  1. package/build.schema.json +39 -18
  2. package/dist/cli.js +5 -0
  3. package/dist/dashboard/assets/graph-canvas-D6GMgkoe.js +8 -0
  4. package/dist/dashboard/assets/index-BNq9j5Jo.js +23 -0
  5. package/dist/dashboard/assets/index-DP3_hKOe.css +2 -0
  6. package/dist/dashboard/index.html +2 -2
  7. package/dist/environment/replace-env-variables.js +8 -5
  8. package/dist/environment/run-source-envs.js +2 -1
  9. package/dist/executer/archive-task-entry.js +1 -1
  10. package/dist/executer/deadline.js +63 -10
  11. package/dist/executer/event-cache.js +5 -1
  12. package/dist/executer/execute-work-task.js +15 -3
  13. package/dist/executer/runner-commands.js +36 -0
  14. package/dist/file/get-file-context.js +4 -7
  15. package/dist/harness/connect.js +12 -8
  16. package/dist/harness/reconnect.js +141 -0
  17. package/dist/harness/sandbox-client.js +241 -33
  18. package/dist/harness/service-tools.js +11 -2
  19. package/dist/kubernetes/cluster-state.js +48 -14
  20. package/dist/kubernetes/ensure-persistent-data.js +15 -4
  21. package/dist/kubernetes/follow-pod-logs.js +8 -5
  22. package/dist/kubernetes/kept-claims.js +26 -5
  23. package/dist/kubernetes/resources.js +5 -1
  24. package/dist/kubernetes/sandbox-runner.js +526 -156
  25. package/dist/kubernetes/store-kubernetes-data.js +18 -3
  26. package/dist/kubernetes/sync-changes.js +463 -0
  27. package/dist/kubernetes/volumes.js +23 -1
  28. package/dist/optimizer/get-work-cache-stats.js +7 -0
  29. package/dist/optimizer/work-task-cache-description.js +3 -2
  30. package/dist/planner/image-build.js +5 -0
  31. package/dist/planner/utils/dependency-outputs.js +7 -6
  32. package/dist/planner/validate.js +41 -0
  33. package/dist/planner/work-item-status.js +12 -2
  34. package/dist/planner/work-runtime-aggregate.js +1 -0
  35. package/dist/planner/work-runtime-docker.js +33 -6
  36. package/dist/planner/work-runtime-kubernetes.js +313 -70
  37. package/dist/planner/work-runtime-local.js +8 -4
  38. package/dist/planner/work-secret.js +33 -11
  39. package/dist/planner/work-service-id.js +30 -6
  40. package/dist/program.js +19 -1
  41. package/dist/remote/annotations.js +37 -5
  42. package/dist/remote/bundle.js +6 -8
  43. package/dist/remote/collect-bundle.js +3 -2
  44. package/dist/remote/device-login.js +4 -1
  45. package/dist/remote/remote-commands.js +16 -7
  46. package/dist/remote/remote-work-commands.js +266 -75
  47. package/dist/remote/server-client.js +38 -40
  48. package/dist/schema/build-file-base-task-schema.js +16 -1
  49. package/dist/schema/build-file-image-build-schema.js +5 -8
  50. package/dist/schema/reference-parser.js +108 -43
  51. package/dist/schema/work-scope-parser.js +8 -0
  52. package/dist/secrets/prefetch-secrets.js +20 -1
  53. package/dist/server/artifacts-api.js +56 -0
  54. package/dist/server/definitions-api.js +62 -8
  55. package/dist/server/executor.js +117 -30
  56. package/dist/server/http.js +4 -1
  57. package/dist/server/keep-artifacts.js +230 -0
  58. package/dist/server/kubernetes-backend.js +186 -59
  59. package/dist/server/kubernetes-sandbox-storage.js +3 -2
  60. package/dist/server/overview.js +73 -9
  61. package/dist/server/paging.js +167 -0
  62. package/dist/server/plan.js +16 -1
  63. package/dist/server/run-access.js +24 -0
  64. package/dist/server/run-artifacts.js +171 -0
  65. package/dist/server/run-logs.js +25 -1
  66. package/dist/server/run-request.js +11 -0
  67. package/dist/server/run-source-environment.js +1 -1
  68. package/dist/server/run-worker.js +267 -33
  69. package/dist/server/runs.js +527 -99
  70. package/dist/server/sandbox-files-api.js +27 -12
  71. package/dist/server/sandbox-files.js +12 -10
  72. package/dist/server/sandbox-follow.js +54 -0
  73. package/dist/server/sandbox-pod.js +1 -1
  74. package/dist/server/sandbox-storage.js +38 -1
  75. package/dist/server/sandbox-sync.js +392 -0
  76. package/dist/server/sandboxes-api.js +116 -19
  77. package/dist/server/sandboxes.js +38 -3
  78. package/dist/server/server-config.js +14 -0
  79. package/dist/server/server.js +169 -38
  80. package/dist/server/task-order.js +56 -0
  81. package/dist/utils/project-path.js +20 -0
  82. package/dist/utils/tar-files.js +52 -0
  83. package/dist/utils/tar.js +37 -1
  84. package/package.json +1 -1
  85. package/dist/dashboard/assets/graph-canvas-DtJSpova.js +0 -8
  86. package/dist/dashboard/assets/index-BndChMep.css +0 -2
  87. package/dist/dashboard/assets/index-DRSwIRXd.js +0 -17
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSecretDigest = exports.resolveSecretValue = exports.parseWorkSecrets = exports.getPortableSecretName = exports.getSecretName = exports.describeSecretSource = void 0;
3
+ exports.getSecretDigest = exports.resolveSecretValue = exports.parseWorkSecrets = exports.getPortableSecretName = exports.getSecretName = exports.getUnreadableSecrets = exports.describeSecretSource = void 0;
4
4
  const crypto_1 = require("crypto");
5
5
  const os_1 = require("os");
6
6
  const fs_1 = require("fs");
@@ -17,9 +17,17 @@ function describeSecretSource(secret) {
17
17
  if (source.type === 'provider') {
18
18
  return `${source.provider}:${source.ref} as ${source.account}`;
19
19
  }
20
+ if (source.type === 'unavailable') {
21
+ return source.from;
22
+ }
20
23
  return source.type === 'env' ? `env:${source.name}` : `file:${source.path}`;
21
24
  }
22
25
  exports.describeSecretSource = describeSecretSource;
26
+ // What a task or service reads that this machine can't, one line each, for `ls` and `validate`
27
+ function getUnreadableSecrets(secrets) {
28
+ return secrets.flatMap((secret) => (secret.source.type === 'unavailable' ? [secret.source.reason] : []));
29
+ }
30
+ exports.getUnreadableSecrets = getUnreadableSecrets;
23
31
  function getSecretName(secret) {
24
32
  return secret.target.type === 'env' ? secret.target.name : secret.target.path;
25
33
  }
@@ -61,28 +69,37 @@ function parseSecretSource(secret, ref, cwd, envs, catalog, taskAccount, owner,
61
69
  return { type: 'file', path: (0, normalize_path_1.normalizePath)(cwd, (0, os_1.homedir)(), (0, template_value_1.templateValue)(ref, envs)) };
62
70
  }
63
71
  const reads = `${owner} reads ${label} from ${secret.from}`;
64
- const provider = (0, secret_catalog_1.declared)(catalog.providers, kind);
65
- if (!provider) {
66
- throw new Error(unknownProviderMessage(catalog, reads, kind));
67
- }
72
+ // what the build file gets wrong fails it as a whole; what this machine does not declare
73
+ // fails only a run that reads the secret
68
74
  const providerRef = (0, template_value_1.templateValue)(ref, envs);
69
75
  if (providerRef.length === 0 || providerRef.startsWith('-')) {
70
76
  throw new Error(`${reads}: a reference for ${kind} must not be empty or start with -`);
71
77
  }
78
+ const unavailable = (reason, error) => ({
79
+ type: 'unavailable',
80
+ from: secret.from,
81
+ reason: `${label} from ${secret.from}: ${reason}`,
82
+ error,
83
+ });
84
+ const server = !!catalog.explicitAccounts;
85
+ const provider = (0, secret_catalog_1.declared)(catalog.providers, kind);
86
+ if (!provider) {
87
+ return unavailable(server ? `this server has no secret provider ${kind}` : `no secret provider ${kind} is declared`, unknownProviderMessage(catalog, reads, kind));
88
+ }
72
89
  const accountName = catalog.explicitAccounts
73
90
  ? secret.account
74
91
  : secret.account ?? taskAccount ?? Object.values(catalog.accounts).find((a) => a.default)?.name;
75
92
  if (!accountName) {
76
- throw new Error(missingAccountMessage(catalog, reads, owner));
93
+ return unavailable(server ? 'it names no account' : 'no account is named and none is the default', missingAccountMessage(catalog, reads, owner));
77
94
  }
78
95
  const account = (0, secret_catalog_1.declared)(catalog.accounts, accountName);
79
96
  if (!account) {
80
97
  const namedBy = secret.account ? 'the account: of the secret' : `the account: of ${owner}`;
81
- throw new Error(unknownAccountMessage(catalog, reads, owner, accountName, namedBy, kind));
98
+ return unavailable(server ? `this server has no account ${accountName}` : `no account ${accountName} is declared`, unknownAccountMessage(catalog, reads, owner, accountName, namedBy, kind));
82
99
  }
83
100
  const credentials = (0, secret_catalog_1.declared)(account.providers, kind);
84
101
  if (!credentials) {
85
- throw new Error(missingCredentialsMessage(catalog, reads, account, kind));
102
+ return unavailable(`account ${accountName} has no credentials for ${kind}`, missingCredentialsMessage(catalog, reads, account, kind));
86
103
  }
87
104
  return {
88
105
  type: 'provider',
@@ -110,10 +127,9 @@ function listDeclared(definitions, server) {
110
127
  }
111
128
  return [...byFile.entries()].map(([file, names]) => `${names.join(', ')} in ${file}`).join(' and ');
112
129
  }
113
- // A build file is checked as a whole when it is read, so one wrong secret stops
114
- // the tasks that don't read it, too.
130
+ // Only a run that reads the secret fails: the other tasks of the build file run.
115
131
  function seeDocs(anchor) {
116
- return `Every task of the build file is checked when it is read, so this stops other tasks too. See ${SECRET_PROVIDERS_DOCS}#${anchor}`;
132
+ return `See ${SECRET_PROVIDERS_DOCS}#${anchor}`;
117
133
  }
118
134
  function hostConfigOf(catalog) {
119
135
  return catalog.hostConfig ?? 'the host config';
@@ -213,6 +229,9 @@ function missingCredentialsMessage(catalog, reads, account, provider) {
213
229
  ].join('\n');
214
230
  }
215
231
  function readSecretValueSync(secret, environment) {
232
+ if (secret.source.type === 'unavailable') {
233
+ throw new Error(secret.source.error);
234
+ }
216
235
  if (secret.source.type === 'env') {
217
236
  const value = environment.processEnvs[secret.source.name];
218
237
  if (value === undefined || value === null) {
@@ -239,6 +258,9 @@ function readSecretValueSync(secret, environment) {
239
258
  // The value, read when the task or service starts (or when a cache-affecting
240
259
  // secret is hashed); a missing source fails naming the secret.
241
260
  async function resolveSecretValue(secret, environment) {
261
+ if (secret.source.type === 'unavailable') {
262
+ throw new Error(secret.source.error);
263
+ }
242
264
  if (secret.source.type === 'env') {
243
265
  const value = environment.processEnvs[secret.source.name];
244
266
  if (value === undefined || value === null) {
@@ -1,15 +1,41 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getWorkServiceId = void 0;
3
+ exports.getLegacyServiceItem = exports.getUnnamedWorkServiceId = exports.getWorkServiceId = void 0;
4
4
  const crypto_1 = require("crypto");
5
5
  const work_service_1 = require("./work-service");
6
6
  const portable_path_1 = require("./utils/portable-path");
7
7
  const plan_work_volume_1 = require("./utils/plan-work-volume");
8
+ // The id of a service: its name in the work tree and what it runs from. Two services of
9
+ // one build file may run the same image from the same directory and differ only in their
10
+ // command, envs or network (an app's api and its worker); the name gives each its own
11
+ // container, Deployment, claim and NetworkPolicy. What the service runs is left out, so
12
+ // a service whose command changed is found again and recreated (getServiceDefinitionHash).
13
+ function getWorkServiceId(service) {
14
+ return hashServiceId({ name: service.name, ...getServiceShape(service) });
15
+ }
16
+ exports.getWorkServiceId = getWorkServiceId;
17
+ // The id without the name, which is all the id was up to 2.0. A task that needs the service
18
+ // caches by it (getWorkServiceCacheIdentity): to the task, a renamed service is the same.
19
+ // A container or Deployment an earlier version started carries it (getLegacyServiceItem).
20
+ function getUnnamedWorkServiceId(service) {
21
+ return hashServiceId(getServiceShape(service));
22
+ }
23
+ exports.getUnnamedWorkServiceId = getUnnamedWorkServiceId;
24
+ // The service under the id an earlier version labeled what it started with. A container or
25
+ // Deployment of it goes once, and the service starts anew under its own id, instead of
26
+ // beside the old one on the same host ports, where neither `up` nor `down` would find it.
27
+ function getLegacyServiceItem(item) {
28
+ return { ...item, id: () => getUnnamedWorkServiceId(item.data) };
29
+ }
30
+ exports.getLegacyServiceItem = getLegacyServiceItem;
31
+ function hashServiceId(shape) {
32
+ return (0, crypto_1.createHash)('sha1').update(JSON.stringify(shape)).digest('hex');
33
+ }
8
34
  // Paths are made project-relative (portablePath) so a service id is identical
9
35
  // wherever the project is checked out, like a task id.
10
- function getWorkServiceId(service) {
36
+ function getServiceShape(service) {
11
37
  const portable = (path) => (0, portable_path_1.portablePath)(service.projectRoot, path);
12
- const jsonData = JSON.stringify((0, work_service_1.isContainerWorkService)(service)
38
+ return (0, work_service_1.isContainerWorkService)(service)
13
39
  ? {
14
40
  cwd: portable(service.cwd),
15
41
  image: service.image,
@@ -31,8 +57,6 @@ function getWorkServiceId(service) {
31
57
  context: service.context,
32
58
  selector: service.selector,
33
59
  kubeconfig: portable(service.kubeconfig),
34
- });
35
- return (0, crypto_1.createHash)('sha1').update(jsonData).digest('hex');
60
+ };
36
61
  }
37
- exports.getWorkServiceId = getWorkServiceId;
38
62
  //# sourceMappingURL=work-service-id.js.map
package/dist/program.js CHANGED
@@ -31,6 +31,7 @@ const run_worker_command_1 = require("./server/run-worker-command");
31
31
  const github_app_token_command_1 = require("./secrets/github-app-token-command");
32
32
  const work_network_1 = require("./planner/work-network");
33
33
  const task_arguments_1 = require("./planner/utils/task-arguments");
34
+ const work_secret_1 = require("./planner/work-secret");
34
35
  async function createCli(fileName, environment, workScope) {
35
36
  const { ctx, scope } = await (0, schema_parser_1.createParseContext)(fileName, environment);
36
37
  const referencedScope = await (0, reference_parser_1.parseReferences)(ctx, scope, environment);
@@ -83,9 +84,22 @@ function printTaskDefinition(environment, definition) {
83
84
  (0, log_1.printProperty)(environment, `env ${reference.name}`, `from $${reference.from} ${colors_1.default.grey(reference.available ? '(set)' : '(not set)')}`);
84
85
  }
85
86
  }
87
+ // A task or service that reads a secret this machine can't read is listed, saying so: only
88
+ // running it fails
89
+ function printUnreadableSecrets(environment, item) {
90
+ for (const reason of (0, work_secret_1.getUnreadableSecrets)('secrets' in item ? item.secrets : [])) {
91
+ (0, log_1.printProperty)(environment, "can't run here", reason);
92
+ }
93
+ }
94
+ // only when there are, so the list of a build file without them stays as it was
95
+ function unreadableJson(item) {
96
+ const unreadable = (0, work_secret_1.getUnreadableSecrets)('secrets' in item ? item.secrets : []);
97
+ return unreadable.length > 0 ? { unreadableSecrets: unreadable } : {};
98
+ }
86
99
  // `ls --json`: what a caller (an agent picking a task) needs to know, with the
87
100
  // command that arguments after `--` are appended to (null: it takes none) and
88
- // `args` as the build file says it (false: it refuses them).
101
+ // `args` as the build file says it (false: it refuses them), and the secrets this
102
+ // machine can't read, which make running it fail (`unreadableSecrets`, when there are).
89
103
  function getListJson(tasks, services) {
90
104
  return {
91
105
  tasks: tasks.map(({ item }) => ({
@@ -98,6 +112,7 @@ function getListJson(tasks, services) {
98
112
  labels: item.data.labels,
99
113
  command: (0, task_arguments_1.getArgumentsTarget)(item.data)?.cmd ?? null,
100
114
  args: item.data.args,
115
+ ...unreadableJson(item.data),
101
116
  })),
102
117
  services: services.map(({ item }) => ({
103
118
  name: item.name,
@@ -108,6 +123,7 @@ function getListJson(tasks, services) {
108
123
  labels: item.data.labels,
109
124
  command: (0, task_arguments_1.getArgumentsTarget)(item.data)?.cmd ?? null,
110
125
  args: item.data.type === 'container-service' ? item.data.args : null,
126
+ ...unreadableJson(item.data),
111
127
  })),
112
128
  };
113
129
  }
@@ -204,6 +220,7 @@ async function getProgram(environment, argv) {
204
220
  (0, log_1.printTitle)(environment, 'Services');
205
221
  for (const service of services) {
206
222
  (0, log_1.printItem)(environment, service.item.data);
223
+ printUnreadableSecrets(environment, service.item.data);
207
224
  (0, log_1.printProperty)(environment, 'ports', service.item.data.ports.map((p) => `127.0.0.1:${p.hostPort} -> ${p.containerPort}`).join(', '));
208
225
  if (service.item.data.type === 'kubernetes-service') {
209
226
  (0, log_1.printProperty)(environment, 'context', service.item.data.context);
@@ -221,6 +238,7 @@ async function getProgram(environment, argv) {
221
238
  (0, log_1.printTitle)(environment, 'Tasks');
222
239
  for (const task of tasks) {
223
240
  (0, log_1.printItem)(environment, task.item.data);
241
+ printUnreadableSecrets(environment, task.item.data);
224
242
  if (task.item.needs.length > 0) {
225
243
  (0, log_1.printProperty)(environment, 'needs', task.item.needs.map((d) => d.name).join(', '));
226
244
  }
@@ -36,24 +36,52 @@ function remoteRepo(url) {
36
36
  }
37
37
  }
38
38
  exports.remoteRepo = remoteRepo;
39
+ // what the server takes for a commit, not for the name of a branch or tag
40
+ const COMMIT_NAME = /^[0-9a-f]{40}([0-9a-f]{24})?$/i;
41
+ const ORIGIN_BRANCHES = 'refs/remotes/origin/';
42
+ const TAGS = 'refs/tags/';
39
43
  // The checkout a directory is in: the repository of its `origin`, the branch it is on and
40
- // its commit, what can be found of them.
44
+ // its commit, what can be found of them. A detached HEAD is on no branch: `heads` are then the
45
+ // branches of origin (as the last fetch or push left them) and the tags whose head is its
46
+ // commit, branches first, as git sorts them.
41
47
  async function readCheckout(cwd) {
42
48
  if ((await git(cwd, 'rev-parse', '--is-inside-work-tree')) !== 'true') {
43
49
  return {};
44
50
  }
45
51
  const remote = await git(cwd, 'remote', 'get-url', 'origin');
46
- // a detached HEAD is on no branch
52
+ const repo = remote ? remoteRepo(remote) : undefined;
47
53
  const branch = await git(cwd, 'symbolic-ref', '--quiet', '--short', 'HEAD');
48
- return { repo: remote ? remoteRepo(remote) : undefined, branch, commit: await git(cwd, 'rev-parse', 'HEAD') };
54
+ const commit = await git(cwd, 'rev-parse', 'HEAD');
55
+ if (branch || !commit) {
56
+ return { repo, branch, commit };
57
+ }
58
+ const refs = await git(cwd, 'for-each-ref', `--points-at=${commit}`, '--format=%(refname)%09%(symref)', ORIGIN_BRANCHES, TAGS);
59
+ const heads = [];
60
+ for (const line of refs?.split('\n') ?? []) {
61
+ const [ref, symref] = line.split('\t');
62
+ // origin/HEAD names the default branch of origin, it is no branch of its own
63
+ if (symref || ref === `${ORIGIN_BRANCHES}HEAD`) {
64
+ continue;
65
+ }
66
+ const head = ref.startsWith(ORIGIN_BRANCHES)
67
+ ? { name: ref.slice(ORIGIN_BRANCHES.length), kind: 'branch' }
68
+ : { name: ref.slice(TAGS.length), kind: 'tag' };
69
+ // a name that looks like a commit would be run as that commit
70
+ if (head.name && !COMMIT_NAME.test(head.name)) {
71
+ heads.push(head);
72
+ }
73
+ }
74
+ return { repo, commit, heads };
49
75
  }
50
76
  exports.readCheckout = readCheckout;
51
77
  // Where a build file is published from: its path in its repository (or on this
52
- // machine, outside of one), the repository and commit, this machine and its user.
78
+ // machine, outside of one), the repository, branch and commit, this machine and its user.
79
+ // The branch is the one checked out; on a detached HEAD, a pull request's job of GitHub
80
+ // Actions names it in `GITHUB_HEAD_REF`.
53
81
  // `files` are the paths of the bundle, relative to the build file's directory: when
54
82
  // one of them differs from the commit, `dirty=true` says the version is not that
55
83
  // commit's. What can not be found is left out.
56
- async function collectAnnotations(fileName, files = [(0, path_1.basename)(fileName)]) {
84
+ async function collectAnnotations(fileName, files = [(0, path_1.basename)(fileName)], env = process.env) {
57
85
  const path = (0, path_1.resolve)(fileName);
58
86
  const cwd = (0, path_1.dirname)(path);
59
87
  const annotations = {};
@@ -69,6 +97,10 @@ async function collectAnnotations(fileName, files = [(0, path_1.basename)(fileNa
69
97
  if (repo) {
70
98
  annotations.repo = repo;
71
99
  }
100
+ const branch = (await git(cwd, 'symbolic-ref', '--quiet', '--short', 'HEAD')) ?? env.GITHUB_HEAD_REF;
101
+ if (branch) {
102
+ annotations.branch = branch.slice(0, 500);
103
+ }
72
104
  if (commit) {
73
105
  annotations.commit = commit;
74
106
  const changed = await git(cwd, '--literal-pathspecs', 'status', '--porcelain', '--untracked-files=all', '--', ...files);
@@ -1,26 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HASH_PATTERN = exports.hashBundle = exports.bundleSchema = exports.annotationsSchema = exports.MAX_ANNOTATIONS = exports.isBundlePath = exports.MAX_BUNDLE_BYTES = exports.MAX_BUNDLE_FILES = exports.DEFAULT_ENTRY = void 0;
3
+ exports.HASH_PATTERN = exports.hashBundle = exports.bundleSchema = exports.annotationsSchema = exports.ANNOTATION_KEY_PATTERN = exports.MAX_ANNOTATIONS = exports.isBundlePath = exports.MAX_BUNDLE_BYTES = exports.MAX_BUNDLE_FILES = exports.DEFAULT_ENTRY = void 0;
4
4
  const crypto_1 = require("crypto");
5
5
  const zod_1 = require("zod");
6
+ const project_path_1 = require("../utils/project-path");
6
7
  exports.DEFAULT_ENTRY = '.hammerkit.yaml';
7
8
  exports.MAX_BUNDLE_FILES = 200;
8
9
  exports.MAX_BUNDLE_BYTES = 1024 * 1024;
9
10
  // A path inside the bundle: relative, forward slashes, nothing that climbs out.
10
11
  function isBundlePath(path) {
11
- return (path.length > 0 &&
12
- path.length <= 200 &&
13
- !path.startsWith('/') &&
14
- !path.includes('\\') &&
15
- !path.includes('\0') &&
16
- !path.split('/').some((part) => part === '' || part === '.' || part === '..'));
12
+ return (0, project_path_1.isRelativePath)(path, 200);
17
13
  }
18
14
  exports.isBundlePath = isBundlePath;
19
15
  exports.MAX_ANNOTATIONS = 20;
16
+ // the key of an annotation
17
+ exports.ANNOTATION_KEY_PATTERN = /^[a-z][a-z0-9._-]{0,63}$/;
20
18
  exports.annotationsSchema = zod_1.z
21
19
  .record(zod_1.z
22
20
  .string()
23
- .regex(/^[a-z][a-z0-9._-]{0,63}$/, 'use lower case letters, digits, ".", "_" and "-", starting with a letter'), zod_1.z.string().min(1).max(500))
21
+ .regex(exports.ANNOTATION_KEY_PATTERN, 'use lower case letters, digits, ".", "_" and "-", starting with a letter'), zod_1.z.string().min(1).max(500))
24
22
  .refine((annotations) => Object.keys(annotations).length <= exports.MAX_ANNOTATIONS, {
25
23
  message: `at most ${exports.MAX_ANNOTATIONS} annotations`,
26
24
  });
@@ -15,9 +15,10 @@ const bundle_1 = require("./bundle");
15
15
  // where a file really is too: a link to a file outside of the directory is refused
16
16
  // rather than followed, so publishing a checkout never sends a file of this machine
17
17
  // that the checkout only points to.
18
- async function collectBundle(fileName, environment) {
18
+ // `missing` is what to do when there is no build file, said after that.
19
+ async function collectBundle(fileName, environment, options = {}) {
19
20
  if (!(await environment.file.exists(fileName))) {
20
- throw new Error(`there is no build file at ${fileName}`);
21
+ throw new Error(`there is no build file at ${fileName}${options.missing ? `. ${options.missing}` : ''}`);
21
22
  }
22
23
  const entryPath = (0, path_1.resolve)(fileName);
23
24
  const root = (0, path_1.dirname)(entryPath);
@@ -87,7 +87,10 @@ function abortable(sleep, signal) {
87
87
  async function deviceLogin(server, options) {
88
88
  const sleep = abortable(options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms))), options.signal);
89
89
  const now = options.now ?? Date.now;
90
- const discovery = await (0, server_client_1.getDiscovery)(server);
90
+ if (options.signal?.aborted) {
91
+ throw new server_client_1.ServerError('login was cancelled');
92
+ }
93
+ const discovery = await (0, server_client_1.getDiscovery)(server, { say: options.say, signal: options.signal });
91
94
  const offered = discovery.issuers.find((i) => i.issuer === server.issuer);
92
95
  if (!offered) {
93
96
  const accepted = discovery.issuers.map((i) => (0, server_client_1.printable)(i.issuer)).join(', ');
@@ -10,7 +10,7 @@ const log_1 = require("../log");
10
10
  const host_config_1 = require("./host-config");
11
11
  const device_login_1 = require("./device-login");
12
12
  const credentials_1 = require("./credentials");
13
- const token_source_1 = require("./token-source");
13
+ const sandbox_client_1 = require("../harness/sandbox-client");
14
14
  const server_client_1 = require("./server-client");
15
15
  const remote_work_commands_1 = require("./remote-work-commands");
16
16
  const mcp_command_1 = require("../harness/mcp-command");
@@ -114,6 +114,7 @@ passthrough = []) {
114
114
  try {
115
115
  login = await (0, device_login_1.deviceLogin)(server, {
116
116
  prompt: (message) => environment.stdout.write(`${message}\n`),
117
+ say: (line) => environment.stderr.write(`${line}\n`),
117
118
  signal: environment.abortCtrl.signal,
118
119
  });
119
120
  }
@@ -128,15 +129,23 @@ passthrough = []) {
128
129
  await (0, host_config_1.pinLogin)(environment, name, pinned);
129
130
  await (0, credentials_1.saveToken)(environment, name, { url: server.url, issuer: server.issuer, ...result });
130
131
  try {
131
- const me = await (0, server_client_1.getMe)(server, result.accessToken);
132
+ const me = await (0, server_client_1.getMe)({
133
+ url: server.url,
134
+ token: async () => result.accessToken,
135
+ say: (line) => environment.stderr.write(`${line}\n`),
136
+ signal: environment.abortCtrl.signal,
137
+ });
132
138
  environment.stdout.write(`signed in to ${name} as ${me.sub}\n`);
133
139
  environment.stdout.write(me.accounts.length > 0
134
140
  ? `service accounts: ${me.accounts.map((a) => `${(0, server_client_1.printable)(a.name)} (${a.level})`).join(', ')}\n`
135
141
  : 'you have no service accounts on this server\n');
136
142
  }
137
143
  catch (e) {
138
- // a token the server does not accept is of no use
139
- await (0, credentials_1.removeToken)(environment, name);
144
+ // a token the server does not accept is of no use; one that could not be checked, because the
145
+ // server was away or the wait was stopped, is kept, and the next command checks it again
146
+ if (e instanceof server_client_1.ServerError && e.status === 401) {
147
+ await (0, credentials_1.removeToken)(environment, name);
148
+ }
140
149
  throw e;
141
150
  }
142
151
  }));
@@ -154,9 +163,9 @@ passthrough = []) {
154
163
  .description('show who you are on a server and which service accounts you may use')
155
164
  .action(guarded('Remote accounts was not successful', async (name) => {
156
165
  const chosen = await getServer(name);
157
- const token = await (0, token_source_1.getTokenSource)(environment, chosen.name, chosen.server).token();
158
- const me = await (0, server_client_1.getMe)(chosen.server, token);
159
- const { body } = await (0, server_client_1.callServer)(chosen.server, token, 'GET', '/v1/accounts');
166
+ const connection = (0, sandbox_client_1.getServerConnection)(environment, chosen.name, chosen.server);
167
+ const me = await (0, server_client_1.getMe)(connection);
168
+ const { body } = await (0, server_client_1.callServer)(connection, 'GET', '/v1/accounts');
160
169
  environment.stdout.write(`${chosen.name}: ${(0, server_client_1.printable)(me.sub)} (${(0, server_client_1.printable)(me.iss)})\n`);
161
170
  if (body.accounts.length === 0) {
162
171
  environment.stdout.write('no service accounts\n');