@sous-io/sous-plugin-api 0.0.0-stage → 1.0.19
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/README.md +97 -2
- package/dist/command-variables.d.ts +13 -0
- package/dist/command-variables.js +28 -0
- package/dist/config.d.ts +235 -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/handlers.d.ts +47 -0
- package/dist/handlers.js +16 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +15 -0
- package/dist/intents.d.ts +158 -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 +199 -0
- package/dist/outputs.js +292 -0
- package/dist/plugin.d.ts +181 -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 +221 -0
- package/dist/report-styles.js +60 -0
- package/dist/reporter.d.ts +270 -0
- package/dist/reporter.js +392 -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 +22 -0
- package/package.json +34 -4
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import type { ContributorDefinition, RunPlan } from "./config.js";
|
|
2
|
+
import type { Environment, EngineHandle, ProjectInfo } from "./context.js";
|
|
3
|
+
import type { EntityKindOptions, EntityReader } from "./entities.js";
|
|
4
|
+
import type { HandlerRegistry } from "./handlers.js";
|
|
5
|
+
import type { EventFor, EventForPattern, EventPattern, EventPayload, Listener, ListenerOptions } from "./events.js";
|
|
6
|
+
import type { IntentDefinition, IntentWrapper, IntentInputOf } from "./intents.js";
|
|
7
|
+
import type { EntityKind, EntityType, IntentReturn, ServiceName, ServiceType } from "./registry.js";
|
|
8
|
+
import type { Reporter } from "./reporter.js";
|
|
9
|
+
import type { SousSchema } from "./schema.js";
|
|
10
|
+
import type { ServiceFactory, ServiceOptions, ServiceReader, ServiceWrapper } from "./services.js";
|
|
11
|
+
/**
|
|
12
|
+
* A plugin: a module that registers contributors, intents, listeners, services and entities. Its module's default export is the definition.
|
|
13
|
+
*/
|
|
14
|
+
export interface PluginDefinition {
|
|
15
|
+
/** The package name: `sous-plugin-diagrams`, `@sous-io/sous-plugin-skills`. */
|
|
16
|
+
name: string;
|
|
17
|
+
/** Its version, checked against other plugins' `dependsOn`. */
|
|
18
|
+
version?: string;
|
|
19
|
+
/** One sentence saying what it adds. */
|
|
20
|
+
description?: string;
|
|
21
|
+
/** Plugins this one needs, with semver ranges. Sous stops before any intent runs when one is missing. */
|
|
22
|
+
dependsOn?: Readonly<Record<string, string>>;
|
|
23
|
+
/** The default `before` of every contributor it adds. */
|
|
24
|
+
before?: readonly string[];
|
|
25
|
+
/** The default `after` of every contributor it adds. */
|
|
26
|
+
after?: readonly string[];
|
|
27
|
+
/**
|
|
28
|
+
* Service and intent names this plugin's contract declares for other plugins to implement
|
|
29
|
+
* (`compiler.namespace-resolver`). Another plugin registering one is expected, so sous does not
|
|
30
|
+
* warn that it starts with this plugin's prefix.
|
|
31
|
+
*/
|
|
32
|
+
implementable?: readonly string[];
|
|
33
|
+
/** Runs once, when the plugin loads during config building. */
|
|
34
|
+
register(sous: Sous): void | Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Declares a plugin. It only gives the definition its type.
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* export default definePlugin({
|
|
41
|
+
* name: "sous-plugin-diagrams",
|
|
42
|
+
* version: "1.0.0",
|
|
43
|
+
* dependsOn: { "@sous-io/sous-plugin-skills": "^1.0.0" },
|
|
44
|
+
*
|
|
45
|
+
* register(sous) {
|
|
46
|
+
* sous.intents.add({ intent: "diagrams.render", handle: async () => ({ rendered: 0 }) });
|
|
47
|
+
* },
|
|
48
|
+
* });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function definePlugin<const T extends PluginDefinition>(definition: T): T;
|
|
52
|
+
/** A front end: the CLI, the MCP server, a web GUI. */
|
|
53
|
+
export interface FrontEndDefinition {
|
|
54
|
+
/** `cli`, `mcp`, `web`. */
|
|
55
|
+
id: string;
|
|
56
|
+
/** Takes over after the config is built: turns its input into submitted chains. */
|
|
57
|
+
start(engine: EngineHandle, argv: readonly string[]): void | Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Whether `argv` needs the built config (`boolean = true`). It is asked on the config of the
|
|
60
|
+
* built-in plugins' registrations alone; `false` lets the application start the front end without
|
|
61
|
+
* building the config when the project loads no further plugin.
|
|
62
|
+
*/
|
|
63
|
+
needsConfig?(engine: EngineHandle, argv: readonly string[]): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* What `argv` will run, read before the config is built (asked on the config of the built-in
|
|
66
|
+
* plugins' registrations alone), or `undefined` when it cannot tell. The application passes it to
|
|
67
|
+
* the config build as `plan`.
|
|
68
|
+
*/
|
|
69
|
+
plan?(engine: EngineHandle, argv: readonly string[]): RunPlan | undefined;
|
|
70
|
+
}
|
|
71
|
+
/** `sous.intents`. */
|
|
72
|
+
export interface IntentRegistry {
|
|
73
|
+
/** Adds an intent. Two plugins adding one name is an error naming both, unless `intents.replace` picks one. */
|
|
74
|
+
add<const N extends string, S extends SousSchema = SousSchema>(definition: IntentDefinition<N, S>): void;
|
|
75
|
+
/** Wraps an intent's handler. */
|
|
76
|
+
wrap<N extends string>(intent: N, wrapper: IntentWrapper<IntentInputOf<N, unknown>, IntentReturn<N>>): void;
|
|
77
|
+
}
|
|
78
|
+
/** `sous.services`. */
|
|
79
|
+
export interface ServiceRegistry extends ServiceReader {
|
|
80
|
+
/** Adds a service with a lifetime. */
|
|
81
|
+
add<N extends ServiceName>(name: N, factory: ServiceFactory<ServiceType<N>>, options?: ServiceOptions): void;
|
|
82
|
+
/** Wraps a service. Wrappers stack in plugin order. */
|
|
83
|
+
wrap<N extends ServiceName>(name: N, wrapper: ServiceWrapper<ServiceType<N>>): void;
|
|
84
|
+
/**
|
|
85
|
+
* Replaces a service. Two plugins replacing one is an error, unless the config picks one
|
|
86
|
+
* (`services.replace."<name>": "<plugin>"`); sous then warns on every run.
|
|
87
|
+
*/
|
|
88
|
+
replace<N extends ServiceName>(name: N, factory: ServiceFactory<ServiceType<N>>, options?: ServiceOptions): void;
|
|
89
|
+
}
|
|
90
|
+
/** `sous.entities`. */
|
|
91
|
+
export interface EntityRegistry extends EntityReader {
|
|
92
|
+
/** Defines a kind, with the schema every entry is checked against. */
|
|
93
|
+
define(kind: string, schema: SousSchema, options?: EntityKindOptions): void;
|
|
94
|
+
/**
|
|
95
|
+
* Adds an entity whose existence does not depend on the config.
|
|
96
|
+
*
|
|
97
|
+
* An entity's methods must not use `this`: the engine stores a copy of each entry (its schema
|
|
98
|
+
* check and its method timing make one), so `this` is not the object the plugin made. Close over
|
|
99
|
+
* what a method needs instead:
|
|
100
|
+
*
|
|
101
|
+
* ```ts
|
|
102
|
+
* const root = ".codex";
|
|
103
|
+
*
|
|
104
|
+
* sous.entities.add("skill-target", {
|
|
105
|
+
* id: "codex",
|
|
106
|
+
* directory: () => root, // not `() => this.root`
|
|
107
|
+
* });
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
add<K extends EntityKind>(kind: K, entry: EntityType<K>): void;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The namespaces plugins add to the `sous` object, by name (`sous.migrations`). A plugin declares
|
|
114
|
+
* its own with declaration merging and adds it with `sous.extensions.add`:
|
|
115
|
+
*
|
|
116
|
+
* ```ts
|
|
117
|
+
* declare module "@sous-io/sous-plugin-api" {
|
|
118
|
+
* interface SousExtensions {
|
|
119
|
+
* migrations: { add(migration: MigrationDefinition): void };
|
|
120
|
+
* }
|
|
121
|
+
* }
|
|
122
|
+
*
|
|
123
|
+
* sous.extensions.add("migrations", (other) => ({
|
|
124
|
+
* add: (migration) => other.entities.add("migration", toEntity(migration)),
|
|
125
|
+
* }));
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* A plugin that registers after it then calls `sous.migrations.add(...)`, and what it adds is
|
|
129
|
+
* recorded as its own registration, since the factory receives that plugin's `sous`.
|
|
130
|
+
*/
|
|
131
|
+
export interface SousExtensions {
|
|
132
|
+
}
|
|
133
|
+
/** Makes the value of one extension for one plugin's `sous` object. */
|
|
134
|
+
export type SousExtensionFactory<T> = (sous: Sous) => T;
|
|
135
|
+
/**
|
|
136
|
+
* What `register(sous)` receives: everything a plugin uses, scoped to that plugin, so every
|
|
137
|
+
* registration is recorded with it. Each namespace another plugin added with
|
|
138
|
+
* `sous.extensions.add` is there too, by its name.
|
|
139
|
+
*/
|
|
140
|
+
export interface Sous extends SousExtensions {
|
|
141
|
+
/** Adds a namespace to the `sous` object of every plugin, this one included (see {@link SousExtensions}). */
|
|
142
|
+
readonly extensions: {
|
|
143
|
+
add<K extends keyof SousExtensions & string>(name: K, factory: SousExtensionFactory<SousExtensions[K]>): void;
|
|
144
|
+
};
|
|
145
|
+
/** The plugin registering. */
|
|
146
|
+
readonly plugin: {
|
|
147
|
+
readonly name: string;
|
|
148
|
+
readonly version: string | undefined;
|
|
149
|
+
};
|
|
150
|
+
readonly project: ProjectInfo | undefined;
|
|
151
|
+
readonly env: Environment;
|
|
152
|
+
/** The engine's reporter, for messages outside any chain. */
|
|
153
|
+
readonly reporter: Reporter;
|
|
154
|
+
/** The engine, as front ends and background intents use it. */
|
|
155
|
+
readonly engine: EngineHandle;
|
|
156
|
+
readonly config: {
|
|
157
|
+
/** Adds a contributor. */
|
|
158
|
+
contribute(definition: ContributorDefinition): void;
|
|
159
|
+
};
|
|
160
|
+
readonly intents: IntentRegistry;
|
|
161
|
+
readonly services: ServiceRegistry;
|
|
162
|
+
readonly entities: EntityRegistry;
|
|
163
|
+
/** Adds handlers: functions run for a purpose (`check`, `uninstall`, ...). Needs `@sous-io/sous-plugin-handlers`. */
|
|
164
|
+
readonly handlers: HandlerRegistry;
|
|
165
|
+
readonly plugins: {
|
|
166
|
+
/** Brings in another plugin as this one's own dependency; users may still disable it by name. */
|
|
167
|
+
add(plugin: PluginDefinition | string): Promise<void>;
|
|
168
|
+
};
|
|
169
|
+
readonly frontEnds: {
|
|
170
|
+
/** Adds a front end. */
|
|
171
|
+
add(definition: FrontEndDefinition): void;
|
|
172
|
+
};
|
|
173
|
+
/** Listens for an event by name, wildcard or regular expression. */
|
|
174
|
+
on<const P extends EventPattern>(pattern: P, listener: Listener<EventForPattern<P>>, options?: ListenerOptions): void;
|
|
175
|
+
/** Listens once, then removes itself. */
|
|
176
|
+
once<const P extends EventPattern>(pattern: P, listener: Listener<EventForPattern<P>>, options?: ListenerOptions): void;
|
|
177
|
+
/** Removes a listener added with the same pattern. */
|
|
178
|
+
off(pattern: EventPattern, listener: Listener<never>): void;
|
|
179
|
+
/** Fires an event and waits for every listener. */
|
|
180
|
+
emit<N extends string>(name: N, payload?: EventPayload<N>): Promise<EventFor<N>>;
|
|
181
|
+
}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declares a plugin. It only gives the definition its type.
|
|
3
|
+
*
|
|
4
|
+
* ```ts
|
|
5
|
+
* export default definePlugin({
|
|
6
|
+
* name: "sous-plugin-diagrams",
|
|
7
|
+
* version: "1.0.0",
|
|
8
|
+
* dependsOn: { "@sous-io/sous-plugin-skills": "^1.0.0" },
|
|
9
|
+
*
|
|
10
|
+
* register(sous) {
|
|
11
|
+
* sous.intents.add({ intent: "diagrams.render", handle: async () => ({ rendered: 0 }) });
|
|
12
|
+
* },
|
|
13
|
+
* });
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export function definePlugin(definition) {
|
|
17
|
+
return definition;
|
|
18
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asking questions. Services never prompt: they ask through the `Prompter` the front end
|
|
3
|
+
* handed over with the chain (`ctx.prompter`). Every question names the flag or argument that
|
|
4
|
+
* answers it without a prompt, so an agent can do everything a person can.
|
|
5
|
+
*/
|
|
6
|
+
/** What every question carries. */
|
|
7
|
+
export interface QuestionBase {
|
|
8
|
+
/** The question, as a person would read it: `Remove the 3 files listed above?` */
|
|
9
|
+
message: string;
|
|
10
|
+
/**
|
|
11
|
+
* The flag or argument that answers this question ahead of time (`--yes`, `--harness <id>`).
|
|
12
|
+
* A prompter that cannot ask names it in its error.
|
|
13
|
+
*/
|
|
14
|
+
answeredBy?: string;
|
|
15
|
+
}
|
|
16
|
+
/** A question answered with free text. */
|
|
17
|
+
export interface ValueQuestion extends QuestionBase {
|
|
18
|
+
/** The answer used when the person just presses enter. */
|
|
19
|
+
default?: string;
|
|
20
|
+
/** Returns a message when the answer is not acceptable, so the prompter asks again. */
|
|
21
|
+
validate?: (answer: string) => string | undefined;
|
|
22
|
+
/** Hides what is typed, for secrets. */
|
|
23
|
+
secret?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/** One option of a {@link ChoiceQuestion}. */
|
|
26
|
+
export interface Choice<T> {
|
|
27
|
+
/** What the person sees. */
|
|
28
|
+
label: string;
|
|
29
|
+
value: T;
|
|
30
|
+
/** One more line about the option. */
|
|
31
|
+
description?: string;
|
|
32
|
+
}
|
|
33
|
+
/** A question answered by picking one option. */
|
|
34
|
+
export interface ChoiceQuestion<T> extends QuestionBase {
|
|
35
|
+
choices: ReadonlyArray<Choice<T>>;
|
|
36
|
+
/** The index of the option picked when the person just presses enter. */
|
|
37
|
+
defaultIndex?: number;
|
|
38
|
+
}
|
|
39
|
+
/** A yes-or-no question. */
|
|
40
|
+
export interface ConfirmQuestion extends QuestionBase {
|
|
41
|
+
/** The answer used when the person just presses enter. */
|
|
42
|
+
default?: boolean;
|
|
43
|
+
}
|
|
44
|
+
/** Where a chain's questions go. Each front end supplies its own. */
|
|
45
|
+
export interface Prompter {
|
|
46
|
+
/** Whether this prompter can ask anything at all in this run. */
|
|
47
|
+
readonly interactive: boolean;
|
|
48
|
+
/** Asks for free text. Throws `NonInteractiveError` naming `answeredBy` when it cannot ask. */
|
|
49
|
+
askValue(question: ValueQuestion): Promise<string>;
|
|
50
|
+
/** Asks the person to pick one option. */
|
|
51
|
+
askChoice<T>(question: ChoiceQuestion<T>): Promise<T>;
|
|
52
|
+
/** Asks a yes-or-no question. */
|
|
53
|
+
confirm(question: ConfirmQuestion): Promise<boolean>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A prompter that never asks: every question fails with a `NonInteractiveError` naming the flag that
|
|
57
|
+
* answers it. Used when nothing can answer, such as in CI or a background intent.
|
|
58
|
+
*/
|
|
59
|
+
export declare const nonInteractivePrompter: Prompter;
|
|
60
|
+
/**
|
|
61
|
+
* A prompter that answers from a list of prepared answers, in order, for tests and for front ends
|
|
62
|
+
* that collect answers up front. Running out of answers fails like {@link nonInteractivePrompter}.
|
|
63
|
+
*/
|
|
64
|
+
export declare function scriptedPrompter(answers: unknown[]): Prompter & {
|
|
65
|
+
readonly asked: string[];
|
|
66
|
+
};
|
package/dist/prompter.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { NonInteractiveError } from "./errors.js";
|
|
2
|
+
/**
|
|
3
|
+
* A prompter that never asks: every question fails with a `NonInteractiveError` naming the flag that
|
|
4
|
+
* answers it. Used when nothing can answer, such as in CI or a background intent.
|
|
5
|
+
*/
|
|
6
|
+
export const nonInteractivePrompter = {
|
|
7
|
+
interactive: false,
|
|
8
|
+
askValue: (question) => Promise.reject(new NonInteractiveError(question.message, question.answeredBy)),
|
|
9
|
+
askChoice: (question) => Promise.reject(new NonInteractiveError(question.message, question.answeredBy)),
|
|
10
|
+
confirm: (question) => Promise.reject(new NonInteractiveError(question.message, question.answeredBy)),
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* A prompter that answers from a list of prepared answers, in order, for tests and for front ends
|
|
14
|
+
* that collect answers up front. Running out of answers fails like {@link nonInteractivePrompter}.
|
|
15
|
+
*/
|
|
16
|
+
export function scriptedPrompter(answers) {
|
|
17
|
+
const asked = [];
|
|
18
|
+
const next = (question) => {
|
|
19
|
+
asked.push(question.message);
|
|
20
|
+
if (answers.length === 0) {
|
|
21
|
+
return Promise.reject(new NonInteractiveError(question.message, question.answeredBy));
|
|
22
|
+
}
|
|
23
|
+
return Promise.resolve(answers.shift());
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
interactive: true,
|
|
27
|
+
asked,
|
|
28
|
+
askValue: (question) => next(question),
|
|
29
|
+
askChoice: (question) => next(question),
|
|
30
|
+
confirm: (question) => next(question),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { IntentOutputs, PlainObject } from "./outputs.js";
|
|
2
|
+
import type { ConfigKeyEntity, PluginLocatorEntity } from "./entities.js";
|
|
3
|
+
import type { ConfigBuiltPayload } from "./events.js";
|
|
4
|
+
/**
|
|
5
|
+
* The interfaces plugins add their own types to, through TypeScript declaration merging. At run time everything is looked up by its string name; these only
|
|
6
|
+
* give the names their types.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* declare module "@sous-io/sous-plugin-api" {
|
|
10
|
+
* interface SousServices {
|
|
11
|
+
* "diagrams.renderer": Renderer;
|
|
12
|
+
* }
|
|
13
|
+
*
|
|
14
|
+
* interface SousIntents {
|
|
15
|
+
* "diagrams.render": { input: { only?: string }; result: { rendered: number } };
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* interface SousEvents {
|
|
19
|
+
* "diagrams.rendered": { files: RenderResult[] };
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* interface SousEntities {
|
|
23
|
+
* "harness": HarnessEntity;
|
|
24
|
+
* }
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export interface SousServices {
|
|
29
|
+
}
|
|
30
|
+
/** Each intent's input and result: `"name": { input: ...; result: ... }`. */
|
|
31
|
+
export interface SousIntents {
|
|
32
|
+
}
|
|
33
|
+
/** Each custom event's payload: `"diagrams.rendered": { files: RenderResult[] }`. */
|
|
34
|
+
export interface SousEvents {
|
|
35
|
+
}
|
|
36
|
+
/** Each entity kind's entry type: `"harness": HarnessEntity`. */
|
|
37
|
+
export interface SousEntities {
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The type of each top-level config key, for `ctx.config.get("diagrams")`. Optional: a key with no
|
|
41
|
+
* entry here reads as `unknown`. (Added beside the four interfaces core names; it follows the same
|
|
42
|
+
* pattern for the keys plugins add as `config-key` entities.)
|
|
43
|
+
*/
|
|
44
|
+
export interface SousConfig {
|
|
45
|
+
}
|
|
46
|
+
/** The entity kinds core itself defines. */
|
|
47
|
+
export interface CoreEntities {
|
|
48
|
+
/** A key the config may hold, with its schema. */
|
|
49
|
+
"config-key": ConfigKeyEntity;
|
|
50
|
+
/** A way to find a plugin's module from the specifier in `plugins.load`. */
|
|
51
|
+
"plugin-locator": PluginLocatorEntity;
|
|
52
|
+
}
|
|
53
|
+
/** The events core itself fires. */
|
|
54
|
+
export interface CoreEvents {
|
|
55
|
+
/** Fired once each time the config has been built (never for "what if" builds). */
|
|
56
|
+
"config.built": ConfigBuiltPayload;
|
|
57
|
+
}
|
|
58
|
+
/** A name any of these registries accepts: a known one, or any string. */
|
|
59
|
+
export type AnyName<Known> = (Known & string) | (string & {});
|
|
60
|
+
/** Every known service name, plus any string. */
|
|
61
|
+
export type ServiceName = AnyName<keyof SousServices>;
|
|
62
|
+
/** The type of a service, or `unknown` when nothing declares it. */
|
|
63
|
+
export type ServiceType<N extends string> = N extends keyof SousServices ? SousServices[N] : unknown;
|
|
64
|
+
/** Every known intent name, plus any string. */
|
|
65
|
+
export type IntentName = AnyName<keyof SousIntents>;
|
|
66
|
+
/** The input type an intent declared, or `unknown`. */
|
|
67
|
+
export type IntentInput<N extends string> = N extends keyof SousIntents ? SousIntents[N] extends {
|
|
68
|
+
input: infer I;
|
|
69
|
+
} ? I : unknown : unknown;
|
|
70
|
+
/** The result type an intent declared, or `unknown`. */
|
|
71
|
+
export type IntentResult<N extends string> = N extends keyof SousIntents ? SousIntents[N] extends {
|
|
72
|
+
result: infer R;
|
|
73
|
+
} ? R : unknown : unknown;
|
|
74
|
+
/**
|
|
75
|
+
* What an intent's handler returns: its outputs, whose `toPlain()` is the declared result (or a plain
|
|
76
|
+
* object when the intent declares none).
|
|
77
|
+
*/
|
|
78
|
+
export type IntentReturn<N extends string> = IntentOutputs<IntentResult<N> extends object ? IntentResult<N> : PlainObject>;
|
|
79
|
+
/** Every entity kind, core's and the plugins'. */
|
|
80
|
+
export type AllEntities = CoreEntities & SousEntities;
|
|
81
|
+
/** Every known entity kind, plus any string. */
|
|
82
|
+
export type EntityKind = AnyName<keyof AllEntities>;
|
|
83
|
+
/** What every entity has. */
|
|
84
|
+
export interface EntityBase {
|
|
85
|
+
/** Unique within its kind. */
|
|
86
|
+
id: string;
|
|
87
|
+
}
|
|
88
|
+
/** The entry type of an entity kind, or {@link EntityBase} when nothing declares it. */
|
|
89
|
+
export type EntityType<K extends string> = K extends keyof AllEntities ? AllEntities[K] : EntityBase & Record<string, unknown>;
|
|
90
|
+
/** The type of a top-level config key, or `unknown`. */
|
|
91
|
+
export type ConfigKeyType<K extends string> = K extends keyof SousConfig ? SousConfig[K] : unknown;
|
package/dist/registry.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The kinds of entry a reporter shows, and the facts each one carries in `details`. A style says what
|
|
3
|
+
* an entry IS, never how it looks: each front end's reporter decides that. A new style is added here
|
|
4
|
+
* when an output needs one, together with its convenience method in `BaseReporter` (reporter.ts),
|
|
5
|
+
* which is the only way callers produce it.
|
|
6
|
+
*
|
|
7
|
+
* Every styled message also carries a plain-text `message`, so a reporter that ignores styles (a
|
|
8
|
+
* log file, a test buffer) still has something readable.
|
|
9
|
+
*/
|
|
10
|
+
/** What kind of entry a reported message is. */
|
|
11
|
+
export declare const ReportEntryStyle: {
|
|
12
|
+
/** A paragraph of text, which a front end may wrap. `details` is optional data. */
|
|
13
|
+
readonly Plain: "plain";
|
|
14
|
+
/** Text shown exactly as given: no wrapping, no color (a value printed for a script to read). No details. */
|
|
15
|
+
readonly Text: "text";
|
|
16
|
+
/** An explanation that is neither a warning nor an error. No details. */
|
|
17
|
+
readonly Note: "note";
|
|
18
|
+
/** The start of an operation, such as "Building the project". {@link OperationStartDetails}. */
|
|
19
|
+
readonly OperationStart: "operation-start";
|
|
20
|
+
/** A step inside the current operation, such as one target being compiled. {@link StepStartDetails}. */
|
|
21
|
+
readonly StepStart: "step-start";
|
|
22
|
+
/** One line of detail inside the current operation or step. No details. */
|
|
23
|
+
readonly Detail: "detail";
|
|
24
|
+
/** One action done (or to be done) to one target, such as a file written. {@link OperationDetails}. */
|
|
25
|
+
readonly Operation: "operation";
|
|
26
|
+
/** How an operation ended, such as "Done." {@link OperationEndDetails}. */
|
|
27
|
+
readonly OperationEnd: "operation-end";
|
|
28
|
+
/** One label and its value. The message is a `VariableSet`. */
|
|
29
|
+
readonly Variable: "variable";
|
|
30
|
+
/** Labels and values, read as one block, under an optional title. The message is a `VariableSet`. */
|
|
31
|
+
readonly VariableList: "variable-list";
|
|
32
|
+
/** The facts a command runs with: the project, its config, ... The message is a `VariableSet`. */
|
|
33
|
+
readonly CommandVariables: "command-variables";
|
|
34
|
+
/** A list of items, with an optional title and closing sentence. The message is an `ItemList`. */
|
|
35
|
+
readonly List: "list";
|
|
36
|
+
/** A table of rows. The message is a `Table`. */
|
|
37
|
+
readonly Table: "table";
|
|
38
|
+
/** Items nested under other items, such as each contributor and the changes it made. The message is a `Tree`. */
|
|
39
|
+
readonly Tree: "tree";
|
|
40
|
+
/** How many things were found. {@link CountDetails}. */
|
|
41
|
+
readonly Count: "count";
|
|
42
|
+
/** Says that a run is a dry run, or what a dry run left undone. No details. */
|
|
43
|
+
readonly DryRun: "dry-run";
|
|
44
|
+
/** Something wrong, with its cause and what to do about it. {@link ProblemDetails}. */
|
|
45
|
+
readonly Problem: "problem";
|
|
46
|
+
/** What a name on the command line resolved to, and why. {@link ResolvedReferenceFacts}. */
|
|
47
|
+
readonly ResolvedReference: "resolved-reference";
|
|
48
|
+
/** The question about to be asked, and where its answer goes. {@link QuestionDetails}. */
|
|
49
|
+
readonly Question: "question";
|
|
50
|
+
/** A command sous runs (or would run). {@link CommandDetails}. */
|
|
51
|
+
readonly Command: "command";
|
|
52
|
+
/** Progress through a longer step. {@link ProgressEvent}. */
|
|
53
|
+
readonly Progress: "progress";
|
|
54
|
+
/** A structured value, such as a command's result as data. The message is a `DataValue`. */
|
|
55
|
+
readonly Data: "data";
|
|
56
|
+
/** The sous banner. No details. */
|
|
57
|
+
readonly Banner: "banner";
|
|
58
|
+
/** A command's result: the message is `IntentOutputs`. */
|
|
59
|
+
readonly Result: "result";
|
|
60
|
+
};
|
|
61
|
+
/** One of the {@link ReportEntryStyle} values. */
|
|
62
|
+
export type ReportEntryStyle = (typeof ReportEntryStyle)[keyof typeof ReportEntryStyle];
|
|
63
|
+
/** {@link ReportEntryStyle.OperationStart}. */
|
|
64
|
+
export interface OperationStartDetails {
|
|
65
|
+
/** What the operation does, in a few words: `Building the project`. */
|
|
66
|
+
readonly name: string;
|
|
67
|
+
}
|
|
68
|
+
/** {@link ReportEntryStyle.StepStart}. */
|
|
69
|
+
export interface StepStartDetails {
|
|
70
|
+
/** What the step does or works on: `CLAUDE.md`. */
|
|
71
|
+
readonly name: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* What was done to a target. The `would-` actions are a dry run's: what a real run would do.
|
|
75
|
+
*
|
|
76
|
+
* - `written`: created or changed.
|
|
77
|
+
* - `unchanged`: already as it should be; nothing written.
|
|
78
|
+
* - `skipped`: left alone on purpose (the note says why).
|
|
79
|
+
* - `failed`: not done because of an error.
|
|
80
|
+
* - `removed`: deleted, such as an output no target produces any more.
|
|
81
|
+
* - `backed-up`: copied to a backup before it was overwritten or removed; the note says where.
|
|
82
|
+
*/
|
|
83
|
+
export type OperationAction = "written" | "would-write" | "unchanged" | "skipped" | "failed" | "removed" | "would-remove" | "backed-up" | "would-back-up";
|
|
84
|
+
/** {@link ReportEntryStyle.Operation}. */
|
|
85
|
+
export interface OperationDetails {
|
|
86
|
+
readonly action: OperationAction;
|
|
87
|
+
/** What the action was done to: usually an absolute file path. */
|
|
88
|
+
readonly target: string;
|
|
89
|
+
/** Why, or anything else worth knowing, in a few words: `left out by the transform "strip"`. */
|
|
90
|
+
readonly note?: string;
|
|
91
|
+
/** For a written file: roughly how many tokens it holds. */
|
|
92
|
+
readonly tokens?: number;
|
|
93
|
+
}
|
|
94
|
+
/** {@link ReportEntryStyle.OperationEnd}. */
|
|
95
|
+
export interface OperationEndDetails {
|
|
96
|
+
/** Whether the operation succeeded. */
|
|
97
|
+
readonly ok: boolean;
|
|
98
|
+
}
|
|
99
|
+
/** One label and its value. */
|
|
100
|
+
export interface VariableEntry {
|
|
101
|
+
/** The name on the left. An empty label continues the entry above. */
|
|
102
|
+
readonly label: string;
|
|
103
|
+
/** The value. */
|
|
104
|
+
readonly value: unknown;
|
|
105
|
+
/** A secondary fact (where it came from), shown less prominently after the value. */
|
|
106
|
+
readonly detail?: string;
|
|
107
|
+
}
|
|
108
|
+
/** What a column holds, which decides how it aligns and where it is cut. */
|
|
109
|
+
export type ColumnKind = "text" | "path" | "url" | "number";
|
|
110
|
+
/** What a column does with a cell too long for it. */
|
|
111
|
+
export type ColumnOverflow = "wrap" | "truncate";
|
|
112
|
+
/** Which end of a cell is given up when it is cut. */
|
|
113
|
+
export type TruncateSide = "start" | "middle" | "end";
|
|
114
|
+
/** Where a cell sits inside its column. */
|
|
115
|
+
export type ColumnAlign = "left" | "right" | "center";
|
|
116
|
+
/** How willingly a column is hidden when there is no room for it. */
|
|
117
|
+
export type ColumnPriority = "low" | "medium" | "high";
|
|
118
|
+
/** One column of a table. Every field after `header` is a hint a front end may ignore. */
|
|
119
|
+
export interface TableColumn {
|
|
120
|
+
/** The property each row is read from. */
|
|
121
|
+
key: string;
|
|
122
|
+
/** The heading shown above the column. */
|
|
123
|
+
header: string;
|
|
124
|
+
/** Whether a long cell wraps onto more lines or is cut. Defaults to wrapping. */
|
|
125
|
+
overflow?: ColumnOverflow;
|
|
126
|
+
/** Which end a cut takes from. Defaults by kind: the middle of a path or a URL, the end of anything else. */
|
|
127
|
+
truncate?: TruncateSide;
|
|
128
|
+
/** What the column holds. Defaults to plain text. */
|
|
129
|
+
kind?: ColumnKind;
|
|
130
|
+
/** Where a cell sits in the column. Defaults to the right for a number, the left for everything else. */
|
|
131
|
+
align?: ColumnAlign;
|
|
132
|
+
/** This column's share of any width left over once every column has its natural width. Defaults to none. */
|
|
133
|
+
flex?: number;
|
|
134
|
+
/** The narrowest this column is ever squeezed to. Defaults to the width of its heading. */
|
|
135
|
+
minWidth?: number;
|
|
136
|
+
/** How willingly the column is hidden. A high column is never hidden; a low one goes first. Defaults to high. */
|
|
137
|
+
priority?: ColumnPriority;
|
|
138
|
+
}
|
|
139
|
+
/** One item of a `Tree` payload, with the items nested under it. */
|
|
140
|
+
export interface TreeNode {
|
|
141
|
+
readonly label: string;
|
|
142
|
+
/** A secondary fact, shown less prominently after the label. */
|
|
143
|
+
readonly detail?: string;
|
|
144
|
+
readonly children?: readonly TreeNode[];
|
|
145
|
+
}
|
|
146
|
+
/** {@link ReportEntryStyle.Count}. */
|
|
147
|
+
export interface CountDetails {
|
|
148
|
+
readonly count: number;
|
|
149
|
+
/** What was counted, already in the right number: `recipes`. */
|
|
150
|
+
readonly entity: string;
|
|
151
|
+
/** The verb before the count. Default `Found`; an empty string for none. */
|
|
152
|
+
readonly verb?: string;
|
|
153
|
+
}
|
|
154
|
+
/** {@link ReportEntryStyle.Problem}. */
|
|
155
|
+
export interface ProblemDetails {
|
|
156
|
+
/** What went wrong, in one sentence. */
|
|
157
|
+
readonly summary: string;
|
|
158
|
+
/** Why: the underlying error or the facts behind it. */
|
|
159
|
+
readonly cause?: string;
|
|
160
|
+
/** What to do about it. */
|
|
161
|
+
readonly hint?: string;
|
|
162
|
+
/** What it is about, such as a file or a recipe. */
|
|
163
|
+
readonly subject?: string;
|
|
164
|
+
/** For a problem in a file: the line. */
|
|
165
|
+
readonly line?: number;
|
|
166
|
+
}
|
|
167
|
+
/** {@link ReportEntryStyle.ResolvedReference}: what a reference resolved to. */
|
|
168
|
+
export interface ResolvedReferenceFacts {
|
|
169
|
+
/** What was typed. */
|
|
170
|
+
readonly search: string;
|
|
171
|
+
/** What it resolved to, in full. */
|
|
172
|
+
readonly resolvedTo: string;
|
|
173
|
+
/** What kind of thing it is: `recipe`, `namespace`, ... */
|
|
174
|
+
readonly kind: string;
|
|
175
|
+
readonly variable?: string;
|
|
176
|
+
readonly recipe?: string;
|
|
177
|
+
readonly namespace?: string;
|
|
178
|
+
readonly repository?: string;
|
|
179
|
+
readonly location?: string;
|
|
180
|
+
readonly description?: string;
|
|
181
|
+
/** Why this candidate won, in one sentence. */
|
|
182
|
+
readonly reason?: string;
|
|
183
|
+
}
|
|
184
|
+
/** {@link ReportEntryStyle.Question}. */
|
|
185
|
+
export interface QuestionDetails {
|
|
186
|
+
/** Its place in the run: question `index` of `total`. */
|
|
187
|
+
readonly index: number;
|
|
188
|
+
readonly total: number;
|
|
189
|
+
/** The variable's name. */
|
|
190
|
+
readonly name: string;
|
|
191
|
+
readonly description?: string;
|
|
192
|
+
readonly example?: string;
|
|
193
|
+
/** The recipe that asks it. */
|
|
194
|
+
readonly recipe?: string;
|
|
195
|
+
/** The file its answer goes into. */
|
|
196
|
+
readonly storedIn?: string;
|
|
197
|
+
/** The environment variable name its answer is stored as. */
|
|
198
|
+
readonly storedAs?: string;
|
|
199
|
+
}
|
|
200
|
+
/** {@link ReportEntryStyle.Command}. */
|
|
201
|
+
export interface CommandDetails {
|
|
202
|
+
readonly command: string;
|
|
203
|
+
readonly args: readonly string[];
|
|
204
|
+
/** The directory it runs in. */
|
|
205
|
+
readonly cwd?: string;
|
|
206
|
+
/** True when it would run, but a dry run does not run it. */
|
|
207
|
+
readonly dryRun?: boolean;
|
|
208
|
+
}
|
|
209
|
+
/** {@link ReportEntryStyle.Progress}: progress through a longer step, such as downloading recipes. */
|
|
210
|
+
export interface ProgressEvent {
|
|
211
|
+
/** What is in progress, in a few words: `Downloading recipes`. */
|
|
212
|
+
label: string;
|
|
213
|
+
/** How far along: items done so far. */
|
|
214
|
+
done?: number;
|
|
215
|
+
/** How far along: items in total, when known. */
|
|
216
|
+
total?: number;
|
|
217
|
+
/** The item being worked on now. */
|
|
218
|
+
item?: string;
|
|
219
|
+
/** True on the last event of this label. */
|
|
220
|
+
finished?: boolean;
|
|
221
|
+
}
|