foliko 1.0.86 → 1.1.0

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.
Files changed (104) hide show
  1. package/.agent/data/default.json +3 -4310
  2. package/.agent/data/plugins-state.json +34 -1
  3. package/.agent/mcp_config.json +0 -1
  4. package/.agent/memory/core.md +1 -0
  5. package/.agent/memory/project/mnn93ogy-ypjn27.md +9 -0
  6. package/.agent/memory/project/mnn98fqy-5nhc1u.md +25 -0
  7. package/.agent/memory/user/mnm67t9m-x8rekk.md +9 -0
  8. package/.agent/memory/user/mnn5mmqh-w6aktx.md +11 -0
  9. package/.agent/memory/user/mnnbfhhn-dk1bd1.md +22 -0
  10. package/.agent/plugins/__pycache__/file_writer.cpython-312.pyc +0 -0
  11. package/.agent/plugins/marknative/index.js +2 -7
  12. package/.agent/plugins/poster-plugin/README.md +304 -0
  13. package/.agent/plugins/poster-plugin/fonts/PatuaOne-Regular.ttf +0 -0
  14. package/.agent/plugins/poster-plugin/fonts//345/276/256/350/275/257/351/233/205/351/273/221.ttf +0 -0
  15. package/.agent/plugins/poster-plugin/fonts//345/276/256/350/275/257/351/233/205/351/273/221/347/262/227/344/275/223.ttf +0 -0
  16. package/.agent/plugins/poster-plugin/index.js +13 -0
  17. package/.agent/plugins/poster-plugin/package.json +28 -0
  18. package/.agent/plugins/poster-plugin/src/canvas.js +161 -0
  19. package/.agent/plugins/poster-plugin/src/components/arrow.js +84 -0
  20. package/.agent/plugins/poster-plugin/src/components/avatar.js +71 -0
  21. package/.agent/plugins/poster-plugin/src/components/badge.js +85 -0
  22. package/.agent/plugins/poster-plugin/src/components/card.js +88 -0
  23. package/.agent/plugins/poster-plugin/src/components/chart.js +127 -0
  24. package/.agent/plugins/poster-plugin/src/components/chip.js +88 -0
  25. package/.agent/plugins/poster-plugin/src/components/columns.js +107 -0
  26. package/.agent/plugins/poster-plugin/src/components/cta.js +85 -0
  27. package/.agent/plugins/poster-plugin/src/components/divider.js +55 -0
  28. package/.agent/plugins/poster-plugin/src/components/feature.js +85 -0
  29. package/.agent/plugins/poster-plugin/src/components/featureGrid.js +112 -0
  30. package/.agent/plugins/poster-plugin/src/components/grid.js +118 -0
  31. package/.agent/plugins/poster-plugin/src/components/imageFrame.js +155 -0
  32. package/.agent/plugins/poster-plugin/src/components/index.js +62 -0
  33. package/.agent/plugins/poster-plugin/src/components/listItem.js +146 -0
  34. package/.agent/plugins/poster-plugin/src/components/notification.js +123 -0
  35. package/.agent/plugins/poster-plugin/src/components/progress.js +79 -0
  36. package/.agent/plugins/poster-plugin/src/components/progressCircle.js +117 -0
  37. package/.agent/plugins/poster-plugin/src/components/quote.js +97 -0
  38. package/.agent/plugins/poster-plugin/src/components/rating.js +85 -0
  39. package/.agent/plugins/poster-plugin/src/components/star.js +70 -0
  40. package/.agent/plugins/poster-plugin/src/components/statCard.js +105 -0
  41. package/.agent/plugins/poster-plugin/src/components/stepper.js +118 -0
  42. package/.agent/plugins/poster-plugin/src/components/table.js +159 -0
  43. package/.agent/plugins/poster-plugin/src/components/tagCloud.js +78 -0
  44. package/.agent/plugins/poster-plugin/src/components/timeline.js +105 -0
  45. package/.agent/plugins/poster-plugin/src/components/watermark.js +52 -0
  46. package/.agent/plugins/poster-plugin/src/composer.js +1904 -0
  47. package/.agent/plugins/poster-plugin/src/elements/artText.js +60 -0
  48. package/.agent/plugins/poster-plugin/src/elements/background.js +52 -0
  49. package/.agent/plugins/poster-plugin/src/elements/circle.js +31 -0
  50. package/.agent/plugins/poster-plugin/src/elements/image.js +71 -0
  51. package/.agent/plugins/poster-plugin/src/elements/index.js +26 -0
  52. package/.agent/plugins/poster-plugin/src/elements/line.js +23 -0
  53. package/.agent/plugins/poster-plugin/src/elements/polygon.js +32 -0
  54. package/.agent/plugins/poster-plugin/src/elements/rectangle.js +32 -0
  55. package/.agent/plugins/poster-plugin/src/elements/svg.js +92 -0
  56. package/.agent/plugins/poster-plugin/src/elements/text.js +38 -0
  57. package/.agent/plugins/poster-plugin/src/fonts.js +118 -0
  58. package/.agent/plugins/poster-plugin/src/index.js +1659 -0
  59. package/.agent/plugins/poster-plugin/src/presets.js +36 -0
  60. package/.agent/plugins/poster-plugin/src/templates/business.js +60 -0
  61. package/.agent/plugins/poster-plugin/src/templates/gradient.js +64 -0
  62. package/.agent/plugins/poster-plugin/src/templates/index.js +43 -0
  63. package/.agent/plugins/poster-plugin/src/templates/modern.js +69 -0
  64. package/.agent/plugins/poster-plugin/src/templates/simple.js +58 -0
  65. package/.agent/plugins/poster-plugin/src/templates/social.js +62 -0
  66. package/.agent/plugins/poster-plugin/src/templates/tech.js +84 -0
  67. package/.agent/sessions/cli_default.json +24265 -0
  68. package/.agent/weixin.json +6 -0
  69. package/.claude/settings.local.json +176 -171
  70. package/CLAUDE.md +144 -108
  71. package/docs/CONTEXT_DESIGN.md +1596 -0
  72. package/examples/test-concurrent-chat.js +60 -0
  73. package/examples/test-long-chat.js +77 -0
  74. package/examples/test-session-chat.js +93 -0
  75. package/output/beef-love-poster.png +0 -0
  76. package/package.json +2 -2
  77. package/plugins/default-plugins.js +2 -1
  78. package/plugins/extension-executor-plugin.js +11 -0
  79. package/plugins/memory-plugin.js +984 -0
  80. package/plugins/session-plugin.js +78 -1
  81. package/plugins/weixin-plugin.js +24 -22
  82. package/skills/poster-guide/SKILL.md +743 -0
  83. package/skills/python-plugin-dev/SKILL.md +238 -238
  84. package/skills/skill-guide/SKILL.md +130 -108
  85. package/src/capabilities/skill-manager.js +99 -0
  86. package/src/core/agent-chat.js +627 -180
  87. package/src/core/agent-context.js +188 -0
  88. package/src/core/agent.js +9 -63
  89. package/src/core/context-manager.js +283 -0
  90. package/src/core/framework.js +264 -3
  91. package/src/core/plugin-manager.js +79 -2
  92. package/src/core/request-context.js +98 -0
  93. package/src/core/session-context.js +341 -0
  94. package/src/core/session-storage.js +274 -0
  95. package/src/executors/mcp-executor.js +2 -2
  96. package/src/utils/index.js +239 -67
  97. package/src/utils/plugin-helpers.js +17 -0
  98. package//346/265/267/346/212/245/346/217/222/344/273/266.md +621 -0
  99. package/.agent/plugins/__pycache__/test_plugin.cpython-312.pyc +0 -0
  100. package/.agent/plugins/temp-repo/LICENSE +0 -201
  101. package/.agent/plugins/temp-repo/puppeteer-plugin/README.md +0 -147
  102. package/.agent/plugins/temp-repo/puppeteer-plugin/index.js +0 -1418
  103. package/.agent/plugins/temp-repo/puppeteer-plugin/package.json +0 -9
  104. package/.agent/plugins/test_plugin.py +0 -304
