@denizokcu/haze 1.7.11 → 1.8.0
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/CHANGELOG.md +56 -0
- package/README.md +142 -102
- package/SECURITY.md +1 -1
- package/assets/graph-grammars/NOTICE.md +21 -0
- package/assets/graph-grammars/tree-sitter-javascript.wasm +0 -0
- package/assets/graph-grammars/tree-sitter-tsx.wasm +0 -0
- package/assets/graph-grammars/tree-sitter-typescript.wasm +0 -0
- package/assets/graph-grammars/web-tree-sitter.cjs +4116 -0
- package/assets/graph-grammars/web-tree-sitter.cjs.map +7 -0
- package/assets/graph-grammars/web-tree-sitter.js +4056 -0
- package/assets/graph-grammars/web-tree-sitter.js.map +7 -0
- package/assets/graph-grammars/web-tree-sitter.wasm +0 -0
- package/assets/graph-grammars/web-tree-sitter.wasm.map +55 -0
- package/bin/haze.js +47 -19
- package/dist/buildInfo.json +3 -3
- package/dist/cli/chat/BusyBar.d.ts +1 -2
- package/dist/cli/chat/ChatHeader.d.ts +6 -0
- package/dist/cli/chat/ChatHeader.js +11 -0
- package/dist/cli/chat/ChatScreen.d.ts +16 -0
- package/dist/cli/chat/ChatScreen.js +399 -0
- package/dist/cli/chat/ChatScreenView.d.ts +68 -0
- package/dist/cli/chat/ChatScreenView.js +47 -0
- package/dist/cli/chat/LiveTail.d.ts +11 -0
- package/dist/cli/chat/LiveTail.js +26 -0
- package/dist/cli/chat/TaskBar.d.ts +3 -2
- package/dist/cli/chat/TaskBar.js +4 -0
- package/dist/cli/chat/agentTurnRunner.d.ts +12 -0
- package/dist/cli/chat/agentTurnRunner.js +177 -0
- package/dist/cli/chat/busyIndicator.js +9 -5
- package/dist/cli/chat/chatMetrics.d.ts +7 -0
- package/dist/cli/chat/chatMetrics.js +15 -1
- package/dist/cli/chat/chatViewModel.d.ts +85 -0
- package/dist/cli/chat/chatViewModel.js +66 -0
- package/dist/cli/chat/fileMentionSuggestions.d.ts +0 -14
- package/dist/cli/chat/fileMentionSuggestions.js +4 -21
- package/dist/cli/chat/inputSuggestions.js +1 -0
- package/dist/cli/chat/liveTheme.d.ts +11 -0
- package/dist/cli/chat/liveTheme.js +26 -0
- package/dist/cli/chat/messageFinalize.d.ts +4 -0
- package/dist/cli/chat/messageFinalize.js +8 -0
- package/dist/cli/chat/messages.js +1 -1
- package/dist/cli/chat/pickerOpeners.d.ts +23 -0
- package/dist/cli/chat/pickerOpeners.js +36 -0
- package/dist/cli/chat/promptSessionState.d.ts +11 -0
- package/dist/cli/chat/promptSessionState.js +39 -0
- package/dist/cli/chat/renderMetrics.d.ts +8 -0
- package/dist/cli/chat/renderMetrics.js +14 -0
- package/dist/cli/chat/resizeGuard.d.ts +11 -0
- package/dist/cli/chat/resizeGuard.js +25 -0
- package/dist/cli/chat/screenDeps.d.ts +116 -0
- package/dist/cli/chat/screenDeps.js +1 -0
- package/dist/cli/chat/sessionLifecycle.d.ts +2 -0
- package/dist/cli/chat/sessionLifecycle.js +6 -2
- package/dist/cli/chat/sessionRecorder.js +4 -1
- package/dist/cli/chat/settingsSelection.d.ts +33 -0
- package/dist/cli/chat/settingsSelection.js +46 -0
- package/dist/cli/chat/skillNotices.d.ts +18 -0
- package/dist/cli/chat/skillNotices.js +26 -0
- package/dist/cli/chat/startupInfo.js +1 -1
- package/dist/cli/chat/startupSequence.d.ts +2 -0
- package/dist/cli/chat/startupSequence.js +6 -0
- package/dist/cli/chat/submitPipeline.d.ts +8 -0
- package/dist/cli/chat/submitPipeline.js +141 -0
- package/dist/cli/chat/terminalControl.js +1 -1
- package/dist/cli/chat/toolSummaries.d.ts +29 -0
- package/dist/cli/chat/toolSummaries.js +268 -0
- package/dist/cli/chat/turnState.d.ts +8 -0
- package/dist/cli/chat/turnState.js +1 -0
- package/dist/cli/chat/userCommandFlow.d.ts +21 -0
- package/dist/cli/chat/userCommandFlow.js +66 -0
- package/dist/cli/chat/userCommandRunner.d.ts +14 -0
- package/dist/cli/chat/userCommandRunner.js +56 -0
- package/dist/cli/chat/wizard/providerHandlers.js +19 -2
- package/dist/cli/chat/wizardTrail.d.ts +22 -0
- package/dist/cli/chat/wizardTrail.js +55 -0
- package/dist/cli/commands/chat.d.ts +1 -13
- package/dist/cli/commands/chat.js +10 -795
- package/dist/cli/commands/commandHelp.js +11 -6
- package/dist/cli/commands/commandSuggest.d.ts +2 -0
- package/dist/cli/commands/commandSuggest.js +35 -0
- package/dist/cli/commands/commands.js +12 -3
- package/dist/cli/commands/formatters.d.ts +1 -23
- package/dist/cli/commands/formatters.js +3 -224
- package/dist/cli/commands/graphCommand.d.ts +2 -0
- package/dist/cli/commands/graphCommand.js +60 -0
- package/dist/cli/commands/initCommand.js +14 -0
- package/dist/cli/commands/modelCommand.js +11 -7
- package/dist/cli/commands/reasoningCommand.js +3 -3
- package/dist/cli/commands/runCommand.js +6 -2
- package/dist/cli/commands/streaming/agentAttempt.js +11 -1
- package/dist/cli/commands/streaming/attemptLifecycle.js +1 -0
- package/dist/cli/commands/streaming/attemptOutcome.js +8 -3
- package/dist/cli/commands/streaming/attemptSetup.d.ts +4 -0
- package/dist/cli/commands/streaming/attemptSetup.js +34 -5
- package/dist/cli/commands/streaming/goalCheckpoint.d.ts +1 -1
- package/dist/cli/commands/streaming/goalSupervisor.js +5 -3
- package/dist/cli/commands/streaming/prepareStep.js +1 -0
- package/dist/cli/commands/streaming/stepProjection.d.ts +59 -0
- package/dist/cli/commands/streaming/stepProjection.js +54 -0
- package/dist/cli/commands/streaming/streamLoop.d.ts +2 -0
- package/dist/cli/commands/streaming/streamLoop.js +34 -23
- package/dist/cli/commands/streaming/toolGroupRenderer.js +1 -1
- package/dist/cli/commands/streaming/toolPartHandlers.js +8 -2
- package/dist/cli/commands/streaming.d.ts +3 -1
- package/dist/cli/commands/streaming.js +5 -0
- package/dist/cli/commands/wizardFlow.d.ts +2 -0
- package/dist/cli/commands/wizardFlow.js +3 -0
- package/dist/cli/index.js +8 -4
- package/dist/cli/terminalTitle.js +9 -3
- package/dist/config/contextFiles.d.ts +2 -5
- package/dist/config/contextFiles.js +1 -1
- package/dist/config/inputHistory.js +2 -2
- package/dist/config/providerAuth.js +2 -2
- package/dist/config/providerModelFacts.js +5 -0
- package/dist/config/providerPresets.js +1 -1
- package/dist/config/settings.d.ts +7 -0
- package/dist/config/settings.js +9 -2
- package/dist/config/updateCheck.js +2 -2
- package/dist/core/agent/compaction.d.ts +1 -0
- package/dist/core/agent/compaction.js +3 -0
- package/dist/core/agent/completionController.d.ts +1 -1
- package/dist/core/agent/contextBudget.d.ts +1 -1
- package/dist/core/agent/goalPolicy.js +8 -2
- package/dist/core/agent/overflow.js +5 -0
- package/dist/core/agent/toolCapabilities.js +14 -0
- package/dist/core/agent/userCommands.d.ts +53 -0
- package/dist/core/agent/userCommands.js +116 -0
- package/dist/core/agent/workState.d.ts +3 -1
- package/dist/core/agent/workState.js +57 -26
- package/dist/core/contextFileTypes.d.ts +12 -0
- package/dist/core/contextFileTypes.js +1 -0
- package/dist/core/graph/analyze.d.ts +61 -0
- package/dist/core/graph/analyze.js +274 -0
- package/dist/core/graph/buildGraph.d.ts +44 -0
- package/dist/core/graph/buildGraph.js +290 -0
- package/dist/core/graph/digest.d.ts +2 -0
- package/dist/core/graph/digest.js +40 -0
- package/dist/core/graph/extract.d.ts +58 -0
- package/dist/core/graph/extract.js +394 -0
- package/dist/core/graph/model.d.ts +63 -0
- package/dist/core/graph/model.js +96 -0
- package/dist/core/graph/query.d.ts +69 -0
- package/dist/core/graph/query.js +391 -0
- package/dist/core/graph/store.d.ts +64 -0
- package/dist/core/graph/store.js +171 -0
- package/dist/core/limits.d.ts +2 -0
- package/dist/core/limits.js +2 -0
- package/dist/core/log/llmLog.js +2 -2
- package/dist/{config → core/persistence}/privateStorage.js +1 -1
- package/dist/core/process/runBoundedProcess.d.ts +7 -4
- package/dist/core/process/runBoundedProcess.js +22 -11
- package/dist/core/safety/redaction.d.ts +2 -0
- package/dist/core/safety/redaction.js +26 -5
- package/dist/core/safety/secretPaths.js +12 -3
- package/dist/core/safety/untrustedEnvelopes.d.ts +6 -0
- package/dist/core/safety/untrustedEnvelopes.js +17 -2
- package/dist/core/safety/urlGuard.js +2 -0
- package/dist/core/session/sessionStore.d.ts +8 -1
- package/dist/core/session/sessionStore.js +15 -4
- package/dist/core/shellOutput/reducers/validation.d.ts +1 -1
- package/dist/core/shellOutput/types.d.ts +1 -1
- package/dist/core/subagent/executionProfiles.js +4 -4
- package/dist/core/tasks/taskStorage.js +11 -1
- package/dist/{llm → core}/toolResultTypes.d.ts +1 -1
- package/dist/core/validation/outputParser.d.ts +1 -1
- package/dist/core/validation/outputParser.js +16 -8
- package/dist/llm/hazeTools.d.ts +2 -12426
- package/dist/llm/hazeTools.js +4 -0
- package/dist/llm/lsp/pool.js +1 -1
- package/dist/llm/lsp/workspaceEdit.d.ts +1 -1
- package/dist/llm/lspTools.d.ts +3 -12622
- package/dist/llm/requestContext.d.ts +6 -0
- package/dist/llm/requestContext.js +28 -7
- package/dist/llm/subagentRunner.d.ts +2 -308
- package/dist/llm/systemPrompt.js +17 -7
- package/dist/llm/toolGroups.d.ts +534 -0
- package/dist/llm/toolGroups.js +57 -0
- package/dist/llm/tools/editMatch.d.ts +1 -1
- package/dist/llm/tools/failures.d.ts +1 -1
- package/dist/llm/tools/fetchTool.d.ts +2 -1221
- package/dist/llm/tools/fileToolShared.d.ts +1 -1
- package/dist/llm/tools/fileToolShared.js +1 -1
- package/dist/llm/tools/fileTools.d.ts +2 -7768
- package/dist/llm/tools/fileTools.js +1 -1
- package/dist/llm/tools/gitTools.d.ts +12 -0
- package/dist/llm/tools/gitTools.js +527 -0
- package/dist/llm/tools/graphAdvisory.d.ts +22 -0
- package/dist/llm/tools/graphAdvisory.js +68 -0
- package/dist/llm/tools/graphTools.d.ts +13 -0
- package/dist/llm/tools/graphTools.js +195 -0
- package/dist/llm/tools/processTool.d.ts +2 -1081
- package/dist/llm/tools/readRecovery.d.ts +1 -1
- package/dist/llm/tools/replaceInFiles.d.ts +1 -1
- package/dist/llm/tools/replaceInFiles.js +1 -1
- package/dist/llm/tools/shellTool.d.ts +2 -1513
- package/dist/llm/tools/storedOutputTool.d.ts +2 -355
- package/dist/llm/tools/taskTool.d.ts +2 -489
- package/dist/llm/tools/taskTool.js +4 -1
- package/dist/llm/tools/toolContext.js +29 -11
- package/dist/llm/tools/toolContextState.d.ts +4 -1
- package/dist/llm/tools/toolContextState.js +2 -1
- package/dist/llm/tools/workspaceFile.d.ts +2 -2
- package/dist/llm/tools/workspaceFile.js +10 -5
- package/dist/skills/SkillRegistry.js +1 -1
- package/dist/skills/builder/SkillBuilder.js +1 -1
- package/dist/skills/plugins/installer.js +1 -1
- package/dist/skills/plugins/runtime.js +1 -1
- package/dist/skills/skillTools.js +4 -1
- package/dist/ui/components/MarkdownText.d.ts +14 -0
- package/dist/ui/components/MarkdownText.js +77 -12
- package/dist/ui/components/NativeIndicators.js +5 -1
- package/dist/ui/components/StreamingMarkdownText.d.ts +3 -1
- package/dist/ui/components/StreamingMarkdownText.js +39 -11
- package/dist/ui/components/TextInput.d.ts +1 -2
- package/dist/ui/components/TextInput.js +79 -9
- package/dist/ui/components/WizardChoices.d.ts +1 -2
- package/dist/ui/components/useInputSuggestions.d.ts +1 -1
- package/dist/ui/components/useInputSuggestions.js +1 -1
- package/dist/ui/mentionDetection.d.ts +20 -0
- package/dist/ui/mentionDetection.js +24 -0
- package/dist/ui/terminalColors.d.ts +4 -4
- package/dist/ui/terminalColors.js +23 -6
- package/dist/ui/terminalSanitize.js +8 -3
- package/dist/ui/textGeometry.d.ts +2 -0
- package/dist/ui/textGeometry.js +6 -0
- package/dist/ui/themes/registry.js +33 -33
- package/dist/utils/openPath.js +7 -0
- package/package.json +22 -19
- /package/dist/{llm/tools → core/ignore}/gitIgnore.d.ts +0 -0
- /package/dist/{llm/tools → core/ignore}/gitIgnore.js +0 -0
- /package/dist/{config → core}/paths.d.ts +0 -0
- /package/dist/{config → core}/paths.js +0 -0
- /package/dist/{config → core/persistence}/privateStorage.d.ts +0 -0
- /package/dist/{llm → core}/toolResultTypes.js +0 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The code-graph tool set (`graphQuery`, `graphExplain`, `graphPath`,
|
|
3
|
+
* `graphAffected`, `graphRebuild`) over the persistent workspace symbol graph
|
|
4
|
+
* built by `core/graph`.
|
|
5
|
+
*
|
|
6
|
+
* The graph is a deterministic AST-derived map of the codebase: querying it
|
|
7
|
+
* is cheap and bounded, edges carry EXTRACTED/INFERRED confidence, and every
|
|
8
|
+
* result annotates staleness so the model knows when the map lags the working
|
|
9
|
+
* tree. Graph output is orientation and retrieval — never validation
|
|
10
|
+
* evidence.
|
|
11
|
+
*/
|
|
12
|
+
import { tool } from 'ai';
|
|
13
|
+
import { z } from 'zod';
|
|
14
|
+
import { workspaceRoot } from '../../utils/path.js';
|
|
15
|
+
import { buildGraphIndex } from '../../core/graph/model.js';
|
|
16
|
+
import { graphStatus, graphStoreFor } from '../../core/graph/store.js';
|
|
17
|
+
import { findNodeCandidates, queryGraph, renderPath, shortestPath } from '../../core/graph/query.js';
|
|
18
|
+
import { affectedBySymbol } from '../../core/graph/analyze.js';
|
|
19
|
+
import { buildWorkspaceGraph } from '../../core/graph/buildGraph.js';
|
|
20
|
+
/** Load the stored graph and index it, with a signature-based staleness check. */
|
|
21
|
+
async function loadGraphIndex() {
|
|
22
|
+
const store = graphStoreFor(workspaceRoot());
|
|
23
|
+
try {
|
|
24
|
+
const status = await graphStatus(store);
|
|
25
|
+
if (!status.exists) {
|
|
26
|
+
return {
|
|
27
|
+
ok: false,
|
|
28
|
+
reasonCode: 'graph_not_built',
|
|
29
|
+
error: 'No code graph for this workspace yet.',
|
|
30
|
+
suggestedNextStep: 'Call graphRebuild first (deterministic tree-sitter extraction, no LLM cost, incremental on later runs), or ask the user to run /graph.',
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (!status.graph)
|
|
34
|
+
throw new Error('graph.json disappeared between reads');
|
|
35
|
+
return { ok: true, index: buildGraphIndex(status.graph), stale: status.stale };
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
return {
|
|
39
|
+
ok: false,
|
|
40
|
+
reasonCode: 'graph_unavailable',
|
|
41
|
+
error: error instanceof Error ? error.message : String(error),
|
|
42
|
+
suggestedNextStep: 'The stored code graph is unreadable. Call graphRebuild to recreate it.',
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** Attach graph stats + staleness to a tool result; a stale map must announce itself. */
|
|
47
|
+
function graphMeta(loaded) {
|
|
48
|
+
return { graph: { nodes: loaded.index.graph.nodes.length, edges: loaded.index.graph.edges.length, builtAt: loaded.index.graph.builtAt, stale: loaded.stale } };
|
|
49
|
+
}
|
|
50
|
+
function candidateList(index, query) {
|
|
51
|
+
const candidates = findNodeCandidates(index, query, 4);
|
|
52
|
+
if (candidates.length === 0)
|
|
53
|
+
return undefined;
|
|
54
|
+
return candidates.map(node => `${node.label} (${node.kind} ${node.file}:${node.line})`).join('\n');
|
|
55
|
+
}
|
|
56
|
+
function graphNotBuilt(toolName, loaded) {
|
|
57
|
+
return { ok: false, toolName, error: loaded.error, reasonCode: loaded.reasonCode, recoverable: true, suggestedNextStep: loaded.suggestedNextStep };
|
|
58
|
+
}
|
|
59
|
+
export const graphTools = {
|
|
60
|
+
graphQuery: tool({
|
|
61
|
+
description: 'Query the persistent workspace code graph with a natural-language question (architecture, relationships, "where does X live", "what surrounds Y"). Returns a token-budgeted subgraph; prefer this over grep loops for orientation on large codebases. Edges carry EXTRACTED/INFERRED confidence. Read-only.',
|
|
62
|
+
inputSchema: z.object({
|
|
63
|
+
question: z.string().min(1).describe('Question or topic, e.g. "how is context compacted" or "theme registry"'),
|
|
64
|
+
mode: z.enum(['bfs', 'dfs']).default('bfs').describe('bfs explores broadly around matches; dfs follows one chain deeply'),
|
|
65
|
+
depth: z.number().int().min(1).max(4).default(2).describe('Traversal hops from matched nodes'),
|
|
66
|
+
budgetTokens: z.number().int().min(200).max(4000).default(1500).describe('Answer token budget'),
|
|
67
|
+
}),
|
|
68
|
+
execute: async ({ question, mode, depth, budgetTokens }) => {
|
|
69
|
+
const loaded = await loadGraphIndex();
|
|
70
|
+
if (!loaded.ok)
|
|
71
|
+
return graphNotBuilt('graphQuery', loaded);
|
|
72
|
+
try {
|
|
73
|
+
const result = queryGraph(loaded.index, question, { mode, depth, budgetTokens });
|
|
74
|
+
if (result.seedCount === 0) {
|
|
75
|
+
return { ok: true, toolName: 'graphQuery', question, answer: result.answer, hint: 'No graph nodes matched. Try different terms, grep for the exact string, or graphRebuild if the codebase changed.', ...graphMeta(loaded) };
|
|
76
|
+
}
|
|
77
|
+
return { ok: true, toolName: 'graphQuery', question, mode, answer: result.answer, truncated: result.truncated, seeds: result.seedCount, nodes: result.nodeCount, edges: result.edgeCount, ...graphMeta(loaded) };
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
return { ok: false, toolName: 'graphQuery', error: error instanceof Error ? error.message : String(error), recoverable: true, suggestedNextStep: 'Retry with a simpler question, or rebuild the graph with graphRebuild.' };
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
}),
|
|
84
|
+
graphExplain: tool({
|
|
85
|
+
description: 'Explain one symbol or file from the code graph: definition site, community, degree, and its neighbors grouped by relation (calls, imports, inherits). Read-only.',
|
|
86
|
+
inputSchema: z.object({
|
|
87
|
+
symbol: z.string().min(1).describe('Symbol name or file path'),
|
|
88
|
+
}),
|
|
89
|
+
execute: async ({ symbol }) => {
|
|
90
|
+
const loaded = await loadGraphIndex();
|
|
91
|
+
if (!loaded.ok)
|
|
92
|
+
return graphNotBuilt('graphExplain', loaded);
|
|
93
|
+
const candidates = findNodeCandidates(loaded.index, symbol, 1);
|
|
94
|
+
if (candidates.length === 0) {
|
|
95
|
+
return { ok: true, toolName: 'graphExplain', symbol, error: `No graph node matches "${symbol}".`, hint: 'Try grep for discovery, or graphRebuild if the codebase changed.', ...graphMeta(loaded) };
|
|
96
|
+
}
|
|
97
|
+
const node = candidates[0];
|
|
98
|
+
const index = loaded.index;
|
|
99
|
+
const describe = (edges, direction) => edges.map(edge => {
|
|
100
|
+
const other = index.nodes.get(direction === 'out' ? edge.target : edge.source);
|
|
101
|
+
const at = edge.line ? ` (${edge.file}:${edge.line})` : '';
|
|
102
|
+
return other ? `${edge.relation} [${edge.confidence}] ${other.label} (${other.kind} ${other.file}:${other.line})${at}` : undefined;
|
|
103
|
+
}).filter((line) => line != null);
|
|
104
|
+
return {
|
|
105
|
+
ok: true,
|
|
106
|
+
toolName: 'graphExplain',
|
|
107
|
+
symbol,
|
|
108
|
+
node: { label: node.label, kind: node.kind, file: node.file, line: node.line, ...(node.community != null ? { community: node.community } : {}) },
|
|
109
|
+
degree: (index.out.get(node.id)?.length ?? 0) + (index.in.get(node.id)?.length ?? 0),
|
|
110
|
+
outgoing: describe((index.out.get(node.id) ?? []).slice(0, 12), 'out'),
|
|
111
|
+
incoming: describe((index.in.get(node.id) ?? []).slice(0, 12), 'in'),
|
|
112
|
+
...graphMeta(loaded),
|
|
113
|
+
};
|
|
114
|
+
},
|
|
115
|
+
}),
|
|
116
|
+
graphPath: tool({
|
|
117
|
+
description: 'Trace the shortest relationship path between two symbols/files in the code graph, hop by hop with relations and confidence. Answers "how does a request get from A to B". Read-only.',
|
|
118
|
+
inputSchema: z.object({
|
|
119
|
+
from: z.string().min(1).describe('Starting symbol name or file path'),
|
|
120
|
+
to: z.string().min(1).describe('Target symbol name or file path'),
|
|
121
|
+
}),
|
|
122
|
+
execute: async ({ from, to }) => {
|
|
123
|
+
const loaded = await loadGraphIndex();
|
|
124
|
+
if (!loaded.ok)
|
|
125
|
+
return graphNotBuilt('graphPath', loaded);
|
|
126
|
+
const fromNode = findNodeCandidates(loaded.index, from, 1)[0];
|
|
127
|
+
const toNode = findNodeCandidates(loaded.index, to, 1)[0];
|
|
128
|
+
if (!fromNode || !toNode) {
|
|
129
|
+
return { ok: true, toolName: 'graphPath', from, to, error: `No graph node matches ${!fromNode ? `"${from}"` : ''}${!fromNode && !toNode ? ' or ' : ''}${!toNode ? `"${to}"` : ''}.`, hint: !fromNode ? candidateList(loaded.index, from) : candidateList(loaded.index, to), ...graphMeta(loaded) };
|
|
130
|
+
}
|
|
131
|
+
const path = shortestPath(loaded.index, fromNode.id, toNode.id);
|
|
132
|
+
if (!path) {
|
|
133
|
+
return { ok: true, toolName: 'graphPath', from, to, error: `No path found between ${fromNode.label} and ${toNode.label} within 8 hops.`, ...graphMeta(loaded) };
|
|
134
|
+
}
|
|
135
|
+
return { ok: true, toolName: 'graphPath', from: fromNode.label, to: toNode.label, hops: path.edges.length, answer: renderPath(loaded.index, path), ...graphMeta(loaded) };
|
|
136
|
+
},
|
|
137
|
+
}),
|
|
138
|
+
graphAffected: tool({
|
|
139
|
+
description: 'Reverse blast radius of a symbol: who calls/inherits/imports it, transitively, with relation sites. Use before risky edits and to choose which files/tests a change should cover. Advisory context only — never validation evidence. Read-only.',
|
|
140
|
+
inputSchema: z.object({
|
|
141
|
+
symbol: z.string().min(1).describe('Symbol name or file path'),
|
|
142
|
+
maxDepth: z.number().int().min(1).max(5).default(3).describe('How many call/import hops to follow back'),
|
|
143
|
+
}),
|
|
144
|
+
execute: async ({ symbol, maxDepth }) => {
|
|
145
|
+
const loaded = await loadGraphIndex();
|
|
146
|
+
if (!loaded.ok)
|
|
147
|
+
return graphNotBuilt('graphAffected', loaded);
|
|
148
|
+
const candidates = findNodeCandidates(loaded.index, symbol, 1);
|
|
149
|
+
if (candidates.length === 0) {
|
|
150
|
+
return { ok: true, toolName: 'graphAffected', symbol, error: `No graph node matches "${symbol}".`, hint: candidateList(loaded.index, symbol), ...graphMeta(loaded) };
|
|
151
|
+
}
|
|
152
|
+
const affected = affectedBySymbol(loaded.index, candidates[0].id, maxDepth);
|
|
153
|
+
return {
|
|
154
|
+
ok: true,
|
|
155
|
+
toolName: 'graphAffected',
|
|
156
|
+
symbol,
|
|
157
|
+
affected: affected.map(entry => ({
|
|
158
|
+
depth: entry.depth, kind: entry.kind, label: entry.label, file: entry.file,
|
|
159
|
+
via: `${entry.viaRelation} [${entry.confidence}] at ${entry.viaFile}:${entry.viaLine ?? '?'}`,
|
|
160
|
+
})),
|
|
161
|
+
...(affected.length === 0 ? { hint: 'No reverse relationships recorded. Dynamic dispatch and untyped call sites are invisible to the graph; treat this as a floor, not a ceiling.' } : {}),
|
|
162
|
+
...graphMeta(loaded),
|
|
163
|
+
};
|
|
164
|
+
},
|
|
165
|
+
}),
|
|
166
|
+
graphRebuild: tool({
|
|
167
|
+
description: 'Build or incrementally refresh the workspace code graph (deterministic tree-sitter extraction, no LLM cost; incremental rebuilds only re-parse changed files). Needed once before graphQuery/graphExplain/graphPath/graphAffected work, and after large refactors.',
|
|
168
|
+
inputSchema: z.object({
|
|
169
|
+
force: z.boolean().default(false).describe('Force a full rebuild even when the graph looks healthy (e.g. after mass file deletion)'),
|
|
170
|
+
}),
|
|
171
|
+
execute: async ({ force }) => {
|
|
172
|
+
try {
|
|
173
|
+
const result = await buildWorkspaceGraph({ force });
|
|
174
|
+
if (result.graph.nodes.length === 0) {
|
|
175
|
+
return { ok: true, toolName: 'graphRebuild', files: 0, nodes: 0, edges: 0, note: 'No supported source files found (js/ts/tsx/jsx only for now). Nothing to map.' };
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
ok: true,
|
|
179
|
+
toolName: 'graphRebuild',
|
|
180
|
+
files: result.files,
|
|
181
|
+
nodes: result.graph.nodes.length,
|
|
182
|
+
edges: result.graph.edges.length,
|
|
183
|
+
parsedFiles: result.parsedFiles,
|
|
184
|
+
cachedFiles: result.cachedFiles,
|
|
185
|
+
durationMs: result.durationMs,
|
|
186
|
+
...(result.skippedLarge > 0 ? { skippedLarge: result.skippedLarge } : {}),
|
|
187
|
+
...(result.capped ? { capped: true, note: `Capped at the file limit; the graph covers the first ${result.files} files.` } : {}),
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
return { ok: false, toolName: 'graphRebuild', error: error instanceof Error ? error.message : String(error), recoverable: true, suggestedNextStep: 'Retry, or report the error if it persists; graph unavailability never blocks other tools.' };
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
}),
|
|
195
|
+
};
|