@miphamai/cli 0.85.34 → 0.85.35
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/README.md +1 -1
- package/package.json +1 -1
- package/src/core/context.ts +22 -5
- package/src/core/engine.ts +3 -3
- package/src/core/hooks-config.ts +32 -0
- package/src/core/memory/memory-loader.ts +2 -2
- package/src/core/session-log.ts +14 -6
- package/src/daemon/engine-capabilities.ts +124 -2
- package/src/daemon/server.ts +13 -1
- package/src/i18n-core/locales/en-US.json +1 -0
- package/src/i18n-core/locales/zh-CN.json +1 -0
- package/src/shared/package-info.ts +2 -2
- package/src/ui/commands.ts +13 -2
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Mipham Code v0.85.
|
|
1
|
+
# Mipham Code v0.85.35
|
|
2
2
|
|
|
3
3
|
**Multi-model open-core intelligent coding terminal** — 12 AI providers, 138 commands, 31 tools, 28 skills + marketplace, self-update. AI-assisted code generation, security auditing, MCP protocol, and extensible skills — in a single CLI.
|
|
4
4
|
|
package/package.json
CHANGED
package/src/core/context.ts
CHANGED
|
@@ -176,9 +176,24 @@ export class ContextManager {
|
|
|
176
176
|
|
|
177
177
|
private log?: SessionLog
|
|
178
178
|
|
|
179
|
+
/**
|
|
180
|
+
* 这份日志是不是**完整历史**(默认是;CLI 的 `--resume` 语义依赖它为真)。
|
|
181
|
+
*
|
|
182
|
+
* `false` 只有一个场景:daemon 的会话日志是**审计增量** —— 历史的真源在 SQLite,
|
|
183
|
+
* 日志只记本进程窗口内发生的事。此时「model-visible means logged」这条不变量
|
|
184
|
+
* **按构造不成立**(回灌的旧消息从来没进过日志),故运行时断言必须跟着关掉,
|
|
185
|
+
* 否则它会在每次 `addMessage` 上抛一条「有消息没被记录」的错,而那不是缺陷。
|
|
186
|
+
*
|
|
187
|
+
* 关掉的是**断言**,不是写通:新事件照常落盘。两者不要混为一谈 ——
|
|
188
|
+
* 断言的价值是「能发现漏记」,而在一个从不记录历史投影的日志上,
|
|
189
|
+
* 它对每一行历史都会报警,于是报警这件事本身失效。
|
|
190
|
+
*/
|
|
191
|
+
private logAuthoritative = true
|
|
192
|
+
|
|
179
193
|
/** 附加一个 append-only 会话日志;addMessage/seedMessages 将写通镜像到日志。 */
|
|
180
|
-
setLog(log?: SessionLog): void {
|
|
194
|
+
setLog(log?: SessionLog, opts?: { authoritative?: boolean }): void {
|
|
181
195
|
this.log = log
|
|
196
|
+
this.logAuthoritative = opts?.authoritative ?? true
|
|
182
197
|
}
|
|
183
198
|
|
|
184
199
|
getLog(): SessionLog | undefined {
|
|
@@ -188,6 +203,8 @@ export class ContextManager {
|
|
|
188
203
|
/** 从已持久化的日志恢复:设 log 为源,messages 为投影(不重复写通)。 */
|
|
189
204
|
restoreLog(log: SessionLog): void {
|
|
190
205
|
this.log = log
|
|
206
|
+
// 恢复出来的这份**就是完整历史**(`messages` 正是由它派生的),故断言重新生效。
|
|
207
|
+
this.logAuthoritative = true
|
|
191
208
|
// 盘上那份历史可能以一条**没有结果**的调用收尾(写盘写到一半被打断,末尾那行半截
|
|
192
209
|
// 结果被 `open()` 静默丢掉 —— 引擎自己的日志顺序到不了这个形状,见下面那个函数的
|
|
193
210
|
// 注释)。挂着 `tool_calls` 却没有结果回应的请求会被 provider 整条拒收,用户看到的
|
|
@@ -320,7 +337,7 @@ export class ContextManager {
|
|
|
320
337
|
for (const e of messageToEvents(msg, Date.now())) this.log.append(e)
|
|
321
338
|
}
|
|
322
339
|
|
|
323
|
-
if (this.log && isAssertModelVisibleDebug()) {
|
|
340
|
+
if (this.log && this.logAuthoritative && isAssertModelVisibleDebug()) {
|
|
324
341
|
assertModelVisible(this.log.events(), this.messages)
|
|
325
342
|
}
|
|
326
343
|
|
|
@@ -345,7 +362,7 @@ export class ContextManager {
|
|
|
345
362
|
this.log.append({ type: 'context/inject', at: Date.now(), source, text })
|
|
346
363
|
}
|
|
347
364
|
|
|
348
|
-
if (this.log && isAssertModelVisibleDebug()) {
|
|
365
|
+
if (this.log && this.logAuthoritative && isAssertModelVisibleDebug()) {
|
|
349
366
|
assertModelVisible(this.log.events(), this.messages)
|
|
350
367
|
}
|
|
351
368
|
|
|
@@ -391,7 +408,7 @@ export class ContextManager {
|
|
|
391
408
|
}
|
|
392
409
|
this.recountMessageTokens()
|
|
393
410
|
|
|
394
|
-
if (this.log && isAssertModelVisibleDebug()) {
|
|
411
|
+
if (this.log && this.logAuthoritative && isAssertModelVisibleDebug()) {
|
|
395
412
|
assertModelVisible(this.log.events(), this.messages)
|
|
396
413
|
}
|
|
397
414
|
}
|
|
@@ -655,7 +672,7 @@ export class ContextManager {
|
|
|
655
672
|
// 之后对 `this.messages` 的原地修改回写进已入队的事件里。
|
|
656
673
|
if (this.log) {
|
|
657
674
|
this.log.append({ type: 'rewind', at: Date.now(), messages: structuredClone(this.messages) })
|
|
658
|
-
if (isAssertModelVisibleDebug()) {
|
|
675
|
+
if (this.logAuthoritative && isAssertModelVisibleDebug()) {
|
|
659
676
|
assertModelVisible(this.log.events(), this.messages)
|
|
660
677
|
}
|
|
661
678
|
}
|
package/src/core/engine.ts
CHANGED
|
@@ -456,9 +456,9 @@ export class QueryEngine {
|
|
|
456
456
|
/**
|
|
457
457
|
* Register the instruction loader — the recall nudge's text source.
|
|
458
458
|
*
|
|
459
|
-
*
|
|
460
|
-
*
|
|
461
|
-
*
|
|
459
|
+
* 两个入口都接(`index.tsx:848` / `daemon/engine-capabilities.ts`):扳机只有在会话
|
|
460
|
+
* **已经被告知过**那份文件时才有意义,而 daemon 现在也会组装系统提示 —— 指针与常驻块
|
|
461
|
+
* 出自同一个 loader 实例,不存在「两边选了不同的文件」这种分叉。
|
|
462
462
|
*/
|
|
463
463
|
setInstructions(loader: InstructionsLoader): void {
|
|
464
464
|
this.instructionsLoader = loader
|
package/src/core/hooks-config.ts
CHANGED
|
@@ -18,12 +18,36 @@ export interface SettingsHooks {
|
|
|
18
18
|
UserPromptSubmit?: HookConfigEntry[]
|
|
19
19
|
PreCompact?: HookConfigEntry[]
|
|
20
20
|
PostCompact?: HookConfigEntry[]
|
|
21
|
+
/** ⚠️ 目前**没有派发点** —— 写在这里不报错,但不会跑。见 `UNDISPATCHED_EVENTS`。 */
|
|
21
22
|
ConfigChange?: HookConfigEntry[]
|
|
22
23
|
SubagentStart?: HookConfigEntry[]
|
|
23
24
|
SubagentStop?: HookConfigEntry[]
|
|
25
|
+
/** ⚠️ 目前**没有派发点** —— 写在这里不报错,但不会跑。见 `UNDISPATCHED_EVENTS`。 */
|
|
24
26
|
PreInference?: HookConfigEntry[]
|
|
25
27
|
}
|
|
26
28
|
|
|
29
|
+
/**
|
|
30
|
+
* `settings.json` 接受、但**生产代码里没有任何派发点**的事件。
|
|
31
|
+
*
|
|
32
|
+
* `HookEngine` 上这两个事件各有一个现成方法(`hooks.ts:162` / `:222`,名字见 ROADMAP D18),
|
|
33
|
+
* 而它们在 `src/` + `bin/` 里**零引用** —— `grep` 只剩定义行与测试。注册进去的后果不是
|
|
34
|
+
* 「静默不生效」那么简单:`/hooks` 遍历的是**配置文件本身**(`ui/commands.ts`),于是用户
|
|
35
|
+
* 看到自己那条 hook 被列出来、计入 `hooks.found N` —— 读起来是「已安装」,实际一次都不会跑。
|
|
36
|
+
* **被告知的东西与发生的事分叉,比「不支持」更坏。**
|
|
37
|
+
*
|
|
38
|
+
* 所以这里**不注册**并说出原因。`/hooks` 读的是配置文件本身、不读注册表,故单靠这一层
|
|
39
|
+
* 并不能改变它的输出 —— 它会**继续列出**这些条目,所以 `ui/commands.ts` 的 `/hooks`
|
|
40
|
+
* 必须用同一个集合给它们打「不会运行」标记并排除出计数。两处共用一个集合,名单才不会
|
|
41
|
+
* 各写一份、各自漂移。接线本身是独立决定(ROADMAP D18):`PreInference` 要先定
|
|
42
|
+
* 「settings.json 的任意命令 hook」与「把整段对话正文发往组织端点的 DLP」如何共存 ——
|
|
43
|
+
* 后者是数据出境面,不能顺手接。
|
|
44
|
+
*
|
|
45
|
+
* ⚠️ 本注释**刻意不逐字写出那两个方法名**:`unwired-disposition.test.ts` 的
|
|
46
|
+
* `referencesOutside` 匹配的是**文本出现**、不是调用点,写出来就会把那条守卫打红
|
|
47
|
+
* (它自己的 docblock 里写着这条反向边界)。要查名字去看 ROADMAP D18。
|
|
48
|
+
*/
|
|
49
|
+
export const UNDISPATCHED_EVENTS = new Set<string>(['ConfigChange', 'PreInference'])
|
|
50
|
+
|
|
27
51
|
/**
|
|
28
52
|
* Load hook configurations from a settings object and convert them to
|
|
29
53
|
* executable HookDefinitions suitable for the HookEngine.
|
|
@@ -34,6 +58,14 @@ export function loadHookConfigs(configs: SettingsHooks): HookDefinition[] {
|
|
|
34
58
|
for (const [eventName, entries] of Object.entries(configs)) {
|
|
35
59
|
if (!entries || !Array.isArray(entries)) continue
|
|
36
60
|
|
|
61
|
+
if (UNDISPATCHED_EVENTS.has(eventName)) {
|
|
62
|
+
process.stderr.write(
|
|
63
|
+
`⚠️ Hook event ${eventName} has no dispatch point in this version — ` +
|
|
64
|
+
`${entries.length} configured hook group(s) under it will not run and are not registered.\n`,
|
|
65
|
+
)
|
|
66
|
+
continue
|
|
67
|
+
}
|
|
68
|
+
|
|
37
69
|
for (const entry of entries) {
|
|
38
70
|
// A matcher is only a *filter*, so a malformed one must not take the whole
|
|
39
71
|
// hook set down with it. `new RegExp` throws here, and both callers register
|
|
@@ -18,7 +18,7 @@ export function getMemoryManager(): MemoryManagerType {
|
|
|
18
18
|
* Load relevant memories for the current session and inject as
|
|
19
19
|
* a system-reminder block. Called at SessionStart.
|
|
20
20
|
*/
|
|
21
|
-
export function loadSessionMemories(context: string): string {
|
|
21
|
+
export function loadSessionMemories(context: string, maxTokens?: number): string {
|
|
22
22
|
const mm = getMemoryManager()
|
|
23
|
-
return mm.buildSystemReminder(context)
|
|
23
|
+
return mm.buildSystemReminder(context, maxTokens)
|
|
24
24
|
}
|
package/src/core/session-log.ts
CHANGED
|
@@ -253,7 +253,15 @@ export class SessionLog {
|
|
|
253
253
|
private buf: SessionEvent[] = []
|
|
254
254
|
private flushed = 0
|
|
255
255
|
|
|
256
|
-
|
|
256
|
+
/**
|
|
257
|
+
* @param dir 落盘目录,**默认 `~/.mipham/sessions`**(CLI 的历史真源)。
|
|
258
|
+
* daemon 传自己的目录:它的日志是**审计增量**而不是可恢复历史(真源是 SQLite),
|
|
259
|
+
* 落进 `sessions/` 会被 `--resume` 当成一个"历史不全"的会话列出来。
|
|
260
|
+
*/
|
|
261
|
+
constructor(
|
|
262
|
+
private name: string,
|
|
263
|
+
private dir: string = LOG_DIR,
|
|
264
|
+
) {}
|
|
257
265
|
|
|
258
266
|
/**
|
|
259
267
|
* Append one event — in memory *and* on disk.
|
|
@@ -279,8 +287,8 @@ export class SessionLog {
|
|
|
279
287
|
save(): void {
|
|
280
288
|
// Session logs contain full conversation + tool results (possibly credentials):
|
|
281
289
|
// restrict to owner-only (dir 0700, file 0600).
|
|
282
|
-
mkdirSync(
|
|
283
|
-
const path = join(
|
|
290
|
+
mkdirSync(this.dir, { recursive: true, mode: 0o700 })
|
|
291
|
+
const path = join(this.dir, `${sanitizeSessionName(this.name)}.jsonl`)
|
|
284
292
|
|
|
285
293
|
// A writer killed mid-append can leave a partial line with no trailing
|
|
286
294
|
// newline. `open()` skips that line, but the next append would glue the new
|
|
@@ -309,9 +317,9 @@ export class SessionLog {
|
|
|
309
317
|
}
|
|
310
318
|
|
|
311
319
|
/** 从既有 JSONL 打开,逐行解析为事件(已落盘事件标记为已 flush)。 */
|
|
312
|
-
static open(name: string): SessionLog {
|
|
313
|
-
const log = new SessionLog(name)
|
|
314
|
-
const path = join(
|
|
320
|
+
static open(name: string, dir: string = LOG_DIR): SessionLog {
|
|
321
|
+
const log = new SessionLog(name, dir)
|
|
322
|
+
const path = join(dir, `${sanitizeSessionName(name)}.jsonl`)
|
|
315
323
|
// 类型闸在读取之前:`SessionStore.load` 在快照读不出来时**回落到这里**,所以路径上
|
|
316
324
|
// 是个 FIFO 时不能在这里换个函数继续等 —— 读不动就当空日志(见 shared/regular-file.ts)。
|
|
317
325
|
let raw = readRegularFileSync(path)
|
|
@@ -20,8 +20,9 @@
|
|
|
20
20
|
* `test/integrity/daemon-capability-parity.test.ts` 能咬住的源码差异,而不是靠人记得。
|
|
21
21
|
*
|
|
22
22
|
* 不搬 `index.tsx` 的整套装配:ArtifactServer 是 TUI 画廊的 localhost 监听器、
|
|
23
|
-
* AgentViewManager 的唯一消费者是 TUI slash
|
|
24
|
-
*
|
|
23
|
+
* AgentViewManager 的唯一消费者是 TUI slash 命令。这里接**有后果的六条**
|
|
24
|
+
* (skills / rulesLoader / hookEngine / agentRegistry / instructions + 系统提示 / llm);
|
|
25
|
+
* 其余按后果分级进守卫的具名豁免表,逐条写理由。
|
|
25
26
|
*/
|
|
26
27
|
|
|
27
28
|
import type { QueryEngine } from '../core/engine'
|
|
@@ -35,6 +36,10 @@ import { isSafeMode } from '../core/safe-mode'
|
|
|
35
36
|
import { loadSettingsJson } from '../config/loader'
|
|
36
37
|
import { getWorkspaceTrust, warnProjectHooksSkipped } from '../core/workspace-trust'
|
|
37
38
|
import { AgentRegistry } from '../agent/agent-registry'
|
|
39
|
+
import { InstructionsLoader } from '../core/instructions'
|
|
40
|
+
import { loadSessionMemories } from '../core/memory/memory-loader'
|
|
41
|
+
import { SessionLog } from '../core/session-log'
|
|
42
|
+
import { miphamHome } from '../core/paths'
|
|
38
43
|
|
|
39
44
|
export interface DaemonEngineCapabilities {
|
|
40
45
|
/** 会话工作目录 —— 三者的派生源(外部 skill 路径 / hooks / agents 都从它算)。 */
|
|
@@ -43,6 +48,8 @@ export interface DaemonEngineCapabilities {
|
|
|
43
48
|
registry: ProviderRegistry
|
|
44
49
|
/** `config.skills.paths`(外部 skill 目录)。省略即只加载内置与用户 skill。 */
|
|
45
50
|
skillsPaths?: string[]
|
|
51
|
+
/** `config.skills.reminder`。省略即 `full`,与 CLI 侧的默认同。 */
|
|
52
|
+
skillsReminder?: 'full' | 'compact' | 'off'
|
|
46
53
|
}
|
|
47
54
|
|
|
48
55
|
/**
|
|
@@ -127,6 +134,22 @@ function agentsFor(cwd: string): AgentRegistry {
|
|
|
127
134
|
return registry
|
|
128
135
|
}
|
|
129
136
|
|
|
137
|
+
/**
|
|
138
|
+
* 指令装载器,**每会话新建、不记忆化** —— 与 `RulesLoader` 同一个理由(见 D7):
|
|
139
|
+
* 一个长命 daemon 服务多个会话,按 cwd 共享一只的话,会话期间改过的 `CLAUDE.md` /
|
|
140
|
+
* `MIPHAM.md` 对所有后来新建的会话都**永远看不见**,直到那个 loader 自己 `refresh()`。
|
|
141
|
+
* 代价只是每次建引擎多读几个小文件 —— 与「配额规则」那点成本同量级。
|
|
142
|
+
*
|
|
143
|
+
* 它是**系统提示里「项目规则」那一段**的唯一来源(`MIPHAM.md` / `CLAUDE.md` / `AGENTS.md`
|
|
144
|
+
* / `USER.md` 链 + CRSI 教训),也是 CRSI 召回扳机的指针来源 —— 两者必须是同一份选择,
|
|
145
|
+
* 否则「扳机说去读那份文件」与「提示里写的是另一份」会分叉。
|
|
146
|
+
*/
|
|
147
|
+
function loadInstructionsFor(cwd: string): InstructionsLoader {
|
|
148
|
+
const loader = new InstructionsLoader()
|
|
149
|
+
loader.loadAll(cwd)
|
|
150
|
+
return loader
|
|
151
|
+
}
|
|
152
|
+
|
|
130
153
|
/**
|
|
131
154
|
* 把一个 daemon 引擎接成「和交互式 CLI 同等能干活」的样子。
|
|
132
155
|
*
|
|
@@ -146,7 +169,106 @@ export function wireDaemonEngine(engine: QueryEngine, opts: DaemonEngineCapabili
|
|
|
146
169
|
engine.setHookEngine(hooksFor(opts.cwd, skills))
|
|
147
170
|
engine.setAgentRegistry(agentsFor(opts.cwd))
|
|
148
171
|
|
|
172
|
+
// ── 系统提示:daemon 此前**一条都没有** ──────────────────────────────
|
|
173
|
+
// 后果不是「提示朴素一点」,而是整条 headless 路径上模型不知道自己是谁:
|
|
174
|
+
// MIPHAM.md 的身份段(集团 MIPHAM.md §〇,强制性)、CLAUDE.md 的项目规则、
|
|
175
|
+
// 记忆、skills 提醒**一条都到不了**经渠道(飞书 / Telegram / 企微 / 钉钉)、
|
|
176
|
+
// `attach` 远端、以及基准 harness 驱动的会话。
|
|
177
|
+
//
|
|
178
|
+
// 与 CLI 同源、同顺序(`index.tsx:524` + `:605-771`),只少三样**会话脚手架**:
|
|
179
|
+
// 首跑引导 / 密钥到期提醒 / 上一会话摘要 —— 它们属于「一次性的终端会话」,
|
|
180
|
+
// 而 daemon 一个进程服务多个会话,把它们烘进每个会话的提示只是噪音。
|
|
181
|
+
const instructions = loadInstructionsFor(opts.cwd)
|
|
182
|
+
engine.setInstructions(instructions)
|
|
183
|
+
|
|
184
|
+
const context = engine.getContext()
|
|
185
|
+
// 权限段**读时派生**。烘进去的会是模式的一份拷贝,而 daemon 的档位会经 `set_mode`
|
|
186
|
+
// 在会话中途变(`server.ts` 的 `sessionModes`):往窄切是自纠正的,**往宽切**则让
|
|
187
|
+
// 模型拿着旧指令拒绝做它已被允许做的事。接的是 live 的 `permission`,同一实例也交给
|
|
188
|
+
// 引擎去执行,故下一次请求就与新档一致。
|
|
189
|
+
context.setPermissionContextSource(() =>
|
|
190
|
+
instructions.buildPermissionBlock(engine.getPermission().getMode()),
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
const basePrompt = instructions.buildSystemPrompt()
|
|
194
|
+
const extras = [
|
|
195
|
+
skills.buildSystemReminder(5000, opts.skillsReminder ?? 'full'),
|
|
196
|
+
// 预算显式给 5000:`getMemoryManager()` 是进程级单例,跟着某个会话的窗口走会让
|
|
197
|
+
// 后建的会话改掉前一个的预算 —— daemon 的会话窗口各不相同,这是唯一不互相干扰的取值。
|
|
198
|
+
loadSessionMemories(basePrompt, 5000),
|
|
199
|
+
]
|
|
200
|
+
.filter((part) => part.length > 0)
|
|
201
|
+
.join('\n\n')
|
|
202
|
+
|
|
203
|
+
// `buildSystemPrompt()` 结尾**没有换行**,`extras` 以 `<system-reminder>` 开头:
|
|
204
|
+
// 直接相加会把标签粘在上一句末尾(CLI 侧 `index.tsx` 是 `\n\n` 连接)。建提示与
|
|
205
|
+
// 压缩后的重建必须走同一个连接方式,否则两条路径的提示形状会分叉。
|
|
206
|
+
const withExtras = (base: string): string => (extras ? `${base}\n\n${extras}` : base)
|
|
207
|
+
context.setSystemPrompt(withExtras(basePrompt))
|
|
208
|
+
// 压缩之后引擎会让提示重建一次;重建前先回读磁盘,**只换指令那一段**,`extras`
|
|
209
|
+
// 原样保留 —— 那是建会话时拼进来的会话级上下文,再生成一遍等于把它们重复塞进每个请求。
|
|
210
|
+
context.setSystemPromptRebuilder(() => {
|
|
211
|
+
instructions.refresh()
|
|
212
|
+
return withExtras(instructions.buildSystemPrompt())
|
|
213
|
+
})
|
|
214
|
+
|
|
149
215
|
// 语义等价于不接(`llmChat` 本就是 `this.llm ?? this.registry`),接上是为了让
|
|
150
216
|
// 两个入口的能力集合真的相等;D2 靠它证明「先修语义再对等」这条顺序约束。
|
|
151
217
|
engine.setLlm(opts.registry)
|
|
152
218
|
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* daemon 会话日志目录 —— **与 CLI 的 `~/.mipham/sessions` 分开**是设计的一部分。
|
|
222
|
+
*
|
|
223
|
+
* daemon 的历史真源是它自己的 SQLite(`daemon.db`,REST API 也读它),日志只记**本进程
|
|
224
|
+
* 窗口内**发生的事。若落进 `sessions/`,`SessionStore.list()` 会把它当成一个可恢复会话
|
|
225
|
+
* 列出来,而它的历史是不全的 —— 那就造出一个「看起来能恢复、恢复出来缺半截」的假广告,
|
|
226
|
+
* 正是本仓反复在修的那一类。分目录之后,`--resume` **结构上**够不到它。
|
|
227
|
+
*/
|
|
228
|
+
export function daemonSessionLogDir(): string {
|
|
229
|
+
return miphamHome('daemon-sessions')
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export interface DaemonSessionLogFacts {
|
|
233
|
+
sessionId: string
|
|
234
|
+
cwd: string
|
|
235
|
+
provider: string
|
|
236
|
+
model: string
|
|
237
|
+
permissionMode: string
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* 给 daemon 会话挂一份**审计用**日志 —— 收口「daemon 会话一条 JSONL 都不写」(ROADMAP T5)。
|
|
242
|
+
*
|
|
243
|
+
* 三条约束,每条都有后果:
|
|
244
|
+
*
|
|
245
|
+
* 1. **必须在 DB 回灌之后调用**(`server.ts` 里紧跟 `wireDaemonEngine`)。日志记的是
|
|
246
|
+
* 「本进程期间发生了什么」。把回灌的历史镜像进来会**重复追加**同一批消息 ——
|
|
247
|
+
* `WorkerPool` 会驱逐空闲 worker,重建引擎时那段历史会被再写一遍 ——
|
|
248
|
+
* 而且把一个审计增量伪装成完整历史。
|
|
249
|
+
* 2. **`authoritative: false`**:`ContextManager` 的「model-visible means logged」断言
|
|
250
|
+
* 只对**完整**日志有意义。残缺日志会让它对每一行旧历史报警,开着的调试断言会因此
|
|
251
|
+
* 炸掉整个 daemon 会话。关掉的是**断言**,写通照常。
|
|
252
|
+
* 3. 名字取 `daemon-<uuid>`:让人一眼看出它不是 CLI 的会话名。
|
|
253
|
+
*
|
|
254
|
+
* **已知边界(如实记)**:日志里 `compaction/summary` 的 `replacedCount` 是按**日志窗口**
|
|
255
|
+
* 算的(`context.ts` 用 `deriveMessages(log)` 的长度),不是按整段对话 —— 旧历史从没进过
|
|
256
|
+
* 这份日志。读审计文件时要知道这个数只对「被记录的那一段」成立。
|
|
257
|
+
*/
|
|
258
|
+
export function attachDaemonSessionLog(
|
|
259
|
+
engine: QueryEngine,
|
|
260
|
+
facts: DaemonSessionLogFacts,
|
|
261
|
+
): SessionLog {
|
|
262
|
+
const log = new SessionLog(`daemon-${facts.sessionId}`, daemonSessionLogDir())
|
|
263
|
+
log.append({
|
|
264
|
+
type: 'session/start',
|
|
265
|
+
at: Date.now(),
|
|
266
|
+
sessionId: facts.sessionId,
|
|
267
|
+
provider: facts.provider,
|
|
268
|
+
model: facts.model,
|
|
269
|
+
cwd: facts.cwd,
|
|
270
|
+
permissionMode: facts.permissionMode,
|
|
271
|
+
})
|
|
272
|
+
engine.getContext().setLog(log, { authoritative: false })
|
|
273
|
+
return log
|
|
274
|
+
}
|
package/src/daemon/server.ts
CHANGED
|
@@ -37,7 +37,7 @@ import { createDingtalkAdapter } from './dingtalk/adapter.js'
|
|
|
37
37
|
import { createDingtalkApi } from './dingtalk/api.js'
|
|
38
38
|
import type { DingtalkConfig } from './dingtalk/types.js'
|
|
39
39
|
import { startHeartbeat } from './heartbeat'
|
|
40
|
-
import { wireDaemonEngine } from './engine-capabilities'
|
|
40
|
+
import { wireDaemonEngine, attachDaemonSessionLog } from './engine-capabilities'
|
|
41
41
|
import {
|
|
42
42
|
cancelAllSessionTimers,
|
|
43
43
|
unregisterWakeupHandler,
|
|
@@ -293,6 +293,18 @@ export function createServer(config: ServerConfig): Server<WsData> {
|
|
|
293
293
|
cwd,
|
|
294
294
|
registry: sharedRegistry,
|
|
295
295
|
skillsPaths: daemonConfig.skills?.paths,
|
|
296
|
+
skillsReminder: daemonConfig.skills?.reminder,
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
// 审计日志必须在上面那次 DB 回灌**之后**挂 —— 它只记本进程窗口内发生的事,
|
|
300
|
+
// 镜像历史会在引擎重建时重复追加(WorkerPool 会驱逐空闲 worker)。
|
|
301
|
+
// 见 `attachDaemonSessionLog` 的三条约束。
|
|
302
|
+
attachDaemonSessionLog(engine, {
|
|
303
|
+
sessionId,
|
|
304
|
+
cwd,
|
|
305
|
+
provider,
|
|
306
|
+
model,
|
|
307
|
+
permissionMode: permission.getMode(),
|
|
296
308
|
})
|
|
297
309
|
engineCache.set(sessionId, engine)
|
|
298
310
|
return engine
|
|
@@ -481,6 +481,7 @@
|
|
|
481
481
|
"source_user": "user",
|
|
482
482
|
"source_project": "project",
|
|
483
483
|
"gated": "⚠️ workspace not trusted — will not run",
|
|
484
|
+
"undispatched": "⚠️ no dispatch point in this version — will not run",
|
|
484
485
|
"found": "{count} hook(s) found.",
|
|
485
486
|
"error": "── Hooks ──\n\nCould not read hooks directory."
|
|
486
487
|
},
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
export const PACKAGE_NAME = '@miphamai/cli' as const
|
|
10
10
|
|
|
11
11
|
/** 当前发布版本 */
|
|
12
|
-
export const PACKAGE_VERSION = '0.85.
|
|
12
|
+
export const PACKAGE_VERSION = '0.85.35' as const
|
|
13
13
|
|
|
14
14
|
/** npm install 全局安装命令 */
|
|
15
15
|
export const NPM_INSTALL_COMMAND = `npm install -g ${PACKAGE_NAME}` as const
|
|
@@ -90,4 +90,4 @@ export const TOOL_COUNT = 31 as const
|
|
|
90
90
|
* —— `test/e2e/full-pipeline.test.ts` 在 Linux 上整文件 skip、在 macOS 上跑 ——
|
|
91
91
|
* 但**总数相同**(两边都把被 skip 的算进去)。
|
|
92
92
|
*/
|
|
93
|
-
export const TEST_COUNT =
|
|
93
|
+
export const TEST_COUNT = 4814 as const
|
package/src/ui/commands.ts
CHANGED
|
@@ -19,6 +19,7 @@ import { McpClient } from '../mcp/client'
|
|
|
19
19
|
import { registerMcpServerTools, unregisterMcpServerTools } from '../mcp/registry'
|
|
20
20
|
import { buildCapabilityReport } from '../core/capability-inventory'
|
|
21
21
|
import { InstructionsLoader } from '../core/instructions'
|
|
22
|
+
import { UNDISPATCHED_EVENTS } from '../core/hooks-config'
|
|
22
23
|
import { findDerivableSections, DERIVABLE_HINTS } from '../core/claude-md-audit'
|
|
23
24
|
import { miphamHome, workflowScriptDir, workflowScriptDirs, worktreeRoot } from '../core/paths.ts'
|
|
24
25
|
import { fixDoctor, fixConfig, fixCache, selectRepoClaudeFiles } from '../core/fix'
|
|
@@ -4257,13 +4258,23 @@ const hooksCmd: CommandHandler = async (ctx) => {
|
|
|
4257
4258
|
|
|
4258
4259
|
let count = 0
|
|
4259
4260
|
for (const [eventName, bucket] of byEvent) {
|
|
4261
|
+
// These events have no dispatch point, so `loadHookConfigs` drops them. This
|
|
4262
|
+
// listing reads the *config files*, not the engine's registry, so it has to
|
|
4263
|
+
// apply the same verdict here — otherwise the entry looks installed and the
|
|
4264
|
+
// count says it will run. Rendered, not hidden: the marker is the honest
|
|
4265
|
+
// version of "we saw your hook and it will not fire". Excluded from `count`
|
|
4266
|
+
// because `found N` must mean "these will run".
|
|
4267
|
+
const undispatchable = UNDISPATCHED_EVENTS.has(eventName)
|
|
4260
4268
|
for (const { entry, project } of bucket) {
|
|
4261
4269
|
for (const hook of entry.hooks) {
|
|
4262
|
-
count++
|
|
4270
|
+
if (!undispatchable) count++
|
|
4263
4271
|
const matcher = entry.matcher || '*'
|
|
4264
4272
|
const cmd = hook.type === 'command' && hook.command ? hook.command : hook.type
|
|
4265
4273
|
const source = t(project ? 'commands.hooks.source_project' : 'commands.hooks.source_user')
|
|
4266
|
-
const
|
|
4274
|
+
const markers: string[] = []
|
|
4275
|
+
if (project && gated) markers.push(t('commands.hooks.gated'))
|
|
4276
|
+
if (undispatchable) markers.push(t('commands.hooks.undispatched'))
|
|
4277
|
+
const suffix = markers.map((marker) => ` ${marker}`).join('')
|
|
4267
4278
|
lines.push(` [${source}] ${eventName} [${matcher}] → ${cmd}${suffix}`)
|
|
4268
4279
|
}
|
|
4269
4280
|
}
|