@maiaos/node 0.1.0-canary.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -0
- package/dist/bin/exit.js +105 -0
- package/dist/bin/exit.js.map +1 -0
- package/dist/bin/maia-node.NOTICES.txt +3917 -0
- package/dist/bin/maia-node.cdx.json +2448 -0
- package/dist/bin/maia-node.meta.json +1 -0
- package/dist/bin/maia-node.mjs +9011 -0
- package/dist/bin/maia-node.mjs.map +6 -0
- package/dist/bin/maia-node.release.json +112 -0
- package/dist/bin/maia-process-host-darwin-arm64 +0 -0
- package/dist/bin/maia-process-host-darwin-arm64.build.json +59 -0
- package/dist/bin/maia-process-host-linux-x64 +0 -0
- package/dist/bin/maia-process-host-linux-x64.build.json +64 -0
- package/package.json +86 -0
package/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# @maiaos/node
|
|
2
|
+
|
|
3
|
+
Maia Node, the local authority of Maia OS: one process per machine and profile
|
|
4
|
+
that owns Sessions, turns, worker accounts, durable state, event order and
|
|
5
|
+
receipts for swarms of AI coding agents.
|
|
6
|
+
|
|
7
|
+
> **Pre-release.** npm carries only `canary` builds (nightlies are historical; none are built since D-185), which are
|
|
8
|
+
> not release-qualified. No stable release exists
|
|
9
|
+
> ([D-132](https://github.com/vllnt/maia/blob/main/docs/decisions.md#d-132)).
|
|
10
|
+
|
|
11
|
+
## Requirements
|
|
12
|
+
|
|
13
|
+
- Node.js 24.22.1.
|
|
14
|
+
- macOS on Apple silicon or Linux x64, the platforms whose process host the
|
|
15
|
+
published builds ship (Linux is a source candidate). Windows is unsupported
|
|
16
|
+
and fails with `platform_unsupported`.
|
|
17
|
+
- On Linux, set pnpm's `packageImportMethod` to `clone-or-copy` before you
|
|
18
|
+
install: the Node refuses a process host with a second hard link, which pnpm
|
|
19
|
+
makes on ext4. Worker containment also needs a delegated cgroup v2 subtree
|
|
20
|
+
and Linux 6.12 or later
|
|
21
|
+
([operations](https://github.com/vllnt/maia/blob/main/docs/operations.md)).
|
|
22
|
+
- Claude Code or the Codex CLI, for workers.
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
pnpm add -g @maiaos/node@canary
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Install the [`maia` CLI](https://github.com/vllnt/maia/blob/main/apps/cli/README.md)
|
|
31
|
+
with it to drive the Node.
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
Run the Node in the foreground, then check it from a second terminal with the
|
|
36
|
+
CLI:
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
maia-node --desktop --profile <name> # --profile defaults to "default"
|
|
40
|
+
maia --profile <name> status # the Node reports ready
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The Node binds an ephemeral port on `127.0.0.1` only and writes an
|
|
44
|
+
owner-private connection descriptor and credential to its profile directory.
|
|
45
|
+
Every client reaches it through `@maiaos/sdk`; none of them owns state.
|
|
46
|
+
|
|
47
|
+
From a source checkout, `pnpm dev:node` runs a Node inside an isolated dev
|
|
48
|
+
worktree and never touches your real `~/.maia`. See the
|
|
49
|
+
[quick start](https://github.com/vllnt/maia#quick-start).
|
|
50
|
+
|
|
51
|
+
## Status
|
|
52
|
+
|
|
53
|
+
**Source candidate.** The Node validates and authorizes each operation, stores
|
|
54
|
+
the result in SQLite, writes a receipt and runs Codex and Claude Code workers
|
|
55
|
+
as child processes under a native process host. A local background service is
|
|
56
|
+
planned. The
|
|
57
|
+
[roadmap](https://github.com/vllnt/maia/blob/main/ROADMAP.md) tracks each
|
|
58
|
+
slice.
|
|
59
|
+
|
|
60
|
+
## Links
|
|
61
|
+
|
|
62
|
+
- [Node architecture](https://github.com/vllnt/maia/blob/main/docs/maia-node/architecture.md)
|
|
63
|
+
- [Operations](https://github.com/vllnt/maia/blob/main/docs/operations.md):
|
|
64
|
+
lifecycle, remote Nodes, SQLite, backup and observability
|
|
65
|
+
- [Vendor executors](https://github.com/vllnt/maia/blob/main/docs/maia-swarm/external-executors.md)
|
|
66
|
+
- [Security policy](https://github.com/vllnt/maia/blob/main/SECURITY.md)
|
|
67
|
+
- [Repository](https://github.com/vllnt/maia)
|
package/dist/bin/exit.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import * as NodeRuntime from "@effect/platform-node-shared/NodeRuntime";
|
|
2
|
+
import { Cause, Clock, Deferred, Effect, Exit, Fiber, Option, Ref, Runtime, } from "effect";
|
|
3
|
+
import { ShutdownDeadline } from "../runtime/desktop-parent/index.js";
|
|
4
|
+
/** How long, in milliseconds, the process waits for readers to take its output once the command ends. */
|
|
5
|
+
const OUTPUT_DEADLINE = 5000;
|
|
6
|
+
/**
|
|
7
|
+
* Twin of `watch` in apps/cli/src/bootstrap/exit.ts: keep the two in step.
|
|
8
|
+
* Watches a stream from the start and returns its drain. An empty write
|
|
9
|
+
* completes after every earlier write; a stream that fails or closes takes no
|
|
10
|
+
* more output. A reader that closes fails its stream with EPIPE, and the error
|
|
11
|
+
* listener keeps that error from replacing the command's exit code. Skip a
|
|
12
|
+
* stream with nothing queued: on macOS even an empty write fails with EPIPE
|
|
13
|
+
* once the reader has closed.
|
|
14
|
+
*/
|
|
15
|
+
const watch = (output) => Effect.gen(function* () {
|
|
16
|
+
const ended = yield* Deferred.make();
|
|
17
|
+
const end = () => {
|
|
18
|
+
Deferred.doneUnsafe(ended, Effect.succeed(true));
|
|
19
|
+
};
|
|
20
|
+
output.on("error", end);
|
|
21
|
+
output.on("close", end);
|
|
22
|
+
const flushed = Effect.callback((resume) => {
|
|
23
|
+
if (output.writableLength === 0) {
|
|
24
|
+
resume(Effect.succeed(true));
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
output.write("", () => {
|
|
28
|
+
resume(Effect.succeed(true));
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
return Effect.raceFirst(Deferred.await(ended), flushed);
|
|
32
|
+
});
|
|
33
|
+
/** A drained interrupt is a clean stop (systemd logs no failure for a restart). */
|
|
34
|
+
const exitCode = (exit) => {
|
|
35
|
+
if (Exit.isSuccess(exit))
|
|
36
|
+
return exit.value;
|
|
37
|
+
if (Cause.hasInterruptsOnly(exit.cause))
|
|
38
|
+
return 0;
|
|
39
|
+
return Runtime.getErrorExitCode(Cause.squash(exit.cause));
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Waits for every drain up to OUTPUT_DEADLINE, and never past the shutdown
|
|
43
|
+
* deadline that a closed Desktop parent pipe sets. None when time runs out.
|
|
44
|
+
*/
|
|
45
|
+
const drainBy = (drains, deadline) => Effect.gen(function* () {
|
|
46
|
+
const now = Number((yield* Clock.monotonicTimeNanos) / 1000000n);
|
|
47
|
+
// A wait of 0 or less ends at once.
|
|
48
|
+
const left = (yield* Ref.get(deadline)) - now;
|
|
49
|
+
return yield* Effect.all(drains, {
|
|
50
|
+
concurrency: "unbounded",
|
|
51
|
+
discard: true,
|
|
52
|
+
}).pipe(Effect.timeoutOption(Math.min(OUTPUT_DEADLINE, left)));
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* Runs the command, then waits for stdout and stderr to reach their readers
|
|
56
|
+
* (see drainBy), and leaves with the command's code. Signals cannot cut that
|
|
57
|
+
* wait short. A failed stream loses its own queued output but neither the
|
|
58
|
+
* code nor the other stream's output. Exit 0 after drained output waits for
|
|
59
|
+
* the event loop instead: a Node that keeps its profile lock for an unsettled
|
|
60
|
+
* telemetry write lives until that write settles. A closed Desktop parent pipe
|
|
61
|
+
* interrupts the command without a signal, so an interrupt leaves explicitly,
|
|
62
|
+
* even while a telemetry write holds the lock.
|
|
63
|
+
*/
|
|
64
|
+
export const exitAfterOutput = (command, host) => Effect.uninterruptibleMask((restore) => Effect.gen(function* () {
|
|
65
|
+
const drains = [yield* watch(host.stdout), yield* watch(host.stderr)];
|
|
66
|
+
// runMain installs its SIGINT and SIGTERM listeners after starting the
|
|
67
|
+
// fiber, and leaves them installed if the fiber already finished.
|
|
68
|
+
yield* Effect.yieldNow;
|
|
69
|
+
// The command runs as its own fiber, so its end interrupts and awaits
|
|
70
|
+
// the fibers it forked, such as the Desktop wrapper's Node. A signal
|
|
71
|
+
// interrupts this wait instead: pass it on and await the command. A
|
|
72
|
+
// signal during that cleanup ends the fiber interrupted, so keep the
|
|
73
|
+
// command's own exit.
|
|
74
|
+
const outcome = yield* Deferred.make();
|
|
75
|
+
const deadline = yield* Ref.make(Number.POSITIVE_INFINITY);
|
|
76
|
+
const running = yield* Effect.forkChild(command.pipe(Effect.onExit((exit) => Deferred.succeed(outcome, exit)), Effect.provideService(ShutdownDeadline, deadline)), { startImmediately: true });
|
|
77
|
+
yield* Effect.exit(restore(Fiber.await(running)));
|
|
78
|
+
yield* Fiber.interrupt(running);
|
|
79
|
+
const exit = yield* Deferred.await(outcome);
|
|
80
|
+
const code = exitCode(exit);
|
|
81
|
+
const inTime = yield* drainBy(drains, deadline);
|
|
82
|
+
if (code !== 0 || Exit.isFailure(exit) || Option.isNone(inTime)) {
|
|
83
|
+
host.exit(code);
|
|
84
|
+
}
|
|
85
|
+
}));
|
|
86
|
+
/**
|
|
87
|
+
* A signal during the drain after exit 0 ends the fiber interrupted; runMain
|
|
88
|
+
* then exits 0. Once the fiber ends, runMain removes its listeners, so a later
|
|
89
|
+
* signal takes its default action.
|
|
90
|
+
*/
|
|
91
|
+
const teardown = (exit, onExit) => {
|
|
92
|
+
if (Exit.isFailure(exit) && !Cause.hasInterruptsOnly(exit.cause)) {
|
|
93
|
+
Runtime.defaultTeardown(exit, onExit);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
onExit(0);
|
|
97
|
+
};
|
|
98
|
+
/** The process entry: runMain owns SIGINT and SIGTERM for the whole run. */
|
|
99
|
+
export const runCommand = (command, host) => {
|
|
100
|
+
NodeRuntime.runMain(exitAfterOutput(command, host), {
|
|
101
|
+
disableErrorReporting: true,
|
|
102
|
+
teardown,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