crewly 1.4.40 → 1.4.41
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/config/orchestrator_tasks/prompts/orchestrator-prompt.md +11 -11
- package/config/roles/architect/prompt.md +1 -5
- package/config/roles/backend-developer/prompt.md +1 -5
- package/config/roles/content-strategist/prompt.md +1 -5
- package/config/roles/designer/prompt.md +1 -5
- package/config/roles/developer/prompt.md +1 -7
- package/config/roles/developer/soul.md +18 -0
- package/config/roles/frontend-developer/prompt.md +1 -5
- package/config/roles/fullstack-dev/prompt.md +1 -5
- package/config/roles/generalist/prompt.md +1 -7
- package/config/roles/ops/prompt.md +1 -7
- package/config/roles/orchestrator/prompt.md +44 -44
- package/config/roles/orchestrator/soul.md +18 -0
- package/config/roles/product-manager/prompt.md +1 -5
- package/config/roles/qa/prompt.md +1 -5
- package/config/roles/qa-engineer/prompt.md +1 -5
- package/config/roles/researcher/prompt.md +1 -5
- package/config/roles/researcher/soul.md +18 -0
- package/config/roles/sales/prompt.md +1 -5
- package/config/roles/support/prompt.md +1 -5
- package/config/roles/team-leader/prompt.md +2 -6
- package/config/roles/tpm/prompt.md +1 -5
- package/config/roles/ux-designer/prompt.md +1 -5
- package/config/souls/developer.md +30 -0
- package/config/souls/orchestrator.md +30 -0
- package/config/souls/researcher.md +30 -0
- package/config/templates/agent-claude-md.md +1 -1
- package/dist/backend/backend/src/services/agent/agent-registration.service.d.ts.map +1 -1
- package/dist/backend/backend/src/services/agent/agent-registration.service.js +12 -7
- package/dist/backend/backend/src/services/agent/agent-registration.service.js.map +1 -1
- package/dist/backend/backend/src/services/agent/oauth-relogin-monitor.service.d.ts.map +1 -1
- package/dist/backend/backend/src/services/agent/oauth-relogin-monitor.service.js +16 -4
- package/dist/backend/backend/src/services/agent/oauth-relogin-monitor.service.js.map +1 -1
- package/dist/backend/backend/src/services/agent/runtime-agent.service.abstract.d.ts.map +1 -1
- package/dist/backend/backend/src/services/agent/runtime-agent.service.abstract.js +11 -0
- package/dist/backend/backend/src/services/agent/runtime-agent.service.abstract.js.map +1 -1
- package/dist/backend/backend/src/services/ai/prompt-modules/communication.module.d.ts +46 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/communication.module.d.ts.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/communication.module.js +145 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/communication.module.js.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/context-assembly.service.d.ts +129 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/context-assembly.service.d.ts.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/context-assembly.service.js +202 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/context-assembly.service.js.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/identity.module.d.ts +28 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/identity.module.d.ts.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/identity.module.js +47 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/identity.module.js.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/index.d.ts +22 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/index.d.ts.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/index.js +26 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/index.js.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/learning-reference.module.d.ts +28 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/learning-reference.module.d.ts.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/learning-reference.module.js +55 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/learning-reference.module.js.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/lifecycle.module.d.ts +44 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/lifecycle.module.d.ts.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/lifecycle.module.js +112 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/lifecycle.module.js.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/memory-reference.module.d.ts +28 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/memory-reference.module.d.ts.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/memory-reference.module.js +46 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/memory-reference.module.js.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/project-reference.module.d.ts +29 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/project-reference.module.d.ts.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/project-reference.module.js +50 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/project-reference.module.js.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/prompt-assembly.service.d.ts +86 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/prompt-assembly.service.d.ts.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/prompt-assembly.service.js +212 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/prompt-assembly.service.js.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/prompt-module.interface.d.ts +100 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/prompt-module.interface.d.ts.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/prompt-module.interface.js +23 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/prompt-module.interface.js.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/recovery.module.d.ts +34 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/recovery.module.d.ts.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/recovery.module.js +61 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/recovery.module.js.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/scheduled-messages.loader.d.ts +55 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/scheduled-messages.loader.d.ts.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/scheduled-messages.loader.js +96 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/scheduled-messages.loader.js.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/skills-reference.module.d.ts +28 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/skills-reference.module.d.ts.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/skills-reference.module.js +65 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/skills-reference.module.js.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/soul.module.d.ts +60 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/soul.module.d.ts.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/soul.module.js +112 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/soul.module.js.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/team-reference.module.d.ts +54 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/team-reference.module.d.ts.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/team-reference.module.js +149 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/team-reference.module.js.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/user-profile-reference.module.d.ts +28 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/user-profile-reference.module.d.ts.map +1 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/user-profile-reference.module.js +53 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/user-profile-reference.module.js.map +1 -0
- package/dist/backend/backend/src/services/prompt/prompt-generator.service.d.ts.map +1 -1
- package/dist/backend/backend/src/services/prompt/prompt-generator.service.js +9 -11
- package/dist/backend/backend/src/services/prompt/prompt-generator.service.js.map +1 -1
- package/dist/backend/backend/src/services/skill/skill-catalog.service.d.ts.map +1 -1
- package/dist/backend/backend/src/services/skill/skill-catalog.service.js +3 -1
- package/dist/backend/backend/src/services/skill/skill-catalog.service.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory reference module — tells the agent how to access and store memories.
|
|
3
|
+
*
|
|
4
|
+
* Consolidates memory routing rules and session recovery protocol
|
|
5
|
+
* into a single module. Contains "how-to" instructions, not actual data.
|
|
6
|
+
*
|
|
7
|
+
* Sources: Path A Steps 8+9, Path B Section 7.
|
|
8
|
+
*/
|
|
9
|
+
export class MemoryReferenceModule {
|
|
10
|
+
name = 'memory_references';
|
|
11
|
+
priority = 4;
|
|
12
|
+
maxTokens = 500;
|
|
13
|
+
compactable = false;
|
|
14
|
+
/**
|
|
15
|
+
* Always included — memory access is fundamental to agent continuity.
|
|
16
|
+
*/
|
|
17
|
+
shouldInclude(_config) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Build the memory reference section with routing rules
|
|
22
|
+
* that tell the agent where to store different types of knowledge.
|
|
23
|
+
*
|
|
24
|
+
* @param config - Module configuration
|
|
25
|
+
* @returns Formatted markdown memory reference section
|
|
26
|
+
*/
|
|
27
|
+
async build(_config) {
|
|
28
|
+
return `## Memory Routing Rules
|
|
29
|
+
|
|
30
|
+
When you learn something worth remembering, store it in the **right place**:
|
|
31
|
+
|
|
32
|
+
| What you learned | Where to store it | How |
|
|
33
|
+
|---|---|---|
|
|
34
|
+
| Team conventions, coding standards, project patterns, shared decisions | Crewly knowledge (project-wide) | \`remember\` with \`scope: "project"\`, \`category: "pattern"\` or \`"decision"\` |
|
|
35
|
+
| User preferences, working style, role-specific tips | Crewly knowledge (agent-specific) | \`remember\` with \`scope: "agent"\`, \`category: "preference"\` or \`"fact"\` |
|
|
36
|
+
| Gotchas, bugs, workarounds discovered during work | Crewly knowledge (project-wide) | \`remember\` with \`scope: "project"\`, \`category: "gotcha"\` |
|
|
37
|
+
| Temporary task notes, in-progress state, scratch data | Project files or Claude native memory | Write to a file in the project, or keep in your conversation context |
|
|
38
|
+
|
|
39
|
+
**Rules of thumb:**
|
|
40
|
+
- If another agent or a future session would benefit → use \`remember\` with \`scope: "project"\`
|
|
41
|
+
- If only YOU would benefit in future sessions → use \`remember\` with \`scope: "agent"\`
|
|
42
|
+
- If it's only useful right now → keep it in your conversation context or a scratch file
|
|
43
|
+
- **Never store secrets, credentials, or tokens** in any memory system`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=memory-reference.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-reference.module.js","sourceRoot":"","sources":["../../../../../../../backend/src/services/ai/prompt-modules/memory-reference.module.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,OAAO,qBAAqB;IACjC,IAAI,GAAG,mBAAmB,CAAC;IAC3B,QAAQ,GAAG,CAAC,CAAC;IACb,SAAS,GAAG,GAAG,CAAC;IAChB,WAAW,GAAG,KAAK,CAAC;IAEpB;;OAEG;IACH,aAAa,CAAC,OAAqB;QAClC,OAAO,IAAI,CAAC;IACb,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,KAAK,CAAC,OAAqB;QAChC,OAAO;;;;;;;;;;;;;;;uEAe8D,CAAC;IACvE,CAAC;CACD"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { PromptModule, ModuleConfig } from './prompt-module.interface.js';
|
|
2
|
+
/**
|
|
3
|
+
* Project reference module — tells the agent how to access project knowledge.
|
|
4
|
+
*
|
|
5
|
+
* Provides references to SOPs, OKR, tasks/tickets, and project specs.
|
|
6
|
+
* Contains "how-to" instructions only — actual SOP content is loaded
|
|
7
|
+
* as context at runtime.
|
|
8
|
+
*
|
|
9
|
+
* Sources: Path B Section 3 (SOP context reference).
|
|
10
|
+
*/
|
|
11
|
+
export declare class ProjectReferenceModule implements PromptModule {
|
|
12
|
+
name: string;
|
|
13
|
+
priority: number;
|
|
14
|
+
maxTokens: number;
|
|
15
|
+
compactable: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Include when agent has a project path.
|
|
18
|
+
*/
|
|
19
|
+
shouldInclude(config: ModuleConfig): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Build the project reference section with instructions on
|
|
22
|
+
* how to access SOPs, project goals, and specifications.
|
|
23
|
+
*
|
|
24
|
+
* @param config - Module configuration with project path
|
|
25
|
+
* @returns Formatted markdown project reference section
|
|
26
|
+
*/
|
|
27
|
+
build(config: ModuleConfig): Promise<string>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=project-reference.module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-reference.module.d.ts","sourceRoot":"","sources":["../../../../../../../backend/src/services/ai/prompt-modules/project-reference.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAE1E;;;;;;;;GAQG;AACH,qBAAa,sBAAuB,YAAW,YAAY;IAC1D,IAAI,SAAwB;IAC5B,QAAQ,SAAK;IACb,SAAS,SAAO;IAChB,WAAW,UAAQ;IAEnB;;OAEG;IACH,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO;IAI5C;;;;;;OAMG;IACG,KAAK,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;CAqBlD"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project reference module — tells the agent how to access project knowledge.
|
|
3
|
+
*
|
|
4
|
+
* Provides references to SOPs, OKR, tasks/tickets, and project specs.
|
|
5
|
+
* Contains "how-to" instructions only — actual SOP content is loaded
|
|
6
|
+
* as context at runtime.
|
|
7
|
+
*
|
|
8
|
+
* Sources: Path B Section 3 (SOP context reference).
|
|
9
|
+
*/
|
|
10
|
+
export class ProjectReferenceModule {
|
|
11
|
+
name = 'project_references';
|
|
12
|
+
priority = 7;
|
|
13
|
+
maxTokens = 400;
|
|
14
|
+
compactable = true;
|
|
15
|
+
/**
|
|
16
|
+
* Include when agent has a project path.
|
|
17
|
+
*/
|
|
18
|
+
shouldInclude(config) {
|
|
19
|
+
return !!config.projectPath;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Build the project reference section with instructions on
|
|
23
|
+
* how to access SOPs, project goals, and specifications.
|
|
24
|
+
*
|
|
25
|
+
* @param config - Module configuration with project path
|
|
26
|
+
* @returns Formatted markdown project reference section
|
|
27
|
+
*/
|
|
28
|
+
async build(config) {
|
|
29
|
+
return `## Project References
|
|
30
|
+
|
|
31
|
+
### Standards
|
|
32
|
+
- Follow established code style and conventions
|
|
33
|
+
- TypeScript strict mode, aim for 80%+ test coverage
|
|
34
|
+
- Follow secure coding practices (parameterized queries, input sanitization, output encoding)
|
|
35
|
+
- Descriptive commit messages, atomic commits
|
|
36
|
+
|
|
37
|
+
### SOPs
|
|
38
|
+
Load relevant Standard Operating Procedures for your current task:
|
|
39
|
+
\`\`\`bash
|
|
40
|
+
bash ${config.agentSkillsPath}/core/get-sops/execute.sh '{"context":"<describe your current task>","role":"${config.role}"}'
|
|
41
|
+
\`\`\`
|
|
42
|
+
|
|
43
|
+
### Project Knowledge
|
|
44
|
+
- Project specs: \`${config.projectPath}/.crewly/specs/\`
|
|
45
|
+
- Active goals: \`${config.projectPath}/.crewly/goals/goals.md\`
|
|
46
|
+
- Task management: \`${config.projectPath}/.crewly/tasks/\`
|
|
47
|
+
- Knowledge base: \`${config.projectPath}/.crewly/knowledge/\``;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=project-reference.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-reference.module.js","sourceRoot":"","sources":["../../../../../../../backend/src/services/ai/prompt-modules/project-reference.module.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,OAAO,sBAAsB;IAClC,IAAI,GAAG,oBAAoB,CAAC;IAC5B,QAAQ,GAAG,CAAC,CAAC;IACb,SAAS,GAAG,GAAG,CAAC;IAChB,WAAW,GAAG,IAAI,CAAC;IAEnB;;OAEG;IACH,aAAa,CAAC,MAAoB;QACjC,OAAO,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC;IAC7B,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,KAAK,CAAC,MAAoB;QAC/B,OAAO;;;;;;;;;;;OAWF,MAAM,CAAC,eAAe,gFAAgF,MAAM,CAAC,IAAI;;;;qBAInG,MAAM,CAAC,WAAW;oBACnB,MAAM,CAAC,WAAW;uBACf,MAAM,CAAC,WAAW;sBACnB,MAAM,CAAC,WAAW,uBAAuB,CAAC;IAC/D,CAAC;CACD"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { PromptModule, ModuleConfig, ModuleBuildResult } from './prompt-module.interface.js';
|
|
2
|
+
/**
|
|
3
|
+
* Service that orchestrates the assembly of prompt modules into a complete agent prompt.
|
|
4
|
+
*
|
|
5
|
+
* Responsibilities:
|
|
6
|
+
* - Registers and manages prompt modules
|
|
7
|
+
* - Assembles modules in priority order
|
|
8
|
+
* - Enforces per-module and total token budgets
|
|
9
|
+
* - Supports Trusted Zone (non-compactable) vs Flexible Zone (compactable) modules
|
|
10
|
+
* - Works across all runtime types (claude-code, gemini-cli, crewly-agent)
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const assembler = new PromptAssemblyService();
|
|
15
|
+
* const prompt = await assembler.assemble({
|
|
16
|
+
* sessionName: 'crewly-dev-001',
|
|
17
|
+
* memberId: 'uuid-123',
|
|
18
|
+
* role: 'developer',
|
|
19
|
+
* projectPath: '/path/to/project',
|
|
20
|
+
* agentSkillsPath: '/path/to/skills/agent',
|
|
21
|
+
* tlSkillsPath: '/path/to/skills/team-leader',
|
|
22
|
+
* projectRoot: '/path/to/project',
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare class PromptAssemblyService {
|
|
27
|
+
private logger;
|
|
28
|
+
private modules;
|
|
29
|
+
private totalTokenBudget;
|
|
30
|
+
constructor(tokenBudget?: number);
|
|
31
|
+
/**
|
|
32
|
+
* Register the default set of prompt modules.
|
|
33
|
+
* Called automatically in constructor. Additional modules
|
|
34
|
+
* can be added via addModule().
|
|
35
|
+
*/
|
|
36
|
+
private registerDefaultModules;
|
|
37
|
+
/**
|
|
38
|
+
* Add a custom prompt module to the assembly pipeline.
|
|
39
|
+
*
|
|
40
|
+
* @param module - Module to add
|
|
41
|
+
*/
|
|
42
|
+
addModule(module: PromptModule): void;
|
|
43
|
+
/**
|
|
44
|
+
* Remove a module by name.
|
|
45
|
+
*
|
|
46
|
+
* @param name - Name of the module to remove
|
|
47
|
+
*/
|
|
48
|
+
removeModule(name: string): void;
|
|
49
|
+
/**
|
|
50
|
+
* Get all registered modules (for inspection/testing).
|
|
51
|
+
*
|
|
52
|
+
* @returns Array of registered prompt modules
|
|
53
|
+
*/
|
|
54
|
+
getModules(): PromptModule[];
|
|
55
|
+
/**
|
|
56
|
+
* Get or set the total token budget.
|
|
57
|
+
*
|
|
58
|
+
* @param budget - Optional new budget to set
|
|
59
|
+
* @returns Current token budget
|
|
60
|
+
*/
|
|
61
|
+
tokenBudget(budget?: number): number;
|
|
62
|
+
/**
|
|
63
|
+
* Assemble all applicable prompt modules into a single prompt string.
|
|
64
|
+
*
|
|
65
|
+
* Modules are processed in priority order (lowest number first).
|
|
66
|
+
* Non-compactable modules are always included (Trusted Zone).
|
|
67
|
+
* Compactable modules are skipped if the token budget is exceeded (Flexible Zone).
|
|
68
|
+
*
|
|
69
|
+
* @param config - Configuration with all context needed by modules
|
|
70
|
+
* @returns Assembled prompt string with all module sections
|
|
71
|
+
*/
|
|
72
|
+
assemble(config: ModuleConfig): Promise<string>;
|
|
73
|
+
/**
|
|
74
|
+
* Assemble modules and return detailed results with per-module metadata.
|
|
75
|
+
* Useful for debugging and token budget analysis.
|
|
76
|
+
*
|
|
77
|
+
* @param config - Configuration with all context needed by modules
|
|
78
|
+
* @returns Array of module build results with token estimates
|
|
79
|
+
*/
|
|
80
|
+
assembleWithDetails(config: ModuleConfig): Promise<{
|
|
81
|
+
prompt: string;
|
|
82
|
+
modules: ModuleBuildResult[];
|
|
83
|
+
totalTokens: number;
|
|
84
|
+
}>;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=prompt-assembly.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-assembly.service.d.ts","sourceRoot":"","sources":["../../../../../../../backend/src/services/ai/prompt-modules/prompt-assembly.service.ts"],"names":[],"mappings":"AACA,OAAO,EACN,YAAY,EACZ,YAAY,EACZ,iBAAiB,EAEjB,MAAM,8BAA8B,CAAC;AAkBtC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,qBAAqB;IACjC,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,OAAO,CAAsB;IACrC,OAAO,CAAC,gBAAgB,CAAS;gBAErB,WAAW,GAAE,MAA6B;IAMtD;;;;OAIG;IACH,OAAO,CAAC,sBAAsB;IAU9B;;;;OAIG;IACH,SAAS,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI;IAIrC;;;;OAIG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIhC;;;;OAIG;IACH,UAAU,IAAI,YAAY,EAAE;IAI5B;;;;;OAKG;IACH,WAAW,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM;IAOpC;;;;;;;;;OASG;IACG,QAAQ,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;IAoErD;;;;;;OAMG;IACG,mBAAmB,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC;QACxD,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,iBAAiB,EAAE,CAAC;QAC7B,WAAW,EAAE,MAAM,CAAC;KACpB,CAAC;CAmCF"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { LoggerService } from '../../core/logger.service.js';
|
|
2
|
+
import { estimateTokens, } from './prompt-module.interface.js';
|
|
3
|
+
import { IdentityModule } from './identity.module.js';
|
|
4
|
+
import { SkillsReferenceModule } from './skills-reference.module.js';
|
|
5
|
+
import { MemoryReferenceModule } from './memory-reference.module.js';
|
|
6
|
+
import { TeamReferenceModule } from './team-reference.module.js';
|
|
7
|
+
import { ProjectReferenceModule } from './project-reference.module.js';
|
|
8
|
+
/**
|
|
9
|
+
* Default total token budget for all prompt modules combined.
|
|
10
|
+
* Modules exceeding this budget are skipped (compactable ones only).
|
|
11
|
+
*/
|
|
12
|
+
const DEFAULT_TOKEN_BUDGET = 25000;
|
|
13
|
+
/**
|
|
14
|
+
* Separator between prompt modules in assembled output.
|
|
15
|
+
*/
|
|
16
|
+
const MODULE_SEPARATOR = '\n\n---\n\n';
|
|
17
|
+
/**
|
|
18
|
+
* Service that orchestrates the assembly of prompt modules into a complete agent prompt.
|
|
19
|
+
*
|
|
20
|
+
* Responsibilities:
|
|
21
|
+
* - Registers and manages prompt modules
|
|
22
|
+
* - Assembles modules in priority order
|
|
23
|
+
* - Enforces per-module and total token budgets
|
|
24
|
+
* - Supports Trusted Zone (non-compactable) vs Flexible Zone (compactable) modules
|
|
25
|
+
* - Works across all runtime types (claude-code, gemini-cli, crewly-agent)
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const assembler = new PromptAssemblyService();
|
|
30
|
+
* const prompt = await assembler.assemble({
|
|
31
|
+
* sessionName: 'crewly-dev-001',
|
|
32
|
+
* memberId: 'uuid-123',
|
|
33
|
+
* role: 'developer',
|
|
34
|
+
* projectPath: '/path/to/project',
|
|
35
|
+
* agentSkillsPath: '/path/to/skills/agent',
|
|
36
|
+
* tlSkillsPath: '/path/to/skills/team-leader',
|
|
37
|
+
* projectRoot: '/path/to/project',
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export class PromptAssemblyService {
|
|
42
|
+
logger;
|
|
43
|
+
modules = [];
|
|
44
|
+
totalTokenBudget;
|
|
45
|
+
constructor(tokenBudget = DEFAULT_TOKEN_BUDGET) {
|
|
46
|
+
this.logger = LoggerService.getInstance().createComponentLogger('PromptAssemblyService');
|
|
47
|
+
this.totalTokenBudget = tokenBudget;
|
|
48
|
+
this.registerDefaultModules();
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Register the default set of prompt modules.
|
|
52
|
+
* Called automatically in constructor. Additional modules
|
|
53
|
+
* can be added via addModule().
|
|
54
|
+
*/
|
|
55
|
+
registerDefaultModules() {
|
|
56
|
+
this.modules = [
|
|
57
|
+
new IdentityModule(),
|
|
58
|
+
new MemoryReferenceModule(),
|
|
59
|
+
new SkillsReferenceModule(),
|
|
60
|
+
new TeamReferenceModule(),
|
|
61
|
+
new ProjectReferenceModule(),
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Add a custom prompt module to the assembly pipeline.
|
|
66
|
+
*
|
|
67
|
+
* @param module - Module to add
|
|
68
|
+
*/
|
|
69
|
+
addModule(module) {
|
|
70
|
+
this.modules.push(module);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Remove a module by name.
|
|
74
|
+
*
|
|
75
|
+
* @param name - Name of the module to remove
|
|
76
|
+
*/
|
|
77
|
+
removeModule(name) {
|
|
78
|
+
this.modules = this.modules.filter((m) => m.name !== name);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Get all registered modules (for inspection/testing).
|
|
82
|
+
*
|
|
83
|
+
* @returns Array of registered prompt modules
|
|
84
|
+
*/
|
|
85
|
+
getModules() {
|
|
86
|
+
return [...this.modules];
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get or set the total token budget.
|
|
90
|
+
*
|
|
91
|
+
* @param budget - Optional new budget to set
|
|
92
|
+
* @returns Current token budget
|
|
93
|
+
*/
|
|
94
|
+
tokenBudget(budget) {
|
|
95
|
+
if (budget !== undefined) {
|
|
96
|
+
this.totalTokenBudget = budget;
|
|
97
|
+
}
|
|
98
|
+
return this.totalTokenBudget;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Assemble all applicable prompt modules into a single prompt string.
|
|
102
|
+
*
|
|
103
|
+
* Modules are processed in priority order (lowest number first).
|
|
104
|
+
* Non-compactable modules are always included (Trusted Zone).
|
|
105
|
+
* Compactable modules are skipped if the token budget is exceeded (Flexible Zone).
|
|
106
|
+
*
|
|
107
|
+
* @param config - Configuration with all context needed by modules
|
|
108
|
+
* @returns Assembled prompt string with all module sections
|
|
109
|
+
*/
|
|
110
|
+
async assemble(config) {
|
|
111
|
+
const results = [];
|
|
112
|
+
let totalTokens = 0;
|
|
113
|
+
// Sort modules by priority (ascending — lower number = higher priority)
|
|
114
|
+
const sorted = [...this.modules].sort((a, b) => a.priority - b.priority);
|
|
115
|
+
for (const module of sorted) {
|
|
116
|
+
// Check if module should be included
|
|
117
|
+
if (!module.shouldInclude(config)) {
|
|
118
|
+
this.logger.debug(`Module '${module.name}' skipped (shouldInclude=false)`, {
|
|
119
|
+
sessionName: config.sessionName,
|
|
120
|
+
});
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
// Check token budget for compactable modules
|
|
124
|
+
if (module.compactable && totalTokens + module.maxTokens > this.totalTokenBudget) {
|
|
125
|
+
this.logger.info(`Module '${module.name}' skipped (token budget exceeded)`, {
|
|
126
|
+
sessionName: config.sessionName,
|
|
127
|
+
currentTokens: totalTokens,
|
|
128
|
+
moduleMaxTokens: module.maxTokens,
|
|
129
|
+
budget: this.totalTokenBudget,
|
|
130
|
+
});
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
const content = await module.build(config);
|
|
135
|
+
if (content && content.trim()) {
|
|
136
|
+
const tokens = estimateTokens(content);
|
|
137
|
+
results.push({
|
|
138
|
+
name: module.name,
|
|
139
|
+
content: content.trim(),
|
|
140
|
+
estimatedTokens: tokens,
|
|
141
|
+
});
|
|
142
|
+
totalTokens += tokens;
|
|
143
|
+
this.logger.debug(`Module '${module.name}' built`, {
|
|
144
|
+
sessionName: config.sessionName,
|
|
145
|
+
tokens,
|
|
146
|
+
totalTokens,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
this.logger.error(`Module '${module.name}' failed to build`, {
|
|
152
|
+
sessionName: config.sessionName,
|
|
153
|
+
error: error instanceof Error ? error.message : String(error),
|
|
154
|
+
});
|
|
155
|
+
// Non-compactable modules failing is critical
|
|
156
|
+
if (!module.compactable) {
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
// Compactable modules failing is logged but not fatal
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
this.logger.info('Prompt assembly complete', {
|
|
163
|
+
sessionName: config.sessionName,
|
|
164
|
+
moduleCount: results.length,
|
|
165
|
+
totalTokens,
|
|
166
|
+
budget: this.totalTokenBudget,
|
|
167
|
+
modules: results.map((r) => r.name),
|
|
168
|
+
});
|
|
169
|
+
return results.map((r) => r.content).join(MODULE_SEPARATOR);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Assemble modules and return detailed results with per-module metadata.
|
|
173
|
+
* Useful for debugging and token budget analysis.
|
|
174
|
+
*
|
|
175
|
+
* @param config - Configuration with all context needed by modules
|
|
176
|
+
* @returns Array of module build results with token estimates
|
|
177
|
+
*/
|
|
178
|
+
async assembleWithDetails(config) {
|
|
179
|
+
const results = [];
|
|
180
|
+
let totalTokens = 0;
|
|
181
|
+
const sorted = [...this.modules].sort((a, b) => a.priority - b.priority);
|
|
182
|
+
for (const module of sorted) {
|
|
183
|
+
if (!module.shouldInclude(config))
|
|
184
|
+
continue;
|
|
185
|
+
if (module.compactable && totalTokens + module.maxTokens > this.totalTokenBudget) {
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
try {
|
|
189
|
+
const content = await module.build(config);
|
|
190
|
+
if (content && content.trim()) {
|
|
191
|
+
const tokens = estimateTokens(content);
|
|
192
|
+
results.push({
|
|
193
|
+
name: module.name,
|
|
194
|
+
content: content.trim(),
|
|
195
|
+
estimatedTokens: tokens,
|
|
196
|
+
});
|
|
197
|
+
totalTokens += tokens;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
if (!module.compactable)
|
|
202
|
+
throw error;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return {
|
|
206
|
+
prompt: results.map((r) => r.content).join(MODULE_SEPARATOR),
|
|
207
|
+
modules: results,
|
|
208
|
+
totalTokens,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
//# sourceMappingURL=prompt-assembly.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-assembly.service.js","sourceRoot":"","sources":["../../../../../../../backend/src/services/ai/prompt-modules/prompt-assembly.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAmB,MAAM,8BAA8B,CAAC;AAC9E,OAAO,EAIN,cAAc,GACd,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAEvE;;;GAGG;AACH,MAAM,oBAAoB,GAAG,KAAK,CAAC;AAEnC;;GAEG;AACH,MAAM,gBAAgB,GAAG,aAAa,CAAC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,OAAO,qBAAqB;IACzB,MAAM,CAAkB;IACxB,OAAO,GAAmB,EAAE,CAAC;IAC7B,gBAAgB,CAAS;IAEj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C,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;QAEzE,KAAK,MAAM,MAAM,IAAI,MAAM,EAAE,CAAC;YAC7B,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC;gBAAE,SAAS;YAE5C,IAAI,MAAM,CAAC,WAAW,IAAI,WAAW,GAAG,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;gBAClF,SAAS;YACV,CAAC;YAED,IAAI,CAAC;gBACJ,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;gBAC3C,IAAI,OAAO,IAAI,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;oBAC/B,MAAM,MAAM,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;oBACvC,OAAO,CAAC,IAAI,CAAC;wBACZ,IAAI,EAAE,MAAM,CAAC,IAAI;wBACjB,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE;wBACvB,eAAe,EAAE,MAAM;qBACvB,CAAC,CAAC;oBACH,WAAW,IAAI,MAAM,CAAC;gBACvB,CAAC;YACF,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,IAAI,CAAC,MAAM,CAAC,WAAW;oBAAE,MAAM,KAAK,CAAC;YACtC,CAAC;QACF,CAAC;QAED,OAAO;YACN,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC;YAC5D,OAAO,EAAE,OAAO;YAChB,WAAW;SACX,CAAC;IACH,CAAC;CACD"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for modular prompt components.
|
|
3
|
+
*
|
|
4
|
+
* Each module is responsible for one concern (identity, skills, team, etc.)
|
|
5
|
+
* and produces a markdown string that gets assembled into the final agent prompt.
|
|
6
|
+
*
|
|
7
|
+
* Modules are assembled in priority order (1 = highest, assembled first).
|
|
8
|
+
* Non-compactable modules are never truncated when token budget is tight.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Configuration passed to each prompt module during assembly.
|
|
12
|
+
* Contains all the context needed to build module-specific content.
|
|
13
|
+
*/
|
|
14
|
+
export interface ModuleConfig {
|
|
15
|
+
/** Agent's session name (e.g. 'crewly-product-sam-217bfbbf') */
|
|
16
|
+
sessionName: string;
|
|
17
|
+
/** Agent's member ID (UUID) */
|
|
18
|
+
memberId: string;
|
|
19
|
+
/** Agent's role (e.g. 'developer', 'orchestrator') */
|
|
20
|
+
role: string;
|
|
21
|
+
/** Team ID this agent belongs to */
|
|
22
|
+
teamId?: string;
|
|
23
|
+
/** Absolute path to the project directory */
|
|
24
|
+
projectPath?: string;
|
|
25
|
+
/** Runtime type determines formatting and injection strategy */
|
|
26
|
+
runtimeType?: 'claude-code' | 'gemini-cli' | 'codex' | 'crewly-agent';
|
|
27
|
+
/** Whether this agent can delegate tasks to subordinates */
|
|
28
|
+
canDelegate?: boolean;
|
|
29
|
+
/** Resolved subordinate details for TL agents */
|
|
30
|
+
subordinates?: SubordinateInfoCompat[];
|
|
31
|
+
/** Absolute path to agent skill scripts */
|
|
32
|
+
agentSkillsPath: string;
|
|
33
|
+
/** Absolute path to team-leader skill scripts */
|
|
34
|
+
tlSkillsPath: string;
|
|
35
|
+
/** Absolute path to the project root (where config/ lives) */
|
|
36
|
+
projectRoot: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Subordinate info compatible with the existing SubordinateInfo type
|
|
40
|
+
*/
|
|
41
|
+
export interface SubordinateInfoCompat {
|
|
42
|
+
name: string;
|
|
43
|
+
sessionName: string;
|
|
44
|
+
role: string;
|
|
45
|
+
memberId: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Result of building a single prompt module.
|
|
49
|
+
* Includes the content and metadata for budget tracking.
|
|
50
|
+
*/
|
|
51
|
+
export interface ModuleBuildResult {
|
|
52
|
+
/** Module name */
|
|
53
|
+
name: string;
|
|
54
|
+
/** Generated markdown content */
|
|
55
|
+
content: string;
|
|
56
|
+
/** Estimated token count of the content */
|
|
57
|
+
estimatedTokens: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Interface that all prompt modules must implement.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* class IdentityModule implements PromptModule {
|
|
65
|
+
* name = 'identity';
|
|
66
|
+
* priority = 1;
|
|
67
|
+
* maxTokens = 150;
|
|
68
|
+
* compactable = false;
|
|
69
|
+
*
|
|
70
|
+
* shouldInclude(_config: ModuleConfig): boolean { return true; }
|
|
71
|
+
*
|
|
72
|
+
* async build(config: ModuleConfig): Promise<string> {
|
|
73
|
+
* return `## Your Identity\n- **Session Name:** ${config.sessionName}`;
|
|
74
|
+
* }
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export interface PromptModule {
|
|
79
|
+
/** Module name (used for logging and debugging) */
|
|
80
|
+
name: string;
|
|
81
|
+
/** Assembly priority (1 = highest, assembled first) */
|
|
82
|
+
priority: number;
|
|
83
|
+
/** Token soft cap for this module */
|
|
84
|
+
maxTokens: number;
|
|
85
|
+
/** Whether this module can be skipped when token budget is tight */
|
|
86
|
+
compactable: boolean;
|
|
87
|
+
/** Condition check — return false to skip this module */
|
|
88
|
+
shouldInclude(config: ModuleConfig): boolean;
|
|
89
|
+
/** Build module content as markdown string */
|
|
90
|
+
build(config: ModuleConfig): Promise<string>;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Estimate token count from a string.
|
|
94
|
+
* Uses the rough heuristic of ~4 characters per token (suitable for English/code mix).
|
|
95
|
+
*
|
|
96
|
+
* @param text - Text to estimate tokens for
|
|
97
|
+
* @returns Estimated token count
|
|
98
|
+
*/
|
|
99
|
+
export declare function estimateTokens(text: string): number;
|
|
100
|
+
//# sourceMappingURL=prompt-module.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-module.interface.d.ts","sourceRoot":"","sources":["../../../../../../../backend/src/services/ai/prompt-modules/prompt-module.interface.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC5B,gEAAgE;IAChE,WAAW,EAAE,MAAM,CAAC;IACpB,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,oCAAoC;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6CAA6C;IAC7C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gEAAgE;IAChE,WAAW,CAAC,EAAE,aAAa,GAAG,YAAY,GAAG,OAAO,GAAG,cAAc,CAAC;IACtE,4DAA4D;IAC5D,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,iDAAiD;IACjD,YAAY,CAAC,EAAE,qBAAqB,EAAE,CAAC;IACvC,2CAA2C;IAC3C,eAAe,EAAE,MAAM,CAAC;IACxB,iDAAiD;IACjD,YAAY,EAAE,MAAM,CAAC;IACrB,8DAA8D;IAC9D,WAAW,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IACjC,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,iCAAiC;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,eAAe,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,WAAW,YAAY;IAC5B,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,QAAQ,EAAE,MAAM,CAAC;IACjB,qCAAqC;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,oEAAoE;IACpE,WAAW,EAAE,OAAO,CAAC;IACrB,yDAAyD;IACzD,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC;IAC7C,8CAA8C;IAC9C,KAAK,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC7C;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAInD"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for modular prompt components.
|
|
3
|
+
*
|
|
4
|
+
* Each module is responsible for one concern (identity, skills, team, etc.)
|
|
5
|
+
* and produces a markdown string that gets assembled into the final agent prompt.
|
|
6
|
+
*
|
|
7
|
+
* Modules are assembled in priority order (1 = highest, assembled first).
|
|
8
|
+
* Non-compactable modules are never truncated when token budget is tight.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Estimate token count from a string.
|
|
12
|
+
* Uses the rough heuristic of ~4 characters per token (suitable for English/code mix).
|
|
13
|
+
*
|
|
14
|
+
* @param text - Text to estimate tokens for
|
|
15
|
+
* @returns Estimated token count
|
|
16
|
+
*/
|
|
17
|
+
export function estimateTokens(text) {
|
|
18
|
+
if (!text)
|
|
19
|
+
return 0;
|
|
20
|
+
// ~4 chars per token is a reasonable estimate for English + code
|
|
21
|
+
return Math.ceil(text.length / 4);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=prompt-module.interface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-module.interface.js","sourceRoot":"","sources":["../../../../../../../backend/src/services/ai/prompt-modules/prompt-module.interface.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAwFH;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY;IAC1C,IAAI,CAAC,IAAI;QAAE,OAAO,CAAC,CAAC;IACpB,iEAAiE;IACjE,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { PromptModule, ModuleConfig } from './prompt-module.interface.js';
|
|
2
|
+
/**
|
|
3
|
+
* Recovery module — unified session recovery protocol.
|
|
4
|
+
*
|
|
5
|
+
* Consolidates the restart/recovery flow that was previously scattered
|
|
6
|
+
* across prompt-builder.service.ts buildSessionRecoverySection(),
|
|
7
|
+
* agent-registration.service.ts hardcoded commands, role prompts
|
|
8
|
+
* (Session Recovery Protocol), and session-handoff.service.ts.
|
|
9
|
+
*
|
|
10
|
+
* Produces the mandatory startup sequence: recall → get-my-context → assess.
|
|
11
|
+
* This module is non-compactable because skipping recovery causes
|
|
12
|
+
* duplicate work and lost context.
|
|
13
|
+
*
|
|
14
|
+
* Sources: Path A Step 9, prompt-builder buildSessionRecoverySection(),
|
|
15
|
+
* developer/prompt.md §Session Recovery Protocol.
|
|
16
|
+
*/
|
|
17
|
+
export declare class RecoveryModule implements PromptModule {
|
|
18
|
+
name: string;
|
|
19
|
+
priority: number;
|
|
20
|
+
maxTokens: number;
|
|
21
|
+
compactable: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Always included — every agent needs session recovery.
|
|
24
|
+
*/
|
|
25
|
+
shouldInclude(_config: ModuleConfig): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Build the session recovery protocol with executable bash commands.
|
|
28
|
+
*
|
|
29
|
+
* @param config - Module configuration with agent identity
|
|
30
|
+
* @returns Formatted markdown recovery section
|
|
31
|
+
*/
|
|
32
|
+
build(config: ModuleConfig): Promise<string>;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=recovery.module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recovery.module.d.ts","sourceRoot":"","sources":["../../../../../../../backend/src/services/ai/prompt-modules/recovery.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAE1E;;;;;;;;;;;;;;GAcG;AACH,qBAAa,cAAe,YAAW,YAAY;IAClD,IAAI,SAAc;IAClB,QAAQ,SAAK;IACb,SAAS,SAAO;IAChB,WAAW,UAAS;IAEpB;;OAEG;IACH,aAAa,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO;IAI7C;;;;;OAKG;IACG,KAAK,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;CA4BlD"}
|