@sous-io/sous 0.2.32 → 0.2.34

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 (111) hide show
  1. package/README.md +7 -6
  2. package/docs/markdown/_sidebar.md +1 -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-variables.md +16 -0
  10. package/docs/markdown/repositories.md +8 -4
  11. package/package.json +2 -1
  12. package/recipes/core/sous-skills/skills/about-liquid-templates/SKILL.tpl.md +33 -20
  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 +21 -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 +93 -15
  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 +289 -82
  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 +32 -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/answers.ts +9 -1
  55. package/src/lib/vars/ask.ts +3 -3
  56. package/src/lib/vars/display.ts +1 -3
  57. package/src/lib/vars/index.ts +1 -0
  58. package/src/lib/vars/mappings.ts +17 -9
  59. package/src/lib/vars/secrets.ts +131 -0
  60. package/src/services/ref-resolver/container.ts +107 -0
  61. package/src/services/ref-resolver/dependency.ts +60 -0
  62. package/src/services/ref-resolver/format.ts +197 -0
  63. package/src/services/ref-resolver/glob.ts +115 -0
  64. package/src/services/ref-resolver/hash-names.ts +155 -0
  65. package/src/services/ref-resolver/index.ts +55 -0
  66. package/src/services/ref-resolver/injectable.ts +36 -0
  67. package/src/services/ref-resolver/location.ts +62 -0
  68. package/src/services/ref-resolver/lookups/cached-index-lookup.ts +53 -0
  69. package/src/services/ref-resolver/lookups/catalog-lookup.ts +23 -0
  70. package/src/services/ref-resolver/lookups/catalog-matcher.ts +261 -0
  71. package/src/services/ref-resolver/lookups/chained-lookup.ts +27 -0
  72. package/src/services/ref-resolver/lookups/env-var-lookup.ts +65 -0
  73. package/src/services/ref-resolver/lookups/fetched-index-lookup.ts +150 -0
  74. package/src/services/ref-resolver/lookups/recorded-dependency-lookup.ts +62 -0
  75. package/src/services/ref-resolver/lookups/ref-lookup.ts +54 -0
  76. package/src/services/ref-resolver/lookups/variable-lookup.ts +123 -0
  77. package/src/services/ref-resolver/named-refs.ts +144 -0
  78. package/src/services/ref-resolver/parser/env-var-splitter.ts +27 -0
  79. package/src/services/ref-resolver/parser/location-splitter.ts +239 -0
  80. package/src/services/ref-resolver/parser/name-path-splitter.ts +200 -0
  81. package/src/services/ref-resolver/parser/partial-ref.ts +84 -0
  82. package/src/services/ref-resolver/parser/query-splitter.ts +61 -0
  83. package/src/services/ref-resolver/parser/range-splitter.ts +52 -0
  84. package/src/services/ref-resolver/parser/ref-parser.ts +115 -0
  85. package/src/services/ref-resolver/parser/repo-qualifier-splitter.ts +51 -0
  86. package/src/services/ref-resolver/parts.ts +115 -0
  87. package/src/services/ref-resolver/pruners/command-line-pruner.ts +47 -0
  88. package/src/services/ref-resolver/pruners/include-pruner.ts +66 -0
  89. package/src/services/ref-resolver/pruners/manifest-pruner.ts +130 -0
  90. package/src/services/ref-resolver/pruners/ref-pruner.ts +135 -0
  91. package/src/services/ref-resolver/pruners/rule-helpers.ts +44 -0
  92. package/src/services/ref-resolver/pruners/stored-key-pruner.ts +136 -0
  93. package/src/services/ref-resolver/ref-helpers.ts +62 -0
  94. package/src/services/ref-resolver/ref-picker-service.ts +204 -0
  95. package/src/{lib/repos/reference-report.ts → services/ref-resolver/ref-report.ts} +2 -40
  96. package/src/services/ref-resolver/ref-resolve-arguments.ts +47 -0
  97. package/src/services/ref-resolver/ref-resolve-result.ts +36 -0
  98. package/src/services/ref-resolver/ref-resolver-service.ts +323 -0
  99. package/src/services/ref-resolver/source.ts +48 -0
  100. package/src/services/ref-resolver/tokens.ts +25 -0
  101. package/src/services/ref-resolver/types.ts +155 -0
  102. package/src/templating/init-liquid-engine.ts +33 -18
  103. package/src/templating/lib/secret-scope.ts +41 -0
  104. package/src/templating/tags/exportScalarVarsJs.ts +5 -2
  105. package/src/templating/tags/showVars.ts +8 -2
  106. package/src/lib/refs/find.ts +0 -770
  107. package/src/lib/refs/index.ts +0 -14
  108. package/src/lib/refs/parse.ts +0 -844
  109. package/src/lib/refs/pick.ts +0 -147
  110. package/src/lib/refs/scopes.ts +0 -95
  111. 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,8 @@ 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 { setSecretNames } from "./lib/secret-scope.js";
