@kkelly-offical/kkcode 0.1.3 → 0.1.7

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.
Files changed (66) hide show
  1. package/README.md +110 -172
  2. package/package.json +46 -46
  3. package/src/agent/agent.mjs +220 -170
  4. package/src/agent/prompt/bug-hunter.txt +90 -0
  5. package/src/agent/prompt/frontend-designer.txt +58 -0
  6. package/src/agent/prompt/longagent-blueprint-agent.txt +83 -0
  7. package/src/agent/prompt/longagent-coding-agent.txt +37 -0
  8. package/src/agent/prompt/longagent-debugging-agent.txt +46 -0
  9. package/src/agent/prompt/longagent-preview-agent.txt +63 -0
  10. package/src/config/defaults.mjs +260 -195
  11. package/src/config/schema.mjs +71 -6
  12. package/src/core/constants.mjs +91 -46
  13. package/src/index.mjs +1 -1
  14. package/src/knowledge/frontend-aesthetics.txt +39 -0
  15. package/src/knowledge/loader.mjs +2 -1
  16. package/src/knowledge/tailwind.txt +12 -3
  17. package/src/mcp/client-http.mjs +141 -157
  18. package/src/mcp/client-sse.mjs +288 -286
  19. package/src/mcp/client-stdio.mjs +533 -451
  20. package/src/mcp/constants.mjs +2 -0
  21. package/src/mcp/registry.mjs +479 -394
  22. package/src/mcp/stdio-framing.mjs +133 -127
  23. package/src/mcp/tool-result.mjs +24 -0
  24. package/src/observability/index.mjs +42 -0
  25. package/src/observability/metrics.mjs +137 -0
  26. package/src/observability/tracer.mjs +137 -0
  27. package/src/orchestration/background-manager.mjs +372 -358
  28. package/src/orchestration/background-worker.mjs +305 -245
  29. package/src/orchestration/longagent-manager.mjs +171 -116
  30. package/src/orchestration/stage-scheduler.mjs +728 -489
  31. package/src/permission/exec-policy.mjs +9 -11
  32. package/src/provider/anthropic.mjs +1 -0
  33. package/src/provider/openai.mjs +340 -339
  34. package/src/provider/retry-policy.mjs +68 -68
  35. package/src/provider/router.mjs +241 -228
  36. package/src/provider/sse.mjs +104 -91
  37. package/src/repl.mjs +59 -7
  38. package/src/session/checkpoint.mjs +66 -3
  39. package/src/session/compaction.mjs +298 -276
  40. package/src/session/engine.mjs +232 -225
  41. package/src/session/longagent-4stage.mjs +460 -0
  42. package/src/session/longagent-hybrid.mjs +1097 -0
  43. package/src/session/longagent-plan.mjs +365 -329
  44. package/src/session/longagent-project-memory.mjs +53 -0
  45. package/src/session/longagent-scaffold.mjs +291 -100
  46. package/src/session/longagent-task-bus.mjs +54 -0
  47. package/src/session/longagent-utils.mjs +472 -0
  48. package/src/session/longagent.mjs +900 -1462
  49. package/src/session/loop.mjs +65 -40
  50. package/src/session/project-context.mjs +30 -0
  51. package/src/session/prompt/agent.txt +25 -0
  52. package/src/session/prompt/plan.txt +31 -9
  53. package/src/session/rollback.mjs +196 -0
  54. package/src/session/store.mjs +519 -503
  55. package/src/session/system-prompt.mjs +273 -260
  56. package/src/session/task-validator.mjs +4 -3
  57. package/src/skill/builtin/design.mjs +76 -0
  58. package/src/skill/builtin/frontend.mjs +8 -0
  59. package/src/skill/registry.mjs +390 -336
  60. package/src/storage/ghost-commit-store.mjs +18 -8
  61. package/src/tool/executor.mjs +11 -0
  62. package/src/tool/git-auto.mjs +0 -19
  63. package/src/tool/question-prompt.mjs +93 -86
  64. package/src/tool/registry.mjs +71 -37
  65. package/src/ui/activity-renderer.mjs +664 -410
  66. package/src/util/git.mjs +23 -0
