@bolloon/bolloon-agent 0.4.3 → 0.4.5

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 (212) hide show
  1. package/README.md +135 -135
  2. package/bin/bolloon-cli.cjs +183 -183
  3. package/bin/bolloon-daemon.sh +207 -0
  4. package/bin/bolloon.cjs +0 -0
  5. package/dist/agents/constraint-layer.js +19 -19
  6. package/dist/agents/judgment-protocol.js +14 -14
  7. package/dist/agents/pi-sdk-types.js +12 -12
  8. package/dist/agents/pi-sdk.js +90 -90
  9. package/dist/agents/skill-organizer.js +19 -19
  10. package/dist/agents/workflow-pivot-loop.js +2 -2
  11. package/dist/bollharness/src/scripts/deploy-guard.js +8 -8
  12. package/dist/bollharness-integration/context-router-judgment.js +4 -4
  13. package/dist/bollharness-integration/context-router.js +292 -292
  14. package/dist/bollharness-integration/gate-state-machine.js +13 -13
  15. package/dist/bollharness-integration/llm-judgment-engine.js +134 -134
  16. package/dist/bollharness-integration/skill-adapter.js +21 -21
  17. package/dist/bootstrap/chat-archiver.js +14 -14
  18. package/dist/bootstrap/context-os.js +24 -24
  19. package/dist/bootstrap/memory-compressor.js +13 -13
  20. package/dist/cli-entry.js +36 -36
  21. package/dist/constraint-runtime/reference_data/archive_surface_snapshot.json +63 -0
  22. package/dist/constraint-runtime/reference_data/commands_snapshot.json +1037 -0
  23. package/dist/constraint-runtime/reference_data/subsystems/assistant.json +8 -0
  24. package/dist/constraint-runtime/reference_data/subsystems/bootstrap.json +8 -0
  25. package/dist/constraint-runtime/reference_data/subsystems/bridge.json +32 -0
  26. package/dist/constraint-runtime/reference_data/subsystems/buddy.json +13 -0
  27. package/dist/constraint-runtime/reference_data/subsystems/cli.json +26 -0
  28. package/dist/constraint-runtime/reference_data/subsystems/components.json +32 -0
  29. package/dist/constraint-runtime/reference_data/subsystems/constants.json +28 -0
  30. package/dist/constraint-runtime/reference_data/subsystems/coordinator.json +8 -0
  31. package/dist/constraint-runtime/reference_data/subsystems/entrypoints.json +15 -0
  32. package/dist/constraint-runtime/reference_data/subsystems/hooks.json +32 -0
  33. package/dist/constraint-runtime/reference_data/subsystems/keybindings.json +21 -0
  34. package/dist/constraint-runtime/reference_data/subsystems/memdir.json +15 -0
  35. package/dist/constraint-runtime/reference_data/subsystems/migrations.json +18 -0
  36. package/dist/constraint-runtime/reference_data/subsystems/moreright.json +8 -0
  37. package/dist/constraint-runtime/reference_data/subsystems/native_ts.json +11 -0
  38. package/dist/constraint-runtime/reference_data/subsystems/outputStyles.json +8 -0
  39. package/dist/constraint-runtime/reference_data/subsystems/plugins.json +9 -0
  40. package/dist/constraint-runtime/reference_data/subsystems/remote.json +11 -0
  41. package/dist/constraint-runtime/reference_data/subsystems/schemas.json +8 -0
  42. package/dist/constraint-runtime/reference_data/subsystems/screens.json +10 -0
  43. package/dist/constraint-runtime/reference_data/subsystems/server.json +10 -0
  44. package/dist/constraint-runtime/reference_data/subsystems/services.json +32 -0
  45. package/dist/constraint-runtime/reference_data/subsystems/skills.json +27 -0
  46. package/dist/constraint-runtime/reference_data/subsystems/state.json +13 -0
  47. package/dist/constraint-runtime/reference_data/subsystems/types.json +18 -0
  48. package/dist/constraint-runtime/reference_data/subsystems/upstreamproxy.json +9 -0
  49. package/dist/constraint-runtime/reference_data/subsystems/utils.json +32 -0
  50. package/dist/constraint-runtime/reference_data/subsystems/vim.json +12 -0
  51. package/dist/constraint-runtime/reference_data/subsystems/voice.json +8 -0
  52. package/dist/constraint-runtime/reference_data/tools_snapshot.json +922 -0
  53. package/dist/context-compaction/auto-compact.js +7 -7
  54. package/dist/electron/config.js.map +1 -0
  55. package/dist/electron/dialogs.js.map +1 -0
  56. package/dist/electron/first-run.js +54 -54
  57. package/dist/electron/first-run.js.map +1 -0
  58. package/dist/electron/ipc.js.map +1 -0
  59. package/dist/electron/logger.js.map +1 -0
  60. package/dist/electron/main.js.map +1 -0
  61. package/dist/electron/menu.js.map +1 -0
  62. package/dist/electron/paths.js.map +1 -0
  63. package/dist/electron/server.js.map +1 -0
  64. package/dist/electron/tray.js.map +1 -0
  65. package/dist/electron/window.js.map +1 -0
  66. package/dist/electron-build/electron/config.js.map +1 -1
  67. package/dist/electron-build/electron/dialogs.js.map +1 -1
  68. package/dist/electron-build/electron/first-run.js +54 -54
  69. package/dist/electron-build/electron/first-run.js.map +1 -1
  70. package/dist/electron-build/electron/ipc.js.map +1 -1
  71. package/dist/electron-build/electron/logger.js.map +1 -1
  72. package/dist/electron-build/electron/menu.js.map +1 -1
  73. package/dist/electron-build/electron/paths.js.map +1 -1
  74. package/dist/electron-build/electron/server.js.map +1 -1
  75. package/dist/electron-build/electron/tray.js.map +1 -1
  76. package/dist/electron-build/electron/window.js.map +1 -1
  77. package/dist/electron-build/utils/auto-update.js.map +1 -1
  78. package/dist/electron-preload.js.map +1 -1
  79. package/dist/electron.js.map +1 -1
  80. package/dist/index.js +112 -112
  81. package/dist/llm/llm-judgment-client.js +102 -102
  82. package/dist/llm/pi-ai.js +48 -48
  83. package/dist/llm/system-prompt/layers/channel/human-async.md +41 -41
  84. package/dist/llm/system-prompt/layers/channel/local.md +14 -14
  85. package/dist/llm/system-prompt/layers/channel/p2p-agent.md +18 -18
  86. package/dist/llm/system-prompt/layers/channel/p2p-peer-sync.md +51 -51
  87. package/dist/llm/system-prompt/layers/channel/p2p-proactive.md +43 -43
  88. package/dist/llm/system-prompt/layers/channel/p2p-visitor.md +19 -19
  89. package/dist/llm/system-prompt/layers/channel/session-handoff.md +61 -61
  90. package/dist/llm/system-prompt/layers/core/artifacts_storage.md +89 -89
  91. package/dist/llm/system-prompt/layers/core/evenhandedness.md +21 -21
  92. package/dist/llm/system-prompt/layers/core/external-engagement.md +73 -73
  93. package/dist/llm/system-prompt/layers/core/hibs_reminders.md +15 -15
  94. package/dist/llm/system-prompt/layers/core/identity.md +48 -48
  95. package/dist/llm/system-prompt/layers/core/knowledge.md +17 -17
  96. package/dist/llm/system-prompt/layers/core/memory_system.md +12 -12
  97. package/dist/llm/system-prompt/layers/core/network_filesystem.md +28 -28
  98. package/dist/llm/system-prompt/layers/core/refusal.md +37 -37
  99. package/dist/llm/system-prompt/layers/core/tone.md +31 -31
  100. package/dist/llm/system-prompt/layers/core/tools.thin.md +13 -13
  101. package/dist/llm/system-prompt/layers/core/wellbeing.md +41 -41
  102. package/dist/llm/system-prompt/layers/role/architect.md +20 -20
  103. package/dist/llm/system-prompt/layers/role/expert.md +19 -19
  104. package/dist/llm/system-prompt/layers/role/implementer.md +15 -15
  105. package/dist/llm/system-prompt/layers/role/security.md +15 -15
  106. package/dist/llm/system-prompt/layers/tool/artifacts.md +72 -72
  107. package/dist/llm/system-prompt/layers/tool/bash.md +25 -25
  108. package/dist/llm/system-prompt/layers/tool/goal_handoff.md +77 -77
  109. package/dist/llm/system-prompt/layers/tool/hibs_api.md +171 -171
  110. package/dist/llm/system-prompt/layers/tool/image_search.md +70 -70
  111. package/dist/llm/system-prompt/layers/tool/manifest.md +89 -89
  112. package/dist/llm/system-prompt/layers/tool/mcp_apps.md +53 -53
  113. package/dist/llm/system-prompt/layers/tool/p2p_request.md +61 -61
  114. package/dist/llm/system-prompt/layers/tool/web_search.md +83 -83
  115. package/dist/llm/tool-manifest/ask_user_input.js +1 -1
  116. package/dist/llm/tool-manifest/bash.js +3 -3
  117. package/dist/llm/tool-manifest/create_file.js +4 -4
  118. package/dist/llm/tool-manifest/fetch_sports_data.js +3 -3
  119. package/dist/llm/tool-manifest/image_search.js +2 -2
  120. package/dist/llm/tool-manifest/index.js +59 -0
  121. package/dist/llm/tool-manifest/mcp.js +2 -2
  122. package/dist/llm/tool-manifest/message_compose.js +3 -3
  123. package/dist/llm/tool-manifest/places.js +2 -2
  124. package/dist/llm/tool-manifest/present_files.js +1 -1
  125. package/dist/llm/tool-manifest/recipe.js +2 -2
  126. package/dist/llm/tool-manifest/str_replace.js +5 -5
  127. package/dist/llm/tool-manifest/view.js +3 -3
  128. package/dist/llm/tool-manifest/weather.js +4 -4
  129. package/dist/llm/tool-manifest/web.js +4 -4
  130. package/dist/pi-ecosystem-judgment/causal-judge.js +51 -51
  131. package/dist/pi-ecosystem-judgment/distill-prompt.js +42 -42
  132. package/dist/pi-ecosystem-judgment/distillation.js +14 -14
  133. package/dist/pi-ecosystem-judgment/human-value-store.js +1 -1
  134. package/dist/pi-ecosystem-judgment/monitor-gate.js +28 -28
  135. package/dist/pi-ecosystem-judgment/value-injection.js +102 -102
  136. package/dist/pi-ecosystem-mcp/index.js +146 -5
  137. package/dist/security/context-router-tool.js +15 -15
  138. package/dist/utils/auto-update.js.map +1 -0
  139. package/dist/web/api-config.html +779 -779
  140. package/dist/web/client-hearth.js +10 -10
  141. package/dist/web/client.js.map +7 -0
  142. package/dist/web/components/wallet-viem.mjs +118 -118
  143. package/dist/web/edge-auth-client.js +120 -0
  144. package/dist/web/index.html +472 -472
  145. package/dist/web/manifest.json +20 -20
  146. package/dist/web/server.js +34 -67
  147. package/dist/web/style.css +4946 -4946
  148. package/package.json +195 -195
  149. package/scripts/build-cli.js +215 -215
  150. package/scripts/build-web.ts +130 -130
  151. package/scripts/postinstall.js +152 -152
  152. package/bin/bolloon.js +0 -157
  153. package/dist/pi-ecosystem-colony/index.js +0 -365
  154. package/dist/social/ant-colony/AdaptiveHeartbeat.js +0 -101
  155. package/dist/social/ant-colony/PheromoneEngine.js +0 -227
  156. package/dist/social/ant-colony/index.js +0 -6
  157. package/dist/social/ant-colony/types.js +0 -24
  158. package/dist/storage/trajectory.js +0 -101
  159. package/dist/test/ai-judgment-test.js +0 -80
  160. package/dist/test/bollharness-integration.test.js +0 -318
  161. package/dist/test/channel-agent-multi-dialogue.js +0 -205
  162. package/dist/test/channel-heartbeat-agent-test.js +0 -201
  163. package/dist/test/constraint-layer.test.js +0 -164
  164. package/dist/test/diap-identity-test.js +0 -172
  165. package/dist/test/diap-quick-test.js +0 -62
  166. package/dist/test/global-shared-context.test.js +0 -315
  167. package/dist/test/harness-judgment-injection.test.js +0 -246
  168. package/dist/test/harness-workflow-integrator-test.js +0 -228
  169. package/dist/test/human-value-store.test.js +0 -243
  170. package/dist/test/hybrid-integration-test.js +0 -118
  171. package/dist/test/hybrid-messenger-verify.js +0 -55
  172. package/dist/test/iroh-bistream-debug.js +0 -38
  173. package/dist/test/iroh-communication.test.js +0 -66
  174. package/dist/test/iroh-debug-test.js +0 -57
  175. package/dist/test/iroh-diap-test.js +0 -71
  176. package/dist/test/iroh-direct-connect.js +0 -55
  177. package/dist/test/iroh-e2e-fixed.js +0 -89
  178. package/dist/test/iroh-e2e-same-process.js +0 -63
  179. package/dist/test/iroh-e2e.js +0 -66
  180. package/dist/test/iroh-final-e2e.js +0 -72
  181. package/dist/test/iroh-relay-test.js +0 -37
  182. package/dist/test/iroh-simple-test.js +0 -41
  183. package/dist/test/iroh-transport-verify.js +0 -54
  184. package/dist/test/iroh-transport.test.js +0 -37
  185. package/dist/test/iroh-two-nodes.js +0 -70
  186. package/dist/test/iroh-verify.js +0 -44
  187. package/dist/test/judgment-decision.test.js +0 -219
  188. package/dist/test/llm-judgment-integration.test.js +0 -220
  189. package/dist/test/p2p-agent-complex-dialogue.js +0 -385
  190. package/dist/test/p2p-agent-dialogue.js +0 -341
  191. package/dist/test/p2p-agent-full-bidirectional.js +0 -510
  192. package/dist/test/p2p-agent-harness-flow.js +0 -437
  193. package/dist/test/p2p-agent-harness-single.js +0 -143
  194. package/dist/test/p2p-ai-dialogue-test.js +0 -318
  195. package/dist/test/p2p-cid-connect-test.js +0 -195
  196. package/dist/test/p2p-connect-receiver.js +0 -69
  197. package/dist/test/p2p-doc-transfer.js +0 -110
  198. package/dist/test/p2p-identity-page-test.js +0 -77
  199. package/dist/test/p2p-iroh-test.js +0 -171
  200. package/dist/test/p2p-minimal-test.js +0 -241
  201. package/dist/test/p2p-node-1.js +0 -148
  202. package/dist/test/p2p-node-2.js +0 -148
  203. package/dist/test/p2p-server.js +0 -281
  204. package/dist/test/p2p-two-nodes-test.js +0 -438
  205. package/dist/test/pi-sdk.test.js +0 -44
  206. package/dist/test/set-persona.js +0 -40
  207. package/dist/test/simple.test.js +0 -9
  208. package/dist/test/storage-integration.test.js +0 -150
  209. package/dist/test/subagent-manager.test.js +0 -276
  210. package/dist/test/test-gate-flow.test.js +0 -81
  211. package/dist/test/workflow-engine.test.js +0 -87
  212. package/dist/test/workflow-pivot-loop.test.js +0 -246
