@denizokcu/haze 0.11.0 → 1.0.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.
Files changed (230) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +23 -14
  3. package/SECURITY.md +3 -3
  4. package/dist/buildInfo.json +3 -3
  5. package/dist/cli/chat/chatMetrics.d.ts +2 -2
  6. package/dist/cli/chat/chatMetrics.js +1 -1
  7. package/dist/cli/chat/fileMentionSuggestions.js +1 -1
  8. package/dist/cli/chat/inputSuggestions.d.ts +8 -16
  9. package/dist/cli/chat/inputSuggestions.js +9 -41
  10. package/dist/cli/chat/messages.d.ts +0 -2
  11. package/dist/cli/chat/messages.js +2 -2
  12. package/dist/cli/chat/sessionLifecycle.d.ts +2 -1
  13. package/dist/cli/chat/turnState.d.ts +1 -1
  14. package/dist/cli/chat/wizardDispatch.d.ts +90 -28
  15. package/dist/cli/chat/wizardDispatch.js +250 -133
  16. package/dist/cli/commands/chat.js +14 -72
  17. package/dist/cli/commands/chatModes.d.ts +8 -1
  18. package/dist/cli/commands/chatModes.js +9 -44
  19. package/dist/cli/commands/doctor.js +1 -1
  20. package/dist/cli/commands/formatters.d.ts +3 -3
  21. package/dist/cli/commands/formatters.js +6 -25
  22. package/dist/cli/commands/providerWizard.js +2 -3
  23. package/dist/cli/commands/runCommand.js +1 -1
  24. package/dist/cli/commands/serverWizard.d.ts +34 -0
  25. package/dist/cli/commands/{mcpWizard.js → serverWizard.js} +44 -2
  26. package/dist/cli/commands/skillsWizard.d.ts +41 -0
  27. package/dist/cli/commands/{skillWizard.js → skillsWizard.js} +33 -11
  28. package/dist/cli/commands/streaming/abortCause.d.ts +2 -1
  29. package/dist/cli/commands/streaming/agentAttempt.d.ts +43 -0
  30. package/dist/cli/commands/streaming/agentAttempt.js +79 -0
  31. package/dist/cli/commands/streaming/attemptLifecycle.d.ts +56 -0
  32. package/dist/cli/commands/streaming/attemptLifecycle.js +110 -0
  33. package/dist/cli/commands/streaming/attemptOutcome.d.ts +96 -0
  34. package/dist/cli/commands/streaming/attemptOutcome.js +206 -0
  35. package/dist/cli/commands/streaming/attemptSetup.d.ts +78 -0
  36. package/dist/cli/commands/streaming/attemptSetup.js +167 -0
  37. package/dist/cli/commands/streaming/goalCheckpoint.d.ts +1 -1
  38. package/dist/cli/commands/streaming/goalCheckpoint.js +2 -2
  39. package/dist/cli/commands/streaming/goalSupervisor.js +9 -6
  40. package/dist/cli/commands/streaming/stallRecovery.d.ts +94 -0
  41. package/dist/cli/commands/streaming/stallRecovery.js +105 -0
  42. package/dist/cli/commands/streaming/streamLoop.d.ts +72 -0
  43. package/dist/cli/commands/streaming/streamLoop.js +448 -0
  44. package/dist/cli/commands/streaming/toolCallRecovery.d.ts +14 -0
  45. package/dist/cli/commands/streaming/toolCallRecovery.js +56 -0
  46. package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +2 -1
  47. package/dist/cli/commands/streaming/turnRuntime.d.ts +4 -0
  48. package/dist/cli/commands/streaming/turnRuntime.js +6 -0
  49. package/dist/cli/commands/streaming.d.ts +14 -25
  50. package/dist/cli/commands/streaming.js +43 -754
  51. package/dist/cli/commands/wizardFlow.d.ts +334 -0
  52. package/dist/cli/commands/wizardFlow.js +377 -0
  53. package/dist/cli/contextReport.js +3 -0
  54. package/dist/cli/index.js +1 -1
  55. package/dist/config/contextFiles.js +9 -3
  56. package/dist/config/inputHistory.d.ts +0 -1
  57. package/dist/config/inputHistory.js +1 -1
  58. package/dist/config/modelDiscovery.d.ts +0 -15
  59. package/dist/config/modelDiscovery.js +1 -1
  60. package/dist/config/settings.d.ts +7 -0
  61. package/dist/config/settings.js +3 -0
  62. package/dist/config/skillSettings.js +4 -4
  63. package/dist/config/updateCheck.d.ts +0 -1
  64. package/dist/config/updateCheck.js +1 -1
  65. package/dist/core/agent/budgets.d.ts +63 -1
  66. package/dist/core/agent/budgets.js +84 -1
  67. package/dist/core/agent/compaction.js +1 -1
  68. package/dist/core/agent/completionController.d.ts +7 -13
  69. package/dist/core/agent/completionController.js +17 -8
  70. package/dist/core/agent/contextBudget.d.ts +0 -4
  71. package/dist/core/agent/contextBudget.js +3 -3
  72. package/dist/core/agent/errors.d.ts +0 -1
  73. package/dist/core/agent/errors.js +1 -1
  74. package/dist/core/agent/events.d.ts +5 -1
  75. package/dist/core/{goal/completionPolicy.d.ts → agent/goalPolicy.d.ts} +18 -0
  76. package/dist/core/agent/goalPolicy.js +106 -0
  77. package/dist/core/agent/requestAssembly.d.ts +2 -2
  78. package/dist/core/agent/requestAssembly.js +16 -4
  79. package/dist/core/agent/toolCapabilities.d.ts +2 -2
  80. package/dist/core/agent/toolCapabilities.js +5 -5
  81. package/dist/core/agent/toolOutputStore.js +1 -1
  82. package/dist/core/agent/toolResults.js +1 -1
  83. package/dist/core/agent/workState.d.ts +6 -3
  84. package/dist/core/agent/workState.js +62 -7
  85. package/dist/core/attachments/imageAttachments.js +90 -42
  86. package/dist/core/deadline.d.ts +0 -6
  87. package/dist/core/deadline.js +1 -1
  88. package/dist/core/io/boundedRead.js +1 -1
  89. package/dist/core/limits.d.ts +51 -0
  90. package/dist/core/limits.js +51 -0
  91. package/dist/core/log/llmLog.js +1 -1
  92. package/dist/core/process/backgroundRegistry.d.ts +2 -3
  93. package/dist/core/process/backgroundRegistry.js +10 -6
  94. package/dist/core/process/userShell.d.ts +16 -0
  95. package/dist/core/process/userShell.js +59 -0
  96. package/dist/core/safety/shellClassifier.d.ts +11 -0
  97. package/dist/core/safety/{bashClassifier.js → shellClassifier.js} +5 -3
  98. package/dist/core/safety/urlGuard.d.ts +1 -1
  99. package/dist/core/session/sessionSlimming.d.ts +0 -3
  100. package/dist/core/session/sessionSlimming.js +2 -3
  101. package/dist/core/session/sessionStore.d.ts +1 -0
  102. package/dist/core/session/sessionStore.js +39 -20
  103. package/dist/core/{bashOutput → shellOutput}/lineFilter.js +8 -2
  104. package/dist/core/{bashOutput → shellOutput}/reducers/search.d.ts +0 -1
  105. package/dist/core/{bashOutput → shellOutput}/reducers/search.js +1 -1
  106. package/dist/core/shellOutput/registry.d.ts +2 -0
  107. package/dist/core/{bashOutput → shellOutput}/registry.js +3 -3
  108. package/dist/core/{bashOutput → shellOutput}/types.d.ts +6 -5
  109. package/dist/core/subagent/contracts.d.ts +2 -14
  110. package/dist/core/subagent/contracts.js +3 -3
  111. package/dist/core/subagent/executionProfiles.js +2 -2
  112. package/dist/core/subagent/subagentRunner.js +3 -4
  113. package/dist/core/toolOutput/reduction.d.ts +0 -12
  114. package/dist/core/toolOutput/reduction.js +1 -1
  115. package/dist/core/validation/outputParser.d.ts +2 -2
  116. package/dist/llm/client.js +5 -1
  117. package/dist/llm/hazeTools.d.ts +139 -124
  118. package/dist/llm/hazeTools.js +14 -11
  119. package/dist/llm/initPrompt.js +1 -1
  120. package/dist/llm/lsp/client.d.ts +45 -0
  121. package/dist/llm/lsp/client.js +195 -0
  122. package/dist/llm/lsp/pool.d.ts +23 -0
  123. package/dist/llm/lsp/pool.js +86 -0
  124. package/dist/llm/lsp/protocol.d.ts +64 -0
  125. package/dist/llm/lsp/protocol.js +128 -0
  126. package/dist/llm/lsp/requests.d.ts +94 -0
  127. package/dist/llm/lsp/requests.js +119 -0
  128. package/dist/llm/lspTools.d.ts +3824 -570
  129. package/dist/llm/lspTools.js +65 -1
  130. package/dist/llm/openaiCodex.d.ts +0 -2
  131. package/dist/llm/openaiCodex.js +0 -4
  132. package/dist/llm/openaiCodexOAuth.d.ts +0 -3
  133. package/dist/llm/openaiCodexOAuth.js +6 -3
  134. package/dist/llm/requestContext.d.ts +5 -1
  135. package/dist/llm/requestContext.js +25 -2
  136. package/dist/llm/systemPrompt.d.ts +1 -0
  137. package/dist/llm/systemPrompt.js +13 -6
  138. package/dist/llm/toolResultTypes.d.ts +0 -14
  139. package/dist/llm/toolResultTypes.js +1 -4
  140. package/dist/llm/tools/editMatch.d.ts +0 -9
  141. package/dist/llm/tools/editMatch.js +1 -1
  142. package/dist/llm/tools/fetchTool.js +1 -1
  143. package/dist/llm/tools/fileToolShared.d.ts +4 -2
  144. package/dist/llm/tools/fileToolShared.js +9 -5
  145. package/dist/llm/tools/gitIgnore.d.ts +25 -32
  146. package/dist/llm/tools/gitIgnore.js +216 -98
  147. package/dist/llm/tools/grepParse.d.ts +2 -1
  148. package/dist/llm/tools/grepRunner.d.ts +1 -1
  149. package/dist/llm/tools/grepRunner.js +2 -2
  150. package/dist/llm/tools/outputCap.d.ts +2 -7
  151. package/dist/llm/tools/outputCap.js +3 -3
  152. package/dist/llm/tools/processTool.d.ts +16 -16
  153. package/dist/llm/tools/processTool.js +1 -1
  154. package/dist/llm/tools/readRecovery.d.ts +0 -2
  155. package/dist/llm/tools/readRecovery.js +2 -2
  156. package/dist/llm/tools/{bashTool.d.ts → shellTool.d.ts} +123 -107
  157. package/dist/llm/tools/{bashTool.js → shellTool.js} +15 -14
  158. package/dist/llm/tools/toolContext.js +5 -5
  159. package/dist/llm/tools/workspaceFile.d.ts +0 -1
  160. package/dist/llm/tools/workspaceFile.js +1 -6
  161. package/dist/llm/webFetch.d.ts +1 -1
  162. package/dist/skills/SkillLoader.d.ts +1 -11
  163. package/dist/skills/SkillLoader.js +1 -2
  164. package/dist/skills/types.d.ts +2 -1
  165. package/dist/utils/buildInfo.d.ts +6 -13
  166. package/dist/utils/buildInfo.js +6 -15
  167. package/dist/utils/fs.d.ts +7 -5
  168. package/dist/utils/fs.js +5 -2
  169. package/dist/utils/path.d.ts +0 -1
  170. package/dist/utils/path.js +1 -1
  171. package/package.json +6 -4
  172. package/dist/cli/commands/lspWizard.d.ts +0 -14
  173. package/dist/cli/commands/lspWizard.js +0 -44
  174. package/dist/cli/commands/mcpWizard.d.ts +0 -15
  175. package/dist/cli/commands/skillConfirmRemove.d.ts +0 -11
  176. package/dist/cli/commands/skillConfirmRemove.js +0 -20
  177. package/dist/cli/commands/skillCreation.d.ts +0 -12
  178. package/dist/cli/commands/skillCreation.js +0 -14
  179. package/dist/cli/commands/skillWizard.d.ts +0 -17
  180. package/dist/cli/commands/streaming/idleTimer.d.ts +0 -26
  181. package/dist/cli/commands/streaming/idleTimer.js +0 -24
  182. package/dist/cli/commands/streaming/turnOutcome.d.ts +0 -27
  183. package/dist/cli/commands/streaming/turnOutcome.js +0 -29
  184. package/dist/cli/commands/wizardActions.d.ts +0 -47
  185. package/dist/cli/commands/wizardActions.js +0 -47
  186. package/dist/cli/commands/wizardInput.d.ts +0 -4
  187. package/dist/cli/commands/wizardInput.js +0 -19
  188. package/dist/cli/commands/wizardPrompts.d.ts +0 -22
  189. package/dist/cli/commands/wizardPrompts.js +0 -58
  190. package/dist/cli/commands/wizardSuggestions.d.ts +0 -31
  191. package/dist/cli/commands/wizardSuggestions.js +0 -190
  192. package/dist/cli/commands/wizardTransition.d.ts +0 -37
  193. package/dist/cli/commands/wizardTransition.js +0 -43
  194. package/dist/core/agent/toolExecutionBudget.d.ts +0 -35
  195. package/dist/core/agent/toolExecutionBudget.js +0 -49
  196. package/dist/core/agent/turnBudget.d.ts +0 -35
  197. package/dist/core/agent/turnBudget.js +0 -27
  198. package/dist/core/bashOutput/ansi.d.ts +0 -1
  199. package/dist/core/bashOutput/ansi.js +0 -7
  200. package/dist/core/bashOutput/registry.d.ts +0 -4
  201. package/dist/core/goal/completionPolicy.js +0 -43
  202. package/dist/core/goal/requestClassifier.d.ts +0 -3
  203. package/dist/core/goal/requestClassifier.js +0 -18
  204. package/dist/core/goal/sessionGoal.d.ts +0 -8
  205. package/dist/core/goal/sessionGoal.js +0 -30
  206. package/dist/core/limits/byteBudgets.d.ts +0 -20
  207. package/dist/core/limits/byteBudgets.js +0 -20
  208. package/dist/core/limits/textBudgets.d.ts +0 -25
  209. package/dist/core/limits/textBudgets.js +0 -25
  210. package/dist/core/safety/bashClassifier.d.ts +0 -10
  211. package/dist/llm/lsp.d.ts +0 -149
  212. package/dist/llm/lsp.js +0 -368
  213. package/dist/ui/components/ErrorView.d.ts +0 -4
  214. package/dist/ui/components/ErrorView.js +0 -7
  215. package/dist/utils/yaml.d.ts +0 -2
  216. package/dist/utils/yaml.js +0 -8
  217. package/examples/skills/files/SKILL.md +0 -16
  218. package/examples/skills/files/examples/file-editing.md +0 -3
  219. /package/dist/core/{bashOutput → shellOutput}/command.d.ts +0 -0
  220. /package/dist/core/{bashOutput → shellOutput}/command.js +0 -0
  221. /package/dist/core/{bashOutput → shellOutput}/lineFilter.d.ts +0 -0
  222. /package/dist/core/{bashOutput → shellOutput}/reducers/content.d.ts +0 -0
  223. /package/dist/core/{bashOutput → shellOutput}/reducers/content.js +0 -0
  224. /package/dist/core/{bashOutput → shellOutput}/reducers/gh.d.ts +0 -0
  225. /package/dist/core/{bashOutput → shellOutput}/reducers/gh.js +0 -0
  226. /package/dist/core/{bashOutput → shellOutput}/reducers/git.d.ts +0 -0
  227. /package/dist/core/{bashOutput → shellOutput}/reducers/git.js +0 -0
  228. /package/dist/core/{bashOutput → shellOutput}/reducers/validation.d.ts +0 -0
  229. /package/dist/core/{bashOutput → shellOutput}/reducers/validation.js +0 -0
  230. /package/dist/core/{bashOutput → shellOutput}/types.js +0 -0
