@oyasmi/pipiclaw 0.6.9 → 0.6.10

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Pipiclaw
2
2
 
3
- Pipiclaw 是一个 AI 助手运行时(AI assistant runtime),以 [`pi-coding-agent`](https://www.npmjs.com/package/@mariozechner/pi-coding-agent) 为核心,补齐了作为工作助手长期使用时最需要的几层能力:钉钉接入、AI Card 过程展示、子代理、分层记忆、定时事件,以及按会话通道持久化的工作区(workspace)。
3
+ Pipiclaw 是一个 AI 助手运行时(AI assistant runtime),以 [`pi-coding-agent`](https://www.npmjs.com/package/@earendil-works/pi-coding-agent) 为核心,补齐了作为工作助手长期使用时最需要的几层能力:钉钉接入、AI Card 过程展示、子代理、分层记忆、定时事件,以及按会话通道持久化的工作区(workspace)。
4
4
 
5
5
  如果你希望 AI 助手不只是聊天,而是能在钉钉里持续工作、保留上下文、执行任务,并且实时告知你它正在做什么,那么 Pipiclaw 就是你需要的。
6
6
 
@@ -18,12 +18,14 @@ npm package: [`@oyasmi/pipiclaw`](https://www.npmjs.com/package/@oyasmi/pipiclaw
18
18
  - 原生支持钉钉 Stream Mode,不需要消息中转服务,不需要公网IP
19
19
  - 支持 AI Card 过程展示,思考、工具执行和状态更新可以持续流式呈现
20
20
  - 支持 `/help`、`/new`、`/compact`、`/session`、`/model`
21
- - 忙碌时可继续接收 `/steer`、`/followup`、`/stop`
21
+ - 忙碌时可继续接收 `/steer`、`/followup`、`/stop`、`/events`
22
22
  - 按工作区 / 会话通道(workspace / channel)分层管理 `SOUL.md`、`AGENTS.md`、`SESSION.md`、`MEMORY.md`、`HISTORY.md`
23
23
  - 支持预定义子代理(sub-agent)和临时内联子代理(inline sub-agent)
24
24
  - 支持立即、单次、周期三类事件调度
25
25
  - 支持自定义模型提供方(provider)和模型(model)配置
26
26
  - 内建 `web_search` / `web_fetch`,支持联网搜索与网页抓取
27
+ - 内建 `session_search`,可按需检索当前会话通道的冷存储历史
28
+ - 内建 workspace skill 管理工具,可查看、创建和维护 `workspace/skills/`
27
29
  - 内置工具层安全防护:`bash` 命令守卫、文件路径守卫、敏感路径拒绝、阻断审计日志
28
30
 
29
31
  ## 安全说明(Security)
@@ -162,6 +164,7 @@ pipiclaw
162
164
  ├── models.json
163
165
  ├── settings.json
164
166
  ├── tools.json
167
+ ├── security.json
165
168
  └── workspace/
166
169
  ├── SOUL.md
167
170
  ├── AGENTS.md
@@ -178,7 +181,7 @@ pipiclaw
178
181
  export PIPICLAW_HOME=/your/custom/pipiclaw-home
179
182
  ```
180
183
 
181
- 设置后,`channel.json`、`auth.json`、`models.json`、`settings.json`、`tools.json` 和整个 `workspace/` 都会改为从这个目录读取和写入。
184
+ 设置后,`channel.json`、`auth.json`、`models.json`、`settings.json`、`tools.json`、`security.json` 和整个 `workspace/` 都会改为从这个目录读取和写入。
182
185
 
183
186
  如果你无法使用 WSL2,选择在 Windows host 模式下配合 Git Bash 运行,并且 `bash` 不在 PATH 中,也可以一并设置:
184
187
 
@@ -210,7 +213,8 @@ $env:PIPICLAW_SHELL = "C:\Program Files\Git\bin\bash.exe"
210
213
  "cardTemplateKey": "content",
211
214
  "allowFrom": [],
212
215
  "busyMessageDefault": "steer",
213
- "responseMode": "full_progress_then_plain_final"
216
+ "responseMode": "full_progress_then_plain_final",
217
+ "cardAutoLayout": true
214
218
  }
215
219
  ```
216
220
 
@@ -233,6 +237,8 @@ $env:PIPICLAW_SHELL = "C:\Program Files\Git\bin\bash.exe"
233
237
  设为 `"steer"`(默认)或 `"followUp"` / `"followup"`。控制 Agent 忙碌时普通消息的默认处理方式;答疑机器人场景建议设为 `"followUp"`。
234
238
  - `responseMode`
235
239
  设为 `"full_progress_then_plain_final"`(默认)、`"rolling_progress_then_plain_final"` 或 `"final_card_only"`。统一控制过程展示与最终投递:`rolling` 执行中只显示最近 3 条进展并在完成后收起为一行摘要;`final_card_only` 不展示过程,最终答案直接写入 AI Card。
240
+ - `cardAutoLayout`
241
+ 默认为 `true`,透传给钉钉 AI Card 模板的 `autoLayout` 渲染开关。
236
242
 
237
243
  推荐把 AI Card 一起配上,这样在钉钉里能直接看到过程更新。只有在排查接入链路时,才建议临时把 `cardTemplateId` 留空。
238
244
 
@@ -344,7 +350,7 @@ pipiclaw
344
350
 
345
351
  如果你希望助手直接使用 `web_search` / `web_fetch`,可以编辑 `~/.pi/pipiclaw/tools.json`。
346
352
 
347
- 第一次启动时,Pipiclaw 会自动生成一份默认关闭的 `tools.json` 模板。它已经带了 Brave 的示例配置,以及可选代理示例,方便你直接改成可用状态:
353
+ 第一次启动时,Pipiclaw 会自动生成一份默认关闭 web 工具、默认启用 `session_search` 和 workspace skill 管理工具的 `tools.json` 模板。它已经带了 Brave 的示例配置,以及可选代理示例,方便你直接改成可用状态:
348
354
 
349
355
  ```json
350
356
  {
@@ -354,7 +360,18 @@ pipiclaw
354
360
  "proxy": null,
355
361
  "search": {
356
362
  "provider": "brave",
357
- "apiKey": ""
363
+ "apiKey": "",
364
+ "maxResults": 5
365
+ }
366
+ },
367
+ "memory": {
368
+ "sessionSearch": {
369
+ "enabled": true
370
+ }
371
+ },
372
+ "skills": {
373
+ "manage": {
374
+ "enabled": true
358
375
  }
359
376
  }
360
377
  },
@@ -373,6 +390,8 @@ pipiclaw
373
390
 
374
391
  未设置 `tools.web.proxy` 时,web 工具会回退到标准环境变量:`HTTP_PROXY`、`HTTPS_PROXY`、`ALL_PROXY`、`NO_PROXY`。DingTalk runtime 也会尊重同一套环境变量。
375
392
 
393
+ `session_search` 只检索当前会话通道的 `context.jsonl`、session JSONL、`log.jsonl` 和轮转日志;它不会跨 channel 搜索。workspace skill 管理工具只作用于 `workspace/skills/`,可通过 `tools.skills.manage.enabled: false` 关闭。
394
+
376
395
  #### 10. 在钉钉中验证(Verify in DingTalk)
377
396
 
378
397
  建议先给机器人发送:
@@ -418,6 +437,7 @@ pipiclaw
418
437
  | `~/.pi/pipiclaw/models.json` | 自定义模型提供方 / 模型,或覆盖内置模型提供方 |
419
438
  | `~/.pi/pipiclaw/settings.json` | 默认模型提供方 / 模型和运行时设置 |
420
439
  | `~/.pi/pipiclaw/tools.json` | 内建工具配置,例如 `tools.web` |
440
+ | `~/.pi/pipiclaw/security.json` | 工具层安全策略配置 |
421
441
 
422
442
  ### 环境变量(Environment Variables)
423
443
 
@@ -425,6 +445,7 @@ pipiclaw
425
445
  |----------|------|
426
446
  | `ANTHROPIC_API_KEY` | Anthropic API Key |
427
447
  | `PIPICLAW_HOME` | 覆盖默认的 `~/.pi/pipiclaw/` 根目录 |
448
+ | `PIPICLAW_SHELL` | Windows host 模式下指定 POSIX shell,例如 Git Bash 的 `bash.exe` |
428
449
  | `PIPICLAW_DEBUG` | 调试模式,会把上下文写到 `last_prompt.json` |
429
450
  | `HTTP_PROXY` / `HTTPS_PROXY` / `ALL_PROXY` / `NO_PROXY` | 标准代理环境变量;DingTalk runtime 和 web 工具都会尊重它们 |
430
451
 
@@ -442,6 +463,10 @@ Pipiclaw 有两层命令。
442
463
  | `/stop` | 停止当前正在执行的任务 |
443
464
  | `/steer <message>` | 在当前任务继续执行时追加新的引导信息 |
444
465
  | `/followup <message>` | 把新的请求排队,等当前任务结束后再执行 |
466
+ | `/events list` | 列出 `workspace/events/` 中的事件文件摘要 |
467
+ | `/events show <name>` | 查看指定事件文件的完整 JSON |
468
+ | `/events delete <name>` | 删除指定事件文件 |
469
+ | `/events history [name]` | 查看事件调度历史,可按事件名过滤 |
445
470
 
446
471
  忙碌时,普通消息默认等价于 `/steer <message>`。
447
472
 
@@ -481,6 +506,8 @@ Pipiclaw 的核心不是一个临时机器人实例,而是一组长期存在
481
506
  ├── auth.json
482
507
  ├── models.json
483
508
  ├── settings.json
509
+ ├── tools.json
510
+ ├── security.json
484
511
  └── workspace/
485
512
  ├── SOUL.md
486
513
  ├── AGENTS.md
@@ -1,4 +1,4 @@
1
- export type BuiltInCommandName = "help" | "steer" | "followup" | "stop";
1
+ export type BuiltInCommandName = "help" | "steer" | "followup" | "stop" | "events";
2
2
  export interface BuiltInCommand {
3
3
  name: BuiltInCommandName;
4
4
  args: string;
@@ -18,6 +18,12 @@ These are handled directly by the DingTalk transport/runtime layer.
18
18
  - \`/followup <message>\`
19
19
  Queue another request to run after the current task completes
20
20
  Example: \`/followup After that, draft a short executive summary\`
21
+ - \`/events <list|show|delete|history>\`
22
+ Manage scheduled event files and inspect event history
23
+ Example: \`/events list\`
24
+ Example: \`/events show weekly-review\`
25
+ Example: \`/events delete weekly-review\`
26
+ Example: \`/events history weekly-review\`
21
27
 
22
28
  While a task is running, plain messages use the configured busy-message default. The default is \`steer\`; set \`busyMessageDefault\` in channel.json to \`followUp\` or \`followup\` to queue plain messages after the current task.
23
29
 
@@ -55,6 +61,7 @@ export function parseBuiltInCommand(text) {
55
61
  case "steer":
56
62
  case "followup":
57
63
  case "stop":
64
+ case "events":
58
65
  return { name: rawName, args, rawText };
59
66
  default:
60
67
  return null;
@@ -1,3 +1,2 @@
1
- export { ChannelRunner } from "./channel-runner.js";
2
1
  export { getOrCreateRunner } from "./runner-factory.js";
3
2
  export type { AgentRunner } from "./types.js";
@@ -1,2 +1 @@
1
- export { ChannelRunner } from "./channel-runner.js";
2
1
  export { getOrCreateRunner } from "./runner-factory.js";
@@ -48,5 +48,5 @@ export function extractToolResultText(result) {
48
48
  return textParts.join("\n");
49
49
  }
50
50
  }
51
- return JSON.stringify(result);
51
+ return JSON.stringify(result) ?? String(result);
52
52
  }
@@ -2,4 +2,3 @@ import type { SandboxConfig } from "../sandbox.js";
2
2
  import type { AgentRunner } from "./types.js";
3
3
  export declare function getOrCreateRunner(sandboxConfig: SandboxConfig, channelId: string, channelDir: string): AgentRunner;
4
4
  export declare function resetRunner(channelId: string): void;
5
- export declare function resetAllRunners(): void;
@@ -11,6 +11,3 @@ export function getOrCreateRunner(sandboxConfig, channelId, channelDir) {
11
11
  export function resetRunner(channelId) {
12
12
  channelRunners.delete(channelId);
13
13
  }
14
- export function resetAllRunners() {
15
- channelRunners.clear();
16
- }
package/dist/log.d.ts CHANGED
@@ -10,7 +10,6 @@ export declare function logToolError(ctx: LogContext, toolName: string, duration
10
10
  export declare function logResponseStart(ctx: LogContext): void;
11
11
  export declare function logThinking(ctx: LogContext, thinking: string): void;
12
12
  export declare function logResponse(ctx: LogContext, text: string): void;
13
- export declare function logStopRequest(ctx: LogContext): void;
14
13
  export declare function logInfo(message: string): void;
15
14
  export declare function logWarning(message: string, details?: string): void;
16
15
  export declare function logAgentError(ctx: LogContext | "system", error: string): void;
@@ -29,4 +28,3 @@ export declare function logUsageSummary(ctx: LogContext, usage: {
29
28
  }, contextTokens?: number, contextWindow?: number): string;
30
29
  export declare function logStartup(workingDir: string, sandbox: string): void;
31
30
  export declare function logConnected(): void;
32
- export declare function logDisconnected(): void;
package/dist/log.js CHANGED
@@ -111,11 +111,6 @@ export function logResponse(ctx, text) {
111
111
  .join("\n");
112
112
  console.log(color("dim", indented));
113
113
  }
114
- // Control
115
- export function logStopRequest(ctx) {
116
- console.log(color("green", `${timestamp()} ${formatContext(ctx)} stop`));
117
- console.log(color("yellow", `${timestamp()} ${formatContext(ctx)} ⊗ Stop requested - aborting`));
118
- }
119
114
  // System
120
115
  export function logInfo(message) {
121
116
  console.log(color("blue", `${timestamp()} [system] ${message}`));
@@ -185,6 +180,3 @@ export function logConnected() {
185
180
  console.log("⚡️ pipiclaw connected and listening!");
186
181
  console.log("");
187
182
  }
188
- export function logDisconnected() {
189
- console.log("pipiclaw disconnected.");
190
- }
@@ -23,6 +23,7 @@ export declare class MemoryLifecycle {
23
23
  private durableRevision;
24
24
  private lastDurableConsolidationRevision;
25
25
  private readonly channelMemoryQueue;
26
+ private backgroundNewSessionConsolidation;
26
27
  constructor(options: MemoryLifecycleOptions);
27
28
  private buildRunOptions;
28
29
  createExtensionFactory(): ExtensionFactory;
@@ -44,6 +45,8 @@ export declare class MemoryLifecycle {
44
45
  private handleSessionBeforeCompact;
45
46
  private handleSessionCompact;
46
47
  private handleSessionBeforeSwitch;
48
+ /** Await any in-flight detached new-session consolidation (shutdown/tests). */
49
+ whenNewSessionConsolidationSettled(): Promise<void>;
47
50
  private handleSessionStart;
48
51
  private recordActivity;
49
52
  }
@@ -10,6 +10,8 @@ export class MemoryLifecycle {
10
10
  this.durableDirty = false;
11
11
  this.durableRevision = 0;
12
12
  this.lastDurableConsolidationRevision = 0;
13
+ // Tracks the detached new-session consolidation so shutdown/tests can await it.
14
+ this.backgroundNewSessionConsolidation = Promise.resolve();
13
15
  this.channelMemoryQueue = options.channelMemoryQueue ?? getDefaultChannelMemoryQueue();
14
16
  }
15
17
  buildRunOptions(messages, sessionEntries) {
@@ -29,8 +31,8 @@ export class MemoryLifecycle {
29
31
  pi.on("session_compact", async (event) => {
30
32
  this.handleSessionCompact(event);
31
33
  });
32
- pi.on("session_before_switch", async (event) => {
33
- await this.handleSessionBeforeSwitch(event);
34
+ pi.on("session_before_switch", (event) => {
35
+ this.handleSessionBeforeSwitch(event);
34
36
  });
35
37
  pi.on("session_start", async (event) => {
36
38
  this.handleSessionStart(event);
@@ -51,6 +53,9 @@ export class MemoryLifecycle {
51
53
  this.recordActivity("assistant-turn-completed");
52
54
  }
53
55
  async flushForShutdown() {
56
+ // Let any detached new-session consolidation finish (and update the durable
57
+ // checkpoint) before deciding whether a final flush is still needed.
58
+ await this.whenNewSessionConsolidationSettled();
54
59
  await this.runDurableMemoryJobSerial(async () => {
55
60
  // Shutdown is the last chance to persist, so use a looser gate than the
56
61
  // idle/compaction path: consolidate any unconsolidated durable activity,
@@ -202,11 +207,28 @@ export class MemoryLifecycle {
202
207
  handleSessionCompact(_event) {
203
208
  this.recordActivity("boundary");
204
209
  }
205
- async handleSessionBeforeSwitch(event) {
210
+ handleSessionBeforeSwitch(event) {
206
211
  if (event.reason !== "new") {
207
212
  return;
208
213
  }
209
- await this.runPreflightConsolidation("new-session");
214
+ // Snapshot the outgoing session synchronously: the switch has not happened
215
+ // yet, so getMessages()/getSessionEntries() still reference the session that
216
+ // is about to be replaced. Once we yield, this.session is rebound to the new
217
+ // (empty) session and the snapshot would be lost.
218
+ const messageSnapshot = [...this.options.getMessages()];
219
+ const sessionEntrySnapshot = [...this.options.getSessionEntries()];
220
+ // Run the LLM-backed consolidation in the background so /new returns
221
+ // immediately. Failures are tolerated: runPreflightConsolidationNow catches
222
+ // and logs its own errors, and the serial queue keeps this from racing with
223
+ // idle/maintenance work on the same channel.
224
+ this.backgroundNewSessionConsolidation = this.runPreflightConsolidation("new-session", messageSnapshot, sessionEntrySnapshot).catch((error) => {
225
+ const message = error instanceof Error ? error.message : String(error);
226
+ log.logWarning(`[${this.options.channelId}] Background new-session consolidation rejected`, message);
227
+ });
228
+ }
229
+ /** Await any in-flight detached new-session consolidation (shutdown/tests). */
230
+ async whenNewSessionConsolidationSettled() {
231
+ await this.backgroundNewSessionConsolidation;
210
232
  }
211
233
  handleSessionStart(event) {
212
234
  if (event.reason !== "new") {
@@ -28,6 +28,5 @@ export interface MemoryActivityEvent {
28
28
  export declare function getMemoryMaintenanceStateDir(appHomeDir: string): string;
29
29
  export declare function getMemoryMaintenanceStatePath(appHomeDir: string, channelId: string): string;
30
30
  export declare function readMemoryMaintenanceState(appHomeDir: string, channelId: string): Promise<MemoryMaintenanceState>;
31
- export declare function writeMemoryMaintenanceState(appHomeDir: string, state: MemoryMaintenanceState): Promise<void>;
32
31
  export declare function updateMemoryMaintenanceState(appHomeDir: string, channelId: string, update: (state: MemoryMaintenanceState) => MemoryMaintenanceState): Promise<MemoryMaintenanceState>;
33
32
  export declare function applyMemoryActivityToState(state: MemoryMaintenanceState, event: MemoryActivityEvent): MemoryMaintenanceState;
@@ -73,12 +73,6 @@ export async function readMemoryMaintenanceState(appHomeDir, channelId) {
73
73
  return createDefaultState(channelId);
74
74
  }
75
75
  }
76
- export async function writeMemoryMaintenanceState(appHomeDir, state) {
77
- const path = getMemoryMaintenanceStatePath(appHomeDir, state.channelId);
78
- await stateUpdateQueue.run(path, async () => {
79
- await writeFileAtomically(path, `${JSON.stringify(normalizeState(state.channelId, state), null, 2)}\n`);
80
- });
81
- }
82
76
  export async function updateMemoryMaintenanceState(appHomeDir, channelId, update) {
83
77
  const path = getMemoryMaintenanceStatePath(appHomeDir, channelId);
84
78
  return stateUpdateQueue.run(path, async () => {
package/dist/paths.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  export declare const APP_NAME = "pipiclaw";
2
2
  export declare const APP_HOME_DIR: string;
3
3
  export declare const WORKSPACE_DIR: string;
4
+ export declare const STATE_DIR: string;
5
+ export declare const EVENT_STATE_DIR: string;
6
+ export declare const EVENT_HISTORY_PATH: string;
4
7
  export declare const SUB_AGENTS_DIR_NAME = "sub-agents";
5
8
  export declare const SUB_AGENTS_DIR: string;
6
9
  export declare const CHANNEL_CONFIG_PATH: string;
package/dist/paths.js CHANGED
@@ -3,6 +3,9 @@ import { join } from "path";
3
3
  export const APP_NAME = "pipiclaw";
4
4
  export const APP_HOME_DIR = process.env.PIPICLAW_HOME ?? join(homedir(), ".pi", APP_NAME);
5
5
  export const WORKSPACE_DIR = join(APP_HOME_DIR, "workspace");
6
+ export const STATE_DIR = join(APP_HOME_DIR, "state");
7
+ export const EVENT_STATE_DIR = join(STATE_DIR, "events");
8
+ export const EVENT_HISTORY_PATH = join(EVENT_STATE_DIR, "history.jsonl");
6
9
  export const SUB_AGENTS_DIR_NAME = "sub-agents";
7
10
  export const SUB_AGENTS_DIR = join(WORKSPACE_DIR, SUB_AGENTS_DIR_NAME);
8
11
  export const CHANNEL_CONFIG_PATH = join(APP_HOME_DIR, "channel.json");
@@ -11,6 +11,7 @@ export interface BootstrapPaths {
11
11
  settingsConfigPath: string;
12
12
  toolsConfigPath: string;
13
13
  securityConfigPath: string;
14
+ eventHistoryPath: string;
14
15
  }
15
16
  export interface BootstrapIO {
16
17
  log: (...args: unknown[]) => void;
@@ -55,7 +56,7 @@ interface RuntimeContextOptions {
55
56
  sandbox: SandboxConfig;
56
57
  dingtalkConfig: DingTalkConfig;
57
58
  createBot?: (handler: DingTalkHandler, config: DingTalkConfig) => DingTalkBot;
58
- createEventsWatcher?: (workspaceDir: string, bot: DingTalkBot, executor: Executor) => {
59
+ createEventsWatcher?: (workspaceDir: string, bot: DingTalkBot, executor: Executor, eventHistoryPath: string) => {
59
60
  start(): void;
60
61
  stop(): void;
61
62
  };
@@ -6,7 +6,7 @@ import { resetRunner } from "../agent/runner-factory.js";
6
6
  import * as log from "../log.js";
7
7
  import { ensureChannelMemoryFilesSync } from "../memory/files.js";
8
8
  import { MemoryMaintenanceScheduler } from "../memory/scheduler.js";
9
- import { APP_HOME_DIR, APP_NAME, AUTH_CONFIG_PATH, CHANNEL_CONFIG_PATH, MODELS_CONFIG_PATH, SECURITY_CONFIG_PATH, SETTINGS_CONFIG_PATH, TOOLS_CONFIG_PATH, WORKSPACE_DIR, } from "../paths.js";
9
+ import { APP_HOME_DIR, APP_NAME, AUTH_CONFIG_PATH, CHANNEL_CONFIG_PATH, EVENT_HISTORY_PATH, MODELS_CONFIG_PATH, SECURITY_CONFIG_PATH, SETTINGS_CONFIG_PATH, TOOLS_CONFIG_PATH, WORKSPACE_DIR, } from "../paths.js";
10
10
  import { createExecutor, parseSandboxArg, validateSandbox } from "../sandbox.js";
11
11
  import { loadSecurityConfigWithDiagnostics } from "../security/config.js";
12
12
  import { PipiclawSettingsManager } from "../settings.js";
@@ -15,6 +15,7 @@ import { loadToolsConfigWithDiagnostics } from "../tools/config.js";
15
15
  import { ensureChannelDir } from "./channel-paths.js";
16
16
  import { createDingTalkContext } from "./delivery.js";
17
17
  import { DingTalkBot, isBusyMessageDefaultConfig, isResponseModeConfig, normalizeBusyMessageDefault, normalizeResponseMode, } from "./dingtalk.js";
18
+ import { handleEventsCommand as runEventsCommand } from "./event-commands.js";
18
19
  import { createEventsWatcher } from "./events.js";
19
20
  import { ChannelStore } from "./store.js";
20
21
  const DEFAULT_SOUL = `# SOUL.md
@@ -153,6 +154,7 @@ export const DEFAULT_BOOTSTRAP_PATHS = {
153
154
  settingsConfigPath: SETTINGS_CONFIG_PATH,
154
155
  toolsConfigPath: TOOLS_CONFIG_PATH,
155
156
  securityConfigPath: SECURITY_CONFIG_PATH,
157
+ eventHistoryPath: EVENT_HISTORY_PATH,
156
158
  };
157
159
  export class BootstrapExitError extends Error {
158
160
  constructor(code, message) {
@@ -403,6 +405,14 @@ export function createRuntimeContext(options) {
403
405
  log.logInfo(`[${channelId}] Stop requested`);
404
406
  }
405
407
  },
408
+ async handleEventsCommand(event, bot, args) {
409
+ const response = await runEventsCommand({
410
+ args,
411
+ workspaceDir: options.paths.workspaceDir,
412
+ historyPath: options.paths.eventHistoryPath,
413
+ });
414
+ await bot.sendPlain(event.channelId, response);
415
+ },
406
416
  async handleBusyMessage(event, bot, mode, queueText) {
407
417
  if (shuttingDown) {
408
418
  return { kind: "handled" };
@@ -475,6 +485,10 @@ export function createRuntimeContext(options) {
475
485
  const builtInCommand = parseBuiltInCommand(event.text);
476
486
  if (builtInCommand) {
477
487
  log.logInfo(`[${event.channelId}] Executing command: ${builtInCommand.rawText}`);
488
+ if (builtInCommand.name === "events") {
489
+ await handler.handleEventsCommand(event, bot, builtInCommand.args);
490
+ return;
491
+ }
478
492
  await state.runner.handleBuiltinCommand(ctx, builtInCommand);
479
493
  return;
480
494
  }
@@ -508,8 +522,8 @@ export function createRuntimeContext(options) {
508
522
  : new DingTalkBot(handler, options.dingtalkConfig);
509
523
  const executor = createExecutor(options.sandbox);
510
524
  const eventsWatcher = options.createEventsWatcher
511
- ? options.createEventsWatcher(options.paths.workspaceDir, bot, executor)
512
- : createEventsWatcher(options.paths.workspaceDir, bot, executor, loadSecurityConfigWithDiagnostics(options.paths.appHomeDir).config.commandGuard);
525
+ ? options.createEventsWatcher(options.paths.workspaceDir, bot, executor, options.paths.eventHistoryPath)
526
+ : createEventsWatcher(options.paths.workspaceDir, bot, executor, loadSecurityConfigWithDiagnostics(options.paths.appHomeDir).config.commandGuard, options.paths.eventHistoryPath);
513
527
  const memoryMaintenanceScheduler = options.createMemoryMaintenanceScheduler
514
528
  ? options.createMemoryMaintenanceScheduler()
515
529
  : new MemoryMaintenanceScheduler({
@@ -64,6 +64,7 @@ export interface DingTalkHandler {
64
64
  isRunning(channelId: string): boolean;
65
65
  handleEvent(event: DingTalkEvent, bot: DingTalkBot, isEvent?: boolean): Promise<void>;
66
66
  handleStop(channelId: string, bot: DingTalkBot): Promise<void>;
67
+ handleEventsCommand(event: DingTalkEvent, bot: DingTalkBot, args: string): Promise<void>;
67
68
  handleBusyMessage(event: DingTalkEvent, bot: DingTalkBot, mode: BusyMessageMode, queueText: string): Promise<BusyMessageResult>;
68
69
  }
69
70
  export declare class DingTalkBot {
@@ -979,12 +979,16 @@ export class DingTalkBot {
979
979
  }
980
980
  return;
981
981
  }
982
+ if (builtInCommand?.name === "events") {
983
+ await this.handler.handleEventsCommand(event, this, builtInCommand.args);
984
+ return;
985
+ }
982
986
  if (builtInCommand) {
983
- await this.sendPlain(channelId, `A task is already running. Use \`/stop\`, \`/steer <message>\`, or \`/followup <message>\`. Plain messages default to ${this.busyMessageDefault}.`);
987
+ await this.sendPlain(channelId, `A task is already running. Use \`/stop\`, \`/steer <message>\`, \`/followup <message>\`, or \`/events <action>\`. Plain messages default to ${this.busyMessageDefault}.`);
984
988
  return;
985
989
  }
986
990
  if (isSlashCommand) {
987
- await this.sendPlain(channelId, "A task is already running. Only `/stop`, `/steer <message>`, and `/followup <message>` are available while streaming.");
991
+ await this.sendPlain(channelId, "A task is already running. Only `/stop`, `/steer <message>`, `/followup <message>`, and `/events <action>` are available while streaming.");
988
992
  return;
989
993
  }
990
994
  const result = await this.handler.handleBusyMessage(event, this, this.busyMessageDefault, content);
@@ -0,0 +1,6 @@
1
+ export interface HandleEventsCommandOptions {
2
+ args: string;
3
+ workspaceDir: string;
4
+ historyPath: string;
5
+ }
6
+ export declare function handleEventsCommand(options: HandleEventsCommandOptions): Promise<string>;