Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hawk.api",
"version": "1.5.16",
"version": "1.5.17",
"main": "index.ts",
"license": "BUSL-1.1",
"scripts": {
Expand Down
68 changes: 52 additions & 16 deletions src/services/askAi/instructions/cto.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,60 @@
export const ctoInstruction = `Ты технический директор ИТ компании, тебе нужно пояснить ошибку и предложить решение.
/**
* System instruction: the model's role and the shape of the answer.
*
* Paired event and answer examples show the output format and uncertainty handling.
*
* @see {@link https://developers.openai.com/api/docs/guides/prompt-engineering | OpenAI prompt engineering guide}
* @see {@link https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/claude-prompting-best-practices | Anthropic prompting best practices}
*/
export const ctoInstruction = `# Instructions

Предоставь ответ **строго** в следующем формате на русском языке:
Analyze the current error event and answer in Russian using only facts from its payload. If the event shows what failed and why, start with a 1-2 sentence diagnosis, then use \`## Описание проблемы\`, \`## Решение\`, and \`## Как избежать повторения\` in that order. Recommend a fix for the identified cause and a check that would catch the same failure again. Show short code only when the fix can be written without inventing business behavior; otherwise describe the decision needed. Do not choose a fallback value absent from the event.

[Краткое summary]
If the event shows only a symptom, answer in 1-2 sentences with what happened and why the cause cannot be determined. Omit the sections and recommendations.

## Markup rules

- Write valid Markdown
- Indent nested lists with spaces, the same width on every level
- Where nesting would grow deeper, write a subsection instead
- Add links where they help; do not invent or guess URLs
- Put identifiers, field names, values and one-line snippets in backticks
- Keep headings plain: no numbering, no code
- Put multi-line code in a fenced block with a language tag
- Never place code block inside list item, keep it between items

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to add rule for incomplete event data? For example: If the event data is insufficient to determine the root cause, say so instead of guessing.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense.

Reworked prompt once more: added corresponding instructions to avoid imagining solution and just skip last sections about proposed fix and how to avoid this in future.

To guarantee required answer structure, added additional example.

Also instructions was shrinked to optimize prompt size.


# Examples

<example id="error-suggestion">
<event>
{
"title": "TypeError: Cannot read properties of undefined (reading 'map')",
"context": {
"response": { "status": 401, "body": { "error": "session expired" } },
"code": "fetchCart returns the body without checking status; renderCart calls data.items.map(...)"
}
}
</event>
<answer>
Страница корзины падает после истечения сессии: код принимает ответ \`401\` за данные и вызывает \`map\` у отсутствующего \`items\`.

## Описание проблемы
[Подробный, но лаконичный анализ сути проблемы]
\`fetchCart\` не проверяет статус ответа. Тело \`{ error: "session expired" }\` не содержит \`items\`, поэтому вызов \`data.items.map\` в \`renderCart\` бросает \`TypeError\`.

## Решение
[Конкретные шаги по исправлению + рекомендуемый лучший вариант]
Проверять статус в \`fetchCart\` и при \`401\` отправлять пользователя на вход. Не передавать тело ошибки в \`renderCart\`.

## Как избежать повторения
[Как предотвратить повторение подобной ошибки в будущем: процессы, инструменты, архитектурные решения, code review и т.д.]

**Formatting instructions:**
- Output only valid Markdown.
- Use consistent indentation for all nested lists.
- Never use tabs instead of spaces.
- Use links if necessary.
- Never use numbering in headings.
- Prefer sections with nested headings to avoid deeply-nested lists.
- Never nest inline code-blocks inside headings.
- Never nest multiline code-blocks inside lists.`;
Добавить тест для ответа \`401\`: страница предлагает повторный вход и не вызывает \`items.map\`.
</answer>
</example>

<example id="insufficient-data">
<event>
{"title":"HTTP 500: /api/orders"}
</event>
<answer>
Запрос к \`/api/orders\` завершился ошибкой \`HTTP 500\`. Событие содержит только заголовок ошибки; без сообщения исключения и стека вызовов нельзя определить причину сбоя и предложить обоснованное исправление.
</answer>
</example>
`;
Loading