@@ -39,7 +39,11 @@ class SessionPlugin extends Plugin {
39
39
  maxHistoryLength: config.maxHistoryLength || 150, // 放宽到 150,Agent 已有智能压缩
40
40
  autoCleanup: config.autoCleanup||false, // 默认不开启自动清理,避免误删会话
41
41
  cleanupInterval: config.cleanupInterval || 5 * 60 * 1000, // 5分钟
42
- persistToStorage: config.persistToStorage !== false // 默认持久化到 storage
42
+ persistToStorage: config.persistToStorage !== false, // 默认持久化到 storage
43
+ // Session 钩子配置
44
+ onSessionStart: config.onSessionStart || null,
45
+ onSessionEnd: config.onSessionEnd || null,
46
+ onSessionCreated: config.onSessionCreated || null
43
47
  }
44
48
  // console.log('SessionPlugin config:', this.config)
45
49
  this._framework = null
@@ -287,6 +291,15 @@ class SessionPlugin extends Plugin {
287
291
 
288
292
  this._sessions.set(id, session)
289
293
  this._saveToStorage(session)
294
+
295
+ // 触发 session:created 事件
296
+ this._events.emit('session:created', session)
297
+
298
+ // 调用 onSessionCreated 钩子
299
+ if (this.config.onSessionCreated) {
300
+ this._callHook(this.config.onSessionCreated, session)
301
+ }
302
+
290
303
  return session
291
304
  }
