@denizokcu/haze 1.7.11 → 1.7.12

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.
Files changed (80) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +113 -97
  3. package/assets/graph-grammars/NOTICE.md +21 -0
  4. package/assets/graph-grammars/tree-sitter-javascript.wasm +0 -0
  5. package/assets/graph-grammars/tree-sitter-tsx.wasm +0 -0
  6. package/assets/graph-grammars/tree-sitter-typescript.wasm +0 -0
  7. package/assets/graph-grammars/web-tree-sitter.cjs +4116 -0
  8. package/assets/graph-grammars/web-tree-sitter.cjs.map +7 -0
  9. package/assets/graph-grammars/web-tree-sitter.js +4056 -0
  10. package/assets/graph-grammars/web-tree-sitter.js.map +7 -0
  11. package/assets/graph-grammars/web-tree-sitter.wasm +0 -0
  12. package/assets/graph-grammars/web-tree-sitter.wasm.map +55 -0
  13. package/dist/buildInfo.json +3 -3
  14. package/dist/cli/chat/inputSuggestions.js +1 -0
  15. package/dist/cli/chat/sessionLifecycle.js +2 -1
  16. package/dist/cli/chat/sessionRecorder.js +4 -1
  17. package/dist/cli/chat/startupSequence.d.ts +2 -0
  18. package/dist/cli/chat/startupSequence.js +6 -0
  19. package/dist/cli/commands/chat.js +5 -2
  20. package/dist/cli/commands/commandHelp.js +4 -1
  21. package/dist/cli/commands/commands.js +2 -0
  22. package/dist/cli/commands/formatters.js +28 -0
  23. package/dist/cli/commands/graphCommand.d.ts +2 -0
  24. package/dist/cli/commands/graphCommand.js +60 -0
  25. package/dist/cli/commands/initCommand.js +14 -0
  26. package/dist/cli/commands/streaming/agentAttempt.js +11 -1
  27. package/dist/cli/commands/streaming/attemptOutcome.js +1 -1
  28. package/dist/cli/commands/streaming/attemptSetup.d.ts +3 -0
  29. package/dist/cli/commands/streaming/attemptSetup.js +8 -3
  30. package/dist/cli/commands/streaming/goalSupervisor.js +5 -3
  31. package/dist/cli/commands/streaming/prepareStep.js +1 -0
  32. package/dist/cli/commands/streaming/streamLoop.d.ts +2 -0
  33. package/dist/cli/commands/streaming/streamLoop.js +3 -0
  34. package/dist/cli/commands/streaming/toolPartHandlers.js +7 -1
  35. package/dist/cli/commands/streaming.js +5 -0
  36. package/dist/core/agent/compaction.d.ts +1 -0
  37. package/dist/core/agent/compaction.js +3 -0
  38. package/dist/core/graph/analyze.d.ts +61 -0
  39. package/dist/core/graph/analyze.js +274 -0
  40. package/dist/core/graph/buildGraph.d.ts +44 -0
  41. package/dist/core/graph/buildGraph.js +290 -0
  42. package/dist/core/graph/digest.d.ts +2 -0
  43. package/dist/core/graph/digest.js +40 -0
  44. package/dist/core/graph/extract.d.ts +58 -0
  45. package/dist/core/graph/extract.js +394 -0
  46. package/dist/core/graph/model.d.ts +63 -0
  47. package/dist/core/graph/model.js +96 -0
  48. package/dist/core/graph/query.d.ts +69 -0
  49. package/dist/core/graph/query.js +391 -0
  50. package/dist/core/graph/store.d.ts +64 -0
  51. package/dist/core/graph/store.js +171 -0
  52. package/dist/core/process/runBoundedProcess.js +12 -6
  53. package/dist/core/safety/untrustedEnvelopes.d.ts +6 -0
  54. package/dist/core/safety/untrustedEnvelopes.js +17 -2
  55. package/dist/core/subagent/executionProfiles.js +4 -4
  56. package/dist/core/tasks/taskStorage.js +11 -1
  57. package/dist/core/validation/outputParser.js +16 -8
  58. package/dist/llm/hazeTools.d.ts +2 -12426
  59. package/dist/llm/hazeTools.js +2 -0
  60. package/dist/llm/lspTools.d.ts +3 -12622
  61. package/dist/llm/requestContext.d.ts +3 -0
  62. package/dist/llm/requestContext.js +13 -4
  63. package/dist/llm/subagentRunner.d.ts +2 -308
  64. package/dist/llm/systemPrompt.js +7 -4
  65. package/dist/llm/toolResultTypes.d.ts +1 -1
  66. package/dist/llm/tools/fetchTool.d.ts +2 -1221
  67. package/dist/llm/tools/fileTools.d.ts +2 -7768
  68. package/dist/llm/tools/graphAdvisory.d.ts +22 -0
  69. package/dist/llm/tools/graphAdvisory.js +68 -0
  70. package/dist/llm/tools/graphTools.d.ts +13 -0
  71. package/dist/llm/tools/graphTools.js +195 -0
  72. package/dist/llm/tools/processTool.d.ts +2 -1081
  73. package/dist/llm/tools/shellTool.d.ts +2 -1513
  74. package/dist/llm/tools/storedOutputTool.d.ts +2 -355
  75. package/dist/llm/tools/taskTool.d.ts +2 -489
  76. package/dist/llm/tools/toolContext.js +24 -9
  77. package/dist/llm/tools/toolContextState.d.ts +3 -0
  78. package/dist/llm/tools/toolContextState.js +2 -1
  79. package/dist/skills/skillTools.js +4 -1
  80. package/package.json +18 -15
