mocode-ai 1.2.8 → 1.2.9
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/dist/agent/core.js +126 -43
- package/dist/config/index.js +31 -6
- package/dist/config/presets.js +36 -1
- package/dist/context/budget.js +0 -15
- package/dist/llm/index.js +33 -0
- package/dist/repl/index.js +57 -13
- package/dist/session/compact.js +237 -13
- package/dist/session/notes.js +63 -0
- package/dist/session/scheduler.js +5 -9
- package/dist/tools/constants.js +7 -0
- package/package.json +1 -1
- package/dist/__trace_manual_test__.js +0 -1
- package/dist/agent/core.d.ts +0 -112
- package/dist/agent/index.d.ts +0 -19
- package/dist/agent/mode.d.ts +0 -29
- package/dist/agent/retry-classifier.js +0 -64
- package/dist/agent/spawn.d.ts +0 -36
- package/dist/attachments/image.d.ts +0 -22
- package/dist/commands/config.d.ts +0 -8
- package/dist/commands/skill.js +0 -230
- package/dist/config/file.d.ts +0 -23
- package/dist/config/index.d.ts +0 -114
- package/dist/config/presets.d.ts +0 -57
- package/dist/context/budget.d.ts +0 -79
- package/dist/context/classifier.d.ts +0 -14
- package/dist/context/encoders/_util.d.ts +0 -11
- package/dist/context/encoders/code.d.ts +0 -2
- package/dist/context/encoders/doc.d.ts +0 -14
- package/dist/context/encoders/graph.d.ts +0 -11
- package/dist/context/encoders/graph.js +0 -81
- package/dist/context/encoders/index.d.ts +0 -2
- package/dist/context/encoders/log.d.ts +0 -2
- package/dist/context/encoders/log.js +0 -2
- package/dist/context/encoders/memory.d.ts +0 -2
- package/dist/context/encoders/passthrough.d.ts +0 -11
- package/dist/context/encoders/search.d.ts +0 -2
- package/dist/context/encoders/summary.d.ts +0 -12
- package/dist/context/encoders/table.d.ts +0 -2
- package/dist/context/encoders/tree.d.ts +0 -2
- package/dist/context/index.d.ts +0 -6
- package/dist/context/lifecycle.d.ts +0 -51
- package/dist/context/pipeline.d.ts +0 -9
- package/dist/context/registry.d.ts +0 -9
- package/dist/context/relevance.d.ts +0 -65
- package/dist/context/types.d.ts +0 -36
- package/dist/foo.js +0 -28
- package/dist/foo.test.js +0 -12
- package/dist/index.d.ts +0 -1
- package/dist/llm/capabilities.d.ts +0 -19
- package/dist/llm/index.d.ts +0 -111
- package/dist/memory/discover.d.ts +0 -15
- package/dist/memory/index.d.ts +0 -13
- package/dist/memory/reflect.d.ts +0 -34
- package/dist/memory/store.d.ts +0 -124
- package/dist/pet/bridge.d.ts +0 -73
- package/dist/pet/protocol.d.ts +0 -83
- package/dist/pet/state.d.ts +0 -28
- package/dist/plan/active.d.ts +0 -23
- package/dist/plan/active.js +0 -45
- package/dist/plan/index.d.ts +0 -13
- package/dist/plan/index.js +0 -33
- package/dist/plan/state.d.ts +0 -2
- package/dist/plan/state.js +0 -11
- package/dist/plan/store.d.ts +0 -78
- package/dist/plan/store.js +0 -429
- package/dist/project-skill/index.js +0 -95
- package/dist/project-skill/initializer.js +0 -178
- package/dist/project-snapshot/index.js +0 -85
- package/dist/project-snapshot/llm-snapshot.js +0 -150
- package/dist/project-snapshot/static-files.js +0 -87
- package/dist/repl/index.d.ts +0 -22
- package/dist/rollback/index.d.ts +0 -79
- package/dist/sandbox/command.d.ts +0 -3
- package/dist/sandbox/index.d.ts +0 -4
- package/dist/sandbox/jail.d.ts +0 -17
- package/dist/sandbox/policy.d.ts +0 -21
- package/dist/sandbox/root.d.ts +0 -5
- package/dist/session/compact.d.ts +0 -92
- package/dist/session/index.d.ts +0 -13
- package/dist/session/notes-plan.js +0 -41
- package/dist/session/persist.d.ts +0 -30
- package/dist/session/scheduler.d.ts +0 -53
- package/dist/skills/discover.d.ts +0 -33
- package/dist/skills/index.d.ts +0 -13
- package/dist/skills/skill-eval.js +0 -345
- package/dist/skills/skill-improve.js +0 -221
- package/dist/skills/stats.js +0 -102
- package/dist/tools/builtins/apply-patch.js +0 -174
- package/dist/tools/builtins/ask-human.d.ts +0 -9
- package/dist/tools/builtins/codegraph.d.ts +0 -2
- package/dist/tools/builtins/codegraph.js +0 -128
- package/dist/tools/builtins/edit-file.d.ts +0 -2
- package/dist/tools/builtins/glob.d.ts +0 -2
- package/dist/tools/builtins/grep.d.ts +0 -2
- package/dist/tools/builtins/index.d.ts +0 -2
- package/dist/tools/builtins/memory-forget.d.ts +0 -2
- package/dist/tools/builtins/memory-list.d.ts +0 -2
- package/dist/tools/builtins/memory-save.d.ts +0 -2
- package/dist/tools/builtins/memory-search.d.ts +0 -2
- package/dist/tools/builtins/memory-update.d.ts +0 -2
- package/dist/tools/builtins/project-skill-update.js +0 -102
- package/dist/tools/builtins/read-file.d.ts +0 -2
- package/dist/tools/builtins/run-command.d.ts +0 -2
- package/dist/tools/builtins/switch-mode.d.ts +0 -2
- package/dist/tools/builtins/switch-mode.js +0 -44
- package/dist/tools/builtins/task.d.ts +0 -2
- package/dist/tools/builtins/todolist.d.ts +0 -2
- package/dist/tools/builtins/todolist.js +0 -411
- package/dist/tools/builtins/use-skill.d.ts +0 -2
- package/dist/tools/builtins/web-fetch.d.ts +0 -2
- package/dist/tools/builtins/web-search.d.ts +0 -2
- package/dist/tools/builtins/write-file.d.ts +0 -2
- package/dist/tools/constants.d.ts +0 -52
- package/dist/tools/registry.d.ts +0 -18
- package/dist/tools/retry.js +0 -137
- package/dist/tools/types.d.ts +0 -42
- package/dist/ui/batch.d.ts +0 -67
- package/dist/ui/clipboard.d.ts +0 -9
- package/dist/ui/content.d.ts +0 -55
- package/dist/ui/diff.d.ts +0 -34
- package/dist/ui/intervention.d.ts +0 -46
- package/dist/ui/layout.d.ts +0 -225
- package/dist/ui/markdown.d.ts +0 -46
- package/dist/ui/mouse.d.ts +0 -29
- package/dist/ui/prompt.d.ts +0 -61
- package/dist/ui/render.d.ts +0 -60
- package/dist/ui/spinner.d.ts +0 -26
- package/dist/ui/theme.d.ts +0 -47
- package/dist/ui/thinking.js +0 -80
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export interface MemoryFile {
|
|
2
|
-
path: string;
|
|
3
|
-
content: string;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* 返回要查找的 MOCODE.md 路径列表,按「远→近」顺序(合并时近的在后,更突出):
|
|
7
|
-
* 全局 ~/.mocode/MOCODE.md → 项目级从根到 cwd 逐级 MOCODE.md。
|
|
8
|
-
* 向上遍历 cwd 到根收集 [cwd..root],反转为 [root..cwd](远→近),前拼全局。
|
|
9
|
-
*/
|
|
10
|
-
export declare function resolveMemoryFiles(): string[];
|
|
11
|
-
/**
|
|
12
|
-
* 读取所有存在的 MOCODE.md,返回 { path, content }(content 已 trim)。
|
|
13
|
-
* 全程静默容错(不存在 / 读失败 → 跳过,不抛),风格对齐 skills/discover.ts 与 session/persist.ts。
|
|
14
|
-
*/
|
|
15
|
-
export declare function loadMemoryFiles(): MemoryFile[];
|
package/dist/memory/index.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export { buildMemoryIndexSection, loadAll, gcMemories, type MemoryEntry, type MemoryIndexItem, type MemoryType, type MemoryStatus, type MemoryScope, } from './store.js';
|
|
2
|
-
export { kickoffReflection, drainMemoryBackground, getLastReflectResult, clearLastReflectResult, snapshotTranscript, formatReflectResult, runReflection, type ReflectResult, } from './reflect.js';
|
|
3
|
-
/**
|
|
4
|
-
* 合并全局 + 项目各级 MOCODE.md(远→近拼接,各段空行分隔),超 MAX_MEMORY_CHARS 截断 + 提示。
|
|
5
|
-
* 懒加载(首次调用触发扫描;启动期 repl 调一次)。无 MOCODE.md 返空串。
|
|
6
|
-
*/
|
|
7
|
-
export declare function loadMemory(): string;
|
|
8
|
-
/**
|
|
9
|
-
* 拼进系统提示的 memory 段(Tier-1 MOCODE.md);无 memory 返空串(零行为变化)。
|
|
10
|
-
* 记忆子系统总开关关闭(isMemoryEnabled()==false)直接返空串:
|
|
11
|
-
* 提示词、Memory Index 段都不进 — 配合 tools/builtins 把 memory_* 工具屏蔽。
|
|
12
|
-
*/
|
|
13
|
-
export declare function buildMemorySection(): string;
|
package/dist/memory/reflect.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { type ChatMessage } from '../llm/index.js';
|
|
2
|
-
export interface ReflectResult {
|
|
3
|
-
ts: string;
|
|
4
|
-
saves: number;
|
|
5
|
-
updates: number;
|
|
6
|
-
forgets: number;
|
|
7
|
-
gcDecayed: number;
|
|
8
|
-
gcCapped: number;
|
|
9
|
-
gcGced: number;
|
|
10
|
-
error?: string;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* 同步拍平最近 K 条对话(跳过 history[0] 大系统提示)。每条裁到 600 字符、总体裁到 6000,
|
|
14
|
-
* 控制反思 prompt 体积。在 kickoff 调用前同步取快照,异步 pass 用这份文本,不再读 history。
|
|
15
|
-
*/
|
|
16
|
-
export declare function snapshotTranscript(history: ChatMessage[], K: number): string;
|
|
17
|
-
/**
|
|
18
|
-
* 跑一次反思:chat() 空 handlers(静默)→ 解析 JSON → 经 store 落地 → gcMemories。
|
|
19
|
-
* 解析失败整 pass 放弃(不部分落地)。store 调用全同步,落地是一个原子块。
|
|
20
|
-
* 60s 超时(AbortSignal.timeout)防 exit 时 drain 挂死。
|
|
21
|
-
*/
|
|
22
|
-
export declare function runReflection(transcript: string, signal?: AbortSignal): Promise<ReflectResult>;
|
|
23
|
-
/** 摘要串(供 repl flush):存N 改N 忘N;有错误附上。 */
|
|
24
|
-
export declare function formatReflectResult(r: ReflectResult): string;
|
|
25
|
-
/**
|
|
26
|
-
* fire-and-forget 触发反思。已有在飞任务 / autoReflect 关闭 / 记忆子系统总开关关闭 → 跳过。
|
|
27
|
-
* 记忆关闭时反思毫无意义(没有可存的地方),且会误打日志、误弹摘要,故一并短路。
|
|
28
|
-
* repl 轮末调:与下一轮 agent 并发跑,不阻塞。
|
|
29
|
-
*/
|
|
30
|
-
export declare function kickoffReflection(transcript: string): void;
|
|
31
|
-
/** 退出前等在飞反思收尾(startRepl 尾调;Ctrl+C 走 SIGINT 直退不等)。 */
|
|
32
|
-
export declare function drainMemoryBackground(): Promise<void>;
|
|
33
|
-
export declare function getLastReflectResult(): ReflectResult | null;
|
|
34
|
-
export declare function clearLastReflectResult(): void;
|
package/dist/memory/store.d.ts
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
export type MemoryType = 'decision' | 'fact' | 'pitfall' | 'reference' | 'feedback';
|
|
2
|
-
export type MemoryStatus = 'active' | 'superseded' | 'archived';
|
|
3
|
-
export type MemoryScope = 'project' | 'global';
|
|
4
|
-
export interface MemoryEntry {
|
|
5
|
-
id: string;
|
|
6
|
-
type: MemoryType;
|
|
7
|
-
name: string;
|
|
8
|
-
summary: string;
|
|
9
|
-
body: string;
|
|
10
|
-
createdAt: string;
|
|
11
|
-
updatedAt: string;
|
|
12
|
-
lastRecalledAt: string | null;
|
|
13
|
-
recallCount: number;
|
|
14
|
-
status: MemoryStatus;
|
|
15
|
-
supersededBy: string | null;
|
|
16
|
-
pinned: boolean;
|
|
17
|
-
scope: MemoryScope;
|
|
18
|
-
source: {
|
|
19
|
-
session?: string;
|
|
20
|
-
turn?: number;
|
|
21
|
-
} | null;
|
|
22
|
-
lastUpdateReason?: string;
|
|
23
|
-
}
|
|
24
|
-
/** 索引项(无 body,不进 history 也不占 token)。 */
|
|
25
|
-
export interface MemoryIndexItem {
|
|
26
|
-
id: string;
|
|
27
|
-
name: string;
|
|
28
|
-
summary: string;
|
|
29
|
-
type: MemoryType;
|
|
30
|
-
status: MemoryStatus;
|
|
31
|
-
}
|
|
32
|
-
/** 加载全部(global + project),按文件归一化 scope(防旧条目缺字段 / 字段错)。 */
|
|
33
|
-
export declare function loadAll(): MemoryEntry[];
|
|
34
|
-
export interface SaveInput {
|
|
35
|
-
name: string;
|
|
36
|
-
summary: string;
|
|
37
|
-
body: string;
|
|
38
|
-
type?: MemoryType;
|
|
39
|
-
pinned?: boolean;
|
|
40
|
-
scope?: MemoryScope;
|
|
41
|
-
source?: {
|
|
42
|
-
session?: string;
|
|
43
|
-
turn?: number;
|
|
44
|
-
} | null;
|
|
45
|
-
}
|
|
46
|
-
export type SaveResult = {
|
|
47
|
-
ok: true;
|
|
48
|
-
id: string;
|
|
49
|
-
} | {
|
|
50
|
-
ok: false;
|
|
51
|
-
exists: string;
|
|
52
|
-
};
|
|
53
|
-
/** 新建:id 全局唯一(跨两文件),撞库返 exists 让工具层提示用 memory_update。 */
|
|
54
|
-
export declare function saveEntry(input: SaveInput): SaveResult;
|
|
55
|
-
export interface SearchOpts {
|
|
56
|
-
type?: MemoryType;
|
|
57
|
-
status?: MemoryStatus | 'any';
|
|
58
|
-
limit?: number;
|
|
59
|
-
}
|
|
60
|
-
/** 关键词搜索:多词子串匹配(name 权重最高)。命中即 bump recallCount/lastRecalledAt 写回(遗忘衰减依据)。 */
|
|
61
|
-
export declare function searchEntries(query: string, opts?: SearchOpts): MemoryEntry[];
|
|
62
|
-
/** 索引(无 body、不 bump recall)。 */
|
|
63
|
-
export declare function listEntries(opts?: {
|
|
64
|
-
type?: MemoryType;
|
|
65
|
-
status?: MemoryStatus | 'any';
|
|
66
|
-
}): MemoryIndexItem[];
|
|
67
|
-
export interface UpdatePatch {
|
|
68
|
-
name?: string;
|
|
69
|
-
summary?: string;
|
|
70
|
-
body?: string;
|
|
71
|
-
reason?: string;
|
|
72
|
-
pinned?: boolean;
|
|
73
|
-
}
|
|
74
|
-
export type UpdateResult = {
|
|
75
|
-
ok: true;
|
|
76
|
-
} | {
|
|
77
|
-
ok: false;
|
|
78
|
-
notFound: true;
|
|
79
|
-
};
|
|
80
|
-
/** 原地改:id 不变(name 可改 → 但 id 仍是旧 slug,故 name 改不会触发重 slug);记 lastUpdateReason;pinned 可切换。 */
|
|
81
|
-
export declare function updateEntry(id: string, patch: UpdatePatch): UpdateResult;
|
|
82
|
-
export type ForgetResult = {
|
|
83
|
-
ok: true;
|
|
84
|
-
mode: string;
|
|
85
|
-
} | {
|
|
86
|
-
ok: false;
|
|
87
|
-
notFound: true;
|
|
88
|
-
} | {
|
|
89
|
-
ok: false;
|
|
90
|
-
pinned: true;
|
|
91
|
-
};
|
|
92
|
-
/** 归档(默认,可复活)/ 硬删;pinned 拒删。 */
|
|
93
|
-
export declare function forgetEntry(id: string, mode?: 'archive' | 'delete'): ForgetResult;
|
|
94
|
-
export interface GcResult {
|
|
95
|
-
decayed: number;
|
|
96
|
-
capped: number;
|
|
97
|
-
gced: number;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* 遗忘策略(全同步,后台调):
|
|
101
|
-
* ① archived 超 GC_DAYS → 硬删;
|
|
102
|
-
* ② active + !pinned + (lastRecalledAt|createdAt) 早于 DECAY_DAYS → archived;
|
|
103
|
-
* ③ active 数 > MAX_ACTIVE → 按 recallCount 低 × 最近未召回久 淘汰到 archived。
|
|
104
|
-
* pinned 豁免一切自动衰减。写回两文件(均按 scope 过滤)。
|
|
105
|
-
*/
|
|
106
|
-
export declare function gcMemories(): GcResult;
|
|
107
|
-
/**
|
|
108
|
-
* active 条目按 updatedAt 降序,封顶 MAX_INDEX_ENTRIES,只注 id/name/summary/type。
|
|
109
|
-
* 无 active 返空串(零行为变化)。body 不注入——按需 memory_search 取。
|
|
110
|
-
*
|
|
111
|
-
* 索引策略(省 token):不全量塞进每轮 systemPrompt。
|
|
112
|
-
* - pinned 永远包含(pinned = 用户明确想长期保留)
|
|
113
|
-
* - recallCount ≥ 1 包含(被引用过,价值已验证)
|
|
114
|
-
* - 否则仅当 (lastRecalledAt|createdAt) 近 RECENT_MS(=DECAY_DAYS×2) 内
|
|
115
|
-
* 排序:pinned 先 → recallCount 降 → updatedAt 降。
|
|
116
|
-
* 封顶 MAX_INDEX_ENTRIES;尾部标 hidden 数量,引导用 memory_list/memory_search 兜底。
|
|
117
|
-
* 真正「陈旧」被滤掉时也明示(让 LLM 知道有内容存在但被策略隐藏,而不是误以为空)。
|
|
118
|
-
*
|
|
119
|
-
* memoryEnabled=false 时(记忆子系统总开关关闭)直接返空串:Memory Index 段
|
|
120
|
-
* 不进系统提示,LLM 看不到工具使用提示;配合 tools/builtins 屏蔽 memory_* 工具,
|
|
121
|
-
* 实现「关闭时零侵入」(默认行为)。传参由 repl 的 buildSystemMessage 在拼装前调
|
|
122
|
-
* isMemoryEnabled() 注入(本文件是叶子,避免直接引 config 起环)。
|
|
123
|
-
*/
|
|
124
|
-
export declare function buildMemoryIndexSection(memoryEnabled?: boolean): string;
|
package/dist/pet/bridge.d.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import WebSocket from 'ws';
|
|
2
|
-
import type { PetState, PetStateMeta, SkinListMessage } from './protocol.js';
|
|
3
|
-
/** 默认端口;MOCODE_PET_PORT 环境变量覆盖(design.md 默认假设)。 */
|
|
4
|
-
export declare const DEFAULT_PET_PORT = 47821;
|
|
5
|
-
/**
|
|
6
|
-
* 探测本地端口是否已有 WS server 监听并可完成一次 WS 握手。
|
|
7
|
-
* 前置条件:port 为合法端口号。
|
|
8
|
-
* 后置条件:返回 true 表示 <timeoutMs> 内握手成功(桌宠已在跑);false 表示超时/拒绝连接。
|
|
9
|
-
* 无副作用(探测用的临时连接在返回前关闭)。
|
|
10
|
-
*/
|
|
11
|
-
export declare function probePort(port: number, timeoutMs?: number): Promise<boolean>;
|
|
12
|
-
/**
|
|
13
|
-
* 拉起独立 Electron 桌宠进程(detached,不随当前 mocode 进程退出而杀死)。
|
|
14
|
-
* 前置条件:调用方已确认端口未被占用(避免重复 spawn)。
|
|
15
|
-
* 后置条件:
|
|
16
|
-
* - resolve() 表示 spawn 系统调用成功发出(不代表桌宠已可连接,调用方需配合 connectWithBackoff)。
|
|
17
|
-
* - reject(err) 表示可执行文件不可解析(mocode-pet-app 未安装/安装失败)——降级路径。
|
|
18
|
-
*/
|
|
19
|
-
export declare function spawnPetProcess(): Promise<void>;
|
|
20
|
-
/**
|
|
21
|
-
* 按退避序列重试连接,直到成功或耗尽重试次数。
|
|
22
|
-
* 前置条件:retryDelaysMs 非空、单调(本设计取 [200,400,800,1600,3200])。
|
|
23
|
-
* 后置条件:
|
|
24
|
-
* - resolve(ws) 表示某次尝试内 probePort/connect 成功。
|
|
25
|
-
* - reject(err) 表示所有尝试均失败,err 汇总最后一次失败原因。
|
|
26
|
-
* 循环不变量:每次尝试前 attempts < retryDelaysMs.length;每次失败后 attempts 严格 +1。
|
|
27
|
-
*/
|
|
28
|
-
export declare function connectWithBackoff(port: number, retryDelaysMs?: number[]): Promise<WebSocket>;
|
|
29
|
-
/**
|
|
30
|
-
* 发送一次状态消息(经节流:与上次发送状态相同则跳过)。
|
|
31
|
-
* 前置条件:无(未连接时静默 no-op,不抛错、不阻塞 agent 主循环)。
|
|
32
|
-
* 后置条件:若 state !== lastSentState,构造并发送一条合法 StateMessage;否则无副作用。
|
|
33
|
-
*/
|
|
34
|
-
export declare function sendState(state: PetState, meta?: PetStateMeta): void;
|
|
35
|
-
/** 当前是否已建立活跃连接。 */
|
|
36
|
-
export declare function isConnected(): boolean;
|
|
37
|
-
/** 主动断开连接(best-effort 发 bye 后 close code=1000)。 */
|
|
38
|
-
export declare function disconnect(): void;
|
|
39
|
-
/**
|
|
40
|
-
* 请求桌宠进程整体退出(方案C:CLI 侧退出入口;托盘图标是桌面侧的另一入口,见 packages/pet-app/src/main.ts)。
|
|
41
|
-
* 不要求本连接是活跃连接——任何已连接的 mocode 进程都可以关闭桌宠。
|
|
42
|
-
* 前置条件:当前进程已建立连接(未连接则先尝试探测端口直连,再发 shutdown)。
|
|
43
|
-
* 后置条件:发送 shutdown 消息后主动断开本地连接;不等待桌宠进程确认退出(best-effort,不阻塞 REPL)。
|
|
44
|
-
*/
|
|
45
|
-
export declare function killPetProcess(): Promise<{
|
|
46
|
-
ok: boolean;
|
|
47
|
-
reason?: string;
|
|
48
|
-
}>;
|
|
49
|
-
/**
|
|
50
|
-
* 请求当前可用皮肤列表(供 /pet skin 菜单展示)。
|
|
51
|
-
* 前置条件:当前进程已建立连接(未连接则先尝试探测端口直连;若桌宠未运行则失败)。
|
|
52
|
-
* 后置条件:resolve 桌宠回复的 SkinListMessage;超时(2s 内无回复)reject。
|
|
53
|
-
*/
|
|
54
|
-
export declare function listSkins(): Promise<SkinListMessage>;
|
|
55
|
-
/**
|
|
56
|
-
* 请求桌宠切换皮肤(选宠物)。
|
|
57
|
-
* 前置条件:当前进程已建立连接(未连接则静默 no-op,与 sendState 的降级策略一致)。
|
|
58
|
-
* 后置条件:已连接时发送 set_skin 消息;未连接时不抛错、无副作用。
|
|
59
|
-
*/
|
|
60
|
-
export declare function setSkin(skinId: string): void;
|
|
61
|
-
/**
|
|
62
|
-
* /pet 命令入口。
|
|
63
|
-
* 前置条件:REPL 主循环已初始化(不要求 agent 正在运行)。
|
|
64
|
-
* 后置条件:
|
|
65
|
-
* - 若调用前无活跃连接:调用后 either 已建立连接(connected=true)
|
|
66
|
-
* 或已尝试 spawn+重试全部失败(connected=false,附错误原因)。
|
|
67
|
-
* - 若调用前有活跃连接:调用后连接已关闭(connected=false)。
|
|
68
|
-
* 不抛异常(所有失败路径转为返回值,供 REPL 渲染提示行)。
|
|
69
|
-
*/
|
|
70
|
-
export declare function togglePet(): Promise<{
|
|
71
|
-
connected: boolean;
|
|
72
|
-
reason?: string;
|
|
73
|
-
}>;
|
package/dist/pet/protocol.d.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/** 桌宠状态集合。子 agent(task 工具派生)永不产生这些状态——只在主 agent hooks 组装处广播。 */
|
|
2
|
-
export type PetState = 'idle' | 'thinking' | 'speaking' | 'tool_call' | 'done' | 'aborted' | 'error' | 'waiting_human';
|
|
3
|
-
/** 全部合法状态值(供运行时校验,如 Set 成员判断)。 */
|
|
4
|
-
export declare const PET_STATES: readonly PetState[];
|
|
5
|
-
/** 状态负载:随 state 消息携带的可选元数据。 */
|
|
6
|
-
export interface PetStateMeta {
|
|
7
|
-
/** 仅 tool_call 状态携带:当前调用的工具名(如 "write_file")。 */
|
|
8
|
-
toolName?: string;
|
|
9
|
-
/** 仅 error 状态携带:简短错误摘要(截断,不含敏感路径/密钥)。 */
|
|
10
|
-
errorMessage?: string;
|
|
11
|
-
}
|
|
12
|
-
/** 每个 mocode 进程生成一次,进程存活期间稳定。 */
|
|
13
|
-
export type ClientId = string;
|
|
14
|
-
export interface HelloMessage {
|
|
15
|
-
type: 'hello';
|
|
16
|
-
clientId: ClientId;
|
|
17
|
-
pid: number;
|
|
18
|
-
cwd: string;
|
|
19
|
-
ts: number;
|
|
20
|
-
}
|
|
21
|
-
export interface StateMessage {
|
|
22
|
-
type: 'state';
|
|
23
|
-
clientId: ClientId;
|
|
24
|
-
state: PetState;
|
|
25
|
-
meta?: PetStateMeta;
|
|
26
|
-
ts: number;
|
|
27
|
-
}
|
|
28
|
-
export interface PingMessage {
|
|
29
|
-
type: 'ping';
|
|
30
|
-
ts: number;
|
|
31
|
-
}
|
|
32
|
-
export interface ByeMessage {
|
|
33
|
-
type: 'bye';
|
|
34
|
-
clientId: ClientId;
|
|
35
|
-
ts: number;
|
|
36
|
-
}
|
|
37
|
-
/** 主动请求桌宠进程整体退出(与 disconnect 不同:disconnect 只断开本连接,shutdown 让桌宠 app.quit())。
|
|
38
|
-
* 不要求发送方是当前活跃连接——任何已连接的 mocode 进程都可以关闭桌宠(见 Requirement 补充:关闭桌宠)。 */
|
|
39
|
-
export interface ShutdownMessage {
|
|
40
|
-
type: 'shutdown';
|
|
41
|
-
clientId: ClientId;
|
|
42
|
-
ts: number;
|
|
43
|
-
}
|
|
44
|
-
/** 请求切换桌宠皮肤(选宠物)。skinId 对应 assets/pets/manifest.json 里的 id,空字符串/'default' 表示恢复默认 mascot.svg。 */
|
|
45
|
-
export interface SetSkinMessage {
|
|
46
|
-
type: 'set_skin';
|
|
47
|
-
clientId: ClientId;
|
|
48
|
-
skinId: string;
|
|
49
|
-
ts: number;
|
|
50
|
-
}
|
|
51
|
-
/** 请求当前可用皮肤列表(触发 server 回复 SkinListMessage)。 */
|
|
52
|
-
export interface ListSkinsMessage {
|
|
53
|
-
type: 'list_skins';
|
|
54
|
-
ts: number;
|
|
55
|
-
}
|
|
56
|
-
export type ClientMessage = HelloMessage | StateMessage | PingMessage | ByeMessage | ShutdownMessage | SetSkinMessage | ListSkinsMessage;
|
|
57
|
-
export interface WelcomeMessage {
|
|
58
|
-
type: 'welcome';
|
|
59
|
-
isActive: boolean;
|
|
60
|
-
ts: number;
|
|
61
|
-
}
|
|
62
|
-
export interface PongMessage {
|
|
63
|
-
type: 'pong';
|
|
64
|
-
ts: number;
|
|
65
|
-
}
|
|
66
|
-
/** 皮肤列表(供 /pet skin 菜单展示)。桌宠进程回复,ids 对应 assets/pets/ 下的候选素材。 */
|
|
67
|
-
export interface SkinListMessage {
|
|
68
|
-
type: 'skin_list';
|
|
69
|
-
skins: {
|
|
70
|
-
id: string;
|
|
71
|
-
name: string;
|
|
72
|
-
}[];
|
|
73
|
-
currentSkinId: string;
|
|
74
|
-
ts: number;
|
|
75
|
-
}
|
|
76
|
-
export type ServerMessage = WelcomeMessage | PongMessage | SkinListMessage;
|
|
77
|
-
/** 判断值是否为合法 PetState(供消息校验,非法值丢弃不崩)。 */
|
|
78
|
-
export declare function isValidPetState(v: unknown): v is PetState;
|
|
79
|
-
/** 校验并解析一条原始 JSON 字符串为 ClientMessage;失败(JSON 非法/缺字段/type 未知)返回 null。
|
|
80
|
-
* 永不抛错——调用方(bridge/server)据此静默丢弃畸形消息,不断开连接。 */
|
|
81
|
-
export declare function parseClientMessage(raw: string): ClientMessage | null;
|
|
82
|
-
/** 校验并解析一条原始 JSON 字符串为 ServerMessage;失败返回 null(同上,永不抛错)。 */
|
|
83
|
-
export declare function parseServerMessage(raw: string): ServerMessage | null;
|
package/dist/pet/state.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { AgentHooks } from '../agent/core.js';
|
|
2
|
-
import type { PetState } from './protocol.js';
|
|
3
|
-
import * as bridge from './bridge.js';
|
|
4
|
-
/** AgentHooks 方法名(供 deriveState 的 event 参数类型与穷举测试)。 */
|
|
5
|
-
export type AgentHookEventName = 'onStepStart' | 'onText' | 'onToolCall' | 'onToolStart' | 'onToolResult' | 'onDone' | 'onAbort' | 'onMaxSteps' | 'onChatDone' | 'onToolBatchEnd' | 'onNoReply';
|
|
6
|
-
/** deriveState 的可选参数(按事件类型而异)。 */
|
|
7
|
-
export interface DeriveStateArgs {
|
|
8
|
-
/** onToolCall / onToolStart 的工具名。 */
|
|
9
|
-
toolName?: string;
|
|
10
|
-
/** onToolResult 的输出(用于判断是否报错:以"错误"开头,参考 agent/index.ts writeToolResult)。 */
|
|
11
|
-
toolOutput?: string;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* 纯函数:给定当前 hook 事件与其参数,推导下一个 PetState。
|
|
15
|
-
* 前置条件:event 是 AgentHooks 定义的方法名之一。
|
|
16
|
-
* 后置条件:返回值 ∈ PetState 枚举;对同一 (event, args) 输入,任意调用时刻返回值相同(确定性,可测)。
|
|
17
|
-
* 不依赖调用历史之外的隐藏状态——纯函数式转移表。
|
|
18
|
-
*/
|
|
19
|
-
export declare function deriveState(event: AgentHookEventName, args?: DeriveStateArgs): PetState;
|
|
20
|
-
/**
|
|
21
|
-
* 把 AgentHooks 事件流映射为 PetState 变化并调用 bridge.sendState。
|
|
22
|
-
* 前置条件:传入的 sender 已存在(可能尚未连接,sendState 内部自行处理未连接情形——no-op)。
|
|
23
|
-
* 后置条件:返回的 AgentHooks 对象的每个方法都是纯粹的"状态推导 + 转发",
|
|
24
|
-
* 不修改 core.ts 的任何行为、不影响现有 TUI hooks 的调用结果。
|
|
25
|
-
*/
|
|
26
|
-
export declare function createPetHooks(sender?: {
|
|
27
|
-
sendState: typeof bridge.sendState;
|
|
28
|
-
}): AgentHooks;
|
package/dist/plan/active.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { Plan } from './store.js';
|
|
2
|
-
export interface ActivePlanSnapshot {
|
|
3
|
-
id: string;
|
|
4
|
-
title: string;
|
|
5
|
-
status: Plan['status'];
|
|
6
|
-
done: number;
|
|
7
|
-
total: number;
|
|
8
|
-
}
|
|
9
|
-
type Listener = (snap: ActivePlanSnapshot | null) => void;
|
|
10
|
-
/** 取当前活跃 plan(完整对象,工具用)。无 → null。 */
|
|
11
|
-
export declare function getActivePlan(): Plan | null;
|
|
12
|
-
/** 设活跃 plan。同一 id 重复设也走 listener(repl 借此刷 status 行——即使内容未变,显式刷新有助)。 */
|
|
13
|
-
export declare function setActivePlan(plan: Plan | null): void;
|
|
14
|
-
/** 清活跃 plan(plan finish/abandon 后由 repl/todolist 调)。 */
|
|
15
|
-
export declare function clearActivePlan(): void;
|
|
16
|
-
/** 注册活跃 plan 变更监听器。返注销函数(不常用,模式 listener 一次性常驻)。 */
|
|
17
|
-
export declare function onActivePlanChange(cb: Listener): () => void;
|
|
18
|
-
/** 是否有活跃 plan(in_progress 状态)。finished/abandoned 不算「活跃」。 */
|
|
19
|
-
export declare function hasActivePlan(): boolean;
|
|
20
|
-
/** 给 status 行用的极简摘要(避免调用方读 Plan 全字段)。无 → 空串。 */
|
|
21
|
-
/** 状态行 chip 用的短摘要(无 ANSI 颜色,由 layout 上色)。maxWidth 默认 56,留 room 给右段。 */
|
|
22
|
-
export declare function getActivePlanSummary(maxWidth?: number): string;
|
|
23
|
-
export {};
|
package/dist/plan/active.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
// 活跃 plan 进程级缓存:单 plan/会话的内存状态 + 变更通知。
|
|
2
|
-
//
|
|
3
|
-
// 仿 src/agent/mode.ts 形态:零依赖、setter/getter/listener,不反向引用业务。
|
|
4
|
-
// todo 工具每次改 plan → 调 setActivePlan(newPlan) → listener 触发(repl 刷 status 行 + history[0])。
|
|
5
|
-
// store 仍是文件源(本缓存与之可能短暂不一致——以文件为准,缓存仅供快速读)。
|
|
6
|
-
import { renderPlanChip } from './store.js';
|
|
7
|
-
let active = null;
|
|
8
|
-
const listeners = new Set();
|
|
9
|
-
/** 取当前活跃 plan(完整对象,工具用)。无 → null。 */
|
|
10
|
-
export function getActivePlan() {
|
|
11
|
-
return active;
|
|
12
|
-
}
|
|
13
|
-
/** 设活跃 plan。同一 id 重复设也走 listener(repl 借此刷 status 行——即使内容未变,显式刷新有助)。 */
|
|
14
|
-
export function setActivePlan(plan) {
|
|
15
|
-
active = plan;
|
|
16
|
-
const snap = plan ? toSnapshot(plan) : null;
|
|
17
|
-
for (const cb of listeners) {
|
|
18
|
-
try {
|
|
19
|
-
cb(snap);
|
|
20
|
-
}
|
|
21
|
-
catch { /* listener 抛错不阻断其他 listener */ }
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
/** 清活跃 plan(plan finish/abandon 后由 repl/todolist 调)。 */
|
|
25
|
-
export function clearActivePlan() {
|
|
26
|
-
setActivePlan(null);
|
|
27
|
-
}
|
|
28
|
-
/** 注册活跃 plan 变更监听器。返注销函数(不常用,模式 listener 一次性常驻)。 */
|
|
29
|
-
export function onActivePlanChange(cb) {
|
|
30
|
-
listeners.add(cb);
|
|
31
|
-
return () => listeners.delete(cb);
|
|
32
|
-
}
|
|
33
|
-
/** 是否有活跃 plan(in_progress 状态)。finished/abandoned 不算「活跃」。 */
|
|
34
|
-
export function hasActivePlan() {
|
|
35
|
-
return active !== null && active.status === 'in_progress';
|
|
36
|
-
}
|
|
37
|
-
/** 给 status 行用的极简摘要(避免调用方读 Plan 全字段)。无 → 空串。 */
|
|
38
|
-
/** 状态行 chip 用的短摘要(无 ANSI 颜色,由 layout 上色)。maxWidth 默认 56,留 room 给右段。 */
|
|
39
|
-
export function getActivePlanSummary(maxWidth = 56) {
|
|
40
|
-
return renderPlanChip(active, maxWidth);
|
|
41
|
-
}
|
|
42
|
-
function toSnapshot(p) {
|
|
43
|
-
const done = p.steps.filter((s) => s.status === 'done' || s.status === 'skipped').length;
|
|
44
|
-
return { id: p.id, title: p.title, status: p.status, done, total: p.steps.length };
|
|
45
|
-
}
|
package/dist/plan/index.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export { type Plan, type PlanStep, type PlanStatus, type StepStatus, plansDir, archiveDir, planPath, ensurePlansDir, ensureArchiveDir, newPlanId, parsePlan, serializePlan, readPlan, writePlan, deletePlan, deletePlanAnywhere, updatePlan, listPlans, archivePlan, unarchivePlan, renderPlanForLLM, renderPlanChip, } from './store.js';
|
|
2
|
-
export { type ActivePlanSnapshot, getActivePlan, setActivePlan, clearActivePlan, onActivePlanChange, hasActivePlan, getActivePlanSummary, } from './active.js';
|
|
3
|
-
/**
|
|
4
|
-
* 拼给 systemPrompt 注入的活跃 plan 摘要段。
|
|
5
|
-
* - 无活跃 plan → 空串(repl 直接跳过拼接,systemPrompt 长度不变)。
|
|
6
|
-
* - 有 → 紧凑 markdown(目标 + 步骤 checkbox + 进度日志末 5 条),header + 内容。
|
|
7
|
-
*
|
|
8
|
-
* 触发:setActivePlan 后由 repl listener 调;也供 buildSystemMessage 直接同步取(repl 入口)。
|
|
9
|
-
* 上限:超 MAX_ACTIVE_PLAN_CHARS 截到尾部(罕见,plan 文件本身就小)。
|
|
10
|
-
*/
|
|
11
|
-
export declare function buildActivePlanSection(): string;
|
|
12
|
-
/** 注入 systemPrompt 的活跃 plan 摘要上限(字符)。 */
|
|
13
|
-
export declare const MAX_ACTIVE_PLAN_CHARS = 3000;
|
package/dist/plan/index.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
// plan 子系统 barrel:
|
|
2
|
-
// - store:文件级 CRUD(markdown 解析/序列化,落盘原子)
|
|
3
|
-
// - active:进程级活跃 plan 缓存 + 变更通知(单 plan/会话)
|
|
4
|
-
// - buildActivePlanSection:给 systemPrompt 用的活跃 plan 摘要段
|
|
5
|
-
//
|
|
6
|
-
// 被 repl 依赖(注入 systemPrompt + 状态行 + listener 注册)+ tools/builtins/todolist 依赖。
|
|
7
|
-
export {
|
|
8
|
-
// store
|
|
9
|
-
plansDir, archiveDir, planPath, ensurePlansDir, ensureArchiveDir, newPlanId, parsePlan, serializePlan, readPlan, writePlan, deletePlan, deletePlanAnywhere, updatePlan, listPlans, archivePlan, unarchivePlan, renderPlanForLLM, renderPlanChip, } from './store.js';
|
|
10
|
-
export { getActivePlan, setActivePlan, clearActivePlan, onActivePlanChange, hasActivePlan, getActivePlanSummary, } from './active.js';
|
|
11
|
-
import { getActivePlan } from './active.js';
|
|
12
|
-
import { renderPlanForLLM } from './store.js';
|
|
13
|
-
const ACTIVE_PLAN_HEADER = '## 当前活跃计划';
|
|
14
|
-
/**
|
|
15
|
-
* 拼给 systemPrompt 注入的活跃 plan 摘要段。
|
|
16
|
-
* - 无活跃 plan → 空串(repl 直接跳过拼接,systemPrompt 长度不变)。
|
|
17
|
-
* - 有 → 紧凑 markdown(目标 + 步骤 checkbox + 进度日志末 5 条),header + 内容。
|
|
18
|
-
*
|
|
19
|
-
* 触发:setActivePlan 后由 repl listener 调;也供 buildSystemMessage 直接同步取(repl 入口)。
|
|
20
|
-
* 上限:超 MAX_ACTIVE_PLAN_CHARS 截到尾部(罕见,plan 文件本身就小)。
|
|
21
|
-
*/
|
|
22
|
-
export function buildActivePlanSection() {
|
|
23
|
-
const p = getActivePlan();
|
|
24
|
-
if (!p)
|
|
25
|
-
return '';
|
|
26
|
-
const body = renderPlanForLLM(p);
|
|
27
|
-
const full = `${ACTIVE_PLAN_HEADER}\n${body}`;
|
|
28
|
-
if (full.length <= MAX_ACTIVE_PLAN_CHARS)
|
|
29
|
-
return full;
|
|
30
|
-
return full.slice(0, MAX_ACTIVE_PLAN_CHARS) + '\n…(plan 摘要已截断)';
|
|
31
|
-
}
|
|
32
|
-
/** 注入 systemPrompt 的活跃 plan 摘要上限(字符)。 */
|
|
33
|
-
export const MAX_ACTIVE_PLAN_CHARS = 3000;
|
package/dist/plan/state.d.ts
DELETED
package/dist/plan/state.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// 活跃 plan 的进程级状态(共享叶子)。
|
|
2
|
-
//
|
|
3
|
-
// 职责:
|
|
4
|
-
// - 跟踪「当前会话的活跃 plan」——单 plan/会话(state 缓存,store 是文件源)。
|
|
5
|
-
// - 暴露 onActivePlanChange listener(repl 借此刷 status 行 + history[0])。
|
|
6
|
-
//
|
|
7
|
-
// 与 mode.ts 同形态:零依赖、不落盘、不反向引用业务;被 plan/、tools/builtins/todolist.ts、repl 依赖。
|
|
8
|
-
//
|
|
9
|
-
// 不在子 agent 持久化(子 agent 走 spawn,独立 history,不该继承主 plan——但 plan 文件本身在 sandboxRoot
|
|
10
|
-
// 下,子 agent 仍能 readPlan 看到全部历史 plan;state 缓存不传,只属于主 agent)。
|
|
11
|
-
export { getActivePlan, setActivePlan, clearActivePlan, onActivePlanChange, hasActivePlan, getActivePlanSummary, } from './active.js';
|
package/dist/plan/store.d.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
export type StepStatus = 'pending' | 'in_progress' | 'done' | 'skipped' | 'failed';
|
|
2
|
-
export interface PlanStep {
|
|
3
|
-
/** 1-based 序号(在当前 plan 内稳定,即便中间 add_step 也不重用旧号——见 addStep)。 */
|
|
4
|
-
id: number;
|
|
5
|
-
title: string;
|
|
6
|
-
status: StepStatus;
|
|
7
|
-
}
|
|
8
|
-
export type PlanStatus = 'in_progress' | 'finished' | 'abandoned';
|
|
9
|
-
export interface Plan {
|
|
10
|
-
id: string;
|
|
11
|
-
title: string;
|
|
12
|
-
status: PlanStatus;
|
|
13
|
-
created: string;
|
|
14
|
-
updated: string;
|
|
15
|
-
goal: string;
|
|
16
|
-
steps: PlanStep[];
|
|
17
|
-
/** 进度日志条目(时间戳 + 一行说明),append-only。 */
|
|
18
|
-
log: {
|
|
19
|
-
at: string;
|
|
20
|
-
text: string;
|
|
21
|
-
}[];
|
|
22
|
-
}
|
|
23
|
-
/** plans 目录:<sandboxRoot>/.mocode/plans/。无 sandboxRoot 退到 cwd(防御)。 */
|
|
24
|
-
export declare function plansDir(): string;
|
|
25
|
-
/** 归档目录:<root>/.mocode/plans/archive/。finish 自动归档、用户手动 unarchive 都走这里。 */
|
|
26
|
-
export declare function archiveDir(): string;
|
|
27
|
-
/** 单 plan 文件路径:<root>/.mocode/plans/<id>.md。可选 baseDir:默认 plans,也可指 archive。 */
|
|
28
|
-
export declare function planPath(id: string, baseDir?: string): string;
|
|
29
|
-
/** 确保 plans 目录存在(惰性,工具每次写前调)。 */
|
|
30
|
-
export declare function ensurePlansDir(): void;
|
|
31
|
-
/** 确保归档目录存在(惰性)。 */
|
|
32
|
-
export declare function ensureArchiveDir(): void;
|
|
33
|
-
/** 本地时间戳(无时区后缀),与 filename 的 YYYY-MM-DDTHH-mm-ss 风格一致。
|
|
34
|
-
* 例:2026-07-04T22:54:51.729(本地时,便于人对读 frontmatter / progress log,
|
|
35
|
-
* 且与同 plan id 文件名"2026-07-04T22-54-51"对应)。
|
|
36
|
-
* 不带 Z 后缀 → JS Date 解析会按本地时读(一致 round-trip);
|
|
37
|
-
* 反例:toISOString() 返 2026-07-04T14:54:51.729Z(UTC),跟用户当地差 8 小时,易误解。 */
|
|
38
|
-
export declare function localIsoTimestamp(d?: Date): string;
|
|
39
|
-
/** plan id:YYYY-MM-DDTHH-mm-ss-xxxxxx(本地时间,文件名安全)。xxxxxx = 4 字节随机 hex(防同秒并发撞)。 */
|
|
40
|
-
export declare function newPlanId(now?: Date): string;
|
|
41
|
-
/**
|
|
42
|
-
* 解析 plan 文件为 Plan 对象。失败(无 frontmatter / 段缺失 / 坏 checkbox)→ 退化:
|
|
43
|
-
* - 无 frontmatter:把整文当 title 段
|
|
44
|
-
* - 缺字段:空串 / 空数组
|
|
45
|
-
* - 坏 checkbox:跳过该行,不污染好行
|
|
46
|
-
* 解析成功但 step id 缺序 / 重号:按出现顺序重排为 1..N(保稳定)。
|
|
47
|
-
*/
|
|
48
|
-
export declare function parsePlan(raw: string, fallbackId: string): Plan;
|
|
49
|
-
/** 序列化为 markdown 文本。固定段序:frontmatter → 目标 → 步骤 → 进度日志。 */
|
|
50
|
-
export declare function serializePlan(p: Plan): string;
|
|
51
|
-
/** 读 plan 文件;不存在 → null,坏文件 → fallbackId 最小可用 Plan(不抛,工具契约)。
|
|
52
|
-
* 可选 baseDir:默认 plans,传 archiveDir() 可读归档。 */
|
|
53
|
-
export declare function readPlan(id: string, baseDir?: string): Plan | null;
|
|
54
|
-
/** 写 plan 文件(atomic:写 .tmp 再 rename)。返回是否成功。 */
|
|
55
|
-
export declare function writePlan(p: Plan): boolean;
|
|
56
|
-
/** 删 plan 文件;不存在静默 ok。可选 baseDir:默认 plans,传 archiveDir() 删归档。 */
|
|
57
|
-
export declare function deletePlan(id: string, baseDir?: string): boolean;
|
|
58
|
-
/**
|
|
59
|
-
* 原子读-改-写:读 → mutator 改 → 写。mutator 返回 false 视为"无改动",跳过写。
|
|
60
|
-
* mutator 抛错 → 写失败 → 返 null(不抛,工具契约)。
|
|
61
|
-
*
|
|
62
|
-
* mutator 同步:本 store 走同步 fs,mutator 必须同步(返 Promise 视为"无信号"——返原对象);
|
|
63
|
-
* 设计如此以避免把 fs API 改成 async(同步 fs 在 node 单 tick 原子,无需锁)。
|
|
64
|
-
*/
|
|
65
|
-
export declare function updatePlan(id: string, mutator: (p: Plan) => Plan | false): Plan | null;
|
|
66
|
-
/** 列 plans 目录下所有 plan(按 updated 倒序,最新在前)。解析失败的跳过。
|
|
67
|
-
* scope: 'active'(默认)=仅 plans/;'archived'=仅 archive/;'all'=合并(去重按 id)。 */
|
|
68
|
-
export declare function listPlans(scope?: 'active' | 'archived' | 'all'): Plan[];
|
|
69
|
-
/** 把 plans/<id>.md mv 到 plans/archive/<id>.md(atomic rename)。
|
|
70
|
-
* 源不存在 → false(已归档 / 删了 / 从未存在都算)。 */
|
|
71
|
-
export declare function archivePlan(id: string): boolean;
|
|
72
|
-
/** 把 plans/archive/<id>.md 还原到 plans/<id>.md。源不存在 → false。 */
|
|
73
|
-
export declare function unarchivePlan(id: string): boolean;
|
|
74
|
-
/** 任一处存在就都删(活跃 + 归档)。用于 todolist delete 不关心来源。 */
|
|
75
|
-
export declare function deletePlanAnywhere(id: string): boolean;
|
|
76
|
-
/** 把 Plan 渲成给 LLM 看的紧凑摘要(多行文本)。 */
|
|
77
|
-
export declare function renderPlanForLLM(p: Plan): string;
|
|
78
|
-
export declare function renderPlanChip(p: Plan | null, maxWidth?: number): string;
|