@sous-io/sous 1.0.18 → 1.1.0

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.
@@ -0,0 +1,221 @@
1
+ # Handlers
2
+
3
+ A handler is a function a recipe or a sous plugin provides for a purpose: checking that the commands a
4
+ recipe's scripts call are installed, cleaning up when the recipe is removed, bringing a project in line
5
+ after the recipe moves to a new version. Each handler receives sous's tools, reports what it finds, and
6
+ never prints; the command you ran prints what it reported.
7
+
8
+ ## The purposes
9
+
10
+ | Purpose | When it runs | What it is for |
11
+ |---|---|---|
12
+ | `check` | On subscribing, and on each build | Prerequisites: commands, versions, sign-in. An `error` fails the build before anything is written; a `warn` does not |
13
+ | `configure` | While the config is built | Adding config from code, such as declared document edits, without writing a whole plugin |
14
+ | `beforeBuild`, `afterBuild` | Around the build | Work that is an action, not a standing state |
15
+ | `uninstall` | Before a recipe is removed through sous (`sous subscription remove`) | Undoing what its own code did |
16
+ | `migrate` | After the recipe moves to a new version in a project | Bringing the project in line with the new version; it is given `{ from, to }` |
17
+
18
+ The set is fixed for now. Each purpose takes a list, and the handlers run in a predictable order: a
19
+ recipe's in the order its manifest lists them, recipes in the lockfile's order; a plugin's in the order
20
+ it registered them, plugins in the order they loaded. Plugins' handlers run before recipes'.
21
+
22
+ ### Where they run in a build
23
+
24
+ `sous build` runs, in this order: the `check` handlers; the `beforeBuild` handlers; the compiler and its
25
+ prune; the declared edits to files sous does not own, with their assertions; the `afterBuild` handlers. A
26
+ `check` error stops the build there, before anything in the project is written, and the build ends with exit
27
+ code 1, naming each handler that failed. A compile error skips the edits and `afterBuild`.
28
+
29
+ `sous build --dry-run` runs the `check` handlers, which only report, and no `beforeBuild` or `afterBuild`
30
+ handler, which act. Watch mode runs them on every rebuild. `sous prune` runs none. `sous doctor` runs the
31
+ `check` handlers too, and reports their errors and warnings without building.
32
+
33
+ ?> To build past failed checks, pass `--ignore-failed-checks` (or `--keep-going`, which also covers
34
+ failed assertions). The failures are still printed, as warnings, and the build ends as successful. There is no
35
+ setting that makes this permanent.
36
+
37
+ ## In a recipe
38
+
39
+ A recipe lists its handlers under `handlers` in `sous.recipe.yaml`. Each entry names a file in the recipe
40
+ and the function it exports:
41
+
42
+ ```yaml
43
+ formatVersion: 1
44
+ namespace: voltagrid
45
+ name: knowledge-worker
46
+ version: 1.0.0
47
+
48
+ handlers:
49
+ check:
50
+ - file: handlers/prerequisites.js
51
+ handler: checkCommands
52
+ - file: handlers/prerequisites.js
53
+ handler: checkJiraSignIn
54
+
55
+ configure:
56
+ - file: handlers/edits.js
57
+ handler: declareEdits
58
+
59
+ uninstall:
60
+ - file: handlers/cleanup.js
61
+ handler: removeSessionFiles
62
+ ```
63
+
64
+ A handler file. Each handler is an exported function that receives sous's tools:
65
+
66
+ ```js
67
+ /** Reports the commands the knowledge worker needs. */
68
+ export async function checkCommands(sous) {
69
+ for (const command of ["git", "jq"]) {
70
+ if (!(await sous.utils.system.isAppAvailable(command))) {
71
+ sous.report.error(`${command} is not installed. The knowledge worker's hooks cannot run without it.`);
72
+ }
73
+ }
74
+
75
+ for (const command of ["pandoc", "curl", "jira"]) {
76
+ if (!(await sous.utils.system.isAppAvailable(command))) {
77
+ sous.report.warn(`${command} is not installed. Some knowledge worker scripts will not work.`);
78
+ }
79
+ }
80
+ }
81
+
82
+ /** Warns when the jira command is installed but not signed in. */
83
+ export async function checkJiraSignIn(sous) {
84
+ if (!(await sous.utils.system.isAppAvailable("jira"))) {
85
+ return;
86
+ }
87
+
88
+ const result = await sous.utils.process.run("jira", ["me"]);
89
+
90
+ if (result.exitCode !== 0) {
91
+ sous.report.warn("The jira command is not signed in. Run `jira init`.");
92
+ }
93
+ }
94
+ ```
95
+
96
+ The rules for a recipe's handlers:
97
+
98
+ - **Trust.** A handler is code, so it runs only from a repository the project trusts, as a recipe's
99
+ plugin does. Nothing inside a repository runs before it is trusted.
100
+ - **One self-contained file each.** sous never runs `npm install` for a recipe, so a handler file cannot
101
+ import packages. Bundle anything it needs into the file.
102
+ - **Only subscribed recipes.** A recipe held only through `depends` is a library and contributes no
103
+ handlers.
104
+ - **A plugin a recipe ships is covered by the recipe's handlers**, `migrate` included: it changes only when
105
+ the recipe's version does.
106
+
107
+ ### `configure` and `migrate` handlers
108
+
109
+ A `configure` handler runs while the config is built, as a contributor sous registers on the recipe's
110
+ behalf. It receives the config builder as `config`, and what it adds is undone when the recipe stops
111
+ listing it:
112
+
113
+ ```js
114
+ /** Declares the edits this recipe needs. */
115
+ export function declareEdits(sous, { config }) {
116
+ config.atPath("editor.edits").append({
117
+ file: ".claude/settings.json",
118
+ ensureIncludes: { path: "permissions.allow", items: ["Bash(git-commit.sh:*)"] },
119
+ });
120
+ }
121
+ ```
122
+
123
+ While the config is built there is no finished config yet: `sous.config.get` reads the config built so
124
+ far, and `sous.editor.file` is not available (declare the edit instead).
125
+
126
+ A `migrate` handler runs after the recipe moves to a new version in a project (`sous subscription update`,
127
+ a subscription that always pulls, or subscribing again at another version), once the new version's files
128
+ are in place. It is given the old and the new version, and is called once per version change:
129
+
130
+ ```js
131
+ /** Runs after this recipe moves to a new version in a project. */
132
+ export async function migrate(sous, { from, to }) {
133
+ if (from.startsWith("1.") && to.startsWith("2.")) {
134
+ // Bring the project in line with version 2.
135
+ }
136
+ }
137
+ ```
138
+
139
+ ## In a plugin for sous
140
+
141
+ A plugin registers the same functions inside `register`, with `sous.handlers.add`. Each handler a
142
+ plugin registers has an `id`, which names it when sous times it or reports it as slow or failing:
143
+
144
+ ```ts
145
+ import { definePlugin } from "@sous-io/sous-plugin-api";
146
+
147
+ /** Reports the commands the knowledge worker needs. */
148
+ async function checkCommands(sous) {
149
+ for (const command of ["git", "jq"]) {
150
+ if (!(await sous.utils.system.isAppAvailable(command))) {
151
+ sous.report.error(`${command} is not installed. The knowledge worker's hooks cannot run without it.`);
152
+ }
153
+ }
154
+
155
+ for (const command of ["pandoc", "curl", "jira"]) {
156
+ if (!(await sous.utils.system.isAppAvailable(command))) {
157
+ sous.report.warn(`${command} is not installed. Some knowledge worker scripts will not work.`);
158
+ }
159
+ }
160
+ }
161
+
162
+ /** Removes the per-session files the hooks wrote. */
163
+ async function removeSessionFiles(sous) {
164
+ await sous.utils.files.removeMatching("docs/context/.kw-session-*");
165
+ }
166
+
167
+ export default definePlugin({
168
+ name: "sous-plugin-knowledge-worker",
169
+ version: "1.0.0",
170
+ description: "Example: registers handlers for three purposes.",
171
+
172
+ register(sous) {
173
+ // The "configure" purpose. This is the call plugins already use.
174
+ sous.config.contribute(editsContributor);
175
+
176
+ // The "check" purpose.
177
+ sous.handlers.add("check", {
178
+ id: "knowledge-worker/commands",
179
+ handle: checkCommands,
180
+ });
181
+
182
+ // The "uninstall" purpose.
183
+ sous.handlers.add("uninstall", {
184
+ id: "knowledge-worker/session-files",
185
+ handle: removeSessionFiles,
186
+ });
187
+ },
188
+ });
189
+ ```
190
+
191
+ The handler functions are identical either way: the same function body works whether a manifest points at
192
+ it or a plugin registers it. A plugin may also pass `order` (a number, default `500`; lower runs earlier).
193
+ A recipe's handlers are named `<namespace>/<recipe>/<purpose>/<function>`, such as
194
+ `voltagrid/knowledge-worker/check/checkCommands`.
195
+
196
+ `uninstall` runs only when the recipe or plugin is removed through sous. Removing a plugin by hand (with
197
+ `npm uninstall`, or by deleting a line from the config) is the manual path, and sous does not clean up
198
+ after it. Plugins installed from npm get no `migrate` call yet.
199
+
200
+ ## What a handler receives
201
+
202
+ A handler receives everything a plugin's code receives (every service, the finished config, the
203
+ project's folder, the reporter, `run` for starting another intent), plus these helpers:
204
+
205
+ | Helper | What it does |
206
+ |---|---|
207
+ | `sous.report.error(...)`, `.warn(...)`, `.info(...)` | Report a result. The command prints it |
208
+ | `sous.utils.system.isAppAvailable(name)` | Whether a command is installed: found on `PATH` (with `PATHEXT` on Windows) |
209
+ | `sous.utils.system.appVersion(name)` | Its version, from `<name> --version`, when it can be read |
210
+ | `sous.utils.process.run(command, args)` | Run a command in the project's folder and get its `exitCode`, `stdout` and `stderr`; a missing command exits 127 |
211
+ | `sous.utils.file.exists(path)`, `.read(path)`, `.remove(path)` | Work with ONE file in the project; `read` gives `undefined` for a missing file, `remove` says whether there was one |
212
+ | `sous.utils.files.removeMatching(pattern)` | Remove every file matching a glob pattern, dot files included, and get the paths removed |
213
+ | `sous.editor.file(path)` | Edit a document directly, with the same operations as a declared edit (needs the editor plugin) |
214
+ | `sous.project.root` | The project's folder |
215
+ | `sous.config.get(path)` | Read a value from the finished config |
216
+ | `sous.vars.get(name)` | Read a recipe variable's answer; a recipe's handler sees it as that recipe does |
217
+
218
+ Paths are relative to the project's folder. Each answer of `isAppAvailable` and `appVersion` is looked
219
+ up once per run, however many handlers ask.
220
+
221
+ A handler that throws is reported as an error naming it, and the handlers after it still run.
@@ -4,9 +4,11 @@ The guide to publishing recipes of your own: creating a repository, writing a re
4
4
  needs, cutting a release, editing a published repository in place, and proposing a change to somebody else's.
5
5
  [Repository file formats](repositories-file-formats.md) holds the schemas; this page is the workflow.
6
6
 
7
- ?> A recipe repository is not a sous project. It has no `.sous/` directory, and `sous repo init` and `sous repo
8
- release` do not look for one. Run them from inside the repository itself. `sous repo submit` runs there too, and
9
- may also be run from a project that links the repository.
7
+ ?> A recipe repository is also a sous project: `sous repo init` sets one up with a `.sous/` directory of its
8
+ own, so its memories file and `.claude/skills/` are build output, and anyone who clones it runs
9
+ `sous build`. `sous repo init` and `sous repo release` find the repository by its `sous.repo.yaml`, not through
10
+ that config. Run them from inside the repository itself. `sous repo submit` runs there too, and may also be run
11
+ from a project that links the repository.
10
12
 
11
13
  ## Create a repository
12
14
 
@@ -20,26 +22,35 @@ $ sous repo init ./my-recipes --name my-recipes --namespace workflow
20
22
  wrote recipes/workflow/example/skills/example-skill/SKILL.tpl.md
21
23
  wrote README.md
22
24
  wrote CONTRIBUTING.md
23
- wrote CLAUDE.md
24
- wrote AGENTS.md
25
25
  wrote .github/workflows/sous-release.yml
26
26
  wrote .gitignore
27
+ // then sous init sets the repository up as a sous project, and runs its first build
27
28
  ```
