@kkelly-offical/kkcode 0.1.6 → 0.2.1
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 +674 -674
- package/README.md +452 -387
- package/package.json +50 -46
- package/src/agent/agent.mjs +19 -2
- package/src/agent/custom-agent-loader.mjs +6 -3
- package/src/agent/generator.mjs +2 -2
- package/src/agent/prompt/assistant.txt +12 -0
- package/src/agent/prompt/bug-hunter.txt +90 -0
- package/src/agent/prompt/frontend-designer.txt +58 -58
- package/src/agent/prompt/guide.txt +1 -1
- package/src/agent/prompt/longagent-blueprint-agent.txt +83 -83
- package/src/agent/prompt/longagent-coding-agent.txt +37 -37
- package/src/agent/prompt/longagent-debugging-agent.txt +46 -46
- package/src/agent/prompt/longagent-preview-agent.txt +63 -63
- package/src/command/custom-commands.mjs +2 -2
- package/src/commands/agent.mjs +1 -1
- package/src/commands/background.mjs +145 -4
- package/src/commands/chat.mjs +117 -76
- package/src/commands/config.mjs +148 -1
- package/src/commands/doctor.mjs +30 -6
- package/src/commands/init.mjs +32 -6
- package/src/commands/longagent.mjs +117 -0
- package/src/commands/mcp.mjs +275 -43
- package/src/commands/permission.mjs +1 -1
- package/src/commands/session.mjs +195 -140
- package/src/commands/skill.mjs +63 -0
- package/src/commands/theme.mjs +1 -1
- package/src/config/defaults.mjs +280 -260
- package/src/config/import-config.mjs +1 -1
- package/src/config/load-config.mjs +61 -4
- package/src/config/schema.mjs +591 -574
- package/src/context.mjs +4 -1
- package/src/core/constants.mjs +97 -91
- package/src/core/types.mjs +1 -1
- package/src/github/api.mjs +78 -78
- package/src/github/auth.mjs +294 -286
- package/src/github/flow.mjs +298 -298
- package/src/github/workspace.mjs +225 -212
- package/src/index.mjs +84 -82
- package/src/knowledge/frontend-aesthetics.txt +38 -38
- package/src/mcp/client-http.mjs +139 -141
- package/src/mcp/client-sse.mjs +297 -288
- package/src/mcp/client-stdio.mjs +534 -533
- package/src/mcp/constants.mjs +2 -2
- package/src/mcp/registry.mjs +498 -479
- package/src/mcp/stdio-framing.mjs +135 -133
- package/src/mcp/tool-result.mjs +24 -24
- package/src/observability/edit-diagnostics.mjs +449 -0
- package/src/observability/index.mjs +42 -42
- package/src/observability/metrics.mjs +165 -137
- package/src/observability/tracer.mjs +137 -137
- package/src/onboarding.mjs +209 -0
- package/src/orchestration/background-manager.mjs +567 -372
- package/src/orchestration/background-worker.mjs +419 -305
- package/src/orchestration/interruption-reason.mjs +21 -0
- package/src/orchestration/longagent-manager.mjs +197 -171
- package/src/orchestration/stage-scheduler.mjs +733 -728
- package/src/orchestration/subagent-router.mjs +7 -1
- package/src/orchestration/task-scheduler.mjs +219 -7
- package/src/permission/engine.mjs +1 -1
- package/src/permission/exec-policy.mjs +370 -370
- package/src/permission/file-edit-policy.mjs +108 -0
- package/src/permission/prompt.mjs +1 -1
- package/src/permission/rules.mjs +116 -7
- package/src/plugin/builtin-hooks/post-edit-format.mjs +2 -1
- package/src/plugin/builtin-hooks/post-edit-typecheck.mjs +104 -40
- package/src/plugin/hook-bus.mjs +19 -5
- package/src/plugin/manifest-loader.mjs +222 -0
- package/src/provider/anthropic.mjs +396 -390
- package/src/provider/ollama.mjs +7 -1
- package/src/provider/openai.mjs +382 -340
- package/src/provider/retry-policy.mjs +74 -68
- package/src/provider/router.mjs +242 -241
- package/src/provider/sse.mjs +104 -104
- package/src/provider/wizard.mjs +556 -0
- package/src/repl/capability-facade.mjs +30 -0
- package/src/repl/command-surface.mjs +23 -0
- package/src/repl/controller-entry.mjs +40 -0
- package/src/repl/core-shell.mjs +208 -0
- package/src/repl/dialog-router.mjs +87 -0
- package/src/repl/input-engine.mjs +76 -0
- package/src/repl/keymap.mjs +7 -0
- package/src/repl/operator-surface.mjs +15 -0
- package/src/repl/permission-flow.mjs +49 -0
- package/src/repl/runtime-facade.mjs +36 -0
- package/src/repl/slash-router.mjs +62 -0
- package/src/repl/state-store.mjs +29 -0
- package/src/repl/turn-controller.mjs +58 -0
- package/src/repl/verification.mjs +23 -0
- package/src/repl.mjs +3368 -2929
- package/src/rules/load-rules.mjs +3 -3
- package/src/runtime.mjs +1 -1
- package/src/session/agent-transaction.mjs +86 -0
- package/src/session/checkpoint.mjs +302 -302
- package/src/session/compaction.mjs +36 -14
- package/src/session/engine.mjs +417 -227
- package/src/session/longagent-4stage.mjs +467 -460
- package/src/session/longagent-hybrid.mjs +1344 -1081
- package/src/session/longagent-plan.mjs +376 -365
- package/src/session/longagent-project-memory.mjs +53 -53
- package/src/session/longagent-scaffold.mjs +291 -291
- package/src/session/longagent-task-bus.mjs +138 -54
- package/src/session/longagent-utils.mjs +828 -472
- package/src/session/longagent.mjs +911 -884
- package/src/session/loop.mjs +1005 -905
- package/src/session/prompt/agent.txt +25 -0
- package/src/session/prompt/anthropic.txt +150 -150
- package/src/session/prompt/beast.txt +1 -1
- package/src/session/prompt/plan.txt +28 -6
- package/src/session/prompt/qwen.txt +46 -46
- package/src/session/recovery.mjs +21 -0
- package/src/session/rollback.mjs +197 -0
- package/src/session/routing-observability.mjs +72 -0
- package/src/session/runtime-state.mjs +47 -0
- package/src/session/store.mjs +523 -510
- package/src/session/system-prompt.mjs +56 -8
- package/src/session/task-validator.mjs +267 -267
- package/src/session/usability-gates.mjs +2 -2
- package/src/skill/builtin/commit.mjs +64 -64
- package/src/skill/builtin/design.mjs +76 -76
- package/src/skill/generator.mjs +18 -2
- package/src/skill/registry.mjs +642 -390
- package/src/storage/audit-store.mjs +18 -11
- package/src/storage/event-log.mjs +7 -1
- package/src/storage/ghost-commit-store.mjs +243 -245
- package/src/storage/paths.mjs +13 -0
- package/src/theme/default-theme.mjs +1 -1
- package/src/theme/markdown.mjs +4 -0
- package/src/theme/schema.mjs +1 -1
- package/src/theme/status-bar.mjs +162 -158
- package/src/tool/audit-wrapper.mjs +18 -2
- package/src/tool/edit-transaction.mjs +23 -0
- package/src/tool/executor.mjs +26 -1
- package/src/tool/file-read-state.mjs +65 -0
- package/src/tool/git-auto.mjs +526 -526
- package/src/tool/git-full-auto.mjs +487 -478
- package/src/tool/mutation-guard.mjs +54 -0
- package/src/tool/prompt/edit.txt +3 -3
- package/src/tool/prompt/multiedit.txt +1 -0
- package/src/tool/prompt/notebookedit.txt +2 -1
- package/src/tool/prompt/patch.txt +25 -24
- package/src/tool/prompt/read.txt +3 -3
- package/src/tool/prompt/sysinfo.txt +29 -0
- package/src/tool/prompt/task.txt +66 -4
- package/src/tool/prompt/write.txt +2 -2
- package/src/tool/question-prompt.mjs +17 -4
- package/src/tool/registry.mjs +1701 -1343
- package/src/tool/task-tool.mjs +14 -6
- package/src/ui/activity-renderer.mjs +667 -664
- package/src/ui/repl-background-panel.mjs +7 -0
- package/src/ui/repl-capability-panel.mjs +9 -0
- package/src/ui/repl-dashboard.mjs +54 -4
- package/src/ui/repl-help.mjs +110 -0
- package/src/ui/repl-operator-panel.mjs +12 -0
- package/src/ui/repl-route-feedback.mjs +35 -0
- package/src/ui/repl-status-view.mjs +76 -0
- package/src/ui/repl-task-panel.mjs +5 -0
- package/src/ui/repl-transcript-panel.mjs +56 -0
- package/src/ui/repl-turn-summary.mjs +135 -0
- package/src/usage/pricing.mjs +122 -121
- package/src/usage/usage-meter.mjs +1 -0
- package/src/util/git.mjs +562 -519
- package/src/util/template.mjs +6 -1
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
=== LONGAGENT STAGE 3/4: CODING AGENT ===
|
|
2
|
-
|
|
3
|
-
You are the Coding Agent in the four-stage LongAgent architecture.
|
|
4
|
-
|
|
5
|
-
# YOUR ROLE
|
|
6
|
-
Implement code strictly according to the blueprint from Stage 2.
|
|
7
|
-
|
|
8
|
-
# STAGE 3: CODE MODE - FULL PERMISSIONS
|
|
9
|
-
You now have full editing permissions. Follow the blueprint EXACTLY.
|
|
10
|
-
|
|
11
|
-
# CODING OBJECTIVES
|
|
12
|
-
|
|
13
|
-
1. STRICTLY adhere to the Stage 2 blueprint
|
|
14
|
-
2. Implement files in the planned order
|
|
15
|
-
3. Use the exact function signatures designed
|
|
16
|
-
4. Handle all edge cases identified
|
|
17
|
-
5. Follow project conventions and style
|
|
18
|
-
|
|
19
|
-
# CODING RULES
|
|
20
|
-
- No Deviations: Follow the blueprint unless you find a critical flaw
|
|
21
|
-
- One Step at a Time: Complete one component before moving to next
|
|
22
|
-
- Verify Early: Check syntax after each file edit
|
|
23
|
-
- Handle Edges: Don't forget the edge cases from the blueprint
|
|
24
|
-
- Clean Code: Follow project's existing style and patterns
|
|
25
|
-
|
|
26
|
-
# IMPLEMENTATION ORDER
|
|
27
|
-
1. Infrastructure/types first
|
|
28
|
-
2. Core logic next
|
|
29
|
-
3. Integration then
|
|
30
|
-
4. Tests/validation last
|
|
31
|
-
|
|
32
|
-
Use `todowrite` to track implementation progress.
|
|
33
|
-
|
|
34
|
-
End your response with:
|
|
35
|
-
```
|
|
36
|
-
[STAGE 3/4: CODING - COMPLETE]
|
|
37
|
-
```
|
|
1
|
+
=== LONGAGENT STAGE 3/4: CODING AGENT ===
|
|
2
|
+
|
|
3
|
+
You are the Coding Agent in the four-stage LongAgent architecture.
|
|
4
|
+
|
|
5
|
+
# YOUR ROLE
|
|
6
|
+
Implement code strictly according to the blueprint from Stage 2.
|
|
7
|
+
|
|
8
|
+
# STAGE 3: CODE MODE - FULL PERMISSIONS
|
|
9
|
+
You now have full editing permissions. Follow the blueprint EXACTLY.
|
|
10
|
+
|
|
11
|
+
# CODING OBJECTIVES
|
|
12
|
+
|
|
13
|
+
1. STRICTLY adhere to the Stage 2 blueprint
|
|
14
|
+
2. Implement files in the planned order
|
|
15
|
+
3. Use the exact function signatures designed
|
|
16
|
+
4. Handle all edge cases identified
|
|
17
|
+
5. Follow project conventions and style
|
|
18
|
+
|
|
19
|
+
# CODING RULES
|
|
20
|
+
- No Deviations: Follow the blueprint unless you find a critical flaw
|
|
21
|
+
- One Step at a Time: Complete one component before moving to next
|
|
22
|
+
- Verify Early: Check syntax after each file edit
|
|
23
|
+
- Handle Edges: Don't forget the edge cases from the blueprint
|
|
24
|
+
- Clean Code: Follow project's existing style and patterns
|
|
25
|
+
|
|
26
|
+
# IMPLEMENTATION ORDER
|
|
27
|
+
1. Infrastructure/types first
|
|
28
|
+
2. Core logic next
|
|
29
|
+
3. Integration then
|
|
30
|
+
4. Tests/validation last
|
|
31
|
+
|
|
32
|
+
Use `todowrite` to track implementation progress.
|
|
33
|
+
|
|
34
|
+
End your response with:
|
|
35
|
+
```
|
|
36
|
+
[STAGE 3/4: CODING - COMPLETE]
|
|
37
|
+
```
|
|
@@ -1,46 +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
|
-
```
|
|
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
|
+
```
|
|
@@ -1,63 +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
|
+
=== 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,6 +1,7 @@
|
|
|
1
1
|
import path from "node:path"
|
|
2
2
|
import { access, readdir, readFile } from "node:fs/promises"
|
|
3
3
|
import { renderTemplate } from "../util/template.mjs"
|
|
4
|
+
import { userRootDir } from "../storage/paths.mjs"
|
|
4
5
|
|
|
5
6
|
async function exists(target) {
|
|
6
7
|
try {
|
|
@@ -34,8 +35,7 @@ async function loadDir(dir, scope) {
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
export async function loadCustomCommands(cwd = process.cwd()) {
|
|
37
|
-
const
|
|
38
|
-
const userDir = path.join(userRoot, ".kkcode", "commands")
|
|
38
|
+
const userDir = path.join(userRootDir(), "commands")
|
|
39
39
|
const projectDir = path.join(cwd, ".kkcode", "commands")
|
|
40
40
|
const [globalCommands, projectCommands] = await Promise.all([loadDir(userDir, "global"), loadDir(projectDir, "project")])
|
|
41
41
|
const map = new Map()
|
package/src/commands/agent.mjs
CHANGED
|
@@ -9,16 +9,100 @@ async function withContext(action) {
|
|
|
9
9
|
return action(ctx)
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
function printTaskSummary(task) {
|
|
13
|
+
const summary = BackgroundManager.summarize(task)
|
|
14
|
+
if (!summary) return
|
|
15
|
+
console.log(`[${summary.status}] ${summary.id} :: ${summary.description}`)
|
|
16
|
+
console.log(` attempt=${summary.attempt} subagent=${summary.subagent || "-"} execution_mode=${summary.execution_mode || "-"} session=${summary.session_id || "-"}`)
|
|
17
|
+
if (summary.interruption_reason) {
|
|
18
|
+
console.log(` interruption=${summary.interruption_reason}`)
|
|
19
|
+
}
|
|
20
|
+
if (summary.result_preview) {
|
|
21
|
+
console.log(` preview=${summary.result_preview}`)
|
|
22
|
+
}
|
|
23
|
+
console.log(` next=${summary.next_action}`)
|
|
24
|
+
}
|
|
25
|
+
|
|
12
26
|
export function createBackgroundCommand() {
|
|
13
27
|
const cmd = new Command("background").description("inspect background delegated tasks")
|
|
14
28
|
|
|
15
29
|
cmd
|
|
16
30
|
.command("list")
|
|
17
31
|
.description("list background tasks")
|
|
18
|
-
.
|
|
32
|
+
.option("--json", "print raw JSON")
|
|
33
|
+
.option("--status <status>", "filter by status")
|
|
34
|
+
.action(async (options) => {
|
|
19
35
|
await withContext(async () => {
|
|
20
|
-
const list = await BackgroundManager.list()
|
|
21
|
-
|
|
36
|
+
const list = (await BackgroundManager.list()).filter((task) => {
|
|
37
|
+
if (!options.status) return true
|
|
38
|
+
return String(task.status || "") === String(options.status || "")
|
|
39
|
+
})
|
|
40
|
+
if (options.json) {
|
|
41
|
+
console.log(JSON.stringify(list, null, 2))
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
const aggregate = BackgroundManager.summarizeList(list)
|
|
45
|
+
console.log(`summary: total=${aggregate.total} active=${aggregate.active} pending=${aggregate.counts.pending} running=${aggregate.counts.running} completed=${aggregate.counts.completed} interrupted=${aggregate.counts.interrupted} error=${aggregate.counts.error}`)
|
|
46
|
+
if (aggregate.recent_terminal.length) {
|
|
47
|
+
console.log(`recent terminal: ${aggregate.recent_terminal.map((item) => `${item.id}:${item.status}`).join(" | ")}`)
|
|
48
|
+
}
|
|
49
|
+
if (!list.length) {
|
|
50
|
+
console.log("no background tasks")
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
for (const task of list) {
|
|
54
|
+
printTaskSummary(task)
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
cmd
|
|
60
|
+
.command("output")
|
|
61
|
+
.description("print the terminal result payload for one background task")
|
|
62
|
+
.requiredOption("--id <id>", "task id")
|
|
63
|
+
.action(async (options) => {
|
|
64
|
+
await withContext(async () => {
|
|
65
|
+
const task = await BackgroundManager.get(options.id)
|
|
66
|
+
if (!task) {
|
|
67
|
+
console.error(`not found: ${options.id}`)
|
|
68
|
+
process.exitCode = 1
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
if (!task.result) {
|
|
72
|
+
console.log(JSON.stringify(BackgroundManager.summarize(task), null, 2))
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
console.log(JSON.stringify(task.result, null, 2))
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
cmd
|
|
80
|
+
.command("wait")
|
|
81
|
+
.description("wait for one background task to reach a terminal state")
|
|
82
|
+
.requiredOption("--id <id>", "task id")
|
|
83
|
+
.option("--timeout <ms>", "wait timeout in milliseconds", "30000")
|
|
84
|
+
.option("--json", "print raw JSON")
|
|
85
|
+
.action(async (options) => {
|
|
86
|
+
await withContext(async (ctx) => {
|
|
87
|
+
const task = await BackgroundManager.waitForTask(options.id, {
|
|
88
|
+
timeoutMs: Number(options.timeout || 30000),
|
|
89
|
+
config: ctx.configState.config
|
|
90
|
+
})
|
|
91
|
+
if (!task) {
|
|
92
|
+
console.error(`not found: ${options.id}`)
|
|
93
|
+
process.exitCode = 1
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
if (!["completed", "cancelled", "error", "interrupted"].includes(task.status)) {
|
|
97
|
+
console.error(`timeout waiting for task: ${options.id} (status=${task.status})`)
|
|
98
|
+
process.exitCode = 1
|
|
99
|
+
return
|
|
100
|
+
}
|
|
101
|
+
if (options.json) {
|
|
102
|
+
console.log(JSON.stringify(task, null, 2))
|
|
103
|
+
return
|
|
104
|
+
}
|
|
105
|
+
printTaskSummary(task)
|
|
22
106
|
})
|
|
23
107
|
})
|
|
24
108
|
|
|
@@ -26,6 +110,7 @@ export function createBackgroundCommand() {
|
|
|
26
110
|
.command("show")
|
|
27
111
|
.description("show one background task")
|
|
28
112
|
.requiredOption("--id <id>", "task id")
|
|
113
|
+
.option("--json", "print raw JSON")
|
|
29
114
|
.action(async (options) => {
|
|
30
115
|
await withContext(async () => {
|
|
31
116
|
const task = await BackgroundManager.get(options.id)
|
|
@@ -34,7 +119,47 @@ export function createBackgroundCommand() {
|
|
|
34
119
|
process.exitCode = 1
|
|
35
120
|
return
|
|
36
121
|
}
|
|
37
|
-
|
|
122
|
+
if (options.json) {
|
|
123
|
+
console.log(JSON.stringify(task, null, 2))
|
|
124
|
+
return
|
|
125
|
+
}
|
|
126
|
+
printTaskSummary(task)
|
|
127
|
+
const summary = BackgroundManager.summarize(task)
|
|
128
|
+
if (summary?.log_tail?.length) {
|
|
129
|
+
console.log(" log tail:")
|
|
130
|
+
for (const line of summary.log_tail) {
|
|
131
|
+
console.log(` ${line}`)
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (task.result) {
|
|
135
|
+
console.log(" result:")
|
|
136
|
+
console.log(JSON.stringify(task.result, null, 2))
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
cmd
|
|
142
|
+
.command("logs")
|
|
143
|
+
.description("show recent log lines for one background task")
|
|
144
|
+
.requiredOption("--id <id>", "task id")
|
|
145
|
+
.option("--tail <n>", "number of lines to show", "20")
|
|
146
|
+
.action(async (options) => {
|
|
147
|
+
await withContext(async () => {
|
|
148
|
+
const task = await BackgroundManager.get(options.id)
|
|
149
|
+
if (!task) {
|
|
150
|
+
console.error(`not found: ${options.id}`)
|
|
151
|
+
process.exitCode = 1
|
|
152
|
+
return
|
|
153
|
+
}
|
|
154
|
+
const tailCount = Math.max(1, Number(options.tail || 20))
|
|
155
|
+
const lines = Array.isArray(task.logs) ? task.logs.slice(-tailCount) : []
|
|
156
|
+
if (!lines.length) {
|
|
157
|
+
console.log(`no logs yet: ${options.id}`)
|
|
158
|
+
return
|
|
159
|
+
}
|
|
160
|
+
for (const line of lines) {
|
|
161
|
+
console.log(line)
|
|
162
|
+
}
|
|
38
163
|
})
|
|
39
164
|
})
|
|
40
165
|
|
|
@@ -54,6 +179,22 @@ export function createBackgroundCommand() {
|
|
|
54
179
|
})
|
|
55
180
|
})
|
|
56
181
|
|
|
182
|
+
cmd
|
|
183
|
+
.command("stop")
|
|
184
|
+
.description("alias for cancel")
|
|
185
|
+
.requiredOption("--id <id>", "task id")
|
|
186
|
+
.action(async (options) => {
|
|
187
|
+
await withContext(async () => {
|
|
188
|
+
const ok = await BackgroundManager.cancel(options.id)
|
|
189
|
+
if (!ok) {
|
|
190
|
+
console.error(`not found: ${options.id}`)
|
|
191
|
+
process.exitCode = 1
|
|
192
|
+
return
|
|
193
|
+
}
|
|
194
|
+
console.log(`cancel requested: ${options.id}`)
|
|
195
|
+
})
|
|
196
|
+
})
|
|
197
|
+
|
|
57
198
|
cmd
|
|
58
199
|
.command("retry")
|
|
59
200
|
.description("retry one interrupted/error background task")
|