7
+ import { resolveIncludeFiles, type AliasMap, type ViewMap } from "../lib/include-resolver.js";
7
8
  import {
8
9
  formatNamespaceProblem,
9
10
  type NamespaceResolver,
@@ -13,9 +14,11 @@ import {
13
14
  export type EngineAliasOptions = {
14
15
  /** Resolved alias map (name → ordered base dirs). */
15
16
  aliases?: AliasMap;
17
+ /** The files each view lists, so a render path may name `#memories/...`. */
18
+ views?: ViewMap;
16
19
  /** Variable scope for `${var}` substitution in render paths. */
17
20
  scope?: Record<string, string>;
18
- /** Resolver consulted for a `~namespace` first segment in a render path. */
21
+ /** Resolver consulted for a `~` recipe reference in a render path. */
19
22
  namespaceResolver?: NamespaceResolver;
20
23
  /**
21
24
  * Absolute path of the template being rendered, handed to the namespace
@@ -23,16 +26,23 @@ export type EngineAliasOptions = {
23
26
  * resolves them against, which is enough to locate the owning recipe.
24
27
  */
25
28
  fromFile?: string;
29
+ /**
30
+ * The variable names a recipe declared `secret: true`. `{% showVars %}` and
31
+ * `{% exportScalarVarsJs %}` hide them, along with anything that very probably
32
+ * is a secret.
33
+ */
34
+ secretVariables?: Iterable<string>;
26
35
  };
27
36
 
28
37
  /**
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.
38
+ * A node-backed LiquidJS FS that additionally understands alias, `#` name and
39
+ * recipe render paths: `{% render "#project/x.md" %}`, `{% render "@docs/y.md" %}`,
40
+ * `{% render "@${var}/z.md" %}` and `{% render "~workflow/task-files/x.md" %}`.
41
+ * They resolve through the same alias/`#`/recipe/var/relative candidate logic
42
+ * as `@include`, and a glob renders the first file it matches. The leading `@`
43
+ * is optional for a `~` or `#` path, since the sigil already marks the path as
44
+ * symbolic rather than relative. Every other path uses standard root-based
45
+ * resolution.
36
46
  *
37
47
  * @param opts - Alias map, variable scope, namespace resolver and including file.
38
48
  * @returns A LiquidJS FS implementation.
@@ -42,27 +52,31 @@ function createAliasFS(opts: EngineAliasOptions): FS {
42
52
  const scope = opts.scope ?? {};
43
53
 
44
54
  /**
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
55
+ * Resolve an `@`-path, `~`-path or `#`-path to its first existing file, or
56
+ * the first candidate. Returns null for ordinary paths so the caller falls
57
+ * back to root-based resolution. Throws when a `~` or `#` reference resolved
58
+ * to nothing and the resolver explained why, so the reason reaches the user
49
59
  * instead of a bare "file not found".
50
60
  */
51
61
  const resolveSymbolic = (file: string, dir: string): string | null => {
52
62
  const isAt = file.startsWith("@");
53
- if (!isAt && !file.startsWith("~")) return null;
63
+ if (!isAt && !file.startsWith("~") && !file.startsWith("#")) return null;
54
64
 
55
65
  const rawPath = isAt ? file.slice(1) : file;
56
- const { candidates, namespaceIssue } = resolveInclude(rawPath, {
66
+ const { files, candidates, namespaceIssue, hashIssue } = resolveIncludeFiles(rawPath, {
57
67
  aliases,
68
+ views: opts.views,
58
69
  scope,
59
70
  baseDir: dir,
60
71
  namespaceResolver: opts.namespaceResolver,
61
72
  fromFile: opts.fromFile ?? dir,
62
73
  });
63
74
 
64
- const existing = candidates.find((c) => fs.existsSync(c));
65
- if (existing) return existing;
75
+ if (files[0] !== undefined) return files[0];
76
+
77
+ if (hashIssue) {
78
+ throw new Error(`Cannot render "${file}"\n ${hashIssue.split("\n").join("\n ")}`);
79
+ }
66
80
 
67
81
  if (namespaceIssue) {
68
82
  throw new Error(
@@ -100,7 +114,7 @@ function createAliasFS(opts: EngineAliasOptions): FS {
100
114
  * @param roots - Filesystem root paths searched (in order) when resolving
101
115
  * `{% render %}` partials (relative paths resolve against these).
102
116
  * @param aliasOpts - Optional alias map, variable scope and namespace resolver,
103
- * enabling `@alias/...`, `@${var}/...` and `~namespace/...` paths in
117
+ * enabling `@alias/...`, `#name/...`, `@${var}/...` and `~namespace/...` paths in
104
118
  * `{% render %}` (parity with `@include`).
105
119
  */
106
120
  export function createLiquidEngine(roots: string[], aliasOpts: EngineAliasOptions = {}): Liquid {
@@ -120,5 +134,6 @@ export function createLiquidEngine(roots: string[], aliasOpts: EngineAliasOption
120
134
  register(engine);
121
135
  }
122
136
 
137
+ setSecretNames(engine, aliasOpts.secretVariables ?? []);
123
138
  return engine;
124
139
  }
@@ -0,0 +1,41 @@
1
+ import type { Liquid } from "liquidjs";
2
+ import { HIDDEN_VALUE, isSecretVariable } from "../../lib/vars/secrets.js";
3
+
4
+ /**
5
+ * The variable names each engine was told are secret. Kept beside the engine
6
+ * rather than in its scope, so the list itself never shows up in a dump.
7
+ */
8
+ const secretNamesByEngine = new WeakMap<Liquid, ReadonlySet<string>>();
9
+
10
+ /**
11
+ * Records the variable names a recipe declared `secret: true` for one engine.
12
+ *
13
+ * @param engine - The engine the tags render with.
14
+ * @param names - The declared names.
15
+ */
16
+ export function setSecretNames(engine: Liquid, names: Iterable<string>): void {
17
+ secretNamesByEngine.set(engine, new Set(names));
18
+ }
19
+
20
+ /**
21
+ * The declared secret names for an engine; empty when none were recorded.
22
+ *
23
+ * @param engine - The engine the tags render with.
24
+ */
25
+ export function secretNamesFor(engine: Liquid): ReadonlySet<string> {
26
+ return secretNamesByEngine.get(engine) ?? new Set();
27
+ }
28
+
29
+ /**
30
+ * Whether a scope entry is a secret a whole-scope dump must not print: a
31
+ * declared secret, or one the heuristic in `lib/vars/secrets.ts` recognizes.
32
+ *
33
+ * @param engine - The engine the tag renders with.
34
+ * @param name - The variable name.
35
+ * @param value - Its value.
36
+ */
37
+ export function isSecretEntry(engine: Liquid, name: string, value: unknown): boolean {
38
+ return isSecretVariable(name, value, secretNamesFor(engine));
39
+ }
40
+
41
+ export { HIDDEN_VALUE };
@@ -1,6 +1,7 @@
1
1
  import type { Liquid } from "liquidjs";
2
2
  import type { Context } from "liquidjs/dist/context/context.js";
3
3
  import { sortObjectKeys } from "../../utils/formatting.js";
4
+ import { isSecretEntry } from "../lib/secret-scope.js";
4
5
 
5
6
  /**
6
7
  * A "scalar" for export purposes: the value types that can be safely embedded
@@ -20,7 +21,9 @@ function isScalar(value: unknown): value is string | number | boolean {
20
21
  * Iterates every variable currently in the LiquidJS scope, keeps only scalars
21
22
  * (strings, finite numbers, booleans), sorts them by key, and emits a valid
22
23
  * `export default { ... };` block. Objects, arrays, functions, null, undefined,
23
- * and non-finite numbers are skipped.
24
+ * and non-finite numbers are skipped, and so is every secret (one a recipe
25
+ * declared, or one that very probably is): runtime code would read a masked
26
+ * value as a real one, so a secret is left out rather than hidden.
24
27
  *
25
28
  * Intended for compiling a `settings.tpl.mjs` that downstream runtime code
26
29
  * (e.g. browser automation scripts) imports for project configuration.
@@ -32,7 +35,7 @@ export function registerExportScalarVarsJsTag(engine: Liquid): void {
32
35
  const scalars: Record<string, string | number | boolean> = {};
33
36
 
34
37
  for (const [key, value] of Object.entries(scope)) {
35
- if (isScalar(value)) scalars[key] = value;
38
+ if (isScalar(value) && !isSecretEntry(engine, key, value)) scalars[key] = value;
36
39
  }
37
40
 
38
41
  const sorted = sortObjectKeys(scalars);
@@ -1,18 +1,24 @@
1
1
  import type { Liquid } from "liquidjs";
2
2
  import type { Context } from "liquidjs/dist/context/context.js";
3
3
  import { sortObjectKeys } from "../../utils/formatting.js";
4
+ import { HIDDEN_VALUE, isSecretEntry } from "../lib/secret-scope.js";
4
5
 
5
- /** Dumps all variables currently in scope as a fenced JSON block. */
6
+ /**
7
+ * Dumps all variables currently in scope as a fenced JSON block. A secret (one a
8
+ * recipe declared, or one that very probably is) prints as `(hidden)`, so the
9
+ * dump never carries it into compiled output.
10
+ */
6
11
  export function registerShowVarsTag(engine: Liquid): void {
7
12
  engine.registerTag("showVars", {
8
13
  render(ctx: Context) {
9
14
  const seen = new WeakSet();
10
15
  const scope = sortObjectKeys(ctx.getAll() as Record<string, unknown>);
11
- const json = JSON.stringify(scope, (_key, value) => {
16
+ const json = JSON.stringify(scope, (key, value) => {
12
17
  if (typeof value === "object" && value !== null) {
13
18
  if (seen.has(value)) return "[Circular]";
14
19
  seen.add(value);
15
20
  }
21
+ if (key !== "" && isSecretEntry(engine, key, value)) return HIDDEN_VALUE;
16
22
  return value;
17
23
  }, 2);
18
24