@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,54 +1,138 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Task Bus — 并行 task 间的轻量通信机制
|
|
3
|
-
* task 可以发布消息(接口变更、共享数据),其他 task 通过 priorContext 读取
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
this.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Task Bus — 并行 task 间的轻量通信机制
|
|
3
|
+
* task 可以发布消息(接口变更、共享数据),其他 task 通过 priorContext 读取
|
|
4
|
+
*
|
|
5
|
+
* Phase 3 增强:
|
|
6
|
+
* - 索引替代时间戳,修复 toDeltaString 竞态
|
|
7
|
+
* - topic 分类支持,按类别查询
|
|
8
|
+
* - parseTaskOutput 支持结构化 JSON 值
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export class TaskBus {
|
|
12
|
+
constructor({ maxMessages = 500 } = {}) {
|
|
13
|
+
this._messages = []
|
|
14
|
+
this._shared = {}
|
|
15
|
+
this._maxMessages = maxMessages
|
|
16
|
+
this._lastFlushedIdx = 0
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
publish(taskId, key, value, topic = null) {
|
|
20
|
+
this._messages.push({ taskId, key, value, topic, ts: Date.now() })
|
|
21
|
+
// Evict oldest messages when exceeding capacity
|
|
22
|
+
if (this._messages.length > this._maxMessages) {
|
|
23
|
+
const keep = Math.round(this._maxMessages * 0.8)
|
|
24
|
+
const removed = this._messages.length - keep
|
|
25
|
+
this._messages = this._messages.slice(-keep)
|
|
26
|
+
// 调整索引偏移,防止 delta 丢失
|
|
27
|
+
this._lastFlushedIdx = Math.max(0, this._lastFlushedIdx - removed)
|
|
28
|
+
}
|
|
29
|
+
this._shared[key] = { value, from: taskId, topic, ts: Date.now() }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get(key) {
|
|
33
|
+
return this._shared[key]?.value ?? null
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
getByTopic(topic) {
|
|
37
|
+
const result = {}
|
|
38
|
+
for (const [key, entry] of Object.entries(this._shared)) {
|
|
39
|
+
if (entry.topic === topic) result[key] = entry.value
|
|
40
|
+
}
|
|
41
|
+
return result
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
snapshot() {
|
|
45
|
+
return { ...this._shared }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
hasPendingMessages() {
|
|
49
|
+
return this._lastFlushedIdx < this._messages.length
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
toContextString(maxLen = 2000) {
|
|
53
|
+
const entries = Object.entries(this._shared)
|
|
54
|
+
if (!entries.length) return ""
|
|
55
|
+
const lines = ["### Task Bus (shared context)"]
|
|
56
|
+
for (const [key, { value, from }] of entries) {
|
|
57
|
+
const val = typeof value === "string" ? value : JSON.stringify(value)
|
|
58
|
+
lines.push(`- [${from}] ${key}: ${val.slice(0, 200)}`)
|
|
59
|
+
}
|
|
60
|
+
const result = lines.join("\n")
|
|
61
|
+
return result.length > maxLen ? result.slice(0, maxLen) + "\n..." : result
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
toDeltaString(maxLen = 2000) {
|
|
65
|
+
// 用索引替代时间戳,避免竞态丢消息
|
|
66
|
+
const startIdx = this._lastFlushedIdx
|
|
67
|
+
this._lastFlushedIdx = this._messages.length
|
|
68
|
+
if (startIdx >= this._messages.length) return ""
|
|
69
|
+
const newMessages = this._messages.slice(startIdx)
|
|
70
|
+
if (!newMessages.length) return ""
|
|
71
|
+
const lines = ["### Task Bus (new since last stage)"]
|
|
72
|
+
for (const { taskId, key, value } of newMessages) {
|
|
73
|
+
const val = typeof value === "string" ? value : JSON.stringify(value)
|
|
74
|
+
lines.push(`- [${taskId}] ${key}: ${val.slice(0, 200)}`)
|
|
75
|
+
}
|
|
76
|
+
const result = lines.join("\n")
|
|
77
|
+
return result.length > maxLen ? result.slice(0, maxLen) + "\n..." : result
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
parseTaskOutput(taskId, text) {
|
|
81
|
+
const marker = "[TASK_BROADCAST:"
|
|
82
|
+
let pos = 0
|
|
83
|
+
while ((pos = text.indexOf(marker, pos)) !== -1) {
|
|
84
|
+
const start = pos + marker.length
|
|
85
|
+
// 提取 key(支持 key@topic 语法)
|
|
86
|
+
const eqIdx = text.indexOf("=", start)
|
|
87
|
+
if (eqIdx === -1) { pos = start; continue }
|
|
88
|
+
const rawKey = text.slice(start, eqIdx).trim()
|
|
89
|
+
if (!rawKey) { pos = start; continue }
|
|
90
|
+
|
|
91
|
+
// 提取 value — 处理嵌套括号
|
|
92
|
+
let valStart = eqIdx + 1
|
|
93
|
+
while (valStart < text.length && text[valStart] === " ") valStart++
|
|
94
|
+
let valEnd = -1
|
|
95
|
+
const ch = text[valStart]
|
|
96
|
+
if (ch === "{" || ch === "[") {
|
|
97
|
+
// 平衡括号扫描
|
|
98
|
+
let depth = 0
|
|
99
|
+
for (let i = valStart; i < text.length; i++) {
|
|
100
|
+
if (text[i] === "{" || text[i] === "[") depth++
|
|
101
|
+
else if (text[i] === "}" || text[i] === "]") {
|
|
102
|
+
depth--
|
|
103
|
+
if (depth === 0) { valEnd = i + 1; break }
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (valEnd === -1) { pos = start; continue }
|
|
107
|
+
} else {
|
|
108
|
+
// 简单值 — 找到下一个 ]
|
|
109
|
+
valEnd = text.indexOf("]", valStart)
|
|
110
|
+
if (valEnd === -1) { pos = start; continue }
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const raw = text.slice(valStart, valEnd).trim()
|
|
114
|
+
// 跳过闭合的 ]
|
|
115
|
+
pos = valEnd + 1
|
|
116
|
+
|
|
117
|
+
// 解析值
|
|
118
|
+
let value = raw
|
|
119
|
+
if (raw.startsWith("{") || raw.startsWith("[")) {
|
|
120
|
+
try { value = JSON.parse(raw) } catch { /* 保持字符串 */ }
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// 解析 key@topic
|
|
124
|
+
const topicMatch = rawKey.match(/^(\w+)@(\w+)$/)
|
|
125
|
+
if (topicMatch) {
|
|
126
|
+
this.publish(taskId, topicMatch[1], value, topicMatch[2])
|
|
127
|
+
} else {
|
|
128
|
+
this.publish(taskId, rawKey, value)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
clear() {
|
|
134
|
+
this._messages = []
|
|
135
|
+
this._shared = {}
|
|
136
|
+
this._lastFlushedIdx = 0
|
|
137
|
+
}
|
|
138
|
+
}
|