@@ -48,6 +48,65 @@ export function getToolsByLayer(layerId) {
48
48
  *
49
49
  * 不包含: 完整 parameters schema (那是 PiAI 客户端在调用时读)
50
50
  */
51
+ /**
52
+ * 把 ToolManifest 转成 OpenAI function calling 格式 (tools 数组)
53
+ * 用于 native tool_choice: "auto" 模式, 让 LLM 选择调用.
54
+ *
55
+ * 注意: 递归处理嵌套参数 (type='object' 的 properties / type='array' 的 items)
56
+ */
57
+ export function formatForOpenAI(tools) {
58
+ const list = tools ?? ALL;
59
+ return list.map((t) => {
60
+ const properties = {};
61
+ const required = [];
62
+ for (const p of t.parameters) {
63
+ properties[p.name] = convertParameter(p);
64
+ if (p.required)
65
+ required.push(p.name);
66
+ }
67
+ return {
68
+ type: 'function',
69
+ function: {
70
+ name: t.id,
71
+ description: t.oneLine,
72
+ parameters: {
73
+ type: 'object',
74
+ properties,
75
+ required,
76
+ },
77
+ },
78
+ };
79
+ });
80
+ }
81
+ function convertParameter(p) {
82
+ const schema = { type: p.type === 'enum' ? 'string' : p.type };
83
+ if (p.description)
84
+ schema.description = p.description;
85
+ if (p.enumValues)
86
+ schema.enum = p.enumValues;
87
+ if (p.default !== undefined)
88
+ schema.default = p.default;
89
+ if (p.minimum !== undefined)
90
+ schema.minimum = p.minimum;
91
+ if (p.maximum !== undefined)
92
+ schema.maximum = p.maximum;
93
+ if (p.format)
94
+ schema.format = p.format;
95
+ if (p.type === 'object' && p.properties) {
96
+ schema.properties = {};
97
+ for (const sub of p.properties) {
98
+ schema.properties[sub.name] = convertParameter(sub);
99
+ }
100
+ }
101
+ if (p.type === 'array' && p.items) {
102
+ schema.items = convertParameter(p.items);
103
+ if (p.minItems !== undefined)
104
+ schema.minItems = p.minItems;
105
+ if (p.maxItems !== undefined)
106
+ schema.maxItems = p.maxItems;
107
+ }
108
+ return schema;
109
+ }
51
110
  export function formatForPrompt(tools) {
52
111
  const list = tools ?? ALL;
53
112
  const lines = [
@@ -15,7 +15,7 @@ export const search_mcp_registry = {
15
15
  parameters: [
16
16
  { name: 'keywords', type: 'array', required: true, description: '搜索关键词', minItems: 1, items: { name: 'kw', type: 'string', required: true, description: '关键词' } }
17
17
  ],
18
- callExample: `[TOOL:search_mcp_registry]
18
+ callExample: `[TOOL:search_mcp_registry]
19
19
  [P:keywords]${'${'}JSON.stringify(["calendar","schedule"])[ENDTOOL]`,
20
20
  layerId: 'tool.mcp_apps',
21
21
  };
@@ -37,7 +37,7 @@ export const suggest_connectors = {
37
37
  parameters: [
38
38
  { name: 'uuids', type: 'array', required: true, description: '从 search_mcp_registry 结果的 directoryUuid 复制', minItems: 1, items: { name: 'u', type: 'string', required: true, description: 'uuid' } }
39
39
  ],
40
- callExample: `[TOOL:suggest_connectors]
40
+ callExample: `[TOOL:suggest_connectors]
41
41
  [P:uuids]${'${'}JSON.stringify(["uuid-from-search-result"])[ENDTOOL]`,
42
42
  layerId: 'tool.mcp_apps',
43
43
  };
@@ -23,9 +23,9 @@ export const message_compose_v1 = {
23
23
  ],
24
24
  } },
25
25
  ],
