@sous-io/plugin-api 0.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +96 -2
- package/dist/command-variables.d.ts +13 -0
- package/dist/command-variables.js +28 -0
- package/dist/config.d.ts +170 -0
- package/dist/config.js +1 -0
- package/dist/context.d.ts +159 -0
- package/dist/context.js +1 -0
- package/dist/entities.d.ts +60 -0
- package/dist/entities.js +1 -0
- package/dist/errors.d.ts +111 -0
- package/dist/errors.js +138 -0
- package/dist/events.d.ts +90 -0
- package/dist/events.js +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +14 -0
- package/dist/intents.d.ts +151 -0
- package/dist/intents.js +1 -0
- package/dist/json.d.ts +84 -0
- package/dist/json.js +7 -0
- package/dist/node.d.ts +81 -0
- package/dist/node.js +1 -0
- package/dist/outputs.d.ts +193 -0
- package/dist/outputs.js +286 -0
- package/dist/plugin.d.ts +144 -0
- package/dist/plugin.js +18 -0
- package/dist/prompter.d.ts +66 -0
- package/dist/prompter.js +32 -0
- package/dist/registry.d.ts +91 -0
- package/dist/registry.js +1 -0
- package/dist/report-styles.d.ts +220 -0
- package/dist/report-styles.js +60 -0
- package/dist/reporter.d.ts +270 -0
- package/dist/reporter.js +388 -0
- package/dist/schema.d.ts +131 -0
- package/dist/schema.js +211 -0
- package/dist/services.d.ts +68 -0
- package/dist/services.js +1 -0
- package/dist/timing.d.ts +31 -0
- package/dist/timing.js +20 -0
- package/package.json +33 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Luke Chavers
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,4 +1,98 @@
|
|
|
1
1
|
# @sous-io/plugin-api
|
|
2
2
|
|
|
3
|
-
The plugin
|
|
4
|
-
|
|
3
|
+
The interface for writing a sous plugin, and the one package of sous that outside plugins depend on. It holds `definePlugin`, the types, the `Reporter` and `Prompter` interfaces and the error classes. It has no dependencies.
|
|
4
|
+
|
|
5
|
+
## Write your first plugin
|
|
6
|
+
|
|
7
|
+
A plugin is a module whose default export is `definePlugin({...})`. Its `register(sous)` runs once, when the plugin loads. Everything below goes inside it.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { definePlugin } from "@sous-io/plugin-api";
|
|
11
|
+
|
|
12
|
+
export default definePlugin({
|
|
13
|
+
name: "sous-plugin-diagrams",
|
|
14
|
+
version: "1.0.0",
|
|
15
|
+
dependsOn: { "@sous-io/plugin-skills": "^1.0.0" },
|
|
16
|
+
|
|
17
|
+
register(sous) {
|
|
18
|
+
// 1. A config contributor: adds to the config while it is built.
|
|
19
|
+
sous.config.contribute({
|
|
20
|
+
id: "diagrams",
|
|
21
|
+
contribute(config) {
|
|
22
|
+
if (config.atPath("diagrams.enabled").valueOr(true)) {
|
|
23
|
+
config.atPath("compilation.targets").appendValue({ id: "diagrams" });
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// 2. An intent: a step with typed input. The CLI command and the MCP tool are generated from it.
|
|
29
|
+
sous.intents.add({
|
|
30
|
+
intent: "diagrams.render",
|
|
31
|
+
summary: "Render every diagram",
|
|
32
|
+
handle: async (input, ctx) => {
|
|
33
|
+
ctx.reporter.info("Rendering");
|
|
34
|
+
return { rendered: 0 };
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// 3. A listener: runs when an event fires.
|
|
39
|
+
sous.on("config.built", (event, ctx) => {
|
|
40
|
+
ctx.reporter.debug("Config built");
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
A contributor re-runs when something it read changes, so it must give the same result for the same input.
|
|
47
|
+
|
|
48
|
+
### Which contributor wins
|
|
49
|
+
|
|
50
|
+
When two contributors set the same key, the one whose patch applies last wins. Patches apply by `applyOrder`, a whole number from 0 to 99999 (default 2000): lower numbers apply first, and equal numbers apply in id order. The user's config files use 89900 and up, so they apply after every plugin and win.
|
|
51
|
+
|
|
52
|
+
`before` and `after` name contributors, plugins or wildcards (`"*"` means every other contributor). They win over the number: a contributor declared `after` another is moved to one past it, and the move is logged at the `debug` level. `sous config show --layers` shows each contributor's number, and the one it moved to.
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
sous.config.contribute({
|
|
56
|
+
id: "diagrams/fixups",
|
|
57
|
+
applyOrder: 3000, // after plugins left at the default (2000)
|
|
58
|
+
after: ["@sous-io/plugin-skills"], // and after every contributor of plugin-skills, whatever its number
|
|
59
|
+
contribute(config) {
|
|
60
|
+
config.atPath("diagrams.enabled").setValue(true);
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Typed access to another plugin
|
|
66
|
+
|
|
67
|
+
Add your plugin's names to the interfaces in this package (declaration merging), and another plugin gets them typed. To use a plugin's names, import its types file with no runtime cost and list it in `dependsOn`:
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
// In sous-plugin-diagrams: describe what it provides.
|
|
71
|
+
declare module "@sous-io/plugin-api" {
|
|
72
|
+
interface SousIntents {
|
|
73
|
+
"diagrams.render": { input: { only?: string }; result: { rendered: number } };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// In another plugin: the intent is now typed.
|
|
78
|
+
import type {} from "sous-plugin-diagrams/types";
|
|
79
|
+
|
|
80
|
+
const { rendered } = await ctx.run("diagrams.render", { only: "intro" });
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
`SousServices`, `SousEvents`, `SousEntities` and `SousConfig` work the same way, for `sous.services.get(name)`, event payloads, entity kinds and config keys.
|
|
84
|
+
|
|
85
|
+
## Where things are
|
|
86
|
+
|
|
87
|
+
- `src/plugin.ts`: `definePlugin` and the `sous` object `register` receives (everything a plugin can add).
|
|
88
|
+
- `src/config.ts`: contributors and the config builder they use.
|
|
89
|
+
- `src/intents.ts`, `src/events.ts`, `src/services.ts`, `src/entities.ts`: what each registry takes.
|
|
90
|
+
- `src/registry.ts`: the interfaces plugins add types to.
|
|
91
|
+
- `src/errors.ts`, `src/reporter.ts`, `src/prompter.ts`: the error classes, and how a plugin reports and asks.
|
|
92
|
+
- Real examples: any `packages/plugin-*` directory, for instance `packages/plugin-inspect`.
|
|
93
|
+
|
|
94
|
+
## Testing
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
pnpm --filter @sous-io/plugin-api test
|
|
98
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Context } from "./context.js";
|
|
2
|
+
import { IntentOutput } from "./outputs.js";
|
|
3
|
+
/**
|
|
4
|
+
* The "Command Variables" output most commands open their result with: the project's name (the
|
|
5
|
+
* config's `name`, else its directory's name), its config file, then `extra` in its key order.
|
|
6
|
+
* Outside a project it holds only `extra`.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* return new IntentOutputs([commandVariables(ctx, { Reading: "the cached indexes" }), listing]);
|
|
10
|
+
* // Project: my-app / Config: /work/my-app/.sous/sous.config.js / Reading: the cached indexes
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare function commandVariables(ctx: Pick<Context, "project" | "config">, extra?: Readonly<Record<string, unknown>>): IntentOutput;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { IntentOutput, VariableSet } from "./outputs.js";
|
|
2
|
+
import { ReportEntryStyle } from "./report-styles.js";
|
|
3
|
+
/**
|
|
4
|
+
* The "Command Variables" output most commands open their result with: the project's name (the
|
|
5
|
+
* config's `name`, else its directory's name), its config file, then `extra` in its key order.
|
|
6
|
+
* Outside a project it holds only `extra`.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* return new IntentOutputs([commandVariables(ctx, { Reading: "the cached indexes" }), listing]);
|
|
10
|
+
* // Project: my-app / Config: /work/my-app/.sous/sous.config.js / Reading: the cached indexes
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export function commandVariables(ctx, extra = {}) {
|
|
14
|
+
const entries = {};
|
|
15
|
+
if (ctx.project !== undefined) {
|
|
16
|
+
const name = ctx.config.get(["name"]);
|
|
17
|
+
entries.Project = typeof name === "string" && name !== "" ? name : baseName(ctx.project.root);
|
|
18
|
+
if (ctx.project.configPath !== undefined) {
|
|
19
|
+
entries.Config = ctx.project.configPath;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return new IntentOutput({ title: "Command Variables", result: new VariableSet({ ...entries, ...extra }), style: ReportEntryStyle.CommandVariables });
|
|
23
|
+
}
|
|
24
|
+
/** The last segment of a path, on any platform. */
|
|
25
|
+
function baseName(directory) {
|
|
26
|
+
const parts = directory.split(/[\\/]/).filter((part) => part !== "");
|
|
27
|
+
return parts[parts.length - 1] ?? directory;
|
|
28
|
+
}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import type { Environment, ProjectInfo } from "./context.js";
|
|
2
|
+
import type { EntityReader } from "./entities.js";
|
|
3
|
+
import type { JsonObject, JsonValue, Patch, PatchSet, PathInput } from "./json.js";
|
|
4
|
+
import type { DocumentNode } from "./node.js";
|
|
5
|
+
import type { ConfigKeyType, EntityKind, EntityType } from "./registry.js";
|
|
6
|
+
import type { Reporter } from "./reporter.js";
|
|
7
|
+
import type { ServiceReader } from "./services.js";
|
|
8
|
+
/** Reading a built config. Values are plain JSON, frozen. */
|
|
9
|
+
export interface ConfigReader {
|
|
10
|
+
/** The value at a path, or `undefined`. */
|
|
11
|
+
get<K extends string>(path: K): ConfigKeyType<K> | undefined;
|
|
12
|
+
get<T = JsonValue>(path: PathInput): T | undefined;
|
|
13
|
+
/** Whether a value exists at a path. */
|
|
14
|
+
has(path: PathInput): boolean;
|
|
15
|
+
/** The whole config. */
|
|
16
|
+
value(): Readonly<JsonObject>;
|
|
17
|
+
}
|
|
18
|
+
/** One primitive change to a value, and who made it. */
|
|
19
|
+
export interface ConfigLayer {
|
|
20
|
+
/** The contributor that made it. */
|
|
21
|
+
readonly contributor: string;
|
|
22
|
+
/** The plugin the contributor belongs to. */
|
|
23
|
+
readonly plugin: string;
|
|
24
|
+
readonly patch: Patch;
|
|
25
|
+
/** The patch sets around it, outermost first, after the contributor's own: `["removeWhere"]`. */
|
|
26
|
+
readonly helpers: readonly string[];
|
|
27
|
+
/** The contributor's declared apply order. */
|
|
28
|
+
readonly applyOrder: number;
|
|
29
|
+
/** Its apply order once `before` and `after` are met; it may pass 99999. */
|
|
30
|
+
readonly actualApplyOrder: number;
|
|
31
|
+
}
|
|
32
|
+
/** One contributor's part in a build. */
|
|
33
|
+
export interface Contribution {
|
|
34
|
+
readonly contributor: string;
|
|
35
|
+
readonly plugin: string;
|
|
36
|
+
readonly stage: number;
|
|
37
|
+
/** Its declared apply order, 0 to 99999 (default 2000). */
|
|
38
|
+
readonly applyOrder: number;
|
|
39
|
+
/**
|
|
40
|
+
* Its apply order once `before` and `after` are met: the declared one, or moved to one past
|
|
41
|
+
* (or one less than) a contributor it must apply after (or before). It may pass 99999.
|
|
42
|
+
*/
|
|
43
|
+
readonly actualApplyOrder: number;
|
|
44
|
+
/** Its latest patch set. */
|
|
45
|
+
readonly patches: PatchSet;
|
|
46
|
+
/** How many times it ran in this build. */
|
|
47
|
+
readonly runs: number;
|
|
48
|
+
}
|
|
49
|
+
/** A config the engine built: the values, and the entities and services that belong to it. */
|
|
50
|
+
export interface BuiltConfig extends ConfigReader {
|
|
51
|
+
/** Counts builds in this process, "what if" builds included. */
|
|
52
|
+
readonly buildNumber: number;
|
|
53
|
+
/** True for a "what if" build, which never replaces the real config. */
|
|
54
|
+
readonly whatIf: boolean;
|
|
55
|
+
/** Passes the build took, over every stage, counting only passes in which something ran. */
|
|
56
|
+
readonly passes: number;
|
|
57
|
+
/** A hash of the values and the entities (ids, sources and data), to tell configs apart. */
|
|
58
|
+
readonly hash: string;
|
|
59
|
+
/** The entities of this build. */
|
|
60
|
+
readonly entities: EntityReader;
|
|
61
|
+
/** The services of this build: `config` services belong to it. */
|
|
62
|
+
readonly services: ServiceReader;
|
|
63
|
+
/** Every change to a path, or anything inside it or around it, in the order it was applied. */
|
|
64
|
+
layers(path: PathInput): ConfigLayer[];
|
|
65
|
+
/** Every contributor's part, in the order their patches apply: earlier stages first, then by actual apply order and id. */
|
|
66
|
+
contributions(): Contribution[];
|
|
67
|
+
}
|
|
68
|
+
/** Watching more than a contributor reads: a path, or an entity kind. */
|
|
69
|
+
export type Monitor = PathInput | {
|
|
70
|
+
entities: string;
|
|
71
|
+
};
|
|
72
|
+
/** Who is running, as the builder tells a contributor. */
|
|
73
|
+
export interface ContributorInfo {
|
|
74
|
+
readonly id: string;
|
|
75
|
+
readonly plugin: string;
|
|
76
|
+
/** The stage it runs in, after any shift. */
|
|
77
|
+
readonly stage: number;
|
|
78
|
+
/** The pass of the current stage, from 1. */
|
|
79
|
+
readonly pass: number;
|
|
80
|
+
/** How many times it has run in this build, this run included. */
|
|
81
|
+
readonly run: number;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* What a contributor is given. It shows the config made from every other
|
|
85
|
+
* contributor's latest patches, without this contributor's own; every read is recorded, and every
|
|
86
|
+
* change becomes this run's patch set. It also reports like a reporter (`config.warn(...)`,
|
|
87
|
+
* `config.log(...)`), through the engine's reporter, with the contributor named in each message
|
|
88
|
+
* (contributors never print).
|
|
89
|
+
*/
|
|
90
|
+
export interface ConfigBuilder extends Reporter {
|
|
91
|
+
/** The root, to merge a whole config file: `config.root().merge(data)`. Reading it monitors everything. */
|
|
92
|
+
root(): DocumentNode;
|
|
93
|
+
/** A node at a path. */
|
|
94
|
+
atPath(path: PathInput): DocumentNode;
|
|
95
|
+
/** Every entity of a kind. Recorded as a read of the list. */
|
|
96
|
+
entities<K extends EntityKind>(kind: K): EntityType<K>[];
|
|
97
|
+
/** One entity. Recorded as a read of that entity alone. */
|
|
98
|
+
entity<K extends EntityKind>(kind: K, id: string): EntityType<K> | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* Adds an entity the config creates. It is part of this run's patch, so a re-run replaces it.
|
|
101
|
+
* Its methods must not use `this` (see `sous.entities.add`).
|
|
102
|
+
*/
|
|
103
|
+
addEntity<K extends EntityKind>(kind: K, entry: EntityType<K>): void;
|
|
104
|
+
/** This contributor's patch set from its previous run, if it ran before. */
|
|
105
|
+
previousPatches(): PatchSet | undefined;
|
|
106
|
+
/** Applies raw patches, as written in a patch file. */
|
|
107
|
+
apply(patches: Patch | PatchSet | readonly Patch[]): void;
|
|
108
|
+
/** This plugin's own options from `plugins.options`. Recorded as a read. */
|
|
109
|
+
options<T = JsonObject>(): T | undefined;
|
|
110
|
+
/** Who is running. */
|
|
111
|
+
readonly contributor: ContributorInfo;
|
|
112
|
+
readonly project: ProjectInfo | undefined;
|
|
113
|
+
readonly env: Environment;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* A contributor: anything that adds to the config.
|
|
117
|
+
*
|
|
118
|
+
* ```ts
|
|
119
|
+
* sous.config.contribute({
|
|
120
|
+
* id: "diagrams",
|
|
121
|
+
* after: ["@sous-io/plugin-skills"],
|
|
122
|
+
*
|
|
123
|
+
* contribute(config) {
|
|
124
|
+
* if (config.atPath("diagrams.enabled").valueOr(true)) {
|
|
125
|
+
* config.atPath("compilation.targets").appendValue({ id: "diagrams" });
|
|
126
|
+
* }
|
|
127
|
+
* },
|
|
128
|
+
* });
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
export interface ContributorDefinition {
|
|
132
|
+
/** Unique in the engine: `diagrams`, `confd/610-mac.jsonc`, `claude-code/defaults`. */
|
|
133
|
+
id: string;
|
|
134
|
+
/** Its config stage; stages run lowest first. Default `0`, shifted for plugins loaded during a stage. */
|
|
135
|
+
stage?: number;
|
|
136
|
+
/**
|
|
137
|
+
* Where its patch applies within its stage: a whole number from 0 to 99999, default `2000`. Higher
|
|
138
|
+
* numbers apply later, so when two contributors set one key, the one with the higher number
|
|
139
|
+
* applies after the other and wins; equal numbers apply in id order. The user's files use
|
|
140
|
+
* 89900 and up, so they apply after every plugin's contributor. `before` and `after` win over
|
|
141
|
+
* the number: a contributor that must apply after another is moved to one past it (see
|
|
142
|
+
* `Contribution.actualApplyOrder`). Any other number is refused when the contributor is added.
|
|
143
|
+
*/
|
|
144
|
+
applyOrder?: number;
|
|
145
|
+
/**
|
|
146
|
+
* Plugins, contributor ids or wildcards this one runs and applies before. `"*"` means every
|
|
147
|
+
* contributor that does not itself declare `before: ["*"]`. Default: its plugin's `before`.
|
|
148
|
+
*/
|
|
149
|
+
before?: readonly string[];
|
|
150
|
+
/**
|
|
151
|
+
* Plugins, contributor ids or wildcards this one runs and applies after. `"*"` means every
|
|
152
|
+
* contributor that does not itself declare `after: ["*"]`. Default: its plugin's `after`.
|
|
153
|
+
*/
|
|
154
|
+
after?: readonly string[];
|
|
155
|
+
/** More to watch than it reads; a change to any re-runs it. */
|
|
156
|
+
monitors?: readonly Monitor[];
|
|
157
|
+
/** Builds this contributor's patch. Must give the same result for the same input. */
|
|
158
|
+
contribute(config: ConfigBuilder): void | Promise<void>;
|
|
159
|
+
}
|
|
160
|
+
/** Options for building a config. */
|
|
161
|
+
export interface BuildOptions {
|
|
162
|
+
/** More contributors for this build only ("what if" builds). */
|
|
163
|
+
extraContributors?: readonly ContributorDefinition[];
|
|
164
|
+
/**
|
|
165
|
+
* `reportBudgets` (`boolean = true`): `false` keeps the build's over-budget warning from being
|
|
166
|
+
* printed. A front end passes it for a command that only prints text (help, version, completion),
|
|
167
|
+
* where the warning is noise above the answer. The build is still timed (`--timings`).
|
|
168
|
+
*/
|
|
169
|
+
reportBudgets?: boolean;
|
|
170
|
+
}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|