@yunuseon/kayra 0.17.1 → 0.17.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 (77) hide show
  1. package/agent/skills/kayra-release/SKILL.md +6 -1
  2. package/ansible/roles/platform/tasks/main.yml +10 -2
  3. package/cli/dist/clients/api/auth.js +1 -1
  4. package/cli/dist/clients/api/commands.js +1 -1
  5. package/cli/dist/clients/api/contract.js +1 -1
  6. package/cli/dist/clients/api/directories.js +1 -1
  7. package/cli/dist/clients/api/discovery.js +1 -1
  8. package/cli/dist/clients/api/queries.js +1 -1
  9. package/cli/dist/clients/api/runs.js +1 -1
  10. package/cli/dist/clients/api/start.js +2 -2
  11. package/cli/dist/clients/cli/explain.js +1 -1
  12. package/cli/dist/clients/cli/framed.js +1 -1
  13. package/cli/dist/clients/cli/invocation.js +1 -1
  14. package/cli/dist/clients/cli/questions.js +1 -1
  15. package/cli/dist/clients/cli/status.js +1 -1
  16. package/cli/dist/clients/cli/terminal.js +1 -1
  17. package/cli/dist/clients/cli/text.js +1 -1
  18. package/cli/dist/clients/cli/validate.js +1 -1
  19. package/cli/dist/clients/cli/values.js +1 -1
  20. package/cli/dist/clients/cli/views.js +1 -1
  21. package/cli/dist/core/adapters/fs.js +1 -1
  22. package/cli/dist/core/adapters/network.js +1 -1
  23. package/cli/dist/core/adapters/opentofu.js +1 -1
  24. package/cli/dist/core/fleet/brand.js +23 -14
  25. package/cli/dist/core/fleet/docs.js +2 -2
  26. package/cli/dist/core/fleet/load.js +3 -2
  27. package/cli/dist/core/fleet/parse.js +59 -91
  28. package/cli/dist/core/fleet/settings.js +38 -13
  29. package/cli/dist/core/fleet/shape.js +5 -20
  30. package/cli/dist/core/interpreter/events.js +1 -1
  31. package/cli/dist/core/interpreter/loop.js +1 -1
  32. package/cli/dist/core/interpreter/needs.js +1 -1
  33. package/cli/dist/core/interpreter/process.js +2 -2
  34. package/cli/dist/core/interpreter/progress.js +1 -1
  35. package/cli/dist/core/interpreter/pty.js +1 -1
  36. package/cli/dist/core/operations/dispatch.js +2 -2
  37. package/cli/dist/core/plan/model.js +1 -1
  38. package/cli/dist/core/recipes/app-check.js +5 -8
  39. package/cli/dist/core/recipes/apps.js +2 -2
  40. package/cli/dist/core/recipes/backup.js +1 -1
  41. package/cli/dist/core/recipes/certs.js +1 -1
  42. package/cli/dist/core/recipes/doctor.js +1 -1
  43. package/cli/dist/core/recipes/host.js +2 -2
  44. package/cli/dist/core/recipes/ssh.js +2 -2
  45. package/cli/dist/core/recipes/steps.js +2 -2
  46. package/cli/dist/core/status/look.js +1 -1
  47. package/cli/dist/core/text/spans.js +1 -1
  48. package/cli/dist/core/validation/facts.js +3 -2
  49. package/cli/dist/core/validation/findings.js +3 -3
  50. package/cli/dist/deployer/app.js +2 -2
  51. package/cli/dist/deployer/brand.js +1 -1
  52. package/cli/dist/deployer/build/builder.js +2 -2
  53. package/cli/dist/deployer/build/bundle.js +2 -2
  54. package/cli/dist/deployer/build/compose.js +1 -1
  55. package/cli/dist/deployer/cron.js +1 -1
  56. package/cli/dist/deployer/ctl/answers.js +1 -1
  57. package/cli/dist/deployer/deployer.js +2 -2
  58. package/cli/dist/deployer/forges/forge.js +1 -1
  59. package/cli/dist/deployer/forges/forgejo.js +1 -1
  60. package/cli/dist/deployer/forges/github.js +1 -1
  61. package/cli/dist/deployer/forges/gitlab.js +1 -1
  62. package/cli/dist/deployer/forges/issues.js +2 -2
  63. package/cli/dist/deployer/forges/notify.js +2 -2
  64. package/cli/dist/deployer/runs/queue.js +1 -1
  65. package/cli/dist/deployer/runs/records.js +1 -1
  66. package/cli/dist/deployer/runs/run.js +2 -2
  67. package/cli/dist/deployer/runs/store.js +1 -1
  68. package/cli/dist/lib/brand.js +2 -0
  69. package/cli/dist/lib/closest.js +17 -0
  70. package/cli/dist/lib/schema.js +7 -0
  71. package/cli/dist/lib/yaml.js +21 -0
  72. package/cli/dist/main.js +1 -1
  73. package/package.json +1 -1
  74. package/schema/app.json +4 -2
  75. package/schema/server.json +10 -5
  76. /package/cli/dist/{result.js → lib/result.js} +0 -0
  77. /package/cli/dist/{typed.js → lib/typed.js} +0 -0