26
- callExample: `[TOOL:message_compose_v1]
27
- [P:kind]email
28
- [P:summary_title]Follow-up on Q3 review
26
+ callExample: `[TOOL:message_compose_v1]
27
+ [P:kind]email
28
+ [P:summary_title]Follow-up on Q3 review
29
29
  [P:variants]${'${'}JSON.stringify([{"label":"direct","subject":"Quick follow-up","body":"..."}])[ENDTOOL]`,
30
30
  layerId: 'tool.manifest',
31
31
  };
@@ -23,7 +23,7 @@ export const places_search = {
23
23
  { name: 'location_bias_lng', type: 'number', required: false, description: '可选经度' },
24
24
  { name: 'location_bias_radius', type: 'number', required: false, description: '米 (默认 5000)', default: 5000 }
25
25
  ],
26
- callExample: `[TOOL:places_search]
26
+ callExample: `[TOOL:places_search]
27
27
  [P:queries]${'${'}JSON.stringify([{"query":"ramen restaurants Tokyo"}])[ENDTOOL]`,
28
28
  layerId: 'tool.manifest',
29
29
  };
@@ -77,7 +77,7 @@ export const places_map_display_v0 = {
77
77
  { name: 'title', type: 'string', required: false, description: '行程标题' },
78
78
  { name: 'narrative', type: 'string', required: false, description: '行程叙述' },
79
79
  ],
