@haystackeditor/cli 0.10.3 → 0.12.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/README.md +15 -16
- package/dist/assets/hooks/agent-context/detect.ts +180 -0
- package/dist/assets/hooks/agent-context/format.ts +1 -0
- package/dist/assets/hooks/agent-context/index.ts +2 -0
- package/dist/assets/hooks/agent-context/parsers/claude.ts +14 -5
- package/dist/assets/hooks/agent-context/parsers/codex.ts +416 -0
- package/dist/assets/hooks/agent-context/tsconfig.json +1 -0
- package/dist/assets/hooks/agent-context/types.ts +1 -1
- package/dist/assets/hooks/package.json +2 -1
- package/dist/assets/hooks/scripts/pre-commit.sh +80 -2
- package/dist/assets/hooks/scripts/pre-push.sh +1 -1
- package/dist/assets/skills/submit.md +20 -0
- package/dist/commands/config.d.ts +4 -0
- package/dist/commands/config.js +94 -69
- package/dist/commands/dismiss.js +2 -1
- package/dist/commands/install-session-hooks.d.ts +3 -2
- package/dist/commands/install-session-hooks.js +27 -11
- package/dist/commands/pr-status.d.ts +5 -0
- package/dist/commands/pr-status.js +2 -2
- package/dist/commands/request-review.d.ts +15 -0
- package/dist/commands/request-review.js +95 -0
- package/dist/commands/setup.d.ts +1 -0
- package/dist/commands/setup.js +285 -2
- package/dist/commands/submit.d.ts +1 -0
- package/dist/commands/submit.js +12 -19
- package/dist/commands/triage.d.ts +16 -4
- package/dist/commands/triage.js +278 -179
- package/dist/index.d.ts +2 -1
- package/dist/index.js +73 -50
- package/dist/triage/prompts.js +13 -5
- package/dist/triage/runner.js +1 -1
- package/dist/triage/traces.js +9 -3
- package/dist/triage/types.d.ts +1 -1
- package/dist/types.d.ts +146 -26
- package/dist/types.js +44 -5
- package/dist/utils/analysis-api.d.ts +16 -0
- package/dist/utils/analysis-api.js +23 -5
- package/dist/utils/telemetry.d.ts +17 -0
- package/dist/utils/telemetry.js +109 -0
- package/package.json +1 -1
- package/dist/commands/check-pending.d.ts +0 -19
- package/dist/commands/check-pending.js +0 -217
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import type {
|
|
4
|
+
AgentContext,
|
|
5
|
+
AgentParser,
|
|
6
|
+
DetectionResult,
|
|
7
|
+
InteractionTurn,
|
|
8
|
+
ModifiedFile,
|
|
9
|
+
TokenUsage,
|
|
10
|
+
ToolUseInfo,
|
|
11
|
+
} from '../types.js';
|
|
12
|
+
import { detectAgent } from '../detect.js';
|
|
13
|
+
|
|
14
|
+
const PATCH_FILE_LINE_RE = /^\*\*\* (?:Update|Add|Delete) File: (.+)$/;
|
|
15
|
+
const PATCH_MOVE_LINE_RE = /^\*\*\* Move to: (.+)$/;
|
|
16
|
+
const EDITING_TOOLS = new Set([
|
|
17
|
+
'apply_patch',
|
|
18
|
+
'write_file',
|
|
19
|
+
'edit_file',
|
|
20
|
+
'create_file',
|
|
21
|
+
'replace_file',
|
|
22
|
+
]);
|
|
23
|
+
const FILE_PATH_KEYS = [
|
|
24
|
+
'path',
|
|
25
|
+
'file_path',
|
|
26
|
+
'filePath',
|
|
27
|
+
'filename',
|
|
28
|
+
'target_path',
|
|
29
|
+
'targetPath',
|
|
30
|
+
'new_path',
|
|
31
|
+
'newPath',
|
|
32
|
+
'old_path',
|
|
33
|
+
'oldPath',
|
|
34
|
+
'notebook_path',
|
|
35
|
+
];
|
|
36
|
+
const TASK_PROMPT_SKIP_PREFIXES = [
|
|
37
|
+
'# AGENTS.md instructions for ',
|
|
38
|
+
'<permissions instructions>',
|
|
39
|
+
'<app-context>',
|
|
40
|
+
'<collaboration_mode>',
|
|
41
|
+
'<skills_instructions>',
|
|
42
|
+
'<environment_context>',
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
interface CodexRecord {
|
|
46
|
+
type?: string;
|
|
47
|
+
payload?: Record<string, unknown>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface CodexSessionMetaPayload {
|
|
51
|
+
id?: string;
|
|
52
|
+
timestamp?: string;
|
|
53
|
+
cwd?: string;
|
|
54
|
+
cli_version?: string;
|
|
55
|
+
git?: {
|
|
56
|
+
branch?: string;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface CodexTurnContextPayload {
|
|
61
|
+
model?: string;
|
|
62
|
+
cwd?: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
interface CodexTokenUsagePayload {
|
|
66
|
+
input_tokens?: number;
|
|
67
|
+
cached_input_tokens?: number;
|
|
68
|
+
output_tokens?: number;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function parseLines(raw: string): CodexRecord[] {
|
|
72
|
+
const records: CodexRecord[] = [];
|
|
73
|
+
for (const line of raw.split('\n')) {
|
|
74
|
+
const trimmed = line.trim();
|
|
75
|
+
if (!trimmed) continue;
|
|
76
|
+
try {
|
|
77
|
+
records.push(JSON.parse(trimmed));
|
|
78
|
+
} catch {
|
|
79
|
+
// Skip partial lines while a session file is still being written.
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return records;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function extractTextContent(content: unknown): string {
|
|
86
|
+
if (typeof content === 'string') return content;
|
|
87
|
+
if (!Array.isArray(content)) return '';
|
|
88
|
+
|
|
89
|
+
return content
|
|
90
|
+
.map((part) => {
|
|
91
|
+
if (typeof part === 'string') return part;
|
|
92
|
+
if (
|
|
93
|
+
part &&
|
|
94
|
+
typeof part === 'object' &&
|
|
95
|
+
'text' in part &&
|
|
96
|
+
typeof part.text === 'string'
|
|
97
|
+
) {
|
|
98
|
+
return part.text;
|
|
99
|
+
}
|
|
100
|
+
return '';
|
|
101
|
+
})
|
|
102
|
+
.filter(Boolean)
|
|
103
|
+
.join('\n');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function truncateString(value: string): string {
|
|
107
|
+
if (value.length <= 200) return value;
|
|
108
|
+
return value.slice(0, 200) + '... (truncated)';
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function sanitizeInput(input: Record<string, unknown>): Record<string, unknown> {
|
|
112
|
+
const sanitized: Record<string, unknown> = {};
|
|
113
|
+
for (const [key, value] of Object.entries(input)) {
|
|
114
|
+
if (typeof value === 'string') {
|
|
115
|
+
sanitized[key] = truncateString(value);
|
|
116
|
+
} else if (Array.isArray(value)) {
|
|
117
|
+
sanitized[key] = value.map((item) =>
|
|
118
|
+
typeof item === 'string' ? truncateString(item) : item,
|
|
119
|
+
);
|
|
120
|
+
} else {
|
|
121
|
+
sanitized[key] = value;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return sanitized;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function parseJsonObject(raw: unknown): Record<string, unknown> {
|
|
128
|
+
if (typeof raw !== 'string' || !raw.trim()) return {};
|
|
129
|
+
try {
|
|
130
|
+
const parsed: unknown = JSON.parse(raw);
|
|
131
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
132
|
+
return parsed as Record<string, unknown>;
|
|
133
|
+
}
|
|
134
|
+
} catch {
|
|
135
|
+
// Ignore malformed arguments payloads.
|
|
136
|
+
}
|
|
137
|
+
return {};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function extractPatchFilePaths(inputText: string): string[] {
|
|
141
|
+
const filePaths = new Set<string>();
|
|
142
|
+
|
|
143
|
+
for (const line of inputText.split('\n')) {
|
|
144
|
+
const fileMatch = line.match(PATCH_FILE_LINE_RE);
|
|
145
|
+
if (fileMatch) {
|
|
146
|
+
filePaths.add(fileMatch[1]);
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const moveMatch = line.match(PATCH_MOVE_LINE_RE);
|
|
151
|
+
if (moveMatch) {
|
|
152
|
+
filePaths.add(moveMatch[1]);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return Array.from(filePaths);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function extractKnownFilePaths(input: Record<string, unknown>): string[] {
|
|
160
|
+
const filePaths = new Set<string>();
|
|
161
|
+
|
|
162
|
+
for (const key of FILE_PATH_KEYS) {
|
|
163
|
+
const value = input[key];
|
|
164
|
+
if (typeof value === 'string' && value.trim()) {
|
|
165
|
+
filePaths.add(value);
|
|
166
|
+
} else if (Array.isArray(value)) {
|
|
167
|
+
for (const item of value) {
|
|
168
|
+
if (typeof item === 'string' && item.trim()) {
|
|
169
|
+
filePaths.add(item);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return Array.from(filePaths);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function extractPatchInputText(
|
|
179
|
+
input: Record<string, unknown>,
|
|
180
|
+
rawInputText?: string,
|
|
181
|
+
): string {
|
|
182
|
+
const parsedInputText = input.input;
|
|
183
|
+
if (typeof parsedInputText === 'string' && parsedInputText.trim()) {
|
|
184
|
+
return parsedInputText;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const parsedPatchText = input.patch;
|
|
188
|
+
if (typeof parsedPatchText === 'string' && parsedPatchText.trim()) {
|
|
189
|
+
return parsedPatchText;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const rawInputObject = parseJsonObject(rawInputText);
|
|
193
|
+
const rawObjectInputText = rawInputObject.input;
|
|
194
|
+
if (typeof rawObjectInputText === 'string' && rawObjectInputText.trim()) {
|
|
195
|
+
return rawObjectInputText;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const rawObjectPatchText = rawInputObject.patch;
|
|
199
|
+
if (typeof rawObjectPatchText === 'string' && rawObjectPatchText.trim()) {
|
|
200
|
+
return rawObjectPatchText;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return typeof rawInputText === 'string' ? rawInputText : '';
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function extractModifiedFiles(
|
|
207
|
+
toolName: string,
|
|
208
|
+
toolUseId: string,
|
|
209
|
+
input: Record<string, unknown>,
|
|
210
|
+
rawInputText?: string,
|
|
211
|
+
): ModifiedFile[] {
|
|
212
|
+
let filePaths: string[] = [];
|
|
213
|
+
|
|
214
|
+
if (toolName === 'apply_patch') {
|
|
215
|
+
const patchInputText = extractPatchInputText(input, rawInputText);
|
|
216
|
+
if (patchInputText) {
|
|
217
|
+
filePaths = extractPatchFilePaths(patchInputText);
|
|
218
|
+
}
|
|
219
|
+
} else if (EDITING_TOOLS.has(toolName)) {
|
|
220
|
+
filePaths = extractKnownFilePaths(input);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return filePaths.map((filePath) => ({
|
|
224
|
+
filePath,
|
|
225
|
+
toolName,
|
|
226
|
+
toolUseId,
|
|
227
|
+
}));
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function getOrCreateAssistantTurn(transcript: InteractionTurn[]): InteractionTurn {
|
|
231
|
+
const lastTurn = transcript[transcript.length - 1];
|
|
232
|
+
if (lastTurn && lastTurn.role === 'assistant') {
|
|
233
|
+
return lastTurn;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const turn: InteractionTurn = {
|
|
237
|
+
turnIndex: transcript.length,
|
|
238
|
+
role: 'assistant',
|
|
239
|
+
content: '',
|
|
240
|
+
modifiedFiles: [],
|
|
241
|
+
toolUses: [],
|
|
242
|
+
};
|
|
243
|
+
transcript.push(turn);
|
|
244
|
+
return turn;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function isMeaningfulTaskPrompt(content: string): boolean {
|
|
248
|
+
const trimmed = content.trim();
|
|
249
|
+
if (!trimmed) return false;
|
|
250
|
+
return !TASK_PROMPT_SKIP_PREFIXES.some((prefix) => trimmed.startsWith(prefix));
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function extractSessionId(sessionFilePath: string, sessionMeta?: CodexSessionMetaPayload): string {
|
|
254
|
+
if (sessionMeta?.id) return sessionMeta.id;
|
|
255
|
+
|
|
256
|
+
const basename = path.basename(sessionFilePath);
|
|
257
|
+
const match = basename.match(
|
|
258
|
+
/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\.jsonl$/i,
|
|
259
|
+
);
|
|
260
|
+
return match ? match[1] : basename.replace(/\.jsonl$/, '');
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export class CodexParser implements AgentParser {
|
|
264
|
+
async detect(repoPath: string): Promise<DetectionResult> {
|
|
265
|
+
return detectAgent(repoPath);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
async parse(
|
|
269
|
+
sessionFilePath: string,
|
|
270
|
+
_repoPath: string,
|
|
271
|
+
): Promise<AgentContext> {
|
|
272
|
+
const raw = fs.readFileSync(sessionFilePath, 'utf-8');
|
|
273
|
+
const records = parseLines(raw);
|
|
274
|
+
const transcript: InteractionTurn[] = [];
|
|
275
|
+
const fallbackUserPrompts: string[] = [];
|
|
276
|
+
let taskPrompt = '';
|
|
277
|
+
let sessionMeta: CodexSessionMetaPayload | undefined;
|
|
278
|
+
let latestTurnContext: CodexTurnContextPayload | undefined;
|
|
279
|
+
let totalUsage: TokenUsage = {
|
|
280
|
+
inputTokens: 0,
|
|
281
|
+
outputTokens: 0,
|
|
282
|
+
cacheReadTokens: 0,
|
|
283
|
+
cacheCreationTokens: 0,
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
for (const record of records) {
|
|
287
|
+
if (!record.type || !record.payload) continue;
|
|
288
|
+
|
|
289
|
+
if (record.type === 'session_meta') {
|
|
290
|
+
sessionMeta = record.payload as unknown as CodexSessionMetaPayload;
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (record.type === 'turn_context') {
|
|
295
|
+
latestTurnContext = record.payload as unknown as CodexTurnContextPayload;
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (record.type === 'event_msg') {
|
|
300
|
+
const payloadType = record.payload.type;
|
|
301
|
+
if (payloadType === 'token_count') {
|
|
302
|
+
const usage = (
|
|
303
|
+
record.payload.info as { total_token_usage?: CodexTokenUsagePayload } | undefined
|
|
304
|
+
)?.total_token_usage;
|
|
305
|
+
if (usage) {
|
|
306
|
+
totalUsage = {
|
|
307
|
+
inputTokens: usage.input_tokens || 0,
|
|
308
|
+
outputTokens: usage.output_tokens || 0,
|
|
309
|
+
cacheReadTokens: usage.cached_input_tokens || 0,
|
|
310
|
+
cacheCreationTokens: 0,
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (record.type !== 'response_item') continue;
|
|
318
|
+
|
|
319
|
+
const payloadType = record.payload.type;
|
|
320
|
+
if (payloadType === 'message') {
|
|
321
|
+
const role = record.payload.role;
|
|
322
|
+
if (role !== 'user' && role !== 'assistant') continue;
|
|
323
|
+
|
|
324
|
+
const content = extractTextContent(record.payload.content);
|
|
325
|
+
if (role === 'user') {
|
|
326
|
+
if (content) {
|
|
327
|
+
fallbackUserPrompts.push(content);
|
|
328
|
+
if (!taskPrompt && isMeaningfulTaskPrompt(content)) {
|
|
329
|
+
taskPrompt = content;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
transcript.push({
|
|
335
|
+
turnIndex: transcript.length,
|
|
336
|
+
role,
|
|
337
|
+
content,
|
|
338
|
+
modifiedFiles: [],
|
|
339
|
+
toolUses: [],
|
|
340
|
+
});
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
if (payloadType === 'function_call') {
|
|
345
|
+
const toolName =
|
|
346
|
+
typeof record.payload.name === 'string' ? record.payload.name : 'unknown';
|
|
347
|
+
const toolUseId =
|
|
348
|
+
typeof record.payload.call_id === 'string' ? record.payload.call_id : '';
|
|
349
|
+
const rawArguments =
|
|
350
|
+
typeof record.payload.arguments === 'string' ? record.payload.arguments : undefined;
|
|
351
|
+
const input = parseJsonObject(record.payload.arguments);
|
|
352
|
+
const assistantTurn = getOrCreateAssistantTurn(transcript);
|
|
353
|
+
|
|
354
|
+
assistantTurn.toolUses.push({
|
|
355
|
+
toolName,
|
|
356
|
+
toolUseId,
|
|
357
|
+
input: sanitizeInput(input),
|
|
358
|
+
});
|
|
359
|
+
assistantTurn.modifiedFiles.push(
|
|
360
|
+
...extractModifiedFiles(toolName, toolUseId, input, rawArguments),
|
|
361
|
+
);
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
if (payloadType === 'custom_tool_call') {
|
|
366
|
+
const toolName =
|
|
367
|
+
typeof record.payload.name === 'string' ? record.payload.name : 'unknown';
|
|
368
|
+
const toolUseId =
|
|
369
|
+
typeof record.payload.call_id === 'string' ? record.payload.call_id : '';
|
|
370
|
+
const rawInput =
|
|
371
|
+
typeof record.payload.input === 'string' ? record.payload.input : '';
|
|
372
|
+
const input = rawInput ? { input: rawInput } : {};
|
|
373
|
+
const assistantTurn = getOrCreateAssistantTurn(transcript);
|
|
374
|
+
|
|
375
|
+
assistantTurn.toolUses.push({
|
|
376
|
+
toolName,
|
|
377
|
+
toolUseId,
|
|
378
|
+
input: sanitizeInput(input),
|
|
379
|
+
});
|
|
380
|
+
assistantTurn.modifiedFiles.push(
|
|
381
|
+
...extractModifiedFiles(toolName, toolUseId, input, rawInput),
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (!taskPrompt) {
|
|
387
|
+
taskPrompt = fallbackUserPrompts.find((prompt) => prompt.trim()) || '';
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const allModifiedFiles = new Set<string>();
|
|
391
|
+
for (const turn of transcript) {
|
|
392
|
+
for (const modifiedFile of turn.modifiedFiles) {
|
|
393
|
+
allModifiedFiles.add(modifiedFile.filePath);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
const stat = fs.statSync(sessionFilePath);
|
|
398
|
+
|
|
399
|
+
return {
|
|
400
|
+
agent: 'codex',
|
|
401
|
+
sessionId: extractSessionId(sessionFilePath, sessionMeta),
|
|
402
|
+
sessionFilePath,
|
|
403
|
+
taskPrompt,
|
|
404
|
+
modifiedFiles: Array.from(allModifiedFiles),
|
|
405
|
+
tokenUsage: totalUsage,
|
|
406
|
+
transcript,
|
|
407
|
+
metadata: {
|
|
408
|
+
model: latestTurnContext?.model,
|
|
409
|
+
version: sessionMeta?.cli_version,
|
|
410
|
+
gitBranch: sessionMeta?.git?.branch,
|
|
411
|
+
startedAt: sessionMeta?.timestamp,
|
|
412
|
+
sessionFileModifiedAt: stat.mtime.toISOString(),
|
|
413
|
+
},
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
}
|
|
@@ -1,10 +1,88 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
HOOKS_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
3
3
|
REPO_ROOT="$(cd "$HOOKS_DIR/.." && pwd)"
|
|
4
|
+
TSX_IMPORT="$HOOKS_DIR/node_modules/tsx/dist/loader.mjs"
|
|
5
|
+
TSX_BIN="$HOOKS_DIR/node_modules/.bin/tsx"
|
|
6
|
+
|
|
7
|
+
if [ ! -f "$TSX_IMPORT" ]; then
|
|
8
|
+
TSX_IMPORT="tsx"
|
|
9
|
+
fi
|
|
10
|
+
|
|
11
|
+
node_version() {
|
|
12
|
+
node -v 2>/dev/null | sed 's/^v//'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
node_version_major() {
|
|
16
|
+
node_version | cut -d. -f1
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
node_version_minor() {
|
|
20
|
+
node_version | cut -d. -f2
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
node_supports_import() {
|
|
24
|
+
major=$(node_version_major)
|
|
25
|
+
minor=$(node_version_minor)
|
|
26
|
+
|
|
27
|
+
if [ -z "$major" ] || [ -z "$minor" ]; then
|
|
28
|
+
return 1
|
|
29
|
+
fi
|
|
30
|
+
|
|
31
|
+
if [ "$major" -gt 20 ]; then
|
|
32
|
+
return 0
|
|
33
|
+
fi
|
|
34
|
+
|
|
35
|
+
if [ "$major" -eq 20 ] && [ "$minor" -ge 6 ]; then
|
|
36
|
+
return 0
|
|
37
|
+
fi
|
|
38
|
+
|
|
39
|
+
if [ "$major" -eq 19 ]; then
|
|
40
|
+
return 0
|
|
41
|
+
fi
|
|
42
|
+
|
|
43
|
+
if [ "$major" -eq 18 ] && [ "$minor" -ge 19 ]; then
|
|
44
|
+
return 0
|
|
45
|
+
fi
|
|
46
|
+
|
|
47
|
+
return 1
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
node_supports_loader() {
|
|
51
|
+
major=$(node_version_major)
|
|
52
|
+
|
|
53
|
+
if [ -z "$major" ]; then
|
|
54
|
+
return 1
|
|
55
|
+
fi
|
|
56
|
+
|
|
57
|
+
if [ "$major" -lt 18 ]; then
|
|
58
|
+
return 1
|
|
59
|
+
fi
|
|
60
|
+
|
|
61
|
+
! node_supports_import
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
run_tsx() {
|
|
65
|
+
if node_supports_import; then
|
|
66
|
+
node --import "$TSX_IMPORT" "$@"
|
|
67
|
+
return
|
|
68
|
+
fi
|
|
69
|
+
|
|
70
|
+
if node_supports_loader; then
|
|
71
|
+
node --loader "$TSX_IMPORT" "$@"
|
|
72
|
+
return
|
|
73
|
+
fi
|
|
74
|
+
|
|
75
|
+
if [ -x "$TSX_BIN" ]; then
|
|
76
|
+
"$TSX_BIN" "$@"
|
|
77
|
+
return
|
|
78
|
+
fi
|
|
79
|
+
|
|
80
|
+
npx tsx "$@"
|
|
81
|
+
}
|
|
4
82
|
|
|
5
83
|
# Extract agent context if running under an AI agent
|
|
6
84
|
# Capture stderr to detect whether an AI agent is present
|
|
7
|
-
AGENT_OUTPUT=$(
|
|
85
|
+
AGENT_OUTPUT=$(run_tsx "$HOOKS_DIR/agent-context/index.ts" "$REPO_ROOT" 2>&1) || true
|
|
8
86
|
|
|
9
87
|
# Print the agent context to stderr so it still appears in the commit output
|
|
10
88
|
if [ -n "$AGENT_OUTPUT" ]; then
|
|
@@ -19,7 +97,7 @@ fi
|
|
|
19
97
|
# --- AI agent detected: run automated checks ---
|
|
20
98
|
|
|
21
99
|
# Check for truncation violations in staged changes
|
|
22
|
-
TRUNCATION_OUTPUT=$(
|
|
100
|
+
TRUNCATION_OUTPUT=$(run_tsx "$HOOKS_DIR/truncation-checker/index.ts" 2>&1)
|
|
23
101
|
TRUNCATION_EXIT=$?
|
|
24
102
|
|
|
25
103
|
if [ -n "$TRUNCATION_OUTPUT" ]; then
|
|
@@ -12,7 +12,7 @@ if [ -n "$current_branch" ] && [ "$current_branch" != "main" ] && [ "$current_br
|
|
|
12
12
|
;;
|
|
13
13
|
*)
|
|
14
14
|
# Check if this is an AI agent session (set by agent-context detector)
|
|
15
|
-
if [ -n "$HAYSTACK_AGENT_SESSION" ] || [ -n "$CLAUDE_CODE" ] || [ -n "$CODEX_CLI" ]; then
|
|
15
|
+
if [ -n "$HAYSTACK_AGENT_SESSION" ] || [ -n "$CLAUDE_CODE" ] || [ -n "$CODEX_CLI" ] || [ -n "$CODEX_SHELL" ] || [ -n "$CODEX_THREAD_ID" ] || [ -n "$CODEX_CI" ]; then
|
|
16
16
|
echo ""
|
|
17
17
|
echo "💡 Tip: Use 'haystack submit' to create PRs through the auto-merge queue."
|
|
18
18
|
echo " This enables automatic analysis and merge when approved."
|
|
@@ -22,6 +22,9 @@ This is faster than waiting for human review on every change.
|
|
|
22
22
|
# Default: Submit to auto-merge queue
|
|
23
23
|
haystack submit
|
|
24
24
|
|
|
25
|
+
# Optional alpha auto-fix for straightforward mechanical issues
|
|
26
|
+
haystack submit --auto-fix
|
|
27
|
+
|
|
25
28
|
# Request Haystack review (for complex/risky changes)
|
|
26
29
|
haystack submit --review
|
|
27
30
|
|
|
@@ -64,6 +67,22 @@ Use for straightforward changes that don't need human review:
|
|
|
64
67
|
haystack submit
|
|
65
68
|
```
|
|
66
69
|
|
|
70
|
+
### Auto-Fix (Alpha, Discouraged)
|
|
71
|
+
|
|
72
|
+
> **Do NOT default to `--auto-fix`.** It is an alpha feature.
|
|
73
|
+
> Use it only when the user explicitly wants to opt in, or when they are
|
|
74
|
+
> comfortable using the sandbox fixer for clearly straightforward mechanical issues.
|
|
75
|
+
|
|
76
|
+
Use `--auto-fix` only for issues like:
|
|
77
|
+
|
|
78
|
+
- Missing null checks
|
|
79
|
+
- Obvious typos or lint fixes
|
|
80
|
+
- Simple deterministic bugs with one clear fix
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
haystack submit --auto-fix
|
|
84
|
+
```
|
|
85
|
+
|
|
67
86
|
### Review Mode
|
|
68
87
|
|
|
69
88
|
> **Do NOT use `--review` unless the user explicitly asks for human review.**
|
|
@@ -110,6 +129,7 @@ This uses GitHub device flow - no tokens to copy/paste.
|
|
|
110
129
|
## Important Notes
|
|
111
130
|
|
|
112
131
|
- **Always use `haystack submit`** instead of `gh pr create` when working in Haystack-enabled repos
|
|
132
|
+
- Prefer plain `haystack submit` by default; use `--auto-fix` only as an explicit alpha opt-in for straightforward mechanical issues
|
|
113
133
|
- The command creates a `haystack/` prefixed branch automatically
|
|
114
134
|
- Labels are applied automatically based on your chosen mode
|
|
115
135
|
- You don't need to push manually - the command handles it
|
|
@@ -11,6 +11,10 @@ export declare function handleAgenticTool(tool?: string): Promise<void>;
|
|
|
11
11
|
/**
|
|
12
12
|
* Check if auto-merge is enabled for the current repo.
|
|
13
13
|
* Returns false if .haystack.json is missing or on error.
|
|
14
|
+
*
|
|
15
|
+
* NOTE: This does NOT go through loadHaystackConfig() because that function
|
|
16
|
+
* calls process.exit(1) when .haystack.json is missing — which is uncatchable
|
|
17
|
+
* by try/catch. We read the file directly so missing config safely returns false.
|
|
14
18
|
*/
|
|
15
19
|
export declare function isAutoMergeEnabled(): Promise<boolean>;
|
|
16
20
|
export declare function getAutoMergeStatus(): Promise<void>;
|