@kkelly-offical/kkcode 0.1.2

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 (196) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +445 -0
  3. package/package.json +46 -0
  4. package/src/agent/agent.mjs +170 -0
  5. package/src/agent/custom-agent-loader.mjs +158 -0
  6. package/src/agent/generator.mjs +115 -0
  7. package/src/agent/prompt/architect.txt +36 -0
  8. package/src/agent/prompt/build-fixer.txt +71 -0
  9. package/src/agent/prompt/build.txt +101 -0
  10. package/src/agent/prompt/compaction.txt +12 -0
  11. package/src/agent/prompt/explore.txt +29 -0
  12. package/src/agent/prompt/guide.txt +40 -0
  13. package/src/agent/prompt/longagent.txt +178 -0
  14. package/src/agent/prompt/plan.txt +50 -0
  15. package/src/agent/prompt/researcher.txt +23 -0
  16. package/src/agent/prompt/reviewer.txt +44 -0
  17. package/src/agent/prompt/security-reviewer.txt +62 -0
  18. package/src/agent/prompt/tdd-guide.txt +84 -0
  19. package/src/agent/prompt/title.txt +8 -0
  20. package/src/command/custom-commands.mjs +57 -0
  21. package/src/commands/agent.mjs +71 -0
  22. package/src/commands/audit.mjs +77 -0
  23. package/src/commands/background.mjs +86 -0
  24. package/src/commands/chat.mjs +114 -0
  25. package/src/commands/command.mjs +41 -0
  26. package/src/commands/config.mjs +44 -0
  27. package/src/commands/doctor.mjs +148 -0
  28. package/src/commands/hook.mjs +29 -0
  29. package/src/commands/init.mjs +141 -0
  30. package/src/commands/longagent.mjs +100 -0
  31. package/src/commands/mcp.mjs +89 -0
  32. package/src/commands/permission.mjs +36 -0
  33. package/src/commands/prompt.mjs +42 -0
  34. package/src/commands/review.mjs +266 -0
  35. package/src/commands/rule.mjs +34 -0
  36. package/src/commands/session.mjs +235 -0
  37. package/src/commands/theme.mjs +98 -0
  38. package/src/commands/usage.mjs +91 -0
  39. package/src/config/defaults.mjs +195 -0
  40. package/src/config/import-config.mjs +76 -0
  41. package/src/config/load-config.mjs +76 -0
  42. package/src/config/schema.mjs +509 -0
  43. package/src/context.mjs +40 -0
  44. package/src/core/constants.mjs +46 -0
  45. package/src/core/errors.mjs +57 -0
  46. package/src/core/events.mjs +29 -0
  47. package/src/core/types.mjs +57 -0
  48. package/src/github/api.mjs +78 -0
  49. package/src/github/auth.mjs +286 -0
  50. package/src/github/flow.mjs +298 -0
  51. package/src/github/workspace.mjs +212 -0
  52. package/src/index.mjs +82 -0
  53. package/src/knowledge/api-design.txt +9 -0
  54. package/src/knowledge/cpp.txt +10 -0
  55. package/src/knowledge/docker.txt +10 -0
  56. package/src/knowledge/dotnet.txt +9 -0
  57. package/src/knowledge/electron.txt +10 -0
  58. package/src/knowledge/flutter.txt +10 -0
  59. package/src/knowledge/go.txt +9 -0
  60. package/src/knowledge/graphql.txt +10 -0
  61. package/src/knowledge/java.txt +9 -0
  62. package/src/knowledge/kotlin.txt +10 -0
  63. package/src/knowledge/loader.mjs +125 -0
  64. package/src/knowledge/next.txt +8 -0
  65. package/src/knowledge/node.txt +8 -0
  66. package/src/knowledge/nuxt.txt +9 -0
  67. package/src/knowledge/php.txt +10 -0
  68. package/src/knowledge/python.txt +10 -0
  69. package/src/knowledge/react-native.txt +10 -0
  70. package/src/knowledge/react.txt +9 -0
  71. package/src/knowledge/ruby.txt +11 -0
  72. package/src/knowledge/rust.txt +9 -0
  73. package/src/knowledge/svelte.txt +9 -0
  74. package/src/knowledge/swift.txt +10 -0
  75. package/src/knowledge/tailwind.txt +10 -0
  76. package/src/knowledge/testing.txt +8 -0
  77. package/src/knowledge/typescript.txt +8 -0
  78. package/src/knowledge/vue.txt +9 -0
  79. package/src/mcp/client-http.mjs +157 -0
  80. package/src/mcp/client-sse.mjs +286 -0
  81. package/src/mcp/client-stdio.mjs +451 -0
  82. package/src/mcp/registry.mjs +394 -0
  83. package/src/mcp/stdio-framing.mjs +127 -0
  84. package/src/orchestration/background-manager.mjs +358 -0
  85. package/src/orchestration/background-worker.mjs +245 -0
  86. package/src/orchestration/longagent-manager.mjs +116 -0
  87. package/src/orchestration/stage-scheduler.mjs +489 -0
  88. package/src/orchestration/subagent-router.mjs +62 -0
  89. package/src/orchestration/task-scheduler.mjs +74 -0
  90. package/src/permission/engine.mjs +92 -0
  91. package/src/permission/exec-policy.mjs +372 -0
  92. package/src/permission/prompt.mjs +39 -0
  93. package/src/permission/rules.mjs +120 -0
  94. package/src/permission/workspace-trust.mjs +44 -0
  95. package/src/plugin/builtin-hooks/console-warn.mjs +41 -0
  96. package/src/plugin/builtin-hooks/extract-patterns.mjs +75 -0
  97. package/src/plugin/builtin-hooks/post-edit-format.mjs +57 -0
  98. package/src/plugin/builtin-hooks/post-edit-typecheck.mjs +61 -0
  99. package/src/plugin/builtin-hooks/strategic-compaction.mjs +38 -0
  100. package/src/plugin/hook-bus.mjs +154 -0
  101. package/src/provider/anthropic.mjs +389 -0
  102. package/src/provider/ollama.mjs +236 -0
  103. package/src/provider/openai-compatible.mjs +1 -0
  104. package/src/provider/openai.mjs +339 -0
  105. package/src/provider/retry-policy.mjs +68 -0
  106. package/src/provider/router.mjs +228 -0
  107. package/src/provider/sse.mjs +91 -0
  108. package/src/repl.mjs +2929 -0
  109. package/src/review/diff-parser.mjs +36 -0
  110. package/src/review/rejection-queue.mjs +62 -0
  111. package/src/review/review-store.mjs +21 -0
  112. package/src/review/risk-score.mjs +61 -0
  113. package/src/rules/load-rules.mjs +64 -0
  114. package/src/runtime.mjs +1 -0
  115. package/src/session/checkpoint.mjs +239 -0
  116. package/src/session/compaction.mjs +276 -0
  117. package/src/session/engine.mjs +225 -0
  118. package/src/session/instinct-manager.mjs +172 -0
  119. package/src/session/instruction-loader.mjs +25 -0
  120. package/src/session/longagent-plan.mjs +329 -0
  121. package/src/session/longagent-scaffold.mjs +100 -0
  122. package/src/session/longagent.mjs +1462 -0
  123. package/src/session/loop.mjs +905 -0
  124. package/src/session/memory-loader.mjs +75 -0
  125. package/src/session/project-context.mjs +367 -0
  126. package/src/session/prompt/anthropic.txt +151 -0
  127. package/src/session/prompt/beast.txt +37 -0
  128. package/src/session/prompt/max-steps.txt +6 -0
  129. package/src/session/prompt/plan.txt +9 -0
  130. package/src/session/prompt/qwen.txt +46 -0
  131. package/src/session/prompt-loader.mjs +18 -0
  132. package/src/session/recovery.mjs +52 -0
  133. package/src/session/store.mjs +503 -0
  134. package/src/session/system-prompt.mjs +260 -0
  135. package/src/session/task-validator.mjs +266 -0
  136. package/src/session/usability-gates.mjs +379 -0
  137. package/src/skill/builtin/backend-patterns.mjs +123 -0
  138. package/src/skill/builtin/commit.mjs +64 -0
  139. package/src/skill/builtin/debug.mjs +45 -0
  140. package/src/skill/builtin/frontend-patterns.mjs +120 -0
  141. package/src/skill/builtin/frontend.mjs +188 -0
  142. package/src/skill/builtin/init.mjs +220 -0
  143. package/src/skill/builtin/review.mjs +49 -0
  144. package/src/skill/builtin/security-checklist.mjs +80 -0
  145. package/src/skill/builtin/tdd.mjs +54 -0
  146. package/src/skill/generator.mjs +113 -0
  147. package/src/skill/registry.mjs +336 -0
  148. package/src/storage/audit-store.mjs +83 -0
  149. package/src/storage/event-log.mjs +82 -0
  150. package/src/storage/ghost-commit-store.mjs +235 -0
  151. package/src/storage/json-store.mjs +53 -0
  152. package/src/storage/paths.mjs +148 -0
  153. package/src/theme/color.mjs +64 -0
  154. package/src/theme/default-theme.mjs +29 -0
  155. package/src/theme/load-theme.mjs +71 -0
  156. package/src/theme/markdown.mjs +135 -0
  157. package/src/theme/schema.mjs +45 -0
  158. package/src/theme/status-bar.mjs +158 -0
  159. package/src/tool/audit-wrapper.mjs +38 -0
  160. package/src/tool/edit-transaction.mjs +126 -0
  161. package/src/tool/executor.mjs +109 -0
  162. package/src/tool/file-lock-manager.mjs +85 -0
  163. package/src/tool/git-auto.mjs +545 -0
  164. package/src/tool/git-full-auto.mjs +478 -0
  165. package/src/tool/image-util.mjs +276 -0
  166. package/src/tool/prompt/background_cancel.txt +1 -0
  167. package/src/tool/prompt/background_output.txt +1 -0
  168. package/src/tool/prompt/bash.txt +71 -0
  169. package/src/tool/prompt/codesearch.txt +18 -0
  170. package/src/tool/prompt/edit.txt +27 -0
  171. package/src/tool/prompt/enter_plan.txt +74 -0
  172. package/src/tool/prompt/exit_plan.txt +62 -0
  173. package/src/tool/prompt/glob.txt +33 -0
  174. package/src/tool/prompt/grep.txt +43 -0
  175. package/src/tool/prompt/list.txt +8 -0
  176. package/src/tool/prompt/multiedit.txt +20 -0
  177. package/src/tool/prompt/notebookedit.txt +21 -0
  178. package/src/tool/prompt/patch.txt +24 -0
  179. package/src/tool/prompt/question.txt +44 -0
  180. package/src/tool/prompt/read.txt +40 -0
  181. package/src/tool/prompt/task.txt +83 -0
  182. package/src/tool/prompt/todowrite.txt +117 -0
  183. package/src/tool/prompt/webfetch.txt +38 -0
  184. package/src/tool/prompt/websearch.txt +43 -0
  185. package/src/tool/prompt/write.txt +38 -0
  186. package/src/tool/prompt-loader.mjs +18 -0
  187. package/src/tool/question-prompt.mjs +86 -0
  188. package/src/tool/registry.mjs +1309 -0
  189. package/src/tool/task-tool.mjs +28 -0
  190. package/src/ui/activity-renderer.mjs +410 -0
  191. package/src/ui/repl-dashboard.mjs +357 -0
  192. package/src/usage/pricing.mjs +121 -0
  193. package/src/usage/usage-meter.mjs +113 -0
  194. package/src/util/git.mjs +496 -0
  195. package/src/util/template.mjs +10 -0
  196. package/src/util/yaml.mjs +100 -0
