riteshjs 0.0.0-stage → 0.2.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.
@@ -0,0 +1,555 @@
1
+ /*! ritesh | MIT | Copyright (c) 2026 Jarrod Baumann | bundles xterm.js and ipaddr.js (MIT, see THIRD_PARTY_NOTICES) */
2
+ declare const ERRNOS: readonly ["ENOENT", "ENOTDIR", "EISDIR", "EACCES", "EPERM", "EEXIST", "ENOTEMPTY", "EROFS", "ELOOP", "EINVAL", "ENOTSUP", "ENOSPC", "EIO", "EPIPE", "ECANCELED", "ETIMEDOUT", "ENOTCONN"];
3
+ type Errno = (typeof ERRNOS)[number];
4
+ declare const ERRNO_MESSAGES: Record<Errno, string>;
5
+ /** The one error type that crosses module boundaries. */
6
+ declare class RiteError extends Error {
7
+ readonly errno: Errno;
8
+ readonly path: string | undefined;
9
+ constructor(errno: Errno, path?: string, message?: string);
10
+ }
11
+ /** Exit codes with fixed meanings (docs/language.md). Others are 0-255. */
12
+ declare const EXIT: {
13
+ readonly OK: 0;
14
+ readonly FAILURE: 1;
15
+ readonly USAGE: 2;
16
+ readonly NOT_EXECUTABLE: 126;
17
+ readonly NOT_FOUND: 127;
18
+ readonly INTERRUPTED: 130;
19
+ readonly CONNECTION_LOST: 255;
20
+ };
21
+ type TokenKind = "word" | "operator" | "redirect" | "comment" | "whitespace" | "reserved";
22
+ /** [start, end) offsets into the source line, in UTF-16 code units. */
23
+ type Span = readonly [start: number, end: number];
24
+ interface Token {
25
+ kind: TokenKind;
26
+ text: string;
27
+ span: Span;
28
+ }
29
+ /** One piece of a word, before expansion. */
30
+ type WordPart = {
31
+ kind: "literal";
32
+ text: string;
33
+ quoted: boolean;
34
+ } | {
35
+ kind: "param";
36
+ name: string;
37
+ quoted: boolean;
38
+ } | {
39
+ kind: "tilde";
40
+ text: string;
41
+ } | {
42
+ kind: "glob";
43
+ text: string;
44
+ };
45
+ interface Word {
46
+ parts: WordPart[];
47
+ span: Span;
48
+ }
49
+ type RedirectOp = ">" | ">>" | "<" | "2>" | "2>>" | "2>&1" | ">&2";
50
+ interface Redirect {
51
+ op: RedirectOp;
52
+ /** Absent for the duplication forms 2>&1 and >&2. */
53
+ target?: Word;
54
+ span: Span;
55
+ }
56
+ interface Assignment {
57
+ name: string;
58
+ value: Word;
59
+ span: Span;
60
+ }
61
+ interface SimpleCommand {
62
+ type: "command";
63
+ assignments: Assignment[];
64
+ words: Word[];
65
+ redirects: Redirect[];
66
+ span: Span;
67
+ }
68
+ interface Pipeline {
69
+ type: "pipeline";
70
+ commands: SimpleCommand[];
71
+ span: Span;
72
+ }
73
+ interface List {
74
+ type: "list";
75
+ /** First pipeline, then (operator, pipeline) pairs, left-associative. */
76
+ first: Pipeline;
77
+ rest: Array<{
78
+ op: ";" | "&&" | "||";
79
+ pipeline: Pipeline;
80
+ }>;
81
+ span: Span;
82
+ }
83
+ type ParseResult = {
84
+ ok: true;
85
+ ast: List | null;
86
+ tokens: Token[];
87
+ } | {
88
+ ok: false;
89
+ incomplete: true;
90
+ tokens: Token[];
91
+ } | {
92
+ ok: false;
93
+ incomplete: false;
94
+ error: SyntaxErrorInfo;
95
+ tokens: Token[];
96
+ };
97
+ interface SyntaxErrorInfo {
98
+ message: string;
99
+ span: Span;
100
+ }
101
+ interface ParseOptions {
102
+ /** Returns an alias body for a name in command position, if defined. */
103
+ alias?: (name: string) => string | undefined;
104
+ }
105
+ interface Parser {
106
+ parse(line: string, options?: ParseOptions): ParseResult;
107
+ /** Tokens only, for highlighting. Never throws. */
108
+ tokenize(line: string): Token[];
109
+ /** Quote a value so it parses back as one literal word. */
110
+ quoteWord(value: string, context: "bare" | "double" | "single"): string;
111
+ /** The version string printed in "not supported in rite <version>". */
112
+ readonly version: string;
113
+ }
114
+ type InodeType = "dir" | "file" | "cmd" | "link" | "action" | "dev";
115
+ interface Stat {
116
+ type: InodeType;
117
+ /** Permission bits, e.g. 0o755. */
118
+ mode: number;
119
+ uid: number;
120
+ gid: number;
121
+ size: number;
122
+ /** Milliseconds since the epoch. */
123
+ mtime: number;
124
+ /** Set when the path is inside a mount. */
125
+ mount?: string;
126
+ }
127
+ interface Entry {
128
+ name: string;
129
+ type: InodeType;
130
+ }
131
+ type ActionDef = {
132
+ navigate: string;
133
+ } | {
134
+ open: string;
135
+ } | {
136
+ event: string;
137
+ detail?: unknown;
138
+ } | {
139
+ print: string;
140
+ };
141
+ type ActionVia = "cd" | "open" | "cat";
142
+ interface ActionEvent {
143
+ kind: "navigate" | "open" | "event" | "print";
144
+ path: string;
145
+ via: ActionVia;
146
+ href?: string;
147
+ url?: string;
148
+ name?: string;
149
+ detail?: unknown;
150
+ /** The host calls this to stop rite's default handling. */
151
+ preventDefault(): void;
152
+ readonly defaultPrevented: boolean;
153
+ }
154
+ interface ActionResult {
155
+ event: ActionEvent;
156
+ /** Text the command prints (print actions, or the URL when a popup is blocked). */
157
+ output?: string;
158
+ }
159
+ type FileContent = string | (() => string | Promise<string>);
160
+ type InodeSpec = {
161
+ type: "dir";
162
+ mode?: number;
163
+ uid?: number;
164
+ } | {
165
+ type: "file";
166
+ content: FileContent;
167
+ mode?: number;
168
+ uid?: number;
169
+ } | {
170
+ type: "cmd";
171
+ command: CommandDef;
172
+ mode?: number;
173
+ } | {
174
+ type: "link";
175
+ target: string;
176
+ } | {
177
+ type: "action";
178
+ action: ActionDef;
179
+ mode?: number;
180
+ } | {
181
+ type: "dev";
182
+ read?: () => string;
183
+ write?: (data: string) => void;
184
+ mode?: number;
185
+ };
186
+ /** What the editor may read synchronously from the vfs cache. */
187
+ interface Inode {
188
+ type: InodeType;
189
+ mode: number;
190
+ uid: number;
191
+ /** Present for cmd inodes. */
192
+ command?: CommandInfo;
193
+ }
194
+ interface CallOptions {
195
+ signal?: AbortSignal;
196
+ }
197
+ interface WriteOptions extends CallOptions {
198
+ mode: "truncate" | "append";
199
+ }
200
+ /**
201
+ * Paths given to the vfs are absolute or relative to `cwd`. Tilde is a
202
+ * kernel expansion and never reaches the vfs. `..` resolves lexically.
203
+ */
204
+ interface Vfs {
205
+ stat(path: string, cwd: string, o?: CallOptions): Promise<Stat>;
206
+ list(path: string, cwd: string, o?: CallOptions): Promise<Entry[]>;
207
+ read(path: string, cwd: string, o?: CallOptions): Promise<string>;
208
+ write(path: string, cwd: string, data: string, o: WriteOptions): Promise<void>;
209
+ mkdir(path: string, cwd: string, o?: CallOptions & {
210
+ parents?: boolean;
211
+ }): Promise<void>;
212
+ remove(path: string, cwd: string, o?: CallOptions & {
213
+ recursive?: boolean;
214
+ }): Promise<void>;
215
+ /** Only cd, open, and cat call this. stat and list never trigger actions. */
216
+ activate(path: string, cwd: string, via: ActionVia): Promise<ActionResult | null>;
217
+ /** Absolute, normalized path. Does not check existence. */
218
+ resolve(path: string, cwd: string): string;
219
+ /** Cache only, synchronous, never does I/O. The editor uses only this. */
220
+ peek(path: string, cwd: string): Inode | undefined;
221
+ /** Create or replace an inode (host setup and kernel use). */
222
+ put(path: string, spec: InodeSpec): void;
223
+ mount(path: string, provider: MountProvider): void;
224
+ unmount(path: string): void;
225
+ /** Permission check for the given uid: r, w, or x. Root bypasses. */
226
+ access(path: string, cwd: string, uid: number, want: "r" | "w" | "x"): Promise<boolean>;
227
+ }
228
+ /** A subtree served by a host object or a remote server. Paths are relative to the mount root, "" is the root. */
229
+ interface MountProvider {
230
+ readonly readonly: boolean;
231
+ stat(rel: string, o: CallOptions): Promise<Stat>;
232
+ list(rel: string, o: CallOptions): Promise<Entry[]>;
233
+ read(rel: string, o: CallOptions): Promise<string>;
234
+ write?(rel: string, data: string, o: WriteOptions): Promise<void>;
235
+ mkdir?(rel: string, o: CallOptions): Promise<void>;
236
+ remove?(rel: string, o: CallOptions): Promise<void>;
237
+ /** Called with a relative path when something under the mount changes. Returns an unsubscribe. */
238
+ watch?(onChange: (rel: string) => void): () => void;
239
+ }
240
+ type Env = Record<string, string>;
241
+ interface Tty {
242
+ readonly cols: number;
243
+ readonly rows: number;
244
+ /** Read one line from the terminal. echo:false for passwords. Never recorded in history. */
245
+ read(options?: {
246
+ echo?: boolean;
247
+ prompt?: string;
248
+ signal?: AbortSignal;
249
+ }): Promise<string | null>;
250
+ /** Unfiltered output. Local commands only (clear, egg animations). */
251
+ raw(data: string): Promise<void>;
252
+ }
253
+ type StdioKind = "tty" | "pipe" | "file" | "null";
254
+ interface Stdio {
255
+ stdin: StdioKind;
256
+ stdout: StdioKind;
257
+ stderr: StdioKind;
258
+ }
259
+ type FlagValue = boolean | string | number | Array<string | number>;
260
+ type Flags = Record<string, FlagValue | undefined>;
261
+ interface Proc {
262
+ /** argv[0] is the name the command was invoked by. */
263
+ readonly argv: readonly string[];
264
+ /** Parsed flags, keyed by the long name when one exists, else the short name. */
265
+ readonly flags: Flags;
266
+ /** Operands after flag parsing; argv.slice(1) when the command declares no flags. */
267
+ readonly args: readonly string[];
268
+ /** The resolved subcommand path, e.g. ["devices", "ls"]. Empty when none. */
269
+ readonly subcommand: readonly string[];
270
+ readonly stdin: ReadableStream<string>;
271
+ readonly stdout: WritableStream<string>;
272
+ readonly stderr: WritableStream<string>;
273
+ /** Write to stdout or stderr; resolves when the sink accepted the chunk. Commands write "\n". */
274
+ out(text: string): Promise<void>;
275
+ err(text: string): Promise<void>;
276
+ /** stdin split into lines, without terminators. */
277
+ lines(): AsyncIterable<string>;
278
+ readonly env: Readonly<Env>;
279
+ readonly cwd: string;
280
+ readonly uid: number;
281
+ readonly fs: Vfs;
282
+ /** Aborted on ^C (reason "INT") or when a downstream reader exits (reason "EPIPE"). */
283
+ readonly signal: AbortSignal;
284
+ /** Null when stdout is not the terminal. */
285
+ readonly tty: Tty | null;
286
+ readonly stdio: Stdio;
287
+ readonly sys: Sys;
288
+ }
289
+ /** A command's body. void means exit 0. A throw is exit 1 with one stderr line. */
290
+ type Run = (p: Proc) => Promise<number | void>;
291
+ type Resolution = {
292
+ kind: "alias";
293
+ name: string;
294
+ body: string;
295
+ } | {
296
+ kind: "builtin";
297
+ name: string;
298
+ info: CommandInfo;
299
+ } | {
300
+ kind: "command";
301
+ name: string;
302
+ path: string;
303
+ info: CommandInfo;
304
+ } | {
305
+ kind: "egg";
306
+ name: string;
307
+ id: string;
308
+ } | {
309
+ kind: "not-found";
310
+ name: string;
311
+ };
312
+ interface SessionView {
313
+ readonly user: string;
314
+ readonly uid: number;
315
+ readonly cwd: string;
316
+ readonly hostname: string;
317
+ readonly home: string;
318
+ readonly lastStatus: number;
319
+ }
320
+ /** The kernel facade a command may use. */
321
+ interface Sys {
322
+ resolve(name: string): Resolution;
323
+ commands(): CommandInfo[];
324
+ /** Run argv as a child. stdio defaults to the caller's. */
325
+ spawn(argv: readonly string[], options?: {
326
+ uid?: number;
327
+ env?: Env;
328
+ stdio?: Partial<StdioStreams>;
329
+ }): Promise<number>;
330
+ /** Run a full line (rite -c, source). */
331
+ run(line: string, options?: {
332
+ env?: Env;
333
+ }): Promise<number>;
334
+ readonly session: SessionView;
335
+ /** Host configuration for sudo. */
336
+ readonly sudo: SudoPolicy;
337
+ history(): readonly string[];
338
+ }
339
+ interface StdioStreams {
340
+ stdin: ReadableStream<string>;
341
+ stdout: WritableStream<string>;
342
+ stderr: WritableStream<string>;
343
+ }
344
+ type SudoPolicy = boolean | ((password: string) => boolean | Promise<boolean>);
345
+ /** Builtins also receive the mutable session. In a pipeline the changes do not persist. */
346
+ interface Session {
347
+ user: string;
348
+ uid: number;
349
+ cwd: string;
350
+ oldCwd: string;
351
+ hostname: string;
352
+ home: string;
353
+ env: Env;
354
+ /** Names exported to child processes. */
355
+ exported: Set<string>;
356
+ aliases: Map<string, string>;
357
+ lastStatus: number;
358
+ /** Set by the exit builtin. */
359
+ exitRequested: number | null;
360
+ }
361
+ type BuiltinRun = (p: Proc, session: Session) => Promise<number | void>;
362
+ interface FlagDef {
363
+ long?: string;
364
+ short?: string;
365
+ type: "boolean" | "string" | "number";
366
+ /** Repeatable flags collect into an array. */
367
+ repeat?: boolean;
368
+ default?: FlagValue;
369
+ description?: string;
370
+ }
371
+ interface Candidate {
372
+ value: string;
373
+ display?: string;
374
+ description?: string;
375
+ /** Appended after insertion: " " by default, "/" for directories, "" to keep typing. */
376
+ suffix?: string;
377
+ }
378
+ interface CompleteContext {
379
+ argv: readonly string[];
380
+ /** Index into argv of the word being completed. */
381
+ index: number;
382
+ prefix: string;
383
+ env: Readonly<Env>;
384
+ cwd: string;
385
+ fs: Vfs;
386
+ signal: AbortSignal;
387
+ }
388
+ type Completer = (ctx: CompleteContext) => Promise<Candidate[]>;
389
+ interface CommandDef {
390
+ name: string;
391
+ summary: string;
392
+ usage: string;
393
+ /** Keyed by the canonical name (long when present). Omit to receive raw argv. */
394
+ flags?: Record<string, FlagDef>;
395
+ subcommands?: Record<string, Omit<CommandDef, "name">>;
396
+ complete?: Completer;
397
+ run?: Run;
398
+ /** Longer text for man. */
399
+ manual?: string;
400
+ }
401
+ interface CommandInfo {
402
+ name: string;
403
+ summary: string;
404
+ usage: string;
405
+ /** Longer text for man, when the definition has one. */
406
+ manual?: string;
407
+ flags?: Record<string, FlagDef>;
408
+ subcommands?: Record<string, {
409
+ summary: string;
410
+ usage: string;
411
+ }>;
412
+ builtin: boolean;
413
+ remote: boolean;
414
+ }
415
+ /** Supplies commands from outside the vfs tree (the remote client). */
416
+ interface CommandSource {
417
+ /** Names known before connecting, so completion and which work early. */
418
+ names(): string[];
419
+ info(name: string): CommandInfo | undefined;
420
+ run(name: string, p: Proc): Promise<number>;
421
+ complete?(argv: readonly string[], index: number, signal: AbortSignal): Promise<Candidate[]>;
422
+ }
423
+ declare const PASS: unique symbol;
424
+ type EggResult = number | void | typeof PASS;
425
+ type EggTrigger = {
426
+ command: string;
427
+ when?: (argv: readonly string[], session: SessionView) => boolean;
428
+ } | {
429
+ input: RegExp;
430
+ } | {
431
+ keys: string;
432
+ };
433
+ interface EggDef {
434
+ id: string;
435
+ trigger: EggTrigger;
436
+ run: (p: Proc) => Promise<EggResult>;
437
+ }
438
+ interface Completion {
439
+ /** The span of the line the candidates replace. */
440
+ span: Span;
441
+ candidates: Candidate[];
442
+ }
443
+ type OutputPolicy = "plain" | "sgr" | "raw";
444
+ interface TermSize {
445
+ cols: number;
446
+ rows: number;
447
+ }
448
+ /** The only boundary to xterm. The editor renders through it; tests back it with @xterm/headless. */
449
+ interface Term {
450
+ /**
451
+ * Write complete text with a policy; resolves once xterm has parsed it.
452
+ * "\n" becomes "\r\n". Each call is filtered on its own: an escape
453
+ * sequence cut off at the end of the data is dropped.
454
+ */
455
+ write(data: string, policy: OutputPolicy): Promise<void>;
456
+ /**
457
+ * A writer for one stream (a process's stdout): its filter keeps an escape
458
+ * sequence split across chunks until it completes, apart from every other
459
+ * writer.
460
+ */
461
+ writer(policy: OutputPolicy): (chunk: string) => Promise<void>;
462
+ /** Key input, already decoded into strings, terminal replies discarded. Returns an unsubscribe. */
463
+ onInput(listener: (data: string) => void): () => void;
464
+ onResize(listener: (size: TermSize) => void): () => void;
465
+ readonly size: TermSize;
466
+ /** Replace the terminal's colors (xterm ITheme keys). */
467
+ setTheme(theme: Theme): void;
468
+ /** Display width of one code point: 0, 1, or 2. */
469
+ width(codePoint: number): 0 | 1 | 2;
470
+ focus(): void;
471
+ fit(): void;
472
+ dispose(): void;
473
+ }
474
+ interface Kernel {
475
+ readonly session: SessionView;
476
+ /** Run one line as if typed. Queued behind any running job. */
477
+ exec(line: string, stdio?: Partial<StdioStreams>): Promise<number>;
478
+ /** Run one egg directly (a key trigger), queued like a line. */
479
+ runEgg(egg: EggDef): Promise<number>;
480
+ complete(line: string, cursor: number, o: {
481
+ signal: AbortSignal;
482
+ }): Promise<Completion>;
483
+ /** Abort the foreground job (^C). */
484
+ interrupt(): void;
485
+ readonly running: boolean;
486
+ register(def: CommandDef, at?: string): void;
487
+ registerEgg(def: EggDef): void;
488
+ /** Eggs with key triggers, for the editor. */
489
+ keyEggs(): readonly EggDef[];
490
+ addCommandSource(at: string, source: CommandSource): void;
491
+ readonly vfs: Vfs;
492
+ readonly parser: Parser;
493
+ }
494
+ type HistoryMode = "local" | "memory" | false;
495
+ /** Terminal colors: xterm's ITheme keys (strings, and extendedAnsi as a list). */
496
+ interface Theme {
497
+ [key: string]: string | readonly string[] | undefined;
498
+ extendedAnsi?: readonly string[];
499
+ }
500
+ interface HostOptions {
501
+ element: HTMLElement;
502
+ hostname?: string;
503
+ user?: string;
504
+ /** Printed before the first prompt; SGR colors are kept, every other escape sequence is dropped. */
505
+ motd?: string;
506
+ files?: Record<string, FileContent>;
507
+ inodes?: Record<string, InodeSpec>;
508
+ mounts?: Array<{
509
+ path: string;
510
+ provider: MountProvider;
511
+ }>;
512
+ commands?: CommandDef[];
513
+ eggs?: EggDef[] | false;
514
+ remote?: RemoteHandle;
515
+ sudo?: SudoPolicy;
516
+ history?: HistoryMode;
517
+ /** xterm ITheme keys; `themes` has brass, tide, dusk (dark) and paper (light) ready-made. */
518
+ theme?: Theme;
519
+ /** The terminal's font. Load web fonts before createRite so the cell size is measured right. */
520
+ font?: {
521
+ family?: string;
522
+ size?: number;
523
+ };
524
+ screenReaderMode?: boolean;
525
+ onAction?: (e: ActionEvent) => void;
526
+ }
527
+ /** What rite/remote hands to createRite. Core never imports the remote module. */
528
+ interface RemoteHandle {
529
+ readonly at: string;
530
+ readonly bin: string;
531
+ readonly provider: MountProvider;
532
+ readonly commands: CommandSource;
533
+ connect(): Promise<void>;
534
+ /** The terminal's size changed: tell the server (tty.resize) if connected. */
535
+ resize(cols: number, rows: number): void;
536
+ dispose(): void;
537
+ onNotify(listener: (text: string, level: "info" | "warn" | "error") => void): () => void;
538
+ }
539
+ interface Rite {
540
+ readonly ready: Promise<void>;
541
+ exec(line: string): Promise<{
542
+ code: number;
543
+ }>;
544
+ print(text: string): void;
545
+ focus(): void;
546
+ fit(): void;
547
+ /** The terminal's size in cells. */
548
+ readonly size: TermSize;
549
+ /** Called after the terminal changes size (a fit, a resize). Returns an unsubscribe. */
550
+ onResize(listener: (size: TermSize) => void): () => void;
551
+ /** Replace the terminal's colors, such as `themes.paper`. */
552
+ setTheme(theme: Theme): void;
553
+ dispose(): void;
554
+ }
555
+ export { Span as $, Inode as A, Parser as B, Errno as C, Flags as D, FlagValue as E, MountProvider as F, RemoteHandle as G, Proc as H, OutputPolicy as I, RiteError as J, Resolution as K, PASS as L, InodeType as M, Kernel as N, HistoryMode as O, List as P, SimpleCommand as Q, ParseOptions as R, Env as S, FlagDef as T, Redirect as U, Pipeline as V, RedirectOp as W, Session as X, Run as Y, SessionView as Z, EXIT as _, Assignment as a, SyntaxErrorInfo as at, EggTrigger as b, Candidate as c, TermSize as ct, CommandSource as d, TokenKind as dt, Stat as et, CompleteContext as f, Tty as ft, ERRNO_MESSAGES as g, WriteOptions as gt, ERRNOS as h, WordPart as ht, ActionVia as i, SudoPolicy as it, InodeSpec as j, HostOptions as k, CommandDef as l, Theme as lt, Completion as m, Word as mt, ActionEvent as n, StdioKind as nt, BuiltinRun as o, Sys as ot, Completer as p, Vfs as pt, Rite as q, ActionResult as r, StdioStreams as rt, CallOptions as s, Term as st, ActionDef as t, Stdio as tt, CommandInfo as u, Token as ut, EggDef as v, FileContent as w, Entry as x, EggResult as y, ParseResult as z };
@@ -0,0 +1,6 @@
1
+ /*! ritesh | MIT | Copyright (c) 2026 Jarrod Baumann | bundles xterm.js and ipaddr.js (MIT, see THIRD_PARTY_NOTICES) */
2
+ import { l as CommandDef, v as EggDef } from "./contracts-DwXN7Pv9.js";
3
+ /** Identity helpers that give a command or egg definition its type. */
4
+ declare function defineCommand(def: CommandDef): CommandDef;
5
+ declare function defineEgg(def: EggDef): EggDef;
6
+ export { defineEgg as n, defineCommand as t };
@@ -0,0 +1,88 @@
1
+ /*! ritesh | MIT | Copyright (c) 2026 Jarrod Baumann | bundles xterm.js and ipaddr.js (MIT, see THIRD_PARTY_NOTICES) */
2
+ import { i as PASS, r as EXIT } from "./contracts-0hnYHcIF.js";
3
+ // src/define.ts
4
+ /** Identity helpers that give a command or egg definition its type. */
5
+ function defineCommand(def) {
6
+ return def;
7
+ }
8
+ function defineEgg(def) {
9
+ return def;
10
+ }
11
+ // src/eggs/rmrf.ts
12
+ /** Entries shown from each top-level directory. */
13
+ const PER_DIR = 6;
14
+ /** Lexical: "." and empty components drop, ".." pops and stops at the root. */
15
+ function normalize(path, cwd) {
16
+ const parts = [];
17
+ for (const part of (path.startsWith("/") ? path : `${cwd}/${path}`).split("/")) {
18
+ if (part === "" || part === ".") continue;
19
+ if (part === "..") parts.pop();
20
+ else parts.push(part);
21
+ }
22
+ return "/" + parts.join("/");
23
+ }
24
+ /**
25
+ * True for `rm` with the recursive and the force flag, in any spelling, and
26
+ * an operand that normalizes to "/". Other options are ignored, as rm would
27
+ * read them, and nothing after `--` is an option.
28
+ */
29
+ function wipesRoot(argv, cwd) {
30
+ let recursive = false;
31
+ let force = false;
32
+ let root = false;
33
+ let options = true;
34
+ for (const word of argv.slice(1)) if (options && word === "--") options = false;
35
+ else if (options && word.startsWith("--")) {
36
+ if (word === "--recursive") recursive = true;
37
+ else if (word === "--force") force = true;
38
+ } else if (options && word.length > 1 && word.startsWith("-")) {
39
+ for (const letter of word.slice(1)) if (letter === "r" || letter === "R") recursive = true;
40
+ else if (letter === "f") force = true;
41
+ } else if (word !== "" && normalize(word, cwd) === "/") root = true;
42
+ return recursive && force && root;
43
+ }
44
+ /** `rm -rf /`: a deletion that is not happening, then the admission. */
45
+ const rmrf = defineEgg({
46
+ id: "rmrf",
47
+ trigger: {
48
+ command: "rm",
49
+ when: (argv, session) => wipesRoot(argv, session.cwd)
50
+ },
51
+ run: async (p) => {
52
+ const list = (path) => p.fs.list(path, "/", { signal: p.signal }).catch(() => []);
53
+ try {
54
+ for (const entry of await list("/")) {
55
+ if (p.signal.aborted) return EXIT.INTERRUPTED;
56
+ const path = `/${entry.name}`;
57
+ if (entry.type !== "dir") {
58
+ await p.out(`removed ${path}\n`);
59
+ continue;
60
+ }
61
+ for (const child of (await list(path)).slice(0, PER_DIR)) await p.out(`removed ${path}/${child.name}\n`);
62
+ await p.out(`removed directory ${path}\n`);
63
+ }
64
+ await p.out("just kidding. nothing here is yours to delete.\n");
65
+ return EXIT.OK;
66
+ } catch (e) {
67
+ if (p.signal.aborted) return EXIT.INTERRUPTED;
68
+ throw e;
69
+ }
70
+ }
71
+ });
72
+ // src/eggs/sudoers.ts
73
+ /** Answers `sudo <command>` when the host lets nobody use sudo, which is the default. */
74
+ const sudoers = defineEgg({
75
+ id: "sudoers",
76
+ trigger: { command: "sudo" },
77
+ run: async (p) => {
78
+ if (p.sys.sudo !== false || p.argv.length < 2) return PASS;
79
+ await p.err(`${p.sys.session.user} is not in the sudoers file. This incident will be reported.\n`);
80
+ return EXIT.FAILURE;
81
+ }
82
+ });
83
+ // src/eggs/index.ts
84
+ /** The eggs shipped with ritesh, for `createRite({ eggs })`. */
85
+ const eggs = [sudoers, rmrf];
86
+ export { defineEgg as a, defineCommand as i, sudoers as n, rmrf as r, eggs as t };
87
+
88
+ //# sourceMappingURL=eggs-xvNKRzfj.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eggs-xvNKRzfj.js","names":[],"sources":["../src/define.ts","../src/eggs/rmrf.ts","../src/eggs/sudoers.ts","../src/eggs/index.ts"],"sourcesContent":["import type { CommandDef, EggDef } from \"./contracts.js\"\n\n/** Identity helpers that give a command or egg definition its type. */\nexport function defineCommand(def: CommandDef): CommandDef {\n return def\n}\n\nexport function defineEgg(def: EggDef): EggDef {\n return def\n}\n","import { type Entry, EXIT } from \"../contracts.js\"\nimport { defineEgg } from \"../define.js\"\n\n/** Entries shown from each top-level directory. */\nconst PER_DIR = 6\n\n/** Lexical: \".\" and empty components drop, \"..\" pops and stops at the root. */\nfunction normalize(path: string, cwd: string): string {\n const parts: string[] = []\n for (const part of (path.startsWith(\"/\") ? path : `${cwd}/${path}`).split(\"/\")) {\n if (part === \"\" || part === \".\") continue\n if (part === \"..\") parts.pop()\n else parts.push(part)\n }\n return \"/\" + parts.join(\"/\")\n}\n\n/**\n * True for `rm` with the recursive and the force flag, in any spelling, and\n * an operand that normalizes to \"/\". Other options are ignored, as rm would\n * read them, and nothing after `--` is an option.\n */\nexport function wipesRoot(argv: readonly string[], cwd: string): boolean {\n let recursive = false\n let force = false\n let root = false\n let options = true\n for (const word of argv.slice(1)) {\n if (options && word === \"--\") options = false\n else if (options && word.startsWith(\"--\")) {\n if (word === \"--recursive\") recursive = true\n else if (word === \"--force\") force = true\n } else if (options && word.length > 1 && word.startsWith(\"-\")) {\n for (const letter of word.slice(1)) {\n if (letter === \"r\" || letter === \"R\") recursive = true\n else if (letter === \"f\") force = true\n }\n } else if (word !== \"\" && normalize(word, cwd) === \"/\") root = true\n }\n return recursive && force && root\n}\n\n/** `rm -rf /`: a deletion that is not happening, then the admission. */\nexport const rmrf = defineEgg({\n id: \"rmrf\",\n trigger: { command: \"rm\", when: (argv, session) => wipesRoot(argv, session.cwd) },\n run: async (p) => {\n const list = (path: string): Promise<Entry[]> =>\n p.fs.list(path, \"/\", { signal: p.signal }).catch((): Entry[] => [])\n try {\n // Plain lines through stdout: the names may come from a mount, so they are never raw.\n for (const entry of await list(\"/\")) {\n if (p.signal.aborted) return EXIT.INTERRUPTED\n const path = `/${entry.name}`\n if (entry.type !== \"dir\") {\n await p.out(`removed ${path}\\n`)\n continue\n }\n for (const child of (await list(path)).slice(0, PER_DIR)) await p.out(`removed ${path}/${child.name}\\n`)\n await p.out(`removed directory ${path}\\n`)\n }\n await p.out(\"just kidding. nothing here is yours to delete.\\n\")\n return EXIT.OK\n } catch (e) {\n if (p.signal.aborted) return EXIT.INTERRUPTED\n throw e\n }\n },\n})\n","import { EXIT, PASS } from \"../contracts.js\"\nimport { defineEgg } from \"../define.js\"\n\n/** Answers `sudo <command>` when the host lets nobody use sudo, which is the default. */\nexport const sudoers = defineEgg({\n id: \"sudoers\",\n trigger: { command: \"sudo\" },\n run: async (p) => {\n // The policy is not part of what a trigger's predicate sees, so it is checked here.\n if (p.sys.sudo !== false || p.argv.length < 2) return PASS\n await p.err(`${p.sys.session.user} is not in the sudoers file. This incident will be reported.\\n`)\n return EXIT.FAILURE\n },\n})\n","import type { EggDef } from \"../contracts.js\"\nimport { rmrf } from \"./rmrf.js\"\nimport { sudoers } from \"./sudoers.js\"\n\nexport { rmrf } from \"./rmrf.js\"\nexport { sudoers } from \"./sudoers.js\"\n\n/** The eggs shipped with ritesh, for `createRite({ eggs })`. */\nexport const eggs: EggDef[] = [sudoers, rmrf]\n"],"mappings":";;;;AAGA,SAAgB,cAAc,KAA6B;CACzD,OAAO;AACT;AAEA,SAAgB,UAAU,KAAqB;CAC7C,OAAO;AACT;;;ACLA,MAAM,UAAU;;AAGhB,SAAS,UAAU,MAAc,KAAqB;CACpD,MAAM,QAAkB,CAAC;CACzB,KAAK,MAAM,SAAS,KAAK,WAAW,GAAG,IAAI,OAAO,GAAG,IAAI,GAAG,OAAA,CAAQ,MAAM,GAAG,GAAG;EAC9E,IAAI,SAAS,MAAM,SAAS,KAAK;EACjC,IAAI,SAAS,MAAM,MAAM,IAAI;OACxB,MAAM,KAAK,IAAI;CACtB;CACA,OAAO,MAAM,MAAM,KAAK,GAAG;AAC7B;;;;;;AAOA,SAAgB,UAAU,MAAyB,KAAsB;CACvE,IAAI,YAAY;CAChB,IAAI,QAAQ;CACZ,IAAI,OAAO;CACX,IAAI,UAAU;CACd,KAAK,MAAM,QAAQ,KAAK,MAAM,CAAC,GAC7B,IAAI,WAAW,SAAS,MAAM,UAAU;MACnC,IAAI,WAAW,KAAK,WAAW,IAAI,GAAG;EACzC,IAAI,SAAS,eAAe,YAAY;OACnC,IAAI,SAAS,WAAW,QAAQ;CACvC,OAAO,IAAI,WAAW,KAAK,SAAS,KAAK,KAAK,WAAW,GAAG,GACrD;OAAA,MAAM,UAAU,KAAK,MAAM,CAAC,GAC/B,IAAI,WAAW,OAAO,WAAW,KAAK,YAAY;OAC7C,IAAI,WAAW,KAAK,QAAQ;CAAA,OAE9B,IAAI,SAAS,MAAM,UAAU,MAAM,GAAG,MAAM,KAAK,OAAO;CAEjE,OAAO,aAAa,SAAS;AAC/B;;AAGA,MAAa,OAAO,UAAU;CAC5B,IAAI;CACJ,SAAS;EAAE,SAAS;EAAM,OAAO,MAAM,YAAY,UAAU,MAAM,QAAQ,GAAG;CAAE;CAChF,KAAK,OAAO,MAAM;EAChB,MAAM,QAAQ,SACZ,EAAE,GAAG,KAAK,MAAM,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,YAAqB,CAAC,CAAC;EACpE,IAAI;GAEF,KAAK,MAAM,SAAS,MAAM,KAAK,GAAG,GAAG;IACnC,IAAI,EAAE,OAAO,SAAS,OAAO,KAAK;IAClC,MAAM,OAAO,IAAI,MAAM;IACvB,IAAI,MAAM,SAAS,OAAO;KACxB,MAAM,EAAE,IAAI,WAAW,KAAK,GAAG;KAC/B;IACF;IACA,KAAK,MAAM,UAAU,MAAM,KAAK,IAAI,EAAA,CAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,IAAI,WAAW,KAAK,GAAG,MAAM,KAAK,GAAG;IACvG,MAAM,EAAE,IAAI,qBAAqB,KAAK,GAAG;GAC3C;GACA,MAAM,EAAE,IAAI,kDAAkD;GAC9D,OAAO,KAAK;EACd,SAAS,GAAG;GACV,IAAI,EAAE,OAAO,SAAS,OAAO,KAAK;GAClC,MAAM;EACR;CACF;AACF,CAAC;;;AChED,MAAa,UAAU,UAAU;CAC/B,IAAI;CACJ,SAAS,EAAE,SAAS,OAAO;CAC3B,KAAK,OAAO,MAAM;EAEhB,IAAI,EAAE,IAAI,SAAS,SAAS,EAAE,KAAK,SAAS,GAAG,OAAO;EACtD,MAAM,EAAE,IAAI,GAAG,EAAE,IAAI,QAAQ,KAAK,+DAA+D;EACjG,OAAO,KAAK;CACd;AACF,CAAC;;;ACLD,MAAa,OAAiB,CAAC,SAAS,IAAI"}
package/dist/eggs.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ /*! ritesh | MIT | Copyright (c) 2026 Jarrod Baumann | bundles xterm.js and ipaddr.js (MIT, see THIRD_PARTY_NOTICES) */
2
+ import { L as PASS, b as EggTrigger, v as EggDef, y as EggResult } from "./contracts-DwXN7Pv9.js";
3
+ import { n as defineEgg } from "./define-C14xvFmq.js";
4
+ /** `rm -rf /`: a deletion that is not happening, then the admission. */
5
+ export declare const rmrf: EggDef;
6
+ /** Answers `sudo <command>` when the host lets nobody use sudo, which is the default. */
7
+ export declare const sudoers: EggDef;
8
+ /** The eggs shipped with ritesh, for `createRite({ eggs })`. */
9
+ export declare const eggs: EggDef[];
10
+ export { type EggDef, type EggResult, type EggTrigger, PASS, defineEgg };
package/dist/eggs.js ADDED
@@ -0,0 +1,4 @@
1
+ /*! ritesh | MIT | Copyright (c) 2026 Jarrod Baumann | bundles xterm.js and ipaddr.js (MIT, see THIRD_PARTY_NOTICES) */
2
+ import { i as PASS } from "./contracts-0hnYHcIF.js";
3
+ import { a as defineEgg, n as sudoers, r as rmrf, t as eggs } from "./eggs-xvNKRzfj.js";
4
+ export { PASS, defineEgg, eggs, rmrf, sudoers };