@yuaone/core 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 +663 -0
- package/README.md +15 -0
- package/dist/__tests__/context-manager.test.d.ts +6 -0
- package/dist/__tests__/context-manager.test.d.ts.map +1 -0
- package/dist/__tests__/context-manager.test.js +220 -0
- package/dist/__tests__/context-manager.test.js.map +1 -0
- package/dist/__tests__/governor.test.d.ts +6 -0
- package/dist/__tests__/governor.test.d.ts.map +1 -0
- package/dist/__tests__/governor.test.js +210 -0
- package/dist/__tests__/governor.test.js.map +1 -0
- package/dist/__tests__/model-router.test.d.ts +6 -0
- package/dist/__tests__/model-router.test.d.ts.map +1 -0
- package/dist/__tests__/model-router.test.js +329 -0
- package/dist/__tests__/model-router.test.js.map +1 -0
- package/dist/agent-logger.d.ts +384 -0
- package/dist/agent-logger.d.ts.map +1 -0
- package/dist/agent-logger.js +820 -0
- package/dist/agent-logger.js.map +1 -0
- package/dist/agent-loop.d.ts +163 -0
- package/dist/agent-loop.d.ts.map +1 -0
- package/dist/agent-loop.js +609 -0
- package/dist/agent-loop.js.map +1 -0
- package/dist/agent-modes.d.ts +85 -0
- package/dist/agent-modes.d.ts.map +1 -0
- package/dist/agent-modes.js +418 -0
- package/dist/agent-modes.js.map +1 -0
- package/dist/approval.d.ts +137 -0
- package/dist/approval.d.ts.map +1 -0
- package/dist/approval.js +299 -0
- package/dist/approval.js.map +1 -0
- package/dist/async-completion-queue.d.ts +56 -0
- package/dist/async-completion-queue.d.ts.map +1 -0
- package/dist/async-completion-queue.js +77 -0
- package/dist/async-completion-queue.js.map +1 -0
- package/dist/auto-fix.d.ts +174 -0
- package/dist/auto-fix.d.ts.map +1 -0
- package/dist/auto-fix.js +319 -0
- package/dist/auto-fix.js.map +1 -0
- package/dist/codebase-context.d.ts +396 -0
- package/dist/codebase-context.d.ts.map +1 -0
- package/dist/codebase-context.js +1260 -0
- package/dist/codebase-context.js.map +1 -0
- package/dist/conflict-resolver.d.ts +191 -0
- package/dist/conflict-resolver.d.ts.map +1 -0
- package/dist/conflict-resolver.js +524 -0
- package/dist/conflict-resolver.js.map +1 -0
- package/dist/constants.d.ts +52 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +141 -0
- package/dist/constants.js.map +1 -0
- package/dist/context-budget.d.ts +435 -0
- package/dist/context-budget.d.ts.map +1 -0
- package/dist/context-budget.js +903 -0
- package/dist/context-budget.js.map +1 -0
- package/dist/context-compressor.d.ts +143 -0
- package/dist/context-compressor.d.ts.map +1 -0
- package/dist/context-compressor.js +511 -0
- package/dist/context-compressor.js.map +1 -0
- package/dist/context-manager.d.ts +112 -0
- package/dist/context-manager.d.ts.map +1 -0
- package/dist/context-manager.js +247 -0
- package/dist/context-manager.js.map +1 -0
- package/dist/continuous-reflection.d.ts +267 -0
- package/dist/continuous-reflection.d.ts.map +1 -0
- package/dist/continuous-reflection.js +338 -0
- package/dist/continuous-reflection.js.map +1 -0
- package/dist/cross-file-refactor.d.ts +352 -0
- package/dist/cross-file-refactor.d.ts.map +1 -0
- package/dist/cross-file-refactor.js +1544 -0
- package/dist/cross-file-refactor.js.map +1 -0
- package/dist/dag-orchestrator.d.ts +138 -0
- package/dist/dag-orchestrator.d.ts.map +1 -0
- package/dist/dag-orchestrator.js +379 -0
- package/dist/dag-orchestrator.js.map +1 -0
- package/dist/debate-orchestrator.d.ts +301 -0
- package/dist/debate-orchestrator.d.ts.map +1 -0
- package/dist/debate-orchestrator.js +719 -0
- package/dist/debate-orchestrator.js.map +1 -0
- package/dist/dependency-analyzer.d.ts +113 -0
- package/dist/dependency-analyzer.d.ts.map +1 -0
- package/dist/dependency-analyzer.js +444 -0
- package/dist/dependency-analyzer.js.map +1 -0
- package/dist/design-loop.d.ts +59 -0
- package/dist/design-loop.d.ts.map +1 -0
- package/dist/design-loop.js +344 -0
- package/dist/design-loop.js.map +1 -0
- package/dist/doc-intelligence.d.ts +383 -0
- package/dist/doc-intelligence.d.ts.map +1 -0
- package/dist/doc-intelligence.js +1307 -0
- package/dist/doc-intelligence.js.map +1 -0
- package/dist/dynamic-role-generator.d.ts +76 -0
- package/dist/dynamic-role-generator.d.ts.map +1 -0
- package/dist/dynamic-role-generator.js +194 -0
- package/dist/dynamic-role-generator.js.map +1 -0
- package/dist/errors.d.ts +69 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +102 -0
- package/dist/errors.js.map +1 -0
- package/dist/event-bus.d.ts +159 -0
- package/dist/event-bus.d.ts.map +1 -0
- package/dist/event-bus.js +305 -0
- package/dist/event-bus.js.map +1 -0
- package/dist/execution-engine.d.ts +425 -0
- package/dist/execution-engine.d.ts.map +1 -0
- package/dist/execution-engine.js +1555 -0
- package/dist/execution-engine.js.map +1 -0
- package/dist/git-intelligence.d.ts +306 -0
- package/dist/git-intelligence.d.ts.map +1 -0
- package/dist/git-intelligence.js +1099 -0
- package/dist/git-intelligence.js.map +1 -0
- package/dist/governor.d.ts +77 -0
- package/dist/governor.d.ts.map +1 -0
- package/dist/governor.js +161 -0
- package/dist/governor.js.map +1 -0
- package/dist/hierarchical-planner.d.ts +313 -0
- package/dist/hierarchical-planner.d.ts.map +1 -0
- package/dist/hierarchical-planner.js +981 -0
- package/dist/hierarchical-planner.js.map +1 -0
- package/dist/index.d.ts +121 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +123 -0
- package/dist/index.js.map +1 -0
- package/dist/intent-inference.d.ts +103 -0
- package/dist/intent-inference.d.ts.map +1 -0
- package/dist/intent-inference.js +605 -0
- package/dist/intent-inference.js.map +1 -0
- package/dist/interrupt-manager.d.ts +143 -0
- package/dist/interrupt-manager.d.ts.map +1 -0
- package/dist/interrupt-manager.js +196 -0
- package/dist/interrupt-manager.js.map +1 -0
- package/dist/kernel.d.ts +564 -0
- package/dist/kernel.d.ts.map +1 -0
- package/dist/kernel.js +1419 -0
- package/dist/kernel.js.map +1 -0
- package/dist/language-support.d.ts +232 -0
- package/dist/language-support.d.ts.map +1 -0
- package/dist/language-support.js +1134 -0
- package/dist/language-support.js.map +1 -0
- package/dist/llm-client.d.ts +82 -0
- package/dist/llm-client.d.ts.map +1 -0
- package/dist/llm-client.js +475 -0
- package/dist/llm-client.js.map +1 -0
- package/dist/mcp-client.d.ts +232 -0
- package/dist/mcp-client.d.ts.map +1 -0
- package/dist/mcp-client.js +718 -0
- package/dist/mcp-client.js.map +1 -0
- package/dist/memory-manager.d.ts +200 -0
- package/dist/memory-manager.d.ts.map +1 -0
- package/dist/memory-manager.js +568 -0
- package/dist/memory-manager.js.map +1 -0
- package/dist/memory.d.ts +87 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +341 -0
- package/dist/memory.js.map +1 -0
- package/dist/model-router.d.ts +245 -0
- package/dist/model-router.d.ts.map +1 -0
- package/dist/model-router.js +632 -0
- package/dist/model-router.js.map +1 -0
- package/dist/parallel-executor.d.ts +125 -0
- package/dist/parallel-executor.d.ts.map +1 -0
- package/dist/parallel-executor.js +201 -0
- package/dist/parallel-executor.js.map +1 -0
- package/dist/perf-optimizer.d.ts +212 -0
- package/dist/perf-optimizer.d.ts.map +1 -0
- package/dist/perf-optimizer.js +721 -0
- package/dist/perf-optimizer.js.map +1 -0
- package/dist/persona.d.ts +305 -0
- package/dist/persona.d.ts.map +1 -0
- package/dist/persona.js +887 -0
- package/dist/persona.js.map +1 -0
- package/dist/planner.d.ts +70 -0
- package/dist/planner.d.ts.map +1 -0
- package/dist/planner.js +264 -0
- package/dist/planner.js.map +1 -0
- package/dist/qa-pipeline.d.ts +365 -0
- package/dist/qa-pipeline.d.ts.map +1 -0
- package/dist/qa-pipeline.js +1352 -0
- package/dist/qa-pipeline.js.map +1 -0
- package/dist/reasoning-adapter.d.ts +116 -0
- package/dist/reasoning-adapter.d.ts.map +1 -0
- package/dist/reasoning-adapter.js +187 -0
- package/dist/reasoning-adapter.js.map +1 -0
- package/dist/role-registry.d.ts +55 -0
- package/dist/role-registry.d.ts.map +1 -0
- package/dist/role-registry.js +192 -0
- package/dist/role-registry.js.map +1 -0
- package/dist/sandbox-tiers.d.ts +327 -0
- package/dist/sandbox-tiers.d.ts.map +1 -0
- package/dist/sandbox-tiers.js +928 -0
- package/dist/sandbox-tiers.js.map +1 -0
- package/dist/security-scanner.d.ts +222 -0
- package/dist/security-scanner.d.ts.map +1 -0
- package/dist/security-scanner.js +1129 -0
- package/dist/security-scanner.js.map +1 -0
- package/dist/security.d.ts +93 -0
- package/dist/security.d.ts.map +1 -0
- package/dist/security.js +393 -0
- package/dist/security.js.map +1 -0
- package/dist/self-reflection.d.ts +397 -0
- package/dist/self-reflection.d.ts.map +1 -0
- package/dist/self-reflection.js +908 -0
- package/dist/self-reflection.js.map +1 -0
- package/dist/session-persistence.d.ts +191 -0
- package/dist/session-persistence.d.ts.map +1 -0
- package/dist/session-persistence.js +395 -0
- package/dist/session-persistence.js.map +1 -0
- package/dist/speculative-executor.d.ts +210 -0
- package/dist/speculative-executor.d.ts.map +1 -0
- package/dist/speculative-executor.js +618 -0
- package/dist/speculative-executor.js.map +1 -0
- package/dist/state-machine.d.ts +289 -0
- package/dist/state-machine.d.ts.map +1 -0
- package/dist/state-machine.js +695 -0
- package/dist/state-machine.js.map +1 -0
- package/dist/sub-agent.d.ts +177 -0
- package/dist/sub-agent.d.ts.map +1 -0
- package/dist/sub-agent.js +303 -0
- package/dist/sub-agent.js.map +1 -0
- package/dist/system-prompt.d.ts +26 -0
- package/dist/system-prompt.d.ts.map +1 -0
- package/dist/system-prompt.js +84 -0
- package/dist/system-prompt.js.map +1 -0
- package/dist/test-intelligence.d.ts +439 -0
- package/dist/test-intelligence.d.ts.map +1 -0
- package/dist/test-intelligence.js +1165 -0
- package/dist/test-intelligence.js.map +1 -0
- package/dist/types.d.ts +632 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/vector-index.d.ts +314 -0
- package/dist/vector-index.d.ts.map +1 -0
- package/dist/vector-index.js +618 -0
- package/dist/vector-index.js.map +1 -0
- package/package.json +41 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module agent-modes
|
|
3
|
+
* @description YUAN Agent 실행 모드 프리셋.
|
|
4
|
+
* 각 모드는 시스템 프롬프트 보충, 도구 제한, 반복 제한, 출력 형식을 정의한다.
|
|
5
|
+
*
|
|
6
|
+
* 사용법:
|
|
7
|
+
* ```typescript
|
|
8
|
+
* const mode = getAgentModeConfig("review");
|
|
9
|
+
* // mode.allowedTools → 사용 가능 도구
|
|
10
|
+
* // mode.systemPromptSuffix → 시스템 프롬프트에 추가
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
/** 에이전트 실행 모드 */
|
|
14
|
+
export type AgentMode = "code" | "report" | "review" | "security" | "debug" | "refactor" | "test" | "plan" | "architect";
|
|
15
|
+
/** 출력 형식 */
|
|
16
|
+
export type AgentOutputFormat = "streaming" | "report" | "checklist" | "diff";
|
|
17
|
+
/** 자동 승인 수준 */
|
|
18
|
+
export type AutoApproveLevel = "none" | "reads" | "safe_writes" | "all";
|
|
19
|
+
/** 에이전트 모드 설정 */
|
|
20
|
+
export interface AgentModeConfig {
|
|
21
|
+
/** 모드 식별자 */
|
|
22
|
+
mode: AgentMode;
|
|
23
|
+
/** 시스템 프롬프트에 추가될 모드별 지시 */
|
|
24
|
+
systemPromptSuffix: string;
|
|
25
|
+
/** 이 모드에서 허용되는 도구 이름 목록 (빈 배열 = 전체 허용) */
|
|
26
|
+
allowedTools: string[];
|
|
27
|
+
/** 이 모드에서 명시적으로 거부되는 도구 이름 목록 */
|
|
28
|
+
deniedTools?: string[];
|
|
29
|
+
/** 최대 반복 횟수 오버라이드 */
|
|
30
|
+
maxIterations: number;
|
|
31
|
+
/** 파일 쓰기 가능 여부 */
|
|
32
|
+
canWrite: boolean;
|
|
33
|
+
/** 명령어 실행 가능 여부 */
|
|
34
|
+
canExecute: boolean;
|
|
35
|
+
/** 출력 형식 */
|
|
36
|
+
outputFormat: AgentOutputFormat;
|
|
37
|
+
/** 자동 승인 수준 */
|
|
38
|
+
autoApprove: AutoApproveLevel;
|
|
39
|
+
/** CLI help에 표시할 설명 */
|
|
40
|
+
description: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 모드 이름으로 설정을 가져온다.
|
|
44
|
+
* @param mode 에이전트 모드 이름
|
|
45
|
+
* @returns 해당 모드의 전체 설정
|
|
46
|
+
*/
|
|
47
|
+
export declare function getAgentModeConfig(mode: AgentMode): AgentModeConfig;
|
|
48
|
+
/**
|
|
49
|
+
* 등록된 모든 모드 목록을 반환한다.
|
|
50
|
+
* @returns 모든 모드 설정 배열
|
|
51
|
+
*/
|
|
52
|
+
export declare function getAllAgentModes(): AgentModeConfig[];
|
|
53
|
+
/**
|
|
54
|
+
* 모드 이름이 유효한지 검증한다.
|
|
55
|
+
* @param mode 검증할 모드 이름
|
|
56
|
+
* @returns 유효한 AgentMode이면 true
|
|
57
|
+
*/
|
|
58
|
+
export declare function isValidAgentMode(mode: string): mode is AgentMode;
|
|
59
|
+
/**
|
|
60
|
+
* 주어진 모드에서 특정 도구의 사용이 허용되는지 확인한다.
|
|
61
|
+
* allowedTools가 빈 배열이면 모든 도구 허용 (deniedTools 제외).
|
|
62
|
+
*
|
|
63
|
+
* @param mode 에이전트 모드 이름
|
|
64
|
+
* @param toolName 확인할 도구 이름
|
|
65
|
+
* @returns 허용되면 true, 거부되면 false
|
|
66
|
+
*/
|
|
67
|
+
export declare function isToolAllowedInMode(mode: AgentMode, toolName: string): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* 테스트 모드에서 파일 경로가 테스트 파일인지 검증한다.
|
|
70
|
+
* test 모드는 테스트 파일만 쓰기 가능.
|
|
71
|
+
*
|
|
72
|
+
* @param filePath 검증할 파일 경로
|
|
73
|
+
* @returns 테스트 파일이면 true
|
|
74
|
+
*/
|
|
75
|
+
export declare function isTestFile(filePath: string): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* 모드별 시스템 프롬프트 서픽스를 기존 시스템 프롬프트에 결합한다.
|
|
78
|
+
* mode가 "code"이면 서픽스가 비어있으므로 원본을 그대로 반환.
|
|
79
|
+
*
|
|
80
|
+
* @param basePrompt 기본 시스템 프롬프트
|
|
81
|
+
* @param mode 에이전트 모드 이름
|
|
82
|
+
* @returns 결합된 시스템 프롬프트
|
|
83
|
+
*/
|
|
84
|
+
export declare function buildModeSystemPrompt(basePrompt: string, mode: AgentMode): string;
|
|
85
|
+
//# sourceMappingURL=agent-modes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-modes.d.ts","sourceRoot":"","sources":["../src/agent-modes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,iBAAiB;AACjB,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,QAAQ,GACR,QAAQ,GACR,UAAU,GACV,OAAO,GACP,UAAU,GACV,MAAM,GACN,MAAM,GACN,WAAW,CAAC;AAEhB,YAAY;AACZ,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,GAAG,MAAM,CAAC;AAE9E,eAAe;AACf,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,OAAO,GAAG,aAAa,GAAG,KAAK,CAAC;AAExE,iBAAiB;AACjB,MAAM,WAAW,eAAe;IAC9B,aAAa;IACb,IAAI,EAAE,SAAS,CAAC;IAChB,2BAA2B;IAC3B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,0CAA0C;IAC1C,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,iCAAiC;IACjC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,qBAAqB;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,kBAAkB;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,mBAAmB;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,YAAY;IACZ,YAAY,EAAE,iBAAiB,CAAC;IAChC,eAAe;IACf,WAAW,EAAE,gBAAgB,CAAC;IAC9B,uBAAuB;IACvB,WAAW,EAAE,MAAM,CAAC;CACrB;AAwVD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,SAAS,GAAG,eAAe,CAEnE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,eAAe,EAAE,CAEpD;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,SAAS,CAEhE;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAe9E;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAepD;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,MAAM,CAMjF"}
|
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module agent-modes
|
|
3
|
+
* @description YUAN Agent 실행 모드 프리셋.
|
|
4
|
+
* 각 모드는 시스템 프롬프트 보충, 도구 제한, 반복 제한, 출력 형식을 정의한다.
|
|
5
|
+
*
|
|
6
|
+
* 사용법:
|
|
7
|
+
* ```typescript
|
|
8
|
+
* const mode = getAgentModeConfig("review");
|
|
9
|
+
* // mode.allowedTools → 사용 가능 도구
|
|
10
|
+
* // mode.systemPromptSuffix → 시스템 프롬프트에 추가
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
// ─── Read-Only Tools ───
|
|
14
|
+
const READ_ONLY_TOOLS = [
|
|
15
|
+
"file_read",
|
|
16
|
+
"grep",
|
|
17
|
+
"glob",
|
|
18
|
+
"code_search",
|
|
19
|
+
];
|
|
20
|
+
const GIT_READ_TOOLS = [
|
|
21
|
+
"git_diff",
|
|
22
|
+
"git_log",
|
|
23
|
+
"git_status",
|
|
24
|
+
];
|
|
25
|
+
const ALL_TOOLS_MARKER = [];
|
|
26
|
+
// ─── Mode Configs ───
|
|
27
|
+
const CODE_MODE = {
|
|
28
|
+
mode: "code",
|
|
29
|
+
systemPromptSuffix: "",
|
|
30
|
+
allowedTools: ALL_TOOLS_MARKER,
|
|
31
|
+
maxIterations: 25,
|
|
32
|
+
canWrite: true,
|
|
33
|
+
canExecute: true,
|
|
34
|
+
outputFormat: "streaming",
|
|
35
|
+
autoApprove: "safe_writes",
|
|
36
|
+
description: "Default autonomous coding mode. Full tool access with safe-write auto-approval.",
|
|
37
|
+
};
|
|
38
|
+
const REPORT_MODE = {
|
|
39
|
+
mode: "report",
|
|
40
|
+
systemPromptSuffix: `You are a codebase analyst. Your job is to generate a comprehensive report about the project.
|
|
41
|
+
|
|
42
|
+
## Report Guidelines
|
|
43
|
+
- Start by understanding the project structure, entry points, and dependencies.
|
|
44
|
+
- Analyze code quality, architecture patterns, and potential issues.
|
|
45
|
+
- Generate a structured markdown report with sections:
|
|
46
|
+
1. **Project Overview** — language, framework, structure
|
|
47
|
+
2. **Architecture** — patterns, layers, data flow
|
|
48
|
+
3. **Code Quality** — style consistency, complexity, duplication
|
|
49
|
+
4. **Dependencies** — outdated, unused, security vulnerabilities
|
|
50
|
+
5. **Recommendations** — prioritized list of improvements
|
|
51
|
+
|
|
52
|
+
## Constraints
|
|
53
|
+
- You are in READ-ONLY mode. Do not attempt to modify any files.
|
|
54
|
+
- Read as many files as needed to build a thorough understanding.
|
|
55
|
+
- Cite specific files and line numbers in your findings.`,
|
|
56
|
+
allowedTools: [...READ_ONLY_TOOLS],
|
|
57
|
+
deniedTools: ["file_write", "file_edit", "shell_exec", "git_commit", "git_push"],
|
|
58
|
+
maxIterations: 50,
|
|
59
|
+
canWrite: false,
|
|
60
|
+
canExecute: false,
|
|
61
|
+
outputFormat: "report",
|
|
62
|
+
autoApprove: "reads",
|
|
63
|
+
description: "Analyze codebase and generate a structured markdown report. Read-only.",
|
|
64
|
+
};
|
|
65
|
+
const REVIEW_MODE = {
|
|
66
|
+
mode: "review",
|
|
67
|
+
systemPromptSuffix: `You are a senior code reviewer. Review the changes for bugs, style issues, security vulnerabilities, and best-practice violations.
|
|
68
|
+
|
|
69
|
+
## Review Process
|
|
70
|
+
1. Run \`git diff\` and \`git log\` to understand what changed.
|
|
71
|
+
2. Read the changed files in full context.
|
|
72
|
+
3. Check related files for potential breakage.
|
|
73
|
+
4. Generate a review checklist with severity levels.
|
|
74
|
+
|
|
75
|
+
## Output Format
|
|
76
|
+
For each issue found, output:
|
|
77
|
+
- **[CRITICAL]** — Bugs, security holes, data loss risks
|
|
78
|
+
- **[HIGH]** — Logic errors, missing error handling, race conditions
|
|
79
|
+
- **[MEDIUM]** — Style violations, code smells, missing tests
|
|
80
|
+
- **[LOW]** — Nitpicks, naming, documentation
|
|
81
|
+
|
|
82
|
+
## Constraints
|
|
83
|
+
- You are in READ-ONLY mode. Do not modify files.
|
|
84
|
+
- Focus on the diff, not the entire codebase.
|
|
85
|
+
- Be specific: cite file paths, line numbers, and concrete suggestions.`,
|
|
86
|
+
allowedTools: [...READ_ONLY_TOOLS, ...GIT_READ_TOOLS],
|
|
87
|
+
deniedTools: ["file_write", "file_edit", "shell_exec", "git_commit", "git_push"],
|
|
88
|
+
maxIterations: 30,
|
|
89
|
+
canWrite: false,
|
|
90
|
+
canExecute: false,
|
|
91
|
+
outputFormat: "checklist",
|
|
92
|
+
autoApprove: "reads",
|
|
93
|
+
description: "Code review mode. Analyzes git diff for bugs, style, and security issues. Read-only.",
|
|
94
|
+
};
|
|
95
|
+
const SECURITY_MODE = {
|
|
96
|
+
mode: "security",
|
|
97
|
+
systemPromptSuffix: `You are a security auditor. Perform a comprehensive security audit of the codebase.
|
|
98
|
+
|
|
99
|
+
## Audit Checklist (OWASP Top 10 + More)
|
|
100
|
+
1. **Injection** — SQL injection, command injection, XSS, template injection
|
|
101
|
+
2. **Authentication** — hardcoded credentials, weak auth patterns
|
|
102
|
+
3. **Sensitive Data** — secrets in code, unencrypted storage, PII exposure
|
|
103
|
+
4. **Access Control** — missing authorization checks, IDOR
|
|
104
|
+
5. **Security Misconfiguration** — debug mode, default credentials, CORS
|
|
105
|
+
6. **Vulnerable Dependencies** — known CVEs in dependencies
|
|
106
|
+
7. **Path Traversal** — directory traversal, symlink attacks
|
|
107
|
+
8. **Deserialization** — unsafe JSON.parse, eval, Function constructor
|
|
108
|
+
9. **Logging** — sensitive data in logs, missing audit trails
|
|
109
|
+
10. **Supply Chain** — typosquatting, suspicious packages
|
|
110
|
+
|
|
111
|
+
## Process
|
|
112
|
+
1. Scan all source files for dangerous patterns (regex-based).
|
|
113
|
+
2. Check dependency manifests for known vulnerabilities.
|
|
114
|
+
3. Analyze configuration files for misconfigurations.
|
|
115
|
+
4. Review authentication and authorization flows.
|
|
116
|
+
|
|
117
|
+
## Output Format
|
|
118
|
+
For each finding:
|
|
119
|
+
- **Severity**: CRITICAL / HIGH / MEDIUM / LOW / INFO
|
|
120
|
+
- **Category**: OWASP category or custom
|
|
121
|
+
- **File**: path and line number
|
|
122
|
+
- **Description**: what the issue is
|
|
123
|
+
- **Recommendation**: how to fix it
|
|
124
|
+
|
|
125
|
+
## Constraints
|
|
126
|
+
- You may run limited shell commands: \`npm audit\`, \`pip audit\`, grep-based scans.
|
|
127
|
+
- You may NOT modify any files.
|
|
128
|
+
- You may NOT install packages or run arbitrary code.`,
|
|
129
|
+
allowedTools: [...READ_ONLY_TOOLS, "shell_exec"],
|
|
130
|
+
deniedTools: ["file_write", "file_edit", "git_commit", "git_push"],
|
|
131
|
+
maxIterations: 40,
|
|
132
|
+
canWrite: false,
|
|
133
|
+
canExecute: true,
|
|
134
|
+
outputFormat: "report",
|
|
135
|
+
autoApprove: "reads",
|
|
136
|
+
description: "Security audit mode. OWASP Top 10, dependency scan, secret detection. Limited execution.",
|
|
137
|
+
};
|
|
138
|
+
const DEBUG_MODE = {
|
|
139
|
+
mode: "debug",
|
|
140
|
+
systemPromptSuffix: `You are a debugging expert. Systematically identify the root cause of bugs and fix them.
|
|
141
|
+
|
|
142
|
+
## Debugging Methodology
|
|
143
|
+
1. **Reproduce** — Understand the bug report. Run the code to confirm the issue.
|
|
144
|
+
2. **Isolate** — Narrow down the problem area using logs, breakpoints, or bisection.
|
|
145
|
+
3. **Diagnose** — Read the relevant code. Trace data flow. Identify the root cause.
|
|
146
|
+
4. **Fix** — Make the minimal change to fix the bug. Do not refactor unrelated code.
|
|
147
|
+
5. **Verify** — Run tests or reproduce the scenario to confirm the fix works.
|
|
148
|
+
|
|
149
|
+
## Guidelines
|
|
150
|
+
- Always explain your reasoning before making changes.
|
|
151
|
+
- If a fix requires modifying multiple files, explain the full change plan first.
|
|
152
|
+
- Check for similar bugs in related code paths.
|
|
153
|
+
- Add regression tests when possible.
|
|
154
|
+
- Prefer targeted fixes over broad rewrites.`,
|
|
155
|
+
allowedTools: ALL_TOOLS_MARKER,
|
|
156
|
+
maxIterations: 30,
|
|
157
|
+
canWrite: true,
|
|
158
|
+
canExecute: true,
|
|
159
|
+
outputFormat: "streaming",
|
|
160
|
+
autoApprove: "reads",
|
|
161
|
+
description: "Debug mode. Systematic bug finding with reproduce-isolate-diagnose-fix-verify methodology.",
|
|
162
|
+
};
|
|
163
|
+
const REFACTOR_MODE = {
|
|
164
|
+
mode: "refactor",
|
|
165
|
+
systemPromptSuffix: `You are a refactoring expert. Improve code quality without changing external behavior.
|
|
166
|
+
|
|
167
|
+
## Refactoring Process
|
|
168
|
+
1. **Baseline** — Run existing tests to confirm they pass before changes.
|
|
169
|
+
2. **Identify** — Find code smells: duplication, long functions, god classes, tight coupling.
|
|
170
|
+
3. **Plan** — Describe each refactoring step before executing it.
|
|
171
|
+
4. **Execute** — Apply one refactoring at a time. Commit after each step.
|
|
172
|
+
5. **Verify** — Run tests after each step to ensure no regressions.
|
|
173
|
+
|
|
174
|
+
## Refactoring Patterns
|
|
175
|
+
- Extract function/method for long blocks
|
|
176
|
+
- Rename for clarity
|
|
177
|
+
- Remove dead code
|
|
178
|
+
- Consolidate duplicates (DRY)
|
|
179
|
+
- Simplify conditionals
|
|
180
|
+
- Introduce interfaces for loose coupling
|
|
181
|
+
- Split large files
|
|
182
|
+
|
|
183
|
+
## Rules
|
|
184
|
+
- NEVER change external behavior (inputs, outputs, API contracts).
|
|
185
|
+
- ALWAYS run tests before AND after each refactoring step.
|
|
186
|
+
- Commit after each logical refactoring step with a descriptive message.
|
|
187
|
+
- If tests fail after a change, revert and try a different approach.`,
|
|
188
|
+
allowedTools: ALL_TOOLS_MARKER,
|
|
189
|
+
maxIterations: 40,
|
|
190
|
+
canWrite: true,
|
|
191
|
+
canExecute: true,
|
|
192
|
+
outputFormat: "diff",
|
|
193
|
+
autoApprove: "safe_writes",
|
|
194
|
+
description: "Refactoring mode. Improves code quality with test-guarded, incremental changes.",
|
|
195
|
+
};
|
|
196
|
+
const TEST_MODE = {
|
|
197
|
+
mode: "test",
|
|
198
|
+
systemPromptSuffix: `You are a test engineer. Generate comprehensive tests for the codebase.
|
|
199
|
+
|
|
200
|
+
## Test Strategy
|
|
201
|
+
1. **Analyze** — Read source files to understand functions, classes, and modules.
|
|
202
|
+
2. **Plan** — Identify untested code paths, edge cases, and boundary conditions.
|
|
203
|
+
3. **Write** — Generate tests covering:
|
|
204
|
+
- Happy path (normal usage)
|
|
205
|
+
- Edge cases (empty, null, boundary values)
|
|
206
|
+
- Error cases (invalid input, network failures)
|
|
207
|
+
- Integration (module interactions)
|
|
208
|
+
4. **Run** — Execute the test suite to verify tests pass.
|
|
209
|
+
|
|
210
|
+
## Test Quality Guidelines
|
|
211
|
+
- Tests should be independent and idempotent.
|
|
212
|
+
- Use descriptive test names that explain the scenario.
|
|
213
|
+
- Follow the Arrange-Act-Assert pattern.
|
|
214
|
+
- Mock external dependencies (API calls, filesystem, database).
|
|
215
|
+
- Aim for meaningful coverage, not just line coverage.
|
|
216
|
+
|
|
217
|
+
## Constraints
|
|
218
|
+
- You may ONLY create or modify test files (files matching *test*, *spec*, __tests__).
|
|
219
|
+
- You may NOT modify source files.
|
|
220
|
+
- You may run the test runner via shell_exec.`,
|
|
221
|
+
allowedTools: [...READ_ONLY_TOOLS, "file_write", "file_edit", "shell_exec"],
|
|
222
|
+
maxIterations: 30,
|
|
223
|
+
canWrite: true,
|
|
224
|
+
canExecute: true,
|
|
225
|
+
outputFormat: "streaming",
|
|
226
|
+
autoApprove: "safe_writes",
|
|
227
|
+
description: "Test generation mode. Creates comprehensive tests without modifying source files.",
|
|
228
|
+
};
|
|
229
|
+
const PLAN_MODE = {
|
|
230
|
+
mode: "plan",
|
|
231
|
+
systemPromptSuffix: `You are a software architect creating a detailed implementation plan.
|
|
232
|
+
|
|
233
|
+
## Planning Process
|
|
234
|
+
1. **Understand** — Read the codebase to understand current architecture and conventions.
|
|
235
|
+
2. **Analyze** — Break down the task into concrete subtasks with dependencies.
|
|
236
|
+
3. **Estimate** — Provide rough time/complexity estimates for each subtask.
|
|
237
|
+
4. **Risk** — Identify risks, unknowns, and potential blockers.
|
|
238
|
+
|
|
239
|
+
## Output Format
|
|
240
|
+
Generate a structured plan:
|
|
241
|
+
\`\`\`
|
|
242
|
+
## Implementation Plan: [Task Title]
|
|
243
|
+
|
|
244
|
+
### Overview
|
|
245
|
+
[1-2 sentence summary]
|
|
246
|
+
|
|
247
|
+
### Tasks
|
|
248
|
+
1. **[Task Name]** (est: Xh, complexity: low/medium/high)
|
|
249
|
+
- Files: [list of files to modify]
|
|
250
|
+
- Description: [what to do]
|
|
251
|
+
- Dependencies: [which tasks must complete first]
|
|
252
|
+
|
|
253
|
+
### Risks & Unknowns
|
|
254
|
+
- [Risk 1]: [mitigation]
|
|
255
|
+
- [Risk 2]: [mitigation]
|
|
256
|
+
|
|
257
|
+
### Testing Strategy
|
|
258
|
+
[How to verify the implementation]
|
|
259
|
+
\`\`\`
|
|
260
|
+
|
|
261
|
+
## Constraints
|
|
262
|
+
- You are in READ-ONLY mode. Do not modify any files.
|
|
263
|
+
- Do not execute any commands.
|
|
264
|
+
- Focus on creating an actionable plan that another agent or developer can follow.`,
|
|
265
|
+
allowedTools: [...READ_ONLY_TOOLS],
|
|
266
|
+
deniedTools: ["file_write", "file_edit", "shell_exec", "git_commit", "git_push"],
|
|
267
|
+
maxIterations: 20,
|
|
268
|
+
canWrite: false,
|
|
269
|
+
canExecute: false,
|
|
270
|
+
outputFormat: "report",
|
|
271
|
+
autoApprove: "reads",
|
|
272
|
+
description: "Planning mode. Creates detailed implementation plans without modifying files. Read-only.",
|
|
273
|
+
};
|
|
274
|
+
const ARCHITECT_MODE = {
|
|
275
|
+
mode: "architect",
|
|
276
|
+
systemPromptSuffix: `You are a system architect. Analyze the codebase architecture, identify patterns and anti-patterns, and recommend improvements.
|
|
277
|
+
|
|
278
|
+
## Analysis Areas
|
|
279
|
+
1. **Structure** — Module organization, layer separation, dependency direction
|
|
280
|
+
2. **Patterns** — Design patterns in use (MVC, repository, factory, observer, etc.)
|
|
281
|
+
3. **Anti-Patterns** — God classes, circular dependencies, leaky abstractions, shotgun surgery
|
|
282
|
+
4. **Scalability** — Bottlenecks, single points of failure, horizontal scaling readiness
|
|
283
|
+
5. **Maintainability** — Coupling, cohesion, complexity metrics, test coverage
|
|
284
|
+
6. **Data Flow** — How data moves through the system (API → service → DB)
|
|
285
|
+
|
|
286
|
+
## Output Format
|
|
287
|
+
\`\`\`
|
|
288
|
+
## Architecture Analysis: [Project Name]
|
|
289
|
+
|
|
290
|
+
### Current Architecture
|
|
291
|
+
[Diagram or description of the current architecture]
|
|
292
|
+
|
|
293
|
+
### Patterns Identified
|
|
294
|
+
- [Pattern]: [where and how it's used]
|
|
295
|
+
|
|
296
|
+
### Anti-Patterns Found
|
|
297
|
+
- **[Anti-Pattern]** (severity: HIGH/MEDIUM/LOW)
|
|
298
|
+
- Location: [files]
|
|
299
|
+
- Impact: [what problems it causes]
|
|
300
|
+
- Recommendation: [how to fix]
|
|
301
|
+
|
|
302
|
+
### Recommendations (Priority Order)
|
|
303
|
+
1. [Most impactful recommendation]
|
|
304
|
+
2. [Second recommendation]
|
|
305
|
+
...
|
|
306
|
+
|
|
307
|
+
### Migration Path
|
|
308
|
+
[If significant changes recommended, outline a migration strategy]
|
|
309
|
+
\`\`\`
|
|
310
|
+
|
|
311
|
+
## Constraints
|
|
312
|
+
- You are in READ-ONLY mode. Do not modify any files.
|
|
313
|
+
- Read broadly across the codebase to understand the full picture.
|
|
314
|
+
- Cite specific files and code patterns in your analysis.`,
|
|
315
|
+
allowedTools: [...READ_ONLY_TOOLS],
|
|
316
|
+
deniedTools: ["file_write", "file_edit", "shell_exec", "git_commit", "git_push"],
|
|
317
|
+
maxIterations: 30,
|
|
318
|
+
canWrite: false,
|
|
319
|
+
canExecute: false,
|
|
320
|
+
outputFormat: "report",
|
|
321
|
+
autoApprove: "reads",
|
|
322
|
+
description: "Architecture analysis mode. Identifies patterns, anti-patterns, and recommends improvements. Read-only.",
|
|
323
|
+
};
|
|
324
|
+
// ─── Mode Registry ───
|
|
325
|
+
/** All mode configurations indexed by mode name */
|
|
326
|
+
const MODE_REGISTRY = {
|
|
327
|
+
code: CODE_MODE,
|
|
328
|
+
report: REPORT_MODE,
|
|
329
|
+
review: REVIEW_MODE,
|
|
330
|
+
security: SECURITY_MODE,
|
|
331
|
+
debug: DEBUG_MODE,
|
|
332
|
+
refactor: REFACTOR_MODE,
|
|
333
|
+
test: TEST_MODE,
|
|
334
|
+
plan: PLAN_MODE,
|
|
335
|
+
architect: ARCHITECT_MODE,
|
|
336
|
+
};
|
|
337
|
+
// ─── Public API ───
|
|
338
|
+
/**
|
|
339
|
+
* 모드 이름으로 설정을 가져온다.
|
|
340
|
+
* @param mode 에이전트 모드 이름
|
|
341
|
+
* @returns 해당 모드의 전체 설정
|
|
342
|
+
*/
|
|
343
|
+
export function getAgentModeConfig(mode) {
|
|
344
|
+
return MODE_REGISTRY[mode];
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* 등록된 모든 모드 목록을 반환한다.
|
|
348
|
+
* @returns 모든 모드 설정 배열
|
|
349
|
+
*/
|
|
350
|
+
export function getAllAgentModes() {
|
|
351
|
+
return Object.values(MODE_REGISTRY);
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* 모드 이름이 유효한지 검증한다.
|
|
355
|
+
* @param mode 검증할 모드 이름
|
|
356
|
+
* @returns 유효한 AgentMode이면 true
|
|
357
|
+
*/
|
|
358
|
+
export function isValidAgentMode(mode) {
|
|
359
|
+
return mode in MODE_REGISTRY;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* 주어진 모드에서 특정 도구의 사용이 허용되는지 확인한다.
|
|
363
|
+
* allowedTools가 빈 배열이면 모든 도구 허용 (deniedTools 제외).
|
|
364
|
+
*
|
|
365
|
+
* @param mode 에이전트 모드 이름
|
|
366
|
+
* @param toolName 확인할 도구 이름
|
|
367
|
+
* @returns 허용되면 true, 거부되면 false
|
|
368
|
+
*/
|
|
369
|
+
export function isToolAllowedInMode(mode, toolName) {
|
|
370
|
+
const config = MODE_REGISTRY[mode];
|
|
371
|
+
// 명시적 거부 목록에 있으면 항상 거부
|
|
372
|
+
if (config.deniedTools?.includes(toolName)) {
|
|
373
|
+
return false;
|
|
374
|
+
}
|
|
375
|
+
// allowedTools가 빈 배열이면 전체 허용 (deniedTools 제외)
|
|
376
|
+
if (config.allowedTools.length === 0) {
|
|
377
|
+
return true;
|
|
378
|
+
}
|
|
379
|
+
// 명시적 허용 목록에 있어야 허용
|
|
380
|
+
return config.allowedTools.includes(toolName);
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* 테스트 모드에서 파일 경로가 테스트 파일인지 검증한다.
|
|
384
|
+
* test 모드는 테스트 파일만 쓰기 가능.
|
|
385
|
+
*
|
|
386
|
+
* @param filePath 검증할 파일 경로
|
|
387
|
+
* @returns 테스트 파일이면 true
|
|
388
|
+
*/
|
|
389
|
+
export function isTestFile(filePath) {
|
|
390
|
+
const lower = filePath.toLowerCase();
|
|
391
|
+
return (lower.includes("test") ||
|
|
392
|
+
lower.includes("spec") ||
|
|
393
|
+
lower.includes("__tests__") ||
|
|
394
|
+
lower.endsWith(".test.ts") ||
|
|
395
|
+
lower.endsWith(".test.js") ||
|
|
396
|
+
lower.endsWith(".test.tsx") ||
|
|
397
|
+
lower.endsWith(".test.jsx") ||
|
|
398
|
+
lower.endsWith(".spec.ts") ||
|
|
399
|
+
lower.endsWith(".spec.js") ||
|
|
400
|
+
lower.endsWith(".spec.tsx") ||
|
|
401
|
+
lower.endsWith(".spec.jsx"));
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* 모드별 시스템 프롬프트 서픽스를 기존 시스템 프롬프트에 결합한다.
|
|
405
|
+
* mode가 "code"이면 서픽스가 비어있으므로 원본을 그대로 반환.
|
|
406
|
+
*
|
|
407
|
+
* @param basePrompt 기본 시스템 프롬프트
|
|
408
|
+
* @param mode 에이전트 모드 이름
|
|
409
|
+
* @returns 결합된 시스템 프롬프트
|
|
410
|
+
*/
|
|
411
|
+
export function buildModeSystemPrompt(basePrompt, mode) {
|
|
412
|
+
const config = MODE_REGISTRY[mode];
|
|
413
|
+
if (!config.systemPromptSuffix) {
|
|
414
|
+
return basePrompt;
|
|
415
|
+
}
|
|
416
|
+
return `${basePrompt}\n\n---\n\n## Mode: ${mode.toUpperCase()}\n\n${config.systemPromptSuffix}`;
|
|
417
|
+
}
|
|
418
|
+
//# sourceMappingURL=agent-modes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-modes.js","sourceRoot":"","sources":["../src/agent-modes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AA8CH,0BAA0B;AAE1B,MAAM,eAAe,GAAG;IACtB,WAAW;IACX,MAAM;IACN,MAAM;IACN,aAAa;CACL,CAAC;AAEX,MAAM,cAAc,GAAG;IACrB,UAAU;IACV,SAAS;IACT,YAAY;CACJ,CAAC;AAEX,MAAM,g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;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CAAC,UAAkB,EAAE,IAAe;IACvE,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IACnC,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAAE,CAAC;QAC/B,OAAO,UAAU,CAAC;IACpB,CAAC;IACD,OAAO,GAAG,UAAU,uBAAuB,IAAI,CAAC,WAAW,EAAE,OAAO,MAAM,CAAC,kBAAkB,EAAE,CAAC;AAClG,CAAC"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module approval
|
|
3
|
+
* @description 승인 시스템 — 위험 작업 실행 전 사용자 승인 요청/대기.
|
|
4
|
+
*
|
|
5
|
+
* 플로우:
|
|
6
|
+
* 1. Governor가 위험 작업 감지 (ApprovalRequiredError)
|
|
7
|
+
* 2. ApprovalManager가 승인 요청 이벤트 emit
|
|
8
|
+
* 3. CLI/UI에서 사용자에게 프롬프트 표시
|
|
9
|
+
* 4. 사용자 응답 (approve/reject/always_approve)
|
|
10
|
+
* 5. 결과를 Agent Loop에 반환
|
|
11
|
+
*
|
|
12
|
+
* @see 설계 문서 Section 6.3
|
|
13
|
+
*/
|
|
14
|
+
import { EventEmitter } from "node:events";
|
|
15
|
+
import type { ApprovalAction, PendingAction, ToolCall } from "./types.js";
|
|
16
|
+
/** 승인 요청 */
|
|
17
|
+
export interface ApprovalRequest {
|
|
18
|
+
/** 고유 ID */
|
|
19
|
+
id: string;
|
|
20
|
+
/** 도구 이름 */
|
|
21
|
+
toolName: string;
|
|
22
|
+
/** 도구 인자 */
|
|
23
|
+
arguments: Record<string, unknown>;
|
|
24
|
+
/** 위험도 */
|
|
25
|
+
riskLevel: "medium" | "high" | "critical";
|
|
26
|
+
/** 승인이 필요한 이유 */
|
|
27
|
+
reason: string;
|
|
28
|
+
/** 변경 미리보기 (file_write/edit의 경우) */
|
|
29
|
+
diff?: string;
|
|
30
|
+
/** 승인 대기 타임아웃 (ms) */
|
|
31
|
+
timeout: number;
|
|
32
|
+
}
|
|
33
|
+
/** 승인 응답 */
|
|
34
|
+
export type ApprovalResponse = "approve" | "reject" | "always_approve";
|
|
35
|
+
/**
|
|
36
|
+
* 승인 핸들러 — CLI/UI가 구현.
|
|
37
|
+
* ApprovalManager에 등록하면 승인 요청 시 호출된다.
|
|
38
|
+
*/
|
|
39
|
+
export type ApprovalHandler = (request: ApprovalRequest) => Promise<ApprovalResponse>;
|
|
40
|
+
/** 자동 승인 설정 */
|
|
41
|
+
export interface AutoApprovalConfig {
|
|
42
|
+
/** 자동 승인할 액션 목록 */
|
|
43
|
+
autoApprove: ApprovalAction[];
|
|
44
|
+
/** 항상 승인 필요한 액션 목록 (기본: DELETE_FILE, GIT_PUSH, CREATE_PR) */
|
|
45
|
+
requireApproval: ApprovalAction[];
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* ApprovalManager — 위험 작업의 승인 프로세스를 관리.
|
|
49
|
+
*
|
|
50
|
+
* 역할:
|
|
51
|
+
* - 도구 호출이 승인 필요한지 판단
|
|
52
|
+
* - 승인 요청 생성 및 핸들러 호출
|
|
53
|
+
* - always_approve 세션 캐시 관리
|
|
54
|
+
* - 승인 타임아웃 처리
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* const manager = new ApprovalManager();
|
|
59
|
+
*
|
|
60
|
+
* // CLI에서 핸들러 등록
|
|
61
|
+
* manager.setHandler(async (request) => {
|
|
62
|
+
* const answer = await askUser(`Approve ${request.reason}? [Y/n/a]`);
|
|
63
|
+
* if (answer === 'a') return 'always_approve';
|
|
64
|
+
* return answer === 'n' ? 'reject' : 'approve';
|
|
65
|
+
* });
|
|
66
|
+
*
|
|
67
|
+
* // Agent Loop에서 사용
|
|
68
|
+
* if (manager.needsApproval('file_write', args)) {
|
|
69
|
+
* const response = await manager.requestApproval(request);
|
|
70
|
+
* if (response === 'reject') { ... }
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare class ApprovalManager extends EventEmitter {
|
|
75
|
+
/** always_approve로 승인된 도구 (세션 내 유지) */
|
|
76
|
+
private readonly alwaysApproved;
|
|
77
|
+
/** 자동 승인 설정 */
|
|
78
|
+
private readonly autoApproveActions;
|
|
79
|
+
/** 항상 승인 필요한 액션 */
|
|
80
|
+
private readonly requireApprovalActions;
|
|
81
|
+
/** 승인 핸들러 (CLI/UI가 등록) */
|
|
82
|
+
private handler;
|
|
83
|
+
/** 기본 타임아웃 (ms) */
|
|
84
|
+
private readonly defaultTimeout;
|
|
85
|
+
constructor(config?: Partial<AutoApprovalConfig>, defaultTimeout?: number);
|
|
86
|
+
/**
|
|
87
|
+
* 승인 핸들러 등록.
|
|
88
|
+
* CLI에서 readline 기반 프롬프트, UI에서 웹소켓 기반 프롬프트를 구현한다.
|
|
89
|
+
* @param handler 승인 요청을 처리할 함수
|
|
90
|
+
*/
|
|
91
|
+
setHandler(handler: ApprovalHandler): void;
|
|
92
|
+
/**
|
|
93
|
+
* 도구 호출이 승인 필요한지 판단.
|
|
94
|
+
* @param toolName 도구 이름
|
|
95
|
+
* @param args 도구 인자
|
|
96
|
+
* @returns 승인이 필요하면 해당 ApprovalRequest 정보, 불필요하면 null
|
|
97
|
+
*/
|
|
98
|
+
checkApproval(toolName: string, args: Record<string, unknown>): ApprovalRequest | null;
|
|
99
|
+
/**
|
|
100
|
+
* 승인 필요 여부를 간단히 확인하는 편의 메서드.
|
|
101
|
+
* @param toolName 도구 이름
|
|
102
|
+
* @param args 도구 인자
|
|
103
|
+
* @returns 승인이 필요하면 true
|
|
104
|
+
*/
|
|
105
|
+
needsApproval(toolName: string, args: Record<string, unknown>): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* 승인 요청을 핸들러에 전달하고 응답을 반환.
|
|
108
|
+
* 핸들러가 없으면 기본적으로 reject.
|
|
109
|
+
* @param request 승인 요청
|
|
110
|
+
* @returns 승인 응답
|
|
111
|
+
*/
|
|
112
|
+
requestApproval(request: ApprovalRequest): Promise<ApprovalResponse>;
|
|
113
|
+
/**
|
|
114
|
+
* 도구를 always_approve 목록에 추가.
|
|
115
|
+
* 세션 내에서 해당 도구의 모든 호출이 자동 승인된다.
|
|
116
|
+
* @param toolName 도구 이름
|
|
117
|
+
*/
|
|
118
|
+
addAlwaysApprove(toolName: string): void;
|
|
119
|
+
/**
|
|
120
|
+
* always_approve 목록을 초기화.
|
|
121
|
+
*/
|
|
122
|
+
clearAlwaysApproved(): void;
|
|
123
|
+
/**
|
|
124
|
+
* 현재 always_approve 목록을 반환.
|
|
125
|
+
*/
|
|
126
|
+
getAlwaysApproved(): ReadonlySet<string>;
|
|
127
|
+
/**
|
|
128
|
+
* ToolCall에서 PendingAction을 생성하는 헬퍼.
|
|
129
|
+
* AgentLoop에서 agent:approval_needed 이벤트 emit에 사용.
|
|
130
|
+
*/
|
|
131
|
+
buildPendingAction(toolCall: ToolCall, request: ApprovalRequest): PendingAction;
|
|
132
|
+
private buildToolKey;
|
|
133
|
+
private buildReason;
|
|
134
|
+
private extractDiff;
|
|
135
|
+
private resolveActionType;
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=approval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approval.d.ts","sourceRoot":"","sources":["../src/approval.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAI1E,YAAY;AACZ,MAAM,WAAW,eAAe;IAC9B,YAAY;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,YAAY;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY;IACZ,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,UAAU;IACV,SAAS,E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