@unerr-ai/unerr 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/cli.js +37236 -35793
- package/package.json +1 -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,162 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Grep Tool — search file contents using regex patterns.
|
|
3
|
-
* Uses Node.js built-in fs for portability (no ripgrep dependency).
|
|
4
|
-
*/
|
|
5
|
-
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
6
|
-
import { join, relative, resolve } from "node:path";
|
|
7
|
-
const MAX_RESULTS = 200;
|
|
8
|
-
const MAX_DEPTH = 10;
|
|
9
|
-
const BINARY_EXTENSIONS = new Set([
|
|
10
|
-
".png",
|
|
11
|
-
".jpg",
|
|
12
|
-
".jpeg",
|
|
13
|
-
".gif",
|
|
14
|
-
".ico",
|
|
15
|
-
".svg",
|
|
16
|
-
".woff",
|
|
17
|
-
".woff2",
|
|
18
|
-
".ttf",
|
|
19
|
-
".eot",
|
|
20
|
-
".mp3",
|
|
21
|
-
".mp4",
|
|
22
|
-
".zip",
|
|
23
|
-
".tar",
|
|
24
|
-
".gz",
|
|
25
|
-
".pdf",
|
|
26
|
-
".exe",
|
|
27
|
-
".dll",
|
|
28
|
-
".so",
|
|
29
|
-
".dylib",
|
|
30
|
-
".node",
|
|
31
|
-
".wasm",
|
|
32
|
-
]);
|
|
33
|
-
const SKIP_DIRS = new Set([
|
|
34
|
-
"node_modules",
|
|
35
|
-
".git",
|
|
36
|
-
"dist",
|
|
37
|
-
"build",
|
|
38
|
-
".next",
|
|
39
|
-
"coverage",
|
|
40
|
-
"__pycache__",
|
|
41
|
-
]);
|
|
42
|
-
function walkFiles(dir, depth, glob) {
|
|
43
|
-
if (depth > MAX_DEPTH)
|
|
44
|
-
return [];
|
|
45
|
-
const files = [];
|
|
46
|
-
try {
|
|
47
|
-
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
48
|
-
if (entry.name.startsWith(".") && SKIP_DIRS.has(entry.name))
|
|
49
|
-
continue;
|
|
50
|
-
if (SKIP_DIRS.has(entry.name))
|
|
51
|
-
continue;
|
|
52
|
-
const full = join(dir, entry.name);
|
|
53
|
-
if (entry.isDirectory()) {
|
|
54
|
-
files.push(...walkFiles(full, depth + 1, glob));
|
|
55
|
-
}
|
|
56
|
-
else if (entry.isFile()) {
|
|
57
|
-
const ext = entry.name.slice(entry.name.lastIndexOf("."));
|
|
58
|
-
if (BINARY_EXTENSIONS.has(ext))
|
|
59
|
-
continue;
|
|
60
|
-
if (glob && !matchGlob(entry.name, glob))
|
|
61
|
-
continue;
|
|
62
|
-
files.push(full);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
catch {
|
|
67
|
-
// Permission denied, etc.
|
|
68
|
-
}
|
|
69
|
-
return files;
|
|
70
|
-
}
|
|
71
|
-
function matchGlob(filename, pattern) {
|
|
72
|
-
// Simple glob: *.ts, *.{ts,tsx}, etc.
|
|
73
|
-
const regex = pattern
|
|
74
|
-
.replace(/\./g, "\\.")
|
|
75
|
-
.replace(/\*/g, ".*")
|
|
76
|
-
.replace(/\{([^}]+)\}/g, (_, alts) => `(${alts.split(",").join("|")})`);
|
|
77
|
-
return new RegExp(`^${regex}$`).test(filename);
|
|
78
|
-
}
|
|
79
|
-
export const grepTool = {
|
|
80
|
-
name: "grep",
|
|
81
|
-
description: "Search file contents for a regex pattern. Returns matching lines with file paths and line numbers. " +
|
|
82
|
-
"Use the glob parameter to filter by file type (e.g., '*.ts', '*.{ts,tsx}').",
|
|
83
|
-
inputSchema: {
|
|
84
|
-
type: "object",
|
|
85
|
-
properties: {
|
|
86
|
-
pattern: {
|
|
87
|
-
type: "string",
|
|
88
|
-
description: "Regular expression pattern to search for",
|
|
89
|
-
},
|
|
90
|
-
path: {
|
|
91
|
-
type: "string",
|
|
92
|
-
description: "Directory or file to search in. Default: project root",
|
|
93
|
-
},
|
|
94
|
-
glob: {
|
|
95
|
-
type: "string",
|
|
96
|
-
description: "Glob pattern to filter files (e.g., '*.ts')",
|
|
97
|
-
},
|
|
98
|
-
case_insensitive: {
|
|
99
|
-
type: "boolean",
|
|
100
|
-
description: "Case insensitive search. Default: false",
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
required: ["pattern"],
|
|
104
|
-
},
|
|
105
|
-
isReadOnly: true,
|
|
106
|
-
requiresPermission: false,
|
|
107
|
-
async execute(args, ctx) {
|
|
108
|
-
const pattern = args.pattern;
|
|
109
|
-
const searchPath = resolve(ctx.cwd, args.path ?? ".");
|
|
110
|
-
const glob = args.glob;
|
|
111
|
-
const caseInsensitive = args.case_insensitive ?? false;
|
|
112
|
-
let regex;
|
|
113
|
-
try {
|
|
114
|
-
regex = new RegExp(pattern, caseInsensitive ? "gi" : "g");
|
|
115
|
-
}
|
|
116
|
-
catch (err) {
|
|
117
|
-
return {
|
|
118
|
-
content: `Invalid regex: ${pattern}. Check pattern escaping. For matching code entity names, call search_code instead — it handles identifiers natively without regex.`,
|
|
119
|
-
isError: true,
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
if (!existsSync(searchPath)) {
|
|
123
|
-
return {
|
|
124
|
-
content: `Path not found: ${searchPath}. For code searches, call search_code (entity-aware, no path required) instead.`,
|
|
125
|
-
isError: true,
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
const stat = statSync(searchPath);
|
|
129
|
-
const files = stat.isFile() ? [searchPath] : walkFiles(searchPath, 0, glob);
|
|
130
|
-
const matches = [];
|
|
131
|
-
for (const file of files) {
|
|
132
|
-
if (matches.length >= MAX_RESULTS)
|
|
133
|
-
break;
|
|
134
|
-
try {
|
|
135
|
-
const content = readFileSync(file, "utf-8");
|
|
136
|
-
const lines = content.split("\n");
|
|
137
|
-
for (let i = 0; i < lines.length; i++) {
|
|
138
|
-
if (matches.length >= MAX_RESULTS)
|
|
139
|
-
break;
|
|
140
|
-
const line = lines[i];
|
|
141
|
-
if (regex.test(line)) {
|
|
142
|
-
const relPath = relative(ctx.cwd, file);
|
|
143
|
-
matches.push(`${relPath}:${i + 1}: ${line}`);
|
|
144
|
-
}
|
|
145
|
-
regex.lastIndex = 0; // Reset global regex
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
catch {
|
|
149
|
-
// Binary file or read error — skip
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
if (matches.length === 0) {
|
|
153
|
-
return {
|
|
154
|
-
content: `No matches found for pattern: ${pattern}. If you were searching for a code entity by name, call search_code (graph-indexed, finds renames + indirect refs that regex misses).`,
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
const truncated = matches.length >= MAX_RESULTS
|
|
158
|
-
? `\n\n(Truncated at ${MAX_RESULTS} results)`
|
|
159
|
-
: "";
|
|
160
|
-
return { content: matches.join("\n") + truncated };
|
|
161
|
-
},
|
|
162
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Coding Tools — standard filesystem and shell tools for the AI assistant.
|
|
3
|
-
*/
|
|
4
|
-
export { bashTool } from "./bash.js";
|
|
5
|
-
export { fileEditTool } from "./file-edit.js";
|
|
6
|
-
export { fileOutlineTool } from "./file-outline.js";
|
|
7
|
-
export { fileReadTool } from "./file-read.js";
|
|
8
|
-
export { fileWriteTool } from "./file-write.js";
|
|
9
|
-
export { globTool } from "./glob-tool.js";
|
|
10
|
-
export { grepTool } from "./grep.js";
|
|
11
|
-
import { bashTool } from "./bash.js";
|
|
12
|
-
import { fileEditTool } from "./file-edit.js";
|
|
13
|
-
import { fileOutlineTool } from "./file-outline.js";
|
|
14
|
-
import { fileReadTool } from "./file-read.js";
|
|
15
|
-
import { fileWriteTool } from "./file-write.js";
|
|
16
|
-
import { globTool } from "./glob-tool.js";
|
|
17
|
-
import { grepTool } from "./grep.js";
|
|
18
|
-
/** All coding tools in registration order. */
|
|
19
|
-
export const codingTools = [
|
|
20
|
-
fileOutlineTool,
|
|
21
|
-
fileReadTool,
|
|
22
|
-
fileWriteTool,
|
|
23
|
-
fileEditTool,
|
|
24
|
-
bashTool,
|
|
25
|
-
grepTool,
|
|
26
|
-
globTool,
|
|
27
|
-
];
|
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Intelligence Tools — wrappers around the QueryRouter's 15 MCP tools.
|
|
3
|
-
*
|
|
4
|
-
* These adapt the existing graph-backed tools so they can be used by the QueryEngine
|
|
5
|
-
* (the LLM calls them during interactive sessions). The QueryRouter handles all the
|
|
6
|
-
* local routing, drift injection, and rule evaluation internally.
|
|
7
|
-
*
|
|
8
|
-
* This is the key differentiator: no other coding assistant has pre-computed
|
|
9
|
-
* code intelligence (conventions, blast radius, business context, health grades)
|
|
10
|
-
* available as tools.
|
|
11
|
-
*/
|
|
12
|
-
// Leapfrog Sprint C: token_budget property shared across all local tools
|
|
13
|
-
const TOKEN_BUDGET_PROP = {
|
|
14
|
-
type: "integer",
|
|
15
|
-
description: "Maximum tokens for this response (default: 400 — structural summary only). Pass include_body:true OR token_budget:1500+ to retrieve full bodies. Most fan-in/metadata questions fit in 400 tokens.",
|
|
16
|
-
default: 400,
|
|
17
|
-
};
|
|
18
|
-
/** Tool definition metadata for each intelligence tool. */
|
|
19
|
-
const TOOL_DEFS = [
|
|
20
|
-
{
|
|
21
|
-
name: "get_entity",
|
|
22
|
-
description: "Get any code entity (function, class, type, variable) by key — signature, metadata, callers, callees, risk level. Returns STRUCTURAL by default; pass include_body:true for full body.",
|
|
23
|
-
inputSchema: {
|
|
24
|
-
type: "object",
|
|
25
|
-
properties: {
|
|
26
|
-
key: {
|
|
27
|
-
type: "string",
|
|
28
|
-
description: "Entity key (e.g., 'handleRequest', 'QueryRouter')",
|
|
29
|
-
},
|
|
30
|
-
kind: {
|
|
31
|
-
type: "string",
|
|
32
|
-
enum: ["function", "class", "type", "variable"],
|
|
33
|
-
description: "Optional entity kind filter",
|
|
34
|
-
},
|
|
35
|
-
include_body: {
|
|
36
|
-
type: "boolean",
|
|
37
|
-
description: "Include full body. Default false — signature + first ~15 lines preview only.",
|
|
38
|
-
default: false,
|
|
39
|
-
},
|
|
40
|
-
token_budget: TOKEN_BUDGET_PROP,
|
|
41
|
-
},
|
|
42
|
-
required: ["key"],
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
name: "get_file",
|
|
47
|
-
description: "Get all entities defined in a file",
|
|
48
|
-
inputSchema: {
|
|
49
|
-
type: "object",
|
|
50
|
-
properties: {
|
|
51
|
-
file_path: {
|
|
52
|
-
type: "string",
|
|
53
|
-
description: "File path relative to project root",
|
|
54
|
-
},
|
|
55
|
-
token_budget: TOKEN_BUDGET_PROP,
|
|
56
|
-
},
|
|
57
|
-
required: ["file_path"],
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
name: "get_references",
|
|
62
|
-
description: "Find all callers or callees of a given entity. Direction 'callers' = who calls this (blast radius). Direction 'callees' = what this calls (dependencies).",
|
|
63
|
-
inputSchema: {
|
|
64
|
-
type: "object",
|
|
65
|
-
properties: {
|
|
66
|
-
key: {
|
|
67
|
-
type: "string",
|
|
68
|
-
description: "Entity key to find references for",
|
|
69
|
-
},
|
|
70
|
-
direction: {
|
|
71
|
-
type: "string",
|
|
72
|
-
enum: ["callers", "callees"],
|
|
73
|
-
description: "Direction: 'callers' (default) or 'callees'",
|
|
74
|
-
},
|
|
75
|
-
limit: {
|
|
76
|
-
type: "number",
|
|
77
|
-
description: "Max references to return (default 25)",
|
|
78
|
-
},
|
|
79
|
-
token_budget: TOKEN_BUDGET_PROP,
|
|
80
|
-
},
|
|
81
|
-
required: ["key"],
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
name: "get_imports",
|
|
86
|
-
description: "Get all imports for a file",
|
|
87
|
-
inputSchema: {
|
|
88
|
-
type: "object",
|
|
89
|
-
properties: {
|
|
90
|
-
file_path: { type: "string", description: "File path" },
|
|
91
|
-
token_budget: TOKEN_BUDGET_PROP,
|
|
92
|
-
},
|
|
93
|
-
required: ["file_path"],
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
name: "search_code",
|
|
98
|
-
description: "Full-text search across all indexed code entities (functions, classes, variables). Returns matching entities with file paths and signatures.",
|
|
99
|
-
inputSchema: {
|
|
100
|
-
type: "object",
|
|
101
|
-
properties: {
|
|
102
|
-
query: { type: "string", description: "Search query" },
|
|
103
|
-
limit: { type: "number", description: "Max results. Default: 20" },
|
|
104
|
-
token_budget: TOKEN_BUDGET_PROP,
|
|
105
|
-
},
|
|
106
|
-
required: ["query"],
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
// Disabled: get_rules — no rules are being detected/stored yet, always returns empty.
|
|
110
|
-
// {
|
|
111
|
-
// name: "get_rules",
|
|
112
|
-
// inputSchema: { type: "object", properties: { file_path: { type: "string" }, content: { type: "string" }, entity_key: { type: "string" }, token_budget: TOKEN_BUDGET_PROP }, },
|
|
113
|
-
// },
|
|
114
|
-
// Disabled: get_business_context — not properly wired, produces no useful data.
|
|
115
|
-
// {
|
|
116
|
-
// name: "get_business_context",
|
|
117
|
-
// description: "Get entity business context — purpose, taxonomy, feature area, justification for why this code exists",
|
|
118
|
-
// inputSchema: { type: "object", properties: { key: { type: "string" }, token_budget: TOKEN_BUDGET_PROP }, required: ["key"] },
|
|
119
|
-
// },
|
|
120
|
-
{
|
|
121
|
-
name: "get_conventions",
|
|
122
|
-
description: "Get detected code conventions and patterns with adherence rates. Shows what patterns the team follows.",
|
|
123
|
-
inputSchema: {
|
|
124
|
-
type: "object",
|
|
125
|
-
properties: {
|
|
126
|
-
token_budget: TOKEN_BUDGET_PROP,
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
name: "get_cross_boundary_links",
|
|
132
|
-
description: "Find surprising cross-community connections — edges between entities in different structural communities, scored by inverse inter-community density. High surprise = unexpected architectural coupling.",
|
|
133
|
-
inputSchema: {
|
|
134
|
-
type: "object",
|
|
135
|
-
properties: {
|
|
136
|
-
community_id: {
|
|
137
|
-
type: "number",
|
|
138
|
-
description: "Optional: filter to connections involving this community ID",
|
|
139
|
-
},
|
|
140
|
-
top_n: {
|
|
141
|
-
type: "number",
|
|
142
|
-
description: "Max results. Default: 20",
|
|
143
|
-
},
|
|
144
|
-
token_budget: TOKEN_BUDGET_PROP,
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
name: "get_critical_nodes",
|
|
150
|
-
description: "Find critical nodes — highest-degree entities (fan_in + fan_out) that are structural bottlenecks. Excludes file/module-level entities. Shows community membership for each node.",
|
|
151
|
-
inputSchema: {
|
|
152
|
-
type: "object",
|
|
153
|
-
properties: {
|
|
154
|
-
top_n: {
|
|
155
|
-
type: "number",
|
|
156
|
-
description: "Max results. Default: 10",
|
|
157
|
-
},
|
|
158
|
-
community_id: {
|
|
159
|
-
type: "number",
|
|
160
|
-
description: "Optional: filter to entities in this community",
|
|
161
|
-
},
|
|
162
|
-
token_budget: TOKEN_BUDGET_PROP,
|
|
163
|
-
},
|
|
164
|
-
},
|
|
165
|
-
},
|
|
166
|
-
{
|
|
167
|
-
name: "semantic_search",
|
|
168
|
-
description: "Vector-based semantic search across the codebase. Finds conceptually similar code even with different naming.",
|
|
169
|
-
inputSchema: {
|
|
170
|
-
type: "object",
|
|
171
|
-
properties: {
|
|
172
|
-
query: { type: "string", description: "Natural language search query" },
|
|
173
|
-
limit: { type: "number", description: "Max results. Default: 10" },
|
|
174
|
-
},
|
|
175
|
-
required: ["query"],
|
|
176
|
-
},
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
name: "find_similar",
|
|
180
|
-
description: "Find entities similar to a given entity (by embedding distance)",
|
|
181
|
-
inputSchema: {
|
|
182
|
-
type: "object",
|
|
183
|
-
properties: {
|
|
184
|
-
key: {
|
|
185
|
-
type: "string",
|
|
186
|
-
description: "Entity key to find similar entities for",
|
|
187
|
-
},
|
|
188
|
-
limit: { type: "number", description: "Max results. Default: 10" },
|
|
189
|
-
},
|
|
190
|
-
required: ["key"],
|
|
191
|
-
},
|
|
192
|
-
},
|
|
193
|
-
{
|
|
194
|
-
name: "get_project_stats",
|
|
195
|
-
description: "Get project-wide statistics: entity counts, risk distribution, convention adherence, health grade",
|
|
196
|
-
inputSchema: {
|
|
197
|
-
type: "object",
|
|
198
|
-
properties: {},
|
|
199
|
-
},
|
|
200
|
-
},
|
|
201
|
-
{
|
|
202
|
-
name: "file_connections",
|
|
203
|
-
description: "Get connected files and contained entities for a file. Shows import relationships, co-change correlations, and file-level structure.",
|
|
204
|
-
inputSchema: {
|
|
205
|
-
type: "object",
|
|
206
|
-
properties: {
|
|
207
|
-
file_path: {
|
|
208
|
-
type: "string",
|
|
209
|
-
description: "File path relative to project root",
|
|
210
|
-
},
|
|
211
|
-
token_budget: TOKEN_BUDGET_PROP,
|
|
212
|
-
},
|
|
213
|
-
required: ["file_path"],
|
|
214
|
-
},
|
|
215
|
-
},
|
|
216
|
-
{
|
|
217
|
-
name: "get_test_coverage",
|
|
218
|
-
description: "Find test functions that cover a source entity. Returns direct and transitive test coverage via 'tests' edges in the graph.",
|
|
219
|
-
inputSchema: {
|
|
220
|
-
type: "object",
|
|
221
|
-
properties: {
|
|
222
|
-
key: {
|
|
223
|
-
type: "string",
|
|
224
|
-
description: "Source entity key to find test coverage for",
|
|
225
|
-
},
|
|
226
|
-
include_transitive: {
|
|
227
|
-
type: "boolean",
|
|
228
|
-
description: "Include tests that cover via intermediate calls (default: true)",
|
|
229
|
-
},
|
|
230
|
-
token_budget: TOKEN_BUDGET_PROP,
|
|
231
|
-
},
|
|
232
|
-
required: ["key"],
|
|
233
|
-
},
|
|
234
|
-
},
|
|
235
|
-
];
|
|
236
|
-
/**
|
|
237
|
-
* Create intelligence Tool instances backed by a QueryRouter.
|
|
238
|
-
* Each tool delegates to router.execute() which handles local routing,
|
|
239
|
-
* drift injection, risk metadata, and rule evaluation.
|
|
240
|
-
*/
|
|
241
|
-
export function createIntelligenceTools(router) {
|
|
242
|
-
return TOOL_DEFS.map((def) => ({
|
|
243
|
-
...def,
|
|
244
|
-
isReadOnly: true,
|
|
245
|
-
requiresPermission: false,
|
|
246
|
-
async execute(args, _ctx) {
|
|
247
|
-
try {
|
|
248
|
-
const result = await router.execute(def.name, args);
|
|
249
|
-
return {
|
|
250
|
-
content: typeof result.content === "string"
|
|
251
|
-
? result.content
|
|
252
|
-
: result.content,
|
|
253
|
-
metadata: {
|
|
254
|
-
source: result._meta.source,
|
|
255
|
-
latency_ms: result._meta.latency_ms,
|
|
256
|
-
entity_risk: result._meta.entity_risk,
|
|
257
|
-
drift: result._meta.drift,
|
|
258
|
-
},
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
catch (err) {
|
|
262
|
-
return {
|
|
263
|
-
content: `Intelligence tool error (${def.name}): ${err instanceof Error ? err.message : String(err)}`,
|
|
264
|
-
isError: true,
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
},
|
|
268
|
-
}));
|
|
269
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* record_fact MCP Tool — Agent-as-LLM fact persistence.
|
|
3
|
-
*
|
|
4
|
-
* Layer 9: The host coding agent (Claude, GPT, etc.) calls this tool when
|
|
5
|
-
* the user states a convention, decision, or anti-pattern. The agent IS
|
|
6
|
-
* the LLM — no separate extraction model needed.
|
|
7
|
-
*
|
|
8
|
-
* This is the ONLY write operation --mcp performs on facts.db.
|
|
9
|
-
* It's a single atomic insert — no lock contention risk.
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* Execute the record_fact tool.
|
|
13
|
-
* Validates input, deduplicates, and persists to facts.db.
|
|
14
|
-
*/
|
|
15
|
-
export async function executeRecordFact(args, factStore, sessionId) {
|
|
16
|
-
const { content, fact_type, scope, subject } = args;
|
|
17
|
-
if (!content || content.trim().length === 0) {
|
|
18
|
-
throw new Error("content is required and cannot be empty");
|
|
19
|
-
}
|
|
20
|
-
if (content.length > 280) {
|
|
21
|
-
throw new Error(`content exceeds 280 character limit (got ${content.length}). Shorten the fact.`);
|
|
22
|
-
}
|
|
23
|
-
if (!["procedural", "semantic", "negative", "convention"].includes(fact_type)) {
|
|
24
|
-
throw new Error(`fact_type must be one of: procedural, semantic, negative, convention (got "${fact_type}")`);
|
|
25
|
-
}
|
|
26
|
-
if (!scope || scope.trim().length === 0) {
|
|
27
|
-
throw new Error("scope is required (file path, entity key, or 'project')");
|
|
28
|
-
}
|
|
29
|
-
if (!subject || subject.trim().length === 0) {
|
|
30
|
-
throw new Error("subject is required (entity key, file, or topic name)");
|
|
31
|
-
}
|
|
32
|
-
const input = {
|
|
33
|
-
fact_type,
|
|
34
|
-
scope: scope.trim(),
|
|
35
|
-
subject: subject.trim(),
|
|
36
|
-
content: content.trim(),
|
|
37
|
-
source: "agent_explicit",
|
|
38
|
-
base_confidence: 0.95,
|
|
39
|
-
};
|
|
40
|
-
const factId = await factStore.createFact(input);
|
|
41
|
-
const isDeduplicated = factId !== undefined && content.trim() !== "";
|
|
42
|
-
const message = `Recorded: "${content.trim().slice(0, 60)}${content.trim().length > 60 ? "..." : ""}" [${fact_type}] → ${scope}`;
|
|
43
|
-
return {
|
|
44
|
-
fact_id: factId,
|
|
45
|
-
message,
|
|
46
|
-
deduplicated: false,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Timeline marker MCP tools (ST-2a).
|
|
3
|
-
*
|
|
4
|
-
* Four lightweight tools the agent emits inline as it works. Each call:
|
|
5
|
-
* 1. Appends a regular `LedgerEntry` via `ShadowLedger.record()` with
|
|
6
|
-
* `tool: "mark_*"` — existing readers see it as a normal MCP call.
|
|
7
|
-
* 2. Mirrors a row into `timeline.db.markers` for indexed lookup
|
|
8
|
-
* (open-threads, intent rail, future miners).
|
|
9
|
-
*
|
|
10
|
-
* Layer 9 modules (`session-narrative`, `session-pattern-analyzer`,
|
|
11
|
-
* `fact-generator`, `temporal-facts`) are NOT touched. They remain agnostic to
|
|
12
|
-
* markers — if Layer 9 wants to prefer marker `text` over its scraped 30 s
|
|
13
|
-
* window later, that's a separate change owned by Layer 9.
|
|
14
|
-
*
|
|
15
|
-
* Text caps:
|
|
16
|
-
* mark_intent ≤ 80 chars
|
|
17
|
-
* mark_decision ≤ 140 chars
|
|
18
|
-
* mark_blocker ≤ 140 chars
|
|
19
|
-
* mark_resolution ≤ 140 chars
|
|
20
|
-
*/
|
|
21
|
-
export const MARKER_TOOLS = [
|
|
22
|
-
"mark_intent",
|
|
23
|
-
"mark_decision",
|
|
24
|
-
"mark_blocker",
|
|
25
|
-
"mark_resolution",
|
|
26
|
-
];
|
|
27
|
-
const MARKER_TOOL_SET = new Set(MARKER_TOOLS);
|
|
28
|
-
export function isMarkerTool(name) {
|
|
29
|
-
return MARKER_TOOL_SET.has(name);
|
|
30
|
-
}
|
|
31
|
-
const TEXT_CAP = {
|
|
32
|
-
mark_intent: 80,
|
|
33
|
-
mark_decision: 140,
|
|
34
|
-
mark_blocker: 140,
|
|
35
|
-
mark_resolution: 140,
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Dispatch a marker tool call. Returns an MCP-shaped response either with a
|
|
39
|
-
* success body (`{ok, marker_id, turn_id}`) or an `{error}` body — callers
|
|
40
|
-
* forward this directly back to the agent.
|
|
41
|
-
*/
|
|
42
|
-
export async function handleMarkerCall(toolName, args, deps) {
|
|
43
|
-
const text = String(args.text ?? "").trim();
|
|
44
|
-
const cap = TEXT_CAP[toolName];
|
|
45
|
-
if (text.length === 0) {
|
|
46
|
-
return errorResult(`${toolName}: text is required`);
|
|
47
|
-
}
|
|
48
|
-
if (text.length > cap) {
|
|
49
|
-
return errorResult(`${toolName}: text exceeds ${cap}-char limit`);
|
|
50
|
-
}
|
|
51
|
-
const argsToPersist = { text };
|
|
52
|
-
let blockerRef = "";
|
|
53
|
-
let filePath = "";
|
|
54
|
-
if (toolName === "mark_decision") {
|
|
55
|
-
const alts = args.alternatives;
|
|
56
|
-
if (Array.isArray(alts) && alts.length > 0) {
|
|
57
|
-
argsToPersist.alternatives = alts
|
|
58
|
-
.map((v) => String(v))
|
|
59
|
-
.slice(0, 5)
|
|
60
|
-
.map((v) => (v.length > 80 ? `${v.slice(0, 80)}…` : v));
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (toolName === "mark_blocker") {
|
|
64
|
-
const fp = args.file_path;
|
|
65
|
-
if (typeof fp === "string" && fp.length > 0) {
|
|
66
|
-
filePath = fp.length > 200 ? `${fp.slice(0, 200)}…` : fp;
|
|
67
|
-
argsToPersist.file_path = filePath;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
if (toolName === "mark_resolution") {
|
|
71
|
-
const ref = String(args.blocker_ref ?? "").trim();
|
|
72
|
-
if (ref.length === 0) {
|
|
73
|
-
return errorResult("mark_resolution: blocker_ref required (the marker_id returned by mark_blocker)");
|
|
74
|
-
}
|
|
75
|
-
blockerRef = ref;
|
|
76
|
-
argsToPersist.blocker_ref = blockerRef;
|
|
77
|
-
}
|
|
78
|
-
const entry = deps.ledger.record(toolName, argsToPersist, { ok: true }, deps.branch, deps.headSha);
|
|
79
|
-
// Read redacted values back from the ledger row — `ShadowLedger.record()`
|
|
80
|
-
// ran the redactor on args_summary, so these are guaranteed scrubbed before
|
|
81
|
-
// they land in timeline.db. (Bug fix: previously we wrote the raw input text,
|
|
82
|
-
// leaking secrets into the markers relation.)
|
|
83
|
-
const persistedArgs = entry.args_summary;
|
|
84
|
-
const redactedText = typeof persistedArgs.text === "string" ? persistedArgs.text : text;
|
|
85
|
-
const redactedFilePath = typeof persistedArgs.file_path === "string"
|
|
86
|
-
? persistedArgs.file_path
|
|
87
|
-
: filePath;
|
|
88
|
-
const redactedBlockerRef = typeof persistedArgs.blocker_ref === "string"
|
|
89
|
-
? persistedArgs.blocker_ref
|
|
90
|
-
: blockerRef;
|
|
91
|
-
try {
|
|
92
|
-
await deps.store.insertMarker({
|
|
93
|
-
marker_id: entry.id,
|
|
94
|
-
type: toolName,
|
|
95
|
-
text: redactedText,
|
|
96
|
-
session_id: entry.session_id,
|
|
97
|
-
turn_id: entry.turn_id ?? "",
|
|
98
|
-
ts: Date.parse(entry.ts),
|
|
99
|
-
blocker_ref: redactedBlockerRef,
|
|
100
|
-
file_path: redactedFilePath,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
catch (err) {
|
|
104
|
-
process.stderr.write(`[unerr:timeline-markers] WARN: insertMarker failed: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
105
|
-
// Continue: ledger row already persisted, miners can still recover from it.
|
|
106
|
-
}
|
|
107
|
-
return {
|
|
108
|
-
content: [
|
|
109
|
-
{
|
|
110
|
-
type: "text",
|
|
111
|
-
text: JSON.stringify({
|
|
112
|
-
ok: true,
|
|
113
|
-
marker_id: entry.id,
|
|
114
|
-
turn_id: entry.turn_id ?? null,
|
|
115
|
-
type: toolName,
|
|
116
|
-
}),
|
|
117
|
-
},
|
|
118
|
-
],
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
function errorResult(msg) {
|
|
122
|
-
return {
|
|
123
|
-
content: [
|
|
124
|
-
{
|
|
125
|
-
type: "text",
|
|
126
|
-
text: JSON.stringify({ error: msg }),
|
|
127
|
-
},
|
|
128
|
-
],
|
|
129
|
-
};
|
|
130
|
-
}
|
package/dist/tools/registry.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tool Registry — central catalog of all available tools.
|
|
3
|
-
*
|
|
4
|
-
* Tools are registered by category (intelligence, coding) and can be
|
|
5
|
-
* looked up by name. The registry provides the tool list for both the MCP
|
|
6
|
-
* server and the QueryEngine's tool definitions sent to the LLM.
|
|
7
|
-
*/
|
|
8
|
-
export class ToolRegistry {
|
|
9
|
-
tools = new Map();
|
|
10
|
-
/** Register a tool. Throws if a tool with the same name already exists. */
|
|
11
|
-
register(tool, category) {
|
|
12
|
-
if (this.tools.has(tool.name)) {
|
|
13
|
-
throw new Error(`Tool "${tool.name}" is already registered`);
|
|
14
|
-
}
|
|
15
|
-
this.tools.set(tool.name, { ...tool, category });
|
|
16
|
-
}
|
|
17
|
-
/** Look up a tool by name. Returns undefined if not found. */
|
|
18
|
-
get(name) {
|
|
19
|
-
return this.tools.get(name);
|
|
20
|
-
}
|
|
21
|
-
/** Get all registered tools. */
|
|
22
|
-
all() {
|
|
23
|
-
return [...this.tools.values()];
|
|
24
|
-
}
|
|
25
|
-
/** Get tools filtered by category. */
|
|
26
|
-
byCategory(category) {
|
|
27
|
-
return this.all().filter((t) => t.category === category);
|
|
28
|
-
}
|
|
29
|
-
/** Get tool definitions for LLM consumption (name, description, inputSchema). */
|
|
30
|
-
definitions() {
|
|
31
|
-
return this.all().map(({ name, description, inputSchema, isReadOnly, requiresPermission }) => ({
|
|
32
|
-
name,
|
|
33
|
-
description,
|
|
34
|
-
inputSchema,
|
|
35
|
-
isReadOnly,
|
|
36
|
-
requiresPermission,
|
|
37
|
-
}));
|
|
38
|
-
}
|
|
39
|
-
/** Get tool definitions formatted for MCP tools/list response. */
|
|
40
|
-
mcpToolList() {
|
|
41
|
-
return this.all().map(({ name, description, inputSchema }) => ({
|
|
42
|
-
name,
|
|
43
|
-
description,
|
|
44
|
-
inputSchema,
|
|
45
|
-
}));
|
|
46
|
-
}
|
|
47
|
-
}
|
package/dist/tools/types.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unified Tool Interface — used by both the MCP server (serving tools to external agents)
|
|
3
|
-
* and the local QueryEngine (tools the LLM calls during interactive sessions).
|
|
4
|
-
*
|
|
5
|
-
* This is the foundational abstraction that makes unerr's intelligence tools
|
|
6
|
-
* available to both external agents (via MCP) and the built-in AI assistant.
|
|
7
|
-
*/
|
|
8
|
-
export {};
|