@unerr-ai/unerr 0.2.1 → 0.2.3
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 +36 -45
- package/dist/cli.js +37443 -36022
- package/package.json +2 -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
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Process manager — spawn, stop, monitor, and idle-sweep per-repo child processes.
|
|
3
|
-
*
|
|
4
|
-
* Each managed repo gets a single Node.js child process (fork of `unerr --daemon-child`).
|
|
5
|
-
* Communication is via Node.js IPC channel (`process.send` / `process.on('message')`).
|
|
6
|
-
*
|
|
7
|
-
* The idle sweep runs every 60s. A repo process is eligible for stop when:
|
|
8
|
-
* - Zero active connections (no IDE bridges connected)
|
|
9
|
-
* - lastActivity older than the repo's idleTimeout
|
|
10
|
-
*
|
|
11
|
-
* Child lifecycle:
|
|
12
|
-
* fork() → child sends { type: "ready", sock } → status = "running"
|
|
13
|
-
* child sends { type: "activity" } → updates lastActivity
|
|
14
|
-
* parent sends { type: "shutdown" } → child snapshots + exits
|
|
15
|
-
* child exits → status = "stopped", cleanup
|
|
16
|
-
*/
|
|
17
|
-
import { fork } from "node:child_process";
|
|
18
|
-
import { readNeedsInput, readRegistry, writeRegistry } from "./registry.js";
|
|
19
|
-
// ── Process Manager ─────────────────────────────────────────────
|
|
20
|
-
const IDLE_SWEEP_INTERVAL_MS = 60_000;
|
|
21
|
-
const READY_TIMEOUT_MS = 30_000;
|
|
22
|
-
export class ProcessManager {
|
|
23
|
-
repos = new Map();
|
|
24
|
-
sweepTimer = null;
|
|
25
|
-
onEvent = null;
|
|
26
|
-
stopped = false;
|
|
27
|
-
/** Register an event handler for lifecycle events (logging, dashboard SSE). */
|
|
28
|
-
setEventHandler(handler) {
|
|
29
|
-
this.onEvent = handler;
|
|
30
|
-
}
|
|
31
|
-
/** Start the idle sweep timer. */
|
|
32
|
-
startIdleSweep() {
|
|
33
|
-
if (this.sweepTimer)
|
|
34
|
-
return;
|
|
35
|
-
this.sweepTimer = setInterval(() => this.runIdleSweep(), IDLE_SWEEP_INTERVAL_MS);
|
|
36
|
-
this.sweepTimer.unref();
|
|
37
|
-
}
|
|
38
|
-
/** Stop the idle sweep timer. */
|
|
39
|
-
stopIdleSweep() {
|
|
40
|
-
if (this.sweepTimer) {
|
|
41
|
-
clearInterval(this.sweepTimer);
|
|
42
|
-
this.sweepTimer = null;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Ensure a repo process is running. If already running, returns the sock path.
|
|
47
|
-
* If stopped, spawns it and waits for the "ready" IPC message.
|
|
48
|
-
*/
|
|
49
|
-
async ensure(repoPath) {
|
|
50
|
-
const existing = this.repos.get(repoPath);
|
|
51
|
-
if (existing?.status === "running" && existing.sock) {
|
|
52
|
-
return existing.sock;
|
|
53
|
-
}
|
|
54
|
-
if (existing?.status === "starting") {
|
|
55
|
-
return this.waitForReady(existing);
|
|
56
|
-
}
|
|
57
|
-
return this.spawn(repoPath);
|
|
58
|
-
}
|
|
59
|
-
/** Record that a bridge connected to this repo. */
|
|
60
|
-
connect(repoPath) {
|
|
61
|
-
const repo = this.repos.get(repoPath);
|
|
62
|
-
if (repo) {
|
|
63
|
-
repo.connections++;
|
|
64
|
-
repo.lastActivity = Date.now();
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
/** Record that a bridge disconnected from this repo. */
|
|
68
|
-
disconnect(repoPath) {
|
|
69
|
-
const repo = this.repos.get(repoPath);
|
|
70
|
-
if (repo && repo.connections > 0) {
|
|
71
|
-
repo.connections--;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
/** Record activity (tool call) for this repo. */
|
|
75
|
-
recordActivity(repoPath) {
|
|
76
|
-
const repo = this.repos.get(repoPath);
|
|
77
|
-
if (repo) {
|
|
78
|
-
repo.lastActivity = Date.now();
|
|
79
|
-
this.onEvent?.("activity", repo);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
/** Gracefully stop a specific repo's process. */
|
|
83
|
-
async stop(repoPath) {
|
|
84
|
-
const repo = this.repos.get(repoPath);
|
|
85
|
-
if (!repo?.child || repo.status === "stopped")
|
|
86
|
-
return;
|
|
87
|
-
await this.shutdownChild(repo);
|
|
88
|
-
}
|
|
89
|
-
/** Gracefully stop ALL children, then clean up. */
|
|
90
|
-
async shutdownAll() {
|
|
91
|
-
this.stopped = true;
|
|
92
|
-
this.stopIdleSweep();
|
|
93
|
-
const shutdowns = [];
|
|
94
|
-
for (const repo of this.repos.values()) {
|
|
95
|
-
if (repo.child && repo.status !== "stopped") {
|
|
96
|
-
shutdowns.push(this.shutdownChild(repo));
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
await Promise.allSettled(shutdowns);
|
|
100
|
-
}
|
|
101
|
-
/** Get status for all managed repos (for daemon status / dashboard). */
|
|
102
|
-
getStatus() {
|
|
103
|
-
const registry = readRegistry();
|
|
104
|
-
const entries = [];
|
|
105
|
-
for (const regEntry of registry.repos) {
|
|
106
|
-
const managed = this.repos.get(regEntry.path);
|
|
107
|
-
entries.push({
|
|
108
|
-
path: regEntry.path,
|
|
109
|
-
label: regEntry.label,
|
|
110
|
-
status: managed?.status ?? "stopped",
|
|
111
|
-
pid: managed?.pid ?? null,
|
|
112
|
-
memory: managed?.memory ?? null,
|
|
113
|
-
idle: managed?.lastActivity
|
|
114
|
-
? Math.round((Date.now() - managed.lastActivity) / 1000)
|
|
115
|
-
: null,
|
|
116
|
-
connections: managed?.connections ?? 0,
|
|
117
|
-
lastActivity: managed?.lastActivity
|
|
118
|
-
? new Date(managed.lastActivity).toISOString()
|
|
119
|
-
: regEntry.lastActivity,
|
|
120
|
-
entityCount: managed?.entities ?? null,
|
|
121
|
-
edgeCount: managed?.edges ?? null,
|
|
122
|
-
needsInput: managed?.needsInput ?? readNeedsInput(regEntry.path),
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
return entries;
|
|
126
|
-
}
|
|
127
|
-
/** Get a managed repo record (for internal use). */
|
|
128
|
-
getManaged(repoPath) {
|
|
129
|
-
return this.repos.get(repoPath);
|
|
130
|
-
}
|
|
131
|
-
// ── Internal: spawn ─────────────────────────────────────────
|
|
132
|
-
async spawn(repoPath) {
|
|
133
|
-
const reg = readRegistry();
|
|
134
|
-
const entry = reg.repos.find((r) => r.path === repoPath);
|
|
135
|
-
const repo = {
|
|
136
|
-
path: repoPath,
|
|
137
|
-
label: entry?.label ?? repoPath.split("/").pop() ?? repoPath,
|
|
138
|
-
idleTimeout: entry?.idleTimeout ?? 1800,
|
|
139
|
-
status: "starting",
|
|
140
|
-
child: null,
|
|
141
|
-
pid: null,
|
|
142
|
-
sock: null,
|
|
143
|
-
connections: 0,
|
|
144
|
-
lastActivity: Date.now(),
|
|
145
|
-
startedAt: Date.now(),
|
|
146
|
-
memory: null,
|
|
147
|
-
entities: null,
|
|
148
|
-
edges: null,
|
|
149
|
-
needsInput: [],
|
|
150
|
-
readyResolve: null,
|
|
151
|
-
readyReject: null,
|
|
152
|
-
};
|
|
153
|
-
this.repos.set(repoPath, repo);
|
|
154
|
-
const unerrBin = process.argv[1];
|
|
155
|
-
const child = fork(unerrBin, ["--daemon-child"], {
|
|
156
|
-
cwd: repoPath,
|
|
157
|
-
stdio: ["ignore", "ignore", "inherit", "ipc"],
|
|
158
|
-
detached: false,
|
|
159
|
-
env: {
|
|
160
|
-
...process.env,
|
|
161
|
-
UNERR_DAEMON_CHILD: "1",
|
|
162
|
-
UNERR_REPO_PATH: repoPath,
|
|
163
|
-
},
|
|
164
|
-
});
|
|
165
|
-
repo.child = child;
|
|
166
|
-
repo.pid = child.pid ?? null;
|
|
167
|
-
child.on("message", (msg) => {
|
|
168
|
-
this.handleChildMessage(repoPath, msg);
|
|
169
|
-
});
|
|
170
|
-
child.on("exit", (code, signal) => {
|
|
171
|
-
this.handleChildExit(repoPath, code, signal);
|
|
172
|
-
});
|
|
173
|
-
child.on("error", (err) => {
|
|
174
|
-
repo.status = "error";
|
|
175
|
-
repo.readyReject?.(err);
|
|
176
|
-
repo.readyResolve = null;
|
|
177
|
-
repo.readyReject = null;
|
|
178
|
-
this.onEvent?.("error", repo, err.message);
|
|
179
|
-
});
|
|
180
|
-
// Update registry lastStarted
|
|
181
|
-
if (entry) {
|
|
182
|
-
entry.lastStarted = new Date().toISOString();
|
|
183
|
-
writeRegistry(reg);
|
|
184
|
-
}
|
|
185
|
-
return this.waitForReady(repo);
|
|
186
|
-
}
|
|
187
|
-
waitForReady(repo) {
|
|
188
|
-
if (repo.sock && repo.status === "running") {
|
|
189
|
-
return Promise.resolve(repo.sock);
|
|
190
|
-
}
|
|
191
|
-
return new Promise((resolve, reject) => {
|
|
192
|
-
repo.readyResolve = resolve;
|
|
193
|
-
repo.readyReject = reject;
|
|
194
|
-
const timer = setTimeout(() => {
|
|
195
|
-
repo.readyReject?.(new Error(`Repo process ${repo.path} failed to become ready in ${READY_TIMEOUT_MS}ms`));
|
|
196
|
-
repo.readyResolve = null;
|
|
197
|
-
repo.readyReject = null;
|
|
198
|
-
if (repo.status === "starting") {
|
|
199
|
-
repo.status = "error";
|
|
200
|
-
repo.child?.kill("SIGTERM");
|
|
201
|
-
}
|
|
202
|
-
}, READY_TIMEOUT_MS);
|
|
203
|
-
timer.unref();
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
// ── Internal: IPC handling ──────────────────────────────────
|
|
207
|
-
handleChildMessage(repoPath, msg) {
|
|
208
|
-
const repo = this.repos.get(repoPath);
|
|
209
|
-
if (!repo)
|
|
210
|
-
return;
|
|
211
|
-
switch (msg.type) {
|
|
212
|
-
case "ready":
|
|
213
|
-
repo.sock = msg.sock;
|
|
214
|
-
repo.status = "running";
|
|
215
|
-
repo.readyResolve?.(msg.sock);
|
|
216
|
-
repo.readyResolve = null;
|
|
217
|
-
repo.readyReject = null;
|
|
218
|
-
this.onEvent?.("started", repo);
|
|
219
|
-
break;
|
|
220
|
-
case "activity":
|
|
221
|
-
repo.lastActivity = Date.now();
|
|
222
|
-
this.onEvent?.("activity", repo);
|
|
223
|
-
break;
|
|
224
|
-
case "stats":
|
|
225
|
-
repo.entities = msg.entities;
|
|
226
|
-
repo.edges = msg.edges;
|
|
227
|
-
repo.memory = msg.memory;
|
|
228
|
-
break;
|
|
229
|
-
case "needs_input":
|
|
230
|
-
repo.needsInput = msg.signals;
|
|
231
|
-
break;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
handleChildExit(repoPath, code, signal) {
|
|
235
|
-
const repo = this.repos.get(repoPath);
|
|
236
|
-
if (!repo)
|
|
237
|
-
return;
|
|
238
|
-
const prev = repo.status;
|
|
239
|
-
repo.status = "stopped";
|
|
240
|
-
repo.child = null;
|
|
241
|
-
repo.pid = null;
|
|
242
|
-
repo.sock = null;
|
|
243
|
-
repo.connections = 0;
|
|
244
|
-
if (prev === "starting") {
|
|
245
|
-
repo.readyReject?.(new Error(`Child exited during startup (code=${code}, signal=${signal})`));
|
|
246
|
-
repo.readyResolve = null;
|
|
247
|
-
repo.readyReject = null;
|
|
248
|
-
}
|
|
249
|
-
this.onEvent?.("stopped", repo, `code=${code}, signal=${signal}`);
|
|
250
|
-
}
|
|
251
|
-
// ── Internal: graceful shutdown ─────────────────────────────
|
|
252
|
-
shutdownChild(repo) {
|
|
253
|
-
return new Promise((resolve) => {
|
|
254
|
-
if (!repo.child) {
|
|
255
|
-
resolve();
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
const child = repo.child;
|
|
259
|
-
const timer = setTimeout(() => {
|
|
260
|
-
if (!child.killed) {
|
|
261
|
-
child.kill("SIGKILL");
|
|
262
|
-
}
|
|
263
|
-
resolve();
|
|
264
|
-
}, 10_000);
|
|
265
|
-
timer.unref();
|
|
266
|
-
child.once("exit", () => {
|
|
267
|
-
clearTimeout(timer);
|
|
268
|
-
resolve();
|
|
269
|
-
});
|
|
270
|
-
try {
|
|
271
|
-
child.send({ type: "shutdown" });
|
|
272
|
-
}
|
|
273
|
-
catch {
|
|
274
|
-
child.kill("SIGTERM");
|
|
275
|
-
}
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
// ── Internal: idle sweep ────────────────────────────────────
|
|
279
|
-
runIdleSweep() {
|
|
280
|
-
if (this.stopped)
|
|
281
|
-
return;
|
|
282
|
-
const now = Date.now();
|
|
283
|
-
for (const repo of this.repos.values()) {
|
|
284
|
-
if (repo.status !== "running")
|
|
285
|
-
continue;
|
|
286
|
-
if (repo.connections > 0)
|
|
287
|
-
continue;
|
|
288
|
-
if (repo.idleTimeout === 0)
|
|
289
|
-
continue;
|
|
290
|
-
const idleMs = now - repo.lastActivity;
|
|
291
|
-
const timeoutMs = repo.idleTimeout * 1000;
|
|
292
|
-
if (idleMs >= timeoutMs) {
|
|
293
|
-
this.shutdownChild(repo).catch(() => {
|
|
294
|
-
/* best-effort */
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
package/dist/daemon/protocol.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* unerrd protocol — newline-delimited JSON over UDS (~/.unerr/unerrd.sock).
|
|
3
|
-
*
|
|
4
|
-
* Three communication planes:
|
|
5
|
-
* 1. Bridge → unerrd (ensure/connect/disconnect/activity)
|
|
6
|
-
* 2. Daemon CLI → unerrd (status/add/remove/stop/shutdown)
|
|
7
|
-
* 3. unerrd ↔ child repo processes (ready/activity/stats/shutdown)
|
|
8
|
-
*/
|
|
9
|
-
export const JAVA_BUILD_TOOLS = [
|
|
10
|
-
"Maven",
|
|
11
|
-
"Gradle",
|
|
12
|
-
"Bazel",
|
|
13
|
-
"Sbt",
|
|
14
|
-
];
|
|
15
|
-
// ── Constants ───────────────────────────────────────────────────
|
|
16
|
-
/** Default idle timeout for repos (30 minutes in seconds). */
|
|
17
|
-
export const DEFAULT_IDLE_TIMEOUT_S = 1800;
|
|
18
|
-
/** Default warm-start budget (top N most-recently-active repos). */
|
|
19
|
-
export const DEFAULT_WARM_START_BUDGET = 3;
|
|
20
|
-
/** Default warm-start delay after daemon boot (ms). */
|
|
21
|
-
export const DEFAULT_WARM_START_DELAY_MS = 30_000;
|
|
22
|
-
/** Default warm-start idle-days cutoff. */
|
|
23
|
-
export const DEFAULT_WARM_START_IDLE_DAYS = 14;
|
package/dist/daemon/registry.js
DELETED
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Daemon registry — CRUD operations on ~/.unerr/repos.json.
|
|
3
|
-
*
|
|
4
|
-
* The registry is the single source of truth for which repos are managed
|
|
5
|
-
* by the unerrd supervisor. Each repo entry stores:
|
|
6
|
-
* - Absolute path (identity anchor — P3: directory is identity)
|
|
7
|
-
* - Timestamps (addedAt, lastStarted, lastActivity)
|
|
8
|
-
* - Derived label (basename for display, guaranteed unique in registry)
|
|
9
|
-
* - Settings (idleTimeout, javaBuildTool, autostart, future keys)
|
|
10
|
-
*
|
|
11
|
-
* All repo-specific artifacts live in <repo>/.unerr/. The registry only
|
|
12
|
-
* stores paths + metadata. Deleting ~/.unerr/ loses registration, not
|
|
13
|
-
* intelligence — each repo's .unerr/ is intact.
|
|
14
|
-
*/
|
|
15
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
16
|
-
import { homedir } from "node:os";
|
|
17
|
-
import { basename, dirname, join, resolve } from "node:path";
|
|
18
|
-
import { DEFAULT_IDLE_TIMEOUT_S, } from "./protocol.js";
|
|
19
|
-
// ── Paths ───────────────────────────────────────────────────────
|
|
20
|
-
/** Global unerr directory — supervisor state only. Respects UNERR_HOME for testing. */
|
|
21
|
-
export function globalDir() {
|
|
22
|
-
const override = process.env.UNERR_HOME;
|
|
23
|
-
if (override)
|
|
24
|
-
return join(override, ".unerr");
|
|
25
|
-
return join(homedir(), ".unerr");
|
|
26
|
-
}
|
|
27
|
-
/** Path to the registry file. */
|
|
28
|
-
export function registryPath() {
|
|
29
|
-
return join(globalDir(), "repos.json");
|
|
30
|
-
}
|
|
31
|
-
// ── Read / Write ────────────────────────────────────────────────
|
|
32
|
-
/** Read the registry from disk. Returns empty registry if missing. */
|
|
33
|
-
export function readRegistry() {
|
|
34
|
-
try {
|
|
35
|
-
const raw = readFileSync(registryPath(), "utf-8");
|
|
36
|
-
const parsed = JSON.parse(raw);
|
|
37
|
-
if (parsed.version !== 1 || !Array.isArray(parsed.repos)) {
|
|
38
|
-
return { version: 1, repos: [] };
|
|
39
|
-
}
|
|
40
|
-
return parsed;
|
|
41
|
-
}
|
|
42
|
-
catch {
|
|
43
|
-
return { version: 1, repos: [] };
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
/** Write the registry atomically (write-then-rename is overkill for <100 entries). */
|
|
47
|
-
export function writeRegistry(reg) {
|
|
48
|
-
const dir = globalDir();
|
|
49
|
-
if (!existsSync(dir)) {
|
|
50
|
-
mkdirSync(dir, { recursive: true });
|
|
51
|
-
}
|
|
52
|
-
writeFileSync(registryPath(), `${JSON.stringify(reg, null, 2)}\n`);
|
|
53
|
-
}
|
|
54
|
-
// ── Label generation ────────────────────────────────────────────
|
|
55
|
-
/**
|
|
56
|
-
* Derive a unique, human-friendly label from the repo path.
|
|
57
|
-
* Falls back to `<parent>-<basename>` then `<basename>-<N>` on collision.
|
|
58
|
-
*/
|
|
59
|
-
export function deriveLabel(repoPath, existing) {
|
|
60
|
-
const base = basename(repoPath);
|
|
61
|
-
const taken = new Set(existing.map((e) => e.label));
|
|
62
|
-
if (!taken.has(base))
|
|
63
|
-
return base;
|
|
64
|
-
const parentBase = `${basename(dirname(repoPath))}-${base}`;
|
|
65
|
-
if (!taken.has(parentBase))
|
|
66
|
-
return parentBase;
|
|
67
|
-
for (let i = 2; i < 100; i++) {
|
|
68
|
-
const candidate = `${base}-${i}`;
|
|
69
|
-
if (!taken.has(candidate))
|
|
70
|
-
return candidate;
|
|
71
|
-
}
|
|
72
|
-
return `${base}-${Date.now()}`;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Add a repo to the registry.
|
|
76
|
-
*
|
|
77
|
-
* Steps:
|
|
78
|
-
* 1. Resolve to absolute path
|
|
79
|
-
* 2. Check if already registered (idempotent — returns existing entry)
|
|
80
|
-
* 3. Parent-directory conflict check
|
|
81
|
-
* 4. Child-directory overlap scan
|
|
82
|
-
* 5. Add entry with settings
|
|
83
|
-
* 6. Ensure <repo>/.unerr/ exists
|
|
84
|
-
* 7. Mirror settings to <repo>/.unerr/config.json
|
|
85
|
-
*/
|
|
86
|
-
export function addRepo(rawPath, settings = {}, opts = {}) {
|
|
87
|
-
const absPath = resolve(rawPath);
|
|
88
|
-
const reg = readRegistry();
|
|
89
|
-
// Already registered — idempotent
|
|
90
|
-
const existing = reg.repos.find((r) => r.path === absPath);
|
|
91
|
-
if (existing) {
|
|
92
|
-
return { ok: true, entry: existing, created: false };
|
|
93
|
-
}
|
|
94
|
-
// Parent-directory conflict: walk up from absPath checking for existing registrations
|
|
95
|
-
if (!opts.skipParentCheck) {
|
|
96
|
-
const parentConflict = detectParentConflict(absPath, reg.repos);
|
|
97
|
-
if (parentConflict) {
|
|
98
|
-
return {
|
|
99
|
-
ok: false,
|
|
100
|
-
error: `Parent directory ${parentConflict} already registered with unerrd. That process covers this subdirectory.`,
|
|
101
|
-
parentConflict,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
// Child-directory overlap: any registered repo that is a subdirectory of absPath
|
|
106
|
-
if (!opts.skipChildCheck) {
|
|
107
|
-
const childConflicts = detectChildConflicts(absPath, reg.repos);
|
|
108
|
-
if (childConflicts.length > 0) {
|
|
109
|
-
return {
|
|
110
|
-
ok: false,
|
|
111
|
-
error: `Subdirectories already registered: ${childConflicts.join(", ")}. Remove them first or use --skip-child-check.`,
|
|
112
|
-
childConflicts,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
const entry = {
|
|
117
|
-
path: absPath,
|
|
118
|
-
addedAt: new Date().toISOString(),
|
|
119
|
-
lastStarted: null,
|
|
120
|
-
lastActivity: null,
|
|
121
|
-
idleTimeout: settings.idleTimeout ?? DEFAULT_IDLE_TIMEOUT_S,
|
|
122
|
-
label: deriveLabel(absPath, reg.repos),
|
|
123
|
-
settings: buildSettings(settings),
|
|
124
|
-
};
|
|
125
|
-
reg.repos.push(entry);
|
|
126
|
-
writeRegistry(reg);
|
|
127
|
-
// Ensure <repo>/.unerr/ exists
|
|
128
|
-
const unerrDir = join(absPath, ".unerr");
|
|
129
|
-
if (!existsSync(unerrDir)) {
|
|
130
|
-
mkdirSync(unerrDir, { recursive: true });
|
|
131
|
-
}
|
|
132
|
-
// Mirror settings to local config
|
|
133
|
-
mirrorSettingsToLocal(absPath, entry.settings);
|
|
134
|
-
return { ok: true, entry, created: true };
|
|
135
|
-
}
|
|
136
|
-
/** Remove a repo from the registry by absolute path. */
|
|
137
|
-
export function removeRepo(rawPath) {
|
|
138
|
-
const absPath = resolve(rawPath);
|
|
139
|
-
const reg = readRegistry();
|
|
140
|
-
const before = reg.repos.length;
|
|
141
|
-
reg.repos = reg.repos.filter((r) => r.path !== absPath);
|
|
142
|
-
if (reg.repos.length === before)
|
|
143
|
-
return false;
|
|
144
|
-
writeRegistry(reg);
|
|
145
|
-
return true;
|
|
146
|
-
}
|
|
147
|
-
/** Find a repo entry by path or label. */
|
|
148
|
-
export function findRepo(pathOrLabel) {
|
|
149
|
-
const reg = readRegistry();
|
|
150
|
-
const abs = resolve(pathOrLabel);
|
|
151
|
-
return (reg.repos.find((r) => r.path === abs) ??
|
|
152
|
-
reg.repos.find((r) => r.label === pathOrLabel));
|
|
153
|
-
}
|
|
154
|
-
/** List all registered repos. */
|
|
155
|
-
export function listRepos() {
|
|
156
|
-
return readRegistry().repos;
|
|
157
|
-
}
|
|
158
|
-
// ── Config update ───────────────────────────────────────────────
|
|
159
|
-
/**
|
|
160
|
-
* Update settings on an existing repo entry.
|
|
161
|
-
* Writes to both registry and <repo>/.unerr/config.json.
|
|
162
|
-
* Returns the updated entry, or null if not found.
|
|
163
|
-
*/
|
|
164
|
-
export function updateRepoSettings(rawPath, patch) {
|
|
165
|
-
const absPath = resolve(rawPath);
|
|
166
|
-
const reg = readRegistry();
|
|
167
|
-
const entry = reg.repos.find((r) => r.path === absPath);
|
|
168
|
-
if (!entry)
|
|
169
|
-
return null;
|
|
170
|
-
// Apply patch
|
|
171
|
-
for (const [k, v] of Object.entries(patch)) {
|
|
172
|
-
entry.settings[k] = v;
|
|
173
|
-
// Keep top-level shorthand fields in sync
|
|
174
|
-
if (k === "idleTimeout" && typeof v === "number") {
|
|
175
|
-
entry.idleTimeout = v;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
writeRegistry(reg);
|
|
179
|
-
mirrorSettingsToLocal(absPath, entry.settings);
|
|
180
|
-
return entry;
|
|
181
|
-
}
|
|
182
|
-
// ── Parent / child detection ────────────────────────────────────
|
|
183
|
-
/**
|
|
184
|
-
* Walk up from `target` checking if any parent directory is registered.
|
|
185
|
-
* Returns the conflicting parent path, or null.
|
|
186
|
-
*/
|
|
187
|
-
export function detectParentConflict(target, repos) {
|
|
188
|
-
const registeredPaths = new Set(repos.map((r) => r.path));
|
|
189
|
-
let current = dirname(target);
|
|
190
|
-
const root = dirname(current) === current ? current : undefined;
|
|
191
|
-
while (current !== root) {
|
|
192
|
-
if (registeredPaths.has(current))
|
|
193
|
-
return current;
|
|
194
|
-
// Also check for .unerr/ directory with a running process
|
|
195
|
-
if (existsSync(join(current, ".unerr", "state", "proxy.pid"))) {
|
|
196
|
-
return current;
|
|
197
|
-
}
|
|
198
|
-
const parent = dirname(current);
|
|
199
|
-
if (parent === current)
|
|
200
|
-
break;
|
|
201
|
-
current = parent;
|
|
202
|
-
}
|
|
203
|
-
return null;
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Find registered repos that are subdirectories of `target`.
|
|
207
|
-
* Returns paths of conflicting children.
|
|
208
|
-
*/
|
|
209
|
-
export function detectChildConflicts(target, repos) {
|
|
210
|
-
const normalized = target.endsWith("/") ? target : `${target}/`;
|
|
211
|
-
return repos.filter((r) => r.path.startsWith(normalized)).map((r) => r.path);
|
|
212
|
-
}
|
|
213
|
-
// ── Needs-input signals ─────────────────────────────────────────
|
|
214
|
-
/**
|
|
215
|
-
* Read needs_input signals from <repo>/.unerr/needs-input.json.
|
|
216
|
-
* Written by the per-repo process when auto-detection picks under ambiguity.
|
|
217
|
-
*/
|
|
218
|
-
export function readNeedsInput(repoPath) {
|
|
219
|
-
try {
|
|
220
|
-
const p = join(repoPath, ".unerr", "needs-input.json");
|
|
221
|
-
return JSON.parse(readFileSync(p, "utf-8"));
|
|
222
|
-
}
|
|
223
|
-
catch {
|
|
224
|
-
return [];
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Write needs_input signals to <repo>/.unerr/needs-input.json.
|
|
229
|
-
* Called by the per-repo process (e.g., Java build tool auto-detection).
|
|
230
|
-
*/
|
|
231
|
-
export function writeNeedsInput(repoPath, signals) {
|
|
232
|
-
const dir = join(repoPath, ".unerr");
|
|
233
|
-
if (!existsSync(dir))
|
|
234
|
-
mkdirSync(dir, { recursive: true });
|
|
235
|
-
writeFileSync(join(dir, "needs-input.json"), `${JSON.stringify(signals, null, 2)}\n`);
|
|
236
|
-
}
|
|
237
|
-
// ── Internal helpers ────────────────────────────────────────────
|
|
238
|
-
/** Build a clean settings object from partial input. */
|
|
239
|
-
function buildSettings(partial) {
|
|
240
|
-
const s = {};
|
|
241
|
-
for (const [k, v] of Object.entries(partial)) {
|
|
242
|
-
if (v !== undefined && k !== "idleTimeout") {
|
|
243
|
-
s[k] = v;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
return s;
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Mirror settings from registry into <repo>/.unerr/config.json.
|
|
250
|
-
* Merges with any existing config (preserves repoId, mode, etc.).
|
|
251
|
-
*/
|
|
252
|
-
function mirrorSettingsToLocal(repoPath, settings) {
|
|
253
|
-
const configPath = join(repoPath, ".unerr", "config.json");
|
|
254
|
-
let config = {};
|
|
255
|
-
try {
|
|
256
|
-
config = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
257
|
-
}
|
|
258
|
-
catch {
|
|
259
|
-
// Fresh config
|
|
260
|
-
}
|
|
261
|
-
for (const [k, v] of Object.entries(settings)) {
|
|
262
|
-
if (v !== undefined) {
|
|
263
|
-
config[k] = v;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
const dir = join(repoPath, ".unerr");
|
|
267
|
-
if (!existsSync(dir))
|
|
268
|
-
mkdirSync(dir, { recursive: true });
|
|
269
|
-
writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`);
|
|
270
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Settings schema — allow-list + validation for per-repo daemon settings.
|
|
3
|
-
*
|
|
4
|
-
* Every key that `daemon add --<key>=<value>` or `daemon config --<key>=<value>`
|
|
5
|
-
* accepts is registered here. The registry stores arbitrary `settings: Record<…>`
|
|
6
|
-
* so new keys require zero schema migration — just add a row to SETTINGS_SCHEMA.
|
|
7
|
-
*/
|
|
8
|
-
import { JAVA_BUILD_TOOLS } from "./protocol.js";
|
|
9
|
-
const parsePositiveInt = (raw) => {
|
|
10
|
-
const n = Number.parseInt(raw, 10);
|
|
11
|
-
if (!Number.isFinite(n) || n < 0) {
|
|
12
|
-
throw new Error(`Expected non-negative integer, got "${raw}"`);
|
|
13
|
-
}
|
|
14
|
-
return n;
|
|
15
|
-
};
|
|
16
|
-
const parseJavaBuildTool = (raw) => {
|
|
17
|
-
const normalized = raw.charAt(0).toUpperCase() + raw.slice(1).toLowerCase();
|
|
18
|
-
if (!JAVA_BUILD_TOOLS.includes(normalized)) {
|
|
19
|
-
throw new Error(`Invalid Java build tool "${raw}". Valid: ${JAVA_BUILD_TOOLS.join(", ")}`);
|
|
20
|
-
}
|
|
21
|
-
return normalized;
|
|
22
|
-
};
|
|
23
|
-
const parseAutostart = (raw) => {
|
|
24
|
-
const valid = ["eager", "auto", "never"];
|
|
25
|
-
const lower = raw.toLowerCase();
|
|
26
|
-
if (!valid.includes(lower)) {
|
|
27
|
-
throw new Error(`Invalid autostart value "${raw}". Valid: ${valid.join(", ")}`);
|
|
28
|
-
}
|
|
29
|
-
return lower;
|
|
30
|
-
};
|
|
31
|
-
export const SETTINGS_SCHEMA = [
|
|
32
|
-
{
|
|
33
|
-
flag: "idle-timeout",
|
|
34
|
-
key: "idleTimeout",
|
|
35
|
-
description: "Idle timeout in seconds before auto-stop (0 = never)",
|
|
36
|
-
parse: parsePositiveInt,
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
flag: "java-build-tool",
|
|
40
|
-
key: "javaBuildTool",
|
|
41
|
-
description: `Java build tool override (${JAVA_BUILD_TOOLS.join("|")})`,
|
|
42
|
-
parse: parseJavaBuildTool,
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
flag: "autostart",
|
|
46
|
-
key: "autostart",
|
|
47
|
-
description: "Warm-start policy on daemon boot (eager|auto|never)",
|
|
48
|
-
parse: parseAutostart,
|
|
49
|
-
},
|
|
50
|
-
];
|
|
51
|
-
/** Map from CLI flag name → SettingDef for O(1) lookup. */
|
|
52
|
-
export const SETTINGS_BY_FLAG = new Map(SETTINGS_SCHEMA.map((s) => [s.flag, s]));
|
|
53
|
-
/** Map from camelCase key → SettingDef for config.json round-tripping. */
|
|
54
|
-
export const SETTINGS_BY_KEY = new Map(SETTINGS_SCHEMA.map((s) => [s.key, s]));
|
|
55
|
-
/**
|
|
56
|
-
* Parse raw CLI `--key=value` pairs into validated RepoSettings.
|
|
57
|
-
* Returns only the keys that were explicitly provided.
|
|
58
|
-
* Throws on the first invalid value with a descriptive error.
|
|
59
|
-
*/
|
|
60
|
-
export function parseSettingsFlags(raw) {
|
|
61
|
-
const result = {};
|
|
62
|
-
for (const [flag, value] of Object.entries(raw)) {
|
|
63
|
-
if (value === undefined)
|
|
64
|
-
continue;
|
|
65
|
-
const def = SETTINGS_BY_FLAG.get(flag);
|
|
66
|
-
if (!def) {
|
|
67
|
-
throw new Error(`Unknown setting "--${flag}". Valid flags: ${SETTINGS_SCHEMA.map((s) => `--${s.flag}`).join(", ")}`);
|
|
68
|
-
}
|
|
69
|
-
result[def.key] = def.parse(value);
|
|
70
|
-
}
|
|
71
|
-
return result;
|
|
72
|
-
}
|