@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
package/dist/commands/install.js
DELETED
|
@@ -1,505 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `unerr install <agent>` — Install unerr for a specific AI coding agent.
|
|
3
|
-
*
|
|
4
|
-
* Following the Graphify pattern: explicit per-agent installation.
|
|
5
|
-
* Each install writes the MCP config + installs intelligence skills.
|
|
6
|
-
*
|
|
7
|
-
* Examples:
|
|
8
|
-
* unerr install claude-code → .mcp.json + .claude/skills/
|
|
9
|
-
* unerr install cursor → .cursor/mcp.json + .cursor/rules/
|
|
10
|
-
* unerr install vscode → .vscode/mcp.json + .github/copilot/
|
|
11
|
-
*
|
|
12
|
-
* All output to stderr (stdout is MCP-sacred).
|
|
13
|
-
*/
|
|
14
|
-
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync, } from "node:fs";
|
|
15
|
-
import { join } from "node:path";
|
|
16
|
-
import { AGENT_REGISTRY, getAgent, normalizeAgentName, } from "../config/agent-registry.js";
|
|
17
|
-
import { addDisallowedTools, mergePreToolUseBashHook, } from "../config/claude-settings-hooks.js";
|
|
18
|
-
import { installClaudeHook } from "../config/hook-installer.js";
|
|
19
|
-
import { generateCustomInstructions, writeInstructionFile, } from "../config/instruction-writer.js";
|
|
20
|
-
import { isConfigured, writeMcpConfig } from "../config/mcp-config-writer.js";
|
|
21
|
-
import { BUNDLED_SKILLS } from "../skills/local-pack.js";
|
|
22
|
-
import { resolveAndInstallSkills } from "../skills/resolver.js";
|
|
23
|
-
export function registerInstallCommand(program) {
|
|
24
|
-
program
|
|
25
|
-
.command("install [agent]")
|
|
26
|
-
.description("Install unerr for a specific AI coding agent")
|
|
27
|
-
.option("--force", "Overwrite existing configuration")
|
|
28
|
-
.option("--no-force-tools", "Keep built-in Read/Grep/Glob enabled (Claude Code only, default: denied)")
|
|
29
|
-
.option("--show-skills", "Print skill content for manual installation")
|
|
30
|
-
.option("--show-instructions [agent]", "Print setup instructions for any AI coding agent")
|
|
31
|
-
.action(async (agent, opts) => {
|
|
32
|
-
const cwd = process.cwd();
|
|
33
|
-
// --show-instructions: print agent-specific or generic setup guide
|
|
34
|
-
if (opts?.showInstructions !== undefined) {
|
|
35
|
-
const targetAgent = typeof opts.showInstructions === "string"
|
|
36
|
-
? opts.showInstructions
|
|
37
|
-
: (agent ?? "other");
|
|
38
|
-
showSetupInstructions(normalizeAgentName(targetAgent));
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
// --show-skills: print skill content for manual copy
|
|
42
|
-
if (opts?.showSkills) {
|
|
43
|
-
await showSkillContent();
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
// No agent specified — show available agents
|
|
47
|
-
if (!agent) {
|
|
48
|
-
showAvailableAgents(cwd);
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
// Normalize agent name (allow "claude" as alias for "claude-code")
|
|
52
|
-
const normalizedAgent = normalizeAgentName(agent);
|
|
53
|
-
const agentDef = getAgent(normalizedAgent);
|
|
54
|
-
if (!agentDef) {
|
|
55
|
-
process.stderr.write(`\x1b[31m✗\x1b[0m Unknown agent: "${agent}"\n\n`);
|
|
56
|
-
showAvailableAgents(cwd);
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
const result = await runInstall(cwd, normalizedAgent, {
|
|
60
|
-
forceTools: opts?.forceTools,
|
|
61
|
-
});
|
|
62
|
-
// Display results
|
|
63
|
-
process.stderr.write("\n");
|
|
64
|
-
process.stderr.write(` \x1b[38;2;139;92;246m◆\x1b[0m \x1b[1munerr → ${agentDef.name}\x1b[0m\n`);
|
|
65
|
-
process.stderr.write("\n");
|
|
66
|
-
// MCP config
|
|
67
|
-
if (result.mcpConfig.action === "created") {
|
|
68
|
-
process.stderr.write(` \x1b[38;2;52;211;153m✓\x1b[0m MCP config created → ${result.mcpConfig.path}\n`);
|
|
69
|
-
}
|
|
70
|
-
else if (result.mcpConfig.action === "updated") {
|
|
71
|
-
process.stderr.write(` \x1b[38;2;52;211;153m✓\x1b[0m MCP config updated → ${result.mcpConfig.path}\n`);
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
process.stderr.write(` \x1b[38;2;161;161;170m·\x1b[0m MCP config already present → ${result.mcpConfig.path}\n`);
|
|
75
|
-
}
|
|
76
|
-
// Skills
|
|
77
|
-
if (result.skillsInstalled > 0) {
|
|
78
|
-
process.stderr.write(` \x1b[38;2;52;211;153m✓\x1b[0m ${result.skillsInstalled} intelligence skills installed\n`);
|
|
79
|
-
}
|
|
80
|
-
// Hook
|
|
81
|
-
if (result.hookInstalled) {
|
|
82
|
-
process.stderr.write(" \x1b[38;2;52;211;153m✓\x1b[0m PreToolUse hook installed (graph-first navigation)\n");
|
|
83
|
-
}
|
|
84
|
-
// Gitignore
|
|
85
|
-
if (result.gitignoreUpdated) {
|
|
86
|
-
process.stderr.write(" \x1b[38;2;52;211;153m✓\x1b[0m .unerr added to .gitignore\n");
|
|
87
|
-
}
|
|
88
|
-
// Instructions
|
|
89
|
-
if (result.instructionsInjected) {
|
|
90
|
-
process.stderr.write(` \x1b[38;2;52;211;153m✓\x1b[0m Tool preferences → ${result.instructionPath}\n`);
|
|
91
|
-
}
|
|
92
|
-
// S8: Disallowed tools (default-on for Claude Code)
|
|
93
|
-
if (result.toolsDenied > 0) {
|
|
94
|
-
process.stderr.write(" \x1b[38;2;52;211;153m✓\x1b[0m Built-in Read/Grep/Glob denied (use --no-force-tools to keep)\n");
|
|
95
|
-
}
|
|
96
|
-
process.stderr.write("\n");
|
|
97
|
-
process.stderr.write(" \x1b[38;2;161;161;170mRun \x1b[0munerr\x1b[38;2;161;161;170m to start the intelligence engine.\x1b[0m\n");
|
|
98
|
-
process.stderr.write("\n");
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Core install logic — writes MCP config + skills for a single agent.
|
|
103
|
-
*/
|
|
104
|
-
export async function runInstall(cwd, ide, opts) {
|
|
105
|
-
const agentDef = getAgent(ide);
|
|
106
|
-
const agentName = agentDef?.name ?? ide;
|
|
107
|
-
// 1. Write MCP config (project-level)
|
|
108
|
-
const mcpConfig = writeMcpConfig(cwd, ide);
|
|
109
|
-
// 2. Install skills into agent-specific directory
|
|
110
|
-
let skillsInstalled = 0;
|
|
111
|
-
try {
|
|
112
|
-
const result = await resolveAndInstallSkills({ ide, cwd });
|
|
113
|
-
skillsInstalled = result.installed.length;
|
|
114
|
-
}
|
|
115
|
-
catch {
|
|
116
|
-
// Non-blocking
|
|
117
|
-
}
|
|
118
|
-
// 3. Install hooks if supported: agent-specific hook registration
|
|
119
|
-
let hookInstalled = false;
|
|
120
|
-
if (agentDef?.hookSupport) {
|
|
121
|
-
try {
|
|
122
|
-
if (ide === "claude-code") {
|
|
123
|
-
// Claude Code: PostToolUse shell hook + PreToolUse/PostToolUse/UserPromptSubmit settings hooks
|
|
124
|
-
const hookResult = installClaudeHook(cwd);
|
|
125
|
-
const preTool = mergePreToolUseBashHook(cwd);
|
|
126
|
-
hookInstalled =
|
|
127
|
-
hookResult.action === "installed" ||
|
|
128
|
-
preTool.action === "merged" ||
|
|
129
|
-
preTool.action === "already_present";
|
|
130
|
-
}
|
|
131
|
-
else if (ide === "cursor") {
|
|
132
|
-
// Cursor: hook config in .cursor/hooks.json (when supported)
|
|
133
|
-
hookInstalled = installCursorHooks(cwd);
|
|
134
|
-
}
|
|
135
|
-
else if (ide === "cline") {
|
|
136
|
-
// Cline: hook scripts in .clinerules/hooks/ (when supported)
|
|
137
|
-
hookInstalled = installClineHooks(cwd);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
catch {
|
|
141
|
-
// Non-blocking
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
// 4. Ensure .unerr is in .gitignore
|
|
145
|
-
const gitignoreUpdated = ensureGitignore(cwd);
|
|
146
|
-
// 5. Inject tool preferences into agent instruction file
|
|
147
|
-
let instructionsInjected = false;
|
|
148
|
-
let instructionPath = "";
|
|
149
|
-
try {
|
|
150
|
-
const instrResult = writeInstructionFile(cwd, ide);
|
|
151
|
-
instructionsInjected =
|
|
152
|
-
instrResult.action === "created" || instrResult.action === "updated";
|
|
153
|
-
instructionPath = instrResult.path;
|
|
154
|
-
}
|
|
155
|
-
catch {
|
|
156
|
-
// Non-blocking
|
|
157
|
-
}
|
|
158
|
-
// 6. S8: Deny built-in tools (Claude Code only, default-on)
|
|
159
|
-
// --no-force-tools opts out; otherwise always deny Read/Grep/Glob
|
|
160
|
-
let toolsDenied = 0;
|
|
161
|
-
const shouldDenyTools = opts?.forceTools !== false && ide === "claude-code";
|
|
162
|
-
if (shouldDenyTools) {
|
|
163
|
-
try {
|
|
164
|
-
const deny = addDisallowedTools(cwd);
|
|
165
|
-
toolsDenied = deny.added;
|
|
166
|
-
}
|
|
167
|
-
catch {
|
|
168
|
-
// Non-blocking
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
// 7. Register repo with daemon supervisor and start the per-repo process (only if unerrd is running)
|
|
172
|
-
let repoRegistered = false;
|
|
173
|
-
try {
|
|
174
|
-
const { daemonSockPath, probeDaemon, ensureRepo } = await import("../daemon/client.js");
|
|
175
|
-
const { addRepo, findRepo } = await import("../daemon/registry.js");
|
|
176
|
-
const sock = daemonSockPath();
|
|
177
|
-
const daemonRunning = await probeDaemon(sock);
|
|
178
|
-
if (daemonRunning) {
|
|
179
|
-
if (!findRepo(cwd)) {
|
|
180
|
-
addRepo(cwd, {});
|
|
181
|
-
repoRegistered = true;
|
|
182
|
-
process.stderr.write("\x1b[38;2;52;211;153m✓\x1b[0m Registered repo with unerrd.\n");
|
|
183
|
-
}
|
|
184
|
-
// Ask the daemon to start the per-repo process
|
|
185
|
-
try {
|
|
186
|
-
await ensureRepo(sock, cwd);
|
|
187
|
-
process.stderr.write("\x1b[38;2;52;211;153m✓\x1b[0m unerr process started via daemon.\n");
|
|
188
|
-
}
|
|
189
|
-
catch {
|
|
190
|
-
process.stderr.write("\x1b[38;2;251;191;36m⚠\x1b[0m Repo registered but process did not start. It will start on next IDE connection.\n");
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
process.stderr.write("\x1b[38;2;34;211;238m▸\x1b[0m Daemon not running. To use daemon mode: \x1b[1munerr daemon initialize\x1b[0m\n" +
|
|
195
|
-
" For standalone mode: run \x1b[1munerr\x1b[0m in this directory.\n");
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
catch {
|
|
199
|
-
// Non-blocking — user can register later
|
|
200
|
-
}
|
|
201
|
-
return {
|
|
202
|
-
agent: agentName,
|
|
203
|
-
mcpConfig,
|
|
204
|
-
skillsInstalled,
|
|
205
|
-
hookInstalled,
|
|
206
|
-
gitignoreUpdated,
|
|
207
|
-
instructionsInjected,
|
|
208
|
-
instructionPath,
|
|
209
|
-
toolsDenied,
|
|
210
|
-
repoRegistered,
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Display available agents with install status.
|
|
215
|
-
*/
|
|
216
|
-
function showAvailableAgents(cwd) {
|
|
217
|
-
process.stderr.write("\n");
|
|
218
|
-
process.stderr.write(" \x1b[38;2;139;92;246m◆\x1b[0m \x1b[1munerr install <agent>\x1b[0m\n");
|
|
219
|
-
process.stderr.write("\n");
|
|
220
|
-
process.stderr.write(" \x1b[38;2;161;161;170mInstall unerr intelligence for a specific AI coding agent.\x1b[0m\n");
|
|
221
|
-
process.stderr.write(" \x1b[38;2;161;161;170mWrites MCP config + installs skills (project-level, never global).\x1b[0m\n");
|
|
222
|
-
process.stderr.write("\n");
|
|
223
|
-
process.stderr.write(" \x1b[38;2;161;161;170mAgent Command Status\x1b[0m\n");
|
|
224
|
-
process.stderr.write(" \x1b[2m─────────────────────────────────────────────────────────────────\x1b[0m\n");
|
|
225
|
-
for (const agent of AGENT_REGISTRY) {
|
|
226
|
-
const installed = isConfigured(cwd, agent.id);
|
|
227
|
-
const status = installed
|
|
228
|
-
? "\x1b[38;2;52;211;153m✓ installed\x1b[0m"
|
|
229
|
-
: "\x1b[38;2;161;161;170m·\x1b[0m";
|
|
230
|
-
const name = agent.name.padEnd(18);
|
|
231
|
-
const cmd = `unerr install ${agent.id}`.padEnd(32);
|
|
232
|
-
process.stderr.write(` ${name} ${cmd} ${status}\n`);
|
|
233
|
-
}
|
|
234
|
-
process.stderr.write("\n");
|
|
235
|
-
process.stderr.write(" \x1b[38;2;161;161;170mExample:\x1b[0m unerr install claude-code\n");
|
|
236
|
-
process.stderr.write("\n");
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Print bundled skill content for manual installation into custom agents.
|
|
240
|
-
*/
|
|
241
|
-
async function showSkillContent() {
|
|
242
|
-
process.stderr.write("\n");
|
|
243
|
-
process.stderr.write(" \x1b[38;2;139;92;246m◆\x1b[0m \x1b[1munerr intelligence skills\x1b[0m\n");
|
|
244
|
-
process.stderr.write("\n");
|
|
245
|
-
process.stderr.write(" \x1b[38;2;161;161;170mCopy these into your agent's rules/prompts directory.\x1b[0m\n");
|
|
246
|
-
process.stderr.write(" \x1b[38;2;161;161;170mThey teach the agent to use unerr's graph tools before reading files.\x1b[0m\n");
|
|
247
|
-
for (const skill of BUNDLED_SKILLS) {
|
|
248
|
-
process.stderr.write("\n");
|
|
249
|
-
process.stderr.write(` \x1b[2m── ${skill.name} ──────────────────────────────────────────\x1b[0m\n`);
|
|
250
|
-
process.stderr.write(` \x1b[38;2;161;161;170m${skill.description}\x1b[0m\n\n`);
|
|
251
|
-
// Print content with indentation
|
|
252
|
-
for (const line of skill.content.split("\n")) {
|
|
253
|
-
process.stderr.write(` ${line}\n`);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
process.stderr.write("\n");
|
|
257
|
-
process.stderr.write(" \x1b[38;2;161;161;170mMCP config to add alongside skills:\x1b[0m\n\n");
|
|
258
|
-
process.stderr.write(` ${JSON.stringify({ mcpServers: { unerr: { command: "unerr", args: ["--mcp"] } } }, null, 2)
|
|
259
|
-
.split("\n")
|
|
260
|
-
.join("\n ")}\n`);
|
|
261
|
-
process.stderr.write("\n");
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Print detailed setup instructions for a specific agent or generic guide.
|
|
265
|
-
*/
|
|
266
|
-
function showSetupInstructions(agentName) {
|
|
267
|
-
const agentDef = getAgent(agentName);
|
|
268
|
-
const w = (s) => process.stderr.write(s);
|
|
269
|
-
w("\n");
|
|
270
|
-
if (agentDef) {
|
|
271
|
-
// Known agent — show agent-specific instructions
|
|
272
|
-
w(` \x1b[38;2;139;92;246m◆\x1b[0m \x1b[1mSetup instructions for ${agentDef.name}\x1b[0m\n\n`);
|
|
273
|
-
// Step 1: MCP config
|
|
274
|
-
w(" \x1b[1m1. MCP Configuration\x1b[0m\n");
|
|
275
|
-
w(` Add to ${agentDef.projectConfigPath}:\n\n`);
|
|
276
|
-
if (agentDef.configFormat === "settings-json") {
|
|
277
|
-
w(` ${JSON.stringify({ mcpServers: { unerr: { command: "unerr", args: ["--mcp"] } } }, null, 2)
|
|
278
|
-
.split("\n")
|
|
279
|
-
.join("\n ")}\n\n`);
|
|
280
|
-
}
|
|
281
|
-
else if (agentDef.configFormat === "continue-config") {
|
|
282
|
-
w(` ${JSON.stringify({
|
|
283
|
-
mcpServers: [{ name: "unerr", command: "unerr", args: ["--mcp"] }],
|
|
284
|
-
}, null, 2)
|
|
285
|
-
.split("\n")
|
|
286
|
-
.join("\n ")}\n\n`);
|
|
287
|
-
}
|
|
288
|
-
else {
|
|
289
|
-
w(` ${JSON.stringify({ mcpServers: { unerr: { command: "unerr", args: ["--mcp"] } } }, null, 2)
|
|
290
|
-
.split("\n")
|
|
291
|
-
.join("\n ")}\n\n`);
|
|
292
|
-
}
|
|
293
|
-
// Step 2: Instruction file
|
|
294
|
-
if (agentDef.instructionFilePath) {
|
|
295
|
-
w(" \x1b[1m2. Tool Preferences\x1b[0m\n");
|
|
296
|
-
w(` ${generateCustomInstructions(agentDef.id).split("\n").join("\n ")}\n\n`);
|
|
297
|
-
}
|
|
298
|
-
// Step 3: Auto install
|
|
299
|
-
w(` \x1b[1m${agentDef.instructionFilePath ? "3" : "2"}. Or run automatically:\x1b[0m\n`);
|
|
300
|
-
w(` unerr install ${agentDef.id}\n\n`);
|
|
301
|
-
// Step 4: Restart
|
|
302
|
-
w(` \x1b[38;2;161;161;170mRestart ${agentDef.name} to pick up changes.\x1b[0m\n`);
|
|
303
|
-
}
|
|
304
|
-
else {
|
|
305
|
-
// Unknown/other agent — generic guide
|
|
306
|
-
w(" \x1b[38;2;139;92;246m◆\x1b[0m \x1b[1mManual setup for any AI coding agent\x1b[0m\n\n");
|
|
307
|
-
w(" unerr works with any agent that supports MCP (Model Context Protocol).\n\n");
|
|
308
|
-
w(" \x1b[1mStep 1: MCP Server Configuration\x1b[0m\n");
|
|
309
|
-
w(" \x1b[2m─────────────────────────────────\x1b[0m\n");
|
|
310
|
-
w(" Add unerr as an MCP server in your agent's config file.\n");
|
|
311
|
-
w(" The exact format depends on your agent:\n\n");
|
|
312
|
-
w(" Standard JSON format (most agents):\n");
|
|
313
|
-
w(` ${JSON.stringify({ mcpServers: { unerr: { command: "unerr", args: ["--mcp"] } } }, null, 2)
|
|
314
|
-
.split("\n")
|
|
315
|
-
.join("\n ")}\n\n`);
|
|
316
|
-
w(" \x1b[1mStep 2: Agent Instructions (Critical for Adoption)\x1b[0m\n");
|
|
317
|
-
w(" \x1b[2m───────────────────────────────────────────────────\x1b[0m\n");
|
|
318
|
-
w(" Add these instructions to your agent's instruction file\n");
|
|
319
|
-
w(" (CLAUDE.md, AGENTS.md, .cursorrules, GEMINI.md, etc.):\n\n");
|
|
320
|
-
w(` ${generateCustomInstructions().split("\n").join("\n ")}\n\n`);
|
|
321
|
-
w(" \x1b[1mStep 3: Verify\x1b[0m\n");
|
|
322
|
-
w(" \x1b[2m──────────────\x1b[0m\n");
|
|
323
|
-
w(" After restarting your agent, verify unerr tools are available.\n");
|
|
324
|
-
w(" You should see tools like: get_callers, search_code, file_read,\n");
|
|
325
|
-
w(" file_outline, get_imports, get_callees.\n\n");
|
|
326
|
-
w(" \x1b[1mStep 4: Start unerr\x1b[0m\n");
|
|
327
|
-
w(" \x1b[2m────────────────────\x1b[0m\n");
|
|
328
|
-
w(" Run \x1b[1munerr\x1b[0m in your project root to start the intelligence engine.\n");
|
|
329
|
-
w(" The MCP server will be available at \x1b[1munerr --mcp\x1b[0m.\n");
|
|
330
|
-
}
|
|
331
|
-
w("\n");
|
|
332
|
-
}
|
|
333
|
-
// ── Cursor Hook Scripts ──────────────────────────────────────────────
|
|
334
|
-
// These are written to .cursor/hooks/ by installCursorHooks().
|
|
335
|
-
// Each reads JSON from stdin and dispatches to the appropriate unerr hook subcommand.
|
|
336
|
-
const CURSOR_PRE_TOOL_SCRIPT = `#!/bin/bash
|
|
337
|
-
# unerr preToolUse hook for Cursor
|
|
338
|
-
# Installed by: unerr install cursor | Removed by: unerr uninstall cursor
|
|
339
|
-
input=$(cat)
|
|
340
|
-
tool_name=$(echo "$input" | jq -r '.tool_name // empty')
|
|
341
|
-
case "$tool_name" in
|
|
342
|
-
Read) echo "$input" | unerr hook pre-read ;;
|
|
343
|
-
Grep) echo "$input" | unerr hook pre-grep ;;
|
|
344
|
-
Glob) echo "$input" | unerr hook pre-glob ;;
|
|
345
|
-
Write) echo "$input" | unerr hook pre-write ;;
|
|
346
|
-
Edit) echo "$input" | unerr hook pre-edit ;;
|
|
347
|
-
*) echo '{"permission":"allow"}' ;;
|
|
348
|
-
esac
|
|
349
|
-
`;
|
|
350
|
-
const CURSOR_POST_TOOL_SCRIPT = `#!/bin/bash
|
|
351
|
-
# unerr postToolUse hook for Cursor
|
|
352
|
-
# Installed by: unerr install cursor | Removed by: unerr uninstall cursor
|
|
353
|
-
input=$(cat)
|
|
354
|
-
tool_name=$(echo "$input" | jq -r '.tool_name // empty')
|
|
355
|
-
case "$tool_name" in
|
|
356
|
-
Read) echo "$input" | unerr hook post-read ;;
|
|
357
|
-
Grep) echo "$input" | unerr hook post-grep ;;
|
|
358
|
-
Glob) echo "$input" | unerr hook post-glob ;;
|
|
359
|
-
Write) echo "$input" | unerr hook post-write ;;
|
|
360
|
-
Edit) echo "$input" | unerr hook post-edit ;;
|
|
361
|
-
*) echo '{}' ;;
|
|
362
|
-
esac
|
|
363
|
-
`;
|
|
364
|
-
const CURSOR_PROMPT_SCRIPT = `#!/bin/bash
|
|
365
|
-
# unerr beforeSubmitPrompt hook for Cursor
|
|
366
|
-
# Installed by: unerr install cursor | Removed by: unerr uninstall cursor
|
|
367
|
-
cat | unerr hook prompt-submit
|
|
368
|
-
`;
|
|
369
|
-
const CURSOR_PRE_SHELL_SCRIPT = `#!/bin/bash
|
|
370
|
-
# unerr beforeShellExecution hook for Cursor
|
|
371
|
-
# Installed by: unerr install cursor | Removed by: unerr uninstall cursor
|
|
372
|
-
# For v1, just allow — shell compression routes through PreToolUse/Bash/exec pipeline
|
|
373
|
-
cat > /dev/null
|
|
374
|
-
echo '{"permission":"allow"}'
|
|
375
|
-
`;
|
|
376
|
-
/**
|
|
377
|
-
* Install Cursor hook configuration in `.cursor/hooks.json`.
|
|
378
|
-
* Registers unerr as a hook provider for PreToolUse events.
|
|
379
|
-
* Idempotent — skips if already present.
|
|
380
|
-
*/
|
|
381
|
-
function installCursorHooks(cwd) {
|
|
382
|
-
const hooksJsonPath = join(cwd, ".cursor", "hooks.json");
|
|
383
|
-
const hooksDir = join(cwd, ".cursor", "hooks");
|
|
384
|
-
// Define our hook entries per Cursor's official format
|
|
385
|
-
const unerrHooks = {
|
|
386
|
-
preToolUse: [
|
|
387
|
-
{
|
|
388
|
-
command: ".cursor/hooks/unerr-pre-tool.sh",
|
|
389
|
-
matcher: "Read|Grep|Glob|Write|Edit",
|
|
390
|
-
},
|
|
391
|
-
],
|
|
392
|
-
postToolUse: [
|
|
393
|
-
{
|
|
394
|
-
command: ".cursor/hooks/unerr-post-tool.sh",
|
|
395
|
-
matcher: "Read|Grep|Glob|Write|Edit",
|
|
396
|
-
},
|
|
397
|
-
],
|
|
398
|
-
beforeSubmitPrompt: [{ command: ".cursor/hooks/unerr-prompt.sh" }],
|
|
399
|
-
beforeShellExecution: [{ command: ".cursor/hooks/unerr-pre-shell.sh" }],
|
|
400
|
-
};
|
|
401
|
-
try {
|
|
402
|
-
// Ensure directories exist
|
|
403
|
-
if (!existsSync(hooksDir)) {
|
|
404
|
-
mkdirSync(hooksDir, { recursive: true });
|
|
405
|
-
}
|
|
406
|
-
// Read or create hooks.json with correct Cursor format
|
|
407
|
-
let config = {
|
|
408
|
-
version: 1,
|
|
409
|
-
hooks: {},
|
|
410
|
-
};
|
|
411
|
-
if (existsSync(hooksJsonPath)) {
|
|
412
|
-
try {
|
|
413
|
-
const existing = JSON.parse(readFileSync(hooksJsonPath, "utf-8"));
|
|
414
|
-
if (existing.version && existing.hooks) {
|
|
415
|
-
config = existing;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
catch {
|
|
419
|
-
// Corrupt file — overwrite with fresh config
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
// Merge our hooks into each event, avoiding duplicates by command path
|
|
423
|
-
for (const [event, entries] of Object.entries(unerrHooks)) {
|
|
424
|
-
const existing = Array.isArray(config.hooks[event])
|
|
425
|
-
? config.hooks[event]
|
|
426
|
-
: [];
|
|
427
|
-
for (const entry of entries) {
|
|
428
|
-
const alreadyPresent = existing.some((h) => h.command === entry.command);
|
|
429
|
-
if (!alreadyPresent) {
|
|
430
|
-
existing.push(entry);
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
config.hooks[event] = existing;
|
|
434
|
-
}
|
|
435
|
-
writeFileSync(hooksJsonPath, `${JSON.stringify(config, null, 2)}\n`);
|
|
436
|
-
// Write hook scripts
|
|
437
|
-
writeCursorHookScript(hooksDir, "unerr-pre-tool.sh", CURSOR_PRE_TOOL_SCRIPT);
|
|
438
|
-
writeCursorHookScript(hooksDir, "unerr-post-tool.sh", CURSOR_POST_TOOL_SCRIPT);
|
|
439
|
-
writeCursorHookScript(hooksDir, "unerr-prompt.sh", CURSOR_PROMPT_SCRIPT);
|
|
440
|
-
writeCursorHookScript(hooksDir, "unerr-pre-shell.sh", CURSOR_PRE_SHELL_SCRIPT);
|
|
441
|
-
return true;
|
|
442
|
-
}
|
|
443
|
-
catch {
|
|
444
|
-
return false;
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
/** Write a hook script file and make it executable. */
|
|
448
|
-
function writeCursorHookScript(dir, filename, content) {
|
|
449
|
-
const scriptPath = join(dir, filename);
|
|
450
|
-
writeFileSync(scriptPath, content, "utf-8");
|
|
451
|
-
chmodSync(scriptPath, 0o755);
|
|
452
|
-
}
|
|
453
|
-
/**
|
|
454
|
-
* Install Cline hook scripts in `.clinerules/hooks/`.
|
|
455
|
-
* Creates a pre-tool hook script that routes through unerr.
|
|
456
|
-
* Idempotent — skips if already present.
|
|
457
|
-
*/
|
|
458
|
-
function installClineHooks(cwd) {
|
|
459
|
-
const hooksDir = join(cwd, ".clinerules", "hooks");
|
|
460
|
-
const hookPath = join(hooksDir, "unerr-pre-tool.sh");
|
|
461
|
-
if (existsSync(hookPath))
|
|
462
|
-
return true;
|
|
463
|
-
try {
|
|
464
|
-
if (!existsSync(hooksDir)) {
|
|
465
|
-
const { mkdirSync } = require("node:fs");
|
|
466
|
-
mkdirSync(hooksDir, { recursive: true });
|
|
467
|
-
}
|
|
468
|
-
const hookContent = `#!/bin/bash
|
|
469
|
-
# unerr hook — graph-first tool navigation for Cline
|
|
470
|
-
# Installed by: unerr install cline
|
|
471
|
-
# Removed by: unerr uninstall cline
|
|
472
|
-
cat /dev/stdin | unerr hook pre-read
|
|
473
|
-
`;
|
|
474
|
-
writeFileSync(hookPath, hookContent, "utf-8");
|
|
475
|
-
chmodSync(hookPath, 0o755);
|
|
476
|
-
return true;
|
|
477
|
-
}
|
|
478
|
-
catch {
|
|
479
|
-
return false;
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
/**
|
|
483
|
-
* Ensure .unerr is listed in .gitignore so artifacts don't get committed.
|
|
484
|
-
* Only modifies .gitignore if it exists and doesn't already contain .unerr.
|
|
485
|
-
*/
|
|
486
|
-
function ensureGitignore(cwd) {
|
|
487
|
-
const gitignorePath = join(cwd, ".gitignore");
|
|
488
|
-
if (!existsSync(gitignorePath))
|
|
489
|
-
return false;
|
|
490
|
-
try {
|
|
491
|
-
const content = readFileSync(gitignorePath, "utf-8");
|
|
492
|
-
const lines = content.split("\n");
|
|
493
|
-
// Check if .unerr is already ignored (exact line match)
|
|
494
|
-
if (lines.some((l) => l.trim() === ".unerr" || l.trim() === ".unerr/")) {
|
|
495
|
-
return false;
|
|
496
|
-
}
|
|
497
|
-
// Append .unerr entry
|
|
498
|
-
const newline = content.endsWith("\n") ? "" : "\n";
|
|
499
|
-
writeFileSync(gitignorePath, `${content}${newline}\n# unerr local artifacts\n.unerr\n`);
|
|
500
|
-
return true;
|
|
501
|
-
}
|
|
502
|
-
catch {
|
|
503
|
-
return false;
|
|
504
|
-
}
|
|
505
|
-
}
|
package/dist/commands/learn.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* unerr learn — Run correction detector on shadow ledger entries.
|
|
3
|
-
*
|
|
4
|
-
* Scans the shadow ledger for error→fix correction pairs and displays
|
|
5
|
-
* detected patterns. With --write, persists patterns to CozoDB for
|
|
6
|
-
* injection into future MCP responses.
|
|
7
|
-
*
|
|
8
|
-
* Leapfrog Sprint B, Task B.4
|
|
9
|
-
*
|
|
10
|
-
* Usage:
|
|
11
|
-
* unerr learn — Detect and display patterns (last 7 days)
|
|
12
|
-
* unerr learn --write — Detect and persist to CozoDB
|
|
13
|
-
* unerr learn --days 30 — Scan last 30 days
|
|
14
|
-
* unerr learn --json — Output as JSON
|
|
15
|
-
* unerr learn --min-conf 0.8 — Only show high-confidence patterns
|
|
16
|
-
*/
|
|
17
|
-
import { existsSync } from "node:fs";
|
|
18
|
-
import { join } from "node:path";
|
|
19
|
-
import { gunzipSync } from "node:zlib";
|
|
20
|
-
import pc from "picocolors";
|
|
21
|
-
import { detectCorrections } from "../tracking/correction-detector.js";
|
|
22
|
-
import { detail, fail, info, section, success, warn } from "../utils/ui.js";
|
|
23
|
-
export function registerLearnCommand(program) {
|
|
24
|
-
program
|
|
25
|
-
.command("learn")
|
|
26
|
-
.description("Detect correction patterns from shadow ledger — learn what mistakes agents keep making")
|
|
27
|
-
.option("--days <n>", "Scan last N days of ledger", "7")
|
|
28
|
-
.option("--write", "Persist detected patterns to CozoDB for agent guidance")
|
|
29
|
-
.option("--json", "Output as JSON")
|
|
30
|
-
.option("--min-conf <f>", "Minimum confidence threshold (0.0-1.0)", "0.6")
|
|
31
|
-
.action(async (opts) => {
|
|
32
|
-
const days = Math.max(1, Number.parseInt(opts.days, 10) || 7);
|
|
33
|
-
const minConf = Math.max(0, Math.min(1, Number.parseFloat(opts.minConf) || 0.6));
|
|
34
|
-
const cwd = process.cwd();
|
|
35
|
-
const unerrDir = join(cwd, ".unerr");
|
|
36
|
-
const ledgerPath = join(unerrDir, "ledger", "shadow.jsonl");
|
|
37
|
-
if (!existsSync(ledgerPath)) {
|
|
38
|
-
fail("No shadow ledger found at .unerr/ledger/shadow.jsonl");
|
|
39
|
-
info("The shadow ledger is created when the unerr proxy runs. Start the proxy first.");
|
|
40
|
-
process.exit(1);
|
|
41
|
-
}
|
|
42
|
-
section("Correction Detection");
|
|
43
|
-
info(`Scanning last ${days} days of shadow ledger...`);
|
|
44
|
-
const patterns = detectCorrections(ledgerPath, {
|
|
45
|
-
since_days: days,
|
|
46
|
-
min_confidence: minConf,
|
|
47
|
-
});
|
|
48
|
-
if (patterns.length === 0) {
|
|
49
|
-
info(`No correction patterns found in last ${days} days (threshold: ${minConf})`);
|
|
50
|
-
process.exit(0);
|
|
51
|
-
}
|
|
52
|
-
if (opts.json) {
|
|
53
|
-
process.stdout.write(`${JSON.stringify(patterns, null, 2)}\n`);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
success(`Detected ${patterns.length} correction pattern${patterns.length !== 1 ? "s" : ""}:`);
|
|
57
|
-
process.stderr.write("\n");
|
|
58
|
-
for (let i = 0; i < patterns.length; i++) {
|
|
59
|
-
const p = patterns[i];
|
|
60
|
-
const name = p.entity_key.split("/").pop()?.split(":").pop() ?? p.entity_key;
|
|
61
|
-
process.stderr.write(` ${pc.bold(`${i + 1}.`)} ${pc.cyan(name)} ${pc.dim(`(${p.error_type})`)} — confidence: ${pc.yellow(String(p.confidence))}, seen ${pc.bold(String(p.occurrences))}x\n`);
|
|
62
|
-
process.stderr.write(` ${pc.dim(p.correction_summary)}\n`);
|
|
63
|
-
process.stderr.write(` ${pc.dim(`Last seen: ${p.last_seen.slice(0, 16).replace("T", " ")}`)}\n`);
|
|
64
|
-
process.stderr.write("\n");
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
if (opts.write) {
|
|
68
|
-
await persistPatterns(patterns, unerrDir);
|
|
69
|
-
}
|
|
70
|
-
else if (!opts.json) {
|
|
71
|
-
detail("Run with --write to persist these patterns for agent guidance.");
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
async function persistPatterns(patterns, _unerrDir) {
|
|
76
|
-
try {
|
|
77
|
-
const cwd = process.cwd();
|
|
78
|
-
// Find snapshot to initialize CozoDB
|
|
79
|
-
const configPath = join(cwd, ".unerr", "config.json");
|
|
80
|
-
if (!existsSync(configPath)) {
|
|
81
|
-
warn("No repo config found — cannot persist to CozoDB. Run 'unerr' to configure.");
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
const { readFileSync } = await import("node:fs");
|
|
85
|
-
const config = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
86
|
-
if (!config.repoId || !config.orgId) {
|
|
87
|
-
warn("Repo not configured — cannot persist to CozoDB.");
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
const snapshotPath = join(cwd, ".unerr", "snapshots", "graph.msgpack.gz");
|
|
91
|
-
if (!existsSync(snapshotPath)) {
|
|
92
|
-
warn("No graph snapshot found — cannot persist to CozoDB.");
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
// Dynamic imports for heavy modules
|
|
96
|
-
const cozoModule = await import("cozo-node");
|
|
97
|
-
const CozoDbClass = cozoModule.default
|
|
98
|
-
? cozoModule.default.CozoDb
|
|
99
|
-
: cozoModule.CozoDb;
|
|
100
|
-
const db = new CozoDbClass();
|
|
101
|
-
const { initSchema } = await import("../intelligence/cozo-schema.js");
|
|
102
|
-
initSchema(db);
|
|
103
|
-
const { CozoGraphStore } = await import("../intelligence/local-graph.js");
|
|
104
|
-
const store = await CozoGraphStore.create(db);
|
|
105
|
-
const { unpack } = await import("msgpackr");
|
|
106
|
-
const raw = readFileSync(snapshotPath);
|
|
107
|
-
const buffer = gunzipSync(raw);
|
|
108
|
-
const envelope = unpack(buffer);
|
|
109
|
-
await store.loadSnapshot(envelope);
|
|
110
|
-
store.persistCorrections(patterns);
|
|
111
|
-
success(`Persisted ${patterns.length} correction pattern${patterns.length !== 1 ? "s" : ""} to CozoDB`);
|
|
112
|
-
}
|
|
113
|
-
catch (err) {
|
|
114
|
-
warn(`Failed to persist corrections: ${err instanceof Error ? err.message : String(err)}`);
|
|
115
|
-
}
|
|
116
|
-
}
|