idlewatch 0.1.3 → 0.1.4
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 +13 -9
- package/bin/idlewatch-agent.js +3 -3
- package/package.json +1 -1
- package/src/enrollment.js +43 -5
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ npx idlewatch quickstart
|
|
|
17
17
|
npx idlewatch --dry-run
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
`quickstart`
|
|
20
|
+
`quickstart` is the happy path: create an API key on idlewatch.com/api, run the wizard, pick a device name + metrics, and IdleWatch saves local config before sending a first sample. By default, quickstart will try to install Rust/Cargo automatically if needed so it can launch the ratatui onboarding flow. Use `idlewatch quickstart --no-tui` to skip the TUI and stay on the plain text setup path without installing Cargo.
|
|
21
21
|
|
|
22
22
|
## CLI options
|
|
23
23
|
|
|
@@ -49,26 +49,30 @@ Use `gpuSource` + `gpuConfidence` in dashboards to decide whether to trust value
|
|
|
49
49
|
- `low`: constrained probe path
|
|
50
50
|
- `none`: no usable sample for that sample window
|
|
51
51
|
|
|
52
|
-
##
|
|
52
|
+
## Quickstart
|
|
53
53
|
|
|
54
|
-
### Recommended: guided enrollment
|
|
54
|
+
### Recommended: guided enrollment
|
|
55
55
|
|
|
56
56
|
```bash
|
|
57
57
|
npx idlewatch quickstart
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
The wizard
|
|
61
|
-
-
|
|
62
|
-
-
|
|
63
|
-
-
|
|
60
|
+
The wizard keeps setup small:
|
|
61
|
+
- asks for a **device name**
|
|
62
|
+
- asks for your **API key** from `idlewatch.com/api`
|
|
63
|
+
- lets you choose which **metrics** to collect
|
|
64
|
+
- saves local config to `~/.idlewatch/idlewatch.env`
|
|
65
|
+
- sends a first sample so the device can link right away
|
|
64
66
|
|
|
65
|
-
|
|
67
|
+
The saved config is auto-loaded on later runs, so you should not need to manually source the env file in normal use.
|
|
68
|
+
|
|
69
|
+
Then run a one-shot publish check any time with:
|
|
66
70
|
|
|
67
71
|
```bash
|
|
68
72
|
idlewatch --once
|
|
69
73
|
```
|
|
70
74
|
|
|
71
|
-
|
|
75
|
+
## Advanced Firebase wiring
|
|
72
76
|
|
|
73
77
|
### Manual wiring
|
|
74
78
|
|
package/bin/idlewatch-agent.js
CHANGED
|
@@ -18,7 +18,7 @@ import { enrichWithOpenClawFleetTelemetry } from '../src/telemetry-mapping.js'
|
|
|
18
18
|
import pkg from '../package.json' with { type: 'json' }
|
|
19
19
|
|
|
20
20
|
function printHelp() {
|
|
21
|
-
console.log(`idlewatch\n\nUsage:\n idlewatch [quickstart|configure|dashboard|run] [--dry-run] [--once] [--help]\n\nOptions:\n quickstart Run first-run setup
|
|
21
|
+
console.log(`idlewatch\n\nUsage:\n idlewatch [quickstart|configure|dashboard|run] [--dry-run] [--once] [--help]\n\nOptions:\n quickstart Run first-run setup and save local IdleWatch config\n configure Alias for quickstart; reopen setup to change device name, API key, or metrics\n dashboard Launch local dashboard from local IdleWatch logs\n run Start the background collector using saved local config\n --no-tui Skip the Rust TUI and use plain text setup without installing Cargo\n --dry-run Collect and print one telemetry sample, then exit without remote writes\n --once Collect and publish one telemetry sample, then exit\n --help Show this help message\n\nQuickstart:\n 1. Create an API key on idlewatch.com/api\n 2. Run: idlewatch quickstart\n 3. Pick a device name and metrics\n 4. IdleWatch saves your local config and sends a first sample\n\nEnvironment:\n IDLEWATCH_HOST Optional custom host label (default: hostname)\n IDLEWATCH_INTERVAL_MS Sampling interval in ms (default: 10000)\n IDLEWATCH_LOCAL_LOG_PATH Optional NDJSON file path for local sample durability\n IDLEWATCH_DASHBOARD_PORT Local dashboard HTTP port (default: 4373)\n IDLEWATCH_OPENCLAW_USAGE OpenClaw usage lookup mode: auto|off (default: auto)\n IDLEWATCH_OPENCLAW_PROBE_TIMEOUT_MS OpenClaw command timeout per probe in ms (default: 2500)\n IDLEWATCH_OPENCLAW_PROBE_RETRIES Extra OpenClaw probe sweep retries after first pass (default: 1)\n IDLEWATCH_OPENCLAW_MAX_OUTPUT_BYTES Max per-command OpenClaw probe output capture in bytes before truncation (default: 2097152 / 2MB)\n IDLEWATCH_OPENCLAW_MAX_OUTPUT_BYTES_HARD_CAP Hard cap for auto-retry output capture escalation (default: 16777216 / 16MB)\n IDLEWATCH_USAGE_STALE_MS Mark OpenClaw usage stale beyond this age in ms (default: max(interval*3,60000))\n IDLEWATCH_USAGE_NEAR_STALE_MS Mark OpenClaw usage as aging beyond this age in ms (default: floor((stale+grace)*0.85))\n IDLEWATCH_USAGE_STALE_GRACE_MS Extra grace window before status becomes stale (default: min(interval,10000))\n IDLEWATCH_USAGE_REFRESH_REPROBES Forced uncached reprobes when usage crosses stale threshold (default: 1)\n IDLEWATCH_USAGE_REFRESH_DELAY_MS Delay between forced stale-threshold reprobes in ms (default: 250)\n IDLEWATCH_USAGE_REFRESH_ON_NEAR_STALE Trigger refresh when usage is near-stale: 1|0 (default: 1)\n IDLEWATCH_USAGE_IDLE_AFTER_MS Downgrade stale usage alerts to idle notice beyond this age in ms (default: 21600000)\n IDLEWATCH_OPENCLAW_LAST_GOOD_MAX_AGE_MS Reuse last successful usage snapshot after probe failures up to this age in ms\n IDLEWATCH_OPENCLAW_LAST_GOOD_CACHE_PATH Persist/reuse last successful usage snapshot across restarts (default: ~/.idlewatch/cache/<host>-openclaw-last-good.json)\n IDLEWATCH_CLOUD_INGEST_URL Optional cloud ingest endpoint (e.g. https://idlewatch.com/api/ingest)\n IDLEWATCH_CLOUD_API_KEY Cloud API key from idlewatch.com/api for device linking\n IDLEWATCH_REQUIRE_CLOUD_WRITES Require cloud publish path in --once mode: 1|0 (default: 0)\n\nAdvanced Firebase / emulator mode:\n IDLEWATCH_REQUIRE_FIREBASE_WRITES Require Firebase publish path in --once mode: 1|0 (default: 0)\n FIREBASE_PROJECT_ID Firebase project id\n FIREBASE_SERVICE_ACCOUNT_FILE Path to service account JSON file (preferred for production)\n FIREBASE_SERVICE_ACCOUNT_JSON Raw JSON service account (supported, less secure than file path)\n FIREBASE_SERVICE_ACCOUNT_B64 Base64-encoded JSON service account (legacy)\n FIRESTORE_EMULATOR_HOST Optional Firestore emulator host; allows local writes without service-account creds\n`)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
const require = createRequire(import.meta.url)
|
|
@@ -372,7 +372,7 @@ if (dashboardRequested) {
|
|
|
372
372
|
|
|
373
373
|
if (quickstartRequested) {
|
|
374
374
|
try {
|
|
375
|
-
const result = await runEnrollmentWizard()
|
|
375
|
+
const result = await runEnrollmentWizard({ noTui: args.has('--no-tui') })
|
|
376
376
|
|
|
377
377
|
const enrolledEnv = parseEnvFileToObject(result.outputEnvFile)
|
|
378
378
|
const onceRun = spawnSync(process.execPath, [process.argv[1], '--once'], {
|
|
@@ -626,7 +626,7 @@ if (firebaseConfigError) {
|
|
|
626
626
|
|
|
627
627
|
if (!appReady && !(CLOUD_INGEST_URL && CLOUD_API_KEY)) {
|
|
628
628
|
console.error(
|
|
629
|
-
'Firebase is not configured. Running without Firebase writes. Set FIREBASE_PROJECT_ID + FIREBASE_SERVICE_ACCOUNT_FILE (preferred, or FIREBASE_SERVICE_ACCOUNT_JSON / FIREBASE_SERVICE_ACCOUNT_B64), use FIREBASE_PROJECT_ID + FIRESTORE_EMULATOR_HOST for emulator writes, or
|
|
629
|
+
'Firebase is not configured. Running without Firebase writes. Set FIREBASE_PROJECT_ID + FIREBASE_SERVICE_ACCOUNT_FILE (preferred, or FIREBASE_SERVICE_ACCOUNT_JSON / FIREBASE_SERVICE_ACCOUNT_B64), use FIREBASE_PROJECT_ID + FIRESTORE_EMULATOR_HOST for emulator writes, or run idlewatch quickstart to link cloud ingest.'
|
|
630
630
|
)
|
|
631
631
|
}
|
|
632
632
|
|
package/package.json
CHANGED
package/src/enrollment.js
CHANGED
|
@@ -94,12 +94,49 @@ function sanitizeDeviceId(raw, fallback = os.hostname()) {
|
|
|
94
94
|
return sanitized || normalizeDeviceName(fallback).replace(/[^a-zA-Z0-9_.-]/g, '_')
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
function
|
|
97
|
+
function cargoAvailable() {
|
|
98
|
+
const cargoProbe = spawnSync('cargo', ['--version'], { stdio: 'ignore' })
|
|
99
|
+
return cargoProbe.status === 0
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function installRustToolchain() {
|
|
103
|
+
if (cargoAvailable()) return { ok: true, installed: false }
|
|
104
|
+
if (process.env.IDLEWATCH_DISABLE_RUST_INSTALL === '1') return { ok: false, reason: 'install-disabled' }
|
|
105
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) return { ok: false, reason: 'non-tty' }
|
|
106
|
+
if (!['darwin', 'linux'].includes(process.platform)) return { ok: false, reason: `unsupported-platform:${process.platform}` }
|
|
107
|
+
|
|
108
|
+
console.log('IdleWatch TUI needs Rust/Cargo. Installing rustup + Cargo now...')
|
|
109
|
+
const install = spawnSync('sh', ['-c', 'curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y'], {
|
|
110
|
+
stdio: 'inherit',
|
|
111
|
+
env: {
|
|
112
|
+
...process.env,
|
|
113
|
+
CARGO_HOME: process.env.CARGO_HOME || path.join(os.homedir(), '.cargo'),
|
|
114
|
+
RUSTUP_HOME: process.env.RUSTUP_HOME || path.join(os.homedir(), '.rustup')
|
|
115
|
+
}
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
if (install.status !== 0) return { ok: false, reason: `rustup-install-failed:${install.status ?? 'unknown'}` }
|
|
119
|
+
|
|
120
|
+
const cargoBinDir = path.join(process.env.CARGO_HOME || path.join(os.homedir(), '.cargo'), 'bin')
|
|
121
|
+
if (!process.env.PATH?.split(path.delimiter).includes(cargoBinDir)) {
|
|
122
|
+
process.env.PATH = `${cargoBinDir}${path.delimiter}${process.env.PATH || ''}`
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return cargoAvailable() ? { ok: true, installed: true } : { ok: false, reason: 'cargo-still-missing' }
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function tryRustTui({ configDir, outputEnvFile, autoInstallRust = true }) {
|
|
98
129
|
const disabled = process.env.IDLEWATCH_DISABLE_RUST_TUI === '1'
|
|
99
130
|
if (disabled) return { ok: false, reason: 'disabled' }
|
|
100
131
|
|
|
101
|
-
|
|
102
|
-
|
|
132
|
+
if (!cargoAvailable()) {
|
|
133
|
+
if (autoInstallRust) {
|
|
134
|
+
const installResult = installRustToolchain()
|
|
135
|
+
if (!installResult.ok) return { ok: false, reason: installResult.reason || 'cargo-missing' }
|
|
136
|
+
} else {
|
|
137
|
+
return { ok: false, reason: 'cargo-missing' }
|
|
138
|
+
}
|
|
139
|
+
}
|
|
103
140
|
|
|
104
141
|
const manifestPath = path.join(PACKAGE_ROOT, 'tui', 'Cargo.toml')
|
|
105
142
|
if (!fs.existsSync(manifestPath)) return { ok: false, reason: 'manifest-missing', manifestPath }
|
|
@@ -126,6 +163,7 @@ function promptModeText() {
|
|
|
126
163
|
|
|
127
164
|
export async function runEnrollmentWizard(options = {}) {
|
|
128
165
|
const nonInteractive = options.nonInteractive || process.env.IDLEWATCH_ENROLL_NON_INTERACTIVE === '1'
|
|
166
|
+
const noTui = options.noTui || process.env.IDLEWATCH_NO_TUI === '1'
|
|
129
167
|
const configDir = path.resolve(options.configDir || process.env.IDLEWATCH_ENROLL_CONFIG_DIR || defaultConfigDir())
|
|
130
168
|
const outputEnvFile = path.resolve(options.outputEnvFile || process.env.IDLEWATCH_ENROLL_OUTPUT_ENV_FILE || path.join(configDir, 'idlewatch.env'))
|
|
131
169
|
|
|
@@ -140,8 +178,8 @@ export async function runEnrollmentWizard(options = {}) {
|
|
|
140
178
|
availableMonitorTargets
|
|
141
179
|
)
|
|
142
180
|
|
|
143
|
-
if (!nonInteractive) {
|
|
144
|
-
const tuiResult = tryRustTui({ configDir, outputEnvFile })
|
|
181
|
+
if (!nonInteractive && !noTui) {
|
|
182
|
+
const tuiResult = tryRustTui({ configDir, outputEnvFile, autoInstallRust: true })
|
|
145
183
|
if (tuiResult.ok) {
|
|
146
184
|
return {
|
|
147
185
|
mode: 'tui',
|