@unerr-ai/unerr 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/cli.js +37236 -35793
- package/package.json +6 -1
- package/dist/behaviors/agent-llm-bridge.js +0 -166
- package/dist/behaviors/architecture-guard.js +0 -256
- package/dist/behaviors/auto-doc.js +0 -247
- package/dist/behaviors/cascade-guard.js +0 -289
- package/dist/behaviors/change-narrative.js +0 -270
- package/dist/behaviors/convention-drift.js +0 -290
- package/dist/behaviors/framework.js +0 -235
- package/dist/behaviors/guard-formatter.js +0 -44
- package/dist/behaviors/incomplete-work.js +0 -270
- package/dist/behaviors/loop-breaker.js +0 -300
- package/dist/behaviors/session-continuity.js +0 -208
- package/dist/commands/branches.js +0 -97
- package/dist/commands/check-commit.js +0 -225
- package/dist/commands/compress-output.js +0 -64
- package/dist/commands/config-verify.js +0 -243
- package/dist/commands/daemon.js +0 -905
- package/dist/commands/dashboard.js +0 -52
- package/dist/commands/debug.js +0 -200
- package/dist/commands/enrich.js +0 -184
- package/dist/commands/exec.js +0 -233
- package/dist/commands/gain.js +0 -156
- package/dist/commands/hook.js +0 -88
- package/dist/commands/index.js +0 -88
- package/dist/commands/init.js +0 -74
- package/dist/commands/install.js +0 -505
- package/dist/commands/learn.js +0 -116
- package/dist/commands/manifest.js +0 -193
- package/dist/commands/rewind.js +0 -103
- package/dist/commands/serve.js +0 -19
- package/dist/commands/setup-wizard.js +0 -414
- package/dist/commands/skills.js +0 -64
- package/dist/commands/stats.js +0 -20
- package/dist/commands/status.js +0 -654
- package/dist/commands/timeline.js +0 -139
- package/dist/commands/uninstall.js +0 -230
- package/dist/components/App.js +0 -109
- package/dist/components/Banner.js +0 -12
- package/dist/components/ConfirmPrompt.js +0 -25
- package/dist/components/DriftSummary.js +0 -23
- package/dist/components/GradeBadge.js +0 -15
- package/dist/components/HealthCard.js +0 -18
- package/dist/components/InkSpinner.js +0 -22
- package/dist/components/InputBox.js +0 -17
- package/dist/components/KeyValue.js +0 -13
- package/dist/components/MessageList.js +0 -14
- package/dist/components/ProgressBar.js +0 -26
- package/dist/components/Section.js +0 -16
- package/dist/components/SessionSummaryCard.js +0 -73
- package/dist/components/StartupDisplay.js +0 -24
- package/dist/components/StatusDashboard.js +0 -57
- package/dist/components/StatusLine.js +0 -8
- package/dist/components/StepLine.js +0 -22
- package/dist/components/Theme.js +0 -20
- package/dist/components/ToolProgress.js +0 -8
- package/dist/components/ViolationList.js +0 -21
- package/dist/components/render.js +0 -13
- package/dist/config/agent-registry.js +0 -237
- package/dist/config/claude-settings-hooks.js +0 -304
- package/dist/config/hook-installer.js +0 -65
- package/dist/config/instruction-writer.js +0 -388
- package/dist/config/mcp-config-writer.js +0 -266
- package/dist/config/settings.js +0 -174
- package/dist/config/tool-detector.js +0 -42
- package/dist/config/value-surfacing.js +0 -119
- package/dist/core/context-assembly.js +0 -108
- package/dist/core/conversation.js +0 -33
- package/dist/core/local-chat-provider.js +0 -475
- package/dist/core/provider-factory.js +0 -55
- package/dist/core/providers.js +0 -90
- package/dist/core/query-engine.js +0 -174
- package/dist/daemon/api.js +0 -312
- package/dist/daemon/autostart.js +0 -119
- package/dist/daemon/bootstrap.js +0 -39
- package/dist/daemon/client.js +0 -164
- package/dist/daemon/detect-ci.js +0 -81
- package/dist/daemon/platform-linux.js +0 -146
- package/dist/daemon/platform-macos.js +0 -134
- package/dist/daemon/platform-windows.js +0 -116
- package/dist/daemon/process-manager.js +0 -299
- package/dist/daemon/protocol.js +0 -23
- package/dist/daemon/registry.js +0 -270
- package/dist/daemon/settings-schema.js +0 -72
- package/dist/daemon/system-health.js +0 -134
- package/dist/daemon/version-checker.js +0 -262
- package/dist/daemon/warm-start.js +0 -223
- package/dist/entrypoints/cli.js +0 -1043
- package/dist/entrypoints/daemon.js +0 -380
- package/dist/entrypoints/repl.js +0 -147
- package/dist/hooks/adapters/claude-code.js +0 -90
- package/dist/hooks/adapters/cline.js +0 -100
- package/dist/hooks/adapters/cursor.js +0 -98
- package/dist/hooks/hook-dedup.js +0 -79
- package/dist/hooks/hook-runner.js +0 -113
- package/dist/hooks/navigation-hooks.js +0 -175
- package/dist/hooks/prompt-hooks.js +0 -63
- package/dist/hooks/shell-hooks.js +0 -47
- package/dist/ignore.js +0 -111
- package/dist/intelligence/approach-suggester.js +0 -61
- package/dist/intelligence/ast-extractor.js +0 -2615
- package/dist/intelligence/ast-worker.js +0 -34
- package/dist/intelligence/background-indexer.js +0 -121
- package/dist/intelligence/blast-radius.js +0 -200
- package/dist/intelligence/community-detection.js +0 -691
- package/dist/intelligence/community-detector.js +0 -184
- package/dist/intelligence/computation-scheduler.js +0 -75
- package/dist/intelligence/confidence-propagation.js +0 -47
- package/dist/intelligence/convention-detector.js +0 -242
- package/dist/intelligence/convention-learner.js +0 -205
- package/dist/intelligence/convention-matcher.js +0 -205
- package/dist/intelligence/cozo-schema.js +0 -376
- package/dist/intelligence/decision-point-detector.js +0 -90
- package/dist/intelligence/deep-dive-tools.js +0 -586
- package/dist/intelligence/durability-scorer.js +0 -84
- package/dist/intelligence/exploration-cost.js +0 -204
- package/dist/intelligence/exploration-pattern-tracker.js +0 -61
- package/dist/intelligence/fact-generator.js +0 -322
- package/dist/intelligence/facts-schema.js +0 -90
- package/dist/intelligence/file-intelligence.js +0 -59
- package/dist/intelligence/graph-holder.js +0 -220
- package/dist/intelligence/graph-temporal-joiner.js +0 -238
- package/dist/intelligence/health-grade.js +0 -423
- package/dist/intelligence/health-grader.js +0 -200
- package/dist/intelligence/health-map-data.js +0 -259
- package/dist/intelligence/import-symbols.js +0 -136
- package/dist/intelligence/incremental-indexer.js +0 -658
- package/dist/intelligence/indexer/centrality.js +0 -62
- package/dist/intelligence/indexer/cfg-context.js +0 -95
- package/dist/intelligence/indexer/confidence.js +0 -34
- package/dist/intelligence/indexer/cross-file-resolver.js +0 -104
- package/dist/intelligence/indexer/edge-repair.js +0 -89
- package/dist/intelligence/indexer/entity-key.js +0 -17
- package/dist/intelligence/indexer/export-map.js +0 -132
- package/dist/intelligence/indexer/git-cochange.js +0 -128
- package/dist/intelligence/indexer/graph-patch.js +0 -147
- package/dist/intelligence/indexer/incremental.js +0 -78
- package/dist/intelligence/indexer/ingest.js +0 -160
- package/dist/intelligence/indexer/language-detect.js +0 -226
- package/dist/intelligence/indexer/metadata.js +0 -63
- package/dist/intelligence/indexer/mutation-tracker.js +0 -79
- package/dist/intelligence/indexer/orchestrator.js +0 -155
- package/dist/intelligence/indexer/plugin-interface.js +0 -31
- package/dist/intelligence/indexer/plugins/csharp.js +0 -440
- package/dist/intelligence/indexer/plugins/go.js +0 -335
- package/dist/intelligence/indexer/plugins/java.js +0 -370
- package/dist/intelligence/indexer/plugins/python.js +0 -358
- package/dist/intelligence/indexer/plugins/regex-fallback.js +0 -82
- package/dist/intelligence/indexer/plugins/ruby.js +0 -290
- package/dist/intelligence/indexer/plugins/rust.js +0 -484
- package/dist/intelligence/indexer/plugins/tier2-generic.js +0 -310
- package/dist/intelligence/indexer/plugins/typescript.js +0 -456
- package/dist/intelligence/indexer/resource-monitor.js +0 -93
- package/dist/intelligence/indexer/scip/decoder.js +0 -253
- package/dist/intelligence/indexer/scip/detector.js +0 -232
- package/dist/intelligence/indexer/scip/downloader.js +0 -427
- package/dist/intelligence/indexer/scip/fallback.js +0 -34
- package/dist/intelligence/indexer/scip/merger.js +0 -109
- package/dist/intelligence/indexer/scip/orchestrator.js +0 -433
- package/dist/intelligence/indexer/scip/runner.js +0 -98
- package/dist/intelligence/indexer/snapshot.js +0 -66
- package/dist/intelligence/indexer/test-detector.js +0 -196
- package/dist/intelligence/indexer/watch-integration.js +0 -61
- package/dist/intelligence/indexer/worker.js +0 -85
- package/dist/intelligence/local-convention-detector.js +0 -437
- package/dist/intelligence/local-embeddings.js +0 -190
- package/dist/intelligence/local-graph.js +0 -1946
- package/dist/intelligence/local-indexer.js +0 -1575
- package/dist/intelligence/local-llm.js +0 -163
- package/dist/intelligence/local-rule-generator.js +0 -154
- package/dist/intelligence/local-snapshot.js +0 -213
- package/dist/intelligence/negative-knowledge.js +0 -103
- package/dist/intelligence/persistent-db.js +0 -85
- package/dist/intelligence/query-router.js +0 -2556
- package/dist/intelligence/risk-classifier.js +0 -116
- package/dist/intelligence/rule-evaluator.js +0 -380
- package/dist/intelligence/rule-generator.js +0 -49
- package/dist/intelligence/search-index.js +0 -173
- package/dist/intelligence/semantic/docstring-extractor.js +0 -67
- package/dist/intelligence/semantic/embedding-store.js +0 -52
- package/dist/intelligence/semantic/enrichment-orchestrator.js +0 -48
- package/dist/intelligence/semantic/git-message-miner.js +0 -114
- package/dist/intelligence/semantic/identifier-tokenizer.js +0 -51
- package/dist/intelligence/semantic/node2vec-embeddings.js +0 -71
- package/dist/intelligence/semantic/node2vec-walks.js +0 -103
- package/dist/intelligence/semantic/path-domain-inference.js +0 -112
- package/dist/intelligence/semantic/similarity-engine.js +0 -60
- package/dist/intelligence/semantic/tfidf-vectors.js +0 -88
- package/dist/intelligence/session-brief-builder.js +0 -159
- package/dist/intelligence/session-context.js +0 -221
- package/dist/intelligence/session-health-monitor.js +0 -211
- package/dist/intelligence/session-narrative.js +0 -197
- package/dist/intelligence/session-pattern-analyzer.js +0 -218
- package/dist/intelligence/signal-scorer.js +0 -390
- package/dist/intelligence/signal-show-store.js +0 -182
- package/dist/intelligence/smart-truncate.js +0 -158
- package/dist/intelligence/subgraph-cache.js +0 -88
- package/dist/intelligence/temporal-facts.js +0 -494
- package/dist/intelligence/token-estimator.js +0 -100
- package/dist/intelligence/tool-injector.js +0 -87
- package/dist/intelligence/tree-sitter-loader.js +0 -71
- package/dist/intelligence/worker-pool.js +0 -116
- package/dist/proxy/arg-validator.js +0 -79
- package/dist/proxy/auto-bootstrap.js +0 -167
- package/dist/proxy/bridge.js +0 -147
- package/dist/proxy/budget-enforcer.js +0 -70
- package/dist/proxy/compression-quality-monitor.js +0 -160
- package/dist/proxy/compression-stats.js +0 -51
- package/dist/proxy/context-rot-detector.js +0 -137
- package/dist/proxy/drift-detector.js +0 -139
- package/dist/proxy/efficiency-tracker.js +0 -79
- package/dist/proxy/fact-ranking.js +0 -154
- package/dist/proxy/format-encoder.js +0 -266
- package/dist/proxy/http-transport.js +0 -90
- package/dist/proxy/lifecycle-actor.js +0 -55
- package/dist/proxy/lifecycle-machine.js +0 -187
- package/dist/proxy/log-tailer.js +0 -265
- package/dist/proxy/model-pricing.js +0 -98
- package/dist/proxy/network-firewall.js +0 -141
- package/dist/proxy/nudge-state.js +0 -93
- package/dist/proxy/output-compressor.js +0 -185
- package/dist/proxy/pid-lock.js +0 -291
- package/dist/proxy/proxy-context.js +0 -11
- package/dist/proxy/proxy.js +0 -2633
- package/dist/proxy/response-enrichment.js +0 -32
- package/dist/proxy/response-envelope.js +0 -313
- package/dist/proxy/session-dedup.js +0 -82
- package/dist/proxy/session-legend.js +0 -30
- package/dist/proxy/session-persistence.js +0 -210
- package/dist/proxy/session-resume.js +0 -94
- package/dist/proxy/session-stats.js +0 -513
- package/dist/proxy/shell-classifier.js +0 -1346
- package/dist/proxy/shell-compression-log.js +0 -93
- package/dist/proxy/shell-compressor.js +0 -390
- package/dist/proxy/shell-graph-boost.js +0 -202
- package/dist/proxy/shell-monitor-map.js +0 -18
- package/dist/proxy/shell-stats.js +0 -54
- package/dist/proxy/shell-strategies/cloud.js +0 -215
- package/dist/proxy/shell-strategies/diff.js +0 -159
- package/dist/proxy/shell-strategies/error-diagnostic.js +0 -796
- package/dist/proxy/shell-strategies/filter-dsl.js +0 -358
- package/dist/proxy/shell-strategies/git-status.js +0 -177
- package/dist/proxy/shell-strategies/key-value.js +0 -193
- package/dist/proxy/shell-strategies/log-text.js +0 -154
- package/dist/proxy/shell-strategies/omni.js +0 -188
- package/dist/proxy/shell-strategies/progress.js +0 -55
- package/dist/proxy/shell-strategies/redact.js +0 -76
- package/dist/proxy/shell-strategies/structured.js +0 -241
- package/dist/proxy/shell-strategies/tabular.js +0 -243
- package/dist/proxy/shell-strategies/test-results-types.js +0 -13
- package/dist/proxy/shell-strategies/test-results.js +0 -784
- package/dist/proxy/shell-strategies/tree-paths.js +0 -144
- package/dist/proxy/shell-strategies/yaml.js +0 -182
- package/dist/proxy/shell-tee.js +0 -111
- package/dist/proxy/signal-dedup.js +0 -171
- package/dist/proxy/startup-renderer.js +0 -158
- package/dist/proxy/task-token-display.js +0 -38
- package/dist/proxy/token-counter.js +0 -61
- package/dist/proxy/tool-clusters.js +0 -273
- package/dist/proxy/tool-definitions.js +0 -525
- package/dist/proxy/transport-mux.js +0 -229
- package/dist/proxy/wire-cap.js +0 -268
- package/dist/rules/developer.mozilla.org.json +0 -9
- package/dist/rules/github.com.json +0 -21
- package/dist/schemas/api/skills.js +0 -19
- package/dist/schemas/common/errors.js +0 -7
- package/dist/schemas/common/headers.js +0 -5
- package/dist/schemas/entities/edge.js +0 -25
- package/dist/schemas/entities/entity.js +0 -22
- package/dist/schemas/entities/rule.js +0 -18
- package/dist/schemas/index.js +0 -14
- package/dist/server/event-bus.js +0 -59
- package/dist/server/http.js +0 -156
- package/dist/server/middleware.js +0 -70
- package/dist/server/routes/drift.js +0 -97
- package/dist/server/routes/intelligence.js +0 -1217
- package/dist/server/routes/reasoning-quality.js +0 -444
- package/dist/server/routes/session.js +0 -86
- package/dist/server/routes/stream.js +0 -120
- package/dist/server/routes/system.js +0 -73
- package/dist/server/routes/temporal.js +0 -170
- package/dist/server/routes/timeline.js +0 -232
- package/dist/server/routes/token-flow.js +0 -403
- package/dist/skills/effectiveness-tracker.js +0 -93
- package/dist/skills/local-pack.js +0 -380
- package/dist/skills/resolver.js +0 -495
- package/dist/state-detector.js +0 -83
- package/dist/timeline/intent-detector.js +0 -263
- package/dist/timeline/loop-miner.js +0 -140
- package/dist/timeline/open-threads.js +0 -49
- package/dist/timeline/signal-reinforcer.js +0 -62
- package/dist/timeline/timeline-bootstrap.js +0 -151
- package/dist/timeline/timeline-store.js +0 -618
- package/dist/tools/coding/bash.js +0 -49
- package/dist/tools/coding/file-edit.js +0 -72
- package/dist/tools/coding/file-outline.js +0 -227
- package/dist/tools/coding/file-read-protocol.js +0 -425
- package/dist/tools/coding/file-read.js +0 -35
- package/dist/tools/coding/file-write.js +0 -43
- package/dist/tools/coding/glob-tool.js +0 -109
- package/dist/tools/coding/grep.js +0 -162
- package/dist/tools/coding/index.js +0 -27
- package/dist/tools/intelligence/index.js +0 -269
- package/dist/tools/intelligence/record-fact.js +0 -48
- package/dist/tools/intelligence/timeline-markers.js +0 -130
- package/dist/tools/registry.js +0 -47
- package/dist/tools/types.js +0 -8
- package/dist/tracking/auto-snapshot-triggers.js +0 -246
- package/dist/tracking/branch-context.js +0 -115
- package/dist/tracking/branch-snapshot.js +0 -217
- package/dist/tracking/causal-bridge.js +0 -317
- package/dist/tracking/circuit-breaker.js +0 -147
- package/dist/tracking/commit-watcher.js +0 -114
- package/dist/tracking/context-ledger.js +0 -119
- package/dist/tracking/correction-detector.js +0 -324
- package/dist/tracking/drift-tracker.js +0 -874
- package/dist/tracking/durability-tracker.js +0 -94
- package/dist/tracking/entity-rewind.js +0 -200
- package/dist/tracking/file-hash-state.js +0 -114
- package/dist/tracking/git-attribution.js +0 -132
- package/dist/tracking/git-trailers.js +0 -171
- package/dist/tracking/intelligence-counter.js +0 -46
- package/dist/tracking/intent-correlator.js +0 -202
- package/dist/tracking/intent-encoder.js +0 -52
- package/dist/tracking/intent-token-tracker.js +0 -159
- package/dist/tracking/ledger-archiver.js +0 -94
- package/dist/tracking/ledger-chains.js +0 -245
- package/dist/tracking/metrics-store.js +0 -361
- package/dist/tracking/native-watcher.js +0 -131
- package/dist/tracking/offline-rewind.js +0 -295
- package/dist/tracking/pending-violations.js +0 -74
- package/dist/tracking/persistence-effectiveness.js +0 -167
- package/dist/tracking/prompt-durability.js +0 -202
- package/dist/tracking/quality-signals.js +0 -213
- package/dist/tracking/redactor.js +0 -73
- package/dist/tracking/rewind-engine.js +0 -161
- package/dist/tracking/session-history.js +0 -128
- package/dist/tracking/session-receipt.js +0 -88
- package/dist/tracking/session-summary-writer.js +0 -157
- package/dist/tracking/shadow-ledger.js +0 -321
- package/dist/tracking/stash-manager.js +0 -258
- package/dist/tracking/timeline-fork.js +0 -213
- package/dist/tracking/timeline.js +0 -69
- package/dist/tracking/token-flow.js +0 -276
- package/dist/tracking/turn-segmenter.js +0 -122
- package/dist/tracking/weekly-accumulator.js +0 -179
- package/dist/tracking/working-snapshots.js +0 -188
- package/dist/tracking/workspace-manifest.js +0 -176
- package/dist/transport/http.js +0 -102
- package/dist/utils/counterfactual.js +0 -65
- package/dist/utils/deep-link.js +0 -34
- package/dist/utils/detect.js +0 -193
- package/dist/utils/exec.js +0 -73
- package/dist/utils/file-logger.js +0 -87
- package/dist/utils/format-error.js +0 -29
- package/dist/utils/git.js +0 -181
- package/dist/utils/log.js +0 -57
- package/dist/utils/logger.js +0 -35
- package/dist/utils/mcp-content-json.js +0 -8
- package/dist/utils/session-logger.js +0 -154
- package/dist/utils/startup-log.js +0 -512
- package/dist/utils/ui.js +0 -56
package/package.json
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unerr-ai/unerr",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"mcpName": "io.github.unerr-ai/unerr",
|
|
4
5
|
"description": "Local-first code intelligence CLI for unerr",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/unerr-ai/unerr-cli.git"
|
|
9
|
+
},
|
|
5
10
|
"type": "module",
|
|
6
11
|
"bin": {
|
|
7
12
|
"unerr": "./dist/cli.js"
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent-as-LLM Bridge — BA-3.3
|
|
3
|
-
*
|
|
4
|
-
* Formalizes the sub-prompt injection pattern used throughout Layer 4.
|
|
5
|
-
* Instead of managing API keys, unerr injects follow-up prompts that the
|
|
6
|
-
* host agent (Claude/GPT) processes as part of its normal flow.
|
|
7
|
-
*
|
|
8
|
-
* Features:
|
|
9
|
-
* - Template system for common sub-prompt types
|
|
10
|
-
* - 5s timeout with graceful fallback to AST-only processing
|
|
11
|
-
* - Follow-through tracking: did the agent act on the injected prompt?
|
|
12
|
-
* - Prompt budgeting: limits injected context to prevent bloat
|
|
13
|
-
*/
|
|
14
|
-
const DEFAULT_TIMEOUT_MS = 5_000;
|
|
15
|
-
const MAX_PROMPT_TOKENS = 500;
|
|
16
|
-
const PROMPT_BUDGET_PER_CALL = 1000;
|
|
17
|
-
const TEMPLATE_DEFINITIONS = {
|
|
18
|
-
session_resume: {
|
|
19
|
-
prefix: "Summarize the following session state for the developer in 2-3 natural sentences.",
|
|
20
|
-
maxTokens: 300,
|
|
21
|
-
priority: "normal",
|
|
22
|
-
},
|
|
23
|
-
doc_generation: {
|
|
24
|
-
prefix: "Generate documentation following the existing style in this file.",
|
|
25
|
-
maxTokens: 400,
|
|
26
|
-
priority: "low",
|
|
27
|
-
},
|
|
28
|
-
doc_update: {
|
|
29
|
-
prefix: "Update the documentation to reflect the following signature change.",
|
|
30
|
-
maxTokens: 300,
|
|
31
|
-
priority: "low",
|
|
32
|
-
},
|
|
33
|
-
loop_diagnosis: {
|
|
34
|
-
prefix: "Analyze why the previous attempts failed before trying again.",
|
|
35
|
-
maxTokens: 500,
|
|
36
|
-
priority: "high",
|
|
37
|
-
},
|
|
38
|
-
convention_fix: {
|
|
39
|
-
prefix: "Regenerate the code following the project's naming conventions.",
|
|
40
|
-
maxTokens: 400,
|
|
41
|
-
priority: "normal",
|
|
42
|
-
},
|
|
43
|
-
cascade_fix: {
|
|
44
|
-
prefix: "Generate updated call sites for each caller with the new signature.",
|
|
45
|
-
maxTokens: 500,
|
|
46
|
-
priority: "high",
|
|
47
|
-
},
|
|
48
|
-
architecture_alternative: {
|
|
49
|
-
prefix: "The following import crosses a module boundary. Suggest an alternative pattern.",
|
|
50
|
-
maxTokens: 400,
|
|
51
|
-
priority: "normal",
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
let promptIdCounter = 0;
|
|
55
|
-
export class AgentLlmBridge {
|
|
56
|
-
injections = [];
|
|
57
|
-
totalPromptTokensThisCall = 0;
|
|
58
|
-
/**
|
|
59
|
-
* Create a sub-prompt from a template with custom context.
|
|
60
|
-
*/
|
|
61
|
-
createPrompt(template, context, options) {
|
|
62
|
-
const def = TEMPLATE_DEFINITIONS[template];
|
|
63
|
-
const content = [def.prefix, "", context].join("\n");
|
|
64
|
-
return {
|
|
65
|
-
template,
|
|
66
|
-
content: truncateToTokens(content, def.maxTokens),
|
|
67
|
-
priority: def.priority,
|
|
68
|
-
maxTokens: def.maxTokens,
|
|
69
|
-
timeoutMs: options?.timeoutMs ?? DEFAULT_TIMEOUT_MS,
|
|
70
|
-
fallbackContent: options?.fallback ?? null,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Inject a sub-prompt into the internal `context` carrier; surfaces as `ur|hnt` prefix line on the response.
|
|
75
|
-
* Returns the prompt content if within budget, or the fallback if over budget.
|
|
76
|
-
*/
|
|
77
|
-
inject(prompt) {
|
|
78
|
-
const estimatedTokens = estimateTokens(prompt.content);
|
|
79
|
-
if (this.totalPromptTokensThisCall + estimatedTokens >
|
|
80
|
-
PROMPT_BUDGET_PER_CALL) {
|
|
81
|
-
return prompt.fallbackContent ?? "";
|
|
82
|
-
}
|
|
83
|
-
this.totalPromptTokensThisCall += estimatedTokens;
|
|
84
|
-
const injection = {
|
|
85
|
-
id: `prompt-${++promptIdCounter}`,
|
|
86
|
-
prompt,
|
|
87
|
-
injectedAt: Date.now(),
|
|
88
|
-
followedThrough: null,
|
|
89
|
-
responseDetectedAt: null,
|
|
90
|
-
};
|
|
91
|
-
this.injections.push(injection);
|
|
92
|
-
return prompt.content;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Record that the agent acted on an injected prompt.
|
|
96
|
-
* Called when a subsequent tool call references the prompted action.
|
|
97
|
-
*/
|
|
98
|
-
recordFollowThrough(promptId) {
|
|
99
|
-
const injection = this.injections.find((i) => i.id === promptId);
|
|
100
|
-
if (injection) {
|
|
101
|
-
injection.followedThrough = true;
|
|
102
|
-
injection.responseDetectedAt = Date.now();
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Reset per-call budget (call at the start of each tool call).
|
|
107
|
-
*/
|
|
108
|
-
resetCallBudget() {
|
|
109
|
-
this.totalPromptTokensThisCall = 0;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Get follow-through rate: what % of injected prompts led to agent action.
|
|
113
|
-
* Counts all injections (null = not followed through yet = counts as miss).
|
|
114
|
-
*/
|
|
115
|
-
getFollowThroughRate() {
|
|
116
|
-
if (this.injections.length === 0)
|
|
117
|
-
return 0;
|
|
118
|
-
const followed = this.injections.filter((i) => i.followedThrough === true);
|
|
119
|
-
return followed.length / this.injections.length;
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Get the last injected prompt's ID (useful for follow-through recording).
|
|
123
|
-
*/
|
|
124
|
-
getLastInjectionId() {
|
|
125
|
-
if (this.injections.length === 0)
|
|
126
|
-
return null;
|
|
127
|
-
return this.injections[this.injections.length - 1]?.id ?? null;
|
|
128
|
-
}
|
|
129
|
-
getStats() {
|
|
130
|
-
const byTemplate = {};
|
|
131
|
-
let followedCount = 0;
|
|
132
|
-
for (const injection of this.injections) {
|
|
133
|
-
const key = injection.prompt.template;
|
|
134
|
-
byTemplate[key] = (byTemplate[key] ?? 0) + 1;
|
|
135
|
-
if (injection.followedThrough)
|
|
136
|
-
followedCount++;
|
|
137
|
-
}
|
|
138
|
-
return {
|
|
139
|
-
totalInjected: this.injections.length,
|
|
140
|
-
followedThrough: followedCount,
|
|
141
|
-
followThroughRate: this.getFollowThroughRate(),
|
|
142
|
-
byTemplate,
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Get all available template types.
|
|
147
|
-
*/
|
|
148
|
-
static getTemplates() {
|
|
149
|
-
return Object.keys(TEMPLATE_DEFINITIONS);
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Get template definition for a specific type.
|
|
153
|
-
*/
|
|
154
|
-
static getTemplateDefinition(template) {
|
|
155
|
-
return { ...TEMPLATE_DEFINITIONS[template] };
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
function estimateTokens(text) {
|
|
159
|
-
return Math.ceil(text.length / 4);
|
|
160
|
-
}
|
|
161
|
-
function truncateToTokens(text, maxTokens) {
|
|
162
|
-
const maxChars = maxTokens * 4;
|
|
163
|
-
if (text.length <= maxChars)
|
|
164
|
-
return text;
|
|
165
|
-
return `${text.slice(0, maxChars - 3)}...`;
|
|
166
|
-
}
|
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Architecture Boundary Guard — BA-3.1
|
|
3
|
-
*
|
|
4
|
-
* PreToolUse: when an agent writes/edits code, parses new import statements,
|
|
5
|
-
* resolves them to file paths, and queries CozoDB for community membership.
|
|
6
|
-
* Blocks cross-community direct imports unless:
|
|
7
|
-
* - The import is a type-only import (`import type`)
|
|
8
|
-
* - An override comment (`// @unerr-allow cross-community: [reason]`) exists
|
|
9
|
-
* - An established bridge exists (same pattern used 3+ times → auto-bridge)
|
|
10
|
-
*
|
|
11
|
-
* Assertiveness: enforcement (blocks with alternatives)
|
|
12
|
-
* Performance: <5ms (CozoDB community query)
|
|
13
|
-
*/
|
|
14
|
-
import { Behavior, } from "./framework.js";
|
|
15
|
-
const BRIDGE_THRESHOLD = 3;
|
|
16
|
-
const OVERRIDE_PATTERN = /\/\/\s*@unerr-allow\s+cross-community:\s*(.*)/;
|
|
17
|
-
const EDIT_TOOLS = new Set([
|
|
18
|
-
"file_write",
|
|
19
|
-
"write_file",
|
|
20
|
-
"edit_file",
|
|
21
|
-
"str_replace_editor",
|
|
22
|
-
"insert_code",
|
|
23
|
-
"replace_code",
|
|
24
|
-
]);
|
|
25
|
-
export class ArchitectureBoundaryGuard extends Behavior {
|
|
26
|
-
id = "architecture_boundary";
|
|
27
|
-
hooks = ["pre_tool_use"];
|
|
28
|
-
defaultLevel = "enforcement";
|
|
29
|
-
graph = null;
|
|
30
|
-
bridges = new Map();
|
|
31
|
-
guardConfig;
|
|
32
|
-
violationsBlocked = 0;
|
|
33
|
-
typeImportsAllowed = 0;
|
|
34
|
-
overridesRecorded = 0;
|
|
35
|
-
constructor(config) {
|
|
36
|
-
super(config, "enforcement");
|
|
37
|
-
this.guardConfig = {
|
|
38
|
-
enabled: true,
|
|
39
|
-
level: "enforcement",
|
|
40
|
-
allowTypeImports: true,
|
|
41
|
-
bridgeThreshold: BRIDGE_THRESHOLD,
|
|
42
|
-
...config,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
attachGraph(graph) {
|
|
46
|
-
this.graph = graph;
|
|
47
|
-
}
|
|
48
|
-
async onPreToolUse(ctx) {
|
|
49
|
-
if (!this.graph)
|
|
50
|
-
return null;
|
|
51
|
-
if (!EDIT_TOOLS.has(ctx.toolName))
|
|
52
|
-
return null;
|
|
53
|
-
const filePath = extractFilePath(ctx.args);
|
|
54
|
-
if (!filePath)
|
|
55
|
-
return null;
|
|
56
|
-
if (!isCodeFile(filePath))
|
|
57
|
-
return null;
|
|
58
|
-
const newContent = extractNewContent(ctx.args);
|
|
59
|
-
if (!newContent)
|
|
60
|
-
return null;
|
|
61
|
-
const imports = parseImports(newContent);
|
|
62
|
-
if (imports.length === 0)
|
|
63
|
-
return null;
|
|
64
|
-
const sourceEntities = await this.graph.getEntitiesByFile(filePath);
|
|
65
|
-
if (sourceEntities.length === 0)
|
|
66
|
-
return null;
|
|
67
|
-
const sourceCommunity = await this.graph.getCommunityForEntity(sourceEntities[0].key);
|
|
68
|
-
if (!sourceCommunity)
|
|
69
|
-
return null;
|
|
70
|
-
const violations = [];
|
|
71
|
-
const alternatives = [];
|
|
72
|
-
for (const imp of imports) {
|
|
73
|
-
if (imp.isTypeOnly && this.guardConfig.allowTypeImports) {
|
|
74
|
-
this.typeImportsAllowed++;
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
if (imp.hasOverride) {
|
|
78
|
-
this.overridesRecorded++;
|
|
79
|
-
await this.recordOverride(sourceCommunity.id, imp.resolvedPath ?? "", filePath);
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
const targetCommunity = await this.resolveTargetCommunity(imp.resolvedPath ?? imp.specifier, filePath);
|
|
83
|
-
if (!targetCommunity)
|
|
84
|
-
continue;
|
|
85
|
-
if (targetCommunity.id === sourceCommunity.id)
|
|
86
|
-
continue;
|
|
87
|
-
const bridgeKey = `${sourceCommunity.id}→${targetCommunity.id}`;
|
|
88
|
-
const bridge = this.bridges.get(bridgeKey);
|
|
89
|
-
if (bridge?.autoBridged)
|
|
90
|
-
continue;
|
|
91
|
-
violations.push({
|
|
92
|
-
import: imp.raw,
|
|
93
|
-
sourceFile: filePath,
|
|
94
|
-
sourceCommunity: sourceCommunity.label,
|
|
95
|
-
sourceCommunityId: sourceCommunity.id,
|
|
96
|
-
targetCommunity: targetCommunity.label,
|
|
97
|
-
targetCommunityId: targetCommunity.id,
|
|
98
|
-
violationType: "cross_community_direct_import",
|
|
99
|
-
});
|
|
100
|
-
alternatives.push({
|
|
101
|
-
pattern: "type_import",
|
|
102
|
-
example: `import type { ... } from '${imp.specifier}' // types are OK, not implementation`,
|
|
103
|
-
}, {
|
|
104
|
-
pattern: "interface_bridge",
|
|
105
|
-
example: "Define shared types in a schemas/ module accessible to both communities",
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
if (violations.length === 0)
|
|
109
|
-
return null;
|
|
110
|
-
this.violationsBlocked += violations.length;
|
|
111
|
-
return {
|
|
112
|
-
behaviorId: this.id,
|
|
113
|
-
level: this.level,
|
|
114
|
-
halt: this.level === "enforcement",
|
|
115
|
-
relatedSkillId: "understand-before-modify",
|
|
116
|
-
_meta: {
|
|
117
|
-
behavior: this.id,
|
|
118
|
-
blocked: this.level === "enforcement",
|
|
119
|
-
violations_count: violations.length,
|
|
120
|
-
},
|
|
121
|
-
_context: {
|
|
122
|
-
violations: violations.map((v) => ({
|
|
123
|
-
import: v.import,
|
|
124
|
-
source_file: v.sourceFile,
|
|
125
|
-
source_community: v.sourceCommunity,
|
|
126
|
-
target_community: v.targetCommunity,
|
|
127
|
-
violation_type: v.violationType,
|
|
128
|
-
})),
|
|
129
|
-
alternatives,
|
|
130
|
-
override: "Add '// @unerr-allow cross-community: [reason]' to bypass",
|
|
131
|
-
},
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
getSessionStats() {
|
|
135
|
-
let autoBridges = 0;
|
|
136
|
-
for (const bridge of this.bridges.values()) {
|
|
137
|
-
if (bridge.autoBridged)
|
|
138
|
-
autoBridges++;
|
|
139
|
-
}
|
|
140
|
-
return {
|
|
141
|
-
violationsBlocked: this.violationsBlocked,
|
|
142
|
-
typeImportsAllowed: this.typeImportsAllowed,
|
|
143
|
-
overridesRecorded: this.overridesRecorded,
|
|
144
|
-
autoBridges,
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
getBridges() {
|
|
148
|
-
return new Map(this.bridges);
|
|
149
|
-
}
|
|
150
|
-
async resolveTargetCommunity(importSpecifier, sourceFile) {
|
|
151
|
-
if (!this.graph)
|
|
152
|
-
return null;
|
|
153
|
-
const resolvedPath = resolveImportPath(importSpecifier, sourceFile);
|
|
154
|
-
if (!resolvedPath)
|
|
155
|
-
return null;
|
|
156
|
-
const targetEntities = await this.graph.getEntitiesByFile(resolvedPath);
|
|
157
|
-
if (targetEntities.length === 0)
|
|
158
|
-
return null;
|
|
159
|
-
const community = await this.graph.getCommunityForEntity(targetEntities[0].key);
|
|
160
|
-
if (!community)
|
|
161
|
-
return null;
|
|
162
|
-
return { id: community.id, label: community.label };
|
|
163
|
-
}
|
|
164
|
-
async recordOverride(sourceCommunityId, _targetPath, _sourceFile) {
|
|
165
|
-
const targetCommunity = await this.resolveTargetCommunity(_targetPath, _sourceFile);
|
|
166
|
-
if (!targetCommunity)
|
|
167
|
-
return;
|
|
168
|
-
const bridgeKey = `${sourceCommunityId}→${targetCommunity.id}`;
|
|
169
|
-
const existing = this.bridges.get(bridgeKey);
|
|
170
|
-
if (existing) {
|
|
171
|
-
existing.overrideCount++;
|
|
172
|
-
if (existing.overrideCount >= this.guardConfig.bridgeThreshold &&
|
|
173
|
-
!existing.autoBridged) {
|
|
174
|
-
existing.autoBridged = true;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
this.bridges.set(bridgeKey, {
|
|
179
|
-
sourceCommunity: sourceCommunityId,
|
|
180
|
-
targetCommunity: targetCommunity.id,
|
|
181
|
-
overrideCount: 1,
|
|
182
|
-
autoBridged: false,
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
function parseImports(content) {
|
|
188
|
-
const results = [];
|
|
189
|
-
const lines = content.split("\n");
|
|
190
|
-
for (let i = 0; i < lines.length; i++) {
|
|
191
|
-
const line = lines[i].trim();
|
|
192
|
-
const importMatch = line.match(/^import\s+(type\s+)?(?:\{[^}]*\}|[^'"]+)\s+from\s+['"]([^'"]+)['"]/);
|
|
193
|
-
if (!importMatch)
|
|
194
|
-
continue;
|
|
195
|
-
const isTypeOnly = !!importMatch[1];
|
|
196
|
-
const specifier = importMatch[2];
|
|
197
|
-
if (!specifier.startsWith("."))
|
|
198
|
-
continue;
|
|
199
|
-
const prevLine = i > 0 ? (lines[i - 1]?.trim() ?? "") : "";
|
|
200
|
-
const hasOverride = OVERRIDE_PATTERN.test(prevLine) || OVERRIDE_PATTERN.test(line);
|
|
201
|
-
results.push({
|
|
202
|
-
raw: line,
|
|
203
|
-
specifier,
|
|
204
|
-
isTypeOnly,
|
|
205
|
-
hasOverride,
|
|
206
|
-
resolvedPath: null,
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
return results;
|
|
210
|
-
}
|
|
211
|
-
function resolveImportPath(specifier, sourceFile) {
|
|
212
|
-
if (!specifier.startsWith("."))
|
|
213
|
-
return null;
|
|
214
|
-
const sourceParts = sourceFile.split("/");
|
|
215
|
-
sourceParts.pop();
|
|
216
|
-
const specParts = specifier.split("/");
|
|
217
|
-
const resolved = [...sourceParts];
|
|
218
|
-
for (const part of specParts) {
|
|
219
|
-
if (part === ".")
|
|
220
|
-
continue;
|
|
221
|
-
if (part === "..") {
|
|
222
|
-
resolved.pop();
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
resolved.push(part);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
let result = resolved.join("/");
|
|
229
|
-
if (!result.match(/\.[jt]sx?$/)) {
|
|
230
|
-
result += ".ts";
|
|
231
|
-
}
|
|
232
|
-
return result;
|
|
233
|
-
}
|
|
234
|
-
function extractFilePath(args) {
|
|
235
|
-
if (typeof args.path === "string")
|
|
236
|
-
return args.path;
|
|
237
|
-
if (typeof args.file_path === "string")
|
|
238
|
-
return args.file_path;
|
|
239
|
-
if (typeof args.file === "string")
|
|
240
|
-
return args.file;
|
|
241
|
-
return null;
|
|
242
|
-
}
|
|
243
|
-
function extractNewContent(args) {
|
|
244
|
-
if (typeof args.new_str === "string")
|
|
245
|
-
return args.new_str;
|
|
246
|
-
if (typeof args.new_string === "string")
|
|
247
|
-
return args.new_string;
|
|
248
|
-
if (typeof args.content === "string")
|
|
249
|
-
return args.content;
|
|
250
|
-
if (typeof args.after === "string")
|
|
251
|
-
return args.after;
|
|
252
|
-
return null;
|
|
253
|
-
}
|
|
254
|
-
function isCodeFile(filePath) {
|
|
255
|
-
return /\.[jt]sx?$/.test(filePath);
|
|
256
|
-
}
|
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Auto-Documentation Generation — BA-2.3
|
|
3
|
-
*
|
|
4
|
-
* PostToolUse: detects exported symbol changes (function signature, type
|
|
5
|
-
* definition, class method). Two-tier approach:
|
|
6
|
-
*
|
|
7
|
-
* 1. Fast path (invisible): template JSDoc/TSDoc from new signature
|
|
8
|
-
* 2. Semantic path (agent-as-LLM): inject sub-prompt for complex docs
|
|
9
|
-
* with 5s timeout + graceful AST fallback
|
|
10
|
-
*
|
|
11
|
-
* Tracks doc updates so the learning loop can calibrate quality.
|
|
12
|
-
*/
|
|
13
|
-
import { Behavior, } from "./framework.js";
|
|
14
|
-
const AGENT_LLM_TIMEOUT_MS = 5_000;
|
|
15
|
-
const EDIT_TOOLS = new Set([
|
|
16
|
-
"file_write",
|
|
17
|
-
"write_file",
|
|
18
|
-
"edit_file",
|
|
19
|
-
"str_replace_editor",
|
|
20
|
-
"insert_code",
|
|
21
|
-
"replace_code",
|
|
22
|
-
]);
|
|
23
|
-
export class AutoDocBehavior extends Behavior {
|
|
24
|
-
id = "auto_doc";
|
|
25
|
-
hooks = ["post_tool_use"];
|
|
26
|
-
defaultLevel = "invisible";
|
|
27
|
-
graph = null;
|
|
28
|
-
docConfig;
|
|
29
|
-
docsGeneratedThisSession = 0;
|
|
30
|
-
docsFlaggedThisSession = 0;
|
|
31
|
-
constructor(config) {
|
|
32
|
-
super(config, "invisible");
|
|
33
|
-
this.docConfig = {
|
|
34
|
-
enabled: true,
|
|
35
|
-
level: "invisible",
|
|
36
|
-
inlineDocs: true,
|
|
37
|
-
useAgentAsLlm: true,
|
|
38
|
-
...config,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
attachGraph(graph) {
|
|
42
|
-
this.graph = graph;
|
|
43
|
-
}
|
|
44
|
-
async onPostToolUse(ctx) {
|
|
45
|
-
if (!EDIT_TOOLS.has(ctx.toolName))
|
|
46
|
-
return null;
|
|
47
|
-
if (!ctx.filePath)
|
|
48
|
-
return null;
|
|
49
|
-
if (!isCodeFile(ctx.filePath))
|
|
50
|
-
return null;
|
|
51
|
-
const newContent = extractNewContent(ctx.args);
|
|
52
|
-
if (!newContent)
|
|
53
|
-
return null;
|
|
54
|
-
const actions = [];
|
|
55
|
-
const inlineActions = await this.detectInlineDocNeeds(ctx.filePath, newContent);
|
|
56
|
-
actions.push(...inlineActions);
|
|
57
|
-
const refActions = await this.detectStaleReferences(ctx.filePath, newContent);
|
|
58
|
-
actions.push(...refActions);
|
|
59
|
-
if (actions.length === 0)
|
|
60
|
-
return null;
|
|
61
|
-
this.docsGeneratedThisSession += actions.filter((a) => a.type !== "reference_flagged").length;
|
|
62
|
-
this.docsFlaggedThisSession += actions.filter((a) => a.type === "reference_flagged").length;
|
|
63
|
-
const agentPrompt = this.docConfig.useAgentAsLlm
|
|
64
|
-
? this.buildAgentPrompt(ctx.filePath, actions)
|
|
65
|
-
: undefined;
|
|
66
|
-
return {
|
|
67
|
-
behaviorId: this.id,
|
|
68
|
-
level: this.level,
|
|
69
|
-
_meta: {
|
|
70
|
-
behavior: this.id,
|
|
71
|
-
docs_updated: actions.filter((a) => a.type !== "reference_flagged")
|
|
72
|
-
.length,
|
|
73
|
-
docs_flagged: actions.filter((a) => a.type === "reference_flagged")
|
|
74
|
-
.length,
|
|
75
|
-
method: agentPrompt ? "agent_as_llm" : "template",
|
|
76
|
-
},
|
|
77
|
-
_context: {
|
|
78
|
-
doc_actions: actions,
|
|
79
|
-
...(agentPrompt ? { agent_prompt: agentPrompt } : {}),
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
getSessionStats() {
|
|
84
|
-
return {
|
|
85
|
-
docsGenerated: this.docsGeneratedThisSession,
|
|
86
|
-
docsFlagged: this.docsFlaggedThisSession,
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Detect exported functions/classes that were changed and need doc updates.
|
|
91
|
-
* Fast path: generate template JSDoc from the new signature.
|
|
92
|
-
*/
|
|
93
|
-
async detectInlineDocNeeds(filePath, content) {
|
|
94
|
-
const actions = [];
|
|
95
|
-
const exportedFunctions = extractExportedSignatures(content);
|
|
96
|
-
for (const sig of exportedFunctions) {
|
|
97
|
-
const hasDoc = hasExistingDoc(content, sig.startIndex);
|
|
98
|
-
const params = extractParamsFromSignature(sig.signature);
|
|
99
|
-
if (!hasDoc && params.length > 0) {
|
|
100
|
-
const jsdoc = generateTemplateJSDoc(sig.name, params, sig.returnType);
|
|
101
|
-
actions.push({
|
|
102
|
-
type: "jsdoc_generated",
|
|
103
|
-
entity: sig.name,
|
|
104
|
-
file: filePath,
|
|
105
|
-
change: `Generated JSDoc for ${sig.name}(${params.map((p) => p.name).join(", ")})`,
|
|
106
|
-
agentPrompt: this.docConfig.useAgentAsLlm
|
|
107
|
-
? buildInlineDocPrompt(filePath, sig.name, sig.signature)
|
|
108
|
-
: undefined,
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
else if (hasDoc && this.graph) {
|
|
112
|
-
const entity = await this.findEntity(sig.name, filePath);
|
|
113
|
-
if (entity?.signature && entity.signature !== sig.signature) {
|
|
114
|
-
actions.push({
|
|
115
|
-
type: "jsdoc_updated",
|
|
116
|
-
entity: sig.name,
|
|
117
|
-
file: filePath,
|
|
118
|
-
change: "Signature changed — doc may be stale",
|
|
119
|
-
agentPrompt: this.docConfig.useAgentAsLlm
|
|
120
|
-
? buildUpdateDocPrompt(filePath, sig.name, entity.signature, sig.signature)
|
|
121
|
-
: undefined,
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return actions;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Flag reference documentation (.md files) that may reference changed entities.
|
|
130
|
-
*/
|
|
131
|
-
async detectStaleReferences(filePath, content) {
|
|
132
|
-
if (!this.graph)
|
|
133
|
-
return [];
|
|
134
|
-
const exportedNames = extractExportedSignatures(content).map((s) => s.name);
|
|
135
|
-
if (exportedNames.length === 0)
|
|
136
|
-
return [];
|
|
137
|
-
const actions = [];
|
|
138
|
-
for (const name of exportedNames) {
|
|
139
|
-
const entity = await this.findEntity(name, filePath);
|
|
140
|
-
if (!entity)
|
|
141
|
-
continue;
|
|
142
|
-
if (entity.fan_in > 3) {
|
|
143
|
-
actions.push({
|
|
144
|
-
type: "reference_flagged",
|
|
145
|
-
entity: name,
|
|
146
|
-
file: filePath,
|
|
147
|
-
change: `High-usage symbol "${name}" (${entity.fan_in} callers) modified — check referencing docs`,
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
return actions;
|
|
152
|
-
}
|
|
153
|
-
async findEntity(name, filePath) {
|
|
154
|
-
if (!this.graph)
|
|
155
|
-
return null;
|
|
156
|
-
const entities = await this.graph.getEntitiesByFile(filePath);
|
|
157
|
-
return entities.find((e) => e.name === name) ?? null;
|
|
158
|
-
}
|
|
159
|
-
buildAgentPrompt(filePath, actions) {
|
|
160
|
-
const parts = [
|
|
161
|
-
"Documentation may need updating based on recent code changes:",
|
|
162
|
-
"",
|
|
163
|
-
];
|
|
164
|
-
for (const action of actions) {
|
|
165
|
-
if (action.agentPrompt) {
|
|
166
|
-
parts.push(action.agentPrompt);
|
|
167
|
-
parts.push("");
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
parts.push(`- ${action.file}: ${action.change}`);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
parts.push("");
|
|
174
|
-
parts.push("Please review and update documentation as needed, following the existing doc style in this project.");
|
|
175
|
-
return parts.join("\n");
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
function isCodeFile(filePath) {
|
|
179
|
-
return /\.[jt]sx?$/.test(filePath);
|
|
180
|
-
}
|
|
181
|
-
function extractNewContent(args) {
|
|
182
|
-
if (typeof args.new_str === "string")
|
|
183
|
-
return args.new_str;
|
|
184
|
-
if (typeof args.new_string === "string")
|
|
185
|
-
return args.new_string;
|
|
186
|
-
if (typeof args.content === "string")
|
|
187
|
-
return args.content;
|
|
188
|
-
if (typeof args.after === "string")
|
|
189
|
-
return args.after;
|
|
190
|
-
return null;
|
|
191
|
-
}
|
|
192
|
-
function extractExportedSignatures(content) {
|
|
193
|
-
const results = [];
|
|
194
|
-
const pattern = /(?:export\s+)?(?:async\s+)?function\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*(\([^)]*\))(?:\s*:\s*([^{]+?))?(?:\s*\{)/g;
|
|
195
|
-
let match;
|
|
196
|
-
match = pattern.exec(content);
|
|
197
|
-
while (match !== null) {
|
|
198
|
-
const name = match[1];
|
|
199
|
-
const params = match[2];
|
|
200
|
-
const returnType = match[3]?.trim() ?? null;
|
|
201
|
-
results.push({
|
|
202
|
-
name,
|
|
203
|
-
signature: `${name}${params}${returnType ? `: ${returnType}` : ""}`,
|
|
204
|
-
startIndex: match.index,
|
|
205
|
-
returnType,
|
|
206
|
-
});
|
|
207
|
-
match = pattern.exec(content);
|
|
208
|
-
}
|
|
209
|
-
return results;
|
|
210
|
-
}
|
|
211
|
-
function hasExistingDoc(content, signatureIndex) {
|
|
212
|
-
const before = content.slice(Math.max(0, signatureIndex - 200), signatureIndex);
|
|
213
|
-
return /\/\*\*[\s\S]*?\*\/\s*$/.test(before);
|
|
214
|
-
}
|
|
215
|
-
function extractParamsFromSignature(signature) {
|
|
216
|
-
const match = signature.match(/\(([^)]*)\)/);
|
|
217
|
-
if (!match || !match[1]?.trim())
|
|
218
|
-
return [];
|
|
219
|
-
return match[1]
|
|
220
|
-
.split(",")
|
|
221
|
-
.map((p) => {
|
|
222
|
-
const trimmed = p.trim();
|
|
223
|
-
const parts = trimmed.split(/\s*:\s*/);
|
|
224
|
-
const name = parts[0]?.replace(/[?]$/, "").trim() ?? "";
|
|
225
|
-
const type = parts[1]?.trim() ?? null;
|
|
226
|
-
return { name, type };
|
|
227
|
-
})
|
|
228
|
-
.filter((p) => p.name.length > 0);
|
|
229
|
-
}
|
|
230
|
-
function generateTemplateJSDoc(name, params, returnType) {
|
|
231
|
-
const lines = ["/**"];
|
|
232
|
-
for (const param of params) {
|
|
233
|
-
const typeStr = param.type ? ` {${param.type}}` : "";
|
|
234
|
-
lines.push(` * @param${typeStr} ${param.name}`);
|
|
235
|
-
}
|
|
236
|
-
if (returnType && returnType !== "void") {
|
|
237
|
-
lines.push(` * @returns {${returnType}}`);
|
|
238
|
-
}
|
|
239
|
-
lines.push(" */");
|
|
240
|
-
return lines.join("\n");
|
|
241
|
-
}
|
|
242
|
-
function buildInlineDocPrompt(filePath, funcName, signature) {
|
|
243
|
-
return `Generate a concise JSDoc comment for the function "${funcName}" in ${filePath}. Signature: ${signature}. Follow the existing documentation style in this file. Focus on what the function does, not how.`;
|
|
244
|
-
}
|
|
245
|
-
function buildUpdateDocPrompt(filePath, funcName, oldSignature, newSignature) {
|
|
246
|
-
return `The function "${funcName}" in ${filePath} had its signature changed from "${oldSignature}" to "${newSignature}". Update the JSDoc above the function to reflect the new parameters. Preserve the existing description.`;
|
|
247
|
-
}
|