bloby-bot 0.19.2 → 0.20.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.
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Sub-agent System Prompt Builder
3
+ *
4
+ * Builds task-specific system prompts for background sub-agents.
5
+ * Extracts relevant sections from the main bloby-system-prompt.txt.
6
+ */
7
+
8
+ import fs from 'fs';
9
+ import path from 'path';
10
+ import { WORKSPACE_DIR } from '../../shared/paths.js';
11
+ import { log } from '../../shared/logger.js';
12
+
13
+ const PROMPT_FILE = path.join(import.meta.dirname, 'bloby-system-prompt.txt');
14
+
15
+ /** Read a workspace memory file, return '(empty)' if missing */
16
+ function readMemoryFile(filename: string): string {
17
+ try {
18
+ const content = fs.readFileSync(path.join(WORKSPACE_DIR, filename), 'utf-8').trim();
19
+ return content || '(empty)';
20
+ } catch {
21
+ return '(empty)';
22
+ }
23
+ }
24
+
25
+ /** Extract a section from the base prompt between two H1 headers */
26
+ function extractSection(prompt: string, startHeader: string, endHeader: string): string {
27
+ const startIdx = prompt.indexOf(startHeader);
28
+ if (startIdx === -1) return '';
29
+
30
+ const endIdx = endHeader ? prompt.indexOf(endHeader, startIdx + startHeader.length) : -1;
31
+ if (endIdx === -1) return prompt.slice(startIdx);
32
+
33
+ return prompt.slice(startIdx, endIdx).trim();
34
+ }
35
+
36
+ /** Build the system prompt for a sub-agent based on type */
37
+ export function assembleSubAgentPrompt(
38
+ type: 'coder' | 'researcher',
39
+ names: { botName: string; humanName: string },
40
+ ): string {
41
+ log.info(`[sub-agent-prompts] Building ${type} prompt for ${names.botName}`);
42
+ if (type === 'coder') {
43
+ const prompt = buildCoderPrompt(names);
44
+ log.info(`[sub-agent-prompts] Coder prompt assembled (${prompt.length} chars)`);
45
+ return prompt;
46
+ }
47
+ // Future: researcher, marketplace
48
+ const prompt = buildCoderPrompt(names);
49
+ log.info(`[sub-agent-prompts] Fallback prompt assembled (${prompt.length} chars)`);
50
+ return prompt;
51
+ }
52
+
53
+ function buildCoderPrompt(names: { botName: string; humanName: string }): string {
54
+ const memory = readMemoryFile('MEMORY.md');
55
+
56
+ // Read base prompt and extract coding-relevant sections
57
+ let codingSection = '';
58
+ let workspaceSection = '';
59
+ try {
60
+ const raw = fs.readFileSync(PROMPT_FILE, 'utf-8')
61
+ .replace(/\$BOT/g, names.botName)
62
+ .replace(/\$HUMAN/g, names.humanName);
63
+
64
+ codingSection = extractSection(raw, '# Coding Excellence', '# Personality and Conduct');
65
+ workspaceSection = extractSection(raw, '# Workspace Architecture', '# Personality and Conduct');
66
+
67
+ log.info(`[sub-agent-prompts] Extracted coding section: ${codingSection.length} chars`);
68
+ log.info(`[sub-agent-prompts] Extracted workspace section: ${workspaceSection.length} chars`);
69
+
70
+ // If workspace was already included in coding section, avoid duplication
71
+ if (codingSection.includes('# Workspace Architecture')) {
72
+ log.info(`[sub-agent-prompts] Workspace already in coding section — skipping duplicate`);
73
+ workspaceSection = '';
74
+ }
75
+ } catch (err) {
76
+ log.warn(`[sub-agent-prompts] Could not read base prompt: ${err}`);
77
+ }
78
+
79
+ return `# Sub-Agent: Coder
80
+
81
+ You are a background coding agent working for ${names.botName}. Your human is ${names.humanName}.
82
+
83
+ You have been delegated a specific coding task by the orchestrator agent. Your job is to complete it fully and report what you did.
84
+
85
+ ## How to Work
86
+ - Focus only on the task described below
87
+ - Complete the full task before responding
88
+ - Do not chat, greet, or explain what you will do — just do it
89
+ - If something is ambiguous, make a reasonable choice and note it in your summary
90
+ - When finished, write a concise summary of what you changed and why
91
+
92
+ ## Constraints
93
+ - Do NOT edit: PULSE.json, CRONS.json, MYSELF.md, MYHUMAN.md — those are orchestrator-only
94
+ - You MAY write to memory/daily notes if you learn something worth remembering
95
+ - You MAY read any file in the workspace
96
+ - You have full tool access: Read, Write, Edit, Bash, Glob, Grep
97
+
98
+ ---
99
+
100
+ ${codingSection}
101
+
102
+ ${workspaceSection}
103
+
104
+ ---
105
+
106
+ # Project Context
107
+
108
+ ## MEMORY.md
109
+ ${memory}
110
+ `;
111
+ }
@@ -1 +0,0 @@
1
- import{i as e}from"./bloby-d8kRAobK.js";export{e as Mermaid};