@sublang/spex 5.0.0 → 7.0.0-beta.2

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 (114) hide show
  1. package/README.md +453 -41
  2. package/dist/cli.js +12 -1
  3. package/dist/commands/add.d.ts +1 -1
  4. package/dist/commands/add.js +3 -3
  5. package/dist/commands/auth-target.d.ts +1 -0
  6. package/dist/commands/auth-target.js +4 -2
  7. package/dist/commands/environment.d.ts +15 -21
  8. package/dist/commands/environment.js +43 -57
  9. package/dist/commands/export.js +2 -2
  10. package/dist/commands/home.d.ts +2 -2
  11. package/dist/commands/home.js +3 -3
  12. package/dist/commands/list.js +1 -1
  13. package/dist/commands/login.js +12 -7
  14. package/dist/commands/logout.js +2 -3
  15. package/dist/commands/publish.js +16 -16
  16. package/dist/commands/remove.js +1 -1
  17. package/dist/commands/run.d.ts +1 -1
  18. package/dist/commands/run.js +22 -3
  19. package/dist/commands/search.js +1 -1
  20. package/dist/commands/settle.d.ts +1 -1
  21. package/dist/commands/settle.js +3 -3
  22. package/dist/commands/whoami.js +2 -6
  23. package/dist/guards/approval.d.ts +56 -0
  24. package/dist/guards/approval.js +158 -0
  25. package/dist/guards/checks.d.ts +207 -0
  26. package/dist/guards/checks.js +681 -0
  27. package/dist/guards/commands.d.ts +15 -0
  28. package/dist/guards/commands.js +313 -0
  29. package/dist/guards/copy.d.ts +67 -0
  30. package/dist/guards/copy.js +306 -0
  31. package/dist/guards/declaration.d.ts +45 -0
  32. package/dist/guards/declaration.js +224 -0
  33. package/dist/guards/files.d.ts +137 -0
  34. package/dist/guards/files.js +544 -0
  35. package/dist/guards/harness.d.ts +58 -0
  36. package/dist/guards/harness.js +420 -0
  37. package/dist/guards/items.d.ts +61 -0
  38. package/dist/guards/items.js +161 -0
  39. package/dist/guards/patch.d.ts +55 -0
  40. package/dist/guards/patch.js +258 -0
  41. package/dist/guards/processes.d.ts +49 -0
  42. package/dist/guards/processes.js +233 -0
  43. package/dist/guards/proofs.d.ts +88 -0
  44. package/dist/guards/proofs.js +503 -0
  45. package/dist/guards/records.d.ts +176 -0
  46. package/dist/guards/records.js +513 -0
  47. package/dist/guards/report.d.ts +26 -0
  48. package/dist/guards/report.js +492 -0
  49. package/dist/guards/runner.d.ts +42 -0
  50. package/dist/guards/runner.js +167 -0
  51. package/dist/guards/tla.d.ts +51 -0
  52. package/dist/guards/tla.js +352 -0
  53. package/dist/guards/tlapm.d.ts +81 -0
  54. package/dist/guards/tlapm.js +172 -0
  55. package/dist/guards/tlc.d.ts +191 -0
  56. package/dist/guards/tlc.js +457 -0
  57. package/dist/guards/translation.d.ts +66 -0
  58. package/dist/guards/translation.js +202 -0
  59. package/dist/guards/types.d.ts +185 -0
  60. package/dist/guards/types.js +437 -0
  61. package/dist/guards/verify.d.ts +290 -0
  62. package/dist/guards/verify.js +1191 -0
  63. package/dist/guards/xml.d.ts +18 -0
  64. package/dist/guards/xml.js +105 -0
  65. package/dist/lib/environment/archive.d.ts +16 -3
  66. package/dist/lib/environment/archive.js +39 -8
  67. package/dist/lib/environment/builtins.d.ts +10 -12
  68. package/dist/lib/environment/builtins.js +18 -20
  69. package/dist/lib/environment/exports.d.ts +14 -13
  70. package/dist/lib/environment/exports.js +31 -16
  71. package/dist/lib/environment/format.d.ts +2 -2
  72. package/dist/lib/environment/format.js +3 -3
  73. package/dist/lib/environment/git-source.js +6 -3
  74. package/dist/lib/environment/install.d.ts +14 -16
  75. package/dist/lib/environment/install.js +66 -61
  76. package/dist/lib/environment/lock.d.ts +4 -3
  77. package/dist/lib/environment/lock.js +6 -5
  78. package/dist/lib/environment/marker.js +1 -2
  79. package/dist/lib/environment/own-paths.d.ts +7 -10
  80. package/dist/lib/environment/own-paths.js +10 -13
  81. package/dist/lib/environment/placed-record.d.ts +3 -2
  82. package/dist/lib/environment/placed-record.js +5 -4
  83. package/dist/lib/environment/registries.d.ts +7 -9
  84. package/dist/lib/environment/registries.js +9 -36
  85. package/dist/lib/environment/registry.d.ts +6 -7
  86. package/dist/lib/environment/registry.js +12 -12
  87. package/dist/lib/environment/requests.d.ts +6 -5
  88. package/dist/lib/environment/requests.js +6 -8
  89. package/dist/lib/environment/resolve.d.ts +4 -4
  90. package/dist/lib/environment/resolve.js +3 -4
  91. package/dist/lib/environment/store.d.ts +34 -8
  92. package/dist/lib/environment/store.js +138 -43
  93. package/dist/lib/files.d.ts +72 -12
  94. package/dist/lib/files.js +200 -65
  95. package/dist/lib/git-host.d.ts +52 -258
  96. package/dist/lib/git-host.js +52 -265
  97. package/dist/lib/home-file.d.ts +13 -10
  98. package/dist/lib/home-file.js +28 -18
  99. package/dist/lib/instance.d.ts +1 -1
  100. package/dist/lib/instance.js +1 -1
  101. package/dist/lint.d.ts +22 -0
  102. package/dist/lint.js +36 -0
  103. package/dist/testing/standin-registry.js +1 -1
  104. package/package.json +7 -3
  105. package/scaffold/.file-history.json +14 -7
  106. package/scaffold/i18n/zh/source-pins.json +41 -0
  107. package/scaffold/i18n/zh/specs/decisions/000-spec-structure-format.md +0 -1
  108. package/scaffold/i18n/zh/specs/intents/000-spdx-headers.md +0 -1
  109. package/scaffold/i18n/zh/specs/map.md +0 -1
  110. package/scaffold/i18n/zh/specs/meta.md +18 -35
  111. package/scaffold/i18n/zh/specs/packages/git.md +0 -1
  112. package/scaffold/i18n/zh/specs/packages/licensing.md +0 -1
  113. package/scaffold/specs/meta.md +18 -3
  114. package/scripts/test-exit-guard.mjs +28 -0
