omkit 0.0.14 → 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.
Files changed (110) hide show
  1. package/README.md +110 -97
  2. package/dist/actions/chrome-page.d.ts +12 -29
  3. package/dist/actions/chrome-page.js +19 -32
  4. package/dist/actions/command.d.ts +8 -41
  5. package/dist/actions/command.js +15 -82
  6. package/dist/actions/healthcheck.d.ts +3 -11
  7. package/dist/actions/healthcheck.js +8 -22
  8. package/dist/actions/index.d.ts +6 -8
  9. package/dist/actions/index.js +4 -6
  10. package/dist/actions/prompt.d.ts +5 -19
  11. package/dist/actions/prompt.js +10 -31
  12. package/dist/actions/tail-log.d.ts +7 -21
  13. package/dist/actions/tail-log.js +13 -34
  14. package/dist/actions/until-log.d.ts +4 -7
  15. package/dist/actions/until-log.js +3 -3
  16. package/dist/actions/watch-dir.d.ts +5 -19
  17. package/dist/actions/watch-dir.js +13 -28
  18. package/dist/actions/watch.d.ts +4 -12
  19. package/dist/actions/watch.js +9 -16
  20. package/dist/core/ActionRun.d.ts +97 -0
  21. package/dist/core/ActionRun.js +266 -0
  22. package/dist/core/ExecutionTree.d.ts +88 -0
  23. package/dist/core/ExecutionTree.js +320 -0
  24. package/dist/core/action.d.ts +6 -0
  25. package/dist/core/action.js +72 -0
  26. package/dist/core/context.d.ts +9 -0
  27. package/dist/core/context.js +8 -0
  28. package/dist/core/om.d.ts +9 -0
  29. package/dist/core/om.js +25 -0
  30. package/dist/core/step.d.ts +9 -0
  31. package/dist/core/step.js +18 -0
  32. package/dist/core/types.d.ts +128 -0
  33. package/dist/foundation/ActionRef.d.ts +18 -0
  34. package/dist/foundation/ActionRef.js +5 -0
  35. package/dist/{utils → foundation}/AsyncQueue.d.ts +2 -4
  36. package/dist/{utils → foundation}/AsyncQueue.js +6 -19
  37. package/dist/foundation/CancelledError.d.ts +10 -0
  38. package/dist/foundation/CancelledError.js +13 -0
  39. package/dist/foundation/Deferred.d.ts +8 -0
  40. package/dist/foundation/Deferred.js +10 -0
  41. package/dist/foundation/LogEntry.d.ts +29 -0
  42. package/dist/{orchestration/events → foundation}/events.d.ts +2 -11
  43. package/dist/{orchestration/events → foundation}/events.js +1 -7
  44. package/dist/{utils → foundation}/format.d.ts +3 -4
  45. package/dist/{utils → foundation}/format.js +12 -4
  46. package/dist/foundation/fsSafe.d.ts +7 -0
  47. package/dist/foundation/fsSafe.js +7 -0
  48. package/dist/foundation/ids.d.ts +9 -0
  49. package/dist/foundation/ids.js +10 -0
  50. package/dist/index.d.ts +11 -22
  51. package/dist/index.js +10 -30
  52. package/dist/output/LiveRenderer.d.ts +13 -0
  53. package/dist/output/LiveRenderer.js +56 -0
  54. package/dist/output/console/ConsoleCapture.d.ts +20 -0
  55. package/dist/output/console/ConsoleCapture.js +47 -0
  56. package/dist/output/folder/RunFolder.d.ts +11 -22
  57. package/dist/output/folder/RunFolder.js +18 -36
  58. package/dist/output/log/LogStore.d.ts +22 -0
  59. package/dist/output/log/LogStore.js +56 -0
  60. package/dist/output/log/RawStream.d.ts +11 -0
  61. package/dist/output/log/RawStream.js +18 -0
  62. package/dist/output/snapshot/SnapshotStore.d.ts +6 -43
  63. package/dist/output/snapshot/SnapshotStore.js +12 -52
  64. package/dist/output/writers/NodeLogWriter.d.ts +8 -0
  65. package/dist/output/writers/NodeLogWriter.js +36 -0
  66. package/dist/output/writers/ResultWriter.d.ts +3 -0
  67. package/dist/output/writers/ResultWriter.js +5 -0
  68. package/dist/output/writers/RollupWriter.d.ts +9 -0
  69. package/dist/output/writers/RollupWriter.js +29 -0
  70. package/dist/output/writers/entryLine.d.ts +10 -0
  71. package/dist/output/writers/entryLine.js +39 -0
  72. package/dist/output/writers/views.d.ts +38 -0
  73. package/dist/output/writers/views.js +6 -0
  74. package/dist/system/fs/FolderCache.d.ts +6 -34
  75. package/dist/system/fs/FolderCache.js +7 -38
  76. package/dist/system/proc.d.ts +51 -0
  77. package/dist/system/proc.js +148 -0
  78. package/dist/system/procRegistry.d.ts +52 -0
  79. package/dist/system/procRegistry.js +117 -0
  80. package/package.json +3 -1
  81. package/dist/orchestration/action/action.d.ts +0 -23
  82. package/dist/orchestration/action/action.js +0 -256
  83. package/dist/orchestration/action/types.d.ts +0 -182
  84. package/dist/orchestration/assert.d.ts +0 -22
  85. package/dist/orchestration/assert.js +0 -26
  86. package/dist/orchestration/spin/SpinHost.d.ts +0 -109
  87. package/dist/orchestration/spin/SpinHost.js +0 -337
  88. package/dist/orchestration/spin/spin.d.ts +0 -24
  89. package/dist/orchestration/spin/spin.js +0 -57
  90. package/dist/orchestration/spin/types.d.ts +0 -63
  91. package/dist/output/Output.d.ts +0 -24
  92. package/dist/output/Output.js +0 -27
  93. package/dist/output/index.d.ts +0 -11
  94. package/dist/output/index.js +0 -11
  95. package/dist/output/log/LogRenderer.d.ts +0 -73
  96. package/dist/output/log/LogRenderer.js +0 -133
  97. package/dist/output/log/LogsCollector.d.ts +0 -79
  98. package/dist/output/log/LogsCollector.js +0 -141
  99. package/dist/output/log/RunLog.d.ts +0 -47
  100. package/dist/output/log/RunLog.js +0 -142
  101. package/dist/output/log/console-capture.d.ts +0 -24
  102. package/dist/output/log/console-capture.js +0 -53
  103. package/dist/system/fs/streams.d.ts +0 -11
  104. package/dist/system/fs/streams.js +0 -14
  105. package/dist/system/process/process.d.ts +0 -35
  106. package/dist/system/process/process.js +0 -104
  107. package/dist/utils/serialize.d.ts +0 -2
  108. package/dist/utils/serialize.js +0 -12
  109. /package/dist/{orchestration/action → core}/types.js +0 -0
  110. /package/dist/{orchestration/spin/types.js → foundation/LogEntry.js} +0 -0
