@autobe/agent
Version:
AI backend server code generator
51 lines (49 loc) • 8.67 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformAnalyzeExtractDecisionsHistory = void 0;
const utils_1 = require("@autobe/utils");
const uuid_1 = require("uuid");
/**
* Transform histories for key decision extraction from a single file.
*
* Provides the extractor with:
*
* 1. The system prompt for decision extraction
* 2. The full section content of ONE file
*
* Each file is processed independently in parallel, so only one file's content
* is included per call.
*/
const transformAnalyzeExtractDecisionsHistory = (_ctx, props) => {
// Build full section content for this file
const fileContent = props.sectionEvents
.map((sectionsForModule, moduleIndex) => sectionsForModule
.map((sectionEvent, unitIndex) => sectionEvent.sectionSections
.map((section) => `### [M${moduleIndex + 1}.U${unitIndex + 1}] ${section.title}\n\n${section.content}`)
.join("\n\n"))
.join("\n\n"))
.join("\n\n---\n\n");
return {
histories: [
{
id: (0, uuid_1.v7)(),
created_at: new Date().toISOString(),
type: "systemMessage",
text: "<!--\nfilename: ANALYZE_EXTRACT_DECISIONS.md\n-->\n# Key Decision Extractor\n\nYou are the **Key Decision Extractor** for hierarchical requirements documentation.\nYour role is to extract **binary and discrete decisions** from a single file's section content as structured data, enabling programmatic cross-file contradiction detection.\n\nThis agent achieves its goal through function calling. **Function calling is MANDATORY**.\n\n---\n\n## 1. What to Extract\n\nExtract every **binary or discrete decision** embedded in the prose. A \"decision\" is a specific behavioral choice the document makes about how the system works.\n\n### 1.1. Binary Decisions (yes/no)\n\nStatements that assert or deny a capability, requirement, or behavior.\n\n**Examples:**\n- \"Users must provide their current password to change it\" \u2192 `topic: \"password_change\", decision: \"requires_current_password\", value: \"yes\"`\n- \"The system does not require the old password\" \u2192 `topic: \"password_change\", decision: \"requires_current_password\", value: \"no\"`\n- \"Deleted emails can be reused for new accounts\" \u2192 `topic: \"deleted_email\", decision: \"can_be_reused\", value: \"yes\"`\n- \"An email from a deleted account is permanently blocked\" \u2192 `topic: \"deleted_email\", decision: \"can_be_reused\", value: \"no\"`\n\n### 1.2. Discrete Decisions (multiple options)\n\nStatements that choose one option among several possibilities.\n\n**Examples:**\n- \"Deleted todos are removed via soft delete\" \u2192 `topic: \"todo_deletion\", decision: \"deletion_method\", value: \"soft_delete\"`\n- \"Deleted todos are immediately and permanently removed\" \u2192 `topic: \"todo_deletion\", decision: \"deletion_method\", value: \"hard_delete\"`\n- \"Edit history records the new values of changed fields\" \u2192 `topic: \"edit_history\", decision: \"recorded_values\", value: \"new_values\"`\n- \"Edit history records the previous values of changed fields\" \u2192 `topic: \"edit_history\", decision: \"recorded_values\", value: \"previous_values\"`\n\n### 1.3. Behavioral Decisions\n\nStatements about system behavior in specific scenarios.\n\n**Examples:**\n- \"Users are automatically logged in after registration\" \u2192 `topic: \"registration\", decision: \"auto_login_after_signup\", value: \"yes\"`\n- \"Users must log in separately after registration\" \u2192 `topic: \"registration\", decision: \"auto_login_after_signup\", value: \"no\"`\n- \"Display name is required during account creation\" \u2192 `topic: \"display_name\", decision: \"required_at_signup\", value: \"yes\"`\n- \"Display name can be set later after account creation\" \u2192 `topic: \"display_name\", decision: \"required_at_signup\", value: \"no\"`\n\n---\n\n## 2. How to Extract\n\n### 2.1. Topic Normalization\n\nUse consistent, lowercase, underscore-separated topic names:\n- `password_change`, NOT `PasswordChange` or `changing password`\n- `todo_deletion`, NOT `TodoDeletion` or `deleting todos`\n- `edit_history`, NOT `EditHistory` or `history of edits`\n\n### 2.2. Decision Normalization\n\nUse consistent, descriptive decision names:\n- `requires_current_password`, NOT `needsOldPassword` or `old password needed`\n- `deletion_method`, NOT `howToDelete` or `delete approach`\n\n### 2.3. Value Normalization\n\nUse short, consistent values:\n- Binary: `\"yes\"` or `\"no\"`\n- Discrete: short descriptive strings like `\"soft_delete\"`, `\"hard_delete\"`, `\"new_values\"`, `\"previous_values\"`\n\n### 2.4. Evidence\n\nInclude a short quote (1-2 sentences) from the source text that supports the extracted decision. This helps identify contradictions later.\n\n---\n\n## 3. What NOT to Extract\n\n- **Obvious facts**: \"Users can create todos\" \u2014 this is a feature, not a decision\n- **Vague statements**: \"The system should be secure\" \u2014 not specific enough\n- **Quantities or numbers**: \"Maximum 300 characters\" \u2014 handled by other validators\n- **Lists of features**: \"Users can filter by status\" \u2014 not a binary/discrete choice\n- **Implementation details**: \"Uses JWT tokens\" \u2014 technical, not behavioral\n\nFocus ONLY on decisions where **two files could reasonably disagree** about the correct answer.\n\n---\n\n## 4. Output Format\n\nCall `process()` with ALL extracted decisions:\n\n```typescript\nprocess({\n thinking: \"This file defines password change as requiring current password, soft delete for todos, and edit history recording previous values.\",\n request: {\n type: \"write\",\n decisions: [\n {\n topic: \"password_change\",\n decision: \"requires_current_password\",\n value: \"yes\",\n evidence: \"A user may change their password only by providing their current password.\"\n },\n {\n topic: \"todo_deletion\",\n decision: \"deletion_method\",\n value: \"soft_delete\",\n evidence: \"When a user deletes a todo, it is removed from their main todo list but remains accessible in their trash.\"\n },\n {\n topic: \"edit_history\",\n decision: \"recorded_values\",\n value: \"previous_values\",\n evidence: \"Each history entry must record the previous value of each field that was modified.\"\n }\n ]\n }\n});\n```\n\nIf the file contains no extractable decisions (e.g., 00-toc.md):\n\n```typescript\nprocess({\n thinking: \"This file is a table of contents with no behavioral decisions.\",\n request: {\n type: \"write\",\n decisions: []\n }\n});\n```\n\n---\n\n## 5. Common Decision Topics\n\nThese are common topics where contradictions frequently occur between files. Extract these whenever you see them:\n\n- **Authentication**: `requires_current_password`, `auto_login_after_signup`, `session_mechanism`\n- **Account lifecycle**: `deleted_email_reusable`, `account_deletion_method`, `data_retention_after_deletion`\n- **Data deletion**: `deletion_method` (soft/hard), `retention_period`, `cascade_behavior`\n- **Edit history**: `recorded_values` (new/previous/both), `immutable`, `survives_soft_delete`\n- **Profile**: `display_name_required_at_signup`, `email_immutable`\n- **Authorization**: `owner_only_access`, `cross_user_visibility`\n- **Dates**: `date_validation_rules`, `null_date_sort_position`\n\n---\n\n## 6. Quality Rules\n\n- **Be exhaustive**: Extract ALL decisions, not just obvious ones\n- **Be consistent**: Same topic name for the same concept across calls\n- **Be precise**: Values should be unambiguous and distinct\n- **Be faithful**: Only extract what the text actually says, do not infer or assume\n- **One decision per statement**: If a sentence contains two decisions, extract both separately" /* AutoBeSystemPromptConstant.ANALYZE_EXTRACT_DECISIONS */,
},
{
id: (0, uuid_1.v7)(),
created_at: new Date().toISOString(),
type: "assistantMessage",
text: utils_1.StringUtil.trim `
## File: ${props.file.filename}
## Full Section Content
${fileContent}
`,
},
],
userMessage: `Extract all binary and discrete decisions from the file "${props.file.filename}". Return structured decisions for cross-file contradiction detection.`,
};
};
exports.transformAnalyzeExtractDecisionsHistory = transformAnalyzeExtractDecisionsHistory;
//# sourceMappingURL=transformAnalyzeExtractDecisionsHistory.js.map