@@ -1,46 +1,34 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  // SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
3
- // The Git host client (git-host-1..21, DR-103, DR-114, DR-120): signs a
4
- // person in as a public client — the browser flow with PKCE on the
5
- // desktop, the device flow on the server shell — keeps the app token
6
- // current in `local/credentials.yaml` (storage-19), and reads and writes
7
- // the host's JSON routes under `/api/v1`: groups, spex repositories and
8
- // members, with what the host says the person may do and the roles it
9
- // grants, and the undo writes — a group renamed or deleted, a spex
10
- // repository moved — and the team servers a person may open a seat on
11
- // with the tickets that open one (git-host-29). A rate limit the host
12
- // answers holds a sync step's calls and the host read until the instant
13
- // it asked for, and refuses every other call meanwhile with the seconds
14
- // that remain (git-host-21).
3
+ // Sign-in, credential storage and personal records requests for a Space.
4
+ // Browser sign-in uses PKCE; device sign-in also works without a local
5
+ // browser. The client keeps the grant current under local/credentials.yaml.
6
+ // A rate limit holds opted-in calls until the Space's retry time.
15
7
  // It composes no reader-facing prose: a failure is a `HostError` carrying
16
8
  // its kind and the host's own words, which the core phrases where it
17
- // speaks (git-host-11). No secret ever enters an error message or a log
9
+ // speaks. No secret ever enters an error message or a log
18
10
  // line.
19
11
  import { createHash, randomBytes } from "node:crypto";
20
12
  import { createServer } from "node:http";
21
- import { mkdirSync, readFileSync, rmSync } from "node:fs";
13
+ import { readFileSync, rmSync } from "node:fs";
22
14
  import { join } from "node:path";
23
15
  import { setTimeout as sleep } from "node:timers/promises";
24
16
  import { parse as parseYaml, stringify as stringifyYaml } from "yaml";
25
- import { writeApplicationBytes } from "./files.js";
17
+ import { makePrivateDirectory, writeApplicationBytes } from "./files.js";
26
18
  import { canonicalOrigin } from "./instance.js";
27
19
  import { words } from "./words.js";
28
20
  export { DEFAULT_HOST_URL, hostUrlFor } from "./instance.js";
29
21
  /** The public OAuth client id Spex signs in as. */
30
22
  export const CLIENT_ID = "spex";
31
- /** An access secret this close to expiring is refreshed first (git-host-4). */
23
+ /** An access secret this close to expiring is refreshed first. */
32
24
  export const REFRESH_MARGIN_MS = 60_000;
33
- /** A browser sign-in without a callback ends `expired` after this long
34
- * (git-host-2). */
25
+ /** A browser sign-in without a callback ends `expired` after this long. */
35
26
  export const BROWSER_SIGN_IN_TIMEOUT_MS = 10 * 60_000;
36
- /** The longest a rate limit holds the calls to the host (git-host-21). */
27
+ /** The longest a rate limit holds the calls to the host. */
37
28
  export const RATE_LIMIT_HOLD_MAX_MS = 120_000;
38
29
  const DEFAULT_REQUEST_TIMEOUT_MS = 30_000;
39
30
  const SLOW_DOWN_STEP_MS = 5_000;
40
31
  const LABEL_MAX = 80;
41
- /** The longest a server's id or a person's id may be in a device
42
- * request (git-host-27; the instance's own bound). */
43
- export const SEAT_ID_MAX = 64;
44
32
  const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
45
33
  const MONTH = MONTHS.join("|");
