@lambdot/console 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ ## [0.1.0](https://github.com/Embers-of-the-Fire/lambdot/compare/console-v0.0.1...console-v0.1.0) (2026-08-29)
4
+
5
+
6
+ ### Miscellaneous Chores
7
+
8
+ * **console:** Synchronize lambdot versions
package/package.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "@lambdot/console",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": "./src/index.ts"
7
+ },
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "dependencies": {
12
+ "@lambdot/core": "workspace:*"
13
+ }
14
+ }
package/src/index.ts ADDED
@@ -0,0 +1,88 @@
1
+ import { createInterface } from "node:readline/promises";
2
+
3
+ import type { Address, EventDef, InputPlugin, OutputContract, OutputPlugin } from "@lambdot/core";
4
+
5
+ /**
6
+ * Where a console message goes. Owned by the output half of the console
7
+ * platform pair — outputs consume addresses, inputs produce them.
8
+ */
9
+ export interface ConsoleAddress extends Address<"console"> {
10
+ readonly target: "stdout" | "stderr";
11
+ }
12
+
13
+ /** The console platform's output contract: plain text. */
14
+ export type ConsoleOutputs = {
15
+ console: OutputContract<ConsoleAddress, string>;
16
+ };
17
+
18
+ /**
19
+ * Events produced by the console input: one per line read from stdin.
20
+ * A type alias (not an interface extending `EventMap`) so `keyof` stays
21
+ * exactly these kinds — an interface extending `Record` would inherit a
22
+ * string index signature and make every kind subscribable.
23
+ */
24
+ export type ConsoleEvents = {
25
+ "console.line": EventDef<string, ConsoleAddress>;
26
+ };
27
+
28
+ /** The input half of the console platform: one `console.line` event per line read from stdin. */
29
+ export function consoleInput(): InputPlugin<ConsoleEvents, void, "console-input"> {
30
+ return {
31
+ role: "input",
32
+ name: "console-input",
33
+ apply(ctx) {
34
+ const rl = createInterface({ input: process.stdin, terminal: false });
35
+ rl.on("line", (line) => {
36
+ void ctx.ingest("console.line", line, { platform: "console", target: "stdout" });
37
+ });
38
+ return () => {
39
+ rl.close();
40
+ };
41
+ },
42
+ };
43
+ }
44
+
45
+ /** The output half of the console platform: writes plain text to stdout or stderr. */
46
+ export function consoleOutput(): OutputPlugin<
47
+ "console",
48
+ ConsoleAddress,
49
+ string,
50
+ void,
51
+ "console-output"
52
+ > {
53
+ return {
54
+ role: "output",
55
+ name: "console-output",
56
+ platform: "console",
57
+ send(to, content) {
58
+ const stream = to.target === "stderr" ? process.stderr : process.stdout;
59
+ stream.write(`${content}\n`);
60
+ },
61
+ };
62
+ }
63
+
64
+ /**
65
+ * One console platform, bundled: the stdin input and stdout/stderr output
66
+ * halves. The pair stays separate (rather than one fused plugin) so the
67
+ * type fold can keep enforcing registration order — input and output before
68
+ * the feature plugins that consume them.
69
+ *
70
+ * ```ts
71
+ * const cli = consolePlatform();
72
+ * createKernel()
73
+ * .use(cli.input)
74
+ * .use(cli.output);
75
+ * ```
76
+ */
77
+ export interface ConsolePlatform {
78
+ readonly input: InputPlugin<ConsoleEvents, void, "console-input">;
79
+ readonly output: OutputPlugin<"console", ConsoleAddress, string, void, "console-output">;
80
+ }
81
+
82
+ /** Build a whole console platform (stdin input + stdout/stderr output). */
83
+ export function consolePlatform(): ConsolePlatform {
84
+ return {
85
+ input: consoleInput(),
86
+ output: consoleOutput(),
87
+ };
88
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "../../../tsconfig.base.json",
3
+ "include": ["src"]
4
+ }