@@ -1,35 +0,0 @@
1
- import { type Options, type ProcessPromise } from "zx";
2
- import type { Logger } from "../../output/log/LogsCollector.ts";
3
- import type { SnapshotStore } from "../../output/snapshot/SnapshotStore.ts";
4
- /**
5
- * Force-kill a process **and its whole tree, synchronously**.
6
- *
7
- * Windows has no process groups: a child outlives its parent, and a Ctrl-C sent
8
- * to the console group can make an intermediate shell exit and *orphan* the real
9
- * app (e.g. electron.exe), which then survives teardown. So the tree must be
10
- * reaped explicitly by PID — `taskkill /F /T` does it, and running it
11
- * **synchronously** guarantees it completes before the run's own process exits
12
- * (a fire-and-forget kill can lose that race). On POSIX, zx's `kill` already
13
- * does a process-group tree kill. Best-effort: an already-dead/missing PID is
14
- * ignored.
15
- */
16
- export declare const killTree: (pid: number) => void;
17
- /**
18
- * Spawns a command (tagged-template, exactly like zx's `$`) and streams the
19
- * child's stdout/stderr into a log (stdout as `info`, stderr as `error`) under
20
- * the given `name`, killing the child when the bound signal aborts. Returns zx's
21
- * `ProcessPromise`, so the caller can await it for the result.
22
- *
23
- * @example
24
- * proc("build-docs", { cwd })`tskb ${pattern} --project ${name}`;
25
- */
26
- export type Proc = (name: string, opts?: Partial<Options>) => (pieces: TemplateStringsArray, ...args: unknown[]) => ProcessPromise;
27
- /**
28
- * Builds a {@link Proc} bound to a specific log sink, abort signal, and the run's
29
- * snapshot store. The action pipeline injects one per action as `ctx.proc`, wired
30
- * to that action's logger, the run's signal, and the run's `output.snapshots` — so
31
- * actions just describe the command, with no ambient lookup and nothing threaded
32
- * through. A custom source (e.g. a CDP connection) follows the same shape: take the
33
- * action's `logs`/`signal`, push into the log, and hook teardown.
34
- */
35
- export declare const createProc: (logs: Logger, signal: AbortSignal, snapshots: SnapshotStore) => Proc;
@@ -1,104 +0,0 @@
1
- import { execFileSync } from "node:child_process";
2
- import os from "node:os";
3
- import { $, kill, usePowerShell } from "zx";
4
- // zx defaults to bash, which isn't present on a stock Windows box.
5
- // Use Windows PowerShell there so zx spawns and quotes for the right shell.
6
- if (os.platform() === "win32")
7
- usePowerShell();
8
- /**
9
- * Force-kill a process **and its whole tree, synchronously**.
10
- *
11
- * Windows has no process groups: a child outlives its parent, and a Ctrl-C sent
12
- * to the console group can make an intermediate shell exit and *orphan* the real
13
- * app (e.g. electron.exe), which then survives teardown. So the tree must be
14
- * reaped explicitly by PID — `taskkill /F /T` does it, and running it
15
- * **synchronously** guarantees it completes before the run's own process exits
16
- * (a fire-and-forget kill can lose that race). On POSIX, zx's `kill` already
17
- * does a process-group tree kill. Best-effort: an already-dead/missing PID is
18
- * ignored.
19
- */
20
- export const killTree = (pid) => {
21
- if (process.platform === "win32") {
22
- try {
23
- execFileSync("taskkill", ["/F", "/T", "/PID", String(pid)], { stdio: "ignore" });
24
- }
25
- catch {
26
- // already gone, access denied, or taskkill missing — nothing more to do
27
- }
28
- }
29
- else {
30
- void kill(pid).catch(() => { });
31
- }
32
- };
33
- /**
34
- * Builds a {@link Proc} bound to a specific log sink, abort signal, and the run's
35
- * snapshot store. The action pipeline injects one per action as `ctx.proc`, wired
36
- * to that action's logger, the run's signal, and the run's `output.snapshots` — so
37
- * actions just describe the command, with no ambient lookup and nothing threaded
38
- * through. A custom source (e.g. a CDP connection) follows the same shape: take the
39
- * action's `logs`/`signal`, push into the log, and hook teardown.
40
- */
41
- export const createProc = (logs, signal, snapshots) => (name, opts) => {
42
- // quiet: zx must not echo the child's output to our terminal — the collector
43
- // owns all output (otherwise every line prints twice: raw from zx, formatted
44
- // from the drain). Caller opts can still override.
45
- const $$ = $({ quiet: true, ...opts });
46
- return (pieces, ...args) => {
47
- const child = $$(pieces, ...args);
48
- // Record the launch on the timeline as an event (the `event` level renders
49
- // `[ev]`), under the proc's own `source` so it's filterable by origin in
50
- // run.jsonl while still rendering as a milestone. The command zx resolved
51
- // rides inline for scanning; the structured args (cmd, cwd, …) are written
52
- // to a snapshot file and linked, exactly as the event bus does for a
53
- // non-string payload (see events.ts).
54
- //
55
- // `env` is dropped: passing it to zx means handing the whole environment
56
- // (you spread `...process.env` to add one var), so snapshotting it would
57
- // write 600+ entries — secrets and tokens included — to logs/ on every
58
- // launch. Everything else in opts is kept.
59
- const { env: _env, ...safeOpts } = opts ?? {};
60
- // Resolve where the child actually runs. zx only records cwd on its child
61
- // when one was passed; left unset it falls back to process.cwd() at spawn,
62
- // so mirror that here to always log a concrete directory (the `...safeOpts`
63
- // spread sits before `cwd` so this resolved value wins even when opts omits
64
- // it). This is the "where" that makes a launch line reproducible.
65
- const cwd = opts?.cwd ?? process.cwd();
66
- const snap = snapshots.captureJson(`proc-${name}-start`, {
67
- cmd: child.cmd,
68
- ...safeOpts,
69
- cwd,
70
- });
71
- logs.append({
72
- source: name,
73
- level: "event",
74
- message: `${name} · start · ${child.cmd} · in ${cwd} · → ${snap.rel}`,
75
- });
76
- logs.attach(child.stdout, name, "info");
77
- logs.attach(child.stderr, name, "error");
78
- // Kill the child's entire process tree on teardown via {@link killTree} —
79
- // a synchronous, force tree kill by PID (taskkill /F /T on Windows,
80
- // process-group kill on Unix). Synchronous so it finishes before the run's
81
- // process exits. NOTE: with zx the direct child is a *shell wrapper*
82
- // (PowerShell on Windows), so this only reaps grandchildren while that
83
- // wrapper is still alive; a GUI app that must survive its shell being
84
- // Ctrl-C'd should be launched shell-less via `command(name, file, args)`,
85
- // whose direct child is the app itself.
86
- let finished = false;
87
- const onAbort = () => {
88
- if (finished)
89
- return;
90
- const pid = child.pid;
91
- if (pid != null)
92
- killTree(pid);
93
- };
94
- const markFinished = () => {
95
- finished = true;
96
- signal.removeEventListener("abort", onAbort);
97
- };
98
- signal.addEventListener("abort", onAbort, { once: true });
99
- // Registered before the caller's own `.then`, so `finished` is set before a
100
- // completion handler can fire `cancel()` and abort us.
101
- void child.then(markFinished, markFinished);
102
- return child;
103
- };
104
- };
@@ -1,2 +0,0 @@
1
- /** Serialize a value for a snapshot file, tolerating circular refs / non-JSON values. */
2
- export declare const serialize: (value: unknown) => string;
@@ -1,12 +0,0 @@
1
- /** Serialize a value for a snapshot file, tolerating circular refs / non-JSON values. */
2
- export const serialize = (value) => {
3
- try {
4
- // JSON.stringify returns undefined for functions/undefined — fall back to a string.
5
- return JSON.stringify(value, null, 2) ?? JSON.stringify(String(value));
6
- }
7
- catch {
8
- // Circular or otherwise non-serializable: keep a best-effort representation
9
- // rather than throwing and losing the value entirely.
10
- return JSON.stringify(String(value));
11
- }
12
- };
File without changes