@@ -1,22 +1,6 @@
1
- import { err, ok } from "../../result.js";
1
+ import { err, ok } from "../../lib/result.js";
2
2
  import { isAnsibleVariable, settings } from "./settings.js";
3
- import { typed } from "../../typed.js";
4
- /** Edit distance, for "did you mean". */
5
- const indices = (length) => typed([...Array(length).keys()]);
6
- const distance = (a, b) => indices(b.length)
7
- .reduce((row, j) => indices(a.length).reduce((next, i) => Object.freeze([
8
- ...next,
9
- Math.min((row[i + 1] ?? 0) + 1, (next[i] ?? 0) + 1, (row[i] ?? 0) + (a.charAt(i) === b.charAt(j) ? 0 : 1)),
10
- ]), [j + 1]), indices(a.length + 1))
11
- .at(-1) ?? 0;
12
- /** The known name a key is most likely a typo of, if one is close enough. */
13
- export const closest = (key, known) => {
14
- const nearest = known
15
- .map((name) => ({ name, cost: distance(key, name) }))
16
- .toSorted((x, y) => x.cost - y.cost)
17
- .at(0);
18
- return nearest !== undefined && nearest.cost <= Math.max(2, Math.floor(key.length / 4)) ? nearest.name : undefined;
19
- };
3
+ import { closest } from "../../lib/closest.js";
20
4
  const suggestion = (key, known) => {
21
5
  const name = closest(key, known);
22
6
  return name === undefined ? "" : ` — did you mean '${name}'?`;
@@ -49,8 +33,9 @@ export const checkSettings = (file, values, schema, known) => {
49
33
  };
50
34
  /** The names a kind's vars.yml may set. */
51
35
  export const knownSettings = (kind) => Object.freeze(settings.filter((each) => !each.secret && (kind === undefined || each.kinds.includes(kind))).map((each) => each.name));
52
- /** A YAML document against a schema, for files whose keys are not settings (server.yml, app.yml). */
36
+ /** A YAML document against a schema, for files whose keys are not settings (app.yml): what the schema makes of it. */
37
+ // eslint-disable-next-line functional/prefer-immutable-types -- a Zod schema: immutable once built, but a class the rule cannot see into
53
38
  export const checkShape = (file, values, schema) => {
54
39
  const parsed = schema.safeParse(values);
55
- return parsed.success ? ok(values) : err(firstIssue(file, parsed.error, [], "is not a key it knows"));
40
+ return parsed.success ? ok(parsed.data) : err(firstIssue(file, parsed.error, [], "is not a key it knows"));
56
41
  };
@@ -4,7 +4,7 @@ import { duration } from "../text/time.js";
4
4
  import { parts, position } from "./progress.js";
5
5
  import { count } from "../text/plural.js";
6
6
  import { milliseconds } from "../fleet/brand.js";
7
- import { typed } from "../../typed.js";
7
+ import { typed } from "../../lib/typed.js";
8
8
  /** The heading for a command: as typed, what it runs on, which kayra. */
9
9
  export const heading = (command, target, version) => typed({
10
10
  command,
@@ -4,7 +4,7 @@ import { ask, isStopped } from "./io.js";
4
4
  import { answer, resolve, spawned } from "./process.js";
5
5
  import { meet, scratch } from "./needs.js";
6
6
  import { inPty } from "./pty.js";
7
- import { typed } from "../../typed.js";
7
+ import { typed } from "../../lib/typed.js";
8
8
  /** Lines as printing them one by one gives the text back: newline-ended, as a ctl writes. */
9
9
  const asItCame = (_answer, said) => (said === "" ? typed([]) : said.replace(/\n$/, "").split("\n"));
10
10
  const lines = (text) => Object.freeze(text
@@ -4,7 +4,7 @@ import { join } from "node:path";
4
4
  import { active, muted, strong } from "../text/spans.js";
5
5
  import { ask } from "./io.js";
6
6
  import { spawned } from "./process.js";
7
- import { typed } from "../../typed.js";
7
+ import { typed } from "../../lib/typed.js";
8
8
  const keyOf = (need) => (need.kind === "vault" ? `vault:${need.server}` : "sudo");
9
9
  const questionOf = (need) => typed(need.kind === "vault" ? { kind: "secret", text: [" ", active("?"), " ", strong(`${need.server}'s vault password`), muted(" (asked once, kept for this run): ")] } : { kind: "secret", text: [" ", active("?"), " ", strong("sudo's password"), muted(" (for this step only): ")] });
10
10
  /** Whether sudo would run without a password: a cached one, or none needed. */
@@ -1,9 +1,9 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import { text } from "node:stream/consumers";
3
- import { all, err, flatMap, ok } from "../../result.js";
3
+ import { all, err, flatMap, ok } from "../../lib/result.js";
4
4
  import { isStopped } from "./io.js";
5
5
  import { exitCode } from "../fleet/brand.js";
6
- import { typed } from "../../typed.js";
6
+ import { typed } from "../../lib/typed.js";
7
7
  const terminal = {};
8
8
  /** A program that ignores SIGINT this long gets SIGTERM. */
9
9
  const patience = 10_000;
@@ -1,4 +1,4 @@
1
- import { typed } from "../../typed.js";
1
+ import { typed } from "../../lib/typed.js";
2
2
  /** Why a plan stopped before its end. */
3
3
  export const stopReasons = ["failed", "declined", "interrupted"];
4
4
  /** Nothing around the steps: for commands whose output is the point (ssh, logs), and for tests. */
@@ -1,5 +1,5 @@
1
1
  import { quote } from "../plan/describe.js";
2
- import { typed } from "../../typed.js";
2
+ import { typed } from "../../lib/typed.js";
3
3
  /** A step that talks with a person, given a pty: macOS's script, util-linux's elsewhere. */
4
4
  export const inPty = (argv, size) => {
5
5
  const { columns, rows } = size ?? { columns: 120, rows: 32 };
@@ -11,10 +11,10 @@ import { ssh } from "../recipes/ssh.js";
11
11
  import { look } from "../status/look.js";
12
12
  import { findings } from "../validation/findings.js";
13
13
  import { gather } from "../validation/facts.js";
14
- import { all, err, flatMap, map, ok } from "../../result.js";
14
+ import { all, err, flatMap, map, ok } from "../../lib/result.js";
15
15
  import { operations } from "./catalog.js";
16
16
  import { textAt } from "../adapters/fs.js";
17
- import { typed } from "../../typed.js";
17
+ import { typed } from "../../lib/typed.js";
18
18
  import { resolve as substitute, spawned } from "../interpreter/process.js";
19
19
  /** The context for a fleet, with the files read from disk: what every client runs the core with. */
20
20
  export const contextFor = (parts) => {
@@ -1,4 +1,4 @@
1
- import { typed } from "../../typed.js";
1
+ import { typed } from "../../lib/typed.js";
2
2
  /** The kayra commands a longer one is made of, each of which runs its part alone. */
3
3
  export const parts = ["provision", "setup", "apps", "verify", "hosts"];
4
4
  export const run = (title, argv, env = {}) => typed({
@@ -1,11 +1,11 @@
1
- import { appName, within } from "../fleet/brand.js";
2
- import { yamlOf } from "../fleet/parse.js";
1
+ import { within } from "../fleet/brand.js";
2
+ import { yamlOf } from "../../lib/yaml.js";
3
3
  import { run } from "../plan/model.js";
4
- import { err, flatMap, map, mapError } from "../../result.js";
4
+ import { err, flatMap, map, mapError } from "../../lib/result.js";
5
5
  import { appManifestSchema } from "../fleet/settings.js";
6
6
  import { checkShape } from "../fleet/shape.js";
7
7
  import { onPath } from "./steps.js";
8
- import { typed } from "../../typed.js";
8
+ import { typed } from "../../lib/typed.js";
9
9
  const tool = (program, hint) => onPath(`${program} is installed`, program, hint, "stop");
10
10
  /**
11
11
  * In an app's own repository, before a push: what the platform checks when it
@@ -16,10 +16,7 @@ const tool = (program, hint) => onPath(`${program} is installed`, program, hint,
16
16
  export const appCheck = (kayra, root, manifest) => {
17
17
  if (manifest === undefined)
18
18
  return err(`no app.yml in ${root}`);
19
- const shaped = flatMap(flatMap(mapError(yamlOf(manifest), (problem) => `app.yml ${problem}`), (values) => checkShape("app.yml", values, appManifestSchema)), (values) => {
20
- const parsed = appManifestSchema.safeParse(values);
21
- return parsed.success ? appName(parsed.data.name) : err("app.yml: invalid");
22
- });
19
+ const shaped = flatMap(mapError(yamlOf(manifest), (problem) => `app.yml ${problem}`), (values) => checkShape("app.yml", values, appManifestSchema));
23
20
  return map(shaped, () => typed([
24
21
  tool("git", "brew install git"),
25
22
  tool("jq", "brew install jq"),
@@ -1,8 +1,8 @@
1
1
  import { partOf, run } from "../plan/model.js";
2
- import { err, map, ok } from "../../result.js";
2
+ import { err, map, ok } from "../../lib/result.js";
3
3
  import { ansibleEnv, ansiblePath, collections, fromMain, inventory, vault, vaulted } from "./steps.js";
4
4
  import { sshTo } from "./ssh.js";
5
- import { typed } from "../../typed.js";
5
+ import { typed } from "../../lib/typed.js";
6
6
  /** Register every app in server.yml, then remove the rest (their data kept). */
7
7
  export const apps = (engine, server) => {
8
8
  const { env } = vault(server);
@@ -1,6 +1,6 @@
1
1
  import { within } from "../fleet/brand.js";
2
2
  import { run } from "../plan/model.js";
3
- import { err, ok } from "../../result.js";
3
+ import { err, ok } from "../../lib/result.js";
4
4
  import { ansibleEnv, inventory, reachable, vaulted } from "./steps.js";
5
5
  import { sshArgv } from "./ssh.js";
6
6
  /**
@@ -1,4 +1,4 @@
1
- import { ok } from "../../result.js";
1
+ import { ok } from "../../lib/result.js";
2
2
  import { certs } from "./steps.js";
3
3
  /** mkcert certs for a domain and its subdomains, for local dev and multipass. */
4
4
  export const certsFor = (engine, domain, subdomains) => ok([certs(engine, domain, subdomains)]);
@@ -1,6 +1,6 @@
1
1
  import { within } from "../fleet/brand.js";
2
2
  import { homeReach, onPath } from "./steps.js";
3
- import { typed } from "../../typed.js";
3
+ import { typed } from "../../lib/typed.js";
4
4
  const everyServer = () => true;
5
5
  const tools = [
6
6
  { program: "git", install: "brew install git", neededBy: everyServer },
@@ -1,8 +1,8 @@
1
1
  import { partOf, run } from "../plan/model.js";
2
- import { err, map, ok } from "../../result.js";
2
+ import { err, map, ok } from "../../lib/result.js";
3
3
  import { ansibleEnv, ansiblePath, appSubdomains, certs, collections, fleetEnv, fromMain, inventory, latestState, needing, reachable, script, sequence, terraform, vault, vaulted } from "./steps.js";
4
4
  import { apps } from "./apps.js";
5
- import { typed } from "../../typed.js";
5
+ import { typed } from "../../lib/typed.js";
6
6
  export const provision = (engine, server) => ok(partOf("provision", [
7
7
  fromMain(engine, server),
8
8
  ...(server.buildsVm ? [run("VM image and seed ISO", ["bash", script(engine, "home-image.sh"), server.name], fleetEnv(engine))] : []),
@@ -1,6 +1,6 @@
1
1
  import { run } from "../plan/model.js";
2
- import { err, map, ok } from "../../result.js";
3
- import { typed } from "../../typed.js";
2
+ import { err, map, ok } from "../../lib/result.js";
3
+ import { typed } from "../../lib/typed.js";
4
4
  /** ssh to a server as its inventory says, its host key trusted as `hostKeys` say. */
5
5
  export const sshArgv = (inventory, hostKeys, remote) => typed([
6
6
  "ssh",
@@ -1,7 +1,7 @@
1
1
  import { within } from "../fleet/brand.js";
2
2
  import { run } from "../plan/model.js";
3
- import { all, map } from "../../result.js";
4
- import { typed } from "../../typed.js";
3
+ import { all, map } from "../../lib/result.js";
4
+ import { typed } from "../../lib/typed.js";
5
5
  /** The local scripts that read the fleet's files find them here, not beside themselves. */
6
6
  export const fleetEnv = ({ fleet }) => typed({ FLEET_ROOT: fleet });
7
7
  export const script = ({ kayra }, name) => within(kayra, "scripts", "local", name);
@@ -1,6 +1,6 @@
1
1
  import { host, sshDefaultPort, within } from "../fleet/brand.js";
2
2
  import { isMachine } from "./model.js";
3
- import { typed } from "../../typed.js";
3
+ import { typed } from "../../lib/typed.js";
4
4
  /** The inventory names the address: hand-written at home, written by provision elsewhere. */
5
5
  export const listed = (server) => server.inventory === undefined
6
6
  ? undefined
@@ -1,6 +1,6 @@
1
1
  /** What a piece of text means, not how it looks: each client gives it a look (a terminal colour, a CSS class), or none. */
2
2
  export const tones = ["ok", "bad", "warn", "active", "muted", "strong", "accent"];
3
- import { typed } from "../../typed.js";
3
+ import { typed } from "../../lib/typed.js";
4
4
  const toned = (tone) => (text) => typed({ tone, text });
5
5
  export const ok = toned("ok");
6
6
  export const bad = toned("bad");
@@ -2,9 +2,10 @@ import { existsSync } from "node:fs";
2
2
  import { homedir } from "node:os";
3
3
  import { join } from "node:path";
4
4
  import { textAt } from "../adapters/fs.js";
5
- import { fields, isVaulted } from "../fleet/parse.js";
5
+ import { isVaulted } from "../fleet/parse.js";
6
+ import { fields } from "../../lib/yaml.js";
6
7
  import { capture } from "../interpreter/process.js";
7
- import { typed } from "../../typed.js";
8
+ import { typed } from "../../lib/typed.js";
8
9
  /** YAML as validate reads it: what it cannot read holds no values. */
9
10
  const valuesOf = (text) => {
10
11
  const parsed = text === undefined ? undefined : fields(text);
@@ -1,9 +1,9 @@
1
1
  import { appManifestSchema, secretsSchema, settings } from "../fleet/settings.js";
2
- import { closest } from "../fleet/shape.js";
2
+ import { closest } from "../../lib/closest.js";
3
3
  import { count } from "../text/plural.js";
4
- import { mapping as fields } from "../fleet/parse.js";
4
+ import { mapping as fields } from "../../lib/yaml.js";
5
5
  import { subdomain } from "../fleet/brand.js";
6
- import { typed } from "../../typed.js";
6
+ import { typed } from "../../lib/typed.js";
7
7
  /** How a check went: it found a problem, could not look, or holds. */
8
8
  export const verdicts = ["problem", "unchecked", "passed"];
9
9
  const finding = (result, text, hint) => typed({ result, text, ...(hint === undefined ? {} : { hint }) });
@@ -1,7 +1,7 @@
1
- import { typed } from "../typed.js";
1
+ import { typed } from "../lib/typed.js";
2
2
  import { existsSync, readFileSync } from "node:fs";
3
3
  import { join } from "node:path";
4
- import { err, ok } from "../result.js";
4
+ import { err, ok } from "../lib/result.js";
5
5
  import { appName } from "./brand.js";
6
6
  const strings = (value, pattern) => Array.isArray(value) && value.every((item) => typeof item === "string" && pattern.test(item))
7
7
  ? typed(value)
@@ -1,4 +1,4 @@
1
- import { err, ok } from "../result.js";
1
+ import { err, ok } from "../lib/result.js";
2
2
  export const appName = (value) => /^[a-z][a-z0-9-]*$/.test(value) ? ok(value) : err(`'${value}' is not an app name`);
3
3
  export const sha = (value) => /^[0-9a-f]{40}$/.test(value) ? ok(value) : err(`'${value}' is not a full commit id`);
4
4
  export const runId = (value) => /^\d{8}T\d{6}Z-[0-9a-f]{6}$/.test(value) ? ok(value) : err(`'${value}' is not a run id`);
@@ -1,7 +1,7 @@
1
1
  import { existsSync, mkdirSync, readFileSync } from "node:fs";
2
2
  import { createServer } from "node:http";
3
3
  import { join } from "node:path";
4
- import { err, ok } from "../../result.js";
4
+ import { err, ok } from "../../lib/result.js";
5
5
  import { field, registered } from "../app.js";
6
6
  import { owner, runId, sha } from "../brand.js";
7
7
  import { body, json, send } from "../http/http.js";
@@ -9,7 +9,7 @@ import { page, runPage } from "../http/page.js";
9
9
  import { spawnLines } from "../process.js";
10
10
  import { forgeRepo, signed } from "../forges/forge.js";
11
11
  import { pushedRef } from "../http/webhook.js";
12
- import { typed } from "../../typed.js";
12
+ import { typed } from "../../lib/typed.js";
13
13
  const fromFile = (path) => () => (existsSync(path) ? readFileSync(path, "utf8").trim() : "");
14
14
  const settings = (env) => {
15
15
  const platformDir = env["PLATFORM_DIR"] ?? "/opt/platform";
@@ -1,7 +1,7 @@
1
- import { err, ok } from "../../result.js";
1
+ import { err, ok } from "../../lib/result.js";
2
2
  import { field } from "../app.js";
3
3
  import { sha } from "../brand.js";
4
- import { typed } from "../../typed.js";
4
+ import { typed } from "../../lib/typed.js";
5
5
  const relative = (path) => path !== "" && !path.startsWith("/") && !path.split("/").some((segment) => segment === ".." || segment === "");
6
6
  export const parseBundle = (app, expected, json) => {
7
7
  if (typeof json !== "object" || json === null)
@@ -1,4 +1,4 @@
1
- import { typed } from "../../typed.js";
1
+ import { typed } from "../../lib/typed.js";
2
2
  /**
3
3
  * The app's compose project, run in the run's directory: its .env from the
4
4
  * platform (operator config), the image refs from this run, the compose files
@@ -1,4 +1,4 @@
1
- import { all, err, map, ok } from "../result.js";
1
+ import { all, err, map, ok } from "../lib/result.js";
2
2
  const range = (from, to, step) => Object.freeze(Array.from({ length: Math.floor((to - from) / step) + 1 }, (_, i) => from + i * step));
3
3
  const part = (text, min, max) => {
4
4
  const match = /^(\*|(\d+)(?:-(\d+))?)(?:\/(\d+))?$/.exec(text);
@@ -1,4 +1,4 @@
1
- import { typed } from "../../typed.js";
1
+ import { typed } from "../../lib/typed.js";
2
2
  /** A release record's compact UTC time, 20261018T101500Z, as ISO 8601. */
3
3
  const iso = (compact) => compact.replace(/^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z$/, "$1-$2-$3T$4:$5:$6Z");
4
4
  const deployed = (release) => typed({ sha: release.sha, time: iso(release.time) });
@@ -5,7 +5,7 @@ import { tmpdir } from "node:os";
5
5
  import { dirname, join } from "node:path";
6
6
  import { createInterface } from "node:readline";
7
7
  import { Readable } from "node:stream";
8
- import { all, err, ok } from "../result.js";
8
+ import { all, err, ok } from "../lib/result.js";
9
9
  import { field, registered } from "./app.js";
10
10
  import { appName, appOwner, jobOwner, newRunId, sha } from "./brand.js";
11
11
  import { matches, parseCron } from "./cron.js";
@@ -18,7 +18,7 @@ import { githubIssues } from "./forges/issues.js";
18
18
  import { decide, parseNotify, silent } from "./forges/notify.js";
19
19
  import { deploy, renovate } from "./runs/run.js";
20
20
  import { runsOf } from "./runs/store.js";
21
- import { typed } from "../typed.js";
21
+ import { typed } from "../lib/typed.js";
22
22
  const token = (name) => {
23
23
  const path = `/run/platform-secrets/${name}`;
24
24
  return existsSync(path) ? readFileSync(path, "utf8").trim() : "";
@@ -1,7 +1,7 @@
1
1
  import { forgejo } from "./forgejo.js";
2
2
  import { github } from "./github.js";
3
3
  import { gitlab } from "./gitlab.js";
4
- import { typed } from "../../typed.js";
4
+ import { typed } from "../../lib/typed.js";
5
5
  const adapters = { github, forgejo, gitlab };
6
6
  const kinds = { "https://github.com": "github", "https://gitlab.com": "gitlab" };
7
7
  /** GitHub for https://github.com, GitLab for https://gitlab.com, a Forgejo for any other host; undefined for a URL none understands. */
@@ -1,4 +1,4 @@
1
- import { err, ok } from "../../result.js";
1
+ import { err, ok } from "../../lib/result.js";
2
2
  import { header, hmacMatches } from "../http/webhook.js";
3
3
  /** A Forgejo's API (Gitea's statuses endpoint); webhooks signed `X-Forgejo-Signature: <hex>` (or Gitea's, or GitHub's, which it sends too). */
4
4
  export const forgejo = {
@@ -1,4 +1,4 @@
1
- import { err, ok } from "../../result.js";
1
+ import { err, ok } from "../../lib/result.js";
2
2
  import { header, hmacMatches } from "../http/webhook.js";
3
3
  /** GitHub's REST API; webhooks signed `X-Hub-Signature-256: sha256=<hex>`. */
4
4
  export const github = {
@@ -1,4 +1,4 @@
1
- import { err, ok } from "../../result.js";
1
+ import { err, ok } from "../../lib/result.js";
2
2
  import { header, secretMatches } from "../http/webhook.js";
3
3
  /** GitLab knows no "failure" or "error", only "failed". */
4
4
  const states = { pending: "pending", success: "success", failure: "failed", error: "failed" };
@@ -1,7 +1,7 @@
1
1
  import { createSign } from "node:crypto";
2
- import { err, ok } from "../../result.js";
2
+ import { err, ok } from "../../lib/result.js";
3
3
  import { field } from "../app.js";
4
- import { typed } from "../../typed.js";
4
+ import { typed } from "../../lib/typed.js";
5
5
  const base64url = (data) => Buffer.from(data).toString("base64url");
6
6
  /** The app's own token: a JWT signed with its private key, valid nine minutes. */
7
7
  export const appJwt = (appId, privateKey, nowSeconds) => {
@@ -1,6 +1,6 @@
1
- import { err, ok } from "../../result.js";
1
+ import { err, ok } from "../../lib/result.js";
2
2
  import { field } from "../app.js";
3
- import { typed } from "../../typed.js";
3
+ import { typed } from "../../lib/typed.js";
4
4
  export const silent = {
5
5
  raise: () => Promise.resolve(ok(undefined)),
6
6
  resolve: () => Promise.resolve(ok(undefined)),
@@ -1,4 +1,4 @@
1
- import { typed } from "../../typed.js";
1
+ import { typed } from "../../lib/typed.js";
2
2
  export const empty = (limit) => typed({ running: [], waiting: [], limit });
3
3
  const exclusive = (request) => request.work.kind === "job" && request.work.job === "gc";
4
4
  /** Starts what may start, in order; a waiting exclusive request holds back everything behind it. */
@@ -1,6 +1,6 @@
1
1
  import { runId, sha } from "../brand.js";
2
2
  import { field } from "../app.js";
3
- import { typed } from "../../typed.js";
3
+ import { typed } from "../../lib/typed.js";
4
4
  /** A release record's name: releases/<app>/<UTC time>-<sha>.env. registry-gc.sh reads the same files. */
5
5
  export const releaseName = (at, commit) => `${at.toISOString().replace(/[-:]/g, "").replace(/\.\d+Z$/, "Z")}-${commit}.env`;
6
6
  /** Newest first, one per commit: the first is what runs now, the rest are what rollback offers. */
@@ -1,7 +1,7 @@
1
- import { err, ok } from "../../result.js";
1
+ import { err, ok } from "../../lib/result.js";
2
2
  import { imagesEnv, parseBundle } from "../build/bundle.js";
3
3
  import { config, policy, up } from "../build/compose.js";
4
- import { typed } from "../../typed.js";
4
+ import { typed } from "../../lib/typed.js";
5
5
  const step = async (fx, label, argv, options) => {
6
6
  fx.log(`── ${label}`);
7
7
  const exit = await fx.exec(argv, options);
@@ -2,7 +2,7 @@ import { existsSync, readdirSync, readFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { owner as mintOwner, runId } from "../brand.js";
4
4
  import { parseMeta } from "./records.js";
5
- import { typed } from "../../typed.js";
5
+ import { typed } from "../../lib/typed.js";
6
6
  /** Reading runs/: <owner>/<id>/{meta.json,log}. Only the deployer writes there. */
7
7
  const entries = (dir) => (existsSync(dir) ? readdirSync(dir).toSorted() : typed([]));
8
8
  export const owners = (runs) => Object.freeze(entries(runs).flatMap((name) => {
@@ -0,0 +1,2 @@
1
+ /** For a schema's `.transform`: what passed it, branded B. The one place a brand is minted without a check of its own. */
2
+ export const branded = () => (value) => value;
@@ -0,0 +1,17 @@
1
+ import { typed } from "./typed.js";
2
+ /** Edit distance, for "did you mean". */
3
+ const indices = (length) => typed([...Array(length).keys()]);
4
+ const distance = (a, b) => indices(b.length)
5
+ .reduce((row, j) => indices(a.length).reduce((next, i) => Object.freeze([
6
+ ...next,
7
+ Math.min((row[i + 1] ?? 0) + 1, (next[i] ?? 0) + 1, (row[i] ?? 0) + (a.charAt(i) === b.charAt(j) ? 0 : 1)),
8
+ ]), [j + 1]), indices(a.length + 1))
9
+ .at(-1) ?? 0;
10
+ /** The known name a key is most likely a typo of, if one is close enough. */
11
+ export const closest = (key, known) => {
12
+ const nearest = known
13
+ .map((name) => ({ name, cost: distance(key, name) }))
14
+ .toSorted((x, y) => x.cost - y.cost)
15
+ .at(0);
16
+ return nearest !== undefined && nearest.cost <= Math.max(2, Math.floor(key.length / 4)) ? nearest.name : undefined;
17
+ };
@@ -0,0 +1,7 @@
1
+ import { err, ok } from "./result.js";
2
+ /** A schema as a constructor: its value, or the first problem it found. */
3
+ // eslint-disable-next-line functional/prefer-immutable-types -- a Zod schema: immutable once built, but a class the rule cannot see into
4
+ export const minting = (schema) => (value) => {
5
+ const parsed = schema.safeParse(value);
6
+ return parsed.success ? ok(parsed.data) : err(parsed.error.issues.at(0)?.message ?? "is invalid");
7
+ };
@@ -0,0 +1,21 @@
1
+ import { parseDocument } from "yaml";
2
+ import { err, ok } from "./result.js";
3
+ import { typed } from "./typed.js";
4
+ export const mapping = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? typed(Object.fromEntries(Object.entries(value))) : undefined;
5
+ /** YAML text as a value; a syntax error is a value too, not an exception. */
6
+ export const yamlOf = (text) => {
7
+ const document = parseDocument(text);
8
+ const problem = document.errors.at(0);
9
+ return problem === undefined ? ok(document.toJS()) : err(`is not valid YAML: ${problem.message.split("\n")[0] ?? ""}`);
10
+ };
11
+ /** YAML text as a mapping; empty for an empty file. */
12
+ export const fields = (text) => {
13
+ const parsed = yamlOf(text);
14
+ if (!parsed.ok)
15
+ return parsed;
16
+ const value = parsed.value;
17
+ if (value === null || value === undefined)
18
+ return ok({});
19
+ const result = mapping(value);
20
+ return result === undefined ? err("is not a YAML mapping") : ok(result);
21
+ };
package/cli/dist/main.js CHANGED
@@ -22,7 +22,7 @@ import { systemBrowser } from "./clients/ui/opener.js";
22
22
  import { serve } from "./serve.js";
23
23
  import { network } from "./core/adapters/network.js";
24
24
  import { render } from "./core/plan/describe.js";
25
- import { err, flatMap, map, ok } from "./result.js";
25
+ import { err, flatMap, map, ok } from "./lib/result.js";
26
26
  import { explain } from "./clients/cli/explain.js";
27
27
  import { draw } from "./clients/cli/views.js";
28
28
  import { bad, muted, strong } from "./core/text/spans.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yunuseon/kayra",
3
- "version": "0.17.1",
3
+ "version": "0.17.2",
4
4
  "description": "A self-hosted app platform and the CLI that runs it: Traefik, Authelia, a registry, rootless BuildKit and a small deployer per server, set up with OpenTofu and Ansible.",
5
5
  "license": "MIT",
6
6
  "author": "Yunus Öztürk",
package/schema/app.json CHANGED
@@ -3,8 +3,9 @@
3
3
  "type": "object",
4
4
  "properties": {
5
5
  "name": {
6
+ "description": "The app's name, as in the server.yml entry.",
6
7
  "type": "string",
7
- "description": "The app's name, as in the server.yml entry."
8
+ "pattern": "^[a-z][a-z0-9-]*$"
8
9
  },
9
10
  "compose": {
10
11
  "type": "array",
@@ -16,7 +17,8 @@
16
17
  "subdomains": {
17
18
  "type": "array",
18
19
  "items": {
19
- "type": "string"
20
+ "type": "string",
21
+ "pattern": "^[a-z0-9]([a-z0-9-]*[a-z0-9])?$"
20
22
  },
21
23
  "description": "Hostnames the app claims: <sub>.<domain>."
22
24
  },
@@ -3,6 +3,7 @@
3
3
  "type": "object",
4
4
  "properties": {
5
5
  "kind": {
6
+ "default": "platform",
6
7
  "description": "Which playbook: platform (default; Traefik, Authelia, the deployer, apps), edge or nas.",
7
8
  "type": "string",
8
9
  "enum": [
@@ -14,17 +15,19 @@
14
15
  "target": {
15
16
  "type": "string",
16
17
  "enum": [
17
- "hetzner",
18
18
  "multipass",
19
+ "hetzner",
19
20
  "home"
20
21
  ],
21
22
  "description": "Where it runs: hetzner, multipass (a local VM) or home (a machine nothing creates)."
22
23
  },
23
24
  "domain": {
25
+ "description": "The server's domain; platform subdomains and the apps' hang off it.",
24
26
  "type": "string",
25
- "description": "The server's domain; platform subdomains and the apps' hang off it."
27
+ "pattern": "^([a-z0-9]([a-z0-9-]*[a-z0-9])?\\.)+[a-z][a-z0-9-]*$"
26
28
  },
27
29
  "vault": {
30
+ "default": false,
28
31
  "description": "secrets.yml is vault-encrypted (required outside multipass).",
29
32
  "type": "boolean"
30
33
  },
@@ -39,11 +42,12 @@
39
42
  "type": "object",
40
43
  "properties": {
41
44
  "name": {
42
- "type": "string"
45
+ "type": "string",
46
+ "pattern": "^[a-z][a-z0-9-]*$"
43
47
  },
44
48
  "repo": {
45
- "type": "string",
46
- "description": "The app's repository, https://."
49
+ "description": "The app's repository, https://.",
50
+ "type": "string"
47
51
  },
48
52
  "ref": {
49
53
  "description": "The branch to build and deploy (default main).",
@@ -51,6 +55,7 @@
51
55
  },
52
56
  "path": {
53
57
  "description": "The app's root inside the repository (default .).",
58
+ "default": ".",
54
59
  "type": "string"
55
60
  }
56
61
  },
File without changes
File without changes