@@ -0,0 +1,46 @@
1
+ === LONGAGENT STAGE 4/4: DEBUGGING AGENT ===
2
+
3
+ You are the Debugging Agent in the four-stage LongAgent architecture.
4
+
5
+ # YOUR ROLE
6
+ Verify the implementation, find bugs, and ensure all requirements are met.
7
+
8
+ # STAGE 4: DEBUG MODE - FULL PERMISSIONS
9
+
10
+ # DEBUGGING OBJECTIVES
11
+
12
+ ## 1. Syntax & Basic Checks
13
+ - Verify all files parse without syntax errors
14
+ - Check for missing imports/exports
15
+ - Run basic syntax validation commands
16
+
17
+ ## 2. Completeness Check
18
+ - Compare implementation against Stage 2 blueprint
19
+ - Verify all planned files exist and all functions implemented
20
+
21
+ ## 3. Test & Validate
22
+ - Run existing test suite (if any)
23
+ - Test edge cases identified in blueprint
24
+ - Validate error handling works
25
+
26
+ ## 4. Bug Detection & Fixing
27
+ - Identify and fix any bugs
28
+ - If major issues found, output: [RETURN TO STAGE 3: CODING]
29
+
30
+ ## 5. Final Verification
31
+ - Run full build/test process
32
+ - Confirm all acceptance criteria met
33
+
34
+ # WORKFLOW
35
+ 1. Check syntax first - quick wins
36
+ 2. Verify completeness against blueprint
37
+ 3. Run tests
38
+ 4. Fix any issues found
39
+ 5. If major issues, go back to Stage 3
40
+ 6. Do final full verification
41
+
42
+ End your response with:
43
+ ```
44
+ [STAGE 4/4: DEBUGGING - COMPLETE]
45
+ [TASK_COMPLETE]
46
+ ```
@@ -0,0 +1,63 @@
1
+ === LONGAGENT STAGE 1/4: PREVIEWING AGENT ===
2
+
3
+ You are the Previewing Agent in the four-stage LongAgent architecture.
4
+
5
+ # YOUR ROLE
6
+ You are responsible for understanding the task, exploring the codebase, and extracting critical information.
7
+
8
+ # STAGE 1: PREVIEW MODE - READ-ONLY
9
+ IMPORTANT: You are in READ-ONLY mode. NO EDITING ALLOWED.
10
+
11
+ CRITICAL CONSTRAINTS:
12
+ - NO file editing (edit, write, multiedit, patch)
13
+ - NO commands that modify filesystem or system state
14
+ - NO git operations (commit, push, etc.)
15
+ - ONLY use: read, glob, grep, list, bash (read-only)
16
+ - This is ZERO-EXCEPTION rule
17
+
18
+ # EXPLORATION OBJECTIVES
19
+
20
+ ## 1. Understand User Request
21
+ - Extract core requirements from user input
22
+ - Identify key constraints, goals, and expected outcomes
23
+ - Note any specific files, functions, or patterns mentioned
24
+
25
+ ## 2. Explore Project Structure
26
+ - Use `glob` to map the entire codebase
27
+ - Understand directory organization and file naming conventions
28
+ - Identify project type (e.g., Node.js, Python, React, etc.)
29
+ - Locate configuration files (package.json, tsconfig.json, etc.)
30
+
31
+ ## 3. Analyze Existing Code
32
+ - Search for relevant existing code using `grep`
33
+ - Read critical files to understand current implementation
34
+ - Identify patterns, utilities, and functions that can be reused
35
+ - Look for tests to understand expected behavior
36
+ - Trace dependencies and import relationships
37
+
38
+ ## 4. Extract Key Information
39
+ - Project structure summary
40
+ - Relevant file paths
41
+ - Existing patterns and utilities
42
+ - Potential challenges or constraints
43
+ - Dependencies and their versions
44
+
45
+ # OUTPUT FORMAT
46
+
47
+ Present findings structurally:
48
+ - Project Overview (type, stack, config)
49
+ - Critical Files Identified (to modify/create/reference)
50
+ - Reusable Assets (existing functions, patterns, dependencies)
51
+ - Constraints & Considerations
52
+
53
+ # WORKFLOW
54
+ 1. Explore thoroughly - don't rush
55
+ 2. Use parallel tool calls for efficiency
56
+ 3. Focus on understanding, not solving
57
+ 4. Document everything clearly
58
+ 5. NO EDITING - STAY IN READ-ONLY MODE
59
+
60
+ End your response with:
61
+ ```
62
+ [STAGE 1/4: PREVIEW - COMPLETE]
63
+ ```
@@ -1,195 +1,260 @@
1
- export const DEFAULT_CONFIG = {
2
- language: "en",
3
- provider: {
4
- default: "openai",
5
- openai: {
6
- base_url: "https://api.openai.com/v1",
7
- api_key_env: "OPENAI_API_KEY",
8
- default_model: "gpt-5.3-codex",
9
- models: ["gpt-5.3-codex", "gpt-5.2"],
10
- timeout_ms: 120000,
11
- stream_idle_timeout_ms: 120000,
12
- max_tokens: 32768,
13
- context_limit: null,
14
- retry_attempts: 3,
15
- retry_base_delay_ms: 800,
16
- stream: true,
17
- thinking: null
18
- },
19
- anthropic: {
20
- base_url: "https://api.anthropic.com/v1",
21
- api_key_env: "ANTHROPIC_API_KEY",
22
- default_model: "claude-opus-4-6",
23
- models: ["claude-sonnet-4-5", "claude-sonnet-4-6", "claude-haiku-4-5-20251001", "claude-opus-4-6"],
24
- timeout_ms: 120000,
25
- stream_idle_timeout_ms: 120000,
26
- max_tokens: 32768,
27
- context_limit: null,
28
- retry_attempts: 3,
29
- retry_base_delay_ms: 800,
30
- stream: true,
31
- thinking: null
32
- },
33
- ollama: {
34
- base_url: "http://localhost:11434",
35
- api_key_env: "",
36
- default_model: "llama3.1",
37
- timeout_ms: 300000,
38
- stream_idle_timeout_ms: 300000,
39
- max_tokens: 32768,
40
- context_limit: null,
41
- retry_attempts: 1,
42
- retry_base_delay_ms: 1000,
43
- stream: true,
44
- thinking: null
45
- },
46
- model_context: {}
47
- },
48
- agent: {
49
- default_mode: "agent",
50
- max_steps: 8,
51
- longagent: {
52
- max_iterations: 0,
53
- no_progress_warning: 3,
54
- no_progress_limit: 5,
55
- max_stage_recoveries: 3,
56
- heartbeat_timeout_ms: 120000,
57
- checkpoint_interval: 5,
58
- parallel: {
59
- enabled: true,
60
- max_concurrency: 3,
61
- stage_pass_rule: "all_success",
62
- task_timeout_ms: 600000,
63
- task_max_retries: 2
64
- },
65
- planner: {
66
- intake_questions: {
67
- enabled: true,
68
- max_rounds: 6
69
- },
70
- ask_user_after_plan_frozen: false
71
- },
72
- resume_incomplete_files: true,
73
- scaffold: {
74
- enabled: true
75
- },
76
- git: {
77
- enabled: "ask",
78
- auto_branch: true,
79
- auto_commit_stages: true,
80
- auto_merge: true,
81
- branch_prefix: "kkcode"
82
- },
83
- usability_gates: {
84
- prompt_user: "first_run",
85
- build: { enabled: true },
86
- test: { enabled: true },
87
- review: { enabled: true },
88
- health: { enabled: true },
89
- budget: { enabled: true }
90
- }
91
- },
92
- subagents: {},
93
- routing: {
94
- categories: {}
95
- }
96
- },
97
- mcp: {
98
- servers: {},
99
- auto_discover: true,
100
- timeout_ms: 30000
101
- },
102
- skills: {
103
- enabled: true,
104
- dirs: [".kkcode/skills"]
105
- },
106
- permission: {
107
- default_policy: "ask",
108
- non_tty_default: "deny",
109
- rules: []
110
- },
111
- storage: {
112
- session_shard_enabled: true,
113
- flush_interval_ms: 1000,
114
- event_rotate_mb: 32,
115
- event_retain_days: 14
116
- },
117
- background: {
118
- mode: "worker_process",
119
- worker_timeout_ms: 900000,
120
- max_parallel: 2
121
- },
122
- runtime: {
123
- tool_registry_cache_ttl_ms: 30000,
124
- mcp_refresh_ttl_ms: 60000
125
- },
126
- tool: {
127
- sources: {
128
- builtin: true,
129
- local: true,
130
- mcp: true,
131
- plugin: true
132
- },
133
- write_lock: {
134
- mode: "file_lock",
135
- wait_timeout_ms: 120000
136
- },
137
- local_dirs: [".kkcode/tools", ".kkcode/tool"],
138
- plugin_dirs: [".kkcode/plugins", ".kkcode/plugin"]
139
- },
140
- session: {
141
- max_history: 30,
142
- recovery: true,
143
- compaction_threshold_ratio: 0.7,
144
- compaction_threshold_messages: 50,
145
- context_cache_points: true
146
- },
147
- review: {
148
- sort: "risk_first",
149
- default_lines: 80,
150
- max_expand_lines: 1200,
151
- risk_weights: {
152
- sensitive_path: 4,
153
- large_change: 3,
154
- medium_change: 2,
155
- small_change: 1,
156
- executable_script: 2,
157
- command_pattern: 3
158
- }
159
- },
160
- usage: {
161
- pricing_file: null,
162
- aggregation: ["turn", "session", "global"],
163
- budget: {
164
- session_usd: null,
165
- global_usd: null,
166
- warn_at_percent: 80,
167
- strategy: "warn"
168
- }
169
- },
170
- ui: {
171
- theme_file: null,
172
- mode_colors: {
173
- ask: "#8da3b9",
174
- plan: "#00b7c2",
175
- agent: "#2ac26f",
176
- longagent: "#ff7a33"
177
- },
178
- layout: "compact",
179
- markdown_render: true,
180
- status: {
181
- show_cost: true,
182
- show_token_meter: true
183
- }
184
- }
185
- }
186
-
187
- export const VALID_PROVIDER_TYPES = ["openai", "anthropic", "ollama", "openai-compatible"]
188
-
189
- import { listProviders } from "../provider/router.mjs"
190
- export function getValidProviderTypes() {
191
- return listProviders()
192
- }
193
- export const VALID_MODES = ["ask", "plan", "agent", "longagent"]
194
- export const VALID_REVIEW_SORT = ["risk_first", "time_order", "file_order"]
195
- export const VALID_LANGUAGES = ["en", "zh"]
1
+ export const DEFAULT_CONFIG = {
2
+ language: "en",
3
+ provider: {
4
+ default: "openai",
5
+ strict_mode: false,
6
+ openai: {
7
+ base_url: "https://api.openai.com/v1",
8
+ api_key_env: "OPENAI_API_KEY",
9
+ default_model: "gpt-5.3-codex",
10
+ models: ["gpt-5.3-codex", "gpt-5.2"],
11
+ timeout_ms: 120000,
12
+ stream_idle_timeout_ms: 120000,
13
+ max_tokens: 32768,
14
+ context_limit: null,
15
+ retry_attempts: 3,
16
+ retry_base_delay_ms: 800,
17
+ stream: true,
18
+ thinking: null
19
+ },
20
+ anthropic: {
21
+ base_url: "https://api.anthropic.com/v1",
22
+ api_key_env: "ANTHROPIC_API_KEY",
23
+ default_model: "claude-opus-4-6",
24
+ models: ["claude-sonnet-4-5", "claude-sonnet-4-6", "claude-haiku-4-5-20251001", "claude-opus-4-6"],
25
+ timeout_ms: 120000,
26
+ stream_idle_timeout_ms: 120000,
27
+ max_tokens: 32768,
28
+ context_limit: null,
29
+ retry_attempts: 3,
30
+ retry_base_delay_ms: 800,
31
+ stream: true,
32
+ thinking: null
33
+ },
34
+ ollama: {
35
+ base_url: "http://localhost:11434",
36
+ api_key_env: "",
37
+ default_model: "llama3.1",
38
+ timeout_ms: 300000,
39
+ stream_idle_timeout_ms: 300000,
40
+ max_tokens: 32768,
41
+ context_limit: null,
42
+ retry_attempts: 1,
43
+ retry_base_delay_ms: 1000,
44
+ stream: true,
45
+ thinking: null
46
+ },
47
+ model_context: {}
48
+ },
49
+ agent: {
50
+ default_mode: "agent",
51
+ max_steps: 8,
52
+ longagent: {
53
+ max_iterations: 0,
54
+ no_progress_warning: 3,
55
+ no_progress_limit: 5,
56
+ max_stage_recoveries: 3,
57
+ heartbeat_timeout_ms: 120000,
58
+ checkpoint_interval: 5,
59
+ lock_timeout_ms: 5000,
60
+ parallel: {
61
+ enabled: true,
62
+ max_concurrency: 3,
63
+ stage_pass_rule: "all_success",
64
+ task_timeout_ms: 600000,
65
+ task_max_retries: 2,
66
+ poll_interval_ms: 300
67
+ },
68
+ planner: {
69
+ intake_questions: {
70
+ enabled: true,
71
+ max_rounds: 6
72
+ },
73
+ ask_user_after_plan_frozen: false
74
+ },
75
+ four_stage: {
76
+ enabled: false,
77
+ preview_max_iterations: 10,
78
+ blueprint_max_iterations: 10,
79
+ coding_max_iterations: 50,
80
+ debugging_max_iterations: 20,
81
+ separate_models: {
82
+ enabled: false,
83
+ preview_model: null,
84
+ blueprint_model: null,
85
+ coding_model: null,
86
+ debugging_model: null
87
+ }
88
+ },
89
+ hybrid: {
90
+ enabled: true,
91
+ intake: true,
92
+ completion_validation: true,
93
+ debugging_max_iterations: 20,
94
+ max_coding_rollbacks: 2,
95
+ parallel_preview: true,
96
+ blueprint_review: false,
97
+ blueprint_validation: true,
98
+ tdd_mode: false,
99
+ cross_review: true,
100
+ incremental_gates: true,
101
+ context_pressure_limit: 8000,
102
+ budget_awareness: true,
103
+ checkpoint_resume: true,
104
+ project_memory: true,
105
+ task_bus: true,
106
+ coding_phase_timeout_ms: 1800000,
107
+ debugging_phase_timeout_ms: 600000,
108
+ checkpoint_max_keep: 10,
109
+ checkpoint_cleanup: true,
110
+ degradation: {
111
+ enabled: true,
112
+ fallback_model: null,
113
+ skip_non_critical: true
114
+ },
115
+ separate_models: {
116
+ enabled: false,
117
+ preview_model: null,
118
+ blueprint_model: null,
119
+ debugging_model: null
120
+ },
121
+ adaptive_models: {
122
+ enabled: false,
123
+ low: null,
124
+ medium: null,
125
+ high: null
126
+ }
127
+ },
128
+ resume_incomplete_files: true,
129
+ scaffold: {
130
+ enabled: true
131
+ },
132
+ git: {
133
+ enabled: "ask",
134
+ auto_branch: true,
135
+ auto_commit_stages: true,
136
+ auto_merge: true,
137
+ branch_prefix: "kkcode"
138
+ },
139
+ usability_gates: {
140
+ prompt_user: "first_run",
141
+ build: { enabled: true },
142
+ test: { enabled: true },
143
+ review: { enabled: true },
144
+ health: { enabled: true },
145
+ budget: { enabled: true }
146
+ }
147
+ },
148
+ subagents: {},
149
+ routing: {
150
+ categories: {}
151
+ }
152
+ },
153
+ mcp: {
154
+ servers: {},
155
+ auto_discover: true,
156
+ timeout_ms: 30000,
157
+ max_reconnect_attempts: 5,
158
+ circuit_reset_ms: 60000,
159
+ health_check_interval_ms: 0,
160
+ max_buffer_bytes: 16777216,
161
+ shutdown_timeout_ms: 5000,
162
+ max_sse_buffer_bytes: 4194304
163
+ },
164
+ skills: {
165
+ enabled: true,
166
+ dirs: [".kkcode/skills"],
167
+ allowed_commands: []
168
+ },
169
+ permission: {
170
+ default_policy: "ask",
171
+ non_tty_default: "deny",
172
+ rules: []
173
+ },
174
+ storage: {
175
+ session_shard_enabled: true,
176
+ flush_interval_ms: 1000,
177
+ event_rotate_mb: 32,
178
+ event_retain_days: 14
179
+ },
180
+ background: {
181
+ mode: "worker_process",
182
+ worker_timeout_ms: 900000,
183
+ max_parallel: 2,
184
+ max_log_lines: 300
185
+ },
186
+ runtime: {
187
+ tool_registry_cache_ttl_ms: 30000,
188
+ mcp_refresh_ttl_ms: 60000
189
+ },
190
+ tool: {
191
+ sources: {
192
+ builtin: true,
193
+ local: true,
194
+ mcp: true,
195
+ plugin: true
196
+ },
197
+ bash_timeout_ms: 120000,
198
+ write_lock: {
199
+ mode: "file_lock",
200
+ wait_timeout_ms: 120000
201
+ },
202
+ local_dirs: [".kkcode/tools", ".kkcode/tool"],
203
+ plugin_dirs: [".kkcode/plugins", ".kkcode/plugin"]
204
+ },
205
+ session: {
206
+ max_history: 30,
207
+ recovery: true,
208
+ compaction_threshold_ratio: 0.7,
209
+ compaction_threshold_messages: 50,
210
+ context_cache_points: true
211
+ },
212
+ review: {
213
+ sort: "risk_first",
214
+ default_lines: 80,
215
+ max_expand_lines: 1200,
216
+ risk_weights: {
217
+ sensitive_path: 4,
218
+ large_change: 3,
219
+ medium_change: 2,
220
+ small_change: 1,
221
+ executable_script: 2,
222
+ command_pattern: 3
223
+ }
224
+ },
225
+ usage: {
226
+ pricing_file: null,
227
+ aggregation: ["turn", "session", "global"],
228
+ budget: {
229
+ session_usd: null,
230
+ global_usd: null,
231
+ warn_at_percent: 80,
232
+ strategy: "warn"
233
+ }
234
+ },
235
+ ui: {
236
+ theme_file: null,
237
+ mode_colors: {
238
+ ask: "#8da3b9",
239
+ plan: "#00b7c2",
240
+ agent: "#2ac26f",
241
+ longagent: "#ff7a33"
242
+ },
243
+ layout: "compact",
244
+ markdown_render: true,
245
+ status: {
246
+ show_cost: true,
247
+ show_token_meter: true
248
+ }
249
+ }
250
+ }
251
+
252
+ export const VALID_PROVIDER_TYPES = ["openai", "anthropic", "ollama", "openai-compatible"]
253
+
254
+ import { listProviders } from "../provider/router.mjs"
255
+ export function getValidProviderTypes() {
256
+ return listProviders()
257
+ }
258
+ export const VALID_MODES = ["ask", "plan", "agent", "longagent"]
259
+ export const VALID_REVIEW_SORT = ["risk_first", "time_order", "file_order"]
260
+ export const VALID_LANGUAGES = ["en", "zh"]