@sous-io/sous 1.0.19 → 1.1.1

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.
@@ -10,20 +10,25 @@ This page is about the config side only.
10
10
  Later scopes override earlier ones:
11
11
 
12
12
  ```
13
- auto-vars -> recipe answers -> _env scope -> _vars -> compilation._vars -> target._vars -> output._vars
13
+ auto-vars -> recipe answers -> _env scope -> _vars -> compilation._vars -> target._vars -> output._vars -> compilation.varOverrides
14
14
  ```
15
15
 
16
- `_vars` may be set at four levels, each inheriting the levels above it, inner values winning:
16
+ `_vars` may be set at four levels, each inheriting the levels above it, inner values winning, and
17
+ `compilation.varOverrides` lays the variables of every rule whose pattern matches an output's path
18
+ over all of them:
17
19
 
18
20
  ```text
19
21
  root _vars
20
22
  └── compilation._vars
21
23
  └── compilation.targets[]._vars
22
24
  └── targets[].outputs[]._vars
25
+ └── compilation.varOverrides[]._vars (each rule whose pattern matches the output's path)
23
26
  ```
24
27
 
25
28
  So a target var may reference a top-level var, and an output var may override both for that output
26
- only. A [config expression](configuration.md#config-expressions) sees the `_vars` of every level
29
+ only. A `varOverrides` rule wins even over the output's own `_vars`, so a project can change a
30
+ variable on outputs it did not write, such as the ones a plugin or a recipe adds; see
31
+ [Variables by output path](configuration.md#variables-by-output-path). A [config expression](configuration.md#config-expressions) sees the `_vars` of every level
27
32
  that contains it, and no others; an expression under `subscriptions`, `repos` or any other top-level
28
33
  key sees only the root `_vars`. Recipe outputs also get a scope per recipe, holding that recipe's
29
34
  answers (see [Recipe variables](repositories-variables.md)).
@@ -42,6 +47,34 @@ Always injected first, before `_env` and `_vars`:
42
47
  | `sousVersion` | the sous CLI version string |
43
48
  | `sousTemplatePath` | absolute path of the `.tpl.` file being rendered (render time only) |
44
49
  | `sousTemplateDir` | directory of the `.tpl.` file being rendered (render time only) |
50
+ | `sousOutputPath` | absolute path of the file the rendered result is written to (render time only) |
51
+ | `sousOutputDir` | directory of that file (render time only) |
52
+
53
+ `sousOutputPath` and `sousOutputDir` hold the path Sous planned to write. A transform (a function a
54
+ plugin attaches to an output) runs after rendering and may rename the file; the variables still
55
+ hold the path from before it. A file included into another file (a partial, or any `@` include)
56
+ renders as part of the file that includes it, so it sees the path of the output it is included
57
+ into. One source rendered to two outputs sees a different value in each:
58
+
59
+ ```liquid
60
+ {% if sousOutputPath contains "/.claude/" %}
61
+ Use the Skill tool.
62
+ {% endif %}
63
+ ```
64
+
65
+ Templates can also read two objects, which are not `${var}` variables:
66
+
67
+ | Value | What it holds |
68
+ |-------|---------------|
69
+ | `host.platform` | the operating system, as Node's `process.platform` names it (`linux`, `darwin`, `win32`): the same value [config expressions](configuration.md#config-expressions) read |
70
+ | `harness.id` | the harness the output belongs to (`claude-code`, `codex`), from the output's `harness`; an empty string for an output that belongs to none |
71
+
72
+ ```liquid
73
+ {% if host.platform == "win32" %}"C:\\Program Files\\Git\\bin\\bash.exe"{% else %}bash{% endif %}
74
+ ```
75
+
76
+ A variable of the same name that the project sets (an `_vars` entry named `host` or `harness`) wins
77
+ over these, so a template written before them keeps working.
45
78
 
46
79
  !> Sous sets `projectRoot`. Setting it in any `_vars` block is an error saying so. A config that
47
80
  wrote `projectRoot: "${sousDir}/.."` before 1.0 drops that line; every `${projectRoot}` keeps
@@ -94,6 +127,12 @@ and then lists the variables that ARE in scope. There is no silent fallthrough:
94
127
  similar action values additionally pass a strict substitution that fails on any leftover
95
128
  reference.
96
129
 
130
+ ## Writing a literal `${`
131
+
132
+ `$${name}` is the text `${name}`, never a variable: write it where a value must carry a placeholder another
133
+ tool fills in, such as `"bash \"$${CLAUDE_PLUGIN_ROOT}/x.sh\""`. An unknown name after `$${` is not an
134
+ error.
135
+
97
136
  ## Path normalization
98
137
 
99
138
  Absolute `entryPoint`, `entryGlob`, `globBase`, `destinationFile` and `destinationDir` values
@@ -8,7 +8,9 @@ user-level config (nothing is read from `~/.sous`) and no multi-project map.
8
8
 
9
9
  Exactly one primary config lives inside `.sous/`: `sous.config.js`, `sous.config.mjs`,
10
10
  `sous.config.ts`, `sous.config.json`, `sous.config.jsonc`, or `sous.config.yaml`. Two or more candidates is an
11
- error, never a silent first-match. A typical config:
11
+ error, never a silent first-match. `sous init` writes `sous.config.jsonc`: JSON with comments, which
12
+ `sous config set` can change in place, keeping the comments, as it cannot a code config. A config
13
+ written by hand may use any of the formats. A typical config, as JavaScript:
12
14
 
13
15
  ```js
14
16
  export const config = {
@@ -32,7 +34,7 @@ export const config = {
32
34
  ],
33
35
  },
34
36
  tools: {
35
- claude: { command: "claude", promptFile: "${projectRoot}/CLAUDE.md" },
37
+ "claude-code": { command: "claude", args: ["--model", "opus"] },
36
38
  },
37
39
  };
38
40
  ```
@@ -46,10 +48,52 @@ need no target of their own: the built-in Claude Code plugin sends them to `.cla
46
48
  [Consuming recipes](repositories-consuming.md)).
47
49
 
48
50
  A target in your config wins over a plugin's or a recipe's target that would write the same file. A
49
- project that compiles its own `CLAUDE.md`, as the config `sous init` writes does, replaces the one the
50
- Claude Code plugin would build from recipe memories. A project skill with the same name as a recipe skill
51
+ project that compiles its own memories file replaces the one the Claude Code plugin would build; the
52
+ config `sous init` writes compiles none, and leaves the memories to the plugin. A project skill with the same name as a recipe skill
51
53
  replaces it too, and the build warns that the recipe's copy was not written.
52
54
 
55
+ ### The memories file
56
+
57
+ Each coding tool's plugin compiles one memories file, the file that tool reads into every session.
58
+ For Claude Code it is `.claude/rules/SOUS-MEMORIES.md`, which Claude Code loads beside any `CLAUDE.md`
59
+ the project has, so Sous never writes over the project's own instructions. Its source is
60
+ `.sous/MEMORIES.tpl.md` when that file exists (`sous init` creates it). Otherwise the source is
61
+ these two lines, read as if they were written in a file inside `.sous/`:
62
+
63
+ ```markdown
64
+ @memories/**/*.md
65
+ @#memories/**/*.md
66
+ ```
67
+
68
+ The first line includes the project's own files under `.sous/memories/`, the second the memories of
69
+ every recipe the project subscribes to. Remove a line to leave that part out; move a line to change
70
+ the order. When the result is empty, no file is written, and a copy an earlier build wrote is
71
+ removed. Sous creates the `.claude/rules/` folder.
72
+
73
+ The Claude Code plugin's options move the file or switch it off:
74
+
75
+ ```jsonc
76
+ {
77
+ "plugins": {
78
+ "options": {
79
+ "@sous-io/sous-plugin-claude-code": {
80
+ // Where the memories file goes. Default: ${projectRoot}/.claude/rules/SOUS-MEMORIES.md
81
+ "memoriesOutputPath": "${projectRoot}/CLAUDE.md",
82
+ // false writes no memories file for Claude Code at all.
83
+ "memories": true
84
+ }
85
+ }
86
+ }
87
+ }
88
+ ```
89
+
90
+ A file Sous did not write that is already at `memoriesOutputPath` is backed up to `.sous/backups/`,
91
+ with a warning, and replaced.
92
+
93
+ ?> Before version 1.1.0 the recipes' memories went into the root `CLAUDE.md`. A project upgraded
94
+ from then is asked once, by `sous doctor` or `sous upgrade`, whether to move them to the new file
95
+ (the default) or keep them in `CLAUDE.md` (`--answer claude-code.memories=keep`).
96
+
53
97
  A JSON config may set `"$schema"` to bind the `sous.config.schema.json` artifact shipped with
54
98
  sous for editor autocompletion; sous accepts and ignores the key.
55
99
 
@@ -65,26 +109,152 @@ without it is never rendered, however much it looks like a template, even when a
65
109
  convention applies to `entryPoint` and `entryGlob` targets alike, and to the files a recipe brings into your
66
110
  project.
67
111
 
112
+ A file that is not a template and includes nothing is copied byte for byte, so an image or any other binary
113
+ file reaches the project unchanged. A source file that is executable gives an executable output, templated or
114
+ not (`probe-info.tpl.py` as well as `run.sh`).
115
+
116
+ ## Outputs and the files a build writes
117
+
118
+ Each output of a target writes one file per source: `destinationFile` names it, or `destinationDir` mirrors
119
+ the source's path under the glob's base (or `globBase`) inside it. An output may also say which harness it
120
+ belongs to, with `harness` (`"claude-code"`, `"codex"`); a template reads it as `harness.id`. The plugins that
121
+ write a harness's skills and memories set it.
122
+
123
+ Sous lists every file a build writes while it builds the config, matching each `entryGlob` against the disk
124
+ then, and keeps the list under `compilation.files`, one entry per output of each source. The compiler writes
125
+ exactly what that list holds, so `sous config get compilation.files` shows what a build will write, and
126
+ `--layers` names the `compiler.files` contributor that listed them:
127
+
128
+ ```jsonc
129
+ // sous config get compilation.files (excerpt)
130
+ [
131
+ {
132
+ "target": "1",
133
+ "targetIndex": 1,
134
+ "source": "/home/me/app/prompts/skills/review/SKILL.tpl.md",
135
+ "output": 0,
136
+ "destination": "/home/me/app/.claude/skills/review/SKILL.md"
137
+ }
138
+ ]
139
+ ```
140
+
141
+ Sous sets `compilation.files` and `compilation.listing` (what went wrong listing them, such as a glob that
142
+ matched nothing, reported when a build runs); anything written there in a config file is replaced. A file
143
+ added or removed under a glob target's folder is picked up by the next command, and `sous build --watch`
144
+ rebuilds the config when it sees one.
145
+
146
+ To write an output only under a condition, put a [config expression](#config-expressions) on the output
147
+ itself. The output setting `_if` was removed; a config that still uses it is refused with the `$if` to write
148
+ instead. `sous doctor` (and `sous upgrade`) runs a migration that rewrites it for you in a `.json`, `.jsonc` or
149
+ `.yaml` config file, changing only that output; for a config written as JavaScript or TypeScript it lists each
150
+ `_if` with its line and the expression to write. An `_if` on a variable named `env` or `host` is left for you,
151
+ since an expression reads those names as sous's own values:
152
+
153
+ ```jsonc
154
+ "outputs": [
155
+ {
156
+ "$if": {
157
+ "expr": "stage == 'prod'",
158
+ "then": { "destinationFile": "${projectRoot}/prod.md" }
159
+ }
160
+ }
161
+ ]
162
+ ```
163
+
164
+ ### Variables by output path
165
+
166
+ `compilation.varOverrides` sets variables for every output whose path matches a pattern, including outputs a
167
+ plugin or a recipe adds. Each rule has `match`, an optional `exclude`, and `_vars`. `match` and `exclude` each
168
+ take one entry or a list, and an entry is a glob, or a regular expression when written between two slashes
169
+ (the convention `recipes.memories.first` uses):
170
+
171
+ ```js
172
+ compilation: {
173
+ varOverrides: [
174
+ {
175
+ match: "${projectRoot}/.claude/**",
176
+ exclude: [
177
+ "${projectRoot}/.claude/desktop.md",
178
+ "/\\.local\\./",
179
+ ],
180
+ _vars: { tool: "claude" },
181
+ },
182
+ {
183
+ match: "${projectRoot}/.codex/**",
184
+ _vars: { tool: "codex" },
185
+ },
186
+ ],
187
+ },
188
+ ```
189
+
190
+ - A rule's variables win over the output's own `_vars`, so a project can change a variable on outputs it did
191
+ not write.
192
+ - When several rules match one output, a later rule wins for a variable both set; a variable only one rule
193
+ sets is kept. Your own config files apply after plugins and recipes, so your rules win over theirs.
194
+ - A rule matches the path Sous planned to write. A transform (a function a plugin attaches to an output) runs
195
+ after rendering and may rename the file; the rule still matched the path from before it.
196
+ - A glob is matched against the absolute path, and a relative one is relative to the project root. A regular
197
+ expression is tested against the absolute path, written with `/`.
198
+
199
+ The variables a rule set show on each matching entry of `compilation.files`, as its `_vars`.
200
+
68
201
  ## Include syntax
69
202
 
70
- A line holding only `@path` includes that file's content. A path may be:
203
+ Sous reads `@path` the way Claude Code reads an import, and puts the file's text where the name stands. An
204
+ `@path` counts anywhere in a line of Markdown text when the `@` starts the line or follows a space:
205
+
206
+ ```markdown
207
+ @sections/context.md
208
+ - @sections/rules.md
209
+ See @docs/guide.md for details.
210
+ ```
211
+
212
+ A name alone on a line is replaced by the file's whole text. A name inside a line is replaced by the file's text
213
+ with its leading and trailing whitespace trimmed, so `See @docs/guide.md for details.` reads as one sentence.
214
+
215
+ A plain path may be:
216
+
217
+ - relative to the including file (`@sections/context.md`, `@../shared/rules.md`);
218
+ - home-relative (`@~/notes/private.md`) or absolute (`@/srv/notes.md`);
219
+ - an alias from `_aliases`, by its first segment (`@myAlias/doc.md`).
220
+
221
+ The path ends at the first space (write `@my\ file.md` for a space in a name) and at the first `#`
222
+ (`@guide.md#setup` includes `guide.md`). Punctuation right after it is part of the path, so `see @guide.md.` names
223
+ a file called `guide.md.`, which does not exist. The file may be of any text type Claude Code imports (`.md`,
224
+ `.txt`, `.json`, `.yaml`, `.sh`, `.py` and about a hundred more, in any case) or have no extension (`@README`).
225
+
226
+ **A plain path that names no file is left as written, with no message**, as Claude Code does, so a mention such as
227
+ `@alice` or `@scope/package` stays text. A typo in a file name therefore does not fail the build; the text simply
228
+ does not appear.
229
+
230
+ Sous's own forms count only on a line that holds nothing else, and are checked before the plain path:
71
231
 
72
- - relative to the including file (`@sections/context.md`);
73
232
  - `${var}` substituted (`@${projectRoot}/prompts/x.md`);
74
- - home-relative (`@~/notes/private.md`);
75
- - an alias from `_aliases`, by its first segment (`@myAlias/doc.md`);
76
233
  - a name sous or a plugin registers, written with the `#` sigil: `#project` is the project root
77
234
  (`@#project/prompts/intro.md`);
78
235
  - a recipe file, written with the `~` sigil and the recipe's namespace (`@~workflow/task-files/_partials/resume.md`);
79
236
  - a view: `@#memories/**/*.md` includes every active recipe's memories (see
80
- [Recipe memories](repositories-consuming.md#recipe-memories)).
81
-
82
- A path may use glob syntax (`*`, `**`, `?`, `[..]`, `{a,b}`) and then includes every file it matches, in bytewise
83
- path order. The same file may be included in more than one place; a circular include is an error, as is a line
84
- that looks like an include (`@docs/notes.txt`, `@~workflow/missing`) but cannot be resolved, which fails the
85
- build naming the file and the line. A line inside a fenced code block is left as written. An alias name may not
86
- start with `~` or `#`. [Including recipe files in your own templates](repositories.md#including-recipe-files-in-your-own-templates)
87
- has the namespace rules.
237
+ [Recipe memories](repositories-consuming.md#recipe-memories));
238
+ - glob syntax (`*`, `**`, `?`, `[..]`, `{a,b}`), which includes every text file it matches;
239
+ - a `?name=value` query after the path (`@part.md?mood=calm`).
240
+
241
+ One of these forms that cannot be resolved fails the build, naming the file and the line. A glob that matches
242
+ nothing does nothing: its line is removed from the output, with no message. A glob's files come in this order: at
243
+ each folder its own files first, then its sub-folders, with the same rule inside each; names are compared one
244
+ character at a time ignoring case, with `_` before every other character and digits before letters, so
245
+ `_intro.md`, `0002-setup.md`, `0010-setup.md`, `10-setup.md`, `2-setup.md`, `apple.md`, `Zebra.md`, then
246
+ `api/routes.md`.
247
+
248
+ The frontmatter of every included file is removed; the including file keeps its own. The same file may be
249
+ included in more than one place; a circular include is an error. An alias name may not start with `~` or `#`.
250
+ [Including recipe files in your own templates](repositories.md#including-recipe-files-in-your-own-templates) has
251
+ the namespace rules.
252
+
253
+ To write an `@path` as text, escape it the way you would for Claude Code: put it in backticks (`` `@docs/x.md` ``)
254
+ or put a backslash before the `@` (`\@docs/x.md`). Sous also leaves alone a name in a fenced or indented code
255
+ block, an HTML block or comment, the frontmatter at the top of the file, a link's destination or an image's text,
256
+ and an `@` that follows anything but a space (`(@x.md)`, `"@x.md"`, `name@x.md`). Sous does not escape text it
257
+ leaves in its output: a name Sous left as text is read again by Claude Code, from the output file's folder.
88
258
 
89
259
  ## Composition
90
260
 
@@ -99,10 +269,11 @@ the full semantics.
99
269
  ## Config expressions
100
270
 
101
271
  A value in a JSON, JSONC or YAML config file may be an expression object, decided when sous builds
102
- the config instead of when the file is written. The reserved keys are `$expr`, `$if`, `$elseif` and
103
- `$else` (each `$if` and `$elseif` may carry a `:<name>` qualifier, and `$expr` a `:<language>` one).
104
- Liquid is the expression language. An expression can read `host.platform`, `env.<NAME>`, variables
105
- by their bare name, and recipe answers (except under `subscriptions` and `repos`).
272
+ the config instead of when the file is written. The reserved keys are `$expr`, `$if`, `$elseif`,
273
+ `$else` and `$file` (each `$if` and `$elseif` may carry a `:<name>` qualifier, and `$expr` a `:<language>` one).
274
+ Liquid is the expression language. An expression can read `host.platform`, `harness.id`,
275
+ `env.<NAME>`, variables by their bare name, and recipe answers (except under `subscriptions` and
276
+ `repos`).
106
277
 
107
278
  A subscription switched off on a Mac only:
108
279
 
@@ -128,6 +299,82 @@ arrays. An object mixing a reserved key with any other key is an error, so a typ
128
299
  never passes through as config. The full rules are in
129
300
  [the design of config expressions](architecture/specifications/S5-config-expressions.md).
130
301
 
302
+ ### Conditions on the harness
303
+
304
+ A "harness" is a coding tool sous writes files for, such as Claude Code or Codex; each one is
305
+ registered by the plugin that knows it. Sous builds the config once with no harness, then once more
306
+ for every registered harness. `harness.id` is the harness of the build: `""` (the empty string) in
307
+ the build with no harness, and the harness's id in its own build. It is never `undefined`, so a
308
+ condition on it never fails as an unknown variable.
309
+
310
+ The config every command reads is the build with no harness, plus what belongs to each harness taken
311
+ from that harness's build:
312
+
313
+ - a compilation output marked with a harness (`"harness": "codex"`) comes from that harness's build,
314
+ with the `_vars` written on it;
315
+ - a compilation target whose outputs are all marked with one harness comes whole from that
316
+ harness's build, so a memory a condition gives one harness reaches that harness's memories file;
317
+ - a compilation target only a harness's build holds (a condition on `harness.id` left it out of the
318
+ build with no harness, such as a recipe's skills folder excluded for every other harness) is
319
+ added after the other targets, with only its outputs marked with that harness; a target with no
320
+ such output is left out;
321
+ - an entry of `editor.edits` or `recipes.contents` that only a harness's build holds (a condition on
322
+ `harness.id` put it there) is added, marked with that harness;
323
+ - everything else keeps the value of the build with no harness.
324
+
325
+ So a condition on `harness.id` takes effect in the merged config only for those lists. A setting
326
+ such as this one is `true` only in the `codex` build, which plugins acting for Codex can read, while
327
+ the merged config keeps `false`:
328
+
329
+ ```jsonc
330
+ {
331
+ "compilation": {
332
+ "includeSourceComments": { "$if": "harness.id == 'codex'" }
333
+ }
334
+ }
335
+ ```
336
+
337
+ `sous config show --harness codex` prints the `codex` build itself. With no harness registered,
338
+ sous builds the config once, as before. The design is in
339
+ [One config build per harness](architecture/specifications/S8-per-harness-config-builds.md).
340
+
341
+ ### Values from a file: `$file`
342
+
343
+ An object whose only key is `$file` stands in for the value a file holds, anywhere a value may go:
344
+
345
+ ```jsonc
346
+ // conf.d/700-rules.jsonc
347
+ {
348
+ "_vars": {
349
+ "banner": { "$file": "banner.txt" }
350
+ },
351
+ "recipes": {
352
+ "skills": {
353
+ "outputs": { "$file": "${projectRoot}/shared/skill-outputs.json" }
354
+ }
355
+ }
356
+ }
357
+ ```
358
+
359
+ The path is relative to the file that holds it, and `${name}` variables in it are filled in. A `.json`,
360
+ `.jsonc`, `.yaml` or `.yml` file gives its structured value; any other file gives its text. A file whose name
361
+ contains `.tpl.` is rendered as a Liquid template first; no other file's content is interpolated, so
362
+ `${CLAUDE_PLUGIN_ROOT}` in it arrives as it is written. Watch mode rebuilds when the file changes.
363
+
364
+ ### Writing a literal `${`
365
+
366
+ Write `$${name}` where a value must hold the text `${name}` for another tool to fill in:
367
+
368
+ ```jsonc
369
+ {
370
+ "_vars": {
371
+ "startHook": "bash \"$${CLAUDE_PLUGIN_ROOT}/scripts/start.sh\""
372
+ }
373
+ }
374
+ ```
375
+
376
+ `${startHook}` gives `bash "${CLAUDE_PLUGIN_ROOT}/scripts/start.sh"`.
377
+
131
378
  ## Plugins
132
379
 
133
380
  Sous is a small engine plus plugins; the CLI, recipes, the compiler, skills, memories, Claude Code
@@ -153,14 +400,21 @@ There is no separate bootstrap config and no `"sous"` key in `package.json`.
153
400
  "sous-plugin-old-thing"
154
401
  ],
155
402
  "options": {
156
- "sous-plugin-claude-code": {
157
- "model": "opus"
403
+ "@sous-io/sous-plugin-claude-code": {
404
+ "memoriesOutputPath": "${projectRoot}/CLAUDE.md"
158
405
  }
159
406
  }
160
407
  }
161
408
  }
162
409
  ```
163
410
 
411
+ ?> Before version 1.1.0 the built-in plugins were named `@sous-io/plugin-<name>`, such as
412
+ `@sous-io/plugin-claude-code`; they are now `@sous-io/sous-plugin-<name>`. A config that still uses the old
413
+ name under `plugins.options`, `plugins.disabled`, `services.replace` or `intents.replace` keeps working, and
414
+ the new name wins when both are written. The package plugins are written against moved too, from
415
+ `@sous-io/plugin-api` to `@sous-io/sous-plugin-api`; a plugin that still imports the old name keeps working
416
+ with the copy it installed.
417
+
164
418
  Two more keys settle what plugins do:
165
419
 
166
420
  - `services.replace` picks the winner when two plugins both take over the same piece of sous's
@@ -9,7 +9,7 @@ When a coding tool can do something natively, do it natively; sous exists for wh
9
9
  cannot do. Sous never wraps, replaces, or re-implements a capability an agent harness already
10
10
  provides well.
11
11
 
12
- *Example: sous compiles `CLAUDE.md` and skill files because no harness composes them from
12
+ *Example: sous compiles a memories file (`.claude/rules/SOUS-MEMORIES.md` for Claude Code) and skill files because no harness composes them from
13
13
  shared, templated sources; it does not try to replace how the harness loads them.*
14
14
 
15
15
  ## 2. Fill the collective gaps