80
- callExample: `[TOOL:places_map_display_v0]
80
+ callExample: `[TOOL:places_map_display_v0]
81
81
  [P:locations]${'${'}JSON.stringify([{"name":"Senso-ji","latitude":35.7148,"longitude":139.7967,"place_id":"ChIJ..."}])[ENDTOOL]`,
82
82
  layerId: 'tool.manifest',
83
83
  };
@@ -15,7 +15,7 @@ export const present_files = {
15
15
  parameters: [
16
16
  { name: 'filepaths', type: 'array', required: true, description: '至少 1 个文件路径', minItems: 1, items: { name: 'path', type: 'string', required: true, description: '容器内路径' } },
17
17
  ],
18
- callExample: `[TOOL:present_files]
18
+ callExample: `[TOOL:present_files]
19
19
  [P:filepaths]${'${'}JSON.stringify(["/home/bolloon/report.md"])[ENDTOOL]`,
20
20
  layerId: 'tool.manifest',
21
21
  };
@@ -33,8 +33,8 @@ export const recipe_display_v0 = {
33
33
  } },
34
34
  { name: 'notes', type: 'string', required: false, description: '附加说明' },
35
35
  ],
36
- callExample: `[TOOL:recipe_display_v0]
37
- [P:title]Pasta
36
+ callExample: `[TOOL:recipe_display_v0]
37
+ [P:title]Pasta
38
38
  [P:ingredients]${'${'}JSON.stringify([{"id":"a1","amount":500,"name":"pasta"}])[ENDTOOL]`,
39
39
  layerId: 'tool.manifest',
40
40
  };
@@ -17,11 +17,11 @@ export const str_replace = {
17
17
  { name: 'new_str', type: 'string', required: true, description: '新字符串 (空字符串 = 删除)', default: '' },
18
18
  { name: 'path', type: 'string', required: true, description: '文件路径' },
19
19
  ],
20
- callExample: `[TOOL:str_replace]
21
- [P:description]修复 typo
22
- [P:old_str]recieve
23
- [P:new_str]receive
24
- [P:path]/home/bolloon/main.py
20
+ callExample: `[TOOL:str_replace]
21
+ [P:description]修复 typo
22
+ [P:old_str]recieve
23
+ [P:new_str]receive
24
+ [P:path]/home/bolloon/main.py
25
25
  [ENDTOOL]`,
