@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/errors.d.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The error classes every plugin throws and every front end recognizes.
|
|
3
|
+
*
|
|
4
|
+
* A front end turns an error into a message and an exit code. Errors are recognized by their
|
|
5
|
+
* `sousErrorKind` as well as by class, so two copies of this package never confuse a front end.
|
|
6
|
+
*/
|
|
7
|
+
/** The kind of a sous error, one per class. */
|
|
8
|
+
export type SousErrorKind = "sous" | "config" | "input" | "non-interactive" | "cancelled" | "loop" | "plugin" | "conflict" | "not-found" | "budget";
|
|
9
|
+
/** Options every sous error accepts. */
|
|
10
|
+
export interface SousErrorOptions {
|
|
11
|
+
/** The error that caused this one. */
|
|
12
|
+
cause?: unknown;
|
|
13
|
+
/** More lines that explain it or say how to fix it, shown under the message. */
|
|
14
|
+
details?: readonly string[];
|
|
15
|
+
/** The exit code a CLI should use. Default 1. */
|
|
16
|
+
exitCode?: number;
|
|
17
|
+
}
|
|
18
|
+
/** The base of every error sous and its plugins throw on purpose. */
|
|
19
|
+
export declare class SousError extends Error {
|
|
20
|
+
/** Identifies sous errors across copies of this package. */
|
|
21
|
+
readonly sousErrorKind: SousErrorKind;
|
|
22
|
+
/** More lines that explain the error or say how to fix it. */
|
|
23
|
+
readonly details: readonly string[];
|
|
24
|
+
/** The exit code a CLI should use. */
|
|
25
|
+
readonly exitCode: number;
|
|
26
|
+
constructor(message: string, options?: SousErrorOptions);
|
|
27
|
+
}
|
|
28
|
+
/** The config could not be built, or is not valid. */
|
|
29
|
+
export declare class ConfigError extends SousError {
|
|
30
|
+
readonly sousErrorKind: SousErrorKind;
|
|
31
|
+
}
|
|
32
|
+
/** One problem with an intent's input, or a config value: where, and what. */
|
|
33
|
+
export interface InputIssue {
|
|
34
|
+
/** Where, as a path string (`ref`, `targets[2].id`); `""` for the value itself. */
|
|
35
|
+
path: string;
|
|
36
|
+
message: string;
|
|
37
|
+
}
|
|
38
|
+
/** An intent's input did not match its schema. */
|
|
39
|
+
export declare class InputError extends SousError {
|
|
40
|
+
readonly sousErrorKind: SousErrorKind;
|
|
41
|
+
/** The intent whose input was wrong. */
|
|
42
|
+
readonly intent: string;
|
|
43
|
+
/** Every problem found. */
|
|
44
|
+
readonly issues: readonly InputIssue[];
|
|
45
|
+
constructor(intent: string, issues: readonly InputIssue[], options?: SousErrorOptions);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A question could not be asked, because nothing can answer it in this run. The message
|
|
49
|
+
* names the question and the flag or argument that answers it ahead of time.
|
|
50
|
+
*/
|
|
51
|
+
export declare class NonInteractiveError extends SousError {
|
|
52
|
+
readonly sousErrorKind: SousErrorKind;
|
|
53
|
+
/** The question that could not be asked. */
|
|
54
|
+
readonly question: string;
|
|
55
|
+
/** The flag or argument that answers it, such as `--yes`. */
|
|
56
|
+
readonly answeredBy: string | undefined;
|
|
57
|
+
constructor(question: string, answeredBy: string | undefined, options?: SousErrorOptions);
|
|
58
|
+
}
|
|
59
|
+
/** A listener cancelled an intent or an event on purpose; `reason` says why. */
|
|
60
|
+
export declare class CancelledError extends SousError {
|
|
61
|
+
readonly sousErrorKind: SousErrorKind;
|
|
62
|
+
/** What was cancelled: an intent or an event name. */
|
|
63
|
+
readonly target: string;
|
|
64
|
+
/** The reason the listener gave. */
|
|
65
|
+
readonly reason: string;
|
|
66
|
+
/** The plugin whose listener cancelled it. */
|
|
67
|
+
readonly cancelledBy: string | undefined;
|
|
68
|
+
constructor(target: string, reason: string, cancelledBy?: string, options?: SousErrorOptions);
|
|
69
|
+
}
|
|
70
|
+
/** The engine found a loop: the config did not settle, or calls nested past a limit. */
|
|
71
|
+
export declare class LoopError extends SousError {
|
|
72
|
+
readonly sousErrorKind: SousErrorKind;
|
|
73
|
+
/** Which limit was passed, as named under the `limits` config key. */
|
|
74
|
+
readonly limit: string;
|
|
75
|
+
constructor(limit: string, message: string, options?: SousErrorOptions);
|
|
76
|
+
}
|
|
77
|
+
/** A plugin could not be found, loaded or registered, or a plugin it depends on is missing. */
|
|
78
|
+
export declare class PluginError extends SousError {
|
|
79
|
+
readonly sousErrorKind: SousErrorKind;
|
|
80
|
+
/** The plugin, by name or by the specifier it was asked for under. */
|
|
81
|
+
readonly plugin: string;
|
|
82
|
+
constructor(plugin: string, message: string, options?: SousErrorOptions);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Two plugins claim the same thing (a service replacement, an intent, a CLI command) and the
|
|
86
|
+
* config does not pick one. The message names both and the config key that picks one.
|
|
87
|
+
*/
|
|
88
|
+
export declare class ConflictError extends SousError {
|
|
89
|
+
readonly sousErrorKind: SousErrorKind;
|
|
90
|
+
/** What is claimed twice. */
|
|
91
|
+
readonly subject: string;
|
|
92
|
+
/** The plugins claiming it. */
|
|
93
|
+
readonly plugins: readonly string[];
|
|
94
|
+
constructor(subject: string, plugins: readonly string[], message: string, options?: SousErrorOptions);
|
|
95
|
+
}
|
|
96
|
+
/** No plugin provides the intent, service, entity or front end asked for. */
|
|
97
|
+
export declare class NotFoundError extends SousError {
|
|
98
|
+
readonly sousErrorKind: SousErrorKind;
|
|
99
|
+
/** What kind of thing was asked for: `intent`, `service`, `entity`, `front end`. */
|
|
100
|
+
readonly thing: string;
|
|
101
|
+
/** Its name or id. */
|
|
102
|
+
readonly id: string;
|
|
103
|
+
constructor(thing: string, id: string, message?: string, options?: SousErrorOptions);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Whether a value is a sous error, by class or by its `sousErrorKind` (so a second copy of this
|
|
107
|
+
* package is still recognized).
|
|
108
|
+
*/
|
|
109
|
+
export declare function isSousError(value: unknown): value is SousError;
|
|
110
|
+
/** Whether a value is a sous error of one kind. */
|
|
111
|
+
export declare function isSousErrorOfKind(value: unknown, kind: SousErrorKind): value is SousError;
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The error classes every plugin throws and every front end recognizes.
|
|
3
|
+
*
|
|
4
|
+
* A front end turns an error into a message and an exit code. Errors are recognized by their
|
|
5
|
+
* `sousErrorKind` as well as by class, so two copies of this package never confuse a front end.
|
|
6
|
+
*/
|
|
7
|
+
/** The base of every error sous and its plugins throw on purpose. */
|
|
8
|
+
export class SousError extends Error {
|
|
9
|
+
/** Identifies sous errors across copies of this package. */
|
|
10
|
+
sousErrorKind = "sous";
|
|
11
|
+
/** More lines that explain the error or say how to fix it. */
|
|
12
|
+
details;
|
|
13
|
+
/** The exit code a CLI should use. */
|
|
14
|
+
exitCode;
|
|
15
|
+
constructor(message, options = {}) {
|
|
16
|
+
super(message, options.cause === undefined ? undefined : { cause: options.cause });
|
|
17
|
+
this.name = new.target.name;
|
|
18
|
+
this.details = options.details ?? [];
|
|
19
|
+
this.exitCode = options.exitCode ?? 1;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** The config could not be built, or is not valid. */
|
|
23
|
+
export class ConfigError extends SousError {
|
|
24
|
+
sousErrorKind = "config";
|
|
25
|
+
}
|
|
26
|
+
/** An intent's input did not match its schema. */
|
|
27
|
+
export class InputError extends SousError {
|
|
28
|
+
sousErrorKind = "input";
|
|
29
|
+
/** The intent whose input was wrong. */
|
|
30
|
+
intent;
|
|
31
|
+
/** Every problem found. */
|
|
32
|
+
issues;
|
|
33
|
+
constructor(intent, issues, options = {}) {
|
|
34
|
+
super(`The input to "${intent}" is not valid.`, {
|
|
35
|
+
exitCode: 2,
|
|
36
|
+
...options,
|
|
37
|
+
details: options.details ?? issues.map((issue) => (issue.path ? `${issue.path}: ${issue.message}` : issue.message)),
|
|
38
|
+
});
|
|
39
|
+
this.intent = intent;
|
|
40
|
+
this.issues = issues;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A question could not be asked, because nothing can answer it in this run. The message
|
|
45
|
+
* names the question and the flag or argument that answers it ahead of time.
|
|
46
|
+
*/
|
|
47
|
+
export class NonInteractiveError extends SousError {
|
|
48
|
+
sousErrorKind = "non-interactive";
|
|
49
|
+
/** The question that could not be asked. */
|
|
50
|
+
question;
|
|
51
|
+
/** The flag or argument that answers it, such as `--yes`. */
|
|
52
|
+
answeredBy;
|
|
53
|
+
constructor(question, answeredBy, options = {}) {
|
|
54
|
+
const fix = answeredBy ? ` Pass ${answeredBy} to answer it ahead of time.` : "";
|
|
55
|
+
// Exit code 1, as before the refactor: only a command line the CLI could not parse exits 2.
|
|
56
|
+
super(`sous needed to ask "${question}" but cannot ask questions in this run.${fix}`, options);
|
|
57
|
+
this.question = question;
|
|
58
|
+
this.answeredBy = answeredBy;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** A listener cancelled an intent or an event on purpose; `reason` says why. */
|
|
62
|
+
export class CancelledError extends SousError {
|
|
63
|
+
sousErrorKind = "cancelled";
|
|
64
|
+
/** What was cancelled: an intent or an event name. */
|
|
65
|
+
target;
|
|
66
|
+
/** The reason the listener gave. */
|
|
67
|
+
reason;
|
|
68
|
+
/** The plugin whose listener cancelled it. */
|
|
69
|
+
cancelledBy;
|
|
70
|
+
constructor(target, reason, cancelledBy, options = {}) {
|
|
71
|
+
const by = cancelledBy ? ` (cancelled by ${cancelledBy})` : "";
|
|
72
|
+
super(`"${target}" was cancelled: ${reason}${by}`, options);
|
|
73
|
+
this.target = target;
|
|
74
|
+
this.reason = reason;
|
|
75
|
+
this.cancelledBy = cancelledBy;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/** The engine found a loop: the config did not settle, or calls nested past a limit. */
|
|
79
|
+
export class LoopError extends SousError {
|
|
80
|
+
sousErrorKind = "loop";
|
|
81
|
+
/** Which limit was passed, as named under the `limits` config key. */
|
|
82
|
+
limit;
|
|
83
|
+
constructor(limit, message, options = {}) {
|
|
84
|
+
super(message, options);
|
|
85
|
+
this.limit = limit;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/** A plugin could not be found, loaded or registered, or a plugin it depends on is missing. */
|
|
89
|
+
export class PluginError extends SousError {
|
|
90
|
+
sousErrorKind = "plugin";
|
|
91
|
+
/** The plugin, by name or by the specifier it was asked for under. */
|
|
92
|
+
plugin;
|
|
93
|
+
constructor(plugin, message, options = {}) {
|
|
94
|
+
super(message, options);
|
|
95
|
+
this.plugin = plugin;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Two plugins claim the same thing (a service replacement, an intent, a CLI command) and the
|
|
100
|
+
* config does not pick one. The message names both and the config key that picks one.
|
|
101
|
+
*/
|
|
102
|
+
export class ConflictError extends SousError {
|
|
103
|
+
sousErrorKind = "conflict";
|
|
104
|
+
/** What is claimed twice. */
|
|
105
|
+
subject;
|
|
106
|
+
/** The plugins claiming it. */
|
|
107
|
+
plugins;
|
|
108
|
+
constructor(subject, plugins, message, options = {}) {
|
|
109
|
+
super(message, options);
|
|
110
|
+
this.subject = subject;
|
|
111
|
+
this.plugins = plugins;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/** No plugin provides the intent, service, entity or front end asked for. */
|
|
115
|
+
export class NotFoundError extends SousError {
|
|
116
|
+
sousErrorKind = "not-found";
|
|
117
|
+
/** What kind of thing was asked for: `intent`, `service`, `entity`, `front end`. */
|
|
118
|
+
thing;
|
|
119
|
+
/** Its name or id. */
|
|
120
|
+
id;
|
|
121
|
+
constructor(thing, id, message, options = {}) {
|
|
122
|
+
super(message ?? `No plugin provides the ${thing} "${id}".`, options);
|
|
123
|
+
this.thing = thing;
|
|
124
|
+
this.id = id;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Whether a value is a sous error, by class or by its `sousErrorKind` (so a second copy of this
|
|
129
|
+
* package is still recognized).
|
|
130
|
+
*/
|
|
131
|
+
export function isSousError(value) {
|
|
132
|
+
return (value instanceof SousError ||
|
|
133
|
+
(value instanceof Error && typeof value.sousErrorKind === "string"));
|
|
134
|
+
}
|
|
135
|
+
/** Whether a value is a sous error of one kind. */
|
|
136
|
+
export function isSousErrorOfKind(value, kind) {
|
|
137
|
+
return isSousError(value) && value.sousErrorKind === kind;
|
|
138
|
+
}
|
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { Context } from "./context.js";
|
|
2
|
+
import type { BuiltConfig } from "./config.js";
|
|
3
|
+
import type { CoreEvents, IntentInput, IntentReturn, SousEvents, SousIntents } from "./registry.js";
|
|
4
|
+
/** What every event has. */
|
|
5
|
+
export interface EventBase {
|
|
6
|
+
/** The event's name: `build.before`, `diagrams.rendered`. */
|
|
7
|
+
readonly name: string;
|
|
8
|
+
/** Shared with later listeners, and from an intent's `before` event to its `after` event. */
|
|
9
|
+
readonly data: Map<string, unknown>;
|
|
10
|
+
/** Stops the intent (or tells the emitter of a custom event to stop); the reason is reported. */
|
|
11
|
+
cancel(reason: string): void;
|
|
12
|
+
/** Whether a listener cancelled it. */
|
|
13
|
+
readonly cancelled: boolean;
|
|
14
|
+
/** The reason given to {@link cancel}. */
|
|
15
|
+
readonly cancelReason: string | undefined;
|
|
16
|
+
/** The plugin whose listener cancelled it. */
|
|
17
|
+
readonly cancelledBy: string | undefined;
|
|
18
|
+
/** Later listeners don't see this event. An intent still runs. */
|
|
19
|
+
stopPropagation(): void;
|
|
20
|
+
/** Whether a listener stopped propagation. */
|
|
21
|
+
readonly propagationStopped: boolean;
|
|
22
|
+
}
|
|
23
|
+
/** A custom event, fired with `emit`. */
|
|
24
|
+
export interface CustomEvent<P = unknown> extends EventBase {
|
|
25
|
+
readonly kind: "custom";
|
|
26
|
+
payload: P;
|
|
27
|
+
}
|
|
28
|
+
/** `<intent>.before`: fired before the handler runs. Listeners may change `input`. */
|
|
29
|
+
export interface IntentBeforeEvent<I extends string = string, In = IntentInput<I>> extends EventBase {
|
|
30
|
+
readonly kind: "before";
|
|
31
|
+
readonly intent: I;
|
|
32
|
+
input: In;
|
|
33
|
+
}
|
|
34
|
+
/** `<intent>.after`: fired after the handler returned. Listeners may replace `result`, its outputs. */
|
|
35
|
+
export interface IntentAfterEvent<I extends string = string, In = IntentInput<I>, R = IntentReturn<I>> extends EventBase {
|
|
36
|
+
readonly kind: "after";
|
|
37
|
+
readonly intent: I;
|
|
38
|
+
readonly input: In;
|
|
39
|
+
result: R;
|
|
40
|
+
}
|
|
41
|
+
/** `<intent>.error`: fired when the handler threw. A listener may turn the failure into outputs. */
|
|
42
|
+
export interface IntentErrorEvent<I extends string = string, In = IntentInput<I>, R = IntentReturn<I>> extends EventBase {
|
|
43
|
+
readonly kind: "error";
|
|
44
|
+
readonly intent: I;
|
|
45
|
+
readonly input: In;
|
|
46
|
+
readonly error: unknown;
|
|
47
|
+
/** Turns the failure into these outputs; the intent then succeeds and `after` fires. */
|
|
48
|
+
recover(result: R): void;
|
|
49
|
+
/** Whether a listener recovered. */
|
|
50
|
+
readonly recovered: boolean;
|
|
51
|
+
}
|
|
52
|
+
/** Any event, for regular expression listeners, which narrow by `event.name` or `event.kind`. */
|
|
53
|
+
export type AnyEvent = CustomEvent<unknown> | IntentBeforeEvent | IntentAfterEvent | IntentErrorEvent;
|
|
54
|
+
/** The payload of `config.built`. */
|
|
55
|
+
export interface ConfigBuiltPayload {
|
|
56
|
+
/** The config that was just built. */
|
|
57
|
+
config: BuiltConfig;
|
|
58
|
+
}
|
|
59
|
+
/** Every custom event TypeScript knows about. */
|
|
60
|
+
export type AllEvents = CoreEvents & SousEvents;
|
|
61
|
+
type KnownIntent = keyof SousIntents & string;
|
|
62
|
+
/** Every event name TypeScript knows about: custom events, and every intent's three events. */
|
|
63
|
+
export type KnownEventName = (keyof AllEvents & string) | `${KnownIntent}.${"before" | "after" | "error"}`;
|
|
64
|
+
type CustomOrAny<N extends string> = N extends keyof AllEvents ? CustomEvent<AllEvents[N]> : AnyEvent;
|
|
65
|
+
/**
|
|
66
|
+
* The event object a listener for one exact name receives. An intent's three events are typed from
|
|
67
|
+
* `SousIntents`; for an intent no plugin declared, the input and result are `unknown`.
|
|
68
|
+
*/
|
|
69
|
+
export type EventFor<N extends string> = N extends keyof AllEvents ? CustomEvent<AllEvents[N]> : N extends `${infer I}.before` ? I extends KnownIntent ? IntentBeforeEvent<I> : IntentBeforeEvent<I, unknown> : N extends `${infer I}.after` ? I extends KnownIntent ? IntentAfterEvent<I> : IntentAfterEvent<I, unknown, unknown> : N extends `${infer I}.error` ? I extends KnownIntent ? IntentErrorEvent<I> : IntentErrorEvent<I, unknown, unknown> : CustomOrAny<N>;
|
|
70
|
+
/** Turns a wildcard pattern into a template literal type: `build.*` becomes `build.${string}`. */
|
|
71
|
+
export type PatternTemplate<P extends string> = P extends `${infer A}*${infer B}` ? `${A}${string}${PatternTemplate<B>}` : P;
|
|
72
|
+
/** The event names a pattern matches, among those TypeScript knows. */
|
|
73
|
+
export type MatchingEventNames<P extends string> = Extract<KnownEventName, PatternTemplate<P>>;
|
|
74
|
+
/**
|
|
75
|
+
* The event a listener receives for a pattern: an exact name gives that event, a wildcard the union
|
|
76
|
+
* of every matching known event, and a regular expression {@link AnyEvent}.
|
|
77
|
+
*/
|
|
78
|
+
export type EventForPattern<P extends EventPattern> = P extends RegExp ? AnyEvent : P extends `${string}*${string}` ? [MatchingEventNames<P & string>] extends [never] ? AnyEvent : EventFor<MatchingEventNames<P & string>> : EventFor<P & string>;
|
|
79
|
+
/** What a listener subscribes to: an exact name, a wildcard (`build.*`, `*.before`) or a regular expression. */
|
|
80
|
+
export type EventPattern = string | RegExp;
|
|
81
|
+
/** A listener. It gets a `ctx` like a handler's, so it can run intents, read the config and report. */
|
|
82
|
+
export type Listener<E = AnyEvent> = (event: E, ctx: Context) => void | Promise<void>;
|
|
83
|
+
/** Options for `on` and `once`. */
|
|
84
|
+
export interface ListenerOptions {
|
|
85
|
+
/** Higher runs first. Default `0`. */
|
|
86
|
+
priority?: number;
|
|
87
|
+
}
|
|
88
|
+
/** The payload type of a custom event. */
|
|
89
|
+
export type EventPayload<N extends string> = N extends keyof AllEvents ? AllEvents[N] : unknown;
|
|
90
|
+
export {};
|
package/dist/events.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handlers: functions a plugin (or a recipe's manifest) provides for a purpose, such as checking
|
|
3
|
+
* that a command is installed before a build. `sous.handlers.add(purpose, { id, handle })` adds one
|
|
4
|
+
* from a plugin's `register()`. The `handler` entity kind, the helpers a handler receives and the
|
|
5
|
+
* intents that run them belong to `@sous-io/sous-plugin-handlers`, which fills in
|
|
6
|
+
* {@link SousHandlerTypes}.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* sous.handlers.add("check", {
|
|
10
|
+
* id: "knowledge-worker/commands",
|
|
11
|
+
* handle: checkCommands,
|
|
12
|
+
* });
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
/** Every purpose a handler can serve, in the order they are listed in the documentation. */
|
|
16
|
+
export declare const HANDLER_PURPOSES: readonly ["check", "configure", "beforeBuild", "afterBuild", "uninstall", "migrate"];
|
|
17
|
+
/** A purpose a handler serves. The set is fixed for now. */
|
|
18
|
+
export type HandlerPurpose = (typeof HANDLER_PURPOSES)[number];
|
|
19
|
+
/**
|
|
20
|
+
* Filled in by `@sous-io/sous-plugin-handlers` through declaration merging:
|
|
21
|
+
* `tools` is what a handler receives as `sous`, and `inputs` what each purpose passes second.
|
|
22
|
+
*/
|
|
23
|
+
export interface SousHandlerTypes {
|
|
24
|
+
}
|
|
25
|
+
/** What a handler receives as its first argument (`sous`). */
|
|
26
|
+
export type HandlerToolsOf = SousHandlerTypes extends {
|
|
27
|
+
tools: infer T;
|
|
28
|
+
} ? T : unknown;
|
|
29
|
+
/** What a handler of one purpose receives as its second argument. */
|
|
30
|
+
export type HandlerInputOf<P extends HandlerPurpose> = SousHandlerTypes extends {
|
|
31
|
+
inputs: infer I;
|
|
32
|
+
} ? P extends keyof I ? I[P] : undefined : unknown;
|
|
33
|
+
/** A handler: the same function body works whether a manifest points at it or a plugin registers it. */
|
|
34
|
+
export type HandlerFunction<P extends HandlerPurpose = HandlerPurpose> = (sous: HandlerToolsOf, input: HandlerInputOf<P>) => unknown;
|
|
35
|
+
/** What `sous.handlers.add` takes. */
|
|
36
|
+
export interface HandlerRegistration<P extends HandlerPurpose = HandlerPurpose> {
|
|
37
|
+
/** Names the handler in timings and reports: `knowledge-worker/commands`. Unique among handlers. */
|
|
38
|
+
id: string;
|
|
39
|
+
handle: HandlerFunction<P>;
|
|
40
|
+
/** Moves it within its purpose: lower runs earlier. Default `500`. */
|
|
41
|
+
order?: number;
|
|
42
|
+
}
|
|
43
|
+
/** `sous.handlers`. */
|
|
44
|
+
export interface HandlerRegistry {
|
|
45
|
+
/** Adds a handler for a purpose, as a `handler` entity of this plugin. */
|
|
46
|
+
add<const P extends HandlerPurpose>(purpose: P, definition: HandlerRegistration<P>): void;
|
|
47
|
+
}
|
package/dist/handlers.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handlers: functions a plugin (or a recipe's manifest) provides for a purpose, such as checking
|
|
3
|
+
* that a command is installed before a build. `sous.handlers.add(purpose, { id, handle })` adds one
|
|
4
|
+
* from a plugin's `register()`. The `handler` entity kind, the helpers a handler receives and the
|
|
5
|
+
* intents that run them belong to `@sous-io/sous-plugin-handlers`, which fills in
|
|
6
|
+
* {@link SousHandlerTypes}.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* sous.handlers.add("check", {
|
|
10
|
+
* id: "knowledge-worker/commands",
|
|
11
|
+
* handle: checkCommands,
|
|
12
|
+
* });
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
/** Every purpose a handler can serve, in the order they are listed in the documentation. */
|
|
16
|
+
export const HANDLER_PURPOSES = ["check", "configure", "beforeBuild", "afterBuild", "uninstall", "migrate"];
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The plugin interface of sous: the one promise sous makes outside its
|
|
3
|
+
* monorepo. It holds `definePlugin`, the interfaces plugins add their types to, every public
|
|
4
|
+
* type, the `Reporter` and `Prompter` interfaces and the error classes. Everything else a plugin
|
|
5
|
+
* uses is handed to it in `register(sous)` and in each `ctx`.
|
|
6
|
+
*/
|
|
7
|
+
export type * from "./config.js";
|
|
8
|
+
export type * from "./context.js";
|
|
9
|
+
export type * from "./entities.js";
|
|
10
|
+
export type * from "./events.js";
|
|
11
|
+
export type * from "./intents.js";
|
|
12
|
+
export type * from "./json.js";
|
|
13
|
+
export type * from "./node.js";
|
|
14
|
+
export type * from "./registry.js";
|
|
15
|
+
export type * from "./services.js";
|
|
16
|
+
export { definePlugin } from "./plugin.js";
|
|
17
|
+
export { HANDLER_PURPOSES } from "./handlers.js";
|
|
18
|
+
export type * from "./handlers.js";
|
|
19
|
+
export type * from "./plugin.js";
|
|
20
|
+
export { CancelledError, ConfigError, ConflictError, InputError, isSousError, isSousErrorOfKind, LoopError, NonInteractiveError, NotFoundError, PluginError, SousError, } from "./errors.js";
|
|
21
|
+
export type { InputIssue, SousErrorKind, SousErrorOptions } from "./errors.js";
|
|
22
|
+
export { nonInteractivePrompter, scriptedPrompter } from "./prompter.js";
|
|
23
|
+
export type * from "./prompter.js";
|
|
24
|
+
export { BaseReporter, BufferedReporter, createReporter, isLevelShown, isLogLevel, LOG_LEVELS, errorChain, LogLevel, messageText, nullReporter, ReportEntryStyle, Reporting, } from "./reporter.js";
|
|
25
|
+
export type * from "./reporter.js";
|
|
26
|
+
export { commandVariables } from "./command-variables.js";
|
|
27
|
+
export { DataValue, IntentOutput, IntentOutputs, ItemList, Payload, Table, TextBlock, Tree, VariableSet } from "./outputs.js";
|
|
28
|
+
export type * from "./outputs.js";
|
|
29
|
+
export { formatIssuePath, isSchema, jsonSchema, toJsonSchema, validateWith, validateWithSync } from "./schema.js";
|
|
30
|
+
export type * from "./schema.js";
|
|
31
|
+
export { TIMING_CATEGORIES } from "./timing.js";
|
|
32
|
+
export type * from "./timing.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The plugin interface of sous: the one promise sous makes outside its
|
|
3
|
+
* monorepo. It holds `definePlugin`, the interfaces plugins add their types to, every public
|
|
4
|
+
* type, the `Reporter` and `Prompter` interfaces and the error classes. Everything else a plugin
|
|
5
|
+
* uses is handed to it in `register(sous)` and in each `ctx`.
|
|
6
|
+
*/
|
|
7
|
+
export { definePlugin } from "./plugin.js";
|
|
8
|
+
export { HANDLER_PURPOSES } from "./handlers.js";
|
|
9
|
+
export { CancelledError, ConfigError, ConflictError, InputError, isSousError, isSousErrorOfKind, LoopError, NonInteractiveError, NotFoundError, PluginError, SousError, } from "./errors.js";
|
|
10
|
+
export { nonInteractivePrompter, scriptedPrompter } from "./prompter.js";
|
|
11
|
+
export { BaseReporter, BufferedReporter, createReporter, isLevelShown, isLogLevel, LOG_LEVELS, errorChain, LogLevel, messageText, nullReporter, ReportEntryStyle, Reporting, } from "./reporter.js";
|
|
12
|
+
export { commandVariables } from "./command-variables.js";
|
|
13
|
+
export { DataValue, IntentOutput, IntentOutputs, ItemList, Payload, Table, TextBlock, Tree, VariableSet } from "./outputs.js";
|
|
14
|
+
export { formatIssuePath, isSchema, jsonSchema, toJsonSchema, validateWith, validateWithSync } from "./schema.js";
|
|
15
|
+
export { TIMING_CATEGORIES } from "./timing.js";
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import type { Context } from "./context.js";
|
|
2
|
+
import type { Prompter } from "./prompter.js";
|
|
3
|
+
import type { IntentInput, IntentReturn, SousIntents } from "./registry.js";
|
|
4
|
+
import type { Reporter } from "./reporter.js";
|
|
5
|
+
import type { InferOutput, SousSchema } from "./schema.js";
|
|
6
|
+
/** A handler: runs an intent and returns its outputs (see S1, "What an intent returns"). */
|
|
7
|
+
export type IntentHandler<In = any, Result = unknown> = (input: In, ctx: Context) => Result | Promise<Result>;
|
|
8
|
+
/**
|
|
9
|
+
* A wrapper changes what an intent's handler does. Wrappers stack in plugin order: the wrapper of
|
|
10
|
+
* the plugin loaded last runs first and calls `next`, down to the handler.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* sous.intents.wrap("build", (next) => async (input, ctx) => {
|
|
14
|
+
* const outputs = await next(input, ctx);
|
|
15
|
+
*
|
|
16
|
+
* return outputs.with(new IntentOutput({ title: "Diagrams", result: await renderDiagrams(ctx) }));
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export type IntentWrapper<In = any, Result = unknown> = (next: IntentHandler<In, Result>) => IntentHandler<In, Result>;
|
|
21
|
+
/** How the CLI shows an intent. */
|
|
22
|
+
export interface CliSection {
|
|
23
|
+
/** The command words. Default: the intent's name split at dots (`namespace.list` → `namespace list`). */
|
|
24
|
+
command?: readonly string[];
|
|
25
|
+
/** More command words that run it, in any group (`["ns", "list"]`, `["list", "namespaces"]`). */
|
|
26
|
+
aliases?: ReadonlyArray<readonly string[]>;
|
|
27
|
+
/** Input fields given as positional arguments, in order. The last may be an array, taking the rest. */
|
|
28
|
+
positional?: readonly string[];
|
|
29
|
+
/**
|
|
30
|
+
* Hands every token the command does not know (unknown flags, extra arguments, everything after
|
|
31
|
+
* `--`) to its last positional, in the order typed, instead of failing: `sous launch claude-code
|
|
32
|
+
* --resume -- -c` gives `tool: ["claude-code", "--resume", "-c"]`. The last positional must be an array.
|
|
33
|
+
*/
|
|
34
|
+
passThrough?: boolean;
|
|
35
|
+
/** Example command lines for `--help`. */
|
|
36
|
+
examples?: readonly string[];
|
|
37
|
+
/** Keeps it out of help and suggestions; it still runs. */
|
|
38
|
+
hidden?: boolean;
|
|
39
|
+
/** Per input field: a one-letter short flag (`y` for `-y`), more flag names, or hiding it from help. */
|
|
40
|
+
flags?: Readonly<Record<string, CliFlagOptions>>;
|
|
41
|
+
}
|
|
42
|
+
/** CLI options for one input field. */
|
|
43
|
+
export interface CliFlagOptions {
|
|
44
|
+
/** A one-letter short form, without the dash. */
|
|
45
|
+
short?: string;
|
|
46
|
+
/** More long names, without the dashes. Shown in help only when not hidden. */
|
|
47
|
+
aliases?: readonly string[];
|
|
48
|
+
/** Keeps the flag out of `--help`. */
|
|
49
|
+
hidden?: boolean;
|
|
50
|
+
}
|
|
51
|
+
/** How agents see an intent through MCP. */
|
|
52
|
+
export interface AgentSection {
|
|
53
|
+
/** The tool name. Default: the intent's name with dots as underscores (`namespace_list`). */
|
|
54
|
+
tool?: string;
|
|
55
|
+
/** When and how to use it. */
|
|
56
|
+
usage?: string;
|
|
57
|
+
/** When not to use it, and what to use instead. */
|
|
58
|
+
whenNotToUse?: string;
|
|
59
|
+
/** Keeps it out of MCP. */
|
|
60
|
+
hidden?: boolean;
|
|
61
|
+
}
|
|
62
|
+
/** The handler module an intent can load lazily, so `--help` never imports command code. */
|
|
63
|
+
export type IntentHandlerModule<In, Result> = IntentHandler<In, Result> | {
|
|
64
|
+
default: IntentHandler<In, Result>;
|
|
65
|
+
} | {
|
|
66
|
+
handle: IntentHandler<In, Result>;
|
|
67
|
+
};
|
|
68
|
+
/** The input type an intent's handler receives: the declared type, or the schema's output. */
|
|
69
|
+
export type IntentInputOf<N extends string, S> = N extends keyof SousIntents ? IntentInput<N> : InferOutput<S>;
|
|
70
|
+
/**
|
|
71
|
+
* An intent: a step a user or another plugin asks for, with a typed input and one handler. The CLI's commands and flags and the MCP server's tools are generated from it.
|
|
72
|
+
*
|
|
73
|
+
* Give either `handle`, or `load` to import the handler only when the intent runs.
|
|
74
|
+
*/
|
|
75
|
+
export interface IntentDefinition<N extends string = string, S extends SousSchema = SousSchema> {
|
|
76
|
+
/** The name, `<plugin>.<verb>`: `diagrams.render`, `subscription.add`. */
|
|
77
|
+
intent: N;
|
|
78
|
+
/** One sentence saying what it does, for help, tools and the web GUI. */
|
|
79
|
+
summary?: string;
|
|
80
|
+
/** More about it, for `--help`. */
|
|
81
|
+
description?: string;
|
|
82
|
+
/** The input schema. Every input is a flag. Default: no input. */
|
|
83
|
+
input?: S;
|
|
84
|
+
/** The result schema, for front ends that describe results (MCP). */
|
|
85
|
+
output?: SousSchema;
|
|
86
|
+
/** Runs outside the scheduler, such as `mcp.serve`; it submits chains instead of using `ctx.run`. */
|
|
87
|
+
background?: boolean;
|
|
88
|
+
/** A chain started with this intent may run beside other parallel chains: it writes nothing others read. */
|
|
89
|
+
parallel?: boolean;
|
|
90
|
+
/** Running it changes the config, so the engine rebuilds the config before the next chain. */
|
|
91
|
+
changesConfig?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* It can run when the config fails to build (`sous upgrade` repairing a broken install): it runs
|
|
94
|
+
* with whatever partial config the failed build reached (the plugins it activated, the values
|
|
95
|
+
* it merged, unchecked), and the build's error is reported as a warning. Other intents fail
|
|
96
|
+
* with that error.
|
|
97
|
+
*/
|
|
98
|
+
toleratesConfigErrors?: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* `boolean = false`. It reads nothing from the config's values, only from what the built-in
|
|
101
|
+
* plugins registered (the command tree, the version), so the front end may run it before the
|
|
102
|
+
* config is built, when the project loads no plugin beyond the built-in ones.
|
|
103
|
+
*/
|
|
104
|
+
runsWithoutConfig?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* `boolean = false`. It reads the files of the recipes the project subscribes to (their config
|
|
107
|
+
* layers, plugins, variables or content), so sous downloads every pinned recipe this machine lacks
|
|
108
|
+
* before it runs, and fails when one cannot be downloaded. Any other intent runs with the recipe
|
|
109
|
+
* files already on this machine, so it works offline and without credentials.
|
|
110
|
+
*/
|
|
111
|
+
needsRecipeFiles?: boolean;
|
|
112
|
+
/**
|
|
113
|
+
* It works on a project, so it fails, before it runs, when sous was started outside one: the
|
|
114
|
+
* error says no sous config was found and how to set a project up.
|
|
115
|
+
*/
|
|
116
|
+
requiresProject?: boolean;
|
|
117
|
+
/** Only callable through `ctx.run`; neither the CLI nor MCP shows it. */
|
|
118
|
+
internal?: boolean;
|
|
119
|
+
/** How the CLI shows it. */
|
|
120
|
+
cli?: CliSection;
|
|
121
|
+
/** How agents see it. */
|
|
122
|
+
agent?: AgentSection;
|
|
123
|
+
/** Runs the intent and returns its outputs: `new IntentOutputs(new IntentOutput({ ... }))`. */
|
|
124
|
+
handle?: IntentHandler<IntentInputOf<N, S>, IntentReturn<N>>;
|
|
125
|
+
/** Imports the handler when the intent first runs. */
|
|
126
|
+
load?: () => Promise<IntentHandlerModule<IntentInputOf<N, S>, IntentReturn<N>>>;
|
|
127
|
+
}
|
|
128
|
+
/** An intent and the plugin that added it, as front ends see it. */
|
|
129
|
+
export interface IntentInfo {
|
|
130
|
+
readonly definition: IntentDefinition;
|
|
131
|
+
/** The plugin that added it. */
|
|
132
|
+
readonly plugin: string;
|
|
133
|
+
}
|
|
134
|
+
/** What front ends read about the intents: every one that is loaded and active. */
|
|
135
|
+
export interface IntentCatalog {
|
|
136
|
+
/** Every active intent, in plugin order. */
|
|
137
|
+
list(): IntentInfo[];
|
|
138
|
+
/** One intent, or `undefined`. */
|
|
139
|
+
get(name: string): IntentInfo | undefined;
|
|
140
|
+
}
|
|
141
|
+
/** Asking the engine to run an intent. */
|
|
142
|
+
export interface IntentRequest<N extends string = string> {
|
|
143
|
+
intent: N;
|
|
144
|
+
input?: IntentInput<N> | Record<string, unknown>;
|
|
145
|
+
}
|
|
146
|
+
/** How a front end submits a chain. */
|
|
147
|
+
export interface SubmitOptions {
|
|
148
|
+
/** Where the chain's output goes. Default: the engine's reporter. */
|
|
149
|
+
reporter?: Reporter;
|
|
150
|
+
/** Where the chain's questions go. Default: a prompter that cannot ask. */
|
|
151
|
+
prompter?: Prompter;
|
|
152
|
+
/** Declares the chain parallel. Default: what the intent declares. */
|
|
153
|
+
parallel?: boolean;
|
|
154
|
+
/** Values of the front end's global arguments (`--debug`, plugin-added ones), as `ctx.globals`. */
|
|
155
|
+
globals?: Readonly<Record<string, unknown>>;
|
|
156
|
+
/** The working directory, as `ctx.cwd` (the CLI: the process's; MCP: the project root). Default: the engine's. */
|
|
157
|
+
cwd?: string;
|
|
158
|
+
}
|
package/dist/intents.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|