Skip to content

Commit 5813ce2

Browse files
CrazyBoyMclaude
andcommitted
fix: resolve Windows compatibility and documentation issues (#3, #5, #6)
Bug Fixes: - Fix error event causing process crash by adding no-op 'error' listener to monitorEmitter in EventBus constructor (Issue #3) - Replace colons with dashes in identifiers (agt-, fork-, sfp-, session-, etc.) for Windows file system compatibility (Issue #6) - Fix documentation using incorrect `onMonitor` API - changed to `on` (Issue #5) Files modified: - src/core/events.ts: Add 'error' listener to prevent ERR_UNHANDLED_ERROR - src/utils/agent-id.ts: agt: -> agt- - src/utils/session-id.ts: org:/team:/user:/agent:/session:/fork: -> dashes - src/core/agent.ts: sfp:/fork:/agt: -> dashes - src/core/checkpointer.ts, src/core/checkpointers/file.ts: checkpoint IDs - docs/skills.md, docs/tools.md, docs/simplified-tools.md: onMonitor -> on - docs/api.md, docs/resume.md: Update examples with new ID format - examples/*, tests/*: Update to use new ID format Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 6d63cd0 commit 5813ce2

14 files changed

Lines changed: 48 additions & 41 deletions

File tree

docs/api.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export function createDependencies(): AgentDependencies {
8989
| 字段 | 说明 |
9090
| --- | --- |
9191
| `templateId` | 必填。引用已注册模板。|
92-
| `agentId?` | 可选。未指定时自动生成 `agt:` 前缀 ULID。|
92+
| `agentId?` | 可选。未指定时自动生成 `agt-` 前缀 ULID。|
9393
| `model` / `modelConfig` | 提供 `ModelProvider` 实例或配置。|
9494
| `sandbox` | `Sandbox` 实例或 `SandboxConfig`(kind/workDir/enforceBoundary/allowPaths 等)。|
9595
| `tools` | 工具名称数组。默认遵循模板:`'*'` 表示注册表所有工具。|
@@ -110,7 +110,7 @@ export function createDependencies(): AgentDependencies {
110110
## Agent.resume / Agent.resumeFromStore
111111

112112
```typescript
113-
const agent = await Agent.resume('agt:demo', {
113+
const agent = await Agent.resume('agt-demo', {
114114
templateId: 'repo-assistant',
115115
modelConfig: { provider: 'anthropic', model: 'claude-3-5-sonnet-20241022', apiKey: process.env.ANTHROPIC_API_KEY! },
116116
sandbox: { kind: 'local', workDir: './workspace', enforceBoundary: true },
@@ -119,7 +119,7 @@ const agent = await Agent.resume('agt:demo', {
119119
autoRun: true, // 恢复后继续处理队列
120120
});
121121

122-
const agent2 = await Agent.resumeFromStore('agt:demo', deps, {
122+
const agent2 = await Agent.resumeFromStore('agt-demo', deps, {
123123
overrides: { modelConfig: { provider: 'anthropic', model: 'claude-3-5-sonnet-20241022', apiKey: process.env.ANTHROPIC_API_KEY! } },
124124
});
125125
```

docs/resume.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { createDependencies } from '../bootstrap/dependencies';
2222
const deps = createDependencies();
2323

2424
// 方式一:显式配置
25-
const agent = await Agent.resume('agt:demo', {
25+
const agent = await Agent.resume('agt-demo', {
2626
templateId: 'repo-assistant',
2727
modelConfig: { provider: 'anthropic', model: 'claude-3-5-sonnet-20241022', apiKey: process.env.ANTHROPIC_API_KEY! },
2828
sandbox: { kind: 'local', workDir: './workspace', enforceBoundary: true },
@@ -32,7 +32,7 @@ const agent = await Agent.resume('agt:demo', {
3232
});
3333

3434
// 方式二:读取 metadata(推荐)
35-
const agent2 = await Agent.resumeFromStore('agt:demo', deps, {
35+
const agent2 = await Agent.resumeFromStore('agt-demo', deps, {
3636
overrides: {
3737
modelConfig: { provider: 'anthropic', model: 'claude-3-5-sonnet-20241022', apiKey: process.env.ANTHROPIC_API_KEY! },
3838
},
@@ -70,7 +70,7 @@ const forked = await agent.fork(bookmarkId);
7070
await forked.send('这是一个基于原对话分叉出的新任务。');
7171
```
7272

73-
- `snapshot(label?)` 返回 `SnapshotId`(默认为 `sfp:{index}`)。
73+
- `snapshot(label?)` 返回 `SnapshotId`(默认为 `sfp-{index}`)。
7474
- `fork(sel?)` 创建新 Agent:继承工具/权限配置与 lineage,并把消息复制到新 Store 命名空间。
7575
- 分叉后的 Agent 需要独立绑定事件监听。
7676

docs/simplified-tools.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ defineTool({
376376
### 监听自定义事件
377377

378378
```typescript
379-
agent.onMonitor('tool_custom_event', (event) => {
379+
agent.on('tool_custom_event', (event) => {
380380
console.log(`[${event.toolName}] ${event.eventType}:`, event.data);
381381

382382
// 示例输出:
@@ -490,7 +490,7 @@ const agent = await Agent.create({
490490
});
491491

492492
// 监听自定义事件
493-
agent.onMonitor('tool_custom_event', (event) => {
493+
agent.on('tool_custom_event', (event) => {
494494
if (event.eventType === 'weather_request') {
495495
console.log(`Fetching weather for ${event.data.city}...`);
496496
}

docs/skills.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,14 +364,14 @@ Agent: [检测到需要日志分析技能]
364364

365365
```typescript
366366
// 监听技能工具调用
367-
agent.onMonitor('tool_executed', (event) => {
367+
agent.on('tool_executed', (event) => {
368368
if (event.call.name === 'skills') {
369369
console.log('Skill loaded:', event.call.input.skill_name);
370370
}
371371
});
372372

373373
// 监听工具说明书更新
374-
agent.onMonitor('tool_manual_updated', (event) => {
374+
agent.on('tool_manual_updated', (event) => {
375375
console.log('Tools manual updated:', event.tools);
376376
});
377377
```

docs/tools.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ export class BadTool implements ToolInstance {
208208
可以监听工具超时事件以进行告警或降级处理:
209209

210210
```typescript
211-
agent.onMonitor('error', (event) => {
211+
agent.on('error', (event) => {
212212
if (event.phase === 'tool' && event.message.includes('aborted')) {
213213
console.log('Tool execution timed out:', event.detail);
214214
// 发送告警、记录日志等

examples/03-room-collab.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ async function main() {
4747
const pool = new AgentPool({ dependencies: deps, maxAgents: 10 });
4848
const room = new Room(pool);
4949

50-
const planner = await pool.create('agt:planner', configFor('planner'));
51-
const dev = await pool.create('agt:dev', configFor('executor'));
50+
const planner = await pool.create('agt-planner', configFor('planner'));
51+
const dev = await pool.create('agt-dev', configFor('executor'));
5252

5353
room.join('planner', planner.agentId);
5454
room.join('dev', dev.agentId);

examples/nextjs-api-route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function bindControlAndMonitor(agent: Agent) {
7979
// ---- API route ----------------------------------------------------------
8080

8181
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
82-
const agentId = (req.query.agentId as string) || 'agt:web-demo';
82+
const agentId = (req.query.agentId as string) || 'agt-web-demo';
8383
const agent = await resumeOrCreate(agentId);
8484

8585
bindControlAndMonitor(agent);

src/core/agent.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ export class Agent {
563563
}
564564

565565
async snapshot(label?: string): Promise<SnapshotId> {
566-
const id = label || `sfp:${this.lastSfpIndex}`;
566+
const id = label || `sfp-${this.lastSfpIndex}`;
567567
const snapshot: Snapshot = {
568568
id,
569569
messages: JSON.parse(JSON.stringify(this.messages)),
@@ -583,7 +583,7 @@ export class Agent {
583583
const snapshot = await this.persistentStore.loadSnapshot(this.agentId, snapshotId);
584584
if (!snapshot) throw new Error(`Snapshot not found: ${snapshotId}`);
585585

586-
const forkId = `${this.agentId}/fork:${Date.now()}`;
586+
const forkId = `${this.agentId}/fork-${Date.now()}`;
587587
const forkConfig: AgentConfig = {
588588
...this.config,
589589
agentId: forkId,
@@ -2307,7 +2307,7 @@ export class Agent {
23072307
const now = Date.now();
23082308
const timePart = encodeUlid(now, 10, chars);
23092309
const random = Array.from({ length: 16 }, () => chars[Math.floor(Math.random() * chars.length)]).join('');
2310-
return `agt:${timePart}${random}`;
2310+
return `agt-${timePart}${random}`;
23112311
}
23122312
}
23132313

src/core/checkpointer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export class MemoryCheckpointer implements Checkpointer {
150150

151151
const forked: Checkpoint = {
152152
...original,
153-
id: `${newAgentId}:${Date.now()}`,
153+
id: `${newAgentId}-${Date.now()}`,
154154
agentId: newAgentId,
155155
timestamp: Date.now(),
156156
metadata: {

src/core/checkpointers/file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export class FileCheckpointer implements Checkpointer {
117117

118118
const forked: Checkpoint = {
119119
...original,
120-
id: `${newAgentId}:${Date.now()}`,
120+
id: `${newAgentId}-${Date.now()}`,
121121
agentId: newAgentId,
122122
timestamp: Date.now(),
123123
metadata: {

0 commit comments

Comments
 (0)