@canonical/summon-core 0.30.0 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/execute/GeneratorResult.js +13 -0
- package/dist/esm/execute/GeneratorResult.js.map +1 -0
- package/dist/esm/execute/collectAnswers.js +92 -0
- package/dist/esm/execute/collectAnswers.js.map +1 -0
- package/dist/esm/execute/execute.js +73 -0
- package/dist/esm/execute/execute.js.map +1 -0
- package/dist/esm/execute/index.js +4 -0
- package/dist/esm/execute/index.js.map +1 -0
- package/dist/esm/execute/validateAnswers.js +47 -0
- package/dist/esm/execute/validateAnswers.js.map +1 -0
- package/dist/esm/format/effects.js +581 -0
- package/dist/esm/format/effects.js.map +1 -0
- package/dist/esm/format/index.js +2 -0
- package/dist/esm/format/index.js.map +1 -0
- package/dist/esm/index.js +8 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/prompt/answerPromptWithDefaults.js +26 -0
- package/dist/esm/prompt/answerPromptWithDefaults.js.map +1 -0
- package/dist/esm/prompt/autoPrompt.js +50 -0
- package/dist/esm/prompt/autoPrompt.js.map +1 -0
- package/dist/esm/prompt/index.js +12 -0
- package/dist/esm/prompt/index.js.map +1 -0
- package/dist/esm/prompt/ink/Spinner.js +18 -0
- package/dist/esm/prompt/ink/Spinner.js.map +1 -0
- package/dist/esm/prompt/ink/Wizard.js +107 -0
- package/dist/esm/prompt/ink/Wizard.js.map +1 -0
- package/dist/esm/prompt/ink/mount.js +41 -0
- package/dist/esm/prompt/ink/mount.js.map +1 -0
- package/dist/esm/prompt/ink/prompts.js +144 -0
- package/dist/esm/prompt/ink/prompts.js.map +1 -0
- package/dist/esm/prompt/ink/session.js +176 -0
- package/dist/esm/prompt/ink/session.js.map +1 -0
- package/dist/esm/prompt/inkPrompt.js +55 -0
- package/dist/esm/prompt/inkPrompt.js.map +1 -0
- package/dist/esm/prompt/mcpPrompt.js +29 -0
- package/dist/esm/prompt/mcpPrompt.js.map +1 -0
- package/dist/esm/prompt/types.js +12 -0
- package/dist/esm/prompt/types.js.map +1 -0
- package/dist/esm/run/index.js +2 -0
- package/dist/esm/run/index.js.map +1 -0
- package/dist/esm/run/runGeneratorTask.js +63 -0
- package/dist/esm/run/runGeneratorTask.js.map +1 -0
- package/dist/esm/stamp/createGeneratorStamp.js +19 -0
- package/dist/esm/stamp/createGeneratorStamp.js.map +1 -0
- package/dist/esm/stamp/createStampOnEffectStart.js +23 -0
- package/dist/esm/stamp/createStampOnEffectStart.js.map +1 -0
- package/dist/esm/stamp/index.js +2 -0
- package/dist/esm/stamp/index.js.map +1 -1
- package/dist/types/execute/GeneratorResult.d.ts +23 -0
- package/dist/types/execute/GeneratorResult.d.ts.map +1 -0
- package/dist/types/execute/collectAnswers.d.ts +52 -0
- package/dist/types/execute/collectAnswers.d.ts.map +1 -0
- package/dist/types/execute/execute.d.ts +57 -0
- package/dist/types/execute/execute.d.ts.map +1 -0
- package/dist/types/execute/index.d.ts +6 -0
- package/dist/types/execute/index.d.ts.map +1 -0
- package/dist/types/execute/validateAnswers.d.ts +23 -0
- package/dist/types/execute/validateAnswers.d.ts.map +1 -0
- package/dist/types/format/effects.d.ts +86 -0
- package/dist/types/format/effects.d.ts.map +1 -0
- package/dist/types/format/index.d.ts +2 -0
- package/dist/types/format/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +8 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/prompt/answerPromptWithDefaults.d.ts +17 -0
- package/dist/types/prompt/answerPromptWithDefaults.d.ts.map +1 -0
- package/dist/types/prompt/autoPrompt.d.ts +35 -0
- package/dist/types/prompt/autoPrompt.d.ts.map +1 -0
- package/dist/types/prompt/index.d.ts +14 -0
- package/dist/types/prompt/index.d.ts.map +1 -0
- package/dist/types/prompt/ink/Spinner.d.ts +11 -0
- package/dist/types/prompt/ink/Spinner.d.ts.map +1 -0
- package/dist/types/prompt/ink/Wizard.d.ts +14 -0
- package/dist/types/prompt/ink/Wizard.d.ts.map +1 -0
- package/dist/types/prompt/ink/mount.d.ts +31 -0
- package/dist/types/prompt/ink/mount.d.ts.map +1 -0
- package/dist/types/prompt/ink/prompts.d.ts +26 -0
- package/dist/types/prompt/ink/prompts.d.ts.map +1 -0
- package/dist/types/prompt/ink/session.d.ts +103 -0
- package/dist/types/prompt/ink/session.d.ts.map +1 -0
- package/dist/types/prompt/inkPrompt.d.ts +64 -0
- package/dist/types/prompt/inkPrompt.d.ts.map +1 -0
- package/dist/types/prompt/mcpPrompt.d.ts +20 -0
- package/dist/types/prompt/mcpPrompt.d.ts.map +1 -0
- package/dist/types/prompt/types.d.ts +23 -0
- package/dist/types/prompt/types.d.ts.map +1 -0
- package/dist/types/run/index.d.ts +3 -0
- package/dist/types/run/index.d.ts.map +1 -0
- package/dist/types/run/runGeneratorTask.d.ts +51 -0
- package/dist/types/run/runGeneratorTask.d.ts.map +1 -0
- package/dist/types/stamp/createGeneratorStamp.d.ts +16 -0
- package/dist/types/stamp/createGeneratorStamp.d.ts.map +1 -0
- package/dist/types/stamp/createStampOnEffectStart.d.ts +17 -0
- package/dist/types/stamp/createStampOnEffectStart.d.ts.map +1 -0
- package/dist/types/stamp/index.d.ts +2 -0
- package/dist/types/stamp/index.d.ts.map +1 -1
- package/dist/types/types/AnyGenerator.d.ts +1 -1
- package/dist/types/types/AnyGenerator.d.ts.map +1 -1
- package/dist/types/types/ForbidReserved.d.ts +1 -1
- package/dist/types/types/ForbidReserved.d.ts.map +1 -1
- package/dist/types/types/ReservedOption.d.ts +1 -1
- package/dist/types/types/ReservedOption.d.ts.map +1 -1
- package/package.json +17 -10
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The interactive Ink prompt strategy — the embedded #819 wizard, seam-backed.
|
|
3
|
+
*
|
|
4
|
+
* CRITICAL (lazy-React discipline): this module's STATIC import graph contains
|
|
5
|
+
* NO JSX and NO `import` of `ink`/`react`. The entire React UI lives under
|
|
6
|
+
* `./ink/**` and is reached ONLY through `await import("./ink/mount.js")` on the
|
|
7
|
+
* first `Prompt` effect. So importing summon-core — or building the pragma
|
|
8
|
+
* command tree, or running `create --yes` (which picks {@link autoPrompt}) —
|
|
9
|
+
* never loads React. The lazy-React guard test enforces this boundary.
|
|
10
|
+
*
|
|
11
|
+
* The session is SESSION-backed, not per-question: one persistent Ink render is
|
|
12
|
+
* stood up on the first prompt and torn down on completion or abort, so it
|
|
13
|
+
* preserves the step-N-of-M header, the live answers table, and the
|
|
14
|
+
* preview/confirm gate across the whole run. The runner feeds it two streams —
|
|
15
|
+
* `Prompt` effects (via `promptHandler`) and effect progress (via
|
|
16
|
+
* `onEffectStart`/`onEffectComplete`/`onLog`) — and it renders both.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Build the interactive Ink session for a generator.
|
|
20
|
+
*
|
|
21
|
+
* The Ink render is not created until the first `Prompt` effect arrives (which
|
|
22
|
+
* dynamically imports the React UI), so picking this strategy on a fast path
|
|
23
|
+
* that never prompts costs nothing and loads no React.
|
|
24
|
+
*
|
|
25
|
+
* @param generator - The generator being run (the session dry-runs it to build
|
|
26
|
+
* the confirm gate's preview).
|
|
27
|
+
* @param options - The abort signal.
|
|
28
|
+
* @returns The {@link InkSession} the `create` verb wires into `runtime.exec`.
|
|
29
|
+
*/
|
|
30
|
+
export default function inkPrompt(generator, options = {}) {
|
|
31
|
+
let mountP;
|
|
32
|
+
let mounted;
|
|
33
|
+
const ensure = () => {
|
|
34
|
+
mountP ??= import("./ink/mount.js").then((mod) => {
|
|
35
|
+
mounted = mod.mountPromptSession(generator, options);
|
|
36
|
+
return mounted;
|
|
37
|
+
});
|
|
38
|
+
return mountP;
|
|
39
|
+
};
|
|
40
|
+
// Cancellation propagates by REJECTION: controller.cancel() rejects the
|
|
41
|
+
// pending answer promise, so a declined/aborted run fails the task straight
|
|
42
|
+
// through here — no separate interrupted flag to read.
|
|
43
|
+
const promptHandler = async (effect) => {
|
|
44
|
+
const session = await ensure();
|
|
45
|
+
return session.answerPrompt(effect);
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
promptHandler,
|
|
49
|
+
onEffectStart: (effect) => mounted?.reportEffectStart(effect),
|
|
50
|
+
onEffectComplete: (effect, duration) => mounted?.reportEffectComplete(effect, duration),
|
|
51
|
+
onLog: (level, message) => mounted?.reportLog(level, message),
|
|
52
|
+
dispose: () => mounted?.dispose(),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=inkPrompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inkPrompt.js","sourceRoot":"","sources":["../../../src/prompt/inkPrompt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AA+CH;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,SAA8B,EAC9B,UAA4B,EAAE;IAE9B,IAAI,MAA2C,CAAC;IAChD,IAAI,OAAmC,CAAC;IAExC,MAAM,MAAM,GAAG,GAA4B,EAAE;QAC3C,MAAM,KAAK,MAAM,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;YAC/C,OAAO,GAAG,GAAG,CAAC,kBAAkB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;YACrD,OAAO,OAAO,CAAC;QACjB,CAAC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;IAEF,wEAAwE;IACxE,4EAA4E;IAC5E,uDAAuD;IACvD,MAAM,aAAa,GAAkB,KAAK,EAAE,MAAM,EAAE,EAAE;QACpD,MAAM,OAAO,GAAG,MAAM,MAAM,EAAE,CAAC;QAC/B,OAAO,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC,CAAC;IAEF,OAAO;QACL,aAAa;QACb,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,EAAE,iBAAiB,CAAC,MAAM,CAAC;QAC7D,gBAAgB,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,CACrC,OAAO,EAAE,oBAAoB,CAAC,MAAM,EAAE,QAAQ,CAAC;QACjD,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC;QAC7D,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE;KAClC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The MCP prompt strategy: resolve every answer from the tool arguments or the
|
|
3
|
+
* prompt's default, and fail structurally otherwise — never block on stdin.
|
|
4
|
+
*
|
|
5
|
+
* An MCP tool call carries all inputs up front as arguments; there is no
|
|
6
|
+
* interactive channel. This handler resolves each `Prompt` effect from the
|
|
7
|
+
* provided `params` (defensively — {@link collectAnswers} already skips provided
|
|
8
|
+
* answers), then the prompt's declared default, and otherwise rejects with a
|
|
9
|
+
* structured `MISSING_REQUIRED_ANSWER` task error. It is synchronous-resolving
|
|
10
|
+
* by construction, so a mutating tool can never hang waiting for input.
|
|
11
|
+
*/
|
|
12
|
+
import { missingRequiredError } from "./autoPrompt.js";
|
|
13
|
+
/**
|
|
14
|
+
* A prompt handler that resolves answers from MCP tool args or defaults.
|
|
15
|
+
*
|
|
16
|
+
* @param params - The tool arguments (already coerced to the answer shape).
|
|
17
|
+
* @returns The MCP {@link PromptHandler} — params-or-default-or-error, never a hang.
|
|
18
|
+
*/
|
|
19
|
+
export default function mcpPrompt(params = {}) {
|
|
20
|
+
return (effect) => {
|
|
21
|
+
const q = effect.question;
|
|
22
|
+
if (q.name in params)
|
|
23
|
+
return Promise.resolve(params[q.name]);
|
|
24
|
+
if (q.default !== undefined)
|
|
25
|
+
return Promise.resolve(q.default);
|
|
26
|
+
return Promise.reject(missingRequiredError(effect, "argument"));
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=mcpPrompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcpPrompt.js","sourceRoot":"","sources":["../../../src/prompt/mcpPrompt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAGvD;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,SAA4C,EAAE;IAE9C,OAAO,CAAC,MAAoB,EAAE,EAAE;QAC9B,MAAM,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC;QAC1B,IAAI,CAAC,CAAC,IAAI,IAAI,MAAM;YAAE,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QAC7D,IAAI,CAAC,CAAC,OAAO,KAAK,SAAS;YAAE,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAC/D,OAAO,OAAO,CAAC,MAAM,CAAC,oBAAoB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;IAClE,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The prompt-handling seam types.
|
|
3
|
+
*
|
|
4
|
+
* A {@link PromptHandler} is exactly the shape the task interpreter's
|
|
5
|
+
* `promptHandler` option expects — it receives the whole `Prompt` effect (whose
|
|
6
|
+
* `.question` carries name/message/type/default/choices/validate) and resolves
|
|
7
|
+
* the answer. Every front-end (Ink wizard, MCP args, non-interactive defaults)
|
|
8
|
+
* is one implementation of this single function type, injected into the runner;
|
|
9
|
+
* summon-core never owns a UI toolkit.
|
|
10
|
+
*/
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/prompt/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/run/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The single, UI-free execution point for running a generator or setup Task
|
|
3
|
+
* for real.
|
|
4
|
+
*
|
|
5
|
+
* Every binary — pragma's kernel, summon's Ink TUI — runs its tasks through
|
|
6
|
+
* here. Interactivity is injected as a `promptHandler`, so this core never
|
|
7
|
+
* imports a UI toolkit; the terminal front-ends own that. Centralising
|
|
8
|
+
* execution here gives every command the same working-directory semantics and
|
|
9
|
+
* a single seam where cross-cutting behavior (progress, interception) can be
|
|
10
|
+
* added without touching the callers.
|
|
11
|
+
*
|
|
12
|
+
* Moved into summon-core (from the v1 cli-core) so it sits below both the
|
|
13
|
+
* summon bin and the pragma kernel — the shared seam the byte-equality
|
|
14
|
+
* guarantee rests on. cli-core re-exports it while it is retired.
|
|
15
|
+
*/
|
|
16
|
+
import { runTask } from "@canonical/task/node";
|
|
17
|
+
/**
|
|
18
|
+
* The tail of the queue serialising runs that request a working directory.
|
|
19
|
+
* `process.cwd()` is process-global state, so two concurrent runs with
|
|
20
|
+
* different `cwd` values would race — one could execute its effects in the
|
|
21
|
+
* other's directory, or restore the wrong one. Chaining every cwd-requesting
|
|
22
|
+
* run onto this promise makes them run one at a time; a failed run must not
|
|
23
|
+
* poison the queue, so the stored tail swallows the rejection (the caller
|
|
24
|
+
* still receives it).
|
|
25
|
+
*/
|
|
26
|
+
let cwdQueue = Promise.resolve();
|
|
27
|
+
/**
|
|
28
|
+
* Run a Task for real in the given working directory and return its value.
|
|
29
|
+
*
|
|
30
|
+
* Runs that request a `cwd` are serialised against each other, so concurrent
|
|
31
|
+
* callers cannot interleave `chdir` calls; runs without a `cwd` execute
|
|
32
|
+
* immediately in whatever the current process directory is.
|
|
33
|
+
*
|
|
34
|
+
* @typeParam A - The task's result type.
|
|
35
|
+
* @param task - A freshly-built task to run.
|
|
36
|
+
* @param options - Working directory and injected handlers.
|
|
37
|
+
* @returns The task's value.
|
|
38
|
+
* @note Impure — performs the task's effects and may `chdir`.
|
|
39
|
+
*/
|
|
40
|
+
export default async function runGeneratorTask(task, options = {}) {
|
|
41
|
+
const { cwd, ...runOptions } = options;
|
|
42
|
+
if (cwd === undefined) {
|
|
43
|
+
return runTask(task, runOptions);
|
|
44
|
+
}
|
|
45
|
+
const run = cwdQueue.then(async () => {
|
|
46
|
+
const previousCwd = process.cwd();
|
|
47
|
+
const shouldChdir = cwd !== previousCwd;
|
|
48
|
+
if (shouldChdir) {
|
|
49
|
+
process.chdir(cwd);
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
return await runTask(task, runOptions);
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
if (shouldChdir) {
|
|
56
|
+
process.chdir(previousCwd);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
cwdQueue = run.then(() => undefined, () => undefined);
|
|
61
|
+
return run;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=runGeneratorTask.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runGeneratorTask.js","sourceRoot":"","sources":["../../../src/run/runGeneratorTask.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAuB,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAsBpE;;;;;;;;GAQG;AACH,IAAI,QAAQ,GAAqB,OAAO,CAAC,OAAO,EAAE,CAAC;AAEnD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,gBAAgB,CAC5C,IAAa,EACb,UAAmC,EAAE;IAErC,MAAM,EAAE,GAAG,EAAE,GAAG,UAAU,EAAE,GAAG,OAAO,CAAC;IAEvC,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,OAAO,OAAO,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IACnC,CAAC;IAED,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE;QACnC,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;QAClC,MAAM,WAAW,GAAG,GAAG,KAAK,WAAW,CAAC;QACxC,IAAI,WAAW,EAAE,CAAC;YAChB,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC;QACD,IAAI,CAAC;YACH,OAAO,MAAM,OAAO,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QACzC,CAAC;gBAAS,CAAC;YACT,IAAI,WAAW,EAAE,CAAC;gBAChB,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;YAC7B,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IACH,QAAQ,GAAG,GAAG,CAAC,IAAI,CACjB,GAAG,EAAE,CAAC,SAAS,EACf,GAAG,EAAE,CAAC,SAAS,CAChB,CAAC;IACF,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build the generated-file stamp for a generator.
|
|
3
|
+
*
|
|
4
|
+
* This is the single source of the stamp identity: every binary that stamps
|
|
5
|
+
* output derives its `StampConfig` here, so `pragma create X` and `summon X`
|
|
6
|
+
* embed the identical generator identifier — a requirement of the cross-binary
|
|
7
|
+
* byte-equality guarantee. The display name is preferred (summon's historical
|
|
8
|
+
* stamp format), falling back to the registry name.
|
|
9
|
+
*
|
|
10
|
+
* @param gen - The generator whose output is being stamped.
|
|
11
|
+
* @returns The stamp configuration for the seam transform.
|
|
12
|
+
*/
|
|
13
|
+
export default function createGeneratorStamp(gen) {
|
|
14
|
+
return {
|
|
15
|
+
generator: gen.meta.displayName ?? gen.meta.name,
|
|
16
|
+
version: gen.meta.version,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=createGeneratorStamp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createGeneratorStamp.js","sourceRoot":"","sources":["../../../src/stamp/createGeneratorStamp.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAC1C,GAAwB;IAExB,OAAO;QACL,SAAS,EAAE,GAAG,CAAC,IAAI,CAAC,WAAW,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI;QAChD,OAAO,EAAE,GAAG,CAAC,IAAI,CAAC,OAAO;KAC1B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import applyStamp from "./applyStamp.js";
|
|
2
|
+
/**
|
|
3
|
+
* Build an `onEffectStart` seam callback that prepends the generated-file
|
|
4
|
+
* stamp to every `WriteFile` effect's content before it executes.
|
|
5
|
+
*
|
|
6
|
+
* This is THE stamping path: every binary that stamps generated output does so
|
|
7
|
+
* through this one transform on the shared executor's seam, so `pragma create
|
|
8
|
+
* X` and `summon X` write byte-identical files.
|
|
9
|
+
*
|
|
10
|
+
* @param stamp - The stamp configuration (generator name/version).
|
|
11
|
+
* @param next - An optional downstream `onEffectStart` (e.g. progress UI),
|
|
12
|
+
* invoked after stamping.
|
|
13
|
+
* @returns The composed `onEffectStart` callback.
|
|
14
|
+
*/
|
|
15
|
+
export default function createStampOnEffectStart(stamp, next) {
|
|
16
|
+
return (effect) => {
|
|
17
|
+
if (effect._tag === "WriteFile") {
|
|
18
|
+
effect.content = applyStamp(effect.path, effect.content, stamp);
|
|
19
|
+
}
|
|
20
|
+
next?.(effect);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=createStampOnEffectStart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createStampOnEffectStart.js","sourceRoot":"","sources":["../../../src/stamp/createStampOnEffectStart.ts"],"names":[],"mappings":"AAEA,OAAO,UAAU,MAAM,iBAAiB,CAAC;AAEzC;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,OAAO,UAAU,wBAAwB,CAC9C,KAAkB,EAClB,IAA+B;IAE/B,OAAO,CAAC,MAAM,EAAE,EAAE;QAChB,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YAC/B,MAA8B,CAAC,OAAO,GAAG,UAAU,CAClD,MAAM,CAAC,IAAI,EACX,MAAM,CAAC,OAAO,EACd,KAAK,CACN,CAAC;QACJ,CAAC;QACD,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC;IACjB,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/esm/stamp/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { default as applyStamp } from "./applyStamp.js";
|
|
2
|
+
export { default as createGeneratorStamp } from "./createGeneratorStamp.js";
|
|
3
|
+
export { default as createStampOnEffectStart } from "./createStampOnEffectStart.js";
|
|
2
4
|
export { default as runTaskWithStamp } from "./runTaskWithStamp.js";
|
|
3
5
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/stamp/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/stamp/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,OAAO,IAAI,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACpF,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The value {@link execute} produces.
|
|
3
|
+
*
|
|
4
|
+
* `execute` returns a `Task<GeneratorResult>`; the runner interprets it. The
|
|
5
|
+
* result carries what a front-end needs to render an outcome summary — the
|
|
6
|
+
* generator identity, the resolved answers, and a preview of the effects the
|
|
7
|
+
* generation performed (paths, and best-effort content for embedded-template
|
|
8
|
+
* generators). Progress does NOT ride a bespoke event channel: it rides the
|
|
9
|
+
* runner's `onEffectStart`/`onEffectComplete`/`onLog` callbacks and the task
|
|
10
|
+
* alphabet's own `TaskEvent` — summon-core invents no parallel event system.
|
|
11
|
+
*/
|
|
12
|
+
import type { Effect } from "@canonical/task";
|
|
13
|
+
import type GeneratorDefinition from "../types/GeneratorDefinition.js";
|
|
14
|
+
/** The outcome of running a generator through {@link execute}. */
|
|
15
|
+
export interface GeneratorResult {
|
|
16
|
+
/** The generator that ran (its meta drives the outcome summary + stamp). */
|
|
17
|
+
readonly generator: GeneratorDefinition;
|
|
18
|
+
/** The resolved answers the generation ran with. */
|
|
19
|
+
readonly answers: Record<string, unknown>;
|
|
20
|
+
/** A dry-run preview of the effects the generation performed. */
|
|
21
|
+
readonly effects: Effect[];
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=GeneratorResult.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GeneratorResult.d.ts","sourceRoot":"","sources":["../../../src/execute/GeneratorResult.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,mBAAmB,MAAM,iCAAiC,CAAC;AAEvE,kEAAkE;AAClE,MAAM,WAAW,eAAe;IAC9B,4EAA4E;IAC5E,QAAQ,CAAC,SAAS,EAAE,mBAAmB,CAAC;IACxC,oDAAoD;IACpD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1C,iEAAiE;IACjE,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;CAC5B"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bridge from form-first generators to the dialog-first prompting model:
|
|
3
|
+
* turn a static prompt-definition list into a Task that asks each question as
|
|
4
|
+
* an interleaved `Prompt` effect through the executor's `promptHandler` seam.
|
|
5
|
+
*
|
|
6
|
+
* One builder makes every existing generator answerable by any front-end
|
|
7
|
+
* handler — Ink, MCP params, or defaults — without touching the generator:
|
|
8
|
+
* prompts already answered (CLI flags / MCP args) are skipped, `when`
|
|
9
|
+
* conditions are evaluated against the answers collected so far, and each
|
|
10
|
+
* remaining definition maps onto the task alphabet's `PromptQuestion`.
|
|
11
|
+
*
|
|
12
|
+
* Moved into summon-core (from the v1 cli-core `promptForAnswers`) as the
|
|
13
|
+
* answer-collection phase of {@link execute}.
|
|
14
|
+
*/
|
|
15
|
+
import { type Task } from "@canonical/task";
|
|
16
|
+
/**
|
|
17
|
+
* A prompt definition a command can ask for: the structural shape shared by
|
|
18
|
+
* generator prompt lists, kept free of any generator-package dependency.
|
|
19
|
+
*/
|
|
20
|
+
export interface AnswerablePrompt {
|
|
21
|
+
/** Answer key, unique within the list. */
|
|
22
|
+
readonly name: string;
|
|
23
|
+
/** Question text displayed to the user. */
|
|
24
|
+
readonly message: string;
|
|
25
|
+
/** Prompt kind, deciding how the handler renders and parses the answer. */
|
|
26
|
+
readonly type: "text" | "confirm" | "select" | "multiselect";
|
|
27
|
+
/** Default value when the user provides no input. */
|
|
28
|
+
readonly default?: unknown;
|
|
29
|
+
/** Available options for select/multiselect prompts. */
|
|
30
|
+
readonly choices?: ReadonlyArray<{
|
|
31
|
+
readonly label: string;
|
|
32
|
+
readonly value: string;
|
|
33
|
+
}>;
|
|
34
|
+
/** Ask only when this predicate over the answers so far returns true. */
|
|
35
|
+
readonly when?: (answers: Record<string, unknown>) => boolean;
|
|
36
|
+
/** Text validation: true to accept, or an error message to re-ask with. */
|
|
37
|
+
readonly validate?: (value: string) => boolean | string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Build a Task that collects answers for the given prompt definitions by
|
|
41
|
+
* asking each unanswered, applicable one as a `Prompt` effect.
|
|
42
|
+
*
|
|
43
|
+
* The returned task is single-use (it is `gen`-based): build a fresh one per
|
|
44
|
+
* run. Prompts whose `name` is already present in `partialAnswers` are not
|
|
45
|
+
* asked; `when` predicates observe flags and earlier answers alike.
|
|
46
|
+
*
|
|
47
|
+
* @param prompts - The prompt definitions, in asking order.
|
|
48
|
+
* @param partialAnswers - Answers already provided (e.g. CLI flags / MCP args).
|
|
49
|
+
* @returns A task yielding the complete answers record.
|
|
50
|
+
*/
|
|
51
|
+
export default function collectAnswers(prompts: readonly AnswerablePrompt[], partialAnswers?: Readonly<Record<string, unknown>>): Task<Record<string, unknown>>;
|
|
52
|
+
//# sourceMappingURL=collectAnswers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collectAnswers.d.ts","sourceRoot":"","sources":["../../../src/execute/collectAnswers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAKL,KAAK,IAAI,EACV,MAAM,iBAAiB,CAAC;AAEzB;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,2CAA2C;IAC3C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,2EAA2E;IAC3E,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,QAAQ,GAAG,aAAa,CAAC;IAC7D,qDAAqD;IACrD,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,wDAAwD;IACxD,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC;QAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;KACxB,CAAC,CAAC;IACH,yEAAyE;IACzE,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC;IAC9D,2EAA2E;IAC3E,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,GAAG,MAAM,CAAC;CACzD;AAuDD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CACpC,OAAO,EAAE,SAAS,gBAAgB,EAAE,EACpC,cAAc,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAM,GACrD,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAc/B"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The summon↔pragma seam: turn a generator + a prompt strategy into a
|
|
3
|
+
* `Task<GeneratorResult>` — WITHOUT running it.
|
|
4
|
+
*
|
|
5
|
+
* This one function is the whole seam. Both binaries build the same task here
|
|
6
|
+
* and interpret it their own way: pragma's `create` verb forwards the prompt
|
|
7
|
+
* strategy through `runtime.exec.promptHandler` and lets the kernel interpret
|
|
8
|
+
* it under the node / dry-run / undo interpreters; the summon bin runs it via
|
|
9
|
+
* `runGeneratorTask({ promptHandler })`. Same package + same handler ⇒
|
|
10
|
+
* byte-identical files.
|
|
11
|
+
*
|
|
12
|
+
* Because `execute` returns a task and does NOT run it, `--dry-run` and
|
|
13
|
+
* `--undo` keep working unchanged through the kernel's existing interpreters
|
|
14
|
+
* (which mock `Prompt` effects to their defaults). The task's shape is:
|
|
15
|
+
*
|
|
16
|
+
* collectAnswers → validate → confirm gate → generate → result
|
|
17
|
+
*
|
|
18
|
+
* The confirm gate is an ordinary `confirm` Prompt effect ({@link CONFIRM_ANSWER_KEY}):
|
|
19
|
+
* the non-interactive strategies resolve it to its default (`true`) and the
|
|
20
|
+
* dry-run interpreter mocks it to `true`, so it is a no-op there; the Ink
|
|
21
|
+
* strategy recognises the key and renders the preview + "Proceed?" gate. It is
|
|
22
|
+
* the single signal that answer collection is complete — which a streaming
|
|
23
|
+
* per-question handler otherwise cannot know.
|
|
24
|
+
*/
|
|
25
|
+
import { type Task } from "@canonical/task";
|
|
26
|
+
import type { PromptHandler } from "../prompt/types.js";
|
|
27
|
+
import type GeneratorDefinition from "../types/GeneratorDefinition.js";
|
|
28
|
+
import type { GeneratorResult } from "./GeneratorResult.js";
|
|
29
|
+
/** The reserved answer key of the confirm gate the Ink strategy recognises. */
|
|
30
|
+
export declare const CONFIRM_ANSWER_KEY = "__summon_proceed__";
|
|
31
|
+
/** Task-error code for an answer that fails its prompt's own constraints. */
|
|
32
|
+
export declare const GENERATOR_INVALID_ANSWER = "GENERATOR_INVALID_ANSWER";
|
|
33
|
+
/** Task-error code for a run cancelled at the interactive confirm gate. */
|
|
34
|
+
export declare const GENERATOR_CANCELLED = "GENERATOR_CANCELLED";
|
|
35
|
+
/** The context {@link execute} builds its task from. */
|
|
36
|
+
export interface ExecuteContext {
|
|
37
|
+
/**
|
|
38
|
+
* The prompt strategy the returned task is meant to be interpreted with. The
|
|
39
|
+
* runner (`runTask` / `runGeneratorTask`) applies it; `execute` itself never
|
|
40
|
+
* calls it, so the same task dry-runs and undoes unchanged.
|
|
41
|
+
*/
|
|
42
|
+
readonly prompt: PromptHandler;
|
|
43
|
+
/** Answers already provided (CLI flags / MCP args) — asked prompts are skipped. */
|
|
44
|
+
readonly params: Readonly<Record<string, unknown>>;
|
|
45
|
+
/** Abort signal, honoured by the interpreter between effects. */
|
|
46
|
+
readonly signal?: AbortSignal;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Build the seam task for one generator run.
|
|
50
|
+
*
|
|
51
|
+
* @param generator - The generator to run.
|
|
52
|
+
* @param ctx - The prompt strategy, provided answers, and optional abort signal.
|
|
53
|
+
* @returns A task that collects+validates answers, gates on confirmation, then
|
|
54
|
+
* performs the generation and yields a {@link GeneratorResult}.
|
|
55
|
+
*/
|
|
56
|
+
export default function execute(generator: GeneratorDefinition, ctx: ExecuteContext): Task<GeneratorResult>;
|
|
57
|
+
//# sourceMappingURL=execute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../../src/execute/execute.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAgC,KAAK,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,mBAAmB,MAAM,iCAAiC,CAAC;AAEvE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAG5D,+EAA+E;AAC/E,eAAO,MAAM,kBAAkB,uBAAuB,CAAC;AAEvD,6EAA6E;AAC7E,eAAO,MAAM,wBAAwB,6BAA6B,CAAC;AAEnE,2EAA2E;AAC3E,eAAO,MAAM,mBAAmB,wBAAwB,CAAC;AAEzD,wDAAwD;AACxD,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,mFAAmF;IACnF,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACnD,iEAAiE;IACjE,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC/B;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAC7B,SAAS,EAAE,mBAAmB,EAC9B,GAAG,EAAE,cAAc,GAClB,IAAI,CAAC,eAAe,CAAC,CAyCvB"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { AnswerablePrompt } from "./collectAnswers.js";
|
|
2
|
+
export { default as collectAnswers } from "./collectAnswers.js";
|
|
3
|
+
export { CONFIRM_ANSWER_KEY, default as execute, type ExecuteContext, GENERATOR_CANCELLED, GENERATOR_INVALID_ANSWER, } from "./execute.js";
|
|
4
|
+
export type { GeneratorResult } from "./GeneratorResult.js";
|
|
5
|
+
export { default as validateAnswers } from "./validateAnswers.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/execute/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EACL,kBAAkB,EAClB,OAAO,IAAI,OAAO,EAClB,KAAK,cAAc,EACnB,mBAAmB,EACnB,wBAAwB,GACzB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validate resolved generator answers against each prompt's own constraints.
|
|
3
|
+
*
|
|
4
|
+
* `select` answers must be one of the declared choices, and any `validate`
|
|
5
|
+
* function must accept the value. Returns the first failure message, or `null`
|
|
6
|
+
* when every applicable answer is valid.
|
|
7
|
+
*
|
|
8
|
+
* Reuses the exact `validate` the interactive prompt already runs, so a
|
|
9
|
+
* flag-driven or MCP-arg run (non-interactive) rejects the same bad input a
|
|
10
|
+
* wizard would — e.g. an empty component path or an unknown package type. This
|
|
11
|
+
* is the moved v1 `executeGenerator.findInvalidAnswer`, now run inside
|
|
12
|
+
* {@link execute} so both interactive and non-interactive paths share it.
|
|
13
|
+
*/
|
|
14
|
+
import type PromptDefinition from "../types/PromptDefinition.js";
|
|
15
|
+
/**
|
|
16
|
+
* Find the first answer that violates its prompt's constraints.
|
|
17
|
+
*
|
|
18
|
+
* @param prompts - The generator's prompt definitions.
|
|
19
|
+
* @param answers - The resolved answers to validate.
|
|
20
|
+
* @returns A human-readable message for the first invalid answer, or `null`.
|
|
21
|
+
*/
|
|
22
|
+
export default function validateAnswers(prompts: readonly PromptDefinition[], answers: Record<string, unknown>): string | null;
|
|
23
|
+
//# sourceMappingURL=validateAnswers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateAnswers.d.ts","sourceRoot":"","sources":["../../../src/execute/validateAnswers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,gBAAgB,MAAM,8BAA8B,CAAC;AAMjE;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,OAAO,EAAE,SAAS,gBAAgB,EAAE,EACpC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,MAAM,GAAG,IAAI,CAyBf"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Effect formatting utilities for CLI output.
|
|
3
|
+
*
|
|
4
|
+
* Moved into summon-core (from the v1 cli-core `formatEffects`) so both the
|
|
5
|
+
* summon bin and the pragma kernel share one effect-formatting surface without
|
|
6
|
+
* either importing the other. The pragma `create` render layer reuses these
|
|
7
|
+
* helpers to project a {@link GeneratorResult}; cli-core re-exports them while
|
|
8
|
+
* it is retired.
|
|
9
|
+
*/
|
|
10
|
+
import type { Effect } from "@canonical/task";
|
|
11
|
+
import type GeneratorDefinition from "../types/GeneratorDefinition.js";
|
|
12
|
+
import type PromptDefinition from "../types/PromptDefinition.js";
|
|
13
|
+
/**
|
|
14
|
+
* Filter effects to only show user-relevant ones (not internal effects).
|
|
15
|
+
* @param effect - The effect to check
|
|
16
|
+
* @param verbose - If true, include debug logs
|
|
17
|
+
*/
|
|
18
|
+
export declare const isVisibleEffect: (effect: Effect, verbose?: boolean) => boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Get human-readable action label for an effect.
|
|
21
|
+
*/
|
|
22
|
+
export declare const getActionLabel: (effect: Effect) => string;
|
|
23
|
+
/**
|
|
24
|
+
* Get color for action label based on effect type.
|
|
25
|
+
*/
|
|
26
|
+
export declare const getActionColor: (effect: Effect) => "green" | "red" | "yellow" | "cyan" | "blue" | "magenta" | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Get the payload (description) for an effect.
|
|
29
|
+
*/
|
|
30
|
+
export declare const getEffectPayload: (effect: Effect) => string;
|
|
31
|
+
/**
|
|
32
|
+
* Format a single effect as a CLI line (for non-interactive output).
|
|
33
|
+
*/
|
|
34
|
+
export declare const formatEffectLine: (effect: Effect, isLast: boolean) => string;
|
|
35
|
+
/**
|
|
36
|
+
* Format file content for preview display.
|
|
37
|
+
* Shows line numbers and truncates long content.
|
|
38
|
+
*
|
|
39
|
+
* @param content - The file content to format
|
|
40
|
+
* @param maxLines - Maximum number of lines to show (default: MAX_PREVIEW_LINES)
|
|
41
|
+
*/
|
|
42
|
+
export declare const formatContentPreview: (content: string, maxLines?: number) => string;
|
|
43
|
+
/**
|
|
44
|
+
* Format an effect with its content (for verbose dry-run mode).
|
|
45
|
+
* This is useful for LLM agents that need to see generated file contents.
|
|
46
|
+
*
|
|
47
|
+
* @param effect - The effect to format
|
|
48
|
+
* @param isLast - Whether this is the last effect in the list
|
|
49
|
+
*/
|
|
50
|
+
export declare const formatEffectWithContent: (effect: Effect, isLast: boolean) => string;
|
|
51
|
+
/**
|
|
52
|
+
* Map file extension to markdown code fence language hint.
|
|
53
|
+
*/
|
|
54
|
+
export declare const getLanguageHint: (filePath: string) => string;
|
|
55
|
+
/**
|
|
56
|
+
* Get the plain-text action label for an effect (for LLM output).
|
|
57
|
+
*/
|
|
58
|
+
export declare const getLlmActionLabel: (effect: Effect) => string;
|
|
59
|
+
/**
|
|
60
|
+
* Get the path/description for an effect (plain text, for LLM output).
|
|
61
|
+
*/
|
|
62
|
+
export declare const getLlmEffectPath: (effect: Effect) => string;
|
|
63
|
+
/**
|
|
64
|
+
* Build the replay command string from generator name and answers.
|
|
65
|
+
*/
|
|
66
|
+
export declare const buildReplayCommand: (generatorName: string, answers: Record<string, unknown>, prompts: PromptDefinition[]) => string;
|
|
67
|
+
/**
|
|
68
|
+
* Format the full LLM output as a markdown document.
|
|
69
|
+
*
|
|
70
|
+
* Produces a clean, structured markdown document with:
|
|
71
|
+
* - Generator metadata as heading + blockquote
|
|
72
|
+
* - Answers as a table
|
|
73
|
+
* - Plan as a table with action, path, line count
|
|
74
|
+
* - File contents in fenced code blocks with language hints
|
|
75
|
+
* - Replay command at the end
|
|
76
|
+
*/
|
|
77
|
+
export declare const formatLlmMarkdown: (generator: GeneratorDefinition, answers: Record<string, unknown>, effects: Effect[], verbose?: boolean) => string;
|
|
78
|
+
/**
|
|
79
|
+
* Build the JSON output structure for --format json.
|
|
80
|
+
*/
|
|
81
|
+
export declare const formatLlmJson: (generator: GeneratorDefinition, answers: Record<string, unknown>, effects: Effect[], verbose?: boolean) => Record<string, unknown>;
|
|
82
|
+
/**
|
|
83
|
+
* Format structured markdown help output for a generator (`--help --llm`).
|
|
84
|
+
*/
|
|
85
|
+
export declare const formatLlmHelp: (generator: GeneratorDefinition, commandPath: string) => string;
|
|
86
|
+
//# sourceMappingURL=effects.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effects.d.ts","sourceRoot":"","sources":["../../../src/format/effects.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,KAAK,mBAAmB,MAAM,iCAAiC,CAAC;AACvE,OAAO,KAAK,gBAAgB,MAAM,8BAA8B,CAAC;AAKjE;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,MAAM,EAAE,iBAAe,KAAG,OAiCjE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,QAAQ,MAAM,KAAG,MAoC/C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,GACzB,QAAQ,MAAM,KACb,OAAO,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,SA+B7D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,KAAG,MAwBjD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,EAAE,QAAQ,OAAO,KAAG,MAUlE,CAAC;AAYF;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAC/B,SAAS,MAAM,EACf,WAAU,MAA0B,KACnC,MAsBF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,GAClC,QAAQ,MAAM,EACd,QAAQ,OAAO,KACd,MAeF,CAAC;AAMF;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,UAAU,MAAM,KAAG,MA8ClD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,QAAQ,MAAM,KAAG,MAyBlD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,KAAG,MAqBjD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAC7B,eAAe,MAAM,EACrB,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,gBAAgB,EAAE,KAC1B,MA4BF,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,GAC5B,WAAW,mBAAmB,EAC9B,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,MAAM,EAAE,EACjB,iBAAe,KACd,MA4FF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,GACxB,WAAW,mBAAmB,EAC9B,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,MAAM,EAAE,EACjB,iBAAe,KACd,MAAM,CAAC,MAAM,EAAE,OAAO,CA8CxB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,GACxB,WAAW,mBAAmB,EAC9B,aAAa,MAAM,KAClB,MAkHF,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { buildReplayCommand, formatContentPreview, formatEffectLine, formatEffectWithContent, formatLlmHelp, formatLlmJson, formatLlmMarkdown, getActionColor, getActionLabel, getEffectPayload, getLanguageHint, getLlmActionLabel, getLlmEffectPath, isVisibleEffect, } from "./effects.js";
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/format/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,uBAAuB,EACvB,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,GAChB,MAAM,cAAc,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -9,7 +9,14 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export type { AnyGenerator, ForbidReserved, GeneratorDefinition, GeneratorMeta, PromptDefinition, ReservedOption, StampConfig, } from "./types/index.js";
|
|
11
11
|
export type { RunTaskWithStampOptions } from "./stamp/index.js";
|
|
12
|
-
export { applyStamp, runTaskWithStamp, } from "./stamp/index.js";
|
|
12
|
+
export { applyStamp, createGeneratorStamp, createStampOnEffectStart, runTaskWithStamp, } from "./stamp/index.js";
|
|
13
|
+
export type { AnswerablePrompt, ExecuteContext, GeneratorResult, } from "./execute/index.js";
|
|
14
|
+
export { CONFIRM_ANSWER_KEY, collectAnswers, execute, GENERATOR_CANCELLED, GENERATOR_INVALID_ANSWER, validateAnswers, } from "./execute/index.js";
|
|
15
|
+
export type { ConfirmPrompt, InkPromptOptions, InkSession, MultiselectPrompt, PromptEffect, PromptHandler, PromptQuestion, SelectPrompt, TextPrompt, } from "./prompt/index.js";
|
|
16
|
+
export { answerPromptWithDefaults, autoPrompt, inkPrompt, MISSING_REQUIRED_ANSWER, mcpPrompt, missingRequiredError, } from "./prompt/index.js";
|
|
17
|
+
export { buildReplayCommand, formatContentPreview, formatEffectLine, formatEffectWithContent, formatLlmHelp, formatLlmJson, formatLlmMarkdown, getActionColor, getActionLabel, getEffectPayload, getLanguageHint, getLlmActionLabel, getLlmEffectPath, isVisibleEffect, } from "./format/index.js";
|
|
18
|
+
export type { RunGeneratorTaskOptions } from "./run/index.js";
|
|
19
|
+
export { runGeneratorTask } from "./run/index.js";
|
|
13
20
|
export type { TemplateDirOptions, TemplateOptions, TemplatingEngine, } from "./template/index.js";
|
|
14
21
|
export { ejsEngine, generateStamp, generatorComment, getCommentStyle, prependStamp, renderFile, renderString, renderStringAsync, template, templateDir, templateHelpers, withHelpers, } from "./template/index.js";
|
|
15
22
|
export { default as discoverGeneratorTree } from "./discovery/discoverGeneratorTree.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,YAAY,EACV,YAAY,EACZ,cAAc,EACd,mBAAmB,EACnB,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAM1B,YAAY,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EACL,UAAU,EACV,gBAAgB,GACjB,MAAM,kBAAkB,CAAC;AAM1B,YAAY,EACV,kBAAkB,EAClB,eAAe,EACf,gBAAgB,GACjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,SAAS,EACT,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,iBAAiB,EACjB,QAAQ,EACR,WAAW,EACX,eAAe,EACf,WAAW,GACZ,MAAM,qBAAqB,CAAC;AAM7B,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AACxF,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,YAAY,EACV,YAAY,EACZ,cAAc,EACd,mBAAmB,EACnB,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAM1B,YAAY,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EACL,UAAU,EACV,oBAAoB,EACpB,wBAAwB,EACxB,gBAAgB,GACjB,MAAM,kBAAkB,CAAC;AAM1B,YAAY,EACV,gBAAgB,EAChB,cAAc,EACd,eAAe,GAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,OAAO,EACP,mBAAmB,EACnB,wBAAwB,EACxB,eAAe,GAChB,MAAM,oBAAoB,CAAC;AAO5B,YAAY,EACV,aAAa,EACb,gBAAgB,EAChB,UAAU,EACV,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,cAAc,EACd,YAAY,EACZ,UAAU,GACX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,wBAAwB,EACxB,UAAU,EACV,SAAS,EACT,uBAAuB,EACvB,SAAS,EACT,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAM3B,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,uBAAuB,EACvB,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAMlD,YAAY,EACV,kBAAkB,EAClB,eAAe,EACf,gBAAgB,GACjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,SAAS,EACT,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,iBAAiB,EACjB,QAAQ,EACR,WAAW,EACX,eAAe,EACf,WAAW,GACZ,MAAM,qBAAqB,CAAC;AAM7B,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AACxF,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Effect } from "@canonical/task";
|
|
2
|
+
/**
|
|
3
|
+
* Resolve a `Prompt` effect to its default without user interaction — the
|
|
4
|
+
* defaults-only handler the summon Ink progress view drives, and the base the
|
|
5
|
+
* seam's {@link autoPrompt} strategy layers required-missing detection on.
|
|
6
|
+
*
|
|
7
|
+
* Each prompt type yields the value a non-interactive run should assume: a
|
|
8
|
+
* confirm's default (or `true`), a select's default (or its first choice), an
|
|
9
|
+
* empty multiselect, or a text default (or `""`).
|
|
10
|
+
*
|
|
11
|
+
* @param effect - A `Prompt` effect to resolve.
|
|
12
|
+
* @returns The default answer for the prompt's type.
|
|
13
|
+
*/
|
|
14
|
+
export default function answerPromptWithDefaults(effect: Effect & {
|
|
15
|
+
_tag: "Prompt";
|
|
16
|
+
}): Promise<unknown>;
|
|
17
|
+
//# sourceMappingURL=answerPromptWithDefaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"answerPromptWithDefaults.d.ts","sourceRoot":"","sources":["../../../src/prompt/answerPromptWithDefaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAE9C;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,UAAU,wBAAwB,CAC9C,MAAM,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClC,OAAO,CAAC,OAAO,CAAC,CAYlB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The non-interactive prompt strategy: flags/args + defaults, with a structured
|
|
3
|
+
* failure for a missing required answer.
|
|
4
|
+
*
|
|
5
|
+
* This is the evolved `answerPromptWithDefaults` the seam calls for `--yes`, a
|
|
6
|
+
* non-interactive terminal, or CI. Because {@link collectAnswers} only emits a
|
|
7
|
+
* `Prompt` effect for a prompt NOT already provided, this handler is reached
|
|
8
|
+
* only for unprovided answers: it returns the prompt's declared default, or —
|
|
9
|
+
* when a prompt has no default (a required, unprovided answer) — rejects with a
|
|
10
|
+
* structured `MISSING_REQUIRED_ANSWER` task error rather than silently
|
|
11
|
+
* substituting a bare `""` / first-choice value (the old exit-3 safety).
|
|
12
|
+
*/
|
|
13
|
+
import { TaskExecutionError } from "@canonical/task";
|
|
14
|
+
import type { PromptEffect, PromptHandler } from "./types.js";
|
|
15
|
+
/** The task-error code raised when a required answer is neither provided nor defaulted. */
|
|
16
|
+
export declare const MISSING_REQUIRED_ANSWER = "MISSING_REQUIRED_ANSWER";
|
|
17
|
+
/**
|
|
18
|
+
* Build the structured error for a required, unprovided answer.
|
|
19
|
+
*
|
|
20
|
+
* @param effect - The `Prompt` effect whose answer is missing.
|
|
21
|
+
* @param noun - How to name the missing input in the message ("flag" / "argument").
|
|
22
|
+
* @returns A {@link TaskExecutionError} the interpreter routes as a task failure.
|
|
23
|
+
*/
|
|
24
|
+
export declare function missingRequiredError(effect: PromptEffect, noun?: "flag" | "argument"): TaskExecutionError;
|
|
25
|
+
/**
|
|
26
|
+
* A prompt handler that resolves each unprovided prompt to its default, or
|
|
27
|
+
* fails with {@link missingRequiredError} when no default exists.
|
|
28
|
+
*
|
|
29
|
+
* @param _params - The already-provided answers (accepted for symmetry with the
|
|
30
|
+
* other strategies; {@link collectAnswers} has already filtered these out, so
|
|
31
|
+
* this handler only ever sees unprovided prompts).
|
|
32
|
+
* @returns The non-interactive {@link PromptHandler}.
|
|
33
|
+
*/
|
|
34
|
+
export default function autoPrompt(_params?: Readonly<Record<string, unknown>>): PromptHandler;
|
|
35
|
+
//# sourceMappingURL=autoPrompt.d.ts.map
|