26
26
  layerId: 'tool.manifest',
27
27
  };
@@ -16,9 +16,9 @@ export const view = {
16
16
  { name: 'path', type: 'string', required: true, description: '绝对路径' },
17
17
  { name: 'view_range', type: 'array', required: false, description: '[start, end] 1-indexed, end=-1 表示到末尾', minItems: 2, maxItems: 2, items: { name: 'r', type: 'integer', required: true, description: '行号' } }
18
18
  ],
19
- callExample: `[TOOL:view]
20
- [P:description]读 README
21
- [P:path]/home/bolloon/README.md
19
+ callExample: `[TOOL:view]
20
+ [P:description]读 README
21
+ [P:path]/home/bolloon/README.md
22
22
  [ENDTOOL]`,
23
23
  layerId: 'tool.manifest',
24
24
  };
@@ -18,10 +18,10 @@ export const weather_fetch = {
18
18
  { name: 'latitude', type: 'number', required: true, description: '纬度' },
19
19
  { name: 'longitude', type: 'number', required: true, description: '经度' },
20
20
  ],
21
- callExample: `[TOOL:weather_fetch]
22
- [P:location_name]San Francisco, CA
23
- [P:latitude]37.78
24
- [P:longitude]-122.41
21
+ callExample: `[TOOL:weather_fetch]
22
+ [P:location_name]San Francisco, CA
23
+ [P:latitude]37.78
24
+ [P:longitude]-122.41
25
25
  [ENDTOOL]`,
26
26
  layerId: 'tool.manifest',
27
27
  };
@@ -15,8 +15,8 @@ export const web_search = {
15
15
  parameters: [
16
16
  { name: 'query', type: 'string', required: true, description: '搜索查询 (1-6 词最佳)' },
17
17
  ],
18
- callExample: `[TOOL:web_search]
19
- [P:query]S&P 500 current price
18
+ callExample: `[TOOL:web_search]
19
+ [P:query]S&P 500 current price
20
20
  [ENDTOOL]`,
21
21
  layerId: 'tool.web_search',
22
22
  };
@@ -44,8 +44,8 @@ export const web_fetch = {
44
44
  { name: 'web_fetch_rate_limit_key', type: 'string', required: false, description: '速率限制键' },
45
45
  { name: 'web_fetch_rate_limit_dark_launch', type: 'boolean', required: false, description: '速率限制暗启动模式' },
46
46
  ],
47
- callExample: `[TOOL:web_fetch]
48
- [P:url]https://example.com/article
47
+ callExample: `[TOOL:web_fetch]
48
+ [P:url]https://example.com/article
49
49
  [ENDTOOL]`,
50
50
  layerId: 'tool.manifest',
51
51
  };
@@ -81,21 +81,21 @@ function getLLM() {
81
81
  }
82
82
  return cachedModel;
83
83
  }