292
305
 
@@ -335,6 +348,20 @@ class SessionPlugin extends Plugin {
335
348
  addMessage(sessionId, message) {
336
349
  const session = this.getSession(sessionId)
337
350
  if (session) {
351
+ // 基础消息验证
352
+ if (!message || !message.role || !message.content) {
353
+ log.warn('Invalid message format, skipping:', { sessionId, message });
354
+ return session;
355
+ }
356
+
357
+ // 触发 session:started 事件(首次添加消息时)
358
+ if (session.messages.length === 0) {
359
+ this._events.emit('session:started', session)
360
+ if (this.config.onSessionStart) {
361
+ this._callHook(this.config.onSessionStart, session)
362
+ }
363
+ }
364
+
338
365
  session.messages.push(message)
339
366
  session.lastActive = new Date()
340
367
 
@@ -349,6 +376,22 @@ class SessionPlugin extends Plugin {
349
376
  return session
350
377
  }
351
378
 
379
+ /**
380
+ * 整体替换会话消息(用于压缩后同步)
381
+ * @param {string} sessionId - 会话 ID
382
+ * @param {Array} messages - 新的消息数组
383
+ */
384
+ replaceMessages(sessionId, messages) {
385
+ const session = this.getSession(sessionId)
386
+ if (session) {
387
+ session.messages = messages || []
388
+ session.lastActive = new Date()
389
+ // 持久化到 storage
390
+ this._saveToStorage(session)
391
+ }
392
+ return session
393
+ }
394
+
352
395
  /**
353
396
  * 获取会话历史
354
397
  */
@@ -462,6 +505,40 @@ class SessionPlugin extends Plugin {
462
505
  this._events.off(event, listener)
463
506
  }
464
507
 
508
+ /**
509
+ * 调用会话钩子
510
+ * @param {Function} hook - 钩子函数
511
+ * @param {Object} session - 会话对象
512
+ * @private
513
+ */
514
+ _callHook(hook, session) {
515
+ if (typeof hook === 'function') {
516
+ try {
517
+ const result = hook(session)
518
+ if (result && typeof result.catch === 'function') {
519
+ result.catch(err => log.warn('Session hook error:', err.message))
520
+ }
521
+ } catch (err) {
522
+ log.warn('Session hook error:', err.message)
523
+ }
524
+ }
525
+ }
526
+
527
+ /**
528
+ * 结束会话(触发 session:ended 事件)
529
+ * 当会话完成处理时调用
530
+ * @param {string} sessionId - 会话 ID
531
+ */
532
+ endSession(sessionId) {
533
+ const session = this.getSession(sessionId)
534
+ if (session) {
535
+ this._events.emit('session:ended', session)
536
+ if (this.config.onSessionEnd) {
537
+ this._callHook(this.config.onSessionEnd, session)
538
+ }
539
+ }
540
+ }
541
+
465
542
  /**
466
543
  * 启动自动清理定时器
467
544
  */
@@ -372,8 +372,9 @@ class WeixinPlugin extends Plugin {
372
372
  return { agent, sessionId: `weixin_${userId}` }
373
373
  }
374
374
 
375
- // 创建新 agent
376
- const agent = this._framework.createSessionAgent(`weixin_${userId}`, {
375
+ // 创建新 agent - 和 CLI 一样使用 createAgent
376
+ const agent = this._framework.createAgent({
377
+ name: `weixin_${userId}`,
377
378
  systemPrompt: this.systemPrompt,
378
379
  sharedPrompt: `工作目录: {{WORK_DIR}}`,
379
380
  metadata: { WORK_DIR: process.cwd() }
@@ -466,14 +467,18 @@ class WeixinPlugin extends Plugin {
466
467
  await new Promise((resolve) => setTimeout(resolve, 1000))
467
468
 
468
469
  try {
469
- const result = await agent.chat(text, {
470
- sessionId: sessionId
471
- })
472
- const fullResponse = cleanResponse(result.message || '')
470
+ // 使用 chatStream 保持和 CLI 一致的行为
471
+
472
+ let fullResponse = '';
473
+ for await (const chunk of agent.chatStream(text, { sessionId })) {
474
+ if (chunk.type === 'text') {
475
+ fullResponse += chunk.text;
476
+ }
477
+ }
478
+ const response = cleanResponse(fullResponse);
473
479
 
474
- if (fullResponse) {
475
- await this._sendMessageBatch(originalMsg, userId, fullResponse, true)
476
- // log.info(` 回复成功 (${fullResponse.length} 字符)`)
480
+ if (response) {
481
+ await this._sendMessageBatch(originalMsg, userId, response, true)
477
482
  }
478
483
  } catch (err) {
479
484
  log.error(' Media chat error:', err)
@@ -506,21 +511,18 @@ class WeixinPlugin extends Plugin {
506
511
  await new Promise((resolve) => setTimeout(resolve, 1000))
507
512
 
508
513
  try {
509
- // 使用非流式响应
510
- const result = await agent.chat(text, {
511
- sessionId: sessionId
512
- })
513
- const fullResponse = cleanResponse(result.message || '')
514
-
515
- // 保存助手回复到历史(使用 SessionPlugin)
516
- // if (this._sessionPlugin) {
517
- // this._sessionPlugin.addMessage(sessionId, { role: 'assistant', content: fullResponse })
518
- // }
514
+ // 使用 chatStream 保持和 CLI 一致的行为
515
+ let fullResponse = '';
516
+ for await (const chunk of agent.chatStream(text, { sessionId })) {
517
+ if (chunk.type === 'text') {
518
+ fullResponse += chunk.text;
519
+ }
520
+ }
521
+ const response = cleanResponse(fullResponse);
519
522
 
520
523
  // 发送回复(超过500字自动分批)
521
- if (fullResponse) {
522
- await this._sendMessageBatch(originalMsg, userId, fullResponse, true)
523
- // log.info(` 回复成功 (${fullResponse.length} 字符)`)
524
+ if (response) {
525
+ await this._sendMessageBatch(originalMsg, userId, response, true)
524
526
  } else {
525
527
  await this._sendMessageBatch(originalMsg, userId, '抱歉,我没有收到有效的回复。', true)
526
528
  }