@aiagentflow/cli 0.1.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/LICENSE +21 -0
- package/README.md +232 -0
- package/dist/agents/base.d.ts +69 -0
- package/dist/agents/base.d.ts.map +1 -0
- package/dist/agents/base.js +78 -0
- package/dist/agents/base.js.map +1 -0
- package/dist/agents/factory.d.ts +21 -0
- package/dist/agents/factory.d.ts.map +1 -0
- package/dist/agents/factory.js +50 -0
- package/dist/agents/factory.js.map +1 -0
- package/dist/agents/roles/architect.d.ts +23 -0
- package/dist/agents/roles/architect.d.ts.map +1 -0
- package/dist/agents/roles/architect.js +39 -0
- package/dist/agents/roles/architect.js.map +1 -0
- package/dist/agents/roles/coder.d.ts +19 -0
- package/dist/agents/roles/coder.d.ts.map +1 -0
- package/dist/agents/roles/coder.js +38 -0
- package/dist/agents/roles/coder.js.map +1 -0
- package/dist/agents/roles/fixer.d.ts +19 -0
- package/dist/agents/roles/fixer.d.ts.map +1 -0
- package/dist/agents/roles/fixer.js +29 -0
- package/dist/agents/roles/fixer.js.map +1 -0
- package/dist/agents/roles/judge.d.ts +24 -0
- package/dist/agents/roles/judge.d.ts.map +1 -0
- package/dist/agents/roles/judge.js +38 -0
- package/dist/agents/roles/judge.js.map +1 -0
- package/dist/agents/roles/reviewer.d.ts +28 -0
- package/dist/agents/roles/reviewer.d.ts.map +1 -0
- package/dist/agents/roles/reviewer.js +49 -0
- package/dist/agents/roles/reviewer.js.map +1 -0
- package/dist/agents/roles/tester.d.ts +19 -0
- package/dist/agents/roles/tester.d.ts.map +1 -0
- package/dist/agents/roles/tester.js +29 -0
- package/dist/agents/roles/tester.js.map +1 -0
- package/dist/agents/types.d.ts +13 -0
- package/dist/agents/types.d.ts.map +1 -0
- package/dist/agents/types.js +25 -0
- package/dist/agents/types.js.map +1 -0
- package/dist/cli/commands/config.d.ts +9 -0
- package/dist/cli/commands/config.d.ts.map +1 -0
- package/dist/cli/commands/config.js +30 -0
- package/dist/cli/commands/config.js.map +1 -0
- package/dist/cli/commands/doctor.d.ts +12 -0
- package/dist/cli/commands/doctor.d.ts.map +1 -0
- package/dist/cli/commands/doctor.js +63 -0
- package/dist/cli/commands/doctor.js.map +1 -0
- package/dist/cli/commands/init.d.ts +12 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +231 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/run.d.ts +11 -0
- package/dist/cli/commands/run.d.ts.map +1 -0
- package/dist/cli/commands/run.js +66 -0
- package/dist/cli/commands/run.js.map +1 -0
- package/dist/cli/index.d.ts +9 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +24 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/core/config/defaults.d.ts +22 -0
- package/dist/core/config/defaults.d.ts.map +1 -0
- package/dist/core/config/defaults.js +60 -0
- package/dist/core/config/defaults.js.map +1 -0
- package/dist/core/config/manager.d.ts +45 -0
- package/dist/core/config/manager.d.ts.map +1 -0
- package/dist/core/config/manager.js +106 -0
- package/dist/core/config/manager.js.map +1 -0
- package/dist/core/config/schema.d.ts +780 -0
- package/dist/core/config/schema.d.ts.map +1 -0
- package/dist/core/config/schema.js +102 -0
- package/dist/core/config/schema.js.map +1 -0
- package/dist/core/config/types.d.ts +24 -0
- package/dist/core/config/types.d.ts.map +1 -0
- package/dist/core/config/types.js +11 -0
- package/dist/core/config/types.js.map +1 -0
- package/dist/core/errors.d.ts +36 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +60 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/workflow/approval.d.ts +22 -0
- package/dist/core/workflow/approval.d.ts.map +1 -0
- package/dist/core/workflow/approval.js +54 -0
- package/dist/core/workflow/approval.js.map +1 -0
- package/dist/core/workflow/engine.d.ts +128 -0
- package/dist/core/workflow/engine.d.ts.map +1 -0
- package/dist/core/workflow/engine.js +159 -0
- package/dist/core/workflow/engine.js.map +1 -0
- package/dist/core/workflow/file-parser.d.ts +41 -0
- package/dist/core/workflow/file-parser.d.ts.map +1 -0
- package/dist/core/workflow/file-parser.js +138 -0
- package/dist/core/workflow/file-parser.js.map +1 -0
- package/dist/core/workflow/qa-policy.d.ts +55 -0
- package/dist/core/workflow/qa-policy.d.ts.map +1 -0
- package/dist/core/workflow/qa-policy.js +119 -0
- package/dist/core/workflow/qa-policy.js.map +1 -0
- package/dist/core/workflow/runner.d.ts +30 -0
- package/dist/core/workflow/runner.d.ts.map +1 -0
- package/dist/core/workflow/runner.js +273 -0
- package/dist/core/workflow/runner.js.map +1 -0
- package/dist/core/workflow/session.d.ts +37 -0
- package/dist/core/workflow/session.d.ts.map +1 -0
- package/dist/core/workflow/session.js +93 -0
- package/dist/core/workflow/session.js.map +1 -0
- package/dist/core/workflow/task-queue.d.ts +46 -0
- package/dist/core/workflow/task-queue.d.ts.map +1 -0
- package/dist/core/workflow/task-queue.js +106 -0
- package/dist/core/workflow/task-queue.js.map +1 -0
- package/dist/core/workflow/test-runner.d.ts +25 -0
- package/dist/core/workflow/test-runner.d.ts.map +1 -0
- package/dist/core/workflow/test-runner.js +50 -0
- package/dist/core/workflow/test-runner.js.map +1 -0
- package/dist/core/workflow/token-tracker.d.ts +54 -0
- package/dist/core/workflow/token-tracker.d.ts.map +1 -0
- package/dist/core/workflow/token-tracker.js +98 -0
- package/dist/core/workflow/token-tracker.js.map +1 -0
- package/dist/git/client.d.ts +47 -0
- package/dist/git/client.d.ts.map +1 -0
- package/dist/git/client.js +109 -0
- package/dist/git/client.js.map +1 -0
- package/dist/prompts/library.d.ts +35 -0
- package/dist/prompts/library.d.ts.map +1 -0
- package/dist/prompts/library.js +238 -0
- package/dist/prompts/library.js.map +1 -0
- package/dist/providers/anthropic.d.ts +55 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +237 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/ollama.d.ts +44 -0
- package/dist/providers/ollama.d.ts.map +1 -0
- package/dist/providers/ollama.js +211 -0
- package/dist/providers/ollama.js.map +1 -0
- package/dist/providers/registry.d.ts +36 -0
- package/dist/providers/registry.d.ts.map +1 -0
- package/dist/providers/registry.js +91 -0
- package/dist/providers/registry.js.map +1 -0
- package/dist/providers/types.d.ts +100 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +12 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +9 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/fs.d.ts +30 -0
- package/dist/utils/fs.d.ts.map +1 -0
- package/dist/utils/fs.js +80 -0
- package/dist/utils/fs.js.map +1 -0
- package/dist/utils/logger.d.ts +46 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +87 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/validation.d.ts +28 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +38 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test runner — executes project tests and captures results.
|
|
3
|
+
*
|
|
4
|
+
* Runs the configured test command (e.g., `pnpm test`) and returns
|
|
5
|
+
* whether tests passed and the output.
|
|
6
|
+
*
|
|
7
|
+
* Dependency direction: test-runner.ts → execa, core/errors, utils
|
|
8
|
+
* Used by: workflow runner
|
|
9
|
+
*/
|
|
10
|
+
import { execa } from 'execa';
|
|
11
|
+
import { logger } from '../../utils/logger.js';
|
|
12
|
+
/**
|
|
13
|
+
* Run the project's test suite.
|
|
14
|
+
*
|
|
15
|
+
* @param projectRoot - Root directory of the project
|
|
16
|
+
* @param testCommand - The test command to run (default: 'pnpm test')
|
|
17
|
+
*/
|
|
18
|
+
export async function runTests(projectRoot, testCommand = 'pnpm test') {
|
|
19
|
+
const parts = testCommand.split(' ');
|
|
20
|
+
const cmd = parts[0] ?? 'pnpm';
|
|
21
|
+
const args = parts.slice(1);
|
|
22
|
+
logger.info(`Running tests: ${testCommand}`);
|
|
23
|
+
try {
|
|
24
|
+
const result = await execa(cmd, args, {
|
|
25
|
+
cwd: projectRoot,
|
|
26
|
+
reject: false, // Don't throw on non-zero exit
|
|
27
|
+
timeout: 120_000, // 2 minute timeout
|
|
28
|
+
env: { ...process.env, FORCE_COLOR: '0' }, // Disable color for cleaner output
|
|
29
|
+
});
|
|
30
|
+
const output = [result.stdout, result.stderr].filter(Boolean).join('\n');
|
|
31
|
+
const passed = result.exitCode === 0;
|
|
32
|
+
if (passed) {
|
|
33
|
+
logger.success('Tests passed');
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
logger.warn(`Tests failed (exit code: ${result.exitCode})`);
|
|
37
|
+
}
|
|
38
|
+
return { passed, output, exitCode: result.exitCode ?? 1 };
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
42
|
+
logger.error(`Failed to run tests: ${message}`);
|
|
43
|
+
return {
|
|
44
|
+
passed: false,
|
|
45
|
+
output: message,
|
|
46
|
+
exitCode: 1,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=test-runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-runner.js","sourceRoot":"","sources":["../../../src/core/workflow/test-runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAW/C;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC1B,WAAmB,EACnB,cAAsB,WAAW;IAEjC,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAA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;YACH,MAAM,EAAE,KAAK;YACb,MAAM,EAAE,OAAO;YACf,QAAQ,EAAE,CAAC;SACd,CAAC;IACN,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token tracker — accumulates token usage across agent calls.
|
|
3
|
+
*
|
|
4
|
+
* Tracks per-agent and total token consumption for cost estimation
|
|
5
|
+
* and usage visibility.
|
|
6
|
+
*
|
|
7
|
+
* Dependency direction: token-tracker.ts → utils
|
|
8
|
+
* Used by: workflow runner
|
|
9
|
+
*/
|
|
10
|
+
import type { AgentRole } from '../../agents/types.js';
|
|
11
|
+
/** Token usage for a single agent call. */
|
|
12
|
+
export interface TokenUsageEntry {
|
|
13
|
+
role: AgentRole;
|
|
14
|
+
model: string;
|
|
15
|
+
promptTokens: number;
|
|
16
|
+
completionTokens: number;
|
|
17
|
+
totalTokens: number;
|
|
18
|
+
timestamp: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Token usage tracker for a workflow run.
|
|
22
|
+
*/
|
|
23
|
+
export declare class TokenTracker {
|
|
24
|
+
private readonly entries;
|
|
25
|
+
/**
|
|
26
|
+
* Record a token usage entry.
|
|
27
|
+
*/
|
|
28
|
+
record(role: AgentRole, model: string, usage: {
|
|
29
|
+
promptTokens: number;
|
|
30
|
+
completionTokens: number;
|
|
31
|
+
totalTokens: number;
|
|
32
|
+
}): void;
|
|
33
|
+
/**
|
|
34
|
+
* Get total tokens used across all agents.
|
|
35
|
+
*/
|
|
36
|
+
getTotalTokens(): number;
|
|
37
|
+
/**
|
|
38
|
+
* Get tokens used per agent role.
|
|
39
|
+
*/
|
|
40
|
+
getTokensByRole(): Record<string, number>;
|
|
41
|
+
/**
|
|
42
|
+
* Estimate total cost in USD based on known model pricing.
|
|
43
|
+
*/
|
|
44
|
+
estimateCost(): number;
|
|
45
|
+
/**
|
|
46
|
+
* Get all recorded entries.
|
|
47
|
+
*/
|
|
48
|
+
getEntries(): readonly TokenUsageEntry[];
|
|
49
|
+
/**
|
|
50
|
+
* Print a summary of token usage to the console.
|
|
51
|
+
*/
|
|
52
|
+
printSummary(): void;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=token-tracker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-tracker.d.ts","sourceRoot":"","sources":["../../../src/core/workflow/token-tracker.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAIvD,2CAA2C;AAC3C,MAAM,WAAW,eAAe;IAC5B,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACrB;AAcD;;GAEG;AACH,qBAAa,YAAY;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyB;IAEjD;;OAEG;IACH,MAAM,CACF,IAAI,EAAE,SAAS,EACf,KAAK,EAAE,MAAM,EACb,KAAK,EAAE;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,gBAAgB,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,GAC/E,IAAI;IAWP;;OAEG;IACH,cAAc,IAAI,MAAM;IAIxB;;OAEG;IACH,eAAe,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAQzC;;OAEG;IACH,YAAY,IAAI,MAAM;IActB;;OAEG;IACH,UAAU,IAAI,SAAS,eAAe,EAAE;IAIxC;;OAEG;IACH,YAAY,IAAI,IAAI;CAmBvB"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token tracker — accumulates token usage across agent calls.
|
|
3
|
+
*
|
|
4
|
+
* Tracks per-agent and total token consumption for cost estimation
|
|
5
|
+
* and usage visibility.
|
|
6
|
+
*
|
|
7
|
+
* Dependency direction: token-tracker.ts → utils
|
|
8
|
+
* Used by: workflow runner
|
|
9
|
+
*/
|
|
10
|
+
import chalk from 'chalk';
|
|
11
|
+
import { AGENT_ROLE_LABELS } from '../../agents/types.js';
|
|
12
|
+
import { logger } from '../../utils/logger.js';
|
|
13
|
+
/** Estimated cost per 1M tokens for known models. */
|
|
14
|
+
const COST_PER_1M_TOKENS = {
|
|
15
|
+
// Anthropic
|
|
16
|
+
'claude-sonnet-4-20250514': { input: 3.00, output: 15.00 },
|
|
17
|
+
'claude-3-5-haiku-20241022': { input: 1.00, output: 5.00 },
|
|
18
|
+
'claude-3-opus-20240229': { input: 15.00, output: 75.00 },
|
|
19
|
+
// Ollama (local — free)
|
|
20
|
+
'llama3.2:latest': { input: 0, output: 0 },
|
|
21
|
+
'codellama:latest': { input: 0, output: 0 },
|
|
22
|
+
'deepseek-coder:latest': { input: 0, output: 0 },
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Token usage tracker for a workflow run.
|
|
26
|
+
*/
|
|
27
|
+
export class TokenTracker {
|
|
28
|
+
entries = [];
|
|
29
|
+
/**
|
|
30
|
+
* Record a token usage entry.
|
|
31
|
+
*/
|
|
32
|
+
record(role, model, usage) {
|
|
33
|
+
this.entries.push({
|
|
34
|
+
role,
|
|
35
|
+
model,
|
|
36
|
+
promptTokens: usage.promptTokens,
|
|
37
|
+
completionTokens: usage.completionTokens,
|
|
38
|
+
totalTokens: usage.totalTokens,
|
|
39
|
+
timestamp: Date.now(),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get total tokens used across all agents.
|
|
44
|
+
*/
|
|
45
|
+
getTotalTokens() {
|
|
46
|
+
return this.entries.reduce((sum, e) => sum + e.totalTokens, 0);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Get tokens used per agent role.
|
|
50
|
+
*/
|
|
51
|
+
getTokensByRole() {
|
|
52
|
+
const byRole = {};
|
|
53
|
+
for (const entry of this.entries) {
|
|
54
|
+
byRole[entry.role] = (byRole[entry.role] ?? 0) + entry.totalTokens;
|
|
55
|
+
}
|
|
56
|
+
return byRole;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Estimate total cost in USD based on known model pricing.
|
|
60
|
+
*/
|
|
61
|
+
estimateCost() {
|
|
62
|
+
let totalCost = 0;
|
|
63
|
+
for (const entry of this.entries) {
|
|
64
|
+
const pricing = COST_PER_1M_TOKENS[entry.model];
|
|
65
|
+
if (pricing) {
|
|
66
|
+
totalCost += (entry.promptTokens / 1_000_000) * pricing.input;
|
|
67
|
+
totalCost += (entry.completionTokens / 1_000_000) * pricing.output;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return totalCost;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get all recorded entries.
|
|
74
|
+
*/
|
|
75
|
+
getEntries() {
|
|
76
|
+
return this.entries;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Print a summary of token usage to the console.
|
|
80
|
+
*/
|
|
81
|
+
printSummary() {
|
|
82
|
+
if (this.entries.length === 0)
|
|
83
|
+
return;
|
|
84
|
+
console.log();
|
|
85
|
+
logger.header('Token Usage');
|
|
86
|
+
const byRole = this.getTokensByRole();
|
|
87
|
+
for (const [role, tokens] of Object.entries(byRole)) {
|
|
88
|
+
const label = AGENT_ROLE_LABELS[role] ?? role;
|
|
89
|
+
console.log(chalk.gray(` ${label}: ${tokens.toLocaleString()} tokens`));
|
|
90
|
+
}
|
|
91
|
+
console.log(chalk.bold(` Total: ${this.getTotalTokens().toLocaleString()} tokens`));
|
|
92
|
+
const cost = this.estimateCost();
|
|
93
|
+
if (cost > 0) {
|
|
94
|
+
console.log(chalk.yellow(` Estimated cost: $${cost.toFixed(4)}`));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=token-tracker.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EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAClD,MAAM,KAAK,GAAG,iBAAiB,CAAC,IAAiB,CAAC,IAAI,IAAI,CAAC;YAC3D,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,KAAK,KAAK,MAAM,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC,CAAC;QAC7E,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC,cAAc,EAAE,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC,CAAC;QAErF,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QACjC,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;YACX,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,sBAAsB,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACvE,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Git client — wraps simple-git for branch, commit, and diff operations.
|
|
3
|
+
*
|
|
4
|
+
* Dependency direction: client.ts → simple-git, core/errors, utils
|
|
5
|
+
* Used by: workflow runner
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Git client for workflow operations.
|
|
9
|
+
*/
|
|
10
|
+
export declare class GitClient {
|
|
11
|
+
private readonly git;
|
|
12
|
+
private readonly projectRoot;
|
|
13
|
+
constructor(projectRoot: string);
|
|
14
|
+
/**
|
|
15
|
+
* Check if the project is a Git repository.
|
|
16
|
+
*/
|
|
17
|
+
isRepo(): Promise<boolean>;
|
|
18
|
+
/**
|
|
19
|
+
* Get the current branch name.
|
|
20
|
+
*/
|
|
21
|
+
getCurrentBranch(): Promise<string>;
|
|
22
|
+
/**
|
|
23
|
+
* Create and switch to a new branch for the workflow task.
|
|
24
|
+
*/
|
|
25
|
+
createBranch(branchName: string): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Stage all changes and commit.
|
|
28
|
+
*/
|
|
29
|
+
commitAll(message: string): Promise<string>;
|
|
30
|
+
/**
|
|
31
|
+
* Get a summary of changed files.
|
|
32
|
+
*/
|
|
33
|
+
getStatus(): Promise<{
|
|
34
|
+
staged: string[];
|
|
35
|
+
modified: string[];
|
|
36
|
+
untracked: string[];
|
|
37
|
+
}>;
|
|
38
|
+
/**
|
|
39
|
+
* Get the diff of current changes.
|
|
40
|
+
*/
|
|
41
|
+
getDiff(): Promise<string>;
|
|
42
|
+
/**
|
|
43
|
+
* Generate a safe branch name from a task description.
|
|
44
|
+
*/
|
|
45
|
+
static toBranchName(prefix: string, task: string): string;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/git/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH;;GAEG;AACH,qBAAa,SAAS;IAClB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAY;IAChC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;gBAEzB,WAAW,EAAE,MAAM;IAK/B;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC;IAQhC;;OAEG;IACG,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC;IAYzC;;OAEG;IACG,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYrD;;OAEG;IACG,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAejD;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,EAAE,CAAC;QAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;QAAC,SAAS,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;IAgBzF;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAWhC;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM;CAQ5D"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Git client — wraps simple-git for branch, commit, and diff operations.
|
|
3
|
+
*
|
|
4
|
+
* Dependency direction: client.ts → simple-git, core/errors, utils
|
|
5
|
+
* Used by: workflow runner
|
|
6
|
+
*/
|
|
7
|
+
import { simpleGit } from 'simple-git';
|
|
8
|
+
import { GitError } from '../core/errors.js';
|
|
9
|
+
import { logger } from '../utils/logger.js';
|
|
10
|
+
/**
|
|
11
|
+
* Git client for workflow operations.
|
|
12
|
+
*/
|
|
13
|
+
export class GitClient {
|
|
14
|
+
git;
|
|
15
|
+
projectRoot;
|
|
16
|
+
constructor(projectRoot) {
|
|
17
|
+
this.projectRoot = projectRoot;
|
|
18
|
+
this.git = simpleGit(projectRoot);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Check if the project is a Git repository.
|
|
22
|
+
*/
|
|
23
|
+
async isRepo() {
|
|
24
|
+
try {
|
|
25
|
+
return await this.git.checkIsRepo();
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get the current branch name.
|
|
33
|
+
*/
|
|
34
|
+
async getCurrentBranch() {
|
|
35
|
+
try {
|
|
36
|
+
const status = await this.git.status();
|
|
37
|
+
return status.current ?? 'main';
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
throw new GitError(`Failed to get current branch: ${err instanceof Error ? err.message : String(err)}`, { projectRoot: this.projectRoot });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Create and switch to a new branch for the workflow task.
|
|
45
|
+
*/
|
|
46
|
+
async createBranch(branchName) {
|
|
47
|
+
try {
|
|
48
|
+
await this.git.checkoutLocalBranch(branchName);
|
|
49
|
+
logger.info(`Created and switched to branch: ${branchName}`);
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
throw new GitError(`Failed to create branch "${branchName}": ${err instanceof Error ? err.message : String(err)}`, { branch: branchName });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Stage all changes and commit.
|
|
57
|
+
*/
|
|
58
|
+
async commitAll(message) {
|
|
59
|
+
try {
|
|
60
|
+
await this.git.add('.');
|
|
61
|
+
const result = await this.git.commit(message);
|
|
62
|
+
const hash = result.commit || 'unknown';
|
|
63
|
+
logger.info(`Committed: ${hash} — ${message}`);
|
|
64
|
+
return hash;
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
throw new GitError(`Failed to commit: ${err instanceof Error ? err.message : String(err)}`, { message });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get a summary of changed files.
|
|
72
|
+
*/
|
|
73
|
+
async getStatus() {
|
|
74
|
+
try {
|
|
75
|
+
const status = await this.git.status();
|
|
76
|
+
return {
|
|
77
|
+
staged: status.staged,
|
|
78
|
+
modified: status.modified,
|
|
79
|
+
untracked: status.not_added,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
throw new GitError(`Failed to get git status: ${err instanceof Error ? err.message : String(err)}`, { projectRoot: this.projectRoot });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Get the diff of current changes.
|
|
88
|
+
*/
|
|
89
|
+
async getDiff() {
|
|
90
|
+
try {
|
|
91
|
+
return await this.git.diff();
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
throw new GitError(`Failed to get diff: ${err instanceof Error ? err.message : String(err)}`, { projectRoot: this.projectRoot });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Generate a safe branch name from a task description.
|
|
99
|
+
*/
|
|
100
|
+
static toBranchName(prefix, task) {
|
|
101
|
+
const slug = task
|
|
102
|
+
.toLowerCase()
|
|
103
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
104
|
+
.replace(/^-+|-+$/g, '')
|
|
105
|
+
.slice(0, 50);
|
|
106
|
+
return `${prefix}${slug}`;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/git/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAkB,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C;;GAEG;AACH,MAAM,OAAO,SAAS;IACD,GAAG,CAAY;IACf,WAAW,CAAS;IAErC,YAAY,WAAmB;QAC3B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,GAAG,GAAG,SAAS,CAAC,WAAW,CAAC,CAAC;IACtC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM;QACR,IAAI,CAAC;YACD,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;QACxC,CAAC;QAAC,MAAM,CAAC;YACL,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,gBAAgB;QAClB,IAAI,CAAC;YACD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;YACvC,OAAO,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC;QACpC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,MAAM,IAAI,QAAQ,CACd,iC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;CACJ"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt library — manages agent prompt templates.
|
|
3
|
+
*
|
|
4
|
+
* When `aiagentflow init` runs, default prompt files are generated in
|
|
5
|
+
* `.aiagentflow/prompts/`. Users can edit these to customize agent behavior.
|
|
6
|
+
* Agents read their prompts from these files at runtime.
|
|
7
|
+
*
|
|
8
|
+
* Dependency direction: prompts.ts → utils/fs, core/errors, agents/types
|
|
9
|
+
* Used by: agent implementations, init command
|
|
10
|
+
*/
|
|
11
|
+
import type { AgentRole } from '../agents/types.js';
|
|
12
|
+
/**
|
|
13
|
+
* Get the prompts directory path.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getPromptsDir(projectRoot: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Get the policies directory path.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getPoliciesDir(projectRoot: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Generate default prompt and policy files in the project's .aiagentflow/ directory.
|
|
22
|
+
* Only creates files that don't already exist (preserves user edits).
|
|
23
|
+
*/
|
|
24
|
+
export declare function generateDefaultPrompts(projectRoot: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* Load an agent's prompt from the project's prompt files.
|
|
27
|
+
* Falls back to the built-in default if the file doesn't exist.
|
|
28
|
+
*/
|
|
29
|
+
export declare function loadAgentPrompt(projectRoot: string, role: AgentRole): string;
|
|
30
|
+
/**
|
|
31
|
+
* Load the coding standards policy.
|
|
32
|
+
* Returns empty string if no policy file exists.
|
|
33
|
+
*/
|
|
34
|
+
export declare function loadCodingStandards(projectRoot: string): string;
|
|
35
|
+
//# sourceMappingURL=library.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"library.d.ts","sourceRoot":"","sources":["../../src/prompts/library.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAOH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AA6KpD;;GAEG;AACH,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAyBhE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,MAAM,CAS5E;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAQ/D"}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt library — manages agent prompt templates.
|
|
3
|
+
*
|
|
4
|
+
* When `aiagentflow init` runs, default prompt files are generated in
|
|
5
|
+
* `.aiagentflow/prompts/`. Users can edit these to customize agent behavior.
|
|
6
|
+
* Agents read their prompts from these files at runtime.
|
|
7
|
+
*
|
|
8
|
+
* Dependency direction: prompts.ts → utils/fs, core/errors, agents/types
|
|
9
|
+
* Used by: agent implementations, init command
|
|
10
|
+
*/
|
|
11
|
+
import { join } from 'node:path';
|
|
12
|
+
import { existsSync } from 'node:fs';
|
|
13
|
+
import { CONFIG_DIR_NAME } from '../core/config/defaults.js';
|
|
14
|
+
import { ensureDir, readTextFile } from '../utils/fs.js';
|
|
15
|
+
import { writeFileSync } from 'node:fs';
|
|
16
|
+
import { ALL_AGENT_ROLES } from '../agents/types.js';
|
|
17
|
+
import { logger } from '../utils/logger.js';
|
|
18
|
+
const PROMPTS_DIR = 'prompts';
|
|
19
|
+
const POLICIES_DIR = 'policies';
|
|
20
|
+
// ── Default Prompts ──
|
|
21
|
+
const DEFAULT_PROMPTS = {
|
|
22
|
+
architect: `# Architect Agent
|
|
23
|
+
|
|
24
|
+
You are a senior software architect. Your job is to analyze a task and create a clear implementation plan.
|
|
25
|
+
|
|
26
|
+
## What you do:
|
|
27
|
+
- Break the task into specific, actionable steps
|
|
28
|
+
- Identify which files need to be created or modified
|
|
29
|
+
- Define the data flow and component interactions
|
|
30
|
+
- Flag any risks or edge cases
|
|
31
|
+
|
|
32
|
+
## Output format:
|
|
33
|
+
1. **Summary** — one paragraph describing the approach
|
|
34
|
+
2. **Files to modify/create** — list each file with what changes are needed
|
|
35
|
+
3. **Step-by-step plan** — numbered implementation steps
|
|
36
|
+
4. **Edge cases** — anything that could go wrong
|
|
37
|
+
|
|
38
|
+
Be specific. No vague instructions. Every step should be directly actionable by a developer.
|
|
39
|
+
`,
|
|
40
|
+
coder: `# Coder Agent
|
|
41
|
+
|
|
42
|
+
You are a senior software developer. You implement features based on a plan provided by the architect.
|
|
43
|
+
|
|
44
|
+
## Rules:
|
|
45
|
+
- Write clean, typed, production-ready code
|
|
46
|
+
- Include error handling for all edge cases
|
|
47
|
+
- Add JSDoc comments for public functions
|
|
48
|
+
- Follow the project's coding conventions
|
|
49
|
+
- Only modify files specified in the plan
|
|
50
|
+
- Never introduce new dependencies without justification
|
|
51
|
+
|
|
52
|
+
## CRITICAL — Output format:
|
|
53
|
+
You MUST use this EXACT format for EVERY file. Do NOT deviate.
|
|
54
|
+
|
|
55
|
+
FILE: src/example.ts
|
|
56
|
+
\`\`\`typescript
|
|
57
|
+
export function example(): string {
|
|
58
|
+
return "hello";
|
|
59
|
+
}
|
|
60
|
+
\`\`\`
|
|
61
|
+
|
|
62
|
+
FILE: src/utils.ts
|
|
63
|
+
\`\`\`typescript
|
|
64
|
+
export const VERSION = "1.0";
|
|
65
|
+
\`\`\`
|
|
66
|
+
|
|
67
|
+
The word FILE: followed by the file path MUST appear on its own line BEFORE each code block.
|
|
68
|
+
Write complete, working code. No placeholders, no TODOs, no "implement this later".
|
|
69
|
+
`,
|
|
70
|
+
reviewer: `# Reviewer Agent
|
|
71
|
+
|
|
72
|
+
You are a senior code reviewer. You review code changes for quality, correctness, and maintainability.
|
|
73
|
+
|
|
74
|
+
## What to check:
|
|
75
|
+
- Logic errors and bugs
|
|
76
|
+
- Missing error handling
|
|
77
|
+
- Type safety issues
|
|
78
|
+
- Security vulnerabilities
|
|
79
|
+
- Performance concerns
|
|
80
|
+
- Code style consistency
|
|
81
|
+
- Missing tests
|
|
82
|
+
|
|
83
|
+
## Output format:
|
|
84
|
+
1. **Verdict**: APPROVE or REQUEST_CHANGES
|
|
85
|
+
2. **Issues** (if any): numbered list with severity (critical/warning/nit)
|
|
86
|
+
3. **Suggestions**: improvements that aren't blocking
|
|
87
|
+
|
|
88
|
+
Be constructive. Explain WHY something is a problem, not just WHAT.
|
|
89
|
+
`,
|
|
90
|
+
tester: `# Tester Agent
|
|
91
|
+
|
|
92
|
+
You are a QA engineer who writes comprehensive tests.
|
|
93
|
+
|
|
94
|
+
## Rules:
|
|
95
|
+
- Write tests that verify behavior, not implementation
|
|
96
|
+
- Cover happy path, edge cases, and error cases
|
|
97
|
+
- Use descriptive test names that read like documentation
|
|
98
|
+
- Mock external dependencies (APIs, file system) where needed
|
|
99
|
+
- Aim for meaningful coverage, not 100% line coverage
|
|
100
|
+
|
|
101
|
+
## Output format:
|
|
102
|
+
For each test file, use this EXACT format:
|
|
103
|
+
|
|
104
|
+
FILE: tests/example.test.ts
|
|
105
|
+
\`\`\`typescript
|
|
106
|
+
import { describe, it, expect } from 'vitest';
|
|
107
|
+
// test code here
|
|
108
|
+
\`\`\`
|
|
109
|
+
|
|
110
|
+
The word FILE: followed by the file path MUST appear on its own line BEFORE each code block.
|
|
111
|
+
`,
|
|
112
|
+
fixer: `# Fixer Agent
|
|
113
|
+
|
|
114
|
+
You are a debugging expert. You fix code issues identified by reviewers and test failures.
|
|
115
|
+
|
|
116
|
+
## Rules:
|
|
117
|
+
- Fix only the reported issues — don't refactor unrelated code
|
|
118
|
+
- Explain what caused the bug and how your fix resolves it
|
|
119
|
+
- Make the minimal change needed to fix the issue
|
|
120
|
+
- Ensure the fix doesn't introduce new problems
|
|
121
|
+
- Update tests if the fix changes expected behavior
|
|
122
|
+
|
|
123
|
+
## Output format:
|
|
124
|
+
1. **Root cause** — what went wrong and why
|
|
125
|
+
2. **Fix** — output each fixed file using this EXACT format:
|
|
126
|
+
|
|
127
|
+
FILE: src/example.ts
|
|
128
|
+
\`\`\`typescript
|
|
129
|
+
// fixed code here
|
|
130
|
+
\`\`\`
|
|
131
|
+
|
|
132
|
+
3. **Verification** — how to confirm the fix works
|
|
133
|
+
`,
|
|
134
|
+
judge: `# Judge Agent
|
|
135
|
+
|
|
136
|
+
You are a QA lead who decides if a task is complete and meets quality standards.
|
|
137
|
+
|
|
138
|
+
## What to evaluate:
|
|
139
|
+
- Does the code fulfill the original task requirements?
|
|
140
|
+
- Did the reviewer approve the code?
|
|
141
|
+
- Do all tests pass?
|
|
142
|
+
- Are there any unresolved issues?
|
|
143
|
+
- Is the code production-ready?
|
|
144
|
+
|
|
145
|
+
## Output format:
|
|
146
|
+
1. **Verdict**: PASS or FAIL
|
|
147
|
+
2. **Rationale** — why you made this decision
|
|
148
|
+
3. **Remaining issues** (if FAIL) — what needs to be fixed before passing
|
|
149
|
+
`,
|
|
150
|
+
};
|
|
151
|
+
const DEFAULT_CODING_STANDARDS = `# Coding Standards
|
|
152
|
+
|
|
153
|
+
These rules are injected into every agent's context. Edit them to match your project.
|
|
154
|
+
|
|
155
|
+
## General
|
|
156
|
+
- Write clean, readable code
|
|
157
|
+
- Use meaningful variable and function names
|
|
158
|
+
- Keep functions small and focused (single responsibility)
|
|
159
|
+
- Handle errors explicitly — never swallow exceptions
|
|
160
|
+
|
|
161
|
+
## TypeScript
|
|
162
|
+
- Enable strict mode
|
|
163
|
+
- Use explicit types for function parameters and return values
|
|
164
|
+
- Prefer interfaces over type aliases for object shapes
|
|
165
|
+
- Use enums for fixed sets of values
|
|
166
|
+
|
|
167
|
+
## Testing
|
|
168
|
+
- Every public function should have tests
|
|
169
|
+
- Test behavior, not implementation
|
|
170
|
+
- Use descriptive test names
|
|
171
|
+
|
|
172
|
+
## Git
|
|
173
|
+
- Write clear commit messages
|
|
174
|
+
- Keep commits focused on a single change
|
|
175
|
+
`;
|
|
176
|
+
// ── Public API ──
|
|
177
|
+
/**
|
|
178
|
+
* Get the prompts directory path.
|
|
179
|
+
*/
|
|
180
|
+
export function getPromptsDir(projectRoot) {
|
|
181
|
+
return join(projectRoot, CONFIG_DIR_NAME, PROMPTS_DIR);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Get the policies directory path.
|
|
185
|
+
*/
|
|
186
|
+
export function getPoliciesDir(projectRoot) {
|
|
187
|
+
return join(projectRoot, CONFIG_DIR_NAME, POLICIES_DIR);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Generate default prompt and policy files in the project's .aiagentflow/ directory.
|
|
191
|
+
* Only creates files that don't already exist (preserves user edits).
|
|
192
|
+
*/
|
|
193
|
+
export function generateDefaultPrompts(projectRoot) {
|
|
194
|
+
const promptsDir = getPromptsDir(projectRoot);
|
|
195
|
+
const policiesDir = getPoliciesDir(projectRoot);
|
|
196
|
+
ensureDir(promptsDir);
|
|
197
|
+
ensureDir(policiesDir);
|
|
198
|
+
// Generate agent prompt files
|
|
199
|
+
for (const role of ALL_AGENT_ROLES) {
|
|
200
|
+
const filePath = join(promptsDir, `${role}.md`);
|
|
201
|
+
if (!existsSync(filePath)) {
|
|
202
|
+
writeFileSync(filePath, DEFAULT_PROMPTS[role], 'utf-8');
|
|
203
|
+
logger.debug(`Created prompt: ${filePath}`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// Generate coding standards
|
|
207
|
+
const standardsPath = join(policiesDir, 'coding-standards.md');
|
|
208
|
+
if (!existsSync(standardsPath)) {
|
|
209
|
+
writeFileSync(standardsPath, DEFAULT_CODING_STANDARDS, 'utf-8');
|
|
210
|
+
logger.debug(`Created policy: ${standardsPath}`);
|
|
211
|
+
}
|
|
212
|
+
logger.success('Prompt templates generated in .aiagentflow/prompts/');
|
|
213
|
+
logger.info('Edit these files to customize agent behavior.');
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Load an agent's prompt from the project's prompt files.
|
|
217
|
+
* Falls back to the built-in default if the file doesn't exist.
|
|
218
|
+
*/
|
|
219
|
+
export function loadAgentPrompt(projectRoot, role) {
|
|
220
|
+
const filePath = join(getPromptsDir(projectRoot), `${role}.md`);
|
|
221
|
+
if (existsSync(filePath)) {
|
|
222
|
+
return readTextFile(filePath);
|
|
223
|
+
}
|
|
224
|
+
// Fall back to built-in default
|
|
225
|
+
return DEFAULT_PROMPTS[role];
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Load the coding standards policy.
|
|
229
|
+
* Returns empty string if no policy file exists.
|
|
230
|
+
*/
|
|
231
|
+
export function loadCodingStandards(projectRoot) {
|
|
232
|
+
const filePath = join(getPoliciesDir(projectRoot), 'coding-standards.md');
|
|
233
|
+
if (existsSync(filePath)) {
|
|
234
|
+
return readTextFile(filePath);
|
|
235
|
+
}
|
|
236
|
+
return '';
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=library.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"library.js","sourceRoot":"","sources":["../../src/prompts/library.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,YAAY,EAAiB,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,MAAM,WAAW,GAAG,SAAS,CAAC;AAC9B,MAAM,YAAY,GAAG,UAAU,CAAC;AAE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