84
- const CORRELATION_PROMPT = `你是"判断力关联分析器"。给定两条 judgment:
85
- A: {a}
86
- B: {b}
87
-
88
- 它们经常在同一对话里被同时注入 (共现 {co} 次).
89
- 判断 A 与 B 的因果关系:
90
- - "A→B": A 引发 B (A 概念在 B 之前)
91
- - "B→A": B 引发 A
92
- - "common_cause": 共同原因 (e.g. 都是某场景触发)
93
- - "unclear": 关系不明确
94
-
95
- 输出严格 JSON:
96
- {
97
- "direction": "A→B" | "B→A" | "common_cause" | "unclear",
98
- "explanation": "≤100 字解释, 含 1 个具体例"
84
+ const CORRELATION_PROMPT = `你是"判断力关联分析器"。给定两条 judgment:
85
+ A: {a}
86
+ B: {b}
87
+
88
+ 它们经常在同一对话里被同时注入 (共现 {co} 次).
89
+ 判断 A 与 B 的因果关系:
90
+ - "A→B": A 引发 B (A 概念在 B 之前)
91
+ - "B→A": B 引发 A
92
+ - "common_cause": 共同原因 (e.g. 都是某场景触发)
93
+ - "unclear": 关系不明确
94
+
95
+ 输出严格 JSON:
96
+ {
97
+ "direction": "A→B" | "B→A" | "common_cause" | "unclear",
98
+ "explanation": "≤100 字解释, 含 1 个具体例"
99
99
  }`;
100
100
  async function explainPair(judgmentA, judgmentB, coOccurrence) {
101
101
  const fallback = { direction: 'unclear', explanation: '(LLM 不可用, 仅显示统计)' };
@@ -213,21 +213,21 @@ export async function runCorrelationAnalysis(opts = {}) {
213
213
  }
214
214
  return out;
215
215
  }
216
- const INTERVENTION_PROMPT = `你是"判断力干预分析器"。判断力库有一条 judgment, 用户想评估它的边际贡献.
217
- 给定:
218
- - judgment: {judgment}
219
- - 上次用过的场景 (user 输入 + AI 回复): {scenario}
220
- - 同时存在的相邻 judgment (供参考): {peers}
221
-
222
- 模拟反事实推理: 如果库**没有**这条 judgment, AI 在同一场景下回答会怎么变?
223
-
224
- 输出严格 JSON:
225
- {
226
- "causalEffect": 0.0-1.0, // 0 = 无影响, 1 = 行为完全变
227
- "reasoning": "2-3 步推理, 含 1 个具体例",
228
- "confidence": 0.0-1.0
229
- }
230
-
216
+ const INTERVENTION_PROMPT = `你是"判断力干预分析器"。判断力库有一条 judgment, 用户想评估它的边际贡献.
217
+ 给定:
218
+ - judgment: {judgment}
219
+ - 上次用过的场景 (user 输入 + AI 回复): {scenario}
220
+ - 同时存在的相邻 judgment (供参考): {peers}
221
+
222
+ 模拟反事实推理: 如果库**没有**这条 judgment, AI 在同一场景下回答会怎么变?
223
+
224
+ 输出严格 JSON:
225
+ {
226
+ "causalEffect": 0.0-1.0, // 0 = 无影响, 1 = 行为完全变
227
+ "reasoning": "2-3 步推理, 含 1 个具体例",
228
+ "confidence": 0.0-1.0
229
+ }
230
+
231
231
  注意: causalEffect < 0 也合法 (如"没有这条 AI 反而更好" — 库污染)`;