46
34
  /** The three forms of an HTTP date (RFC 9110 §5.6.7), always GMT. */
@@ -71,7 +59,7 @@ function httpDate(text, now) {
71
59
  return null;
72
60
  }
73
61
  /**
74
- * The seconds a host's `Retry-After` asks to wait (git-host-11): its
62
+ * The seconds a host's `Retry-After` asks to wait: its
75
63
  * number where it is all digits, the seconds from `now` until its HTTP
76
64
  * date — none below zero — and null where it is absent or anything else.
77
65
  */
@@ -90,7 +78,7 @@ function trimUrl(url) {
90
78
  return url.replace(/\/+$/, "");
91
79
  }
92
80
  /**
93
- * A host answer other than success (git-host-11). `words` is the host's
81
+ * A host answer other than success. `words` is the host's
94
82
  * own message, kept whole; `retryAfter` the host's `Retry-After` for
95
83
  * `rate_limited`, raw, read as seconds by `retryAfterSeconds`; `code`
96
84
  * the envelope's `error.code` where one came; and,
@@ -116,7 +104,7 @@ export class HostError extends Error {
116
104
  }
117
105
  }
118
106
  /** A call's own Stop ended its wait for the host's rate limit before it
119
- * was sent (git-host-21). Local; not the host's. */
107
+ * was sent. Local; not the host's. */
120
108
  export class HostWaitStopped extends Error {
121
109
  code = "stopped";
122
110
  constructor() {
@@ -128,7 +116,7 @@ export class HostWaitStopped extends Error {
128
116
  class ReadRecoveryExpired extends Error {
129
117
  }
130
118
  /** The pair a step used was no longer the stored one when its answer
131
- * came (git-host-4, git-host-10, storage-19): nothing was stored or
119
+ * came (git-host-31, storage-19): nothing was stored or
132
120
  * removed, and the step may be made again. Local; not the host's. */
133
121
  export class CredentialChanged extends Error {
134
122
  code = "changed";
@@ -137,7 +125,7 @@ export class CredentialChanged extends Error {
137
125
  this.name = "CredentialChanged";
138
126
  }
139
127
  }
140
- /** A sign-in started while another runs (git-host-2: a second start is
128
+ /** A sign-in started while another runs (a second start is
141
129
  * `busy`). */
142
130
  export class SignInBusyError extends Error {
143
131
  code = "busy";
@@ -230,7 +218,7 @@ export function fileCredentialStore(homeDir, hostUrl, scope = "space") {
230
218
  rmSync(file, { force: true });
231
219
  return true;
232
220
  }
233
- mkdirSync(dir, { recursive: true, mode: 0o700 });
221
+ makePrivateDirectory(dir);
234
222
  writeApplicationBytes(file, stringifyYaml({ format: 1, hosts: doc.hosts }));
235
223
  return true;
236
224
  }
@@ -261,16 +249,10 @@ export function fileCredentialStore(homeDir, hostUrl, scope = "space") {
261
249
  };
262
250
  }
263
251
  /** The refusal of a sign-in at a listed instance as another person than
264
- * its entry's account (git-host-2): `words` carries the entry's login. */
252
+ * its entry's account: `words` carries the entry's login. */
265
253
  export function anotherAccountError(login) {
266
254
  return signInError("account", { words: login });
267
255
  }
268
- /** The refusal of a seat's sign-in as a person other than the one its
269
- * device request named (git-host-27): `words` carries the login the
270
- * instance signed in. */
271
- export function anotherPersonError(login) {
272
- return signInError("person", { words: login });
273
- }
274
256
  const DEFAULT_PAGES = {
275
257
  complete: page("Signed in", "Spex is signed in. You may close this browser window."),
276
258
  failed: page("Not signed in", "Spex did not sign in. You may close this browser window and return to Spex."),
@@ -281,7 +263,7 @@ function page(title, text) {
281
263
  const REAUTH_CODES = new Set(["invalid_token", "token_revoked", "reauth_required", "unauthenticated", "token_expired"]);
282
264
  /**
283
265
  * The client of one Git host. Every call to a host route presents the
284
- * stored access secret and keeps the app token current (git-host-4);
266
+ * stored access secret and keeps the app token current;
285
267
  * `describe()` alone needs no token.
286
268
  */
287
269
  export class GitHostClient {
@@ -296,17 +278,14 @@ export class GitHostClient {
296
278
  requestTimeoutMs;
297
279
  onHold;
298
280
  holdMaxMs;
299
- server;
300
281
  refreshing = null;
301
282
  signIn = null;
302
283
  /** The instant the host's last rate limit asked every call to wait
303
- * until (git-host-21); 0 where none holds. */
284
+ * until; 0 where none holds. */
304
285
  holdUntil = 0;
305
286
  constructor(options) {
306
287
  this.url = trimUrl(options.url);
307
288
  this.scope = options.scope ?? "space";
308
- if (this.scope === "registry" && options.server)
309
- throw new HostError("bad_request", { code: "registry_seat_forbidden" });
310
289
  this.clientId = options.clientId ?? CLIENT_ID;
311
290
  const label = options.label.trim();
312
291
  this.label = (label.length > 0 ? label : "Spex").slice(0, LABEL_MAX);
@@ -317,23 +296,19 @@ export class GitHostClient {
317
296
  this.requestTimeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
318
297
  this.onHold = options.onHold;
319
298
  this.holdMaxMs = options.holdMaxMs ?? RATE_LIMIT_HOLD_MAX_MS;
320
- if (options.server)
321
- this.server = { id: options.server.id, personId: options.server.personId };
322
299
  }
323
- /** Whether the host's rate limit holds the calls now (git-host-21). */
300
+ /** Whether the host's rate limit holds the calls now. */
324
301
  holding() {
325
302
  return this.holdUntil > this.now();
326
303
  }
327
304
  /** `GET /api/v1/host`: the host's display name, the Git origin its
328
- * credentials are valid for, and the roles it grants (git-host-5). */
305
+ * credentials are valid for. */
329
306
  async describe(options = {}) {
330
307
  const answer = await this.send("GET", "/api/v1/host", options);
331
308
  if (answer.status !== 200)
332
309
  throw answerError(answer);
333
310
  const body = record(answer.json);
334
- // A host that lists no roles grants none through Spex.
335
- const roles = body.roles === undefined || body.roles === null ? [] : list(body.roles).map(roleFrom);
336
- return { displayName: text(body.display_name), gitOrigin: text(body.git_origin), roles };
311
+ return { displayName: text(body.display_name), gitOrigin: text(body.git_origin) };
337
312
  }
338
313
  /** Whether this device holds an app token for the host. */
339
314
  async signedIn() {
@@ -344,7 +319,7 @@ export class GitHostClient {
344
319
  return this.signIn !== null;
345
320
  }
346
321
  /**
347
- * The browser flow with PKCE (git-host-2): a loopback listener on
322
+ * The browser flow with PKCE: a loopback listener on
348
323
  * `127.0.0.1` at an OS-assigned port for one callback, an S256
349
324
  * challenge, and the host's `/login/app` URL to open.
350
325
  */
@@ -464,23 +439,15 @@ export class GitHostClient {
464
439
  }
465
440
  }
466
441
  /**
467
- * The device flow (git-host-3): the host's user code and verification
442
+ * The device flow (git-host-40): the host's user code and verification
468
443
  * URL, completed with the code where the host gives it, then polling the token endpoint at its interval, five seconds
469
444
  * slower on each `slow_down`, until the token, a denial or the expiry.
470
- * On a seat, `ticket` is the one the member's client presented for it,
471
- * on which the host may grant the code without its page (git-host-27).
472
445
  */
473
446
  async startDeviceSignIn(options = {}) {
474
447
  const { slot, expected } = await this.beginSignIn();
475
448
  let start;
476
449
  try {
477
- // A seat names its server and the person it was opened for, both
478
- // or neither, and the ticket where its start named one; off a seat
479
- // no ticket is sent (git-host-27).
480
- const seat = this.server
481
- ? { server_id: this.server.id, person_id: this.server.personId, ...(options.ticket ? { ticket: options.ticket } : {}) }
482
- : {};
483
- const answer = await this.send("POST", "/api/v1/auth/device", { body: { scope: this.scope, client_id: this.clientId, label: this.label, ...seat } });
450
+ const answer = await this.send("POST", "/api/v1/auth/device", { body: { scope: this.scope, client_id: this.clientId, label: this.label } });
484
451
  if (answer.status !== 200)
485
452
  throw answerError(answer);
486
453
  const body = record(answer.json);
@@ -488,7 +455,7 @@ export class GitHostClient {
488
455
  deviceCode: text(body.device_code),
489
456
  userCode: text(body.user_code),
490
457
  // The URL completed with the code where the host gives one,
491
- // so the person never types it (git-host-3).
458
+ // so the person never types it (git-host-40).
492
459
  verificationUri: optionalText(body.verification_uri_complete) || text(body.verification_uri),
493
460
  expiresIn: positive(body.expires_in, 600),
494
461
  interval: positive(body.interval, 5),
@@ -593,7 +560,7 @@ export class GitHostClient {
593
560
  };
594
561
  }
595
562
  /**
596
- * Sign this device out (git-host-10): revoke it at the host with its
563
+ * Sign this device out (git-host-31): revoke it at the host with its
597
564
  * app token, tried once, and remove that pair either way, calling
598
565
  * `onRemoved` in the same turn as the removal. Where another pair was
599
566
  * stored in its place meanwhile, that pair stays, `onRemoved` is not
@@ -655,12 +622,6 @@ export class GitHostClient {
655
622
  async me(options = {}) {
656
623
  return accountFrom((await this.call("GET", (this.scope === "registry" ? "/api/v1/whoami?scope=registry" : "/api/v1/host/me"), undefined, options)).json);
657
624
  }
658
- /** `GET /api/v1/host/groups`: the person's own group and every group
659
- * they belong to. */
660
- async groups(options = {}) {
661
- const body = record((await this.call("GET", "/api/v1/host/groups", undefined, options)).json);
662
- return list(body.groups).map(groupFrom);
663
- }
664
625
  /** `GET /api/v1/host/repositories`, every page. */
665
626
  async repositories(options = {}) {
666
627
  const all = [];
@@ -686,114 +647,12 @@ export class GitHostClient {
686
647
  const body = record((await this.call("GET", `/api/v1/host/repositories/${encodeURIComponent(id)}`, undefined, options)).json);
687
648
  return detailFrom(body);
688
649
  }
689
- /** `GET /api/v1/host/repositories/:id/members` or
690
- * `GET /api/v1/host/groups/:id/members` (git-host-8): every member with
691
- * the host's role name and source. */
692
- async members(target, options = {}) {
693
- const body = record((await this.call("GET", membersPath(target), undefined, options)).json);
694
- return { members: list(body.members).map(memberFrom) };
695
- }
696
- /**
697
- * `POST /api/v1/host/groups` (git-host-15): a private group named
698
- * `name` at the path `path`, inside the group `parentId` or at the top
699
- * where it is null. A taken name throws `name_taken`, the host's
700
- * refusal `host_refused` with its words.
701
- */
702
- async createGroup(input) {
703
- const body = record((await this.call("POST", "/api/v1/host/groups", { name: input.name, path: input.path, parent_id: input.parentId })).json);
704
- return groupFrom(body.group);
705
- }
706
- /**
707
- * `PATCH /api/v1/host/groups/:id` (git-host-18): give a group of the
708
- * instance the name, the path segment, or both, given. A path taken
709
- * there throws `name_taken`, the host's refusal `host_refused` with
710
- * its words.
711
- */
712
- async renameGroup(id, input) {
713
- const fields = {};
714
- if (input.name !== undefined)
715
- fields.name = input.name;
716
- if (input.path !== undefined)
717
- fields.path = input.path;
718
- const body = record((await this.call("PATCH", `/api/v1/host/groups/${encodeURIComponent(id)}`, fields)).json);
719
- return groupFrom(body.group);
720
- }
721
- /** Request normal deletion through the confirmation-aware route
722
- * (git-host-19). Older deployments are refused, never retried through
723
- * the legacy route, whose behavior may permanently delete a group. */
724
- async deleteGroup(id, confirmPath) {
725
- if (confirmPath === undefined || confirmPath.trim().length === 0)
726
- throw new HostError("bad_request", { code: "confirmation_required", words: "Confirm the group's path before deleting it." });
727
- const body = record((await this.call("POST", `/api/v1/host/groups/${encodeURIComponent(id)}/deletion`, { confirm_path: confirmPath })).json);
728
- if (body.status === "deleted")
729
- return { status: "deleted" };
730
- if (body.status === "scheduled") {
731
- const group = groupFrom(body.group);
732
- if (group.id === id && group.pendingDeletion && group.deletionRoot)
733
- return { status: "scheduled", group };
734
- }
735
- throw new HostError("unreachable", { code: "malformed_answer" });
736
- }
737
- /** Read the Space's current contents, including contents omitted from
738
- * the records listing. Members are not contents. */
739
- async inspectGroupDeletion(id) {
740
- const body = record((await this.call("GET", `/api/v1/host/groups/${encodeURIComponent(id)}/deletion`)).json);
741
- const group = groupFrom(body.group);
742
- if (group.id !== id || !Array.isArray(body.contents))
743
- throw new HostError("unreachable", { code: "malformed_answer" });
744
- const contents = body.contents.map((value) => {
745
- const item = record(value);
746
- if (!["project", "group", "records", "server"].includes(String(item.kind)) || typeof item.name !== "string" || item.name.length === 0)
747
- throw new HostError("unreachable", { code: "malformed_answer" });
748
- return { kind: item.kind, name: item.name };
749
- });
750
- return { group, contents };
751
- }
752
- /** Restore the group's normal scheduled deletion, where the Space
753
- * permits it; no retention period is inferred by the client. */
754
- async restoreGroup(id) {
755
- const body = record((await this.call("POST", `/api/v1/host/groups/${encodeURIComponent(id)}/restore`, {})).json);
756
- const group = groupFrom(body.group);
757
- if (group.id !== id || group.pendingDeletion)
758
- throw new HostError("unreachable", { code: "malformed_answer" });
759
- return group;
760
- }
761
- /**
762
- * `POST /api/v1/host/repositories/:id/transfer` (git-host-20): move a
763
- * spex repository into the group `groupId`, or the person's own group
764
- * where it is null. A name taken there throws `name_taken`, the host's
765
- * refusal `host_refused` with its words.
766
- */
767
- async transferRepository(id, groupId) {
768
- const body = record((await this.call("POST", `/api/v1/host/repositories/${encodeURIComponent(id)}/transfer`, { group_id: groupId })).json);
769
- return repositoryFrom(body.repository);
770
- }
771
- /**
772
- * `POST …/members` (git-host-16): add the account the host lists under
773
- * exactly `login` to the group or repository at the role whose id is
774
- * `role`. No such account throws `not_found` with the host's words
775
- * naming the login; a refusal `host_refused` with its words.
776
- */
777
- async addMember(target, input) {
778
- const body = record((await this.call("POST", membersPath(target), { login: input.login, role: input.role })).json);
779
- return memberFrom(body.member);
780
- }
781
- /**
782
- * `DELETE …/members/:login` (git-host-17): remove the account under
783
- * `login` from the group's or repository's own members. No account, or
784
- * no membership of its own there, throws `not_found` with the host's
785
- * words; a refusal `host_refused` with its words.
786
- */
787
- async removeMember(target, login) {
788
- await this.call("DELETE", `${membersPath(target)}/${encodeURIComponent(login)}`);
789
- }
790
650
  /**
791
- * `POST /api/v1/host/repositories` (git-host-6): `name` is the whole
792
- * repository name, `<name>-spex`; `groupId` null means the person's own
793
- * group. A taken name throws `name_taken`.
651
+ * `POST /api/v1/host/repositories`: `name` is the whole
652
+ * repository name, `<name>-spex`; creation uses the authenticated account’s namespace. A taken name throws `name_taken`.
794
653
  */
795
654
  async create(input) {
796
- const answer = await this.call("POST", "/api/v1/host/repositories", { group_id: input.groupId, name: input.name, description: input.description });
655
+ const answer = await this.call("POST", "/api/v1/host/repositories", { group_id: null, name: input.name, description: input.description });
797
656
  const body = record(answer.json);
798
657
  if (answer.status === 202)
799
658
  return { status: "pending", message: pendingWords(body) };
@@ -801,7 +660,7 @@ export class GitHostClient {
801
660
  throw new HostError("unreachable", { code: "malformed_answer", status: answer.status });
802
661
  return { status: "created", repository: repositoryFrom(body.repository) };
803
662
  }
804
- /** `POST /api/v1/host/repositories/:id/spex-branch` (git-host-7). */
663
+ /** `POST /api/v1/host/repositories/:id/spex-branch`. */
805
664
  async prepareBranch(id, options = {}) {
806
665
  const answer = await this.call("POST", `/api/v1/host/repositories/${encodeURIComponent(id)}/spex-branch`, {}, options);
807
666
  const body = record(answer.json);
@@ -811,32 +670,7 @@ export class GitHostClient {
811
670
  throw new HostError("unreachable", { code: "malformed_answer", status: answer.status });
812
671
  return { status: "ready" };
813
672
  }
814
- /**
815
- * `GET /api/v1/host/servers` (git-host-29): the servers the person may
816
- * open a seat on, as the instance answers them, in its order. The
817
- * client keeps nothing of the answer.
818
- */
819
- async servers(options = {}) {
820
- const body = record((await this.call("GET", "/api/v1/host/servers", undefined, options)).json);
821
- return list(body.servers).map(serverFrom);
822
- }
823
- /**
824
- * `POST /api/v1/host/servers/:id/tickets` (git-host-29): a ticket for a
825
- * seat on the server `id`, as the instance answers it; the client keeps
826
- * nothing of it. A server the instance does not list for the person
827
- * throws `not_found`, a membership below the role it needs
828
- * `host_refused`, each with the instance's words.
829
- */
830
- async ticket(id, options = {}) {
831
- const body = record((await this.call("POST", `/api/v1/host/servers/${encodeURIComponent(id)}/tickets`, {}, options)).json);
832
- const server = record(body.server);
833
- return {
834
- ticket: text(body.ticket),
835
- expiresIn: positive(body.expires_in, 0),
836
- server: { id: text(server.id), name: text(server.name), address: text(server.address) },
837
- };
838
- }
839
- /** `POST /api/v1/host/credential` (git-host-9): the Git credential for
673
+ /** `POST /api/v1/host/credential` (git-host-41): the Git credential for
840
674
  * the host's Git origin, with its expiry in Unix milliseconds. */
841
675
  async credential(origin, options = {}) {
842
676
  const body = record((await this.call("POST", "/api/v1/host/credential", { origin }, options)).json);
@@ -846,7 +680,7 @@ export class GitHostClient {
846
680
  /**
847
681
  * The access secret a call to the host presents now, for a client of
848
682
  * the same host outside this one — the registry (environments-12):
849
- * kept current as every call's is (git-host-4), refreshed first where
683
+ * kept current as every call's is, refreshed first where
850
684
  * it is within a minute of expiring; null where this device holds no
851
685
  * app token, or the host refused the refresh and so signed it out.
852
686
  * An unreachable host or a rate limit is thrown as the host answered.
@@ -866,7 +700,7 @@ export class GitHostClient {
866
700
  /**
867
701
  * A client of the same host outside this one — the registry
868
702
  * (environments-12) — was refused `access` with a code that signs the
869
- * device out: as a refusal of this client's own call does (git-host-4),
703
+ * device out: as a refusal of this client's own call does,
870
704
  * the pair that presented it is removed and the device signed out of
871
705
  * this host alone in one step, `onSignedOut` called; true then. Where
872
706
  * it is no longer the stored pair's — a sign-in, a refresh or a
@@ -888,7 +722,7 @@ export class GitHostClient {
888
722
  return slot;
889
723
  }
890
724
  /** Claim the one sign-in, and read the pair it begins over: its token
891
- * is stored only in that pair's place (git-host-2). */
725
+ * is stored only in that pair's place. */
892
726
  async beginSignIn() {
893
727
  const slot = this.claimSignIn();
894
728
  try {
@@ -904,7 +738,7 @@ export class GitHostClient {
904
738
  this.signIn = null;
905
739
  }
906
740
  /** The issued app token and the person read with it, nothing stored
907
- * yet; a person the host does not return throws (git-host-2). */
741
+ * yet; a person the host does not return throws. */
908
742
  async issued(answer) {
909
743
  const credential = tokenFrom(answer, this.now());
910
744
  const me = await this.send("GET", (this.scope === "registry" ? "/api/v1/whoami?scope=registry" : "/api/v1/host/me"), { bearer: credential.access });
@@ -913,15 +747,11 @@ export class GitHostClient {
913
747
  return { credential, account: accountFrom(me.json) };
914
748
  }
915
749
  /** Store an issued token in place of the pair its sign-in began over;
916
- * the caller ends the sign-in in the same turn. On a seat, a person
917
- * bearing another permanent id than the one the request named ends it
918
- * naming the account signed in (git-host-27); a person `admit` refuses
750
+ * the caller ends the sign-in in the same turn. A person `admit` refuses
919
751
  * ends it with that refusal; and another pair stored meanwhile ends it
920
- * `stopped`, that pair kept: each stores nothing (git-host-2). */
752
+ * `stopped`, that pair kept: each stores nothing. */
921
753
  publish(expected, issued, admit) {
922
754
  try {
923
- if (this.server && issued.account.id !== this.server.personId)
924
- return { error: anotherPersonError(issued.account.login) };
925
755
  const refused = admit?.(issued.account);
926
756
  if (refused)
927
757
  return { error: refused };
@@ -931,12 +761,12 @@ export class GitHostClient {
931
761
  return { error: asSignInError(error) };
932
762
  }
933
763
  }
934
- /** A host route with the bearer kept current (git-host-4). Only a
764
+ /** A host route with the bearer kept current. Only a
935
765
  * success, `202` included, comes back; everything else throws.
936
- * `signal` ends the call's wait for the host's rate limit (git-host-21). */
766
+ * `signal` ends the call's wait for the host's rate limit. */
937
767
  async call(method, path, body, options = {}) {
938
768
  // A call that does not wait is refused while the hold stands before
939
- // anything is sent for it, a refresh among them (git-host-21).
769
+ // anything is sent for it, a refresh among them.
940
770
  const waits = options.signal !== undefined || options.wait === true;
941
771
  if (!waits)
942
772
  this.refuseWhileHeld();
@@ -944,7 +774,7 @@ export class GitHostClient {
944
774
  let refreshed = false;
945
775
  let recovery;
946
776
  const retryableRead = options.retryRead === true && waits && method === "GET"
947
- && /^\/api\/v1\/host\/(?:me|groups|repositories(?:\?[^/]*|\/[^/?]+)?)$/.test(path);
777
+ && /^\/api\/v1\/host\/(?:me|repositories(?:\?[^/]*|\/[^/?]+)?)$/.test(path);
948
778
  const unchanged = () => {
949
779
  if (options.signal?.aborted)
950
780
  throw new HostWaitStopped();
@@ -1005,8 +835,7 @@ export class GitHostClient {
1005
835
  }
1006
836
  }
1007
837
  /** The pair a call presents, refreshed first near its expiry; the
1008
- * refresh waits out the host's rate limit where the call does
1009
- * (git-host-21). */
838
+ * refresh waits out the host's rate limit where the call does. */
1010
839
  async current(waits = false) {
1011
840
  const stored = await this.credentials.read();
1012
841
  if (!stored)
@@ -1050,7 +879,7 @@ export class GitHostClient {
1050
879
  throw error;
1051
880
  throw this.signOutLocally(latest, new HostError("reauth", { code: codeOf(answer), words: wordsOf(answer), status: answer.status }));
1052
881
  }
1053
- /** The host refused `used` (git-host-4): remove it and say the device
882
+ /** The host refused `used`: remove it and say the device
1054
883
  * is signed out in the same turn, giving back `refusal` to throw;
1055
884
  * where another pair is stored in its place, nothing is removed or
1056
885
  * said, and `CredentialChanged` comes back instead. */
@@ -1065,7 +894,7 @@ export class GitHostClient {
1065
894
  }
1066
895
  return refusal;
1067
896
  }
1068
- /** Wait out the host's rate limit (git-host-21): until the instant it
897
+ /** Wait out the host's rate limit: until the instant it
1069
898
  * holds, again where a later answer moves it on meanwhile; `signal`
1070
899
  * ends the wait. The timer keeps no process alive. */
1071
900
  async waitOut(signal, recovery) {
@@ -1090,8 +919,7 @@ export class GitHostClient {
1090
919
  }
1091
920
  /** An answer of 429 holds the calls until the instant it asks for —
1092
921
  * its time plus its seconds, `holdMaxMs` at most — keeping a later
1093
- * instant already held; none where its seconds are unknown
1094
- * (git-host-21). */
922
+ * instant already held; none where its seconds are unknown. */
1095
923
  hold(retryAfter, answeredAt) {
1096
924
  const seconds = retryAfterSeconds(retryAfter, answeredAt);
1097
925
  if (seconds === null || seconds <= 0)
@@ -1108,8 +936,7 @@ export class GitHostClient {
1108
936
  }
1109
937
  }
1110
938
  /** A call that does not wait, made while the hold stands, is refused
1111
- * at once as the host asking to wait the seconds that remain
1112
- * (git-host-21). */
939
+ * at once as the host asking to wait the seconds that remain. */
1113
940
  refuseWhileHeld() {
1114
941
  const ms = this.holdUntil - this.now();
1115
942
  if (ms > 0)
@@ -1117,7 +944,7 @@ export class GitHostClient {
1117
944
  }
1118
945
  /** One request to the host. A call carrying a signal, or asked to
1119
946
  * wait, waits out the host's rate limit first; any other is refused
1120
- * while it holds (git-host-21). */
947
+ * while it holds. */
1121
948
  async send(method, path, init) {
1122
949
  if (init.signal !== undefined || init.wait === true)
1123
950
  await this.waitOut(init.signal, init.recovery);
@@ -1199,49 +1026,22 @@ function positive(value, fallback) {
1199
1026
  }
1200
1027
  function accountFrom(value) {
1201
1028
  const body = record(value);
1202
- return { id: text(body.id), login: text(body.login), displayName: optionalText(body.display_name), canCreateGroup: flag(body.can_create_group) };
1203
- }
1204
- function groupFrom(value) {
1205
- const body = record(value);
1206
- const can = isRecord(body.can) ? body.can : {};
1207
- return {
1208
- id: optionalText(body.id),
1209
- fullPath: text(body.full_path),
1210
- name: text(body.name),
1211
- kind: body.kind === "user" ? "user" : "group",
1212
- can: { createSubgroup: flag(can.create_subgroup), manageMembers: flag(can.manage_members), rename: flag(can.rename), delete: flag(can.delete), ...(can.restore === true ? { restore: true } : {}) },
1213
- ...(body.pending_deletion === true ? { pendingDeletion: true } : {}),
1214
- ...(typeof body.deletion_root === "string" ? { deletionRoot: body.deletion_root } : {}),
1215
- };
1216
- }
1217
- function serverFrom(value) {
1218
- const body = record(value);
1219
- const { can: _can, ...group } = groupFrom(body.group);
1220
- return { id: text(body.id), name: text(body.name), group, address: text(body.address) };
1221
- }
1222
- function roleFrom(value) {
1223
- const body = record(value);
1224
- return { id: text(body.id), name: text(body.name), mayPush: flag(body.may_push) };
1225
- }
1226
- /** The members route of a group or a repository at the host. */
1227
- function membersPath(target) {
1228
- return `/api/v1/host/${target.kind === "group" ? "groups" : "repositories"}/${encodeURIComponent(target.id)}/members`;
1029
+ return { id: text(body.id), login: text(body.login), displayName: optionalText(body.display_name) };
1229
1030
  }
1230
1031
  function repositoryFrom(value) {
1231
1032
  const body = record(value);
1033
+ const namespace = record(body.group);
1232
1034
  return {
1233
1035
  id: text(body.id),
1234
1036
  name: text(body.name),
1235
1037
  path: text(body.path),
1236
- group: groupFrom(body.group),
1038
+ group: { fullPath: text(namespace.full_path), kind: namespace.kind === "user" ? "user" : "group" },
1237
1039
  remoteUrl: text(body.remote_url),
1238
- visibility: text(body.visibility),
1239
1040
  archived: flag(body.archived),
1240
1041
  empty: flag(body.empty),
1241
1042
  lfs: flag(body.lfs),
1242
1043
  spexBranch: flag(body.spex_branch),
1243
1044
  project: isRecord(body.project) ? body.project : null,
1244
- can: { manageMembers: isRecord(body.can) && flag(body.can.manage_members), transfer: isRecord(body.can) && flag(body.can.transfer) },
1245
1045
  };
1246
1046
  }
1247
1047
  function detailFrom(body) {
@@ -1260,19 +1060,6 @@ function detailFrom(body) {
1260
1060
  },
1261
1061
  };
1262
1062
  }
1263
- function memberFrom(value) {
1264
- const body = record(value);
1265
- return {
1266
- id: text(body.id),
1267
- login: text(body.login),
1268
- displayName: optionalText(body.display_name),
1269
- role: text(body.role),
1270
- // A host that says nothing of the source lists the member as the
1271
- // group's or repository's own.
1272
- direct: typeof body.direct === "boolean" ? body.direct : true,
1273
- via: body.direct === false ? optionalText(body.via) : null,
1274
- };
1275
- }
1276
1063
  function tokenFrom(answer, now) {
1277
1064
  const body = record(answer.json);
1278
1065
  return {
@@ -1302,7 +1089,7 @@ function codeOf(answer) {
1302
1089
  function wordsOf(answer) {
1303
1090
  return envelopeOf(answer).message;
1304
1091
  }
1305
- /** A failure answer as its kind (git-host-4, git-host-11). */
1092
+ /** A failure answer as its kind. */
1306
1093
  function answerError(answer) {
1307
1094
  const { code, message } = envelopeOf(answer);
1308
1095
  const base = { code, words: message, status: answer.status };