@omochi-ui/utils 0.1.2 → 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.
package/README.md CHANGED
@@ -1,202 +1,65 @@
1
- # @omochi-ui/utils
2
-
3
- Publish command controls, development observations, and agent-created A2UI
4
- surfaces through the existing Omochi gateway. Requires a Unix-like environment,
5
- like the discovery transport. Build with `bun install && bun run build` from the
6
- repository root.
7
-
8
- ## Turn a command into a button
9
-
10
- ```sh
11
- bun run omochi-utils button --service-id build --name "Build" -- bun run build
12
- # In another terminal:
13
- bun run omochi-ui hub
14
- ```
15
-
16
- Open the hub's printed URL, then use **Add view** to add `Build · main` to a
17
- dashboard. The command runs only when clicked. The surface shows live combined
18
- stdout/stderr, running status and the exit code. Only one execution can run at
19
- a time, including when multiple browsers are connected. After completion or a
20
- startup failure the button can be used again.
21
-
22
- ```sh
23
- bun run omochi-utils button --name "Tests" --cwd /path/to/project -- bun run test
24
- bun run omochi-utils button --name "Pipeline" -- sh -c 'printf hello | wc -c'
25
- ```
26
-
27
- Arguments after `--` are passed literally without a shell. Commands inherit the
28
- environment and current directory unless `--cwd` is supplied; stdin is closed.
29
- Output keeps the latest 64 KiB, marks truncation, and resets on each run. It is
30
- displayed as literal code, not interpreted as Markdown. Ctrl+C or SIGTERM stops
31
- child process groups (TERM, then KILL within one second) and retracts the service.
32
-
33
- ## Watch a command
34
-
35
- ```sh
36
- bun run omochi-utils watch --interval 2s -- git status --short
37
- bun run omochi-utils watch --diff --on-change --history 10 -- bun run test
38
- bun run omochi-utils watch --timeout 30s --cwd /path/to/project -- command args
39
- ```
40
-
41
- `watch` runs immediately, waits for the command to finish, then waits for the
42
- interval before running again. Runs never overlap. The surface can pause future
43
- runs, resume immediately, or run once now. `--timeout` stops a hung process group.
44
- `--diff` shows the current output and a line diff from the previous run;
45
- `--on-change` suppresses completed updates whose output and exit result are
46
- unchanged. `--history N` retains 1–100 short execution records without retaining
47
- old full output.
48
-
49
- ## Control a long-running process
50
-
51
- ```sh
52
- bun run omochi-utils process --name "Dev server" -- bun run dev
53
- bun run omochi-utils process --restart on-failure --restart-delay 2s -- worker
54
- ```
55
-
56
- Processes start only when **Start** is clicked. The surface provides **Stop** and
57
- **Restart**, retains the latest 64 KiB of logs across restarts, and records exit
58
- reasons. `--restart` accepts `never` (the default), `on-failure`, or `always`.
59
- Manual stops and CLI shutdown never trigger automatic restart.
60
-
61
- ## Follow a log file or stdin
62
-
63
- ```sh
64
- bun run omochi-utils tail --lines 200 ./logs/api.log
65
- journalctl -f | bun run omochi-utils stream --name "System log"
66
- ```
67
-
68
- `tail` waits if the path does not exist and follows the name across truncation
69
- and log rotation, like `tail -F`. It treats the file as UTF-8 and never writes to
70
- it. `stream` displays stdin as UTF-8. When stdin reaches EOF, it leaves the final
71
- surface visible until SIGINT or SIGTERM instead of exiting immediately.
72
-
73
- ## Monitor HTTP
74
-
75
- ```sh
76
- bun run omochi-utils http http://127.0.0.1:3000/health
77
- bun run omochi-utils http --interval 30s --timeout 5s \
78
- --expect-status 200 --expect-body '"ready":true' https://example.test/health
79
- ```
80
-
81
- `http` sends non-overlapping GET requests and provides the same pause, resume,
82
- and run-now controls as `watch`. It shows status, latency, final URL, content
83
- type, size, consecutive failures, and health transitions. The default expected
84
- status is 200–299. Text responses are shown up to 64 KiB; JSON media types are
85
- parsed and pretty-printed. Binary response bodies are not displayed. For custom
86
- methods, headers, authentication, or request bodies, use `watch -- curl ...`.
87
-
88
- ## Let an agent publish surfaces over MCP
89
-
90
- Configure a stdio MCP server in your agent. For a source checkout, point Node to
91
- the absolute path of the built CLI:
92
-
93
- ```json
94
- {
95
- "mcpServers": {
96
- "omochi": {
97
- "command": "bun",
98
- "args": ["/absolute/path/to/omochi-ui/packages/utils/bin/omochi-utils.js", "mcp", "--name", "Agent"]
99
- }
100
- }
101
- }
102
- ```
103
-
104
- The process publishes through `UnixSocketServerTransport`; an existing gateway
105
- discovers it automatically. Start `omochi-ui hub` separately to view surfaces.
106
- The agent, gateway and hub must share the same user and `XDG_RUNTIME_DIR` for
107
- local discovery. Existing SSH/paired-gateway routing works without changes.
108
-
109
- | Tool | Arguments | Result |
110
- | --- | --- | --- |
111
- | `publish_messages` | `messages`: nonempty A2UI v0.9 message array | `accepted`, `serviceId`, `surfaceIds` |
112
- | `list_surfaces` | none | `serviceId`, `surfaceIds` |
113
- | `read_events` | `after` (default 0), `timeoutMs` (default 0, max 30000) | `events`, `nextCursor`, `dropped`, `closed` |
114
-
115
- `publish_messages` accepts standard `createSurface`, `updateComponents`,
116
- `updateDataModel`, and `deleteSurface` messages. It validates the entire batch
117
- against the current state before sending anything. Errors report the failing
118
- array index, leaving the published state intact. Concurrent calls are serialized.
119
- Use surface-local IDs; gateway/hub prefixes are applied by the existing routers.
120
- Validation checks wire shape and surface lifecycle; catalog-specific component
121
- validation is still performed by the renderer.
122
-
123
- For example, pass this to `publish_messages` to publish an interactive form:
124
-
125
- ```json
126
- {
127
- "messages": [
128
- {
129
- "version": "v0.9",
130
- "createSurface": {
131
- "surfaceId": "main",
132
- "catalogId": "https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json",
133
- "sendDataModel": true
134
- }
135
- },
136
- {
137
- "version": "v0.9",
138
- "updateComponents": {
139
- "surfaceId": "main",
140
- "components": [
141
- { "id": "root", "component": "Column", "children": ["title", "request", "submit"] },
142
- { "id": "title", "component": "Text", "text": "What should we build?" },
143
- { "id": "request", "component": "TextField", "label": "Request", "value": { "path": "/request" } },
144
- { "id": "submit", "component": "Button", "child": "label", "action": { "event": { "name": "submit", "context": { "request": { "path": "/request" } } } } },
145
- { "id": "label", "component": "Text", "text": "Send" }
146
- ]
147
- }
148
- },
149
- { "version": "v0.9", "updateDataModel": { "surfaceId": "main", "path": "/", "value": { "request": "" } } }
150
- ]
151
- }
152
- ```
153
-
154
- Call `read_events` with `{ "after": 0, "timeoutMs": 30000 }`. Each returned event
155
- contains `sequence`, `receivedAt` (ISO timestamp), and the original A2UI client
156
- `message`, including `action.context` and any client data model metadata. The
157
- example's submitted text is in `message.action.context.request`. Respond by
158
- publishing another message batch:
159
-
160
- ```json
161
- {
162
- "messages": [{
163
- "version": "v0.9",
164
- "updateComponents": {
165
- "surfaceId": "main",
166
- "components": [{ "id": "title", "component": "Text", "text": "Working…" }]
167
- }
168
- }]
169
- }
170
- ```
171
-
172
- Use the returned `nextCursor` as `after` for the next read. Reads do not consume
173
- events, so retrying a cursor is safe. The latest 1,000 events are retained;
174
- `dropped` reports how many events since the requested cursor have expired. A
175
- timeout returns an empty array. Pending reads support MCP cancellation and are
176
- woken on shutdown. Button clicks do not automatically wake an idle agent: it
177
- must call `read_events`. These tools do not execute shell commands or callbacks.
178
-
179
- To remove a surface, publish
180
- `{"version":"v0.9","deleteSurface":{"surfaceId":"main"}}`.
181
- There is no persistence: stdin EOF, SIGINT or SIGTERM closes the MCP server and
182
- retracts its service. A gateway connecting later receives current surface state.
183
-
184
- ## Shared options and lifetime
185
-
186
- All subcommands accept `--service-id ID` and `--name NAME`. IDs default to a
187
- unique `utils-<uuid>`; use an explicit stable ID if saving a dashboard layout.
188
- Starting a second process with a live ID fails without replacing the first.
189
- Durations accept `ms`, `s`, and `m` suffixes. Each process has its own surfaces
190
- and event buffer. Service registration does not start the gateway or
191
- automatically place panels on a dashboard.
192
-
193
- Use `bun run omochi-utils --help` for usage. No new TCP listener, dashboard API,
194
- or transport protocol is introduced. Runtime directory permissions and existing
195
- gateway access controls apply to these services as to other Omochi apps.
196
-
197
- ## Tests
198
-
199
- `bun run build` then `bun run --filter @omochi-ui/utils test`
200
- runs command execution, watch/diff, process restart, tail/stream, HTTP, shutdown,
201
- event cursor, stdio MCP, and gateway integration tests. Temporary runtime
202
- directories keep tests separate from real services.
1
+ # Omochi native services
2
+
3
+ The archive contains omochi-ui and omochi-utils for the target in manifest.json.
4
+ The production dashboard is embedded. Neither binary requires Bun, Node.js,
5
+ Python or Rust at runtime. Applications launched by them need their own runtime.
6
+
7
+ Verify the archive against its .sha256 file, extract it, and install both binaries:
8
+
9
+ ./install.sh # $HOME/.local/bin
10
+ ./install.sh /your/preferred/bin # optional destination
11
+ omochi-ui hub
12
+
13
+ The default dashboard is http://127.0.0.1:5555. Keep this loopback default.
14
+ Use omochi-ui up omochi.toml for compositions, and omochi-utils --help for utility
15
+ modes. dev bridges application stdio to the separate developer preview frontend;
16
+ the Vite developer preview is not included in this archive.
17
+
18
+ ## Pairing
19
+
20
+ On the gateway machine:
21
+
22
+ omochi-ui gateway --remote --pair --name workstation
23
+
24
+ Import its invitation on the hub PC:
25
+
26
+ omochi-ui pair --name workstation
27
+ # Paste the invitation on stdin, then Ctrl+D.
28
+ omochi-ui hub
29
+
30
+ Possession of an invitation grants access. It expires after 180 seconds and admits
31
+ one hub; keep it private. Registered gateways connect automatically without IP
32
+ input. --offline disables public discovery and relays while retaining LAN mDNS
33
+ and direct connections.
34
+
35
+ Online development uses n0 public discovery and relays. For a project relay, use
36
+ the same --relay https://your-relay.example option on remote gateway, pair and hub
37
+ commands. This archive does not provision a relay. The source repository includes host
38
+ configuration and monitoring templates in deploy/relay.
39
+
40
+ status reports registered gateway connection attempts and failures from the running
41
+ hub (use --port if the hub has a non-default port). It does not initialize state.
42
+
43
+ trust list shows peers. trust forget NAME_OR_ENDPOINT_ID waits for live processes
44
+ to destroy revoked connections. An acknowledgement failure remains an error even
45
+ though the trust removal is already durable.
46
+
47
+ ## Breaking upgrade
48
+
49
+ Stop old gateways/hubs first. SDK APIs and manifests are unchanged; gateway wire
50
+ protocol and NodeIds are new. Pair devices again and recreate saved dashboards.
51
+ Native state lives at $XDG_CONFIG_HOME/omochi/rust-v1 or
52
+ $HOME/.config/omochi/rust-v1. Legacy state is left untouched.
53
+
54
+ Linux binaries use their build runner's libc; choose an OS/architecture-compatible
55
+ archive and libc, or build from source. This script does not codesign or notarize
56
+ macOS binaries.
57
+
58
+ ## Registry distributions
59
+
60
+ Native releases also prepare npm `@omochi-ui/cli` and `@omochi-ui/utils` under
61
+ the existing package names, using exact-version platform binary dependencies.
62
+ The npm launcher needs Node.js 22+; the native archives above do not. Published
63
+ Cargo sources can be installed with `cargo install omochi-cli --locked` and
64
+ `cargo install omochi-utils --locked`. The existing `omochi-ui` crate remains the SDK.
65
+ See docs/native-releasing.md in the repository for release setup and migration.
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ const path = require('node:path');
4
+ const { spawn } = require('node:child_process');
5
+ const manifest = require('../package.json');
6
+ const platform = `${process.platform}-${process.arch}`;
7
+ const dependency = manifest.nativePlatforms[platform];
8
+ function fail(message) { console.error(`[${manifest.name}] ${message}`); process.exit(1); }
9
+ if (!dependency) fail(`Unsupported platform ${platform}. Use a supported Linux/glibc or macOS build.`);
10
+ if (process.platform === 'linux' && !process.report?.getReport().header.glibcVersionRuntime) {
11
+ fail('The prebuilt Linux binary requires glibc. On musl, build with cargo install instead.');
12
+ }
13
+ let binary;
14
+ try {
15
+ const installed = require.resolve(`${dependency}/package.json`);
16
+ const native = require(installed);
17
+ if (native.version !== manifest.version) fail(`Binary version mismatch: expected ${manifest.version}, found ${native.version}. Reinstall the package.`);
18
+ binary = path.join(path.dirname(installed), 'bin', manifest.nativeBinary);
19
+ } catch {
20
+ fail(`Missing ${dependency}@${manifest.version}. Reinstall with optional dependencies enabled (npm install --include=optional).`);
21
+ }
22
+ const child = spawn(binary, process.argv.slice(2), { stdio: 'inherit' });
23
+ const handlers = new Map();
24
+ for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
25
+ const handler = () => child.kill(signal);
26
+ handlers.set(signal, handler);
27
+ process.on(signal, handler);
28
+ }
29
+ child.once('error', error => fail(`Cannot start ${binary}: ${error.message}`));
30
+ child.once('exit', (code, signal) => {
31
+ for (const [name, handler] of handlers) process.removeListener(name, handler);
32
+ if (signal) process.kill(process.pid, signal);
33
+ else process.exitCode = code ?? 1;
34
+ });
package/package.json CHANGED
@@ -1,37 +1,35 @@
1
1
  {
2
2
  "name": "@omochi-ui/utils",
3
- "version": "0.1.2",
4
- "publishConfig": {
5
- "access": "public",
6
- "registry": "https://registry.npmjs.org/"
7
- },
3
+ "version": "0.2.0",
4
+ "description": "Native Omochi utils",
5
+ "files": [
6
+ "bin"
7
+ ],
8
8
  "engines": {
9
- "bun": ">=1.4.3"
9
+ "node": ">=22"
10
10
  },
11
- "description": "Publish development utilities and agent-created A2UI surfaces to Omochi",
12
- "license": "Apache-2.0",
13
- "type": "module",
14
11
  "bin": {
15
- "omochi-utils": "./bin/omochi-utils.js"
12
+ "omochi-utils": "./bin/omochi-utils.cjs"
16
13
  },
17
- "files": [
18
- "bin",
19
- "dist"
20
- ],
21
- "dependencies": {
22
- "@modelcontextprotocol/sdk": "^1.31.0",
23
- "diff": "^9.0.0",
24
- "@omochi-ui/core": "0.1.2",
25
- "@omochi-ui/sdk": "0.1.2",
26
- "zod": "^4.0.0"
14
+ "nativeBinary": "omochi-utils",
15
+ "nativePlatforms": {
16
+ "linux-x64": "@omochi-ui/native-linux-x64",
17
+ "linux-arm64": "@omochi-ui/native-linux-arm64",
18
+ "darwin-x64": "@omochi-ui/native-darwin-x64",
19
+ "darwin-arm64": "@omochi-ui/native-darwin-arm64"
20
+ },
21
+ "optionalDependencies": {
22
+ "@omochi-ui/native-linux-x64": "0.2.0",
23
+ "@omochi-ui/native-linux-arm64": "0.2.0",
24
+ "@omochi-ui/native-darwin-x64": "0.2.0",
25
+ "@omochi-ui/native-darwin-arm64": "0.2.0"
27
26
  },
27
+ "license": "Apache-2.0",
28
28
  "repository": {
29
29
  "type": "git",
30
- "url": "https://github.com/omochi-ui/omochi.git",
31
- "directory": "packages/utils"
30
+ "url": "https://github.com/omochi-ui/omochi.git"
32
31
  },
33
- "homepage": "https://github.com/omochi-ui/omochi#readme",
34
- "bugs": {
35
- "url": "https://github.com/omochi-ui/omochi/issues"
32
+ "publishConfig": {
33
+ "access": "public"
36
34
  }
37
35
  }
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env bun
2
- import '../dist/cli.js';
package/dist/button.d.ts DELETED
@@ -1,20 +0,0 @@
1
- import { type UI } from "@omochi-ui/sdk";
2
- import { Publisher } from "./publisher.js";
3
- import { UtilitySurface } from "./surface.js";
4
- export interface ButtonOptions {
5
- command: string[];
6
- cwd?: string;
7
- name: string;
8
- }
9
- export declare class CommandButton extends UtilitySurface {
10
- private readonly output;
11
- private readonly runner;
12
- private running;
13
- private status;
14
- private closePromise?;
15
- constructor(publisher: Publisher, options: ButtonOptions);
16
- protected build(ui: UI): void;
17
- protected onAction(name: string): void;
18
- close(): Promise<void>;
19
- private run;
20
- }
package/dist/button.js DELETED
@@ -1,51 +0,0 @@
1
- import { Action } from "@omochi-ui/sdk";
2
- import { ManagedCommand, describeResult } from "./command.js";
3
- import { OutputBuffer, fenced } from "./output.js";
4
- import { UtilitySurface } from "./surface.js";
5
- export class CommandButton extends UtilitySurface {
6
- output = new OutputBuffer();
7
- runner;
8
- running = false;
9
- status = "Ready";
10
- closePromise;
11
- constructor(publisher, options) {
12
- super(publisher, options.name);
13
- this.runner = new ManagedCommand({
14
- command: options.command,
15
- cwd: options.cwd,
16
- onData: (chunk) => {
17
- this.output.append(chunk);
18
- this.scheduleRender();
19
- },
20
- });
21
- }
22
- build(ui) {
23
- ui.text(this.name, { key: "title", variant: "h3" });
24
- if (!this.running)
25
- ui.button("Run", new Action("run").call(null), { key: "run", variant: "primary" });
26
- ui.text(this.status, { key: "status" });
27
- ui.text(fenced(this.output.text, this.output.truncated), { key: "output" });
28
- }
29
- onAction(name) {
30
- if (name !== "run" || this.running || this.closing)
31
- return;
32
- void this.run();
33
- }
34
- close() {
35
- if (this.closePromise)
36
- return this.closePromise;
37
- this.closeSurface();
38
- this.closePromise = this.runner.close();
39
- return this.closePromise;
40
- }
41
- async run() {
42
- this.running = true;
43
- this.output.reset();
44
- this.status = "Running…";
45
- this.scheduleRender();
46
- const result = await this.runner.start();
47
- this.running = false;
48
- this.status = describeResult(result);
49
- this.scheduleRender();
50
- }
51
- }
package/dist/cli.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};