232
232
  export async function runIntervention(judgmentId, opts = {}) {
233
233
  const fallback = {
@@ -273,27 +273,27 @@ export async function runIntervention(judgmentId, opts = {}) {
273
273
  return fallback;
274
274
  }
275
275
  }
276
- const COUNTERFACTUAL_PROMPT = `你是"判断力反事实审计员"。某次 AI 回复违反了注入的 judgment. 判断是库设计问题还是 LLM 偶然违规.
277
-
278
- 事件:
279
- - 用户: {userInput}
280
- - AI 回复: {aiReply}
281
- - 违反原则: {principles}
282
-
283
- 构造 3 个反事实 scenario:
284
- 1. 删去最相关那条 judgment
285
- 2. 把那条 judgment 改成反向 (例如"必须"→"避免")
286
- 3. 删去整个 channel 的 judgment 库 (空库)
287
-
288
- 每个 scenario 模拟 AI 在该库下的回答, 判断还会不会违规.
289
-
290
- 输出严格 JSON:
291
- {
292
- "scenarios": [
293
- { "modification": "...", "outcomeCompliant": true/false, "explanation": "≤100 字" }
294
- ],
295
- "verdict": "库设计合理" | "建议调库" | "需更多数据",
296
- "recomendaciones": "≤200 字, ≤3 条建议"
276
+ const COUNTERFACTUAL_PROMPT = `你是"判断力反事实审计员"。某次 AI 回复违反了注入的 judgment. 判断是库设计问题还是 LLM 偶然违规.
277
+
278
+ 事件:
279
+ - 用户: {userInput}
280
+ - AI 回复: {aiReply}
281
+ - 违反原则: {principles}
282
+
283
+ 构造 3 个反事实 scenario:
284
+ 1. 删去最相关那条 judgment
285
+ 2. 把那条 judgment 改成反向 (例如"必须"→"避免")
286
+ 3. 删去整个 channel 的 judgment 库 (空库)
287
+
288
+ 每个 scenario 模拟 AI 在该库下的回答, 判断还会不会违规.
289
+
290
+ 输出严格 JSON:
291
+ {
292
+ "scenarios": [
293
+ { "modification": "...", "outcomeCompliant": true/false, "explanation": "≤100 字" }
294
+ ],
295
+ "verdict": "库设计合理" | "建议调库" | "需更多数据",
296
+ "recomendaciones": "≤200 字, ≤3 条建议"
297
297
  }`;
298
298
  export async function runCounterfactualAudit(opts) {
299
299
  const fallback = {
@@ -4,39 +4,39 @@
4
4
  * - 演化对齐: 判定新判断力与已有判断力的关系 (merge/contradict/unrelated)
5
5
  */
6
6
  import { getModel } from '../llm/pi-ai.js';
7
- const DISTILL_SYSTEM_PROMPT = `你是一个"判断力蒸馏器"。从给定的对话片段中,提取出**一条**可以长期复用的判断力原则。
8
-
9
- 要求:
10
- - 长度 30-80 字(中文字符),软目标 50 字
11
- - 用陈述句,不要"我觉得/我想要"这种主观前缀
12
- - 要有可操作性,能被未来的自己/AI 引用
13
- - 如果对话里没有值得提炼的判断力,返回 {"value": null}
14
-
15
- 输出格式(严格 JSON,无其他文字):
16
- {
17
- "value": "<30-80 字的判断力>" | null,
18
- "category": "rule" | "preference" | "trajectory" | "reward",
19
- "confidence": 0.0-1.0,
20
- "evidence": "<原文中支持这句话的关键句,不超过 30 字>"
7
+ const DISTILL_SYSTEM_PROMPT = `你是一个"判断力蒸馏器"。从给定的对话片段中,提取出**一条**可以长期复用的判断力原则。
8
+
9
+ 要求:
10
+ - 长度 30-80 字(中文字符),软目标 50 字
11
+ - 用陈述句,不要"我觉得/我想要"这种主观前缀
12
+ - 要有可操作性,能被未来的自己/AI 引用
13
+ - 如果对话里没有值得提炼的判断力,返回 {"value": null}
14
+
15
+ 输出格式(严格 JSON,无其他文字):
16
+ {
17
+ "value": "<30-80 字的判断力>" | null,
18
+ "category": "rule" | "preference" | "trajectory" | "reward",
19
+ "confidence": 0.0-1.0,
20
+ "evidence": "<原文中支持这句话的关键句,不超过 30 字>"
21
21
  }`;
22
- const EVOLVE_SYSTEM_PROMPT = `你是"判断力演化对齐器"。对比一条新判断力与已有判断力,判定关系。
23
-
24
- 新判断力:
25
- {new_value}
26
-
27
- 已有判断力列表(最多 10 条):
28
- {existing_list}
29
-
30
- 对每条已有判断力,判定:
31
- - "merge": 新判断力是这条的更新版/具体版/纠正版 → 旧条应被 superseded
32
- - "contradict": 新判断力与这条方向相反(例如"保守"vs"激进") → 旧条应被 superseded
33
- - "unrelated": 两者主题不同,各自保留
34
-
35
- 输出严格 JSON:
36
- {
37
- "relations": [
38
- {"id": "...", "relation": "merge" | "contradict" | "unrelated", "reason": "≤20 字"}
39
- ]
22
+ const EVOLVE_SYSTEM_PROMPT = `你是"判断力演化对齐器"。对比一条新判断力与已有判断力,判定关系。
23
+
24
+ 新判断力:
25
+ {new_value}
26
+
27
+ 已有判断力列表(最多 10 条):
28
+ {existing_list}
29
+
30
+ 对每条已有判断力,判定:
31
+ - "merge": 新判断力是这条的更新版/具体版/纠正版 → 旧条应被 superseded
32
+ - "contradict": 新判断力与这条方向相反(例如"保守"vs"激进") → 旧条应被 superseded
33
+ - "unrelated": 两者主题不同,各自保留
34
+
35
+ 输出严格 JSON:
36
+ {
37
+ "relations": [
38
+ {"id": "...", "relation": "merge" | "contradict" | "unrelated", "reason": "≤20 字"}
39
+ ]
40
40
  }`;
41
41
  let cachedModel = null;
42
42
  function getDistillModel() {
@@ -56,13 +56,13 @@ export async function detectIfWorthStoring(turns) {
56
56
  if (!model)
57
57
  return fallback;
58
58
  const conversation = formatTurns(turns);
59
- const prompt = `请判断以下对话是否包含"值得长期保留的判断力"(用户的偏好/规则/原则/价值观)。
60
- 如果包含,返回 {"worth": true, "reason": "≤20 字理由"}
61
- 如果不包含,返回 {"worth": false, "reason": "≤20 字理由"}
62
-
63
- 对话:
64
- ${conversation}
65
-
59
+ const prompt = `请判断以下对话是否包含"值得长期保留的判断力"(用户的偏好/规则/原则/价值观)。
60
+ 如果包含,返回 {"worth": true, "reason": "≤20 字理由"}
61
+ 如果不包含,返回 {"worth": false, "reason": "≤20 字理由"}
62
+
63
+ 对话:
64
+ ${conversation}
65
+
66
66
  输出严格 JSON:`;
67
67
  try {
68
68
  const res = await withRetry(() => model.chat(prompt, '判断力检测专家'));
@@ -84,9 +84,9 @@ export async function distillFromConversation(turns) {
84
84
  if (!model)
85
85
  return fallback;
86
86
  const conversation = formatTurns(turns);
87
- const userPrompt = `对话上下文(最多 10 轮):
88
- ${conversation}
89
-
87
+ const userPrompt = `对话上下文(最多 10 轮):
88
+ ${conversation}
89
+
90
90
  输出:`;
91
91
  try {
92
92
  const res = await withRetry(() => model.chat(userPrompt, DISTILL_SYSTEM_PROMPT));
@@ -143,20 +143,20 @@ async function llmDistill(rawInput, trigger, context, conversationHistory) {
143
143
  const historyText = conversationHistory
144
144
  ? conversationHistory.slice(-5).join('\n')
145
145
  : 'No history';
146
- const prompt = `从以下人类输入中提取判断力原理。
147
-
148
- 输入类型: ${trigger}
149
- 输入内容: ${rawInput}
150
- 上下文: ${context}
151
- 对话历史:
152
- ${historyText}
153
-
154
- 请提取:
155
- 1. type: rule(明确规则) | preference(偏好) | trajectory(行为轨迹) | reward(奖励信号)
156
- 2. content: 凝练后的原理(简洁,1-2句话)
157
- 3. confidence: 0.0-1.0 的置信度
158
- 4. evidence: 支持证据(如有)
159
-
146
+ const prompt = `从以下人类输入中提取判断力原理。
147
+
148
+ 输入类型: ${trigger}
149
+ 输入内容: ${rawInput}
150
+ 上下文: ${context}
151
+ 对话历史:
152
+ ${historyText}
153
+
154
+ 请提取:
155
+ 1. type: rule(明确规则) | preference(偏好) | trajectory(行为轨迹) | reward(奖励信号)
156
+ 2. content: 凝练后的原理(简洁,1-2句话)
157
+ 3. confidence: 0.0-1.0 的置信度
158
+ 4. evidence: 支持证据(如有)
159
+
160
160
  直接输出JSON格式,不需要解释。`;
161
161
  try {
162
162
  const response = await llmModel.chat(`对话: ${historyText}\n\n输入: ${rawInput}`, `你是判断力提取专家。从人类输入中提取判断力原理。输入类型: ${trigger}`);
@@ -279,7 +279,7 @@ export async function findRecentSimilarDecisions(decision, withinMs, options) {
279
279
  for (const j of judgments) {
280
280
  if (statusFilter !== 'all' && (j.status ?? 'active') !== statusFilter)
281
281
  continue;
282
- if (new Date(j.timestamp).getTime() < cutoff)
282
+ if (new Date(j.timestamp).getTime() <= cutoff)
283
283
  continue;
284
284
  if (wantChannel) {
285
285
  const jChannel = j.context?.domain;
@@ -29,25 +29,25 @@ function getMonitorModel() {
29
29
  }
30
30
  return cachedModel;
31
31
  }
32
- const MONITOR_PROMPT = `你是"回复合规审计员"。给定:
33
- 1. 用户输入
34
- 2. AI 回复
35
- 3. 该 AI 在生成前被注入的"判断力原则" (前文注入)
36
-
37
- 请判断 AI 回复是否违反了其中任一原则.
38
-
39
- 输出严格 JSON:
40
- {
41
- "compliant": true | false,
42
- "violatedPrinciples": [
43
- {"principle": "<原则原文>", "reason": "<≤30 字原因>"}
44
- ],
45
- "confidence": 0.0-1.0
46
- }
47
-
48
- - 严格判定: 真的有冲突才算违反; "不太相关" 不算违反
49
- - 找不到冲突 → compliant: true, violatedPrinciples: []
50
- - 多个原则同时违反 → 全部列出
32
+ const MONITOR_PROMPT = `你是"回复合规审计员"。给定:
33
+ 1. 用户输入
34
+ 2. AI 回复
35
+ 3. 该 AI 在生成前被注入的"判断力原则" (前文注入)
36
+
37
+ 请判断 AI 回复是否违反了其中任一原则.
38
+
39
+ 输出严格 JSON:
40
+ {
41
+ "compliant": true | false,
42
+ "violatedPrinciples": [
43
+ {"principle": "<原则原文>", "reason": "<≤30 字原因>"}
44
+ ],
45
+ "confidence": 0.0-1.0
46
+ }
47
+
48
+ - 严格判定: 真的有冲突才算违反; "不太相关" 不算违反
49
+ - 找不到冲突 → compliant: true, violatedPrinciples: []
50
+ - 多个原则同时违反 → 全部列出
51
51
  - 输出严格 JSON, 无其他文字`;
52
52
  /**
53
53
  * 监控门主函数: 给定 (userInput, aiReply) 判断是否违反 judgment 库
@@ -71,15 +71,15 @@ export async function checkCompliance(userInput, aiReply) {
71
71
  .slice(0, 5) // 监控只看 Top 5, 太多会让 LLM 关注点分散
72
72
  .map((v, i) => `${i + 1}. [${v.category}] ${v.value}`)
73
73
  .join('\n');
74
- const userPrompt = `【用户输入】
75
- ${userInput.substring(0, 500)}
76
-
77
- 【AI 回复】
78
- ${aiReply.substring(0, 1000)}
79
-
80
- 【注入的判断力原则】
81
- ${principlesText}
82
-
74
+ const userPrompt = `【用户输入】
75
+ ${userInput.substring(0, 500)}
76
+
77
+ 【AI 回复】
78
+ ${aiReply.substring(0, 1000)}
79
+
80
+ 【注入的判断力原则】
81
+ ${principlesText}
82
+
83
83
  输出:`;
84
84
  const res = await model.chat(userPrompt, MONITOR_PROMPT);
85
85
  return parseMonitorResponse(res.reply, fallback);