@sous-io/sous 0.2.31 → 0.2.33

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 (104) hide show
  1. package/README.md +7 -6
  2. package/docs/markdown/_sidebar.md +2 -0
  3. package/docs/markdown/commands.md +8 -4
  4. package/docs/markdown/configuration.md +28 -4
  5. package/docs/markdown/repositories-authoring.md +22 -2
  6. package/docs/markdown/repositories-consuming.md +40 -11
  7. package/docs/markdown/repositories-file-formats.md +28 -13
  8. package/docs/markdown/repositories-quickstart.md +1 -1
  9. package/docs/markdown/repositories.md +14 -9
  10. package/package.json +2 -1
  11. package/recipes/core/sous-skills/skills/about-liquid-templates/SKILL.tpl.md +32 -17
  12. package/recipes/core/sous-skills/skills/about-sous/SKILL.tpl.md +8 -2
  13. package/recipes/core/sous-skills/skills/about-sous-configuration/SKILL.tpl.md +4 -0
  14. package/recipes/core/sous-skills/skills/about-sous-recipes/SKILL.tpl.md +29 -9
  15. package/recipes/core/sous-skills/sous.recipe.yaml +1 -1
  16. package/sous.config.schema.json +27 -15
  17. package/src/commands/lock/rebuild.ts +3 -6
  18. package/src/commands/namespace/show.ts +2 -2
  19. package/src/commands/recipe/show.ts +26 -9
  20. package/src/commands/repo/contribute.ts +32 -23
  21. package/src/commands/repo/gc.ts +1 -1
  22. package/src/commands/repo/remove.ts +1 -1
  23. package/src/commands/repo/search.ts +1 -1
  24. package/src/commands/vars/ask.ts +75 -54
  25. package/src/lib/build-service.ts +85 -11
  26. package/src/lib/config-schema.ts +59 -19
  27. package/src/lib/include-resolver.ts +307 -69
  28. package/src/lib/markdown-compiler.ts +273 -81
  29. package/src/lib/project-scaffold/templates.ts +19 -11
  30. package/src/lib/repos/catalog-inputs.ts +1 -1
  31. package/src/lib/repos/catalog.ts +98 -72
  32. package/src/lib/repos/declarations.ts +22 -12
  33. package/src/lib/repos/formats/index-file.ts +1 -1
  34. package/src/lib/repos/formats/recipe-manifest.ts +3 -4
  35. package/src/lib/repos/lock-service.ts +1 -1
  36. package/src/lib/repos/locked-namespace-resolver.ts +14 -6
  37. package/src/lib/repos/locked-recipe-lookup.ts +123 -0
  38. package/src/lib/repos/locked-recipes.ts +1 -1
  39. package/src/lib/repos/memories-hash-name.ts +33 -0
  40. package/src/lib/repos/namespace-resolver.ts +198 -119
  41. package/src/lib/repos/recipe-config-layers.ts +29 -1
  42. package/src/lib/repos/recipe-key-matcher.ts +62 -0
  43. package/src/lib/repos/recipe-memories.ts +175 -0
  44. package/src/lib/repos/recipe-targets.ts +27 -28
  45. package/src/lib/repos/ref-search.ts +1 -1
  46. package/src/lib/repos/release/index-builder.ts +23 -15
  47. package/src/lib/repos/release/plan.ts +14 -7
  48. package/src/lib/repos/release/settle.ts +38 -121
  49. package/src/lib/repos/release/submit-checkout.ts +42 -23
  50. package/src/lib/repos/release/tags.ts +1 -1
  51. package/src/lib/repos/resolver.ts +90 -72
  52. package/src/lib/repos/subscription-service.ts +192 -170
  53. package/src/lib/settings.ts +37 -33
  54. package/src/lib/vars/ask.ts +3 -3
  55. package/src/lib/vars/mappings.ts +17 -9
  56. package/src/services/ref-resolver/container.ts +107 -0
  57. package/src/services/ref-resolver/dependency.ts +60 -0
  58. package/src/services/ref-resolver/format.ts +197 -0
  59. package/src/services/ref-resolver/glob.ts +115 -0
  60. package/src/services/ref-resolver/hash-names.ts +155 -0
  61. package/src/services/ref-resolver/index.ts +55 -0
  62. package/src/services/ref-resolver/injectable.ts +36 -0
  63. package/src/services/ref-resolver/location.ts +62 -0
  64. package/src/services/ref-resolver/lookups/cached-index-lookup.ts +53 -0
  65. package/src/services/ref-resolver/lookups/catalog-lookup.ts +23 -0
  66. package/src/services/ref-resolver/lookups/catalog-matcher.ts +261 -0
  67. package/src/services/ref-resolver/lookups/chained-lookup.ts +27 -0
  68. package/src/services/ref-resolver/lookups/env-var-lookup.ts +65 -0
  69. package/src/services/ref-resolver/lookups/fetched-index-lookup.ts +150 -0
  70. package/src/services/ref-resolver/lookups/recorded-dependency-lookup.ts +62 -0
  71. package/src/services/ref-resolver/lookups/ref-lookup.ts +54 -0
  72. package/src/services/ref-resolver/lookups/variable-lookup.ts +123 -0
  73. package/src/services/ref-resolver/named-refs.ts +144 -0
  74. package/src/services/ref-resolver/parser/env-var-splitter.ts +27 -0
  75. package/src/services/ref-resolver/parser/location-splitter.ts +239 -0
  76. package/src/services/ref-resolver/parser/name-path-splitter.ts +200 -0
  77. package/src/services/ref-resolver/parser/partial-ref.ts +84 -0
  78. package/src/services/ref-resolver/parser/query-splitter.ts +61 -0
  79. package/src/services/ref-resolver/parser/range-splitter.ts +52 -0
  80. package/src/services/ref-resolver/parser/ref-parser.ts +115 -0
  81. package/src/services/ref-resolver/parser/repo-qualifier-splitter.ts +51 -0
  82. package/src/services/ref-resolver/parts.ts +115 -0
  83. package/src/services/ref-resolver/pruners/command-line-pruner.ts +47 -0
  84. package/src/services/ref-resolver/pruners/include-pruner.ts +66 -0
  85. package/src/services/ref-resolver/pruners/manifest-pruner.ts +130 -0
  86. package/src/services/ref-resolver/pruners/ref-pruner.ts +135 -0
  87. package/src/services/ref-resolver/pruners/rule-helpers.ts +44 -0
  88. package/src/services/ref-resolver/pruners/stored-key-pruner.ts +136 -0
  89. package/src/services/ref-resolver/ref-helpers.ts +62 -0
  90. package/src/services/ref-resolver/ref-picker-service.ts +204 -0
  91. package/src/{lib/repos/reference-report.ts → services/ref-resolver/ref-report.ts} +2 -40
  92. package/src/services/ref-resolver/ref-resolve-arguments.ts +47 -0
  93. package/src/services/ref-resolver/ref-resolve-result.ts +36 -0
  94. package/src/services/ref-resolver/ref-resolver-service.ts +323 -0
  95. package/src/services/ref-resolver/source.ts +48 -0
  96. package/src/services/ref-resolver/tokens.ts +25 -0
  97. package/src/services/ref-resolver/types.ts +155 -0
  98. package/src/templating/init-liquid-engine.ts +25 -18
  99. package/src/lib/refs/find.ts +0 -770
  100. package/src/lib/refs/index.ts +0 -14
  101. package/src/lib/refs/parse.ts +0 -844
  102. package/src/lib/refs/pick.ts +0 -147
  103. package/src/lib/refs/scopes.ts +0 -95
  104. package/src/lib/refs/settle.ts +0 -219
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Where a ref was written. The parser reads every form wherever a ref comes
3
+ * from, and the place decides which of those forms it allows: the pruner for
4
+ * that place drops the readings it refuses, saying what to write there instead.
5
+ */
6
+ export enum RefSource {
7
+ /**
8
+ * A ref typed on the command line. Every form is allowed: a bare name, a
9
+ * namespace and recipe, a `repo:` qualifier, a version range, a
10
+ * provider-scheme locator, an HTTPS, SSH or scheme-less URL, and a browser
11
+ * URL copied from a host's file view. Names may be written in any case.
12
+ */
13
+ CommandLine = "commandLine",
14
+ /**
15
+ * A subscription key in a config layer. Only the stored form is allowed:
16
+ * `namespace` or `namespace/recipe`, lowercase. The repository a
17
+ * subscription resolves into is recorded in the lockfile, and its range in
18
+ * the entry's own `range` field.
19
+ */
20
+ Config = "config",
21
+ /**
22
+ * An entry of a recipe manifest's `depends` or `subscribes` list. A bare ref
23
+ * names a recipe in the same repository; every locator and URL form names
24
+ * one in another repository. A `repo:` qualifier is refused, because it is
25
+ * one project's private name for a repository, and so is a local path.
26
+ */
27
+ Manifest = "manifest",
28
+ /**
29
+ * A key sous wrote itself: the lockfile, the index and the store. Only the
30
+ * canonical `namespace` or `namespace/recipe` is allowed.
31
+ */
32
+ Lockfile = "lockfile",
33
+ /**
34
+ * The path of a template include line, once its sigil is taken off. Only a
35
+ * file inside a recipe is allowed (`namespace/recipe/path`), and the path may
36
+ * be a glob.
37
+ */
38
+ Include = "include",
39
+ }
40
+
41
+ /** What each place is called in a sentence. */
42
+ export const SOURCE_LABELS: Record<RefSource, string> = {
43
+ [RefSource.CommandLine]: "on the command line",
44
+ [RefSource.Config]: "as a subscription key in a config file",
45
+ [RefSource.Manifest]: "in a recipe manifest's 'depends' or 'subscribes' list",
46
+ [RefSource.Lockfile]: "as a key sous stores",
47
+ [RefSource.Include]: "in an include line",
48
+ };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * The Inversify tokens of the ref services, in one place. A plugin adds a
3
+ * splitter, a pruner or a provider by binding one more value under the matching
4
+ * token; nothing else in the module needs to change.
5
+ */
6
+
7
+ /** Every token the ref services are bound under. */
8
+ export const REF_TOKENS = {
9
+ /** A `RefSplitter`; bound once per splitter, injected as a list. */
10
+ Splitter: Symbol.for("sous.ref.Splitter"),
11
+ /** A `RefPruner`; bound once per pruner, injected as a list. */
12
+ Pruner: Symbol.for("sous.ref.Pruner"),
13
+ /** A `RepoProvider`; bound once per provider, injected as a list. */
14
+ Provider: Symbol.for("sous.ref.Provider"),
15
+ /** A `HashName`; bound once per `#` name, injected as a list. */
16
+ HashName: Symbol.for("sous.ref.HashName"),
17
+ /** The `HashNameRegistry`. */
18
+ HashNames: Symbol.for("sous.ref.HashNames"),
19
+ /** The `RefParser`. */
20
+ Parser: Symbol.for("sous.ref.Parser"),
21
+ /** The `RefResolverService`. */
22
+ Resolver: Symbol.for("sous.ref.Resolver"),
23
+ /** The `RefPickerService`. */
24
+ Picker: Symbol.for("sous.ref.Picker"),
25
+ } as const;
@@ -0,0 +1,155 @@
1
+ /**
2
+ * What a ref is: plain data, never a class instance, so it survives a JSON
3
+ * round trip, can be compared structurally and can be extended by a plugin.
4
+ *
5
+ * A ref is a discriminated union on `kind`. Every kind with parents nests them:
6
+ * a recipe file carries its recipe, which carries its namespace, which carries
7
+ * the repository qualifier it was written with. A parent is optional wherever
8
+ * the written form may leave it out (a bare `task-files` is a recipe whose
9
+ * namespace is unknown), and a parent is a candidate of its own only when the
10
+ * written text could mean it.
11
+ *
12
+ * Globs are a flag on the ref (`glob`), not a kind of their own: a glob is a
13
+ * way of writing the name or path of a namespace, a recipe or a file, and the
14
+ * kind is what a lookup needs to know where to search. `glob` is true when any
15
+ * name or path part of the ref (a parent's included) is a pattern.
16
+ */
17
+
18
+ import type { ProviderId } from "../../lib/repos/providers/index.js";
19
+
20
+ /** Where a ref says a repository lives. */
21
+ export type RefLocation = {
22
+ /** The provider that reads the location. */
23
+ provider: ProviderId;
24
+ /** The host, such as `github.com`. */
25
+ host: string;
26
+ /** The repository's path on the host, such as `sous-io/sous-recipes`. */
27
+ repoPath: string;
28
+ /** The repository's canonical identity, as the store and the lockfile key it. */
29
+ identity: string;
30
+ /** The repository's HTTPS URL, which is what adding it is handed. */
31
+ url: string;
32
+ };
33
+
34
+ /** What every ref may carry. */
35
+ export type RefBase = {
36
+ /** True when any name or path part of the ref is a glob pattern. */
37
+ glob?: true;
38
+ /** The `?name=value` pairs the ref was written with, percent-decoded. */
39
+ vars?: Record<string, string>;
40
+ /**
41
+ * What the publisher says the thing is, in one line. Never read from written
42
+ * text; a lookup fills it in so a person choosing between matches can tell
43
+ * them apart.
44
+ */
45
+ description?: string;
46
+ };
47
+
48
+ /**
49
+ * A repository: named by the short name a project gave it, by where it lives,
50
+ * or both. As the parent of another ref it is the repository qualifier.
51
+ */
52
+ export type RepoRef = RefBase & {
53
+ kind: "repo";
54
+ /** The project's short name for the repository (may be a glob). */
55
+ name?: string;
56
+ /** Where the repository lives, when the ref said so. */
57
+ location?: RefLocation;
58
+ /** A branch or tag, once a lookup has told it apart from the path after it. */
59
+ revision?: string;
60
+ /**
61
+ * A folder or file path copied from a host's file view, branch still in
62
+ * front of it (`main/recipes/workflow/alpha`). Which recipe or namespace it
63
+ * is, and where the branch ends, only the repository's index can say.
64
+ */
65
+ browsed?: string;
66
+ /** The version range a browsed path was written with; it applies to the recipe it settles to. */
67
+ range?: string;
68
+ };
69
+
70
+ /** A namespace published by a repository. */
71
+ export type NamespaceRef = RefBase & {
72
+ kind: "namespace";
73
+ /** The namespace name (may be a glob). */
74
+ name: string;
75
+ /** The repository qualifier, when one was written. */
76
+ repo?: RepoRef;
77
+ /** True when the namespace was spelled out as `namespace/*`. */
78
+ wildcard?: true;
79
+ };
80
+
81
+ /** A recipe published in a namespace. */
82
+ export type RecipeRef = RefBase & {
83
+ kind: "recipe";
84
+ /** The recipe name (may be a glob). */
85
+ name: string;
86
+ /** The namespace, when the ref named it. */
87
+ namespace?: NamespaceRef;
88
+ /** The repository qualifier, set here only when there is no namespace to hold it. */
89
+ repo?: RepoRef;
90
+ /** The semantic version range, when one was given. */
91
+ range?: string;
92
+ };
93
+
94
+ /** A file inside a recipe. */
95
+ export type RecipeFileRef = RefBase & {
96
+ kind: "recipeFile";
97
+ /** The path inside the recipe, `/`-separated (may be a glob). */
98
+ path: string;
99
+ /** The recipe holding it. */
100
+ recipe: RecipeRef;
101
+ /** The semantic version range, when one was given. */
102
+ range?: string;
103
+ };
104
+
105
+ /** A variable a recipe declares, written `namespace/recipe.variableName`. */
106
+ export type VariableRef = RefBase & {
107
+ kind: "variable";
108
+ /** The variable's own name, as its author wrote it (may be a glob). */
109
+ name: string;
110
+ /** The recipe declaring it, when the ref named it. */
111
+ recipe?: RecipeRef;
112
+ /** The repository qualifier, set here only when there is no recipe to hold it. */
113
+ repo?: RepoRef;
114
+ };
115
+
116
+ /** An environment variable name, held whole: it is never split into scopes. */
117
+ export type EnvVarRef = RefBase & {
118
+ kind: "envVar";
119
+ /** The name, exactly as written. */
120
+ name: string;
121
+ /** The variables this name answers, once a lookup has said. */
122
+ variables?: VariableRef[];
123
+ };
124
+
125
+ /** Anything a written ref can name. */
126
+ export type SousRef =
127
+ | RepoRef
128
+ | NamespaceRef
129
+ | RecipeRef
130
+ | RecipeFileRef
131
+ | VariableRef
132
+ | EnvVarRef;
133
+
134
+ /** Every kind, in the order matches of equal specificity are listed in. */
135
+ export const REF_KINDS = [
136
+ "repo",
137
+ "namespace",
138
+ "recipe",
139
+ "recipeFile",
140
+ "variable",
141
+ "envVar",
142
+ ] as const;
143
+
144
+ /** One kind of ref. */
145
+ export type RefKind = (typeof REF_KINDS)[number];
146
+
147
+ /** What each kind is called in a sentence. */
148
+ export const KIND_LABELS: Record<RefKind, string> = {
149
+ repo: "repository",
150
+ namespace: "namespace",
151
+ recipe: "recipe",
152
+ recipeFile: "recipe file",
153
+ variable: "variable",
154
+ envVar: "environment variable",
155
+ };
@@ -3,7 +3,7 @@ import path from "node:path";
3
3
  import { Liquid, type FS } from "liquidjs";