@@ -1,128 +1,246 @@
1
- import { spawn } from 'node:child_process';
1
+ import fs from 'fs-extra';
2
+ import path from 'node:path';
3
+ import ignoreFactory from 'ignore';
2
4
  import { workspaceRelativePath, workspaceRoot } from '../../utils/path.js';
3
5
  /**
4
- * Maximum candidate paths submitted to a single `git check-ignore` invocation.
5
- * Bounding the batch keeps stdin/stdout bounded while collapsing hundreds of
6
- * entries into O(batches) subprocesses instead of one process per path
7
- * (RH-001). 256 candidates comfortably fits a typical directory frontier.
6
+ * In-process `.gitignore` evaluation. No Git binary is required or used: rules
7
+ * come from `.gitignore` files between the repository/worktree boundary and
8
+ * each candidate (deepest file wins, last matching line within a file wins),
9
+ * plus the resolved Git common directory's `info/exclude` at lowest precedence.
10
+ * Global user excludes are intentionally omitted for deterministic workspaces. The
11
+ * evaluation is pure filesystem work — stat/read/regex — so it is fast enough
12
+ * to call per walked entry and deterministic across environments.
8
13
  */
9
- export const GIT_IGNORE_BATCH = 256;
10
- /**
11
- * Generous stdout ceiling for a single batch. check-ignore echoes at most the
12
- * ignored paths it was given, so this is bounded by batch size in practice.
13
- */
14
- const CHECK_IGNORE_MAX_BYTES = 8 * 1024 * 1024;
15
- /**
16
- * Run one bounded `git check-ignore -z --stdin` invocation. Resolves with the
17
- * raw NUL-delimited stdout (empty when no paths are ignored or the workspace is
18
- * not a repository); rejects only on a spawn-level failure such as git missing.
19
- */
20
- function runCheckIgnore(root, input) {
21
- return new Promise((resolve, reject) => {
22
- const child = spawn('git', ['-C', root, 'check-ignore', '-z', '--stdin'], { windowsHide: true });
23
- const chunks = [];
24
- let totalBytes = 0;
25
- let overflowed = false;
26
- let settled = false;
27
- const finish = (stdout) => {
28
- if (settled)
29
- return;
30
- settled = true;
31
- resolve(stdout);
32
- };
33
- const fail = (error) => {
34
- if (settled)
35
- return;
36
- settled = true;
37
- reject(error);
38
- };
39
- child.stdout.on('data', (chunk) => {
40
- if (overflowed)
41
- return;
42
- totalBytes += chunk.length;
43
- if (totalBytes > CHECK_IGNORE_MAX_BYTES) {
44
- overflowed = true;
45
- chunks.length = 0;
46
- return;
14
+ const GITIGNORE_FILE = '.gitignore';
15
+ const GIT_POINTER_MAX_BYTES = 8 * 1024;
16
+ /** Convert native separators only; a backslash is a valid POSIX filename byte. */
17
+ function gitPath(relPath) {
18
+ return path.sep === '\\' ? relPath.replaceAll('\\', '/') : relPath;
19
+ }
20
+ function probePath(relPath, isDirectory) {
21
+ const normalized = gitPath(relPath).replace(/^\.\//, '').replace(/\/$/, '');
22
+ return isDirectory ? `${normalized}/` : normalized;
23
+ }
24
+ function isOutsideRoot(relativePath) {
25
+ return relativePath === '..' || relativePath.startsWith(`..${path.sep}`) || path.isAbsolute(relativePath);
26
+ }
27
+ async function lstatIsDirectory(absolutePath) {
28
+ try {
29
+ return (await fs.lstat(absolutePath)).isDirectory();
30
+ }
31
+ catch {
32
+ return false;
33
+ }
34
+ }
35
+ async function readSmallPointer(filePath) {
36
+ const stat = await fs.stat(filePath);
37
+ if (stat.size > GIT_POINTER_MAX_BYTES)
38
+ throw new Error(`Git pointer file exceeds ${GIT_POINTER_MAX_BYTES} bytes.`);
39
+ return fs.readFile(filePath, 'utf8');
40
+ }
41
+ async function resolveExcludeFile(repositoryRoot, gitMarker) {
42
+ try {
43
+ const markerStat = await fs.lstat(gitMarker);
44
+ let gitDir = gitMarker;
45
+ if (!markerStat.isDirectory()) {
46
+ const pointer = /^gitdir:\s*(.+)\s*$/im.exec(await readSmallPointer(gitMarker))?.[1];
47
+ if (!pointer)
48
+ return { checked: false };
49
+ gitDir = path.resolve(repositoryRoot, pointer);
50
+ }
51
+ const commonDirFile = path.join(gitDir, 'commondir');
52
+ try {
53
+ const commonDir = (await readSmallPointer(commonDirFile)).trim();
54
+ if (commonDir)
55
+ gitDir = path.resolve(gitDir, commonDir);
56
+ }
57
+ catch (error) {
58
+ if (error.code !== 'ENOENT')
59
+ return { checked: false };
60
+ }
61
+ return { path: path.join(gitDir, 'info', 'exclude'), checked: true };
62
+ }
63
+ catch {
64
+ return { checked: false };
65
+ }
66
+ }
67
+ /** Find the repository boundary without requiring Git, including linked worktrees. */
68
+ async function discoverIgnoreRoot(workspace) {
69
+ let current = path.resolve(workspace);
70
+ while (true) {
71
+ const marker = path.join(current, '.git');
72
+ try {
73
+ await fs.lstat(marker);
74
+ const exclude = await resolveExcludeFile(current, marker);
75
+ const workspaceRelative = path.relative(current, workspace);
76
+ return {
77
+ ignoreRoot: current,
78
+ workspacePrefix: workspaceRelative === '' ? '' : gitPath(workspaceRelative),
79
+ ...(exclude.path ? { excludeFile: exclude.path } : {}),
80
+ checked: exclude.checked,
81
+ };
82
+ }
83
+ catch (error) {
84
+ if (error.code !== 'ENOENT') {
85
+ return { ignoreRoot: workspace, workspacePrefix: '', checked: false };
47
86
  }
48
- chunks.push(chunk);
49
- });
50
- child.stderr.on('data', () => undefined);
51
- child.on('error', fail);
52
- child.on('close', () => {
53
- // Exit codes: 0 = some ignored, 1 = none ignored, 128 = not a repo. All
54
- // are resolved with whatever stdout arrived (empty for 1/128); overflow
55
- // yields empty output so the batch fails open (nothing reported ignored).
56
- finish(overflowed ? '' : Buffer.concat(chunks).toString('utf8'));
57
- });
58
- child.stdin.on('error', () => undefined);
59
- child.stdin.end(input, 'utf8');
60
- });
87
+ }
88
+ const parent = path.dirname(current);
89
+ if (parent === current)
90
+ return { ignoreRoot: workspace, workspacePrefix: '', checked: true };
91
+ current = parent;
92
+ }
61
93
  }
62
94
  /**
63
- * Create a bounded batch ignore classifier rooted at `root` (defaults to the
64
- * workspace root). One classifier should own an entire listing operation so
65
- * sibling/frontier candidates share subprocesses.
95
+ * Create an ignore classifier rooted at `root` (defaults to the workspace
96
+ * root). One classifier should own an entire listing operation: it memoizes
97
+ * compiled rule files by mtime, so a walk stats each `.gitignore` once per
98
+ * mtime change instead of re-reading it per entry. Nothing is cached across
99
+ * classifier instances, so external edits are always picked up.
66
100
  */
67
101
  export function createIgnoreClassifier(root = workspaceRoot()) {
68
- let invocationCount = 0;
69
- const classifyChecked = async (relativePaths) => {
70
- // De-duplicate and drop meaningless inputs; preserve insertion uniqueness
71
- // so the returned set keys match caller-supplied relative paths exactly.
72
- const unique = Array.from(new Set(relativePaths.filter(candidate => candidate && candidate !== '.')));
73
- if (unique.length === 0)
74
- return { ignored: new Set(), checked: true };
102
+ const workspace = path.resolve(root);
103
+ const rootContext = discoverIgnoreRoot(workspace);
104
+ const ruleFiles = new Map();
105
+ async function loadAbsoluteRuleFile(absolute) {
106
+ let stat;
107
+ try {
108
+ stat = await fs.stat(absolute);
109
+ }
110
+ catch (error) {
111
+ if (error.code === 'ENOENT') {
112
+ const absent = { mtimeMs: -1, size: -1, rules: null };
113
+ ruleFiles.set(absolute, absent);
114
+ return absent;
115
+ }
116
+ // Exists (or unknowable) but cannot be stat-read: not cached, retried next call.
117
+ return { unreadable: true };
118
+ }
119
+ const cached = ruleFiles.get(absolute);
120
+ if (cached && cached.mtimeMs === stat.mtimeMs && cached.size === stat.size)
121
+ return cached;
122
+ try {
123
+ const rules = ignoreFactory().add(await fs.readFile(absolute, 'utf8'));
124
+ const state = { mtimeMs: stat.mtimeMs, size: stat.size, rules };
125
+ ruleFiles.set(absolute, state);
126
+ return state;
127
+ }
128
+ catch {
129
+ return { unreadable: true };
130
+ }
131
+ }
132
+ async function loadRuleFile(relDir) {
133
+ const context = await rootContext;
134
+ return loadAbsoluteRuleFile(path.join(context.ignoreRoot, relDir, GITIGNORE_FILE));
135
+ }
136
+ /**
137
+ * Verdict for one path from its applicable rule files: `.gitignore` files in
138
+ * the parent chain, deepest first (deeper overrides shallower), then the
139
+ * root exclude file (lowest precedence). `unknown` is true when any file in
140
+ * the chain could not be read.
141
+ */
142
+ async function verdictFor(relPath, isDirectory) {
143
+ const context = await rootContext;
144
+ const probe = probePath(relPath, isDirectory);
145
+ const parentSegments = probe.split('/').filter(segment => segment.length > 0).slice(0, -1);
146
+ let unknown = !context.checked;
147
+ for (let index = parentSegments.length; index >= 0; index--) {
148
+ const relDir = parentSegments.slice(0, index).join('/');
149
+ const state = await loadRuleFile(relDir);
150
+ if ('unreadable' in state) {
151
+ unknown = true;
152
+ continue;
153
+ }
154
+ if (!state.rules)
155
+ continue;
156
+ // Paths probed against a nested rule file are relative to its directory.
157
+ const relToDir = index === 0 ? probe : probe.slice(relDir.length + 1);
158
+ const result = state.rules.test(relToDir);
159
+ if (result.ignored || result.unignored)
160
+ return { ignored: result.ignored, unknown };
161
+ }
162
+ if (context.excludeFile) {
163
+ const exclude = await loadAbsoluteRuleFile(context.excludeFile);
164
+ if ('unreadable' in exclude)
165
+ return { ignored: false, unknown: true };
166
+ if (exclude.rules) {
167
+ const result = exclude.rules.test(probe);
168
+ if (result.ignored || result.unignored)
169
+ return { ignored: result.ignored, unknown };
170
+ }
171
+ }
172
+ return { ignored: false, unknown };
173
+ }
174
+ /**
175
+ * Tri-state status for one root-relative path. Any ignored ancestor makes
176
+ * the path ignored (Git cannot re-include below an excluded directory);
177
+ * otherwise the deepest matching rule decides the leaf itself.
178
+ */
179
+ async function statusOf(relPath, isDirectory) {
180
+ const segments = probePath(relPath, isDirectory).replace(/\/$/, '').split('/');
181
+ let unknown = false;
182
+ for (let depth = 1; depth <= segments.length; depth++) {
183
+ const rel = segments.slice(0, depth).join('/');
184
+ const isDir = depth < segments.length || isDirectory;
185
+ const verdict = await verdictFor(rel, isDir);
186
+ if (verdict.unknown)
187
+ unknown = true;
188
+ // An ignored prefix is decisive: everything below it is ignored too.
189
+ if (verdict.ignored)
190
+ return { status: 'ignored', checked: !unknown };
191
+ }
192
+ return { status: 'not-ignored', checked: !unknown };
193
+ }
194
+ const classifyChecked = async (candidates) => {
195
+ // De-duplicate while preserving the first occurrence's directory hint.
196
+ const unique = new Map();
197
+ for (const candidate of candidates) {
198
+ const entry = typeof candidate === 'string' ? { path: candidate } : candidate;
199
+ if (!entry.path || entry.path === '.')
200
+ continue;
201
+ if (!unique.has(entry.path))
202
+ unique.set(entry.path, entry);
203
+ }
75
204
  const ignored = new Set();
76
205
  let checked = true;
77
- for (let offset = 0; offset < unique.length; offset += GIT_IGNORE_BATCH) {
78
- const batch = unique.slice(offset, offset + GIT_IGNORE_BATCH);
79
- const input = `${batch.join('\0')}\0`;
80
- invocationCount++;
81
- // check-ignore echoes each ignored path verbatim (NUL-delimited with
82
- // -z). Matching by exact submitted string preserves spaces, embedded
83
- // newlines, and unusual names; only ignored entries appear in stdout.
84
- try {
85
- const stdout = await runCheckIgnore(root, input);
86
- for (const part of stdout.split('\0'))
87
- if (part)
88
- ignored.add(part);
89
- }
90
- catch {
91
- // Spawn-level failure (e.g. git not installed): whatever was classified
92
- // so far stands, but the batch could not be checked.
206
+ const context = await rootContext;
207
+ for (const [relPath, entry] of unique) {
208
+ const workspaceRelative = entry.absolutePath ? path.relative(workspace, entry.absolutePath) : relPath;
209
+ if (isOutsideRoot(workspaceRelative))
210
+ continue;
211
+ const absolutePath = entry.absolutePath ?? path.join(workspace, workspaceRelative);
212
+ const isDirectory = entry.isDirectory ?? (await lstatIsDirectory(absolutePath));
213
+ const workspaceProbe = gitPath(workspaceRelative);
214
+ const ignoreRelative = context.workspacePrefix ? `${context.workspacePrefix}/${workspaceProbe}` : workspaceProbe;
215
+ const { status, checked: entryChecked } = await statusOf(ignoreRelative, isDirectory);
216
+ if (!entryChecked)
93
217
  checked = false;
94
- return { ignored, checked };
95
- }
218
+ // Reads fail open: an uncertain verdict is never returned as ignored.
219
+ if (status === 'ignored' && entryChecked)
220
+ ignored.add(relPath);
96
221
  }
97
222
  return { ignored, checked };
98
223
  };
99
224
  return {
100
225
  classifyChecked,
101
- classify: async (relativePaths) => (await classifyChecked(relativePaths)).ignored,
102
- get invocationCount() {
103
- return invocationCount;
104
- },
226
+ classify: async (candidates) => (await classifyChecked(candidates)).ignored,
105
227
  };
106
228
  }
107
- /** Classify a set of workspace-relative paths in bounded batches. */
229
+ /** Classify a set of root-relative paths. */
108
230
  export async function classifyGitIgnored(relativePaths, root) {
109
231
  return createIgnoreClassifier(root ?? workspaceRoot()).classify(relativePaths);
110
232
  }
111
- /**
112
- * Single-path ignore classification (used by mutating-tool guards and other
113
- * one-off checks). Built on the batch primitive so the fail-open read contract
114
- * stays identical to batched traversal; `unknown` means Git could not be run
115
- * at all, so callers that must not fail open (mutations) can fail closed.
116
- */
117
233
  export async function isGitIgnored(absolutePath) {
118
234
  return (await checkGitIgnored(absolutePath)) === 'ignored';
119
235
  }
120
236
  /** Tri-state single-path check: mutation guards key off `unknown` (F-05). */
121
237
  export async function checkGitIgnored(absolutePath) {
238
+ const root = workspaceRoot();
122
239
  const relative = workspaceRelativePath(absolutePath);
123
- if (relative === '.')
124
- return 'not-ignored';
125
- const { ignored, checked } = await createIgnoreClassifier(workspaceRoot()).classifyChecked([relative]);
240
+ if (relative === '.' || relative.startsWith('..'))
241
+ return 'not-ignored'; // root, or outside the workspace: no rules apply
242
+ const isDirectory = await lstatIsDirectory(absolutePath);
243
+ const { ignored, checked } = await createIgnoreClassifier(root).classifyChecked([{ path: relative, isDirectory }]);
126
244
  if (!checked)
127
245
  return 'unknown';
128
246
  return ignored.has(relative) ? 'ignored' : 'not-ignored';
@@ -1,4 +1,4 @@
1
- export type GrepMatchItem = {
1
+ type GrepMatchItem = {
2
2
  file: string;
3
3
  line: number;
4
4
  content: string;
@@ -11,3 +11,4 @@ export type ParsedGrepOutput = {
11
11
  omittedMatches: number;
12
12
  };
13
13
  export declare function parseRipgrepJsonStream(stdout: string, maxMatches: number, contextLines: number, toRelativePath?: (absolute: string) => string): ParsedGrepOutput;
14
+ export {};
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Line-oriented bounded ripgrep runner built on the shared bounded-process
3
3
  * primitive, so spawn/timeout/abort/process-group teardown behavior is
4
- * identical to bash (CR-004). Match counting and early-stop stay here.
4
+ * identical to shell execution (CR-004). Match counting and early-stop stay here.
5
5
  */
6
6
  export declare function runRipgrepBounded(input: {
7
7
  executable: string;
@@ -1,10 +1,10 @@
1
1
  import { StringDecoder } from 'node:string_decoder';
2
2
  import { runBoundedProcess } from '../../core/process/runBoundedProcess.js';
3
- import { GREP_STREAM_BYTES, PROCESS_STDERR_BYTES, TEXT_LINE_BYTES } from '../../core/limits/byteBudgets.js';
3
+ import { GREP_STREAM_BYTES, PROCESS_STDERR_BYTES, TEXT_LINE_BYTES } from '../../core/limits.js';
4
4
  /**
5
5
  * Line-oriented bounded ripgrep runner built on the shared bounded-process
6
6
  * primitive, so spawn/timeout/abort/process-group teardown behavior is
7
- * identical to bash (CR-004). Match counting and early-stop stay here.
7
+ * identical to shell execution (CR-004). Match counting and early-stop stay here.
8
8
  */
9
9
  export async function runRipgrepBounded(input) {
10
10
  const decoder = new StringDecoder('utf8');
@@ -1,5 +1,5 @@
1
- import { COMPACT_COMMAND_CHARS, GREP_MAX_LINE_CHARS, GREP_MAX_OUTPUT_CHARS } from '../../core/limits/textBudgets.js';
2
- export { COMPACT_COMMAND_CHARS, GREP_MAX_OUTPUT_CHARS, GREP_MAX_LINE_CHARS };
1
+ import { COMPACT_COMMAND_CHARS } from '../../core/limits.js';
2
+ export { COMPACT_COMMAND_CHARS };
3
3
  /**
4
4
  * Cap a string to `maxChars` characters, keeping a head + tail and storing the
5
5
  * full text behind a `readToolOutput` handle so nothing is lost.
@@ -15,11 +15,6 @@ export declare function compactStoredOutput(text: string, maxChars?: number): {
15
15
  omittedChars: number;
16
16
  handle: string;
17
17
  };
18
- /** Truncate a single over-long line in place. */
19
- export declare function compactLine(text: string, maxChars?: number): {
20
- text: string;
21
- truncated: boolean;
22
- };
23
18
  /** Render structured grep matches as `file:line:content` lines (context flagged with `-`). */
24
19
  export declare function renderGrepMatches(matches: Array<{
25
20
  file: string;
@@ -1,6 +1,6 @@
1
1
  import { storeToolOutput } from '../../core/agent/toolOutputStore.js';
2
- import { COMPACT_COMMAND_CHARS, GREP_MAX_LINE_CHARS, GREP_MAX_OUTPUT_CHARS } from '../../core/limits/textBudgets.js';
3
- export { COMPACT_COMMAND_CHARS, GREP_MAX_OUTPUT_CHARS, GREP_MAX_LINE_CHARS };
2
+ import { COMPACT_COMMAND_CHARS, GREP_MAX_LINE_CHARS, GREP_MAX_OUTPUT_CHARS } from '../../core/limits.js';
3
+ export { COMPACT_COMMAND_CHARS };
4
4
  /**
5
5
  * Cap a string to `maxChars` characters, keeping a head + tail and storing the
6
6
  * full text behind a `readToolOutput` handle so nothing is lost.
@@ -19,7 +19,7 @@ export function compactStoredOutput(text, maxChars = COMPACT_COMMAND_CHARS) {
19
19
  };
20
20
  }
21
21
  /** Truncate a single over-long line in place. */
22
- export function compactLine(text, maxChars = GREP_MAX_LINE_CHARS) {
22
+ function compactLine(text, maxChars = GREP_MAX_LINE_CHARS) {
23
23
  if (text.length <= maxChars)
24
24
  return { text, truncated: false };
25
25
  return { text: `${text.slice(0, Math.max(0, maxChars - 22))}[line truncated]`, truncated: true };
@@ -67,7 +67,7 @@ export declare const processTool: ({
67
67
  matches?: number;
68
68
  ok: boolean;
69
69
  backgroundId: string;
70
- status: import("../../core/process/backgroundRegistry.js").BackgroundProcessStatus;
70
+ status: "failed" | "killed" | "running" | "exited";
71
71
  outputHandle: string;
72
72
  reasonCode?: undefined;
73
73
  recoverable?: undefined;
@@ -120,7 +120,7 @@ export declare const processTool: ({
120
120
  matches?: number;
121
121
  ok: boolean;
122
122
  backgroundId: string;
123
- status: import("../../core/process/backgroundRegistry.js").BackgroundProcessStatus;
123
+ status: "failed" | "killed" | "running" | "exited";
124
124
  outputHandle: string;
125
125
  reasonCode?: undefined;
126
126
  recoverable?: undefined;
@@ -176,7 +176,7 @@ export declare const processTool: ({
176
176
  matches?: number;
177
177
  ok: boolean;
178
178
  backgroundId: string;
179
- status: import("../../core/process/backgroundRegistry.js").BackgroundProcessStatus;
179
+ status: "failed" | "killed" | "running" | "exited";
180
180
  outputHandle: string;
181
181
  reasonCode?: undefined;
182
182
  recoverable?: undefined;
@@ -253,7 +253,7 @@ export declare const processTool: ({
253
253
  matches?: number;
254
254
  ok: boolean;
255
255
  backgroundId: string;
256
- status: import("../../core/process/backgroundRegistry.js").BackgroundProcessStatus;
256
+ status: "failed" | "killed" | "running" | "exited";
257
257
  outputHandle: string;
258
258
  reasonCode?: undefined;
259
259
  recoverable?: undefined;
@@ -341,7 +341,7 @@ export declare const processTool: ({
341
341
  matches?: number;
342
342
  ok: boolean;
343
343
  backgroundId: string;
344
- status: import("../../core/process/backgroundRegistry.js").BackgroundProcessStatus;
344
+ status: "failed" | "killed" | "running" | "exited";
345
345
  outputHandle: string;
346
346
  reasonCode?: undefined;
347
347
  recoverable?: undefined;
@@ -394,7 +394,7 @@ export declare const processTool: ({
394
394
  matches?: number;
395
395
  ok: boolean;
396
396
  backgroundId: string;
397
- status: import("../../core/process/backgroundRegistry.js").BackgroundProcessStatus;
397
+ status: "failed" | "killed" | "running" | "exited";
398
398
  outputHandle: string;
399
399
  reasonCode?: undefined;
400
400
  recoverable?: undefined;
@@ -450,7 +450,7 @@ export declare const processTool: ({
450
450
  matches?: number;
451
451
  ok: boolean;
452
452
  backgroundId: string;
453
- status: import("../../core/process/backgroundRegistry.js").BackgroundProcessStatus;
453
+ status: "failed" | "killed" | "running" | "exited";
454
454
  outputHandle: string;
455
455
  reasonCode?: undefined;
456
456
  recoverable?: undefined;
@@ -527,7 +527,7 @@ export declare const processTool: ({
527
527
  matches?: number;
528
528
  ok: boolean;
529
529
  backgroundId: string;
530
- status: import("../../core/process/backgroundRegistry.js").BackgroundProcessStatus;
530
+ status: "failed" | "killed" | "running" | "exited";
531
531
  outputHandle: string;
532
532
  reasonCode?: undefined;
533
533
  recoverable?: undefined;
@@ -615,7 +615,7 @@ export declare const processTool: ({
615
615
  matches?: number;
616
616
  ok: boolean;
617
617
  backgroundId: string;
618
- status: import("../../core/process/backgroundRegistry.js").BackgroundProcessStatus;
618
+ status: "failed" | "killed" | "running" | "exited";
619
619
  outputHandle: string;
620
620
  reasonCode?: undefined;
621
621
  recoverable?: undefined;
@@ -668,7 +668,7 @@ export declare const processTool: ({
668
668
  matches?: number;
669
669
  ok: boolean;
670
670
  backgroundId: string;
671
- status: import("../../core/process/backgroundRegistry.js").BackgroundProcessStatus;
671
+ status: "failed" | "killed" | "running" | "exited";
672
672
  outputHandle: string;
673
673
  reasonCode?: undefined;
674
674
  recoverable?: undefined;
@@ -724,7 +724,7 @@ export declare const processTool: ({
724
724
  matches?: number;
725
725
  ok: boolean;
726
726
  backgroundId: string;
727
- status: import("../../core/process/backgroundRegistry.js").BackgroundProcessStatus;
727
+ status: "failed" | "killed" | "running" | "exited";
728
728
  outputHandle: string;
729
729
  reasonCode?: undefined;
730
730
  recoverable?: undefined;
@@ -791,7 +791,7 @@ export declare const processTool: ({
791
791
  matches?: number;
792
792
  ok: boolean;
793
793
  backgroundId: string;
794
- status: import("../../core/process/backgroundRegistry.js").BackgroundProcessStatus;
794
+ status: "failed" | "killed" | "running" | "exited";
795
795
  outputHandle: string;
796
796
  reasonCode?: undefined;
797
797
  recoverable?: undefined;
@@ -879,7 +879,7 @@ export declare const processTool: ({
879
879
  matches?: number;
880
880
  ok: boolean;
881
881
  backgroundId: string;
882
- status: import("../../core/process/backgroundRegistry.js").BackgroundProcessStatus;
882
+ status: "failed" | "killed" | "running" | "exited";
883
883
  outputHandle: string;
884
884
  reasonCode?: undefined;
885
885
  recoverable?: undefined;
@@ -932,7 +932,7 @@ export declare const processTool: ({
932
932
  matches?: number;
933
933
  ok: boolean;
934
934
  backgroundId: string;
935
- status: import("../../core/process/backgroundRegistry.js").BackgroundProcessStatus;
935
+ status: "failed" | "killed" | "running" | "exited";
936
936
  outputHandle: string;
937
937
  reasonCode?: undefined;
938
938
  recoverable?: undefined;
@@ -988,7 +988,7 @@ export declare const processTool: ({
988
988
  matches?: number;
989
989
  ok: boolean;
990
990
  backgroundId: string;
991
- status: import("../../core/process/backgroundRegistry.js").BackgroundProcessStatus;
991
+ status: "failed" | "killed" | "running" | "exited";
992
992
  outputHandle: string;
993
993
  reasonCode?: undefined;
994
994
  recoverable?: undefined;
@@ -1055,7 +1055,7 @@ export declare const processTool: ({
1055
1055
  matches?: number;
1056
1056
  ok: boolean;
1057
1057
  backgroundId: string;
1058
- status: import("../../core/process/backgroundRegistry.js").BackgroundProcessStatus;
1058
+ status: "failed" | "killed" | "running" | "exited";
1059
1059
  outputHandle: string;
1060
1060
  reasonCode?: undefined;
1061
1061
  recoverable?: undefined;
@@ -4,7 +4,7 @@ import { getBackgroundProcess, killBackgroundProcess, listBackgroundProcesses }
4
4
  import { readToolOutput } from '../../core/agent/toolOutputStore.js';
5
5
  import { hazeContext, hazeToolContextSchema } from './toolContext.js';
6
6
  export const processTool = tool({
7
- description: 'List, read output from, or kill background processes started by bash background=true. Kill servers and watchers when finished.',
7
+ description: 'List, read output from, or kill background processes started by shell background=true. Kill servers and watchers when finished.',
8
8
  contextSchema: hazeToolContextSchema,
9
9
  inputSchema: z.object({
10
10
  action: z.enum(['list', 'output', 'kill']),
@@ -4,7 +4,5 @@ export interface ReadFailureRecovery {
4
4
  suggestedNextStep: string;
5
5
  suggestedPaths?: string[];
6
6
  }
7
- /** Return a few close, non-ignored siblings without walking the workspace. */
8
- export declare function nearbyReadablePaths(filePath: string): Promise<string[]>;
9
7
  export declare function assertReadableTextFile(absolutePath: string, filePath: string): Promise<void>;
10
8
  export declare function readFailureRecovery(filePath: string, error: unknown): Promise<ReadFailureRecovery>;
@@ -38,7 +38,7 @@ async function existingAncestor(candidate, root) {
38
38
  return undefined;
39
39
  }
40
40
  /** Return a few close, non-ignored siblings without walking the workspace. */
41
- export async function nearbyReadablePaths(filePath) {
41
+ async function nearbyReadablePaths(filePath) {
42
42
  let candidate;
43
43
  try {
44
44
  candidate = resolveWorkspacePath(filePath);
@@ -60,7 +60,7 @@ export async function nearbyReadablePaths(filePath) {
60
60
  return [];
61
61
  }
62
62
  const ranked = entries
63
- .filter(entry => entry.name !== '.git' && entry.name !== 'node_modules')
63
+ .filter(entry => entry.name !== '.git')
64
64
  .map(entry => ({ entry, distance: editDistance(wanted.toLowerCase(), entry.name.toLowerCase()) }))
65
65
  .filter(({ entry, distance }) => distance <= Math.max(2, Math.ceil(wanted.length * 0.4)) || entry.name.toLowerCase().includes(wanted.toLowerCase()) || wanted.toLowerCase().includes(entry.name.toLowerCase()))
66
66
  .sort((left, right) => left.distance - right.distance || left.entry.name.localeCompare(right.entry.name))