@unerr-ai/unerr 0.2.0 → 0.2.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.
- package/README.md +6 -0
- package/dist/cli.js +37236 -35793
- package/package.json +6 -1
- package/dist/behaviors/agent-llm-bridge.js +0 -166
- package/dist/behaviors/architecture-guard.js +0 -256
- package/dist/behaviors/auto-doc.js +0 -247
- package/dist/behaviors/cascade-guard.js +0 -289
- package/dist/behaviors/change-narrative.js +0 -270
- package/dist/behaviors/convention-drift.js +0 -290
- package/dist/behaviors/framework.js +0 -235
- package/dist/behaviors/guard-formatter.js +0 -44
- package/dist/behaviors/incomplete-work.js +0 -270
- package/dist/behaviors/loop-breaker.js +0 -300
- package/dist/behaviors/session-continuity.js +0 -208
- package/dist/commands/branches.js +0 -97
- package/dist/commands/check-commit.js +0 -225
- package/dist/commands/compress-output.js +0 -64
- package/dist/commands/config-verify.js +0 -243
- package/dist/commands/daemon.js +0 -905
- package/dist/commands/dashboard.js +0 -52
- package/dist/commands/debug.js +0 -200
- package/dist/commands/enrich.js +0 -184
- package/dist/commands/exec.js +0 -233
- package/dist/commands/gain.js +0 -156
- package/dist/commands/hook.js +0 -88
- package/dist/commands/index.js +0 -88
- package/dist/commands/init.js +0 -74
- package/dist/commands/install.js +0 -505
- package/dist/commands/learn.js +0 -116
- package/dist/commands/manifest.js +0 -193
- package/dist/commands/rewind.js +0 -103
- package/dist/commands/serve.js +0 -19
- package/dist/commands/setup-wizard.js +0 -414
- package/dist/commands/skills.js +0 -64
- package/dist/commands/stats.js +0 -20
- package/dist/commands/status.js +0 -654
- package/dist/commands/timeline.js +0 -139
- package/dist/commands/uninstall.js +0 -230
- package/dist/components/App.js +0 -109
- package/dist/components/Banner.js +0 -12
- package/dist/components/ConfirmPrompt.js +0 -25
- package/dist/components/DriftSummary.js +0 -23
- package/dist/components/GradeBadge.js +0 -15
- package/dist/components/HealthCard.js +0 -18
- package/dist/components/InkSpinner.js +0 -22
- package/dist/components/InputBox.js +0 -17
- package/dist/components/KeyValue.js +0 -13
- package/dist/components/MessageList.js +0 -14
- package/dist/components/ProgressBar.js +0 -26
- package/dist/components/Section.js +0 -16
- package/dist/components/SessionSummaryCard.js +0 -73
- package/dist/components/StartupDisplay.js +0 -24
- package/dist/components/StatusDashboard.js +0 -57
- package/dist/components/StatusLine.js +0 -8
- package/dist/components/StepLine.js +0 -22
- package/dist/components/Theme.js +0 -20
- package/dist/components/ToolProgress.js +0 -8
- package/dist/components/ViolationList.js +0 -21
- package/dist/components/render.js +0 -13
- package/dist/config/agent-registry.js +0 -237
- package/dist/config/claude-settings-hooks.js +0 -304
- package/dist/config/hook-installer.js +0 -65
- package/dist/config/instruction-writer.js +0 -388
- package/dist/config/mcp-config-writer.js +0 -266
- package/dist/config/settings.js +0 -174
- package/dist/config/tool-detector.js +0 -42
- package/dist/config/value-surfacing.js +0 -119
- package/dist/core/context-assembly.js +0 -108
- package/dist/core/conversation.js +0 -33
- package/dist/core/local-chat-provider.js +0 -475
- package/dist/core/provider-factory.js +0 -55
- package/dist/core/providers.js +0 -90
- package/dist/core/query-engine.js +0 -174
- package/dist/daemon/api.js +0 -312
- package/dist/daemon/autostart.js +0 -119
- package/dist/daemon/bootstrap.js +0 -39
- package/dist/daemon/client.js +0 -164
- package/dist/daemon/detect-ci.js +0 -81
- package/dist/daemon/platform-linux.js +0 -146
- package/dist/daemon/platform-macos.js +0 -134
- package/dist/daemon/platform-windows.js +0 -116
- package/dist/daemon/process-manager.js +0 -299
- package/dist/daemon/protocol.js +0 -23
- package/dist/daemon/registry.js +0 -270
- package/dist/daemon/settings-schema.js +0 -72
- package/dist/daemon/system-health.js +0 -134
- package/dist/daemon/version-checker.js +0 -262
- package/dist/daemon/warm-start.js +0 -223
- package/dist/entrypoints/cli.js +0 -1043
- package/dist/entrypoints/daemon.js +0 -380
- package/dist/entrypoints/repl.js +0 -147
- package/dist/hooks/adapters/claude-code.js +0 -90
- package/dist/hooks/adapters/cline.js +0 -100
- package/dist/hooks/adapters/cursor.js +0 -98
- package/dist/hooks/hook-dedup.js +0 -79
- package/dist/hooks/hook-runner.js +0 -113
- package/dist/hooks/navigation-hooks.js +0 -175
- package/dist/hooks/prompt-hooks.js +0 -63
- package/dist/hooks/shell-hooks.js +0 -47
- package/dist/ignore.js +0 -111
- package/dist/intelligence/approach-suggester.js +0 -61
- package/dist/intelligence/ast-extractor.js +0 -2615
- package/dist/intelligence/ast-worker.js +0 -34
- package/dist/intelligence/background-indexer.js +0 -121
- package/dist/intelligence/blast-radius.js +0 -200
- package/dist/intelligence/community-detection.js +0 -691
- package/dist/intelligence/community-detector.js +0 -184
- package/dist/intelligence/computation-scheduler.js +0 -75
- package/dist/intelligence/confidence-propagation.js +0 -47
- package/dist/intelligence/convention-detector.js +0 -242
- package/dist/intelligence/convention-learner.js +0 -205
- package/dist/intelligence/convention-matcher.js +0 -205
- package/dist/intelligence/cozo-schema.js +0 -376
- package/dist/intelligence/decision-point-detector.js +0 -90
- package/dist/intelligence/deep-dive-tools.js +0 -586
- package/dist/intelligence/durability-scorer.js +0 -84
- package/dist/intelligence/exploration-cost.js +0 -204
- package/dist/intelligence/exploration-pattern-tracker.js +0 -61
- package/dist/intelligence/fact-generator.js +0 -322
- package/dist/intelligence/facts-schema.js +0 -90
- package/dist/intelligence/file-intelligence.js +0 -59
- package/dist/intelligence/graph-holder.js +0 -220
- package/dist/intelligence/graph-temporal-joiner.js +0 -238
- package/dist/intelligence/health-grade.js +0 -423
- package/dist/intelligence/health-grader.js +0 -200
- package/dist/intelligence/health-map-data.js +0 -259
- package/dist/intelligence/import-symbols.js +0 -136
- package/dist/intelligence/incremental-indexer.js +0 -658
- package/dist/intelligence/indexer/centrality.js +0 -62
- package/dist/intelligence/indexer/cfg-context.js +0 -95
- package/dist/intelligence/indexer/confidence.js +0 -34
- package/dist/intelligence/indexer/cross-file-resolver.js +0 -104
- package/dist/intelligence/indexer/edge-repair.js +0 -89
- package/dist/intelligence/indexer/entity-key.js +0 -17
- package/dist/intelligence/indexer/export-map.js +0 -132
- package/dist/intelligence/indexer/git-cochange.js +0 -128
- package/dist/intelligence/indexer/graph-patch.js +0 -147
- package/dist/intelligence/indexer/incremental.js +0 -78
- package/dist/intelligence/indexer/ingest.js +0 -160
- package/dist/intelligence/indexer/language-detect.js +0 -226
- package/dist/intelligence/indexer/metadata.js +0 -63
- package/dist/intelligence/indexer/mutation-tracker.js +0 -79
- package/dist/intelligence/indexer/orchestrator.js +0 -155
- package/dist/intelligence/indexer/plugin-interface.js +0 -31
- package/dist/intelligence/indexer/plugins/csharp.js +0 -440
- package/dist/intelligence/indexer/plugins/go.js +0 -335
- package/dist/intelligence/indexer/plugins/java.js +0 -370
- package/dist/intelligence/indexer/plugins/python.js +0 -358
- package/dist/intelligence/indexer/plugins/regex-fallback.js +0 -82
- package/dist/intelligence/indexer/plugins/ruby.js +0 -290
- package/dist/intelligence/indexer/plugins/rust.js +0 -484
- package/dist/intelligence/indexer/plugins/tier2-generic.js +0 -310
- package/dist/intelligence/indexer/plugins/typescript.js +0 -456
- package/dist/intelligence/indexer/resource-monitor.js +0 -93
- package/dist/intelligence/indexer/scip/decoder.js +0 -253
- package/dist/intelligence/indexer/scip/detector.js +0 -232
- package/dist/intelligence/indexer/scip/downloader.js +0 -427
- package/dist/intelligence/indexer/scip/fallback.js +0 -34
- package/dist/intelligence/indexer/scip/merger.js +0 -109
- package/dist/intelligence/indexer/scip/orchestrator.js +0 -433
- package/dist/intelligence/indexer/scip/runner.js +0 -98
- package/dist/intelligence/indexer/snapshot.js +0 -66
- package/dist/intelligence/indexer/test-detector.js +0 -196
- package/dist/intelligence/indexer/watch-integration.js +0 -61
- package/dist/intelligence/indexer/worker.js +0 -85
- package/dist/intelligence/local-convention-detector.js +0 -437
- package/dist/intelligence/local-embeddings.js +0 -190
- package/dist/intelligence/local-graph.js +0 -1946
- package/dist/intelligence/local-indexer.js +0 -1575
- package/dist/intelligence/local-llm.js +0 -163
- package/dist/intelligence/local-rule-generator.js +0 -154
- package/dist/intelligence/local-snapshot.js +0 -213
- package/dist/intelligence/negative-knowledge.js +0 -103
- package/dist/intelligence/persistent-db.js +0 -85
- package/dist/intelligence/query-router.js +0 -2556
- package/dist/intelligence/risk-classifier.js +0 -116
- package/dist/intelligence/rule-evaluator.js +0 -380
- package/dist/intelligence/rule-generator.js +0 -49
- package/dist/intelligence/search-index.js +0 -173
- package/dist/intelligence/semantic/docstring-extractor.js +0 -67
- package/dist/intelligence/semantic/embedding-store.js +0 -52
- package/dist/intelligence/semantic/enrichment-orchestrator.js +0 -48
- package/dist/intelligence/semantic/git-message-miner.js +0 -114
- package/dist/intelligence/semantic/identifier-tokenizer.js +0 -51
- package/dist/intelligence/semantic/node2vec-embeddings.js +0 -71
- package/dist/intelligence/semantic/node2vec-walks.js +0 -103
- package/dist/intelligence/semantic/path-domain-inference.js +0 -112
- package/dist/intelligence/semantic/similarity-engine.js +0 -60
- package/dist/intelligence/semantic/tfidf-vectors.js +0 -88
- package/dist/intelligence/session-brief-builder.js +0 -159
- package/dist/intelligence/session-context.js +0 -221
- package/dist/intelligence/session-health-monitor.js +0 -211
- package/dist/intelligence/session-narrative.js +0 -197
- package/dist/intelligence/session-pattern-analyzer.js +0 -218
- package/dist/intelligence/signal-scorer.js +0 -390
- package/dist/intelligence/signal-show-store.js +0 -182
- package/dist/intelligence/smart-truncate.js +0 -158
- package/dist/intelligence/subgraph-cache.js +0 -88
- package/dist/intelligence/temporal-facts.js +0 -494
- package/dist/intelligence/token-estimator.js +0 -100
- package/dist/intelligence/tool-injector.js +0 -87
- package/dist/intelligence/tree-sitter-loader.js +0 -71
- package/dist/intelligence/worker-pool.js +0 -116
- package/dist/proxy/arg-validator.js +0 -79
- package/dist/proxy/auto-bootstrap.js +0 -167
- package/dist/proxy/bridge.js +0 -147
- package/dist/proxy/budget-enforcer.js +0 -70
- package/dist/proxy/compression-quality-monitor.js +0 -160
- package/dist/proxy/compression-stats.js +0 -51
- package/dist/proxy/context-rot-detector.js +0 -137
- package/dist/proxy/drift-detector.js +0 -139
- package/dist/proxy/efficiency-tracker.js +0 -79
- package/dist/proxy/fact-ranking.js +0 -154
- package/dist/proxy/format-encoder.js +0 -266
- package/dist/proxy/http-transport.js +0 -90
- package/dist/proxy/lifecycle-actor.js +0 -55
- package/dist/proxy/lifecycle-machine.js +0 -187
- package/dist/proxy/log-tailer.js +0 -265
- package/dist/proxy/model-pricing.js +0 -98
- package/dist/proxy/network-firewall.js +0 -141
- package/dist/proxy/nudge-state.js +0 -93
- package/dist/proxy/output-compressor.js +0 -185
- package/dist/proxy/pid-lock.js +0 -291
- package/dist/proxy/proxy-context.js +0 -11
- package/dist/proxy/proxy.js +0 -2633
- package/dist/proxy/response-enrichment.js +0 -32
- package/dist/proxy/response-envelope.js +0 -313
- package/dist/proxy/session-dedup.js +0 -82
- package/dist/proxy/session-legend.js +0 -30
- package/dist/proxy/session-persistence.js +0 -210
- package/dist/proxy/session-resume.js +0 -94
- package/dist/proxy/session-stats.js +0 -513
- package/dist/proxy/shell-classifier.js +0 -1346
- package/dist/proxy/shell-compression-log.js +0 -93
- package/dist/proxy/shell-compressor.js +0 -390
- package/dist/proxy/shell-graph-boost.js +0 -202
- package/dist/proxy/shell-monitor-map.js +0 -18
- package/dist/proxy/shell-stats.js +0 -54
- package/dist/proxy/shell-strategies/cloud.js +0 -215
- package/dist/proxy/shell-strategies/diff.js +0 -159
- package/dist/proxy/shell-strategies/error-diagnostic.js +0 -796
- package/dist/proxy/shell-strategies/filter-dsl.js +0 -358
- package/dist/proxy/shell-strategies/git-status.js +0 -177
- package/dist/proxy/shell-strategies/key-value.js +0 -193
- package/dist/proxy/shell-strategies/log-text.js +0 -154
- package/dist/proxy/shell-strategies/omni.js +0 -188
- package/dist/proxy/shell-strategies/progress.js +0 -55
- package/dist/proxy/shell-strategies/redact.js +0 -76
- package/dist/proxy/shell-strategies/structured.js +0 -241
- package/dist/proxy/shell-strategies/tabular.js +0 -243
- package/dist/proxy/shell-strategies/test-results-types.js +0 -13
- package/dist/proxy/shell-strategies/test-results.js +0 -784
- package/dist/proxy/shell-strategies/tree-paths.js +0 -144
- package/dist/proxy/shell-strategies/yaml.js +0 -182
- package/dist/proxy/shell-tee.js +0 -111
- package/dist/proxy/signal-dedup.js +0 -171
- package/dist/proxy/startup-renderer.js +0 -158
- package/dist/proxy/task-token-display.js +0 -38
- package/dist/proxy/token-counter.js +0 -61
- package/dist/proxy/tool-clusters.js +0 -273
- package/dist/proxy/tool-definitions.js +0 -525
- package/dist/proxy/transport-mux.js +0 -229
- package/dist/proxy/wire-cap.js +0 -268
- package/dist/rules/developer.mozilla.org.json +0 -9
- package/dist/rules/github.com.json +0 -21
- package/dist/schemas/api/skills.js +0 -19
- package/dist/schemas/common/errors.js +0 -7
- package/dist/schemas/common/headers.js +0 -5
- package/dist/schemas/entities/edge.js +0 -25
- package/dist/schemas/entities/entity.js +0 -22
- package/dist/schemas/entities/rule.js +0 -18
- package/dist/schemas/index.js +0 -14
- package/dist/server/event-bus.js +0 -59
- package/dist/server/http.js +0 -156
- package/dist/server/middleware.js +0 -70
- package/dist/server/routes/drift.js +0 -97
- package/dist/server/routes/intelligence.js +0 -1217
- package/dist/server/routes/reasoning-quality.js +0 -444
- package/dist/server/routes/session.js +0 -86
- package/dist/server/routes/stream.js +0 -120
- package/dist/server/routes/system.js +0 -73
- package/dist/server/routes/temporal.js +0 -170
- package/dist/server/routes/timeline.js +0 -232
- package/dist/server/routes/token-flow.js +0 -403
- package/dist/skills/effectiveness-tracker.js +0 -93
- package/dist/skills/local-pack.js +0 -380
- package/dist/skills/resolver.js +0 -495
- package/dist/state-detector.js +0 -83
- package/dist/timeline/intent-detector.js +0 -263
- package/dist/timeline/loop-miner.js +0 -140
- package/dist/timeline/open-threads.js +0 -49
- package/dist/timeline/signal-reinforcer.js +0 -62
- package/dist/timeline/timeline-bootstrap.js +0 -151
- package/dist/timeline/timeline-store.js +0 -618
- package/dist/tools/coding/bash.js +0 -49
- package/dist/tools/coding/file-edit.js +0 -72
- package/dist/tools/coding/file-outline.js +0 -227
- package/dist/tools/coding/file-read-protocol.js +0 -425
- package/dist/tools/coding/file-read.js +0 -35
- package/dist/tools/coding/file-write.js +0 -43
- package/dist/tools/coding/glob-tool.js +0 -109
- package/dist/tools/coding/grep.js +0 -162
- package/dist/tools/coding/index.js +0 -27
- package/dist/tools/intelligence/index.js +0 -269
- package/dist/tools/intelligence/record-fact.js +0 -48
- package/dist/tools/intelligence/timeline-markers.js +0 -130
- package/dist/tools/registry.js +0 -47
- package/dist/tools/types.js +0 -8
- package/dist/tracking/auto-snapshot-triggers.js +0 -246
- package/dist/tracking/branch-context.js +0 -115
- package/dist/tracking/branch-snapshot.js +0 -217
- package/dist/tracking/causal-bridge.js +0 -317
- package/dist/tracking/circuit-breaker.js +0 -147
- package/dist/tracking/commit-watcher.js +0 -114
- package/dist/tracking/context-ledger.js +0 -119
- package/dist/tracking/correction-detector.js +0 -324
- package/dist/tracking/drift-tracker.js +0 -874
- package/dist/tracking/durability-tracker.js +0 -94
- package/dist/tracking/entity-rewind.js +0 -200
- package/dist/tracking/file-hash-state.js +0 -114
- package/dist/tracking/git-attribution.js +0 -132
- package/dist/tracking/git-trailers.js +0 -171
- package/dist/tracking/intelligence-counter.js +0 -46
- package/dist/tracking/intent-correlator.js +0 -202
- package/dist/tracking/intent-encoder.js +0 -52
- package/dist/tracking/intent-token-tracker.js +0 -159
- package/dist/tracking/ledger-archiver.js +0 -94
- package/dist/tracking/ledger-chains.js +0 -245
- package/dist/tracking/metrics-store.js +0 -361
- package/dist/tracking/native-watcher.js +0 -131
- package/dist/tracking/offline-rewind.js +0 -295
- package/dist/tracking/pending-violations.js +0 -74
- package/dist/tracking/persistence-effectiveness.js +0 -167
- package/dist/tracking/prompt-durability.js +0 -202
- package/dist/tracking/quality-signals.js +0 -213
- package/dist/tracking/redactor.js +0 -73
- package/dist/tracking/rewind-engine.js +0 -161
- package/dist/tracking/session-history.js +0 -128
- package/dist/tracking/session-receipt.js +0 -88
- package/dist/tracking/session-summary-writer.js +0 -157
- package/dist/tracking/shadow-ledger.js +0 -321
- package/dist/tracking/stash-manager.js +0 -258
- package/dist/tracking/timeline-fork.js +0 -213
- package/dist/tracking/timeline.js +0 -69
- package/dist/tracking/token-flow.js +0 -276
- package/dist/tracking/turn-segmenter.js +0 -122
- package/dist/tracking/weekly-accumulator.js +0 -179
- package/dist/tracking/working-snapshots.js +0 -188
- package/dist/tracking/workspace-manifest.js +0 -176
- package/dist/transport/http.js +0 -102
- package/dist/utils/counterfactual.js +0 -65
- package/dist/utils/deep-link.js +0 -34
- package/dist/utils/detect.js +0 -193
- package/dist/utils/exec.js +0 -73
- package/dist/utils/file-logger.js +0 -87
- package/dist/utils/format-error.js +0 -29
- package/dist/utils/git.js +0 -181
- package/dist/utils/log.js +0 -57
- package/dist/utils/logger.js +0 -35
- package/dist/utils/mcp-content-json.js +0 -8
- package/dist/utils/session-logger.js +0 -154
- package/dist/utils/startup-log.js +0 -512
- package/dist/utils/ui.js +0 -56
package/dist/commands/daemon.js
DELETED
|
@@ -1,905 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `unerr daemon` — CLI surface for daemon management.
|
|
3
|
-
*
|
|
4
|
-
* Subcommands:
|
|
5
|
-
* start Start the unerrd supervisor
|
|
6
|
-
* stop Stop the unerrd supervisor
|
|
7
|
-
* add <path> Register a repo with unerrd
|
|
8
|
-
* remove <path> Unregister a repo
|
|
9
|
-
* status List all registered repos + state
|
|
10
|
-
* config <path> View/modify per-repo settings
|
|
11
|
-
*
|
|
12
|
-
* Registry operations (add/remove/config/status) work without a running unerrd.
|
|
13
|
-
* Process management (start/stop) spawns or terminates the supervisor.
|
|
14
|
-
*/
|
|
15
|
-
import { resolve } from "node:path";
|
|
16
|
-
import { addRepo, findRepo, listRepos, readNeedsInput, removeRepo, updateRepoSettings, } from "../daemon/registry.js";
|
|
17
|
-
import { SETTINGS_SCHEMA, parseSettingsFlags, } from "../daemon/settings-schema.js";
|
|
18
|
-
const write = (msg) => process.stderr.write(msg);
|
|
19
|
-
const PACKAGE_NAME = "unerr";
|
|
20
|
-
export function registerDaemonCommand(program) {
|
|
21
|
-
const daemon = program
|
|
22
|
-
.command("daemon")
|
|
23
|
-
.description("Manage the unerr daemon registry");
|
|
24
|
-
// ── daemon initialize ────────────────────────────────────────
|
|
25
|
-
// One-time setup: registers unerrd at system boot + starts it now.
|
|
26
|
-
daemon
|
|
27
|
-
.command("initialize")
|
|
28
|
-
.description("One-time daemon setup: register at boot (launchd/systemd/schtasks) and start unerrd")
|
|
29
|
-
.action(async () => {
|
|
30
|
-
const { installForCurrentPlatform } = await import("../daemon/autostart.js");
|
|
31
|
-
const { existsSync, mkdirSync, writeFileSync } = await import("node:fs");
|
|
32
|
-
const { homedir } = await import("node:os");
|
|
33
|
-
const { join } = await import("node:path");
|
|
34
|
-
write("\x1b[38;2;139;92;246m▸\x1b[0m Initializing unerr daemon...\n");
|
|
35
|
-
// 1. Register at boot
|
|
36
|
-
const result = await installForCurrentPlatform();
|
|
37
|
-
if (result.installed) {
|
|
38
|
-
const sentinel = join(homedir(), ".unerr", ".autostart-installed");
|
|
39
|
-
const dir = join(homedir(), ".unerr");
|
|
40
|
-
mkdirSync(dir, { recursive: true });
|
|
41
|
-
writeFileSync(sentinel, new Date().toISOString(), "utf-8");
|
|
42
|
-
write(`\x1b[38;2;52;211;153m✓\x1b[0m Registered at boot: ${result.path}\n`);
|
|
43
|
-
}
|
|
44
|
-
else if (result.error) {
|
|
45
|
-
write(`\x1b[38;2;251;191;36m⚠\x1b[0m Boot registration failed: ${result.error}\n`);
|
|
46
|
-
write(" You can still use `unerr daemon start` to start manually.\n");
|
|
47
|
-
}
|
|
48
|
-
// 2. Check if daemon is already running (idempotent)
|
|
49
|
-
const { daemonSockPath, probeDaemon } = await import("../daemon/client.js");
|
|
50
|
-
const sock = daemonSockPath();
|
|
51
|
-
if (await probeDaemon(sock)) {
|
|
52
|
-
// Read the actual PID from the PID file
|
|
53
|
-
const pidPath = join(homedir(), ".unerr", "unerrd.pid");
|
|
54
|
-
let pidStr = "";
|
|
55
|
-
try {
|
|
56
|
-
const { readFileSync: readPid } = await import("node:fs");
|
|
57
|
-
pidStr = readPid(pidPath, "utf-8").trim();
|
|
58
|
-
}
|
|
59
|
-
catch {
|
|
60
|
-
/* fall through */
|
|
61
|
-
}
|
|
62
|
-
write(`\x1b[38;2;52;211;153m✓\x1b[0m unerrd is already running${pidStr ? ` (PID ${pidStr})` : ""}.\n\n`);
|
|
63
|
-
write(" Next steps:\n" +
|
|
64
|
-
" cd /path/to/your-project\n" +
|
|
65
|
-
" unerr install <agent> # registers repo + installs MCP config\n\n");
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
// 3. Spawn unerrd as a detached background process
|
|
69
|
-
write("\x1b[38;2;139;92;246m▸\x1b[0m Starting unerrd...\n");
|
|
70
|
-
const { spawn } = await import("node:child_process");
|
|
71
|
-
const unerrBin = process.argv[1];
|
|
72
|
-
const child = spawn(process.execPath, [unerrBin, "daemon", "start", "--foreground"], { detached: true, stdio: "ignore", env: { ...process.env } });
|
|
73
|
-
child.unref();
|
|
74
|
-
// 4. Poll until socket is reachable
|
|
75
|
-
const maxWait = 5000;
|
|
76
|
-
const start = Date.now();
|
|
77
|
-
let running = false;
|
|
78
|
-
while (Date.now() - start < maxWait) {
|
|
79
|
-
await new Promise((r) => setTimeout(r, 150));
|
|
80
|
-
if (await probeDaemon(sock)) {
|
|
81
|
-
running = true;
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (running) {
|
|
86
|
-
// Read the actual PID from the PID file (not child.pid, which is the
|
|
87
|
-
// spawner process — the real daemon may have a different PID)
|
|
88
|
-
const pidPath = join(homedir(), ".unerr", "unerrd.pid");
|
|
89
|
-
let daemonPid = String(child.pid);
|
|
90
|
-
try {
|
|
91
|
-
const { readFileSync: readPid } = await import("node:fs");
|
|
92
|
-
daemonPid = readPid(pidPath, "utf-8").trim();
|
|
93
|
-
}
|
|
94
|
-
catch {
|
|
95
|
-
/* fall back to child.pid */
|
|
96
|
-
}
|
|
97
|
-
write(`\x1b[38;2;52;211;153m✓\x1b[0m unerrd is running (PID ${daemonPid}).\n\n`);
|
|
98
|
-
write(" Next steps:\n" +
|
|
99
|
-
" cd /path/to/your-project\n" +
|
|
100
|
-
" unerr install <agent> # registers repo + installs MCP config\n\n");
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
write("\x1b[38;2;248;113;113m✗\x1b[0m unerrd did not start in time. Check: ~/.unerr/logs/unerrd.log\n");
|
|
104
|
-
process.exitCode = 1;
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
// ── daemon start ──────────────────────────────────────────
|
|
108
|
-
daemon
|
|
109
|
-
.command("start")
|
|
110
|
-
.description("Start the unerrd supervisor (without boot registration)")
|
|
111
|
-
.option("--foreground", "Run in foreground (blocks terminal)")
|
|
112
|
-
.action(async (opts) => {
|
|
113
|
-
if (opts.foreground) {
|
|
114
|
-
// Run in-process (for debugging or launchd/systemd which manage the lifecycle)
|
|
115
|
-
const { startDaemon } = await import("../entrypoints/daemon.js");
|
|
116
|
-
await startDaemon({ background: false });
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
// Default: spawn detached and return immediately
|
|
120
|
-
const { spawn } = await import("node:child_process");
|
|
121
|
-
const unerrBin = process.argv[1];
|
|
122
|
-
const child = spawn(process.execPath, [unerrBin, "daemon", "start", "--foreground"], { detached: true, stdio: "ignore", env: { ...process.env } });
|
|
123
|
-
child.unref();
|
|
124
|
-
// Poll until ready
|
|
125
|
-
const { daemonSockPath, probeDaemon } = await import("../daemon/client.js");
|
|
126
|
-
const sock = daemonSockPath();
|
|
127
|
-
const maxWait = 5000;
|
|
128
|
-
const startTime = Date.now();
|
|
129
|
-
let running = false;
|
|
130
|
-
while (Date.now() - startTime < maxWait) {
|
|
131
|
-
await new Promise((r) => setTimeout(r, 150));
|
|
132
|
-
if (await probeDaemon(sock)) {
|
|
133
|
-
running = true;
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
if (running) {
|
|
138
|
-
// Read the actual PID from the PID file
|
|
139
|
-
const { homedir } = await import("node:os");
|
|
140
|
-
const { join } = await import("node:path");
|
|
141
|
-
const pidPath = join(homedir(), ".unerr", "unerrd.pid");
|
|
142
|
-
let daemonPid = String(child.pid);
|
|
143
|
-
try {
|
|
144
|
-
const { readFileSync } = await import("node:fs");
|
|
145
|
-
daemonPid = readFileSync(pidPath, "utf-8").trim();
|
|
146
|
-
}
|
|
147
|
-
catch {
|
|
148
|
-
/* fall back to child.pid */
|
|
149
|
-
}
|
|
150
|
-
write(`\x1b[38;2;52;211;153m✓\x1b[0m unerrd started (PID ${daemonPid}).\n`);
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
write("\x1b[38;2;248;113;113m✗\x1b[0m unerrd did not start in time. Check: ~/.unerr/logs/unerrd.log\n");
|
|
154
|
-
process.exitCode = 1;
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
// ── daemon stop ───────────────────────────────────────────
|
|
158
|
-
daemon
|
|
159
|
-
.command("stop")
|
|
160
|
-
.description("Stop the unerrd supervisor")
|
|
161
|
-
.action(async () => {
|
|
162
|
-
const { createConnection } = await import("node:net");
|
|
163
|
-
const { globalDir } = await import("../daemon/registry.js");
|
|
164
|
-
const { join } = await import("node:path");
|
|
165
|
-
const sock = join(globalDir(), "unerrd.sock");
|
|
166
|
-
const { existsSync } = await import("node:fs");
|
|
167
|
-
if (!existsSync(sock)) {
|
|
168
|
-
write("unerrd is not running (no socket found).\n");
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
try {
|
|
172
|
-
await new Promise((resolve, reject) => {
|
|
173
|
-
const conn = createConnection(sock, () => {
|
|
174
|
-
conn.write(`${JSON.stringify({ cmd: "shutdown" })}\n`);
|
|
175
|
-
});
|
|
176
|
-
conn.on("data", () => {
|
|
177
|
-
conn.destroy();
|
|
178
|
-
resolve();
|
|
179
|
-
});
|
|
180
|
-
conn.on("error", (err) => reject(err));
|
|
181
|
-
setTimeout(() => {
|
|
182
|
-
conn.destroy();
|
|
183
|
-
resolve();
|
|
184
|
-
}, 3000);
|
|
185
|
-
});
|
|
186
|
-
write("\x1b[38;2;52;211;153m\u2713\x1b[0m unerrd stopped.\n");
|
|
187
|
-
}
|
|
188
|
-
catch {
|
|
189
|
-
write("\x1b[38;2;248;113;113m\u2717\x1b[0m Failed to connect to unerrd.\n");
|
|
190
|
-
process.exitCode = 1;
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
// ── daemon teardown ──────────────────────────────────────────
|
|
194
|
-
// Full inverse of `daemon initialize`: stop + deregister boot + optionally purge state.
|
|
195
|
-
daemon
|
|
196
|
-
.command("teardown")
|
|
197
|
-
.description("Remove unerr daemon completely: stop unerrd, deregister from boot, remove state")
|
|
198
|
-
.option("--purge", "Also delete ~/.unerr (logs, registry, cached data)")
|
|
199
|
-
.action(async (opts) => {
|
|
200
|
-
const { createConnection } = await import("node:net");
|
|
201
|
-
const { existsSync, rmSync, unlinkSync } = await import("node:fs");
|
|
202
|
-
const { homedir } = await import("node:os");
|
|
203
|
-
const { join } = await import("node:path");
|
|
204
|
-
const home = join(homedir(), ".unerr");
|
|
205
|
-
const sock = join(home, "unerrd.sock");
|
|
206
|
-
let stopped = false;
|
|
207
|
-
// 1. Stop unerrd if running
|
|
208
|
-
if (existsSync(sock)) {
|
|
209
|
-
write("\x1b[38;2;139;92;246m▸\x1b[0m Stopping unerrd...\n");
|
|
210
|
-
try {
|
|
211
|
-
await new Promise((resolve, reject) => {
|
|
212
|
-
const conn = createConnection(sock, () => {
|
|
213
|
-
conn.write(`${JSON.stringify({ cmd: "shutdown" })}\n`);
|
|
214
|
-
});
|
|
215
|
-
conn.on("data", () => {
|
|
216
|
-
conn.destroy();
|
|
217
|
-
resolve();
|
|
218
|
-
});
|
|
219
|
-
conn.on("error", (err) => reject(err));
|
|
220
|
-
setTimeout(() => {
|
|
221
|
-
conn.destroy();
|
|
222
|
-
resolve();
|
|
223
|
-
}, 3000);
|
|
224
|
-
});
|
|
225
|
-
stopped = true;
|
|
226
|
-
write("\x1b[38;2;52;211;153m✓\x1b[0m unerrd stopped.\n");
|
|
227
|
-
}
|
|
228
|
-
catch {
|
|
229
|
-
write("\x1b[38;2;251;191;36m⚠\x1b[0m Could not connect to unerrd (may already be stopped).\n");
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
else {
|
|
233
|
-
write("\x1b[38;2;34;211;238m▸\x1b[0m unerrd not running (no socket found).\n");
|
|
234
|
-
}
|
|
235
|
-
// 2. Remove boot-time service registration
|
|
236
|
-
write("\x1b[38;2;139;92;246m▸\x1b[0m Removing boot registration...\n");
|
|
237
|
-
try {
|
|
238
|
-
const { uninstallForCurrentPlatform, removeSentinel } = await import("../daemon/autostart.js");
|
|
239
|
-
const result = await uninstallForCurrentPlatform();
|
|
240
|
-
removeSentinel();
|
|
241
|
-
if (result.error) {
|
|
242
|
-
write(`\x1b[38;2;251;191;36m⚠\x1b[0m Boot service removal note: ${result.error}\n`);
|
|
243
|
-
}
|
|
244
|
-
else {
|
|
245
|
-
write("\x1b[38;2;52;211;153m✓\x1b[0m Boot registration removed.\n");
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
catch {
|
|
249
|
-
write("\x1b[38;2;251;191;36m⚠\x1b[0m No boot registration found.\n");
|
|
250
|
-
}
|
|
251
|
-
// 3. Clean up PID file and socket
|
|
252
|
-
const pidFile = join(home, "unerrd.pid");
|
|
253
|
-
for (const f of [sock, pidFile]) {
|
|
254
|
-
if (existsSync(f)) {
|
|
255
|
-
try {
|
|
256
|
-
unlinkSync(f);
|
|
257
|
-
}
|
|
258
|
-
catch {
|
|
259
|
-
// best-effort
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
// 4. Optionally purge all state
|
|
264
|
-
if (opts.purge) {
|
|
265
|
-
write("\x1b[38;2;139;92;246m▸\x1b[0m Purging ~/.unerr...\n");
|
|
266
|
-
if (existsSync(home)) {
|
|
267
|
-
rmSync(home, { recursive: true, force: true });
|
|
268
|
-
write("\x1b[38;2;52;211;153m✓\x1b[0m ~/.unerr removed.\n");
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
write(`\n\x1b[38;2;52;211;153m✓\x1b[0m Daemon teardown complete.${opts.purge
|
|
272
|
-
? ""
|
|
273
|
-
: " Registry and logs preserved in ~/.unerr (use --purge to remove)."}\n`);
|
|
274
|
-
if (!opts.purge) {
|
|
275
|
-
write("\n To re-initialize: \x1b[1munerr daemon initialize\x1b[0m\n");
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
// ── daemon add <path> ───────────────────────────────────────
|
|
279
|
-
const addCmd = daemon
|
|
280
|
-
.command("add [path]")
|
|
281
|
-
.description("Register a repo with unerrd")
|
|
282
|
-
.option("--skip-parent-check", "Allow registration even if parent dir is registered")
|
|
283
|
-
.option("--skip-child-check", "Allow registration even if subdirectories are registered");
|
|
284
|
-
for (const s of SETTINGS_SCHEMA) {
|
|
285
|
-
addCmd.option(`--${s.flag} <value>`, s.description);
|
|
286
|
-
}
|
|
287
|
-
addCmd.action(async (pathArg, opts) => {
|
|
288
|
-
const targetPath = resolve(pathArg ?? ".");
|
|
289
|
-
// Parse and validate settings flags
|
|
290
|
-
const settingsRaw = {};
|
|
291
|
-
for (const s of SETTINGS_SCHEMA) {
|
|
292
|
-
const camelFlag = s.flag.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
293
|
-
if (opts[camelFlag] !== undefined) {
|
|
294
|
-
settingsRaw[s.flag] = opts[camelFlag];
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
let settings;
|
|
298
|
-
try {
|
|
299
|
-
settings = parseSettingsFlags(settingsRaw);
|
|
300
|
-
}
|
|
301
|
-
catch (err) {
|
|
302
|
-
write(`\x1b[38;2;248;113;113m\u2717\x1b[0m ${err.message}\n`);
|
|
303
|
-
process.exitCode = 1;
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
const result = addRepo(targetPath, settings, {
|
|
307
|
-
skipParentCheck: opts.skipParentCheck,
|
|
308
|
-
skipChildCheck: opts.skipChildCheck,
|
|
309
|
-
});
|
|
310
|
-
if (!result.ok) {
|
|
311
|
-
write(`\x1b[38;2;248;113;113m\u2717\x1b[0m ${result.error}\n`);
|
|
312
|
-
if (result.parentConflict) {
|
|
313
|
-
write(` Parent: ${result.parentConflict}\n Use --skip-parent-check to override.\n`);
|
|
314
|
-
}
|
|
315
|
-
if (result.childConflicts) {
|
|
316
|
-
write(` Children: ${result.childConflicts.join(", ")}\n Use --skip-child-check to override.\n`);
|
|
317
|
-
}
|
|
318
|
-
process.exitCode = 1;
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
|
-
if (result.created) {
|
|
322
|
-
write(`\x1b[38;2;52;211;153m\u2713\x1b[0m Registered \x1b[1m${result.entry.label}\x1b[0m (${result.entry.path})\n`);
|
|
323
|
-
const keys = Object.keys(settings);
|
|
324
|
-
if (keys.length > 0) {
|
|
325
|
-
write(` Settings: ${keys.map((k) => `${k}=${settings[k]}`).join(", ")}\n`);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
else {
|
|
329
|
-
write(`\x1b[38;2;251;191;36m\u25c6\x1b[0m Already registered: \x1b[1m${result.entry.label}\x1b[0m\n`);
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
// ── daemon remove <path> ────────────────────────────────────
|
|
333
|
-
daemon
|
|
334
|
-
.command("remove [path]")
|
|
335
|
-
.description("Unregister a repo from unerrd")
|
|
336
|
-
.action((pathArg) => {
|
|
337
|
-
const targetPath = resolve(pathArg ?? ".");
|
|
338
|
-
const removed = removeRepo(targetPath);
|
|
339
|
-
if (removed) {
|
|
340
|
-
write(`\x1b[38;2;52;211;153m\u2713\x1b[0m Removed ${targetPath}\n`);
|
|
341
|
-
}
|
|
342
|
-
else {
|
|
343
|
-
write(`\x1b[38;2;248;113;113m\u2717\x1b[0m Not registered: ${targetPath}\n`);
|
|
344
|
-
process.exitCode = 1;
|
|
345
|
-
}
|
|
346
|
-
});
|
|
347
|
-
// ── daemon status ───────────────────────────────────────────
|
|
348
|
-
daemon
|
|
349
|
-
.command("status")
|
|
350
|
-
.description("List all registered repos and their state")
|
|
351
|
-
.action(async () => {
|
|
352
|
-
// Show update banner if available
|
|
353
|
-
try {
|
|
354
|
-
const { getCachedUpdateInfo } = await import("../daemon/version-checker.js");
|
|
355
|
-
const info = getCachedUpdateInfo();
|
|
356
|
-
if (info.available && !info.dismissed) {
|
|
357
|
-
write(`\n \x1b[38;2;34;211;238m▸\x1b[0m Update available: \x1b[1m${info.current}\x1b[0m → \x1b[1m${info.latest}\x1b[0m — run \x1b[38;2;139;92;246munerr daemon update\x1b[0m\n`);
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
catch {
|
|
361
|
-
// Non-blocking
|
|
362
|
-
}
|
|
363
|
-
const repos = listRepos();
|
|
364
|
-
if (repos.length === 0) {
|
|
365
|
-
write("No repos registered. Use `unerr daemon add .` to register.\n");
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
368
|
-
// Try to get live status from daemon API when daemon is running
|
|
369
|
-
let liveStatus = null;
|
|
370
|
-
try {
|
|
371
|
-
const { daemonSockPath, probeDaemon } = await import("../daemon/client.js");
|
|
372
|
-
const sock = daemonSockPath();
|
|
373
|
-
if (await probeDaemon(sock)) {
|
|
374
|
-
const { request } = await import("node:http");
|
|
375
|
-
const body = await new Promise((resolveReq, rejectReq) => {
|
|
376
|
-
const req = request({
|
|
377
|
-
hostname: "127.0.0.1",
|
|
378
|
-
port: 9847,
|
|
379
|
-
path: "/api/repos",
|
|
380
|
-
method: "GET",
|
|
381
|
-
timeout: 2000,
|
|
382
|
-
}, (res) => {
|
|
383
|
-
let data = "";
|
|
384
|
-
res.on("data", (chunk) => {
|
|
385
|
-
data += chunk.toString();
|
|
386
|
-
});
|
|
387
|
-
res.on("end", () => resolveReq(data));
|
|
388
|
-
});
|
|
389
|
-
req.on("error", rejectReq);
|
|
390
|
-
req.on("timeout", () => {
|
|
391
|
-
req.destroy();
|
|
392
|
-
rejectReq(new Error("timeout"));
|
|
393
|
-
});
|
|
394
|
-
req.end();
|
|
395
|
-
});
|
|
396
|
-
const parsed = JSON.parse(body);
|
|
397
|
-
liveStatus = new Map();
|
|
398
|
-
for (const r of parsed.repos) {
|
|
399
|
-
liveStatus.set(r.path, {
|
|
400
|
-
status: r.status,
|
|
401
|
-
pid: r.pid,
|
|
402
|
-
connections: r.connections,
|
|
403
|
-
idle: r.idle,
|
|
404
|
-
memory: r.memory,
|
|
405
|
-
});
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
catch {
|
|
410
|
-
// Daemon API unavailable — fall back to file-based display
|
|
411
|
-
}
|
|
412
|
-
write(`\n \x1b[1munerr daemon\x1b[0m — ${repos.length} repo${repos.length === 1 ? "" : "s"} registered\n\n`);
|
|
413
|
-
for (const repo of repos) {
|
|
414
|
-
const needsInput = readNeedsInput(repo.path);
|
|
415
|
-
const idleLabel = repo.idleTimeout === 0 ? "never" : `${repo.idleTimeout}s`;
|
|
416
|
-
const live = liveStatus?.get(repo.path);
|
|
417
|
-
const isRunning = live?.status === "running" || live?.status === "starting";
|
|
418
|
-
const statusIcon = isRunning
|
|
419
|
-
? "\x1b[38;2;52;211;153m●\x1b[0m"
|
|
420
|
-
: "\u25cb";
|
|
421
|
-
const statusSuffix = live
|
|
422
|
-
? ` \x1b[2m(${live.status}${live.pid ? `, PID ${live.pid}` : ""}${live.connections ? `, ${live.connections} conn` : ""}${live.idle != null ? `, idle ${live.idle}s` : ""})\x1b[0m`
|
|
423
|
-
: "";
|
|
424
|
-
write(` ${statusIcon} \x1b[1m${repo.label}\x1b[0m${statusSuffix}\n` +
|
|
425
|
-
` Path: ${repo.path}\n` +
|
|
426
|
-
` Idle timeout: ${idleLabel}\n` +
|
|
427
|
-
` Added: ${repo.addedAt}\n`);
|
|
428
|
-
const settingsEntries = Object.entries(repo.settings).filter(([, v]) => v !== undefined);
|
|
429
|
-
if (settingsEntries.length > 0) {
|
|
430
|
-
write(` Settings: ${settingsEntries.map(([k, v]) => `${k}=${v}`).join(", ")}\n`);
|
|
431
|
-
}
|
|
432
|
-
if (needsInput.length > 0) {
|
|
433
|
-
write(" \x1b[38;2;251;191;36m⚠\x1b[0m Needs input:\n");
|
|
434
|
-
for (const ni of needsInput) {
|
|
435
|
-
write(` ${ni.key}: auto-selected \x1b[1m${ni.auto}\x1b[0m (${ni.reason})\n` +
|
|
436
|
-
` Alternatives: ${ni.alternatives.join(", ")}\n` +
|
|
437
|
-
` Override: unerr daemon config ${repo.path} --${toKebab(ni.key)}=${ni.alternatives[0]}\n`);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
write("\n");
|
|
441
|
-
}
|
|
442
|
-
});
|
|
443
|
-
// ── daemon config <path> ────────────────────────────────────
|
|
444
|
-
const configCmd = daemon
|
|
445
|
-
.command("config [path]")
|
|
446
|
-
.description("View or modify per-repo settings")
|
|
447
|
-
.option("--show", "Show current settings without modifying");
|
|
448
|
-
for (const s of SETTINGS_SCHEMA) {
|
|
449
|
-
configCmd.option(`--${s.flag} <value>`, s.description);
|
|
450
|
-
}
|
|
451
|
-
configCmd.action((pathArg, opts) => {
|
|
452
|
-
const targetPath = resolve(pathArg ?? ".");
|
|
453
|
-
// Collect setting flags
|
|
454
|
-
const settingsRaw = {};
|
|
455
|
-
for (const s of SETTINGS_SCHEMA) {
|
|
456
|
-
const camelFlag = s.flag.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
457
|
-
if (opts[camelFlag] !== undefined) {
|
|
458
|
-
settingsRaw[s.flag] = opts[camelFlag];
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
const hasSettingFlags = Object.keys(settingsRaw).length > 0;
|
|
462
|
-
if (opts.show || !hasSettingFlags) {
|
|
463
|
-
// Show mode
|
|
464
|
-
const entry = findRepo(targetPath);
|
|
465
|
-
if (!entry) {
|
|
466
|
-
write(`\x1b[38;2;248;113;113m\u2717\x1b[0m Not registered: ${targetPath}\n` +
|
|
467
|
-
` Register first: unerr daemon add ${targetPath}\n`);
|
|
468
|
-
process.exitCode = 1;
|
|
469
|
-
return;
|
|
470
|
-
}
|
|
471
|
-
write(`\n \x1b[1m${entry.label}\x1b[0m — ${entry.path}\n\n` +
|
|
472
|
-
` Idle timeout: ${entry.idleTimeout === 0 ? "never" : `${entry.idleTimeout}s`}\n` +
|
|
473
|
-
` Added: ${entry.addedAt}\n`);
|
|
474
|
-
const settingsEntries = Object.entries(entry.settings).filter(([, v]) => v !== undefined);
|
|
475
|
-
if (settingsEntries.length > 0) {
|
|
476
|
-
write(" Settings:\n");
|
|
477
|
-
for (const [k, v] of settingsEntries) {
|
|
478
|
-
write(` ${k}: ${v}\n`);
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
const needsInput = readNeedsInput(entry.path);
|
|
482
|
-
if (needsInput.length > 0) {
|
|
483
|
-
write("\n \x1b[38;2;251;191;36m⚠ Auto-detected picks (override with flags):\x1b[0m\n");
|
|
484
|
-
for (const ni of needsInput) {
|
|
485
|
-
write(` ${ni.key}: ${ni.auto} (${ni.reason})\n` +
|
|
486
|
-
` Override: --${toKebab(ni.key)}=${ni.alternatives[0]}\n`);
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
write("\n");
|
|
490
|
-
return;
|
|
491
|
-
}
|
|
492
|
-
// Modify mode
|
|
493
|
-
let parsed;
|
|
494
|
-
try {
|
|
495
|
-
parsed = parseSettingsFlags(settingsRaw);
|
|
496
|
-
}
|
|
497
|
-
catch (err) {
|
|
498
|
-
write(`\x1b[38;2;248;113;113m\u2717\x1b[0m ${err.message}\n`);
|
|
499
|
-
process.exitCode = 1;
|
|
500
|
-
return;
|
|
501
|
-
}
|
|
502
|
-
const updated = updateRepoSettings(targetPath, parsed);
|
|
503
|
-
if (!updated) {
|
|
504
|
-
write(`\x1b[38;2;248;113;113m\u2717\x1b[0m Not registered: ${targetPath}\n` +
|
|
505
|
-
` Register first: unerr daemon add ${targetPath}\n`);
|
|
506
|
-
process.exitCode = 1;
|
|
507
|
-
return;
|
|
508
|
-
}
|
|
509
|
-
write(`\x1b[38;2;52;211;153m\u2713\x1b[0m Updated \x1b[1m${updated.label}\x1b[0m: ${Object.entries(parsed)
|
|
510
|
-
.map(([k, v]) => `${k}=${v}`)
|
|
511
|
-
.join(", ")}\n`);
|
|
512
|
-
});
|
|
513
|
-
// ── daemon autostart on|off|status ──────────────────────────
|
|
514
|
-
daemon
|
|
515
|
-
.command("autostart <action>")
|
|
516
|
-
.description("Manage platform auto-start (on|off|status)")
|
|
517
|
-
.action(async (action) => {
|
|
518
|
-
const validActions = ["on", "off", "status"];
|
|
519
|
-
if (!validActions.includes(action)) {
|
|
520
|
-
write(`\x1b[38;2;248;113;113m\u2717\x1b[0m Invalid action "${action}". Valid: ${validActions.join(", ")}\n`);
|
|
521
|
-
process.exitCode = 1;
|
|
522
|
-
return;
|
|
523
|
-
}
|
|
524
|
-
if (action === "status") {
|
|
525
|
-
const { getAutostartStatus, isAutostartInstalled } = await import("../daemon/autostart.js");
|
|
526
|
-
const status = await getAutostartStatus();
|
|
527
|
-
const { loadWarmStartConfig } = await import("../daemon/warm-start.js");
|
|
528
|
-
const config = loadWarmStartConfig();
|
|
529
|
-
const repos = listRepos();
|
|
530
|
-
const autostartRepos = repos.filter((r) => (r.settings?.autostart ?? "auto") !== "never");
|
|
531
|
-
write("\n \x1b[1munerr daemon autostart\x1b[0m\n\n");
|
|
532
|
-
write(` Platform: ${status.platform}\n`);
|
|
533
|
-
write(` Service: ${status.installed ? "\x1b[38;2;52;211;153m●\x1b[0m installed" : "\x1b[38;2;248;113;113m●\x1b[0m not installed"}\n`);
|
|
534
|
-
write(` Warm budget: ${config.warmStartBudget}\n`);
|
|
535
|
-
write(` Idle cutoff: ${config.warmStartIdleDays} days\n`);
|
|
536
|
-
write(` Boot delay: ${config.warmStartDelayMs}ms\n`);
|
|
537
|
-
write(` Repos: ${autostartRepos.length}/${repos.length} eligible\n\n`);
|
|
538
|
-
if (repos.length > 0) {
|
|
539
|
-
write(" Per-repo autostart policies:\n");
|
|
540
|
-
for (const r of repos) {
|
|
541
|
-
const policy = r.settings?.autostart ?? "auto";
|
|
542
|
-
const icon = policy === "never"
|
|
543
|
-
? "\x1b[38;2;248;113;113m●\x1b[0m"
|
|
544
|
-
: policy === "eager"
|
|
545
|
-
? "\x1b[38;2;52;211;153m●\x1b[0m"
|
|
546
|
-
: "\x1b[38;2;251;191;36m●\x1b[0m";
|
|
547
|
-
write(` ${icon} ${r.label}: ${policy}\n`);
|
|
548
|
-
}
|
|
549
|
-
write("\n");
|
|
550
|
-
}
|
|
551
|
-
return;
|
|
552
|
-
}
|
|
553
|
-
if (action === "on") {
|
|
554
|
-
const { installForCurrentPlatform } = await import("../daemon/autostart.js");
|
|
555
|
-
const result = await installForCurrentPlatform();
|
|
556
|
-
if (result.installed) {
|
|
557
|
-
// Write sentinel
|
|
558
|
-
const { existsSync: ex, mkdirSync: mk, writeFileSync: wf, } = await import("node:fs");
|
|
559
|
-
const { homedir: hd } = await import("node:os");
|
|
560
|
-
const { join: jn } = await import("node:path");
|
|
561
|
-
const sentinel = jn(hd(), ".unerr", ".autostart-installed");
|
|
562
|
-
mk(jn(hd(), ".unerr"), { recursive: true });
|
|
563
|
-
wf(sentinel, new Date().toISOString(), "utf-8");
|
|
564
|
-
write(`\x1b[38;2;52;211;153m\u2713\x1b[0m Auto-start enabled (${result.path})\n`);
|
|
565
|
-
}
|
|
566
|
-
else {
|
|
567
|
-
write(`\x1b[38;2;248;113;113m\u2717\x1b[0m Failed: ${result.error}\n`);
|
|
568
|
-
process.exitCode = 1;
|
|
569
|
-
}
|
|
570
|
-
return;
|
|
571
|
-
}
|
|
572
|
-
if (action === "off") {
|
|
573
|
-
const { uninstallForCurrentPlatform, removeSentinel } = await import("../daemon/autostart.js");
|
|
574
|
-
const result = await uninstallForCurrentPlatform();
|
|
575
|
-
removeSentinel();
|
|
576
|
-
write(`\x1b[38;2;52;211;153m\u2713\x1b[0m Auto-start disabled${result.error ? ` (note: ${result.error})` : ""}\n`);
|
|
577
|
-
}
|
|
578
|
-
});
|
|
579
|
-
// ── daemon logs ──────────────────────────────────────────────
|
|
580
|
-
daemon
|
|
581
|
-
.command("logs")
|
|
582
|
-
.description("Tail daemon and repo log files")
|
|
583
|
-
.option("--repo <label>", "Filter to a specific repo by label")
|
|
584
|
-
.option("--bridge", "Include bridge session logs")
|
|
585
|
-
.option("--follow", "Follow log output (tail -f)")
|
|
586
|
-
.option("-n <lines>", "Number of lines to show", "50")
|
|
587
|
-
.option("--boot", "Show only entries from this boot cycle")
|
|
588
|
-
.action(async (opts) => {
|
|
589
|
-
const { existsSync: ex, readFileSync: rf, readdirSync: rd, } = await import("node:fs");
|
|
590
|
-
const { homedir: hd } = await import("node:os");
|
|
591
|
-
const { join: jn } = await import("node:path");
|
|
592
|
-
const { spawn } = await import("node:child_process");
|
|
593
|
-
const lines = Number.parseInt(opts.n ?? "50", 10) || 50;
|
|
594
|
-
const logFiles = [];
|
|
595
|
-
// Supervisor log
|
|
596
|
-
const daemonLog = jn(hd(), ".unerr", "logs", "unerrd.log");
|
|
597
|
-
if (!opts.repo && ex(daemonLog))
|
|
598
|
-
logFiles.push(daemonLog);
|
|
599
|
-
// Per-repo logs
|
|
600
|
-
const repos = listRepos();
|
|
601
|
-
const filteredRepos = opts.repo
|
|
602
|
-
? repos.filter((r) => r.label === opts.repo)
|
|
603
|
-
: repos;
|
|
604
|
-
for (const r of filteredRepos) {
|
|
605
|
-
const repoLog = jn(r.path, ".unerr", "logs", "unerr.log");
|
|
606
|
-
if (ex(repoLog))
|
|
607
|
-
logFiles.push(repoLog);
|
|
608
|
-
if (opts.bridge) {
|
|
609
|
-
const logsDir = jn(r.path, ".unerr", "logs");
|
|
610
|
-
if (ex(logsDir)) {
|
|
611
|
-
try {
|
|
612
|
-
const bridgeLogs = rd(logsDir).filter((f) => f.startsWith("mcp-"));
|
|
613
|
-
for (const bl of bridgeLogs) {
|
|
614
|
-
logFiles.push(jn(logsDir, bl));
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
catch {
|
|
618
|
-
// Permission or read error
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
if (logFiles.length === 0) {
|
|
624
|
-
write("No log files found.\n");
|
|
625
|
-
return;
|
|
626
|
-
}
|
|
627
|
-
if (opts.follow) {
|
|
628
|
-
const child = spawn("tail", ["-f", "-n", String(lines), ...logFiles], {
|
|
629
|
-
stdio: ["ignore", "inherit", "inherit"],
|
|
630
|
-
});
|
|
631
|
-
await new Promise((resolve) => {
|
|
632
|
-
child.on("close", () => resolve());
|
|
633
|
-
process.on("SIGINT", () => {
|
|
634
|
-
child.kill("SIGTERM");
|
|
635
|
-
resolve();
|
|
636
|
-
});
|
|
637
|
-
});
|
|
638
|
-
return;
|
|
639
|
-
}
|
|
640
|
-
// Static mode — read last N lines from each file
|
|
641
|
-
for (const file of logFiles) {
|
|
642
|
-
try {
|
|
643
|
-
const content = rf(file, "utf-8");
|
|
644
|
-
let fileLines = content.split("\n");
|
|
645
|
-
if (opts.boot) {
|
|
646
|
-
// Find last boot marker
|
|
647
|
-
const bootIdx = fileLines.findLastIndex((l) => l.includes("Started (PID"));
|
|
648
|
-
if (bootIdx >= 0)
|
|
649
|
-
fileLines = fileLines.slice(bootIdx);
|
|
650
|
-
}
|
|
651
|
-
const tail = fileLines.slice(-lines).join("\n");
|
|
652
|
-
write(`\x1b[38;2;139;92;246m▸\x1b[0m ${file}\n${tail}\n\n`);
|
|
653
|
-
}
|
|
654
|
-
catch {
|
|
655
|
-
write(`\x1b[38;2;248;113;113m\u2717\x1b[0m Could not read: ${file}\n`);
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
});
|
|
659
|
-
// ── daemon dashboard ────────────────────────────────────────
|
|
660
|
-
daemon
|
|
661
|
-
.command("dashboard")
|
|
662
|
-
.description("Open the unerr dashboard in browser")
|
|
663
|
-
.option("--port <port>", "Dashboard port (default: 9847)")
|
|
664
|
-
.action(async (opts) => {
|
|
665
|
-
const port = opts.port ?? "9847";
|
|
666
|
-
const url = `http://localhost:${port}`;
|
|
667
|
-
const { platform } = await import("node:os");
|
|
668
|
-
const { execSync: ex } = await import("node:child_process");
|
|
669
|
-
try {
|
|
670
|
-
const plat = platform();
|
|
671
|
-
if (plat === "darwin") {
|
|
672
|
-
ex(`open "${url}"`, { stdio: "ignore" });
|
|
673
|
-
}
|
|
674
|
-
else if (plat === "linux") {
|
|
675
|
-
ex(`xdg-open "${url}"`, { stdio: "ignore" });
|
|
676
|
-
}
|
|
677
|
-
else if (plat === "win32") {
|
|
678
|
-
ex(`start "" "${url}"`, { stdio: "ignore" });
|
|
679
|
-
}
|
|
680
|
-
else {
|
|
681
|
-
write(`Open ${url} in your browser.\n`);
|
|
682
|
-
return;
|
|
683
|
-
}
|
|
684
|
-
write(`\x1b[38;2;52;211;153m\u2713\x1b[0m Opening ${url}\n`);
|
|
685
|
-
}
|
|
686
|
-
catch {
|
|
687
|
-
write(`Open ${url} in your browser.\n`);
|
|
688
|
-
}
|
|
689
|
-
});
|
|
690
|
-
// ── daemon config (global warm-start flags) ─────────────────
|
|
691
|
-
daemon
|
|
692
|
-
.command("set")
|
|
693
|
-
.description("Set global daemon configuration")
|
|
694
|
-
.option("--warm-start-budget <n>", "Max repos to warm-start on boot (0=disabled)")
|
|
695
|
-
.option("--warm-start-idle-days <n>", "Skip repos inactive for N+ days")
|
|
696
|
-
.option("--warm-start-delay-ms <n>", "Delay after boot before warm-start")
|
|
697
|
-
.action(async (opts) => {
|
|
698
|
-
const { saveWarmStartConfig } = await import("../daemon/warm-start.js");
|
|
699
|
-
const partial = {};
|
|
700
|
-
let anySet = false;
|
|
701
|
-
if (opts.warmStartBudget !== undefined) {
|
|
702
|
-
const n = Number.parseInt(opts.warmStartBudget, 10);
|
|
703
|
-
if (!Number.isFinite(n) || n < 0) {
|
|
704
|
-
write(`\x1b[38;2;248;113;113m\u2717\x1b[0m Invalid warm-start-budget: ${opts.warmStartBudget}\n`);
|
|
705
|
-
process.exitCode = 1;
|
|
706
|
-
return;
|
|
707
|
-
}
|
|
708
|
-
partial.warmStartBudget = n;
|
|
709
|
-
anySet = true;
|
|
710
|
-
}
|
|
711
|
-
if (opts.warmStartIdleDays !== undefined) {
|
|
712
|
-
const n = Number.parseInt(opts.warmStartIdleDays, 10);
|
|
713
|
-
if (!Number.isFinite(n) || n < 0) {
|
|
714
|
-
write(`\x1b[38;2;248;113;113m\u2717\x1b[0m Invalid warm-start-idle-days: ${opts.warmStartIdleDays}\n`);
|
|
715
|
-
process.exitCode = 1;
|
|
716
|
-
return;
|
|
717
|
-
}
|
|
718
|
-
partial.warmStartIdleDays = n;
|
|
719
|
-
anySet = true;
|
|
720
|
-
}
|
|
721
|
-
if (opts.warmStartDelayMs !== undefined) {
|
|
722
|
-
const n = Number.parseInt(opts.warmStartDelayMs, 10);
|
|
723
|
-
if (!Number.isFinite(n) || n < 0) {
|
|
724
|
-
write(`\x1b[38;2;248;113;113m\u2717\x1b[0m Invalid warm-start-delay-ms: ${opts.warmStartDelayMs}\n`);
|
|
725
|
-
process.exitCode = 1;
|
|
726
|
-
return;
|
|
727
|
-
}
|
|
728
|
-
partial.warmStartDelayMs = n;
|
|
729
|
-
anySet = true;
|
|
730
|
-
}
|
|
731
|
-
if (!anySet) {
|
|
732
|
-
// Show current config
|
|
733
|
-
const { loadWarmStartConfig } = await import("../daemon/warm-start.js");
|
|
734
|
-
const config = loadWarmStartConfig();
|
|
735
|
-
write("\n \x1b[1mGlobal daemon config\x1b[0m\n\n");
|
|
736
|
-
write(` warmStartBudget: ${config.warmStartBudget}\n`);
|
|
737
|
-
write(` warmStartIdleDays: ${config.warmStartIdleDays}\n`);
|
|
738
|
-
write(` warmStartDelayMs: ${config.warmStartDelayMs}\n\n`);
|
|
739
|
-
return;
|
|
740
|
-
}
|
|
741
|
-
saveWarmStartConfig(partial);
|
|
742
|
-
write(`\x1b[38;2;52;211;153m\u2713\x1b[0m Updated: ${Object.entries(partial)
|
|
743
|
-
.map(([k, v]) => `${k}=${v}`)
|
|
744
|
-
.join(", ")}\n`);
|
|
745
|
-
});
|
|
746
|
-
// ── daemon update ───────────────────────────────────────────
|
|
747
|
-
daemon
|
|
748
|
-
.command("update")
|
|
749
|
-
.description("Check for and apply unerr updates")
|
|
750
|
-
.option("--check", "Only check, don't install")
|
|
751
|
-
.option("--yes", "Skip confirmation prompt")
|
|
752
|
-
.action(async (opts) => {
|
|
753
|
-
const { checkForUpdate, getInstalledVersion } = await import("../daemon/version-checker.js");
|
|
754
|
-
write("\x1b[38;2;139;92;246m▸\x1b[0m Checking for updates...\n");
|
|
755
|
-
const info = await checkForUpdate();
|
|
756
|
-
if (!info.available) {
|
|
757
|
-
write(`\x1b[38;2;52;211;153m\u2713\x1b[0m unerr is up to date (${info.current})\n`);
|
|
758
|
-
return;
|
|
759
|
-
}
|
|
760
|
-
write(`\n \x1b[1mUpdate available\x1b[0m\n\n Current: ${info.current}\n Latest: \x1b[38;2;34;211;238m${info.latest}\x1b[0m\n Behind: ${info.behindMinor} minor version${info.behindMinor !== 1 ? "s" : ""}\n\n`);
|
|
761
|
-
if (opts.check)
|
|
762
|
-
return;
|
|
763
|
-
// Confirmation prompt (skip with --yes)
|
|
764
|
-
if (!opts.yes) {
|
|
765
|
-
const { createInterface } = await import("node:readline");
|
|
766
|
-
const rl = createInterface({
|
|
767
|
-
input: process.stdin,
|
|
768
|
-
output: process.stderr,
|
|
769
|
-
});
|
|
770
|
-
const answer = await new Promise((resolve) => {
|
|
771
|
-
rl.question(` Update unerr ${info.current} → ${info.latest}? [y/N] `, (ans) => {
|
|
772
|
-
rl.close();
|
|
773
|
-
resolve(ans.trim().toLowerCase());
|
|
774
|
-
});
|
|
775
|
-
});
|
|
776
|
-
if (answer !== "y" && answer !== "yes") {
|
|
777
|
-
write(" Cancelled.\n");
|
|
778
|
-
return;
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
write("\n");
|
|
782
|
-
// Step 1: Stop unerrd if running
|
|
783
|
-
write(" [1/5] Stopping unerrd...\n");
|
|
784
|
-
try {
|
|
785
|
-
const { createConnection } = await import("node:net");
|
|
786
|
-
const { globalDir } = await import("../daemon/registry.js");
|
|
787
|
-
const { join } = await import("node:path");
|
|
788
|
-
const sock = join(globalDir(), "unerrd.sock");
|
|
789
|
-
const { existsSync } = await import("node:fs");
|
|
790
|
-
if (existsSync(sock)) {
|
|
791
|
-
await new Promise((resolve) => {
|
|
792
|
-
const conn = createConnection(sock, () => {
|
|
793
|
-
conn.write(`${JSON.stringify({ cmd: "shutdown" })}\n`);
|
|
794
|
-
});
|
|
795
|
-
conn.on("data", () => {
|
|
796
|
-
conn.destroy();
|
|
797
|
-
resolve();
|
|
798
|
-
});
|
|
799
|
-
conn.on("error", () => resolve());
|
|
800
|
-
setTimeout(() => {
|
|
801
|
-
conn.destroy();
|
|
802
|
-
resolve();
|
|
803
|
-
}, 5000);
|
|
804
|
-
});
|
|
805
|
-
// Wait for process to fully exit
|
|
806
|
-
await new Promise((r) => setTimeout(r, 2000));
|
|
807
|
-
}
|
|
808
|
-
write(" \x1b[38;2;52;211;153m\u2713\x1b[0m stopped\n");
|
|
809
|
-
}
|
|
810
|
-
catch {
|
|
811
|
-
write(" \x1b[38;2;251;191;36m⚠\x1b[0m already stopped\n");
|
|
812
|
-
}
|
|
813
|
-
// Step 2: Detect package manager and install
|
|
814
|
-
write(" [2/5] Installing update...\n");
|
|
815
|
-
const { execSync } = await import("node:child_process");
|
|
816
|
-
const { existsSync: exists } = await import("node:fs");
|
|
817
|
-
let installCmd;
|
|
818
|
-
const target = `${PACKAGE_NAME}@${info.latest}`;
|
|
819
|
-
// Detect how unerr was installed
|
|
820
|
-
if (process.env.npm_config_global_prefix) {
|
|
821
|
-
installCmd = `npm install -g ${target}`;
|
|
822
|
-
}
|
|
823
|
-
else {
|
|
824
|
-
try {
|
|
825
|
-
const pnpmGlobal = execSync("pnpm root -g", {
|
|
826
|
-
encoding: "utf-8",
|
|
827
|
-
}).trim();
|
|
828
|
-
if (pnpmGlobal && process.argv[1]?.includes("pnpm")) {
|
|
829
|
-
installCmd = `pnpm add -g ${target}`;
|
|
830
|
-
}
|
|
831
|
-
else {
|
|
832
|
-
installCmd = `npm install -g ${target}`;
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
catch {
|
|
836
|
-
installCmd = `npm install -g ${target}`;
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
try {
|
|
840
|
-
execSync(installCmd, { stdio: "pipe", timeout: 120_000 });
|
|
841
|
-
write(` \x1b[38;2;52;211;153m\u2713\x1b[0m ${installCmd}\n`);
|
|
842
|
-
}
|
|
843
|
-
catch (err) {
|
|
844
|
-
write(` \x1b[38;2;248;113;113m\u2717\x1b[0m Install failed: ${err.message}\n` +
|
|
845
|
-
` Try manually: ${installCmd}\n`);
|
|
846
|
-
process.exitCode = 1;
|
|
847
|
-
return;
|
|
848
|
-
}
|
|
849
|
-
// Step 3: Verify new version
|
|
850
|
-
write(" [3/5] Verifying...\n");
|
|
851
|
-
try {
|
|
852
|
-
const newVer = execSync("unerr --version", {
|
|
853
|
-
encoding: "utf-8",
|
|
854
|
-
}).trim();
|
|
855
|
-
write(` \x1b[38;2;52;211;153m\u2713\x1b[0m ${newVer}\n`);
|
|
856
|
-
}
|
|
857
|
-
catch {
|
|
858
|
-
write(" \x1b[38;2;251;191;36m⚠\x1b[0m Could not verify version\n");
|
|
859
|
-
}
|
|
860
|
-
// Step 4: Restart unerrd
|
|
861
|
-
write(" [4/5] Restarting unerrd...\n");
|
|
862
|
-
try {
|
|
863
|
-
const { spawn } = await import("node:child_process");
|
|
864
|
-
const child = spawn(process.execPath, [process.argv[1], "daemon", "start", "--background"], { detached: true, stdio: "ignore" });
|
|
865
|
-
child.unref();
|
|
866
|
-
await new Promise((r) => setTimeout(r, 3000));
|
|
867
|
-
write(" \x1b[38;2;52;211;153m\u2713\x1b[0m started\n");
|
|
868
|
-
}
|
|
869
|
-
catch {
|
|
870
|
-
write(" \x1b[38;2;251;191;36m⚠\x1b[0m Manual restart: unerr daemon start\n");
|
|
871
|
-
}
|
|
872
|
-
// Step 5: Health check
|
|
873
|
-
write(" [5/5] Health check...\n");
|
|
874
|
-
try {
|
|
875
|
-
const { probeDaemon } = await import("../daemon/client.js");
|
|
876
|
-
const { globalDir } = await import("../daemon/registry.js");
|
|
877
|
-
const { join } = await import("node:path");
|
|
878
|
-
const sock = join(globalDir(), "unerrd.sock");
|
|
879
|
-
const healthy = await probeDaemon(sock);
|
|
880
|
-
if (healthy) {
|
|
881
|
-
write(" \x1b[38;2;52;211;153m\u2713\x1b[0m healthy\n");
|
|
882
|
-
}
|
|
883
|
-
else {
|
|
884
|
-
write(" \x1b[38;2;251;191;36m⚠\x1b[0m daemon not yet responsive\n");
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
catch {
|
|
888
|
-
write(" \x1b[38;2;251;191;36m⚠\x1b[0m could not reach daemon\n");
|
|
889
|
-
}
|
|
890
|
-
write(`\n \x1b[38;2;52;211;153m\u2713\x1b[0m Updated to \x1b[1m${info.latest}\x1b[0m\n\n`);
|
|
891
|
-
});
|
|
892
|
-
// ── daemon dismiss-update ───────────────────────────────────
|
|
893
|
-
daemon
|
|
894
|
-
.command("dismiss-update <version>")
|
|
895
|
-
.description("Dismiss update notification for a specific version")
|
|
896
|
-
.action(async (version) => {
|
|
897
|
-
const { dismissVersion } = await import("../daemon/version-checker.js");
|
|
898
|
-
dismissVersion(version);
|
|
899
|
-
write(`\x1b[38;2;52;211;153m\u2713\x1b[0m Dismissed update notification for v${version.replace(/^v/, "")}\n`);
|
|
900
|
-
});
|
|
901
|
-
}
|
|
902
|
-
/** Convert camelCase key to kebab-case for CLI flags. */
|
|
903
|
-
function toKebab(s) {
|
|
904
|
-
return s.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
|
|
905
|
-
}
|