@deepmaid/maid-cron 0.0.0-stage → 0.1.0-alpha.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 kenyonxu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ - insert:
2
+ - id: deepmaid-maid-cron
3
+ name: '@deepmaid/maid-cron'
package/lib/index.d.ts ADDED
@@ -0,0 +1,191 @@
1
+ import { DeliveryAddress, MaidDelivery } from "@deepmaid/maid-delivery";
2
+ //#region src/schedule.d.ts
3
+ type JobSchedule = {
4
+ cron: string;
5
+ timezone: string;
6
+ } | {
7
+ everyMinutes: number;
8
+ } | {
9
+ once: string;
10
+ };
11
+ /** 下一次 due(epoch ms);null = 沉寂(once 已过/表达式非法)。fromMs 语义:从该时刻起算下一次。 */
12
+ declare function nextDueAfter(schedule: JobSchedule, fromMs: number): number | null;
13
+ //#endregion
14
+ //#region src/jobs.d.ts
15
+ declare const BRIEFING_TEMPLATE_DEFAULT: string;
16
+ interface ScriptSpec {
17
+ command: string;
18
+ args?: string[];
19
+ cwd?: string;
20
+ timeoutMs?: number;
21
+ env?: Record<string, string>;
22
+ }
23
+ interface JobDeclaration {
24
+ maidId: string;
25
+ type?: string;
26
+ name?: string;
27
+ enabled?: boolean;
28
+ schedule: JobSchedule;
29
+ promptTemplate?: string;
30
+ target?: DeliveryAddress;
31
+ genTimeoutMs?: number;
32
+ script?: ScriptSpec;
33
+ deliverLocalDir?: string;
34
+ /**
35
+ * 固定路径落盘目的地(Task 12):存在即产物写盘、不投递(优先于 deliverLocalDir/target;
36
+ * script 型与 llm 型共用)。路径支持 `{{date}}` 占位 → job 时区 ISO 日期(YYYY-MM-DD,
37
+ * isoDateOf)。**job 声明者负责写成 per-maid 路径**(如 `<stateDir>/doris/overnight-{{date}}.txt`
38
+ * ——maid-voice 读取端按 `<stateDir>/<maidId>/overnight-<date>.txt` 约定读取),防多女仆串档。
39
+ */
40
+ persistTo?: string;
41
+ recentLimit?: number;
42
+ skipOnEmptyScriptOutput?: boolean;
43
+ }
44
+ interface CompiledJob {
45
+ jobId: string;
46
+ type: string;
47
+ maidId: string;
48
+ enabled: boolean;
49
+ kind: 'script' | 'llm';
50
+ promptTemplate: string;
51
+ script: ScriptSpec | undefined;
52
+ deliverLocalDir: string | undefined;
53
+ persistTo: string | undefined;
54
+ recentLimit: number | undefined;
55
+ skipOnEmptyScriptOutput: boolean;
56
+ target: DeliveryAddress | null;
57
+ genTimeoutMs: number;
58
+ schedule: JobSchedule;
59
+ }
60
+ declare function compileJobs(jobs: readonly JobDeclaration[] | undefined, warn: (m: string) => void): CompiledJob[];
61
+ declare function renderRecentMemories(recents: readonly {
62
+ id?: string;
63
+ title: string;
64
+ content: string;
65
+ createdAt?: string;
66
+ }[], maxChars: number): string;
67
+ declare function renderBriefingPrompt(template: string, vars: {
68
+ date: string;
69
+ recentMemories: string;
70
+ scriptOutput?: string;
71
+ nightContext?: string;
72
+ overnightSentence?: string;
73
+ }): string;
74
+ //#endregion
75
+ //#region src/state.d.ts
76
+ type RunStatus = 'ok' | 'ok-silent' | 'script-failed' | 'gen-failed' | 'deliver-failed' | 'misfire-skipped' | 'overlap-skipped';
77
+ interface JobRunState {
78
+ lastRunAt: string | undefined;
79
+ lastStatus: RunStatus | undefined;
80
+ lastError: string | undefined;
81
+ misfireCount: number;
82
+ nextDueAt: number | undefined;
83
+ }
84
+ type RunStateMap = Record<string, JobRunState>;
85
+ declare function loadState(file: string): RunStateMap;
86
+ declare function saveState(file: string, map: RunStateMap): void;
87
+ //#endregion
88
+ //#region ../maid-memory/lib/index.d.ts
89
+ interface RecentMemory {
90
+ readonly id: string;
91
+ readonly title: string;
92
+ readonly content: string;
93
+ readonly createdAt?: string;
94
+ }
95
+ //#endregion
96
+ //#region src/engine.d.ts
97
+ interface EnginePorts {
98
+ identity: {
99
+ presetOf(maidId: string): string | undefined;
100
+ addressOf(maidId: string): {
101
+ botId: string;
102
+ targetId: string;
103
+ } | undefined;
104
+ };
105
+ memory: {
106
+ recent(maidId: string, limit: number): Promise<RecentMemory[]>;
107
+ markSkip(sessionId: string): void;
108
+ } | undefined;
109
+ agents: {
110
+ create(opts: Record<string, unknown>): Promise<{
111
+ agent: {
112
+ followup(message: unknown): void;
113
+ whenIdle(): Promise<void>;
114
+ };
115
+ dispose(): Promise<void>;
116
+ }>;
117
+ };
118
+ delivery: MaidDelivery;
119
+ events: {
120
+ onAssistantText(sessionId: string, cb: (text: string) => void): () => void;
121
+ };
122
+ now(): number;
123
+ /**
124
+ * M3c Task 12:maid-voice 服务面鸭子声明(不引 maid-voice 包依赖;plugin 侧经
125
+ * reflect 'maidVoice' 接入)。同步两方法;未挂 → {{nightContext}}/{{overnightSentence}}
126
+ * 渲染为空(fail-open,warn 在 plugin 装配期,照 maidMemory 未挂先例)。
127
+ */
128
+ voice?: {
129
+ buildNightContext(maidId: string): string;
130
+ getMorningSentence(maidId: string): string;
131
+ };
132
+ }
133
+ interface ResolvedCronConfig {
134
+ tickIntervalMs: number;
135
+ misfireWindowMs: number;
136
+ recentLimit: number;
137
+ recentMaxChars: number;
138
+ timezone: string;
139
+ deliverRetryDelayMs: number;
140
+ agent: {
141
+ provider: string;
142
+ model: string;
143
+ cwd?: string;
144
+ } | undefined;
145
+ agentSetup: ((agentCtx: unknown) => Promise<void>) | undefined;
146
+ stateFile: string;
147
+ /** 终局观测回调:每次终局迁移(finish 各终局 + overlap-skipped/misfire-skipped)在 persist 之后触发,携带同一 status/error。 */
148
+ onTerminal?: (jobId: string, status: RunStatus, error: string | undefined) => void;
149
+ }
150
+ declare function createCronEngine(config: ResolvedCronConfig, jobs: readonly CompiledJob[], ports: EnginePorts): {
151
+ tick: (nowMs?: number) => void;
152
+ whenIdle: () => Promise<void>;
153
+ dispose: () => Promise<void>;
154
+ runStates: () => RunStateMap;
155
+ };
156
+ //#endregion
157
+ //#region src/plugin.d.ts
158
+ interface MaidCronConfig {
159
+ tickIntervalMs?: number;
160
+ misfireWindowMs?: number;
161
+ recentLimit?: number;
162
+ recentMaxChars?: number;
163
+ timezone?: string;
164
+ deliverRetryDelayMs?: number;
165
+ stateFile: string;
166
+ agent?: {
167
+ provider: string;
168
+ model: string;
169
+ cwd?: string;
170
+ };
171
+ agentSetup?: (agentCtx: unknown) => Promise<void>;
172
+ /** T17:把 maid preset 挂进 cron 会话(persona/工具/技能目录全部继承);缺省 false——现有行为零变化。 */
173
+ mountPresets?: boolean;
174
+ /** agent-preset-registry 服务名(0.2.0 通道:ctx[name] 的 resolve/mount);缺省 'agentPresets'。 */
175
+ presetRegistryService?: string;
176
+ /** 时钟注入(测试用);缺省 Date.now()。 */
177
+ now?: () => number;
178
+ jobs?: JobDeclaration[];
179
+ }
180
+ interface MaidCronService {
181
+ tick(nowMs?: number): void;
182
+ whenIdle(): Promise<void>;
183
+ runStates(): RunStateMap;
184
+ }
185
+ declare const apply: (ctx: any, config: MaidCronConfig) => (() => Promise<void>);
186
+ //#endregion
187
+ //#region src/identity.d.ts
188
+ declare const name = "maid-cron";
189
+ declare const inject: string[];
190
+ //#endregion
191
+ export { BRIEFING_TEMPLATE_DEFAULT, type CompiledJob, type EnginePorts, type JobDeclaration, type JobRunState, type JobSchedule, type MaidCronConfig, type MaidCronService, type ResolvedCronConfig, type RunStateMap, type RunStatus, apply, compileJobs, createCronEngine, inject, loadState, name, nextDueAfter, renderBriefingPrompt, renderRecentMemories, saveState };