@nocoo/bat 0.0.0-stage → 3.1.2

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 (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +130 -2
  3. package/dist/bat.js +9722 -0
  4. package/package.json +52 -5
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Zheng Li
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,131 @@
1
- # Temporary Holding Version
1
+ # `bat` CLI
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Command line client for [bat](https://bat.hexly.ai). It talks to two independent domains and keeps
4
+ them isolated: an **assets profile** for the bat API, and a **workstation profile** for this machine.
5
+
6
+ ```bash
7
+ npm install --global @nocoo/bat
8
+ # or run without installing
9
+ npx @nocoo/bat --help
10
+ ```
11
+
12
+ Requires Node.js 22 or newer. The published package is a single self-contained bundle: no
13
+ postinstall scripts, no native build step, no workspace dependencies at runtime.
14
+
15
+ ## Domains
16
+
17
+ | Domain | Host | Credential | Commands |
18
+ | ------------------- | -------------------------------------------------------------------- | ----------------------- | --------------------------------------------------------- |
19
+ | Assets profile | Browser login at `bat.hexly.ai`; API at `bat-ingest.worker.hexly.ai` | Assets-scoped CLI token | `login`, `status`, `agent`, `asset`, `binding`, `service` |
20
+ | Workstation profile | `https://bat-ingest.worker.hexly.ai` (ingest) | `batw_` workstation key | `workstation login`, `setup`, `probe`, `status`, `logout` |
21
+
22
+ Asset commands manage remote agents, assets and bindings. Login and service commands also manage
23
+ their own local configuration and heartbeat task. Workstation commands report this laptop or desktop's
24
+ capacity and server reachability. The dashboard retains their observation history under the global
25
+ retention setting; workstation probes do not collect process lists or create server alerts.
26
+
27
+ The two profiles never share credential files or tokens. They use separately configured API origins;
28
+ a workstation login does not overwrite the assets profile.
29
+
30
+ ## Asset commands
31
+
32
+ ```bash
33
+ bat login [--url https://bat.hexly.ai] # browser OAuth, writes ~/.config/bat/config.json
34
+ bat status # verify the stored token against the API
35
+ bat agent list # agents registered for this source key
36
+ bat agent create <match-key> [--nickname ...] [--role ...]
37
+ bat agent update <id> [--status ...] [--clear-nickname]
38
+ bat agent delete <id>
39
+ bat agent heartbeat <key:running,key:stopped>
40
+ bat agent tags <id> [--tag-ids 1,2,3] [--clear]
41
+ bat asset list|create|update|delete|tags
42
+ bat binding list|create|delete
43
+ bat service run <key:status,...> # foreground heartbeat loop
44
+ bat service status # PID file check
45
+ bat service install <key:status,...> # macOS launchd plist (does not load it)
46
+ bat service uninstall # bootout + remove the plist
47
+ ```
48
+
49
+ The config lives in `~/.config/bat/` with `0600` permissions. Credentials are overwritten only by
50
+ `bat login`; a re-login keeps the installation `source_key` unless none exists yet.
51
+
52
+ ## Workstation commands
53
+
54
+ Workstation commands live under `bat workstation` with their own profile in
55
+ `~/.config/bat/workstation/`. The stable installation UUID (`installation.json`) survives logout; the
56
+ `batw_` credential (`workstation.json`) does not. Both files are atomic writes with `0600` permissions, and
57
+ a Windows login additionally restricts the directory ACL to the current user.
58
+
59
+ ```bash
60
+ bat workstation login # PKCE browser authorization, then machine exchange
61
+ bat workstation probe # one collection cycle and one report
62
+ bat workstation setup # install the 10 minute schedule (login required)
63
+ bat workstation setup --remove # remove only the files this CLI owns
64
+ bat workstation status # local profile and schedule source config
65
+ bat workstation logout # revoke the key on the server, then forget it
66
+ ```
67
+
68
+ `login` opens `/workstation-login` on `https://bat.hexly.ai`; the machine then exchanges the
69
+ authorization code with `https://bat-ingest.worker.hexly.ai`. That ingest origin is derived locally
70
+ from the trusted dashboard origin, never from callback data, and the exchange response must name
71
+ exactly that origin. Local acceptance uses one explicit origin:
72
+
73
+ ```bash
74
+ bat workstation login --loopback-url http://127.0.0.1:8787
75
+ ```
76
+
77
+ `probe` fetches authorized targets, samples CPU over at least 200 ms, reads memory with platform
78
+ semantics, checks only the primary local volume through an isolated `statfs` child, lists addresses
79
+ without MAC data, and pings each target exactly three times. Unix uses argv-only `ping`/`ping6` with
80
+ `LC_ALL=C` (macOS `ping6` has no usable `-W`); Windows uses the .NET `Ping` class through PowerShell
81
+ with bounded output. A missing ping binary or a denied socket is reported as a local error, never as a
82
+ network outage, and a lost packet keeps its sequence slot. At most 100 targets run with 8 in flight
83
+ inside one absolute 120 second deadline that also covers HTTP, child processes, retries and sleeps;
84
+ the upload keeps a reserved budget, retries reuse the same report ID and body, and there is no
85
+ persisted queue or cached target list. Targets that were never probed are reported as an error with
86
+ the reason in `collection_errors`. Report bodies are capped at 64 KiB and collection errors are
87
+ bounded.
88
+
89
+ `setup` installs a native per-user schedule with an absolute Node.js path and an absolute entry point:
90
+
91
+ | OS | Backend | Registration |
92
+ | ------- | ------- | ------------------------------------------------------------ |
93
+ | macOS | launchd | `StartInterval` 600, no `KeepAlive` |
94
+ | Linux | systemd | `--user` oneshot service plus timer |
95
+ | POSIX | cron | explicit `--backend cron`, managed crontab block only |
96
+ | Windows | windows | interactive Task Scheduler task, battery allowed, no wake-up |
97
+
98
+ There is no silent fallback: Linux without `systemd --user` fails and tells you to pass
99
+ `--backend cron`. `setup` requires a logged-in profile, is idempotent for the same backend, and
100
+ refuses to switch backends while an old schedule is registered (remove it first). Registration is
101
+ transactional: a failed reinstall restores the previous working files and registration instead of
102
+ deleting a valid schedule. Removal unregisters first, tolerates only "nothing registered" answers,
103
+ deletes its own files, then reloads the unit manager; a real unregister failure keeps the files and
104
+ the schedule record.
105
+
106
+ A probe holds a single-instance lock at `~/.config/bat/workstation/probe.lock` via `proper-lockfile`:
107
+ acquisition is an atomic directory create, the lock is refreshed every 30 seconds, and a lock older
108
+ than three minutes (longer than one run) is recovered automatically. If the lock is stolen or its
109
+ heartbeat fails, the whole run aborts instead of reporting. `status` reports a live lock.
110
+
111
+ `logout` revokes the current key through `POST /api/workstation-probe/revoke` before deleting the
112
+ credential. If revocation fails nothing is deleted and the command exits non-zero, so a machine never
113
+ silently keeps a live key or claims an offline revoke. The installation UUID and any installed
114
+ schedule remain; the schedule is removed only by `setup --remove`.
115
+
116
+ ## Development
117
+
118
+ ```bash
119
+ bun run build # bun build --target node → dist/bat.js
120
+ bun run dev # run the entrypoint from source
121
+ bun run typecheck
122
+ bun run test:coverage
123
+ ```
124
+
125
+ `dist/bat.js` is a single bundled Node.js file; it embeds the shared types/validators and the CLI
126
+ framework. The command modules stay thin: argument parsing and output only, with the logic in
127
+ exported `run*` functions that tests call directly.
128
+
129
+ ## License
130
+
131
+ MIT