4
4
  import filterRegistrars from "./filters/index.js";
5
5
  import tagRegistrars from "./tags/index.js";
6
- import { resolveInclude, type AliasMap } from "../lib/include-resolver.js";
6
+ import { resolveIncludeFiles, type AliasMap, type ViewMap } from "../lib/include-resolver.js";
7
7
  import {
8
8
  formatNamespaceProblem,
9
9
  type NamespaceResolver,
@@ -13,9 +13,11 @@ import {
13
13
  export type EngineAliasOptions = {
14
14
  /** Resolved alias map (name → ordered base dirs). */
15
15
  aliases?: AliasMap;
16
+ /** The files each view lists, so a render path may name `#memories/...`. */
17
+ views?: ViewMap;
16
18
  /** Variable scope for `${var}` substitution in render paths. */
17
19
  scope?: Record<string, string>;
18
- /** Resolver consulted for a `~namespace` first segment in a render path. */
20
+ /** Resolver consulted for a `~` recipe reference in a render path. */
19
21
  namespaceResolver?: NamespaceResolver;
20
22
  /**
21
23
  * Absolute path of the template being rendered, handed to the namespace
@@ -26,13 +28,14 @@ export type EngineAliasOptions = {
26
28
  };
27
29
 
28
30
  /**
29
- * A node-backed LiquidJS FS that additionally understands alias and namespace
30
- * render paths — `{% render "@~project/x.md" %}`, `{% render "@docs/y.md" %}`,
31
- * `{% render "@${var}/z.md" %}` and `{% render "~workflow/task-files/x.md" %}` —
32
- * resolving them through the same alias/namespace/var/relative candidate logic
33
- * as `@include`. The leading `@` is optional for a `~`-sigil path, since `~`
34
- * already marks the path as symbolic rather than relative. Every other path
35
- * uses standard root-based resolution.
31
+ * A node-backed LiquidJS FS that additionally understands alias, `#` name and
32
+ * recipe render paths: `{% render "#project/x.md" %}`, `{% render "@docs/y.md" %}`,
33
+ * `{% render "@${var}/z.md" %}` and `{% render "~workflow/task-files/x.md" %}`.
34
+ * They resolve through the same alias/`#`/recipe/var/relative candidate logic
35
+ * as `@include`, and a glob renders the first file it matches. The leading `@`
36
+ * is optional for a `~` or `#` path, since the sigil already marks the path as
37
+ * symbolic rather than relative. Every other path uses standard root-based
38
+ * resolution.
36
39
  *
37
40
  * @param opts - Alias map, variable scope, namespace resolver and including file.
38
41
  * @returns A LiquidJS FS implementation.
@@ -42,27 +45,31 @@ function createAliasFS(opts: EngineAliasOptions): FS {
42
45
  const scope = opts.scope ?? {};
43
46
 
44
47
  /**
45
- * Resolve an `@`-path or `~`-path to its first existing candidate, or the
46
- * first candidate. Returns null for ordinary paths so the caller falls back
47
- * to root-based resolution. Throws when a `~namespace` reference resolved to
48
- * nothing and the resolver explained why, so the reason reaches the user
48
+ * Resolve an `@`-path, `~`-path or `#`-path to its first existing file, or
49
+ * the first candidate. Returns null for ordinary paths so the caller falls
50
+ * back to root-based resolution. Throws when a `~` or `#` reference resolved
51
+ * to nothing and the resolver explained why, so the reason reaches the user
49
52
  * instead of a bare "file not found".
50
53
  */
51
54
  const resolveSymbolic = (file: string, dir: string): string | null => {
52
55
  const isAt = file.startsWith("@");
53
- if (!isAt && !file.startsWith("~")) return null;
56
+ if (!isAt && !file.startsWith("~") && !file.startsWith("#")) return null;
54
57
 
55
58
  const rawPath = isAt ? file.slice(1) : file;
56
- const { candidates, namespaceIssue } = resolveInclude(rawPath, {
59
+ const { files, candidates, namespaceIssue, hashIssue } = resolveIncludeFiles(rawPath, {
57
60
  aliases,
61
+ views: opts.views,
58
62
  scope,
59
63
  baseDir: dir,
60
64
  namespaceResolver: opts.namespaceResolver,
61
65
  fromFile: opts.fromFile ?? dir,
62
66
  });
63
67
 
64
- const existing = candidates.find((c) => fs.existsSync(c));
65
- if (existing) return existing;
68
+ if (files[0] !== undefined) return files[0];
69
+
70
+ if (hashIssue) {
71
+ throw new Error(`Cannot render "${file}"\n ${hashIssue.split("\n").join("\n ")}`);
72
+ }
66
73
 
67
74
  if (namespaceIssue) {
68
75
  throw new Error(
@@ -100,7 +107,7 @@ function createAliasFS(opts: EngineAliasOptions): FS {
100
107
  * @param roots - Filesystem root paths searched (in order) when resolving
101
108
  * `{% render %}` partials (relative paths resolve against these).
102
109
  * @param aliasOpts - Optional alias map, variable scope and namespace resolver,
103
- * enabling `@alias/...`, `@${var}/...` and `~namespace/...` paths in
110
+ * enabling `@alias/...`, `#name/...`, `@${var}/...` and `~namespace/...` paths in
104
111
  * `{% render %}` (parity with `@include`).
105
112
  */
106
113
  export function createLiquidEngine(roots: string[], aliasOpts: EngineAliasOptions = {}): Liquid {