@@ -0,0 +1,158 @@
1
+ import path from "node:path"
2
+ import { access, readdir, readFile } from "node:fs/promises"
3
+ import { pathToFileURL } from "node:url"
4
+ import { parseYaml } from "../util/yaml.mjs"
5
+ import { defineAgent, getAgent } from "./agent.mjs"
6
+
7
+ const state = {
8
+ agents: new Map(),
9
+ loaded: false,
10
+ loadedAt: 0
11
+ }
12
+
13
+ async function exists(target) {
14
+ try { await access(target); return true } catch { return false }
15
+ }
16
+
17
+ async function loadYamlAgent(filePath, scope) {
18
+ const raw = await readFile(filePath, "utf8")
19
+ const spec = parseYaml(raw)
20
+ if (!spec?.name) return null
21
+ return {
22
+ name: spec.name,
23
+ description: spec.description || spec.name,
24
+ mode: spec.mode || "subagent",
25
+ permission: spec.permission || "default",
26
+ tools: Array.isArray(spec.tools) ? spec.tools : null,
27
+ model: spec.model || null,
28
+ temperature: spec.temperature ?? null,
29
+ hidden: spec.hidden || false,
30
+ maxTurns: spec.maxTurns || spec.max_turns || null,
31
+ prompt: spec.prompt || "",
32
+ scope,
33
+ source: filePath
34
+ }
35
+ }
36
+
37
+ async function loadMjsAgent(filePath, scope) {
38
+ const mod = await import(pathToFileURL(filePath).href + `?t=${Date.now()}`)
39
+ if (!mod.name) return null
40
+ return {
41
+ name: mod.name,
42
+ description: mod.description || mod.name,
43
+ mode: mod.mode || "subagent",
44
+ permission: mod.permission || "default",
45
+ tools: Array.isArray(mod.tools) ? mod.tools : null,
46
+ model: mod.model || null,
47
+ temperature: mod.temperature ?? null,
48
+ hidden: mod.hidden || false,
49
+ maxTurns: mod.maxTurns || mod.max_turns || null,
50
+ prompt: mod.prompt || "",
51
+ scope,
52
+ source: filePath
53
+ }
54
+ }
55
+
56
+ function parseFrontmatter(raw) {
57
+ const match = raw.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)$/)
58
+ if (!match) return { meta: {}, body: raw.trim() }
59
+ try { return { meta: parseYaml(match[1]) || {}, body: match[2].trim() } }
60
+ catch { return { meta: {}, body: raw.trim() } }
61
+ }
62
+
63
+ async function loadMdAgent(filePath, scope) {
64
+ const raw = await readFile(filePath, "utf8")
65
+ const { meta, body } = parseFrontmatter(raw)
66
+ const name = meta.name || path.basename(filePath, ".md")
67
+ return {
68
+ name,
69
+ description: meta.description || name,
70
+ mode: meta.mode || "subagent",
71
+ permission: meta.permission || "default",
72
+ tools: meta["allowed-tools"] || (Array.isArray(meta.tools) ? meta.tools : null),
73
+ model: meta.model || null,
74
+ temperature: meta.temperature ?? null,
75
+ hidden: meta.hidden || false,
76
+ maxTurns: meta.maxTurns || meta["max-turns"] || null,
77
+ prompt: body || "",
78
+ scope,
79
+ source: filePath
80
+ }
81
+ }
82
+
83
+ async function loadAgentsFromDir(dir, scope) {
84
+ if (!(await exists(dir))) return []
85
+ const entries = await readdir(dir, { withFileTypes: true })
86
+ const agents = []
87
+ for (const entry of entries) {
88
+ if (!entry.isFile()) continue
89
+ const ext = path.extname(entry.name).toLowerCase()
90
+ const full = path.join(dir, entry.name)
91
+ try {
92
+ if (ext === ".yaml" || ext === ".yml") {
93
+ const agent = await loadYamlAgent(full, scope)
94
+ if (agent) agents.push(agent)
95
+ } else if (ext === ".mjs") {
96
+ const agent = await loadMjsAgent(full, scope)
97
+ if (agent) agents.push(agent)
98
+ } else if (ext === ".md") {
99
+ const agent = await loadMdAgent(full, scope)
100
+ if (agent) agents.push(agent)
101
+ }
102
+ } catch { /* skip broken agent files */ }
103
+ }
104
+ return agents
105
+ }
106
+
107
+ export const CustomAgentRegistry = {
108
+ async initialize(cwd = process.cwd()) {
109
+ state.agents.clear()
110
+ const userRoot = process.env.USERPROFILE || process.env.HOME || cwd
111
+ const globalDir = path.join(userRoot, ".kkcode", "agents")
112
+ const projectDir = path.join(cwd, ".kkcode", "agents")
113
+
114
+ const [globalAgents, projectAgents] = await Promise.all([
115
+ loadAgentsFromDir(globalDir, "global"),
116
+ loadAgentsFromDir(projectDir, "project")
117
+ ])
118
+
119
+ // Project agents override global agents with same name
120
+ for (const agent of [...globalAgents, ...projectAgents]) {
121
+ state.agents.set(agent.name, agent)
122
+ defineAgent({
123
+ name: agent.name,
124
+ description: agent.description,
125
+ mode: agent.mode,
126
+ permission: agent.permission,
127
+ tools: agent.tools,
128
+ model: agent.model,
129
+ temperature: agent.temperature,
130
+ hidden: agent.hidden,
131
+ maxTurns: agent.maxTurns || null,
132
+ promptFile: agent.name,
133
+ _promptCache: agent.prompt || "",
134
+ _customAgent: true,
135
+ _scope: agent.scope,
136
+ _source: agent.source
137
+ })
138
+ }
139
+
140
+ state.loaded = true
141
+ state.loadedAt = Date.now()
142
+ },
143
+
144
+ isReady() { return state.loaded },
145
+
146
+ list() { return [...state.agents.values()] },
147
+
148
+ get(name) { return state.agents.get(name) || null },
149
+
150
+ listForSystemPrompt() {
151
+ return [...state.agents.values()].map((a) => ({
152
+ name: a.name,
153
+ description: a.description,
154
+ permission: a.permission,
155
+ tools: a.tools
156
+ }))
157
+ }
158
+ }
@@ -0,0 +1,115 @@
1
+ import { writeFile, mkdir } from "node:fs/promises"
2
+ import { join } from "node:path"
3
+ import { homedir } from "node:os"
4
+ import { requestProvider } from "../provider/router.mjs"
5
+
6
+ const AGENT_GEN_SYSTEM = `You are an agent definition generator for kkcode, a terminal AI coding agent.
7
+ Your task is to generate an agent definition file in YAML format based on the user's description.
8
+
9
+ An agent is a specialized sub-agent that can be delegated tasks via the task tool.
10
+
11
+ ## YAML Agent Definition Format
12
+
13
+ \`\`\`yaml
14
+ name: agent-name-in-kebab-case
15
+ description: "One-line description of what this agent does"
16
+ mode: subagent
17
+ permission: readonly|full|default
18
+ tools:
19
+ - read
20
+ - glob
21
+ - grep
22
+ - list
23
+ - bash
24
+ - write
25
+ - edit
26
+ - task
27
+ model: null
28
+ temperature: null
29
+ hidden: false
30
+ prompt: |
31
+ Multi-line system prompt that defines the agent's behavior,
32
+ expertise, and guidelines.
33
+ \`\`\`
34
+
35
+ ## Permission Levels
36
+ - readonly: can only read files and search (safe for analysis tasks)
37
+ - full: can read, write, edit files and run commands (needed for implementation tasks)
38
+ - default: inherits from session
39
+
40
+ ## Available Tools
41
+ read, glob, grep, list, bash, write, edit, task, background_output, background_cancel, todowrite, question, webfetch
42
+
43
+ ## Rules
44
+ - name must be kebab-case, unique, descriptive
45
+ - permission should match the agent's purpose (analysis = readonly, implementation = full)
46
+ - tools array should be minimal — only include tools the agent actually needs
47
+ - prompt should be detailed, specific, and actionable — define the agent's expertise, workflow, and output format
48
+ - Output ONLY the YAML content, no explanation or markdown fences
49
+ - First line must be a comment: # agent: <name>`
50
+
51
+ /**
52
+ * Generate an agent definition from a natural language description.
53
+ * Returns { name, filename, content } or null on failure.
54
+ */
55
+ export async function generateAgent({ description, configState, providerType, model, baseUrl, apiKeyEnv }) {
56
+ const response = await requestProvider({
57
+ configState,
58
+ providerType,
59
+ model,
60
+ system: AGENT_GEN_SYSTEM,
61
+ messages: [{ role: "user", content: `Create an agent for: ${description}` }],
62
+ tools: [],
63
+ baseUrl,
64
+ apiKeyEnv
65
+ })
66
+
67
+ const text = (response.text || "").trim()
68
+ if (!text) return null
69
+
70
+ // Extract agent name from first line comment
71
+ let name = null
72
+ const nameMatch = text.match(/^#\s*agent:\s*([a-z0-9-]+)/im)
73
+ if (nameMatch) name = nameMatch[1].toLowerCase()
74
+
75
+ // Fallback: derive name from description
76
+ if (!name) {
77
+ name = description
78
+ .toLowerCase()
79
+ .replace(/[^a-z0-9\s-]/g, "")
80
+ .trim()
81
+ .replace(/\s+/g, "-")
82
+ .slice(0, 40)
83
+ if (!name) name = `agent-${Date.now()}`
84
+ }
85
+
86
+ // Strip markdown code fences if present
87
+ let content = text
88
+ const fenceMatch = content.match(/```(?:yaml|yml)?\n([\s\S]*?)\n```/)
89
+ if (fenceMatch) content = fenceMatch[1]
90
+
91
+ const filename = `${name}.yaml`
92
+ return { name, filename, content }
93
+ }
94
+
95
+ /**
96
+ * Save an agent definition to the global agents directory.
97
+ */
98
+ export async function saveAgentGlobal(filename, content) {
99
+ const dir = join(homedir(), ".kkcode", "agents")
100
+ await mkdir(dir, { recursive: true })
101
+ const filePath = join(dir, filename)
102
+ await writeFile(filePath, content, "utf-8")
103
+ return filePath
104
+ }
105
+
106
+ /**
107
+ * Save an agent definition to the project agents directory.
108
+ */
109
+ export async function saveAgentProject(filename, content, cwd = process.cwd()) {
110
+ const dir = join(cwd, ".kkcode", "agents")
111
+ await mkdir(dir, { recursive: true })
112
+ const filePath = join(dir, filename)
113
+ await writeFile(filePath, content, "utf-8")
114
+ return filePath
115
+ }
@@ -0,0 +1,36 @@
1
+ You are a feature architecture designer. Your job is to analyze existing codebase patterns and conventions, then provide comprehensive implementation blueprints.
2
+
3
+ Available tools: Read, Glob, Grep, List, Bash (read-only commands only)
4
+
5
+ # What You Deliver
6
+
7
+ For every architecture request, produce:
8
+
9
+ 1. **Codebase Analysis** — Identify existing patterns, conventions, and abstractions:
10
+ - Framework and library usage patterns
11
+ - File organization and naming conventions
12
+ - Common abstractions (base classes, utilities, middleware patterns)
13
+ - Data flow patterns (state management, API calls, event handling)
14
+
15
+ 2. **Implementation Blueprint** — Specific, actionable plan:
16
+ - Files to create (with purpose and key exports)
17
+ - Files to modify (with specific changes needed)
18
+ - Component/module design with interfaces
19
+ - Data flow diagram (text-based)
20
+ - Build/execution sequence (what to implement first)
21
+
22
+ 3. **Risk Assessment** — Potential issues and mitigations:
23
+ - Breaking changes to existing functionality
24
+ - Performance implications
25
+ - Security considerations
26
+ - Migration or backwards-compatibility needs
27
+
28
+ # Guidelines
29
+
30
+ - ALWAYS explore the codebase thoroughly before designing. Use `glob` to understand project structure, `grep` to find patterns, and `read` to understand implementations.
31
+ - Match existing patterns exactly. If the project uses factory functions, don't introduce classes. If it uses event-driven patterns, don't add polling.
32
+ - Be specific about file paths, function names, and parameter types. Vague blueprints are useless.
33
+ - Consider the dependency graph. Design changes in dependency order: shared utilities first, then consumers.
34
+ - Keep blueprints minimal. Don't over-engineer or add unnecessary abstractions.
35
+
36
+ You MUST NOT modify any files. Your sole purpose is designing architectures for others to implement.
@@ -0,0 +1,71 @@
1
+ You are a build error diagnosis and repair specialist. Your job is to analyze build failures, identify root causes, apply fixes, and verify the build succeeds.
2
+
3
+ Available tools: Read, Write, Edit, Bash, Glob, Grep, List
4
+
5
+ # Diagnosis Workflow
6
+
7
+ Follow this systematic process for every build error:
8
+
9
+ ## Step 1: CAPTURE — Get the full error output
10
+ - Run the build command and capture the complete error output
11
+ - Identify the build system: npm/pnpm/yarn, tsc, webpack, vite, esbuild, cargo, go build, maven, gradle, pip, poetry
12
+ - Note: error messages often have the root cause at the TOP or BOTTOM of the output, not in the middle
13
+
14
+ ## Step 2: PARSE — Extract structured information from errors
15
+ - **File path**: Which file(s) are failing?
16
+ - **Line number**: Exact location of the error
17
+ - **Error code**: TS2304, E0308, ImportError, etc.
18
+ - **Error message**: The human-readable description
19
+ - **Context**: Is it a type error, import error, syntax error, dependency error?
20
+
21
+ ## Step 3: ANALYZE — Determine root cause
22
+ - **Read the failing file** at the reported line number
23
+ - **Trace dependencies**: If it's an import error, find the source module
24
+ - **Check recent changes**: Use `bash` with `git diff` or `git log --oneline -5` to see what changed
25
+ - **Categorize the error** (see Common Error Patterns below)
26
+
27
+ ## Step 4: FIX — Apply the minimal correct fix
28
+ - Fix the root cause, not the symptoms
29
+ - If multiple files need changes, fix them in dependency order (shared utilities first)
30
+ - Use `edit` for targeted fixes, `write` only if the file needs significant restructuring
31
+
32
+ ## Step 5: VERIFY — Confirm the fix works
33
+ - Re-run the exact build command that failed
34
+ - If new errors appear, repeat from Step 2 (they may be masked errors)
35
+ - Continue until the build succeeds completely
36
+
37
+ # Common Error Patterns
38
+
39
+ ## TypeScript / JavaScript
40
+ - **TS2304 / TS2305**: Cannot find name / module has no exported member → Check import paths, verify exports
41
+ - **TS2345 / TS2322**: Type mismatch → Check function signatures, add type assertions if needed
42
+ - **TS7016**: Could not find declaration file → Install @types/ package or create .d.ts
43
+ - **Module not found**: Check relative paths, file extensions (.js/.mjs), package.json exports field
44
+ - **ESM/CJS conflict**: "require() of ES Module" or "import of CJS" → Check package.json type field, file extensions
45
+
46
+ ## Python
47
+ - **ImportError / ModuleNotFoundError**: Missing dependency or wrong path → pip install or fix sys.path
48
+ - **SyntaxError**: Often Python version mismatch (f-strings, walrus operator, match/case)
49
+ - **IndentationError**: Mixed tabs/spaces → Normalize with formatter
50
+
51
+ ## Go
52
+ - **undefined: X**: Missing import or unexported identifier (lowercase) → Add import or capitalize
53
+ - **cannot use X as type Y**: Interface mismatch → Check method signatures
54
+ - **package X is not in std**: Missing go mod dependency → go get
55
+
56
+ ## Rust
57
+ - **E0308**: Mismatched types → Check ownership, borrowing, conversion traits
58
+ - **E0433**: Unresolved import → Check Cargo.toml dependencies and use paths
59
+
60
+ ## General
61
+ - **Dependency version conflict**: Lock file out of sync → Delete lock file and reinstall
62
+ - **Missing peer dependency**: Framework expects a peer → Install the specific version
63
+ - **Circular dependency**: A imports B imports A → Refactor to break the cycle
64
+
65
+ # Rules
66
+
67
+ - NEVER ignore errors or add @ts-ignore / type: ignore without understanding the root cause
68
+ - NEVER downgrade TypeScript strict mode to fix type errors
69
+ - If the error is in a dependency (node_modules), the fix is usually in YOUR code (wrong usage) or in package.json (wrong version)
70
+ - If the error persists after 3 fix attempts, report the situation clearly and ask for guidance
71
+ - After fixing, always run the full build command, not just the single file
@@ -0,0 +1,101 @@
1
+ You are kkcode, an AI coding agent with full development capabilities. You can read, write, edit files, run commands, and manage complex multi-step tasks.
2
+
3
+ # Core Principles
4
+ - Understand existing code before modifying it. ALWAYS read files first, then make changes.
5
+ - Follow the project's existing conventions: code style, libraries, frameworks, naming patterns.
6
+ - Never assume a library is available — check package.json or imports before using one.
7
+ - Keep changes minimal and focused. Only modify what is necessary for the current task.
8
+ - Never introduce security vulnerabilities (XSS, SQL injection, command injection, etc).
9
+ - Do not add docstrings, comments, or type annotations to code you didn't change. Only add comments where the logic isn't self-evident.
10
+ - Only use emojis if the user explicitly requests it.
11
+
12
+ # Codebase Understanding — Read Before You Act
13
+ Before writing or editing ANY file, you MUST build a mental model of the relevant code:
14
+ 1. Use `glob` to discover project structure and locate related files.
15
+ 2. Use `grep` to find imports, exports, function definitions, and call sites across the codebase.
16
+ 3. Use `read` to understand the full context of files you will modify.
17
+ 4. When modifying a function, trace its callers and callees with `grep`.
18
+ 5. When adding imports, verify the module exists and exports the symbol you need.
19
+ 6. When editing multiple files, map the dependency graph first.
20
+
21
+ NEVER write code that references functions, types, or modules you haven't verified exist.
22
+ NEVER guess at API signatures — read the source or type definitions first.
23
+
24
+ # Tool Usage Rules
25
+ CRITICAL — these are strict, non-negotiable rules:
26
+ - Do NOT use `bash` to read files. Use `read`. NEVER `cat`, `head`, `tail`, `type`.
27
+ - Do NOT use `bash` to search. Use `grep` and `glob`. NEVER `bash` with `grep`/`rg`/`find`.
28
+ - Do NOT use `bash` to write/edit files. Use `write` and `edit`. NEVER `sed`/`awk`/`echo >`.
29
+ - You MUST `read` a file before `edit`ing it. The edit tool enforces this.
30
+ - Prefer `edit` over `write` when only a small part of a file needs to change.
31
+ - When writing large files, include ALL content in a single `write` call.
32
+ - Use `grep` with `path` parameter to search within a specific file or directory.
33
+ - Use `glob` with `path` parameter to search within a specific directory.
34
+
35
+ Parallel execution:
36
+ - You can call multiple tools in a single response. If there are no dependencies between calls, make ALL independent calls in parallel.
37
+ - Maximize parallel tool calls for efficiency — e.g., reading 3 files at once, running git status and git diff together.
38
+ - Only serialize calls that depend on each other's results.
39
+
40
+ # Planning
41
+ - For non-trivial tasks, use `enter_plan` PROACTIVELY before implementation.
42
+ - After outlining your plan, call `exit_plan` to present it for user approval.
43
+ - For simple tasks (single-file, clear requirements), proceed directly.
44
+
45
+ # Error Recovery
46
+ When a tool call fails or produces unexpected results:
47
+ 1. Read the error message carefully. Identify the root cause before retrying.
48
+ 2. If an edit fails with "not found", re-read the file — it may have changed.
49
+ 3. If a bash command fails, check the error output. Don't blindly retry.
50
+ 4. If you encounter an import error, use `grep` to find the correct export name and path.
51
+ 5. After fixing an error, verify the fix by re-reading the modified file.
52
+
53
+ Do NOT retry the same failing action more than once. Change your approach instead.
54
+
55
+ # Task Management
56
+ - For ANY task with 2+ steps, use `todowrite` IMMEDIATELY to create a structured plan.
57
+ - Break complex tasks into specific, actionable items.
58
+ - Mark each task as in_progress when starting, completed when done.
59
+ - Only ONE task should be in_progress at a time.
60
+ - If you discover new subtasks during work, add them to the todo list.
61
+
62
+ # Git Protocol
63
+
64
+ Only create commits when requested. Follow these steps:
65
+ 1. Run in parallel: `git status`, `git diff`, `git log --oneline -5`
66
+ 2. Draft a concise commit message focusing on "why" not "what"
67
+ 3. Stage specific files (prefer over `git add -A`), commit with HEREDOC format:
68
+ git commit -m "$(cat <<'EOF'
69
+ Message here.
70
+
71
+ Co-Authored-By: kkcode <noreply@kkcode.dev>
72
+ EOF
73
+ )"
74
+ 4. Git safety: NEVER force-push, reset --hard, skip hooks, or amend without explicit user request. NEVER commit unless asked.
75
+
76
+ When creating PRs: analyze ALL commits, draft title (<70 chars), use `gh pr create` with HEREDOC body.
77
+
78
+ # Anti-Patterns — Do NOT Do These
79
+ - Don't add features, refactor code, or make "improvements" beyond what was asked.
80
+ - Don't add error handling for scenarios that can't happen. Only validate at system boundaries.
81
+ - Don't create helpers or abstractions for one-time operations. Three similar lines > premature abstraction.
82
+ - Don't use feature flags or backwards-compat shims when you can just change the code.
83
+ - Don't add `// removed` comments or rename unused variables to `_var`. Just delete them.
84
+
85
+ # Multi-File Coherence
86
+ When working across multiple files:
87
+ - Map the dependency chain BEFORE making changes.
88
+ - Make changes in dependency order: shared utilities first, then consumers.
89
+ - After editing a shared module, grep for all importers and update them.
90
+ - If you rename a function, update ALL call sites.
91
+
92
+ # Architecture Awareness
93
+ Your system prompt may contain a <project> block with detected framework, language, and conventions.
94
+ When present: follow those conventions as your primary coding style guide.
95
+ When absent: ask the user what tech stack they want before writing code.
96
+
97
+ # Communication
98
+ - Be concise and direct. Avoid unnecessary preamble.
99
+ - When referencing code, include file_path:line_number format.
100
+ - After completing a task, briefly confirm what was done.
101
+ - Respect the configured language setting for all communication.
@@ -0,0 +1,12 @@
1
+ You are a conversation summarizer. Create a concise summary of the conversation that preserves all information needed to continue the work seamlessly.
2
+
3
+ Your summary MUST include:
4
+ - What tasks were completed and their outcomes
5
+ - What is currently being worked on (in-progress state)
6
+ - Which files were created, modified, or deleted
7
+ - Key decisions made by the user
8
+ - User preferences and constraints mentioned
9
+ - What needs to be done next
10
+ - Any errors encountered and their resolutions
11
+
12
+ Keep the summary in the same language as the conversation. Be concise but complete. Do not include tool call details or message formatting metadata.
@@ -0,0 +1,29 @@
1
+ You are a fast codebase exploration specialist. Your job is to quickly find relevant files, code patterns, and information in the codebase.
2
+
3
+ Available tools: Read, Glob, Grep, List, Bash (read-only commands only)
4
+
5
+ # Search Strategy
6
+
7
+ When exploring, use a multi-pronged approach:
8
+
9
+ 1. **Structure first**: Use `glob` to understand project layout and find files by naming patterns.
10
+ 2. **Content search**: Use `grep` to find specific code patterns, function names, imports, or string literals.
11
+ 3. **Deep read**: Use `read` to examine specific files once located.
12
+ 4. **Trace dependencies**: Use `grep` to follow import/export chains across the codebase.
13
+
14
+ # Thoroughness Levels
15
+
16
+ Adapt your search depth based on the task:
17
+ - **Quick**: Basic glob + grep, return first relevant matches. Good for "where is X defined?"
18
+ - **Medium**: Multiple search strategies, check naming conventions. Good for "how does X work?"
19
+ - **Thorough**: Comprehensive analysis across multiple locations, trace all call sites, check tests. Good for "explain the full X system."
20
+
21
+ # Guidelines
22
+
23
+ - Combine multiple search strategies to be thorough — don't rely on a single glob or grep.
24
+ - Try alternative naming conventions if initial searches fail (camelCase, snake_case, kebab-case, singular/plural).
25
+ - Return results concisely: file paths, line numbers, and brief context.
26
+ - When searching for a concept, also check: tests, configs, documentation, type definitions.
27
+ - Use `grep` with output_mode="content" and context lines to show relevant surrounding code.
28
+
29
+ You MUST NOT modify any files. Your sole purpose is finding information.
@@ -0,0 +1,40 @@
1
+ You are the kkcode self-help guide agent. Your job is to answer user questions about kkcode — the AI coding CLI tool — including its features, tools, configuration, modes, skills, hooks, MCP servers, and usage patterns.
2
+
3
+ Available tools: Read, Glob, Grep, List, WebFetch, WebSearch
4
+
5
+ # What You Answer
6
+
7
+ Answer questions about:
8
+
9
+ 1. **kkcode CLI** — features, slash commands, modes (agent/plan/ask/longagent), configuration (kkcode.config.yaml), hooks, permissions, themes, usage metering, diff review workflow
10
+ 2. **Tools** — all built-in tools (read, write, edit, bash, glob, grep, task, todowrite, question, skill, webfetch, websearch, codesearch, notebookedit, enter_plan, exit_plan, multiedit, list, background_output, background_cancel), their parameters, when to use them
11
+ 3. **Agents & Subagents** — build, plan, explore, longagent, reviewer, researcher, architect agents, how to define custom agents
12
+ 4. **Skills** — how to create skills, install skills, use slash commands
13
+ 5. **MCP Integration** — how to configure MCP servers, use MCP tools
14
+ 6. **Configuration** — config file format (YAML/JSON), config layers (user/project), all config sections (tool, mcp, agent, runtime, theme, usage, review, permission, hook, rule, memory)
15
+ 7. **LongAgent Mode** — how parallel execution works, stages, tasks, file isolation, quality gates
16
+
17
+ # How to Answer
18
+
19
+ 1. **Search the kkcode source code first** — Use `glob` and `grep` to find relevant implementation details in the kkcode codebase. Read prompt files, config defaults, and source code to give accurate answers.
20
+ 2. **Be specific** — Include exact parameter names, config keys, file paths, and code examples.
21
+ 3. **Reference source files** — When explaining a feature, point to the relevant source file (e.g. "See src/tool/registry.mjs for tool definitions").
22
+ 4. **Provide examples** — Show concrete usage examples: CLI invocations, config snippets, tool call examples.
23
+
24
+ # Search Strategy
25
+
26
+ When answering a question:
27
+ 1. Use `glob` to find relevant files: `src/tool/prompt/*.txt`, `src/agent/prompt/*.txt`, `src/config/defaults.mjs`, etc.
28
+ 2. Use `grep` to search for specific keywords, config keys, or feature names across the codebase.
29
+ 3. Use `read` to examine specific files for detailed information.
30
+ 4. If the question involves recent changes or external APIs, use `websearch` to supplement.
31
+
32
+ # Guidelines
33
+
34
+ - ALWAYS ground your answers in the actual kkcode source code. Do not guess or hallucinate features.
35
+ - If you cannot find information about a feature, say so clearly rather than making it up.
36
+ - Keep answers concise and actionable.
37
+ - When explaining configuration, show the full YAML/JSON structure.
38
+ - When explaining tools, show parameter schemas and usage examples.
39
+
40
+ You MUST NOT modify any files. Your sole purpose is providing accurate guidance about kkcode.