@@ -0,0 +1,22 @@
1
+ export interface GraphAffectedNeighbor {
2
+ symbol: string;
3
+ kind: string;
4
+ /** e.g. `calls [INFERRED] at src/foo.ts:42` */
5
+ via: string;
6
+ }
7
+ export interface PostMutationGraphResult {
8
+ ok: boolean;
9
+ stale: boolean;
10
+ files: Array<{
11
+ path: string;
12
+ affectedNeighbors: GraphAffectedNeighbor[];
13
+ }>;
14
+ truncated: boolean;
15
+ }
16
+ export type PostMutationGraphAdvisory = (paths: readonly string[]) => Promise<PostMutationGraphResult | undefined>;
17
+ /**
18
+ * Build the advisory hook. Self-disables (returns undefined) when no graph
19
+ * exists yet — building one is an explicit model/user action, never a
20
+ * side effect of a mutation.
21
+ */
22
+ export declare function createPostMutationGraphAdvisory(): PostMutationGraphAdvisory;
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Bounded graph advisory attached to successful file-mutation results, the
3
+ * graph-side twin of the automatic LSP diagnostics hook: after editing a file,
4
+ * the model immediately sees which symbols elsewhere depend on it (reverse
5
+ * call/import edges with sites) without another tool call, plus a staleness
6
+ * note for the touched file.
7
+ *
8
+ * Advisory only — it orients validation scope and follow-up edits; it never
9
+ * counts as validation evidence and never blocks a mutation.
10
+ */
11
+ import { workspaceRoot } from '../../utils/path.js';
12
+ import { buildGraphIndex } from '../../core/graph/model.js';
13
+ import { graphStoreFor, readGraph } from '../../core/graph/store.js';
14
+ const ADVISORY_FILE_LIMIT = 8;
15
+ const ADVISORY_PER_FILE = 5;
16
+ const ADVISORY_TOTAL = 12;
17
+ /**
18
+ * Build the advisory hook. Self-disables (returns undefined) when no graph
19
+ * exists yet — building one is an explicit model/user action, never a
20
+ * side effect of a mutation.
21
+ */
22
+ export function createPostMutationGraphAdvisory() {
23
+ return async (paths) => {
24
+ const uniquePaths = [...new Set(paths)].slice(0, ADVISORY_FILE_LIMIT);
25
+ if (uniquePaths.length === 0)
26
+ return undefined;
27
+ const store = graphStoreFor(workspaceRoot());
28
+ let graph;
29
+ try {
30
+ graph = await readGraph(store);
31
+ }
32
+ catch {
33
+ return undefined; // Unreadable graph: silent, the tools surface it on demand.
34
+ }
35
+ if (!graph)
36
+ return undefined;
37
+ const index = buildGraphIndex(graph);
38
+ const files = [];
39
+ let remaining = ADVISORY_TOTAL;
40
+ for (const filePath of uniquePaths) {
41
+ if (remaining <= 0)
42
+ break;
43
+ const normalized = filePath.replace(/\\/g, '/');
44
+ // Symbol nodes defined in the mutated file.
45
+ const owned = graph.nodes.filter(node => node.kind !== 'file' && node.file === normalized);
46
+ const neighbors = [];
47
+ const seen = new Set();
48
+ for (const symbol of owned) {
49
+ for (const edge of index.in.get(symbol.id) ?? []) {
50
+ if (edge.relation === 'defines')
51
+ continue; // the file->symbol edge, not a dependency
52
+ const source = index.nodes.get(edge.source);
53
+ if (!source || source.file === normalized || seen.has(source.id))
54
+ continue;
55
+ seen.add(source.id);
56
+ neighbors.push({ symbol: source.label, kind: source.kind, via: `${edge.relation} [${edge.confidence}] at ${edge.file ?? source.file}:${edge.line ?? '?'}` });
57
+ remaining -= 1;
58
+ if (neighbors.length >= ADVISORY_PER_FILE || remaining <= 0)
59
+ break;
60
+ }
61
+ if (neighbors.length >= ADVISORY_PER_FILE || remaining <= 0)
62
+ break;
63
+ }
64
+ files.push({ path: normalized, affectedNeighbors: neighbors });
65
+ }
66
+ return { ok: true, stale: true, files, truncated: remaining <= 0 || uniquePaths.length < new Set(paths).size };
67
+ };
68
+ }
@@ -0,0 +1,13 @@
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 { type ToolSet } from 'ai';
13
+ export declare const graphTools: ToolSet;
@@ -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
+ };