28
29
 
29
30
  `--name` is the repository's short name (default: the directory's own name), `--namespace` the one namespace to
30
31
  declare (default: the repository's name), `--force` overwrites a repository that already exists, and `--dry-run`
31
- lists the files without writing them. The command asks nothing, and names are lowercase kebab-case, so `My-Recipes`
32
- yields `my-recipes`. Every file is read back through the schemas sous uses on published repositories, so the
33
- scaffold validates. The scaffold is files only: run `git init`, commit it, and add the remote you publish from
34
- before releasing, since `sous repo release` reads and writes tags and fails in a directory git does not track.
32
+ lists the files without writing them. Names are lowercase kebab-case, so `My-Recipes` yields `my-recipes`. Every
33
+ file is read back through the schemas sous uses on published repositories, so the scaffold validates. The scaffold
34
+ is files only: run `git init`, commit it, and add the remote you publish from before releasing, since
35
+ `sous repo release` reads and writes tags and fails in a directory git does not track.
36
+
37
+ After the scaffold, the command runs [`sous init`](commands.md#sous-init-directory) in the same directory, so the
38
+ repository is also a sous project. Init imports a `CLAUDE.md`, an `AGENTS.md` or skills in `.claude/skills/` that
39
+ the directory already holds, and with nothing to import it writes a starter memory,
40
+ `.sous/memories/project.tpl.md`, which says this is a sous recipe repository and names the core skills an agent
41
+ loads before changing anything. It then runs the first build, which compiles the memories file and installs the
42
+ core skills. Init asks what happens to files an existing `CLAUDE.md` or `AGENTS.md` includes, and, in a directory
43
+ with a `.git` folder, whether to install the git hooks; `--yes`, `--move-includes`, `--copy-includes` and
44
+ `--leave-includes` are passed through, as are `--no-build` and `--dry-run`, and `--yes` installs the hooks. A
45
+ directory that already holds a sous config keeps it, and init is skipped with a note.
35
46
 
36
47
  ?> `repo init --force` means overwrite, not "answer yes". It is unrelated to the confirmation flag other
37
48
  commands spell `--yes`, `-y`, `--force` or `--trust`.
38
49
 
39
50
  `sous.repo.yaml` says what the repository publishes, `sous.index.json` is the catalog that `sous repo release`
40
- writes, and each recipe folder carries one `sous.recipe.yaml` beside the files it contributes. `CONTRIBUTING.md`,
41
- `CLAUDE.md` and `AGENTS.md` are for agents: they say that contribution instructions are written for agents, and
42
- point an agent at the sous core skills, which explain how a recipe repository works. The scaffold follows
51
+ writes, and each recipe folder carries one `sous.recipe.yaml` beside the files it contributes. `CONTRIBUTING.md` is
52
+ for agents: it says that contribution instructions are written for agents, and that `sous build` after cloning
53
+ installs the sous core skills, which explain how a recipe repository works. The scaffold follows
43
54
  [`sous-io/sous-recipes`](https://github.com/sous-io/sous-recipes), a complete repository minus its recipes, and
44
55
  its placeholder skill is named `SKILL.tpl.md` because it ends with a footer that only a render fills in. Nothing else is
45
56
  fixed: recipe folders may live anywhere, and what makes a folder a recipe is that `sous.repo.yaml` lists its
@@ -67,12 +78,51 @@ contents:
67
78
  ```
68
79
 
69
80
  `contents` groups are what a subscribing project receives, one group per kind, each with `include` glob patterns
70
- relative to the recipe folder (and optional `exclude` patterns). The four kinds are `skills`, `memories`,
71
- `prompts` and `config`; the kind decides what happens to them in the subscriber's project, which the subscriber shapes with
81
+ relative to the recipe folder (and optional `exclude` patterns). Sous registers four kinds, `skills`, `memories`,
82
+ `prompts` and `config`, and a sous plugin may register more; the kind decides what happens to them in the subscriber's project, which the subscriber shapes with
72
83
  [`recipes`](repositories-file-formats.md#recipes-what-each-content-kind-does). Field tables are in the
73
84
  [recipe manifest](repositories-file-formats.md#sousrecipeyaml-the-recipe-manifest) reference, and recipe
74
85
  metadata is the source of truth for the version: never edit `sous.index.json` by hand.
75
86
 
87
+ ### Conditional contents, inline content and edits
88
+
89
+ `contents` is added to the subscriber's config, so any of its values may be a
90
+ [config expression](configuration.md#config-expressions), evaluated in the subscriber's project with the
91
+ recipe's own answers. An optional part of a recipe is a variable the subscriber answers, and a condition on it:
92
+
93
+ ```yaml
94
+ variables:
95
+ - name: jiraEnabled
96
+ type: boolean
97
+ prompt: Should the Jira capability be installed?
98
+ description: Installs the Jira skills. The default leaves them out.
99
+ example: "true"
100
+ default: false
101
+
102
+ contents:
103
+ - kind: skills
104
+ include:
105
+ - skills/**/*
106
+ exclude:
107
+ - $if:
108
+ expr: "harness.id != 'claude-code'"
109
+ then: skills/session-harness/**/*
110
+ - $if:
111
+ expr: "jiraEnabled != true"
112
+ then: skills/jira-*/**/*
113
+ ```
114
+
115
+ An `include` item may also be content written in place, with the path it is treated as having
116
+ (`{ $inline: "...", path: skills/hello/SKILL.md }`), and a value anywhere may come from a file with
117
+ `{ $file: documents/rules.json }`, relative to the recipe folder. A recipe can also change files it does
118
+ not own, such as a setting in `.claude/settings.json`, with a top-level `edits` list. The forms are in
119
+ [Contents are config](repositories-file-formats.md#contents-are-config) and
120
+ [Edits](repositories-file-formats.md#edits).
121
+
122
+ A kind that no plugin registers fails a subscriber's build. `sous repo release` refuses it when nothing the
123
+ recipe names could register it (no `requires.plugins`, no `subscribes`, no plugin of its own), and warns
124
+ otherwise, so a typo such as `claude-code-plugn` is caught before it is published.
125
+
76
126
  ### Shipping memories
77
127
 
78
128
  A memory is a fragment of an agent's always-loaded instructions. A recipe ships one with a `contents` group of
@@ -125,7 +175,10 @@ requires:
125
175
  sous-plugin-claude-code: "^1.0.0"
126
176
  ```
127
177
 
128
- A subscriber is offered the missing plugin when they subscribe; see
178
+ A subscriber is offered the missing plugin when they subscribe. When npm cannot install it, sous adds
179
+ "Perhaps the required plugin ships as part of a recipe?": a plugin shipped inside a recipe has no npm
180
+ name, and a recipe that needs one lists that recipe under `subscribes` (never `depends`, whose plugins are
181
+ never loaded). See
129
182
  [Subscribe to a recipe](repositories-consuming.md#subscribe-to-a-recipe). How a plugin is written is in
130
183
  [the engine specification](architecture/specifications/S1-engine.md), under "Plugins".
131
184
 
@@ -381,10 +434,10 @@ Once your change is released, one of these moves the project onto it:
381
434
 
382
435
  ```bash
383
436
  sous repo unlink my-recipes --update # unlink, move this repository's pins, then rebuild
384
- sous subscription update my-recipes # the same move, when nothing is linked any more
437
+ sous update my-recipes # the same move, when nothing is linked any more
385
438
  ```
386
439
 
387
- `--update` runs exactly the code `sous subscription update my-recipes` runs: every pin the repository supplies
440
+ `--update` runs exactly the code `sous update my-recipes` runs: every pin the repository supplies
388
441
  moves to the newest version its range allows, after one plan and one question. See
389
442
  [Moving to newer versions](repositories-consuming.md#moving-to-newer-versions).
390
443
 
@@ -197,8 +197,10 @@ like every other file sous writes, so `sous prune` removes what an unsubscribed
197
197
 
198
198
  ## Recipe memories
199
199
 
200
- A memory is a recipe's fragment of an agent's instructions. Sous does not copy memories anywhere; your
201
- instruction source includes them. Put one line in the file your `AGENTS.md` or `CLAUDE.md` is built from:
200
+ A memory is a recipe's fragment of an agent's instructions. Sous includes them into each coding tool's
201
+ memories file (for Claude Code, `.claude/rules/SOUS-MEMORIES.md`; see
202
+ [The memories file](configuration.md#the-memories-file)), through one line in that file's source,
203
+ `.sous/MEMORIES.tpl.md`. The same line works in any file a target of yours compiles:
202
204
 
203
205
  ```text
204
206
  @#memories/**/*.md
@@ -207,7 +209,8 @@ instruction source includes them. Put one line in the file your `AGENTS.md` or `
207
209
  `#memories` is a view: it lists the memories of every recipe you hold directly (a subscription to it, to its
208
210
  namespace, or a co-subscription of a recipe you hold) at the virtual path
209
211
  `#memories/<namespace>/<recipe>/<path>`, and the line includes each one. A recipe held only through `depends`
210
- adds none. `sous init` writes this line into its starter, `.sous/memories/AGENTS.tpl.md`.
212
+ adds none. `sous init` writes this line into `.sous/MEMORIES.tpl.md`, the source of the memories file, after
213
+ a line that includes the project's own memories.
211
214
 
212
215
  Memories come in dependency order (a recipe after the recipes it depends on, ties by recipe key). Two config
213
216
  lists under `recipes.memories` shape the rest, each entry a glob over `namespace/recipe` keys or a regular
@@ -227,10 +230,11 @@ When a build finds a memory an active recipe publishes that no include of any ou
227
230
  or the view) and `exclude` does not name, it warns, naming the memory and the line to add. Subscribing alone
228
231
  includes nothing, and the warning is how that is never silent.
229
232
 
230
- ?> In sous 1.0 an agent's plugin can also name the instruction file that agent reads in every session
231
- (`CLAUDE.md` for the Claude Code plugin built into sous). Sous then writes that file with one `@` include
232
- line for each memory `recipes.memories` selects, so the memories reach the agent without a line of your own.
233
- How that file and an instruction file your own templates write fit together is still being decided.
233
+ ?> Each coding tool's plugin built into sous also compiles one memories file, the file that tool reads in
234
+ every session: `.claude/rules/SOUS-MEMORIES.md` for Claude Code, and `AGENTS.override.md` for Codex once a
235
+ project turns Codex on. Its source, `.sous/MEMORIES.tpl.md`, holds the `@#memories/**/*.md` line above, so the
236
+ memories reach the agent without a line of your own (see [The memories file](configuration.md#the-memories-file)).
237
+ When a target in your own config writes the same file, your target wins and the plugin's steps aside.
234
238
 
235
239
  ## Answer the questions
236
240
 
@@ -294,10 +298,11 @@ indexes, fetching nothing.
294
298
  ## Moving to newer versions
295
299
 
296
300
  A build holds the versions the lockfile pins, so a newer release reaches the project only when
297
- something moves the pin. `sous subscription update` is that step:
301
+ something moves the pin. `sous update` is that step (`sous subscription update` and `sous recipe update` are
302
+ other spellings of it):
298
303
 
299
304
  ```term
300
- $ sous subscription update workflow/qa-variables
305
+ $ sous update workflow/qa-variables
301
306
  Updating the recipe 'qa-recipes:workflow/qa-variables' changes the lockfile:
302
307
 
303
308
  • Adding workflow/qa-helper version 1.0.0
@@ -469,7 +474,7 @@ is missing from the cached index, sous asks upstream once more before reporting
469
474
  released moments ago is found straight away. Always-pull changes what
470
475
  happens after that check, not how often it happens: a repository or subscription marked
471
476
  `alwaysPull` takes a newer in-range version rather than the locked one; set it with
472
- `--always-pull`, or on either entry in the config. Without it, `sous subscription update` is how a
477
+ `--always-pull`, or on either entry in the config. Without it, `sous update` is how a
473
478
  pin moves; see [Moving to newer versions](#moving-to-newer-versions).
474
479
 
475
480
  Every other repository the lockfile pins from is checked on the same window, only to tell you what
@@ -102,7 +102,7 @@ A contribution ships when the repository's maintainers merge it and the reposito
102
102
  that happened before you finished, `--finish` already moved your pins to it. If it happens later, move them with
103
103
 
104
104
  ```bash
105
- sous subscription update sous-recipes
105
+ sous update sous-recipes
106
106
  ```
107
107
 
108
108
  which runs the same update `unlink --update` runs; with `--dry-run` it only shows what it would move. See
@@ -77,10 +77,12 @@ contents: # what a subscriber actually receives
77
77
  | `version` | yes | An exact semantic version; the manifest is the source of truth and the git tag follows it |
78
78
  | `description` | no | Copied into the index at release time; shown by `sous recipe list` and `sous repo search` |
79
79
  | `depends`, `subscribes` | no | Build dependencies and co-subscriptions; within either list, no entry may repeat |
80
- | `contents`, `variables` | no | Contents default to an empty list, which is what a curated bundle publishes; a duplicated variable name, or two definitions claiming one `env`, is an error |
80
+ | `contents`, `variables` | no | Contents default to an empty list, which is what a curated bundle publishes; a duplicated variable name, or two definitions claiming one `env`, is an error. Any value in `contents` may be an expression; see [Contents are config](#contents-are-config) |
81
+ | `edits` | no | Changes to document files the recipe does not own; see [Edits](#edits) |
81
82
  | `submissions` | no | Whether this recipe takes proposed changes, winning over the repository's block; see [The submissions block](#the-submissions-block) |
82
83
  | `plugin` | no | A sous plugin the recipe ships: `bundle`, the path of one self-contained bundled file, and optionally `types`, its `.d.ts` file; see [Recipes that ship sous plugins](repositories-authoring.md#recipes-that-ship-sous-plugins) |
83
84
  | `requires` | no | `requires.plugins` maps npm sous plugin names to version ranges the recipe needs |
85
+ | `handlers` | no | For each purpose (`check`, `configure`, `beforeBuild`, `afterBuild`, `uninstall`, `migrate`), a list of `{ file, handler }`: a self-contained JavaScript file in the recipe and the function it exports, run in the order listed; see [Handlers](handlers.md) |
84
86
 
85
87
  ```yaml
86
88
  plugin:
@@ -89,15 +91,118 @@ plugin:
89
91
  requires:
90
92
  plugins:
91
93
  sous-plugin-claude-code: "^1.0.0"
94
+ handlers:
95
+ check:
96
+ - file: handlers/prerequisites.js
97
+ handler: checkCommands
92
98
  ```
93
99
 
94
- `contents[].kind` is `skills`, `memories`, `prompts` or `config`; a sous plugin is not a content kind but the
95
- `plugin` field above. `skills` are
100
+ `contents[].kind` names a content kind. Sous registers `skills`, `memories`, `prompts` and `config`, and its
101
+ Claude Code plugin registers `claude-code-plugin` and `claude-code-agent` (see
102
+ [Kinds for Claude Code](#kinds-for-claude-code)); a sous plugin can register more (a `content-kind` entity), so
103
+ any lowercase, hyphenated name is accepted here. A sous plugin is
104
+ not a content kind but the `plugin` field above. `skills` are
96
105
  written to the destinations named by [`recipes`](#recipes-what-each-content-kind-does); `memories` are included
97
- into your instruction files by one line (see [Recipe memories](repositories-consuming.md#recipe-memories));
106
+ into each coding tool's memories file by one line (see [Recipe memories](repositories-consuming.md#recipe-memories));
98
107
  each `config` file joins the subscriber's config, under the project's own files so the project wins; nothing takes `prompts` yet, and the build warns about a recipe that
99
108
  publishes them. `include` needs at least one glob, and both lists are recipe-relative.
100
109
 
110
+ A kind no plugin registers stops a subscriber's build, naming the kind and the recipe. `sous repo release`
111
+ refuses one when nothing the recipe names could register it (no `requires.plugins`, no `subscribes`, no
112
+ `plugin` of its own), and warns otherwise.
113
+
114
+ ### Kinds for Claude Code
115
+
116
+ Two kinds carry files only Claude Code reads. Only Claude Code's part of Sous takes them, so a recipe needs no
117
+ harness condition for them, and other coding tools never receive them.
118
+
119
+ ```yaml
120
+ contents:
121
+ - kind: claude-code-plugin
122
+ include:
123
+ - plugins/** # each folder directly under plugins/ is one plugin
124
+ - kind: claude-code-agent
125
+ include:
126
+ - agents/**/*.md
127
+ ```
128
+
129
+ | Recipe file | Written to |
130
+ |---|---|
131
+ | `plugins/session-harness/.claude-plugin/plugin.json` | `.claude/skills/session-harness/.claude-plugin/plugin.json` |
132
+ | `plugins/session-harness/scripts/start.tpl.sh` | `.claude/skills/session-harness/scripts/start.sh` (rendered) |
133
+ | `agents/reviewer.tpl.md` | `.claude/agents/reviewer.md` (rendered) |
134
+ | `agents/review/security.md` | `.claude/agents/review/security.md` |
135
+
136
+ - `claude-code-plugin`: a Claude Code plugin folder, one holding `.claude-plugin/plugin.json`. Each folder directly
137
+ under an `include` pattern's fixed part is one plugin, written under Claude Code's skills directory with the
138
+ folder name the recipe gives it; Claude Code loads it from there as a plugin.
139
+ - `claude-code-agent`: agent files (Markdown with frontmatter), written to `.claude/agents/` with their
140
+ sub-folders kept. An agent here keeps its plain name, where an agent inside a plugin is named `<plugin>:<name>`.
141
+ - A file whose name holds `.tpl.` is rendered, so an agent's `model` can be a recipe variable each person answers
142
+ for themselves; any other file is written as it is.
143
+ - When a build adds, changes or removes a file of a Claude Code plugin (any folder holding
144
+ `.claude-plugin/plugin.json`, however the recipe shipped it), the build ends with one line: run
145
+ `/reload-plugins` in any open Claude Code session, since Claude Code loads plugins only when a session starts or
146
+ on that command.
147
+
148
+ A plugin folder may also be listed among a recipe's `skills`, with an `exclude` entry carrying
149
+ `harness.id != 'claude-code'` so other tools do not receive it (see [Authoring](repositories-authoring.md)).
150
+
151
+ ### Contents are config
152
+
153
+ A subscriber's build adds each group of `contents` to its config under `recipes.contents`, so any value in a
154
+ group may be a [config expression](configuration.md#config-expressions) (`$if`, `$elseif`, `$else`, `$expr`) or a
155
+ `$file`, evaluated in the subscriber's project. A condition can read the recipe's own answers, `host.platform`,
156
+ `harness.id` and `env.<NAME>`. An `include` item may also be inline content, with the path it is treated as
157
+ having:
158
+
159
+ ```yaml
160
+ contents:
161
+ - $if: # a whole group, only for Claude Code
162
+ expr: "harness.id == 'claude-code'"
163
+ then:
164
+ kind: skills
165
+ include: [claude/**]
166
+ - kind: skills
167
+ include:
168
+ - skills/**/*
169
+ - $inline: | # inline content needs a path
170
+ Say hello.
171
+ path: skills/hello/SKILL.md
172
+ exclude:
173
+ - $if: # one item, gated by a yes-or-no question
174
+ expr: "jiraEnabled != true"
175
+ then: skills/jira-*/**/*
176
+ ```
177
+
178
+ `sous config show recipes.contents` shows what the groups gave. Inline content is never interpolated; it is a
179
+ Liquid template only when its path contains `.tpl.`.
180
+
181
+ ### Edits
182
+
183
+ `edits` lists changes to document files the recipe does not own, such as a setting in `.claude/settings.json`.
184
+ Each entry names `file` (relative to the project root) and one or more operations, each holding its own
185
+ parameters, or a file-less operation such as `ensureDirectoryExists`. A subscriber's build appends each entry to
186
+ the config key `editor.edits`, with the recipe that declared it, and the editor plugin applies them. An entry may
187
+ be an expression, and a value may come from a `$file`:
188
+
189
+ ```yaml
190
+ edits:
191
+ - file: .claude/settings.json
192
+ ensureIncludes:
193
+ path: permissions.allow
194
+ items: ["Bash(git-commit.sh:*)"]
195
+ - $if:
196
+ expr: "harness.id == 'claude-code'"
197
+ then:
198
+ file: .claude/settings.json
199
+ set:
200
+ path: permissions.deny
201
+ value: { $file: documents/deny-rules.json }
202
+ ```
203
+
204
+ The manifest checks only that each entry is an object naming an operation; the editor checks the operations.
205
+
101
206
  ### The submissions block
102
207
 
103
208
  Both manifests accept a `submissions` block. On `sous.repo.yaml` it covers every recipe in the repository; on
@@ -421,6 +526,7 @@ varMappings:
421
526
  | `enabled: false` | either of the two above | The opt-out for the entries sous provides itself, the `sous-recipes` repository and the `core` subscription |
422
527
  | `store` | fixed fields | Plain numbers, all optional; the values sous ships are defaults, not assumptions |
423
528
  | `recipes` | content kind | What each kind does; see [recipes: what each content kind does](#recipes-what-each-content-kind-does) |
529
+ | `recipes.handlers` | a list | Written by sous while the config is built: one `{ recipe, purpose, file, handler }` entry for each handler a subscribed recipe from a trusted repository lists; see [Handlers](handlers.md) |
424
530
  | `varMappings` | environment variable name | Binds one name to one recipe variable, written `namespace/recipe/variableName` with an optional `repo:` qualifier |
425
531
 
426
532
  A repository's `url` may be a URL or an absolute path to one on this machine, read by the `local` provider
@@ -447,6 +553,10 @@ includes, so it is dropped from a recipe's layer with a warning.
447
553
 
448
554
  There is no `prompts` block.
449
555
 
556
+ `recipes.contents` is a list sous writes itself while it builds the config: one entry per `contents` group of
557
+ each subscribed recipe (`recipe`, `dir`, `kind`, `include`, `exclude`), its expressions evaluated. Read it with
558
+ `sous config show recipes.contents`; plugins that publish a kind read it too.
559
+
450
560
  ## Managed config layers
451
561
 
452
562
  Three files in a project's `conf.d/` are written by sous rather than by a person, in the machine-written
@@ -26,8 +26,10 @@ echo 'name: my-project' > .sous/sous.config.yaml
26
26
  Everything else has a default: skills compile into `<project root>/.claude/skills` (where the
27
27
  Claude Code plugin built into sous puts them), and the lockfile, the state file and the `conf.d`
28
28
  files sous writes land under `.sous/`. Outside a
29
- walkthrough, `sous init` writes a fuller starting point (a commented config, a starter prompt,
30
- the env files and the ignore block) and runs the first build for you; the one-line config is
29
+ walkthrough, `sous init` writes a fuller starting point (it imports the project's existing
30
+ `CLAUDE.md`, `AGENTS.md` and skills, and writes a commented `sous.config.jsonc`, the memories
31
+ source `.sous/MEMORIES.tpl.md`, the env files and the ignore blocks, and offers the git hooks) and runs the first
32
+ build for you; the one-line config is
31
33
  used here so that each step shows one thing. `SOUS_HOME` puts
32
34
  the machine-wide store somewhere throwaway, so this walkthrough leaves your real one alone. See
33
35
  [The config file](configuration.md) for the keys you will want later.
@@ -152,8 +154,10 @@ under
152
154
 
153
155
  ## 6. Start a repository of your own
154
156
 
155
- A recipe repository is not a sous project; it has no `.sous/` directory, and the three commands
156
- that work inside one do not look for a config. Run this outside your project:
157
+ A recipe repository is also a sous project: `sous repo init` writes the repository, then runs
158
+ `sous init` in it, so its agent instructions and skills are compiled from its own `.sous/`. The
159
+ `sous repo` commands that work inside a repository find it by its `sous.repo.yaml`, not through
160
+ that config. Run this outside your project:
157
161
 
158
162
  ```bash
159
163
  sous repo init ~/projects/my-recipes --name my-recipes --namespace workflow
@@ -167,13 +171,12 @@ sous repo init ~/projects/my-recipes --name my-recipes --namespace workflow
167
171
  wrote recipes/workflow/example/skills/example-skill/SKILL.tpl.md
168
172
  wrote README.md
169
173
  wrote CONTRIBUTING.md
170
- wrote CLAUDE.md
171
- wrote AGENTS.md
172
174
  wrote .github/workflows/sous-release.yml
173
175
  wrote .gitignore
174
176
  ```
175
177
 
176
- The scaffold validates as written, and every file it leaves is heavily commented. `sous.repo.yaml`
178
+ The output goes on with what `sous init` writes and with its first build, which compiles the
179
+ memories file. The scaffold validates as written, and every file it leaves is heavily commented. `sous.repo.yaml`
177
180
  declares the namespaces and lists every recipe folder; each folder's `sous.recipe.yaml` is one
178
181
  recipe, with its own version.
179
182
 
@@ -382,7 +382,10 @@ answer while everything else, your templates included, renders the first definit
382
382
  tells you which names are in play.
383
383
 
384
384
  An answer is laid in exactly as it is stored: a path stays the string you typed, relative or absolute, and a
385
- number stays text. A template that needs an absolute path from a relative answer composes one under another
385
+ number stays text. A `boolean` is the exception: its answer is `true` or `false` whatever word stored it
386
+ (`yes`, `off`, `1`), and a template or a config condition sees a real boolean, so `{% if jiraEnabled %}` and
387
+ `$if: jiraEnabled` take the false branch for an answer, or a default, of `false`. `${jiraEnabled}` still gives
388
+ the text `false`. Compare a boolean with `true`, not with the text `"true"`. A template that needs an absolute path from a relative answer composes one under another
386
389
  name in `_vars`, for instance `taskFileDir: "${projectRoot}/${taskFileRoot}"`. `projectRoot` is set by sous
387
390
  (the directory holding `.sous/`); setting it in any `_vars` is an error.
388
391