@wowok/agent-mcp 2.3.14 → 2.3.18

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 (189) hide show
  1. package/dist/config/index.d.ts +1 -0
  2. package/dist/config/index.js +1 -0
  3. package/dist/config/runtime.d.ts +26 -0
  4. package/dist/config/runtime.js +217 -0
  5. package/dist/customer/index.d.ts +9 -0
  6. package/dist/customer/index.js +9 -0
  7. package/dist/customer/industry-risks.d.ts +40 -0
  8. package/dist/customer/industry-risks.js +438 -0
  9. package/dist/customer/info-puzzle.d.ts +102 -0
  10. package/dist/customer/info-puzzle.js +312 -0
  11. package/dist/customer/order-monitor.d.ts +75 -0
  12. package/dist/customer/order-monitor.js +327 -0
  13. package/dist/customer/order-strategy.d.ts +36 -0
  14. package/dist/customer/order-strategy.js +373 -0
  15. package/dist/customer/post-purchase.d.ts +42 -0
  16. package/dist/customer/post-purchase.js +350 -0
  17. package/dist/customer/reminder-system.d.ts +42 -0
  18. package/dist/customer/reminder-system.js +295 -0
  19. package/dist/customer/risk-assessment.d.ts +8 -0
  20. package/dist/customer/risk-assessment.js +337 -0
  21. package/dist/customer/types.d.ts +193 -0
  22. package/dist/customer/types.js +13 -0
  23. package/dist/customer/user-preferences.d.ts +70 -0
  24. package/dist/customer/user-preferences.js +460 -0
  25. package/dist/experience/experience-reuse.d.ts +10 -0
  26. package/dist/experience/experience-reuse.js +103 -0
  27. package/dist/experience/index.d.ts +6 -0
  28. package/dist/experience/index.js +5 -0
  29. package/dist/experience/intent-distill.d.ts +3 -0
  30. package/dist/experience/intent-distill.js +83 -0
  31. package/dist/experience/realtime-feedback.d.ts +5 -0
  32. package/dist/experience/realtime-feedback.js +94 -0
  33. package/dist/experience/types.d.ts +50 -0
  34. package/dist/experience/types.js +1 -0
  35. package/dist/experience/user-profile.d.ts +25 -0
  36. package/dist/experience/user-profile.js +171 -0
  37. package/dist/index.js +842 -371
  38. package/dist/knowledge/acquisition-flywheel.d.ts +53 -0
  39. package/dist/knowledge/acquisition-flywheel.js +192 -0
  40. package/dist/knowledge/arbitration-trust.d.ts +24 -0
  41. package/dist/knowledge/arbitration-trust.js +117 -0
  42. package/dist/knowledge/audit-rules.d.ts +28 -0
  43. package/dist/knowledge/audit-rules.js +141 -0
  44. package/dist/knowledge/demand-matching.d.ts +29 -0
  45. package/dist/knowledge/demand-matching.js +132 -0
  46. package/dist/knowledge/dynamic-pricing.d.ts +31 -0
  47. package/dist/knowledge/dynamic-pricing.js +87 -0
  48. package/dist/knowledge/flywheel-loop.d.ts +87 -0
  49. package/dist/knowledge/flywheel-loop.js +378 -0
  50. package/dist/knowledge/glossary.d.ts +18 -0
  51. package/dist/knowledge/glossary.js +209 -0
  52. package/dist/knowledge/guard-ledger.d.ts +19 -0
  53. package/dist/knowledge/guard-ledger.js +219 -0
  54. package/dist/knowledge/guard-puzzle.d.ts +93 -0
  55. package/dist/knowledge/guard-puzzle.js +278 -0
  56. package/dist/knowledge/guard-risk.d.ts +60 -0
  57. package/dist/knowledge/guard-risk.js +474 -0
  58. package/dist/knowledge/guard-translation.d.ts +46 -0
  59. package/dist/knowledge/guard-translation.js +487 -0
  60. package/dist/knowledge/index.d.ts +77 -0
  61. package/dist/knowledge/index.js +79 -0
  62. package/dist/knowledge/industry-evolution.d.ts +82 -0
  63. package/dist/knowledge/industry-evolution.js +323 -0
  64. package/dist/knowledge/industry-generalizer.d.ts +17 -0
  65. package/dist/knowledge/industry-generalizer.js +381 -0
  66. package/dist/knowledge/industry-registry.d.ts +48 -0
  67. package/dist/knowledge/industry-registry.js +187 -0
  68. package/dist/knowledge/intent-metrics.d.ts +42 -0
  69. package/dist/knowledge/intent-metrics.js +566 -0
  70. package/dist/knowledge/process-model.d.ts +24 -0
  71. package/dist/knowledge/process-model.js +160 -0
  72. package/dist/knowledge/reputation-rules.d.ts +42 -0
  73. package/dist/knowledge/reputation-rules.js +99 -0
  74. package/dist/knowledge/reward-templates.d.ts +25 -0
  75. package/dist/knowledge/reward-templates.js +125 -0
  76. package/dist/knowledge/safety-rules.d.ts +36 -0
  77. package/dist/knowledge/safety-rules.js +232 -0
  78. package/dist/knowledge/tool-constraints.d.ts +30 -0
  79. package/dist/knowledge/tool-constraints.js +175 -0
  80. package/dist/knowledge/trust-metrics.d.ts +37 -0
  81. package/dist/knowledge/trust-metrics.js +138 -0
  82. package/dist/loop-engineering/diagnose.d.ts +3 -2
  83. package/dist/loop-engineering/diagnose.js +94 -0
  84. package/dist/loop-engineering/improve.d.ts +1 -1
  85. package/dist/loop-engineering/improve.js +52 -1
  86. package/dist/project/graph.d.ts +71 -0
  87. package/dist/project/graph.js +314 -0
  88. package/dist/project/index.d.ts +62 -0
  89. package/dist/project/index.js +167 -0
  90. package/dist/project/namespace.d.ts +62 -0
  91. package/dist/project/namespace.js +181 -0
  92. package/dist/project/query.d.ts +40 -0
  93. package/dist/project/query.js +110 -0
  94. package/dist/safety/confirm-gate.d.ts +17 -0
  95. package/dist/safety/confirm-gate.js +88 -0
  96. package/dist/safety/index.d.ts +3 -0
  97. package/dist/safety/index.js +3 -0
  98. package/dist/safety/preview.d.ts +2 -0
  99. package/dist/safety/preview.js +36 -0
  100. package/dist/schema/call/allocation.d.ts +39 -14
  101. package/dist/schema/call/arbitration.d.ts +187 -162
  102. package/dist/schema/call/base.d.ts +1971 -87
  103. package/dist/schema/call/base.js +135 -3
  104. package/dist/schema/call/bridge-handler.js +15 -2
  105. package/dist/schema/call/bridge.d.ts +1478 -53
  106. package/dist/schema/call/bridge.js +50 -2
  107. package/dist/schema/call/contact.d.ts +25 -0
  108. package/dist/schema/call/demand.d.ts +79 -54
  109. package/dist/schema/call/guard.d.ts +125 -50
  110. package/dist/schema/call/handler.d.ts +3 -0
  111. package/dist/schema/call/handler.js +60 -14
  112. package/dist/schema/call/machine.d.ts +988 -938
  113. package/dist/schema/call/order.d.ts +25 -0
  114. package/dist/schema/call/payment.d.ts +25 -0
  115. package/dist/schema/call/permission.d.ts +244 -219
  116. package/dist/schema/call/personal.d.ts +25 -0
  117. package/dist/schema/call/progress.d.ts +25 -0
  118. package/dist/schema/call/proof.d.ts +62 -12
  119. package/dist/schema/call/proof.js +3 -3
  120. package/dist/schema/call/repository.d.ts +101 -76
  121. package/dist/schema/call/reward.d.ts +55 -30
  122. package/dist/schema/call/semantic.d.ts +10 -2
  123. package/dist/schema/call/semantic.js +616 -11
  124. package/dist/schema/call/service.d.ts +442 -417
  125. package/dist/schema/call/treasury.d.ts +25 -0
  126. package/dist/schema/common/index.js +3 -3
  127. package/dist/schema/config/index.d.ts +18 -0
  128. package/dist/schema/config/index.js +17 -0
  129. package/dist/schema/index.d.ts +6 -0
  130. package/dist/schema/index.js +5 -0
  131. package/dist/schema/local/index.d.ts +237 -81
  132. package/dist/schema/local/index.js +42 -6
  133. package/dist/schema/messenger/index.d.ts +1018 -79
  134. package/dist/schema/messenger/index.js +26 -17
  135. package/dist/schema/operations.d.ts +3192 -1746
  136. package/dist/schema/operations.js +93 -98
  137. package/dist/schema/project/index.d.ts +21 -0
  138. package/dist/schema/project/index.js +32 -0
  139. package/dist/schema/query/index.d.ts +2762 -1856
  140. package/dist/schema/query/index.js +38 -35
  141. package/dist/schema/schema-query/index.d.ts +33 -0
  142. package/dist/schema/schema-query/index.js +36 -0
  143. package/dist/schema/schema-version.d.ts +25 -0
  144. package/dist/schema/schema-version.js +76 -0
  145. package/dist/schema/trust/index.d.ts +407 -0
  146. package/dist/schema/trust/index.js +113 -0
  147. package/dist/schemas/account_operation.output.json +25 -16
  148. package/dist/schemas/account_operation.schema.json +1 -1
  149. package/dist/schemas/bridge_operation.output.json +744 -0
  150. package/dist/schemas/bridge_operation.schema.json +82 -8
  151. package/dist/schemas/config_operation.output.json +18 -0
  152. package/dist/schemas/config_operation.schema.json +34 -0
  153. package/dist/schemas/guard-node-schema.json +82 -0
  154. package/dist/schemas/guard2file.schema.json +23 -0
  155. package/dist/schemas/index.json +19 -1
  156. package/dist/schemas/local_info_operation.output.json +23 -0
  157. package/dist/schemas/local_info_operation.schema.json +1 -1
  158. package/dist/schemas/local_mark_operation.output.json +24 -1
  159. package/dist/schemas/local_mark_operation.schema.json +4 -4
  160. package/dist/schemas/machineNode2file.schema.json +23 -0
  161. package/dist/schemas/messenger_operation.output.json +752 -0
  162. package/dist/schemas/onchain_events.output.json +718 -0
  163. package/dist/schemas/onchain_operations.output.json +627 -18
  164. package/dist/schemas/onchain_operations.schema.json +115 -39
  165. package/dist/schemas/onchain_operations_allocation.schema.json +23 -0
  166. package/dist/schemas/onchain_operations_arbitration.schema.json +23 -0
  167. package/dist/schemas/onchain_operations_contact.schema.json +23 -0
  168. package/dist/schemas/onchain_operations_demand.schema.json +23 -0
  169. package/dist/schemas/onchain_operations_gen_passport.schema.json +46 -0
  170. package/dist/schemas/onchain_operations_guard.schema.json +26 -16
  171. package/dist/schemas/onchain_operations_machine.schema.json +89 -23
  172. package/dist/schemas/onchain_operations_order.schema.json +23 -0
  173. package/dist/schemas/onchain_operations_payment.schema.json +23 -0
  174. package/dist/schemas/onchain_operations_permission.schema.json +23 -0
  175. package/dist/schemas/onchain_operations_personal.schema.json +23 -0
  176. package/dist/schemas/onchain_operations_progress.schema.json +23 -0
  177. package/dist/schemas/onchain_operations_repository.schema.json +23 -0
  178. package/dist/schemas/onchain_operations_reward.schema.json +23 -0
  179. package/dist/schemas/onchain_operations_service.schema.json +23 -0
  180. package/dist/schemas/onchain_operations_treasury.schema.json +23 -0
  181. package/dist/schemas/onchain_table_data.output.json +939 -69
  182. package/dist/schemas/onchain_table_data.schema.json +2 -2
  183. package/dist/schemas/project_operation.output.json +18 -0
  184. package/dist/schemas/project_operation.schema.json +42 -0
  185. package/dist/schemas/query_toolkit.schema.json +360 -368
  186. package/dist/schemas/schema_query.schema.json +6 -3
  187. package/dist/schemas/trust_score.output.json +327 -0
  188. package/dist/schemas/trust_score.schema.json +46 -0
  189. package/package.json +2 -2
@@ -0,0 +1,378 @@
1
+ import { aggregateIndustryMetrics, evaluateIndustryHealth, suggestIndustryUpdate, } from "./industry-evolution.js";
2
+ import { getIndustryProfile, resolveIndustryName } from "./industry-registry.js";
3
+ import { evaluateIndustryHealthByIntent, suggestIndustryUpdateByIntent, getRoleAdvice, filterSuggestionsByRole, getIntentProfile, } from "./intent-metrics.js";
4
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
5
+ import { dirname, join } from "path";
6
+ import { homedir } from "os";
7
+ export const FLYWHEEL_LOOP_VERSION = 2;
8
+ const MIN_SIGNALS_FOR_EVOLUTION = 10;
9
+ const DEFAULT_SCHEDULE = {
10
+ mode: "manual",
11
+ };
12
+ const industrySchedules = new Map();
13
+ const industryLastUpdate = new Map();
14
+ const industryIntent = new Map();
15
+ const signalBuffer = new Map();
16
+ const decisionContexts = new Map();
17
+ const latestMetrics = new Map();
18
+ const latestHealth = new Map();
19
+ const pendingSuggestions = new Map();
20
+ export function recordIndustrySignal(industry, operation, outcome) {
21
+ if (!industry)
22
+ return;
23
+ const resolved = resolveIndustryName(industry) ?? industry;
24
+ const signal = {
25
+ industry: resolved,
26
+ operation_type: operation.type,
27
+ success: outcome.success,
28
+ error_code: outcome.error_code,
29
+ timestamp: Date.now(),
30
+ };
31
+ const list = signalBuffer.get(resolved) ?? [];
32
+ list.push(signal);
33
+ signalBuffer.set(resolved, list);
34
+ tryMaybeAutoTrigger(resolved, list.length);
35
+ }
36
+ function tryMaybeAutoTrigger(resolved, signalCount) {
37
+ const schedule = industrySchedules.get(resolved) ?? DEFAULT_SCHEDULE;
38
+ if (schedule.mode === "manual")
39
+ return;
40
+ const now = Date.now();
41
+ const lastUpdate = industryLastUpdate.get(resolved) ?? 0;
42
+ if (schedule.mode === "realtime") {
43
+ if (signalCount >= MIN_SIGNALS_FOR_EVOLUTION &&
44
+ signalCount % MIN_SIGNALS_FOR_EVOLUTION === 0) {
45
+ doAutoUpdate(resolved, schedule);
46
+ }
47
+ return;
48
+ }
49
+ if (schedule.mode === "semi_realtime") {
50
+ const threshold = schedule.signal_threshold ?? 20;
51
+ const interval = schedule.time_interval_ms ?? 5 * 60 * 1000;
52
+ const signalMet = signalCount >= threshold && signalCount % threshold === 0;
53
+ const timeMet = lastUpdate > 0 && (now - lastUpdate) >= interval;
54
+ if (signalMet || timeMet) {
55
+ doAutoUpdate(resolved, schedule);
56
+ }
57
+ }
58
+ }
59
+ function doAutoUpdate(resolved, schedule) {
60
+ try {
61
+ const result = updateIndustryCognition(resolved);
62
+ industryLastUpdate.set(resolved, Date.now());
63
+ if (schedule.auto_apply && result.suggestions_generated > 0) {
64
+ const suggestions = pendingSuggestions.get(resolved) ?? [];
65
+ const { applyIndustryUpdate } = require("./industry-evolution.js");
66
+ for (const s of suggestions) {
67
+ try {
68
+ applyIndustryUpdate(resolved, s);
69
+ }
70
+ catch { }
71
+ }
72
+ }
73
+ }
74
+ catch {
75
+ }
76
+ }
77
+ export function setEvolutionSchedule(industry, config) {
78
+ if (!industry)
79
+ return;
80
+ const resolved = resolveIndustryName(industry) ?? industry;
81
+ industrySchedules.set(resolved, config);
82
+ }
83
+ export function getEvolutionSchedule(industry) {
84
+ const resolved = resolveIndustryName(industry) ?? industry;
85
+ return industrySchedules.get(resolved) ?? DEFAULT_SCHEDULE;
86
+ }
87
+ export function setIndustryIntent(industry, intent) {
88
+ if (!industry)
89
+ return;
90
+ const resolved = resolveIndustryName(industry) ?? industry;
91
+ industryIntent.set(resolved, intent);
92
+ }
93
+ export function getIndustryIntent(industry) {
94
+ const resolved = resolveIndustryName(industry) ?? industry;
95
+ return industryIntent.get(resolved) ?? "default";
96
+ }
97
+ export function getIndustrySignalCount(industry) {
98
+ const resolved = resolveIndustryName(industry) ?? industry;
99
+ return signalBuffer.get(resolved)?.length ?? 0;
100
+ }
101
+ export function getIndustrySignals(industry) {
102
+ const resolved = resolveIndustryName(industry) ?? industry;
103
+ return [...(signalBuffer.get(resolved) ?? [])];
104
+ }
105
+ export function listIndustriesWithSignals() {
106
+ return Array.from(signalBuffer.keys());
107
+ }
108
+ export function getPendingSuggestions(industry) {
109
+ const resolved = resolveIndustryName(industry) ?? industry;
110
+ return [...(pendingSuggestions.get(resolved) ?? [])];
111
+ }
112
+ export function recordDecisionContext(ctx, graph) {
113
+ if (!ctx.id || !ctx.node_id)
114
+ return;
115
+ decisionContexts.set(ctx.id, { ...ctx });
116
+ if (graph) {
117
+ try {
118
+ graph.attachDecisionContext(ctx.node_id, {
119
+ id: ctx.id,
120
+ decided_at: ctx.decided_at,
121
+ decider: ctx.decider,
122
+ industry: ctx.industry,
123
+ intent: ctx.intent,
124
+ alternatives: ctx.alternatives,
125
+ rationale: ctx.rationale,
126
+ outcome: ctx.outcome,
127
+ });
128
+ }
129
+ catch {
130
+ }
131
+ }
132
+ }
133
+ export function queryDecisionsByIndustry(industry) {
134
+ const resolved = resolveIndustryName(industry) ?? industry;
135
+ return Array.from(decisionContexts.values())
136
+ .filter((d) => d.industry === resolved)
137
+ .sort((a, b) => b.decided_at - a.decided_at);
138
+ }
139
+ export function queryDecisionsByNode(nodeId) {
140
+ return Array.from(decisionContexts.values())
141
+ .filter((d) => d.node_id === nodeId)
142
+ .sort((a, b) => b.decided_at - a.decided_at);
143
+ }
144
+ export function backfillDecisionOutcome(decisionId, outcome) {
145
+ const ctx = decisionContexts.get(decisionId);
146
+ if (!ctx)
147
+ return false;
148
+ ctx.outcome = outcome;
149
+ return true;
150
+ }
151
+ export function updateIndustryCognition(industry, rawData) {
152
+ const resolved = resolveIndustryName(industry) ?? industry;
153
+ const signals = signalBuffer.get(resolved) ?? [];
154
+ const result = {
155
+ industry: resolved,
156
+ metrics_updated: false,
157
+ health_recomputed: false,
158
+ suggestions_generated: 0,
159
+ evolution_ready: signals.length >= MIN_SIGNALS_FOR_EVOLUTION,
160
+ };
161
+ if (signals.length < MIN_SIGNALS_FOR_EVOLUTION && (!rawData || rawData.length === 0)) {
162
+ return result;
163
+ }
164
+ let metrics;
165
+ if (rawData && rawData.length > 0) {
166
+ metrics = aggregateIndustryMetrics(resolved, rawData);
167
+ }
168
+ else {
169
+ const synthesizedRaw = signals.map((s) => ({
170
+ industry: resolved,
171
+ completed: s.success,
172
+ has_dispute: !!s.error_code && s.error_code.includes("dispute"),
173
+ has_refund: !!s.error_code && s.error_code.includes("refund"),
174
+ ticket_size: 0n,
175
+ timestamp: s.timestamp,
176
+ }));
177
+ metrics = aggregateIndustryMetrics(resolved, synthesizedRaw);
178
+ }
179
+ latestMetrics.set(resolved, metrics);
180
+ result.metrics_updated = true;
181
+ const intent = industryIntent.get(resolved) ?? "default";
182
+ let health;
183
+ let suggestions;
184
+ if (intent !== "default") {
185
+ health = evaluateIndustryHealthByIntent(resolved, metrics, intent);
186
+ suggestions = suggestIndustryUpdateByIntent(resolved, metrics, intent);
187
+ }
188
+ else {
189
+ health = evaluateIndustryHealth(resolved, metrics);
190
+ suggestions = suggestIndustryUpdate(resolved, metrics);
191
+ }
192
+ latestHealth.set(resolved, health);
193
+ result.health_recomputed = true;
194
+ pendingSuggestions.set(resolved, suggestions);
195
+ result.suggestions_generated = suggestions.length;
196
+ return result;
197
+ }
198
+ export function injectEvolutionContext(_semantic, industry, role) {
199
+ if (!industry) {
200
+ return { confidence: 0 };
201
+ }
202
+ const resolved = resolveIndustryName(industry) ?? industry;
203
+ const profile = getIndustryProfile(resolved);
204
+ if (!profile) {
205
+ return {
206
+ confidence: 0,
207
+ industry_signal: `行业 ${resolved} 尚未注册,建议通过泛化引擎合成画像`,
208
+ };
209
+ }
210
+ const health = latestHealth.get(resolved);
211
+ const metrics = latestMetrics.get(resolved);
212
+ const suggestions = pendingSuggestions.get(resolved) ?? [];
213
+ const signalCount = signalBuffer.get(resolved)?.length ?? 0;
214
+ const intent = industryIntent.get(resolved) ?? "default";
215
+ const parts = [];
216
+ let advice;
217
+ let confidence = 0.5;
218
+ if (health) {
219
+ parts.push(`行业健康度 ${health.health_score}/100(${health.level})`);
220
+ confidence = Math.max(confidence, 0.7);
221
+ if (health.weaknesses.length > 0) {
222
+ advice = `弱项:${health.weaknesses[0]}`;
223
+ }
224
+ if (health.recommendations.length > 0) {
225
+ advice = advice
226
+ ? `${advice};建议:${health.recommendations[0]}`
227
+ : `建议:${health.recommendations[0]}`;
228
+ }
229
+ }
230
+ if (metrics && metrics.anomalies.length > 0) {
231
+ parts.push(`异常:${metrics.anomalies[0]}`);
232
+ confidence = Math.max(confidence, 0.8);
233
+ }
234
+ if (signalCount > 0) {
235
+ parts.push(`累积 ${signalCount} 个行业信号`);
236
+ }
237
+ if (intent !== "default") {
238
+ parts.push(`当前意图:${intent}`);
239
+ }
240
+ if (!advice && suggestions.length > 0) {
241
+ const highPriority = suggestions.find((s) => s.priority === "high") ?? suggestions[0];
242
+ advice = `${highPriority.suggestion_type}:${highPriority.evidence}`;
243
+ confidence = Math.max(confidence, highPriority.confidence);
244
+ }
245
+ let roleAdvice;
246
+ let filteredSuggestions = suggestions;
247
+ if (role) {
248
+ const intentSpec = getIntentProfile(intent);
249
+ if (intentSpec) {
250
+ roleAdvice = getRoleAdvice(intent, role);
251
+ }
252
+ const triggers = intentSpec?.suggestion_triggers ?? [];
253
+ filteredSuggestions = filterSuggestionsByRole(suggestions, role, triggers);
254
+ if (filteredSuggestions.length > 0) {
255
+ const topRole = filteredSuggestions.find((s) => s.priority === "high") ?? filteredSuggestions[0];
256
+ advice = `${topRole.suggestion_type}(${role}):${topRole.evidence}`;
257
+ }
258
+ }
259
+ return {
260
+ industry_signal: parts.length > 0 ? parts.join(";") : undefined,
261
+ evolution_advice: advice,
262
+ confidence,
263
+ health_score: health?.health_score,
264
+ pending_suggestions: filteredSuggestions.length,
265
+ intent: intent !== "default" ? intent : undefined,
266
+ role_advice: roleAdvice && roleAdvice.length > 0 ? roleAdvice : undefined,
267
+ role,
268
+ };
269
+ }
270
+ export function getIndustryEvolutionStatus(industry) {
271
+ const resolved = resolveIndustryName(industry) ?? industry;
272
+ const profile = getIndustryProfile(resolved);
273
+ return {
274
+ industry: resolved,
275
+ version: profile?.version ?? "v0",
276
+ last_updated: profile?.evolution?.last_updated ?? 0,
277
+ signal_count: signalBuffer.get(resolved)?.length ?? 0,
278
+ health: latestHealth.get(resolved),
279
+ pending_suggestions: pendingSuggestions.get(resolved)?.length ?? 0,
280
+ evolution_ready: (signalBuffer.get(resolved)?.length ?? 0) >= MIN_SIGNALS_FOR_EVOLUTION,
281
+ };
282
+ }
283
+ export const EVOLUTION_STATE_VERSION = 1;
284
+ function evolutionStateFilePath() {
285
+ const dir = process.env.WOWOK_CONFIG_DIR
286
+ ? process.env.WOWOK_CONFIG_DIR
287
+ : join(homedir(), ".wowok");
288
+ return join(dir, "evolution-state.json");
289
+ }
290
+ export function saveEvolutionState() {
291
+ const path = evolutionStateFilePath();
292
+ const dir = dirname(path);
293
+ if (!existsSync(dir))
294
+ mkdirSync(dir, { recursive: true });
295
+ const snap = {
296
+ version: EVOLUTION_STATE_VERSION,
297
+ saved_at: Date.now(),
298
+ signal_buffer: Object.fromEntries(signalBuffer),
299
+ decision_contexts: Object.fromEntries(decisionContexts),
300
+ latest_metrics: Object.fromEntries(latestMetrics),
301
+ latest_health: Object.fromEntries(latestHealth),
302
+ pending_suggestions: Object.fromEntries(pendingSuggestions),
303
+ industry_schedules: Object.fromEntries(industrySchedules),
304
+ industry_last_update: Object.fromEntries(industryLastUpdate),
305
+ industry_intent: Object.fromEntries(industryIntent),
306
+ };
307
+ const replacer = (_key, value) => {
308
+ if (typeof value === "bigint") {
309
+ return { __bigint__: value.toString() };
310
+ }
311
+ return value;
312
+ };
313
+ writeFileSync(path, JSON.stringify(snap, replacer, 2), "utf-8");
314
+ return path;
315
+ }
316
+ export function loadEvolutionState() {
317
+ const path = evolutionStateFilePath();
318
+ if (!existsSync(path))
319
+ return false;
320
+ try {
321
+ const raw = readFileSync(path, "utf-8");
322
+ const reviver = (_key, value) => {
323
+ if (value && typeof value === "object" && "__bigint__" in value) {
324
+ return BigInt(value.__bigint__);
325
+ }
326
+ return value;
327
+ };
328
+ const snap = JSON.parse(raw, reviver);
329
+ if (!snap || snap.version !== EVOLUTION_STATE_VERSION)
330
+ return false;
331
+ _resetFlywheelLoopForTest();
332
+ for (const [k, v] of Object.entries(snap.signal_buffer)) {
333
+ signalBuffer.set(k, v);
334
+ }
335
+ for (const [k, v] of Object.entries(snap.decision_contexts)) {
336
+ decisionContexts.set(k, v);
337
+ }
338
+ for (const [k, v] of Object.entries(snap.latest_metrics)) {
339
+ latestMetrics.set(k, v);
340
+ }
341
+ for (const [k, v] of Object.entries(snap.latest_health)) {
342
+ latestHealth.set(k, v);
343
+ }
344
+ for (const [k, v] of Object.entries(snap.pending_suggestions)) {
345
+ pendingSuggestions.set(k, v);
346
+ }
347
+ for (const [k, v] of Object.entries(snap.industry_schedules)) {
348
+ industrySchedules.set(k, v);
349
+ }
350
+ for (const [k, v] of Object.entries(snap.industry_last_update)) {
351
+ industryLastUpdate.set(k, v);
352
+ }
353
+ for (const [k, v] of Object.entries(snap.industry_intent)) {
354
+ industryIntent.set(k, v);
355
+ }
356
+ return true;
357
+ }
358
+ catch {
359
+ return false;
360
+ }
361
+ }
362
+ export function hasPersistedEvolutionState() {
363
+ return existsSync(evolutionStateFilePath());
364
+ }
365
+ export function _resetFlywheelLoopForTest() {
366
+ signalBuffer.clear();
367
+ decisionContexts.clear();
368
+ latestMetrics.clear();
369
+ latestHealth.clear();
370
+ pendingSuggestions.clear();
371
+ industrySchedules.clear();
372
+ industryLastUpdate.clear();
373
+ industryIntent.clear();
374
+ }
375
+ export function _snapshotSignalBuffer() {
376
+ return Object.fromEntries(signalBuffer);
377
+ }
378
+ export { MIN_SIGNALS_FOR_EVOLUTION as FLYWHEEL_LOOP_MIN_SIGNALS };
@@ -0,0 +1,18 @@
1
+ export type GlossaryCategory = "role" | "object" | "operation" | "acceptance" | "permission" | "fund";
2
+ export interface GlossaryEntry {
3
+ term: string;
4
+ definition: string;
5
+ aliases: string[];
6
+ category: GlossaryCategory;
7
+ }
8
+ export declare const CONCEPT_GLOSSARY: GlossaryEntry[];
9
+ export declare function resolveTerm(alias: string): string;
10
+ export declare function lookupEntry(term: string): GlossaryEntry | undefined;
11
+ export interface GlossaryDrift {
12
+ alias: string;
13
+ canonical: string;
14
+ line?: number;
15
+ }
16
+ export declare function validateText(text: string): GlossaryDrift[];
17
+ export declare function auditSchemaFields(obj: Record<string, unknown>): GlossaryDrift[];
18
+ export declare const CONCEPT_GLOSSARY_VERSION = 1;
@@ -0,0 +1,209 @@
1
+ export const CONCEPT_GLOSSARY = [
2
+ {
3
+ term: "Permission",
4
+ definition: "Organization-wide permission object. indices 0-999 builtin, 1000-65535 custom. " +
5
+ "Shared across all Progress instances of a Service. Use for internal staff roles.",
6
+ aliases: ["permission object", "权限对象"],
7
+ category: "permission",
8
+ },
9
+ {
10
+ term: "NamedOperator",
11
+ definition: "Per-order role assignment inside a Progress. Each Progress node can map a role " +
12
+ "string to an address. Use for external collaborators whose identity varies per order.",
13
+ aliases: ["named operator", "namedoperator"],
14
+ category: "permission",
15
+ },
16
+ {
17
+ term: "OrderHolder",
18
+ definition: "The order holder and their agents. Represented by namedOperator=\"\" (empty string) " +
19
+ "on a Forward. Lets the customer operate their own order.",
20
+ aliases: ["order owner", "orderholder", "订单持有人"],
21
+ category: "permission",
22
+ },
23
+ {
24
+ term: "Forward",
25
+ definition: "A state-transition edge in a Machine. Carries weight, a permission " +
26
+ "(Permission index / NamedOperator / OrderHolder), and an optional Guard. " +
27
+ "Every Forward MUST define at least one permission.",
28
+ aliases: ["迁移", "transition"],
29
+ category: "operation",
30
+ },
31
+ {
32
+ term: "Pair",
33
+ definition: "A prev_node → next_node transition group in a Machine with a threshold. " +
34
+ "When the cumulative weight of executed Forwards meets the threshold, the Pair fires.",
35
+ aliases: ["迁移对", "transition pair"],
36
+ category: "operation",
37
+ },
38
+ {
39
+ term: "Machine",
40
+ definition: "Workflow blueprint (directed graph). Becomes immutable after publish. " +
41
+ "A Progress instance is created per order from the Machine.",
42
+ aliases: ["工作流模板", "machine template"],
43
+ category: "object",
44
+ },
45
+ {
46
+ term: "Progress",
47
+ definition: "A workflow instance bound to one order. Advances via Forwards; " +
48
+ "carries retained_submission values for Guard verification.",
49
+ aliases: ["流程实例", "progress instance"],
50
+ category: "object",
51
+ },
52
+ {
53
+ term: "Guard",
54
+ definition: "Immutable static validation rule. Verifies submissions and on-chain object data. " +
55
+ "Returns boolean. Cannot be mutated after creation.",
56
+ aliases: ["守卫", "guard object"],
57
+ category: "acceptance",
58
+ },
59
+ {
60
+ term: "Repository",
61
+ definition: "Mutable dynamic acceptance store. Keyed by (name, entity). " +
62
+ "Used for data that can change over time (e.g. SLA config, review records).",
63
+ aliases: ["仓库", "repository object"],
64
+ category: "acceptance",
65
+ },
66
+ {
67
+ term: "Acceptance",
68
+ definition: "The verification standard for a process step. Composed of static Guard + " +
69
+ "dynamic Repository. Drives whether a Forward can execute.",
70
+ aliases: ["验收标准", "acceptance standard"],
71
+ category: "acceptance",
72
+ },
73
+ {
74
+ term: "Service",
75
+ definition: "A merchant's service listing. References Machine, order_allocators, arbitrations, " +
76
+ "compensation_fund, rewards, buy_guard. machine & order_allocators lock after publish.",
77
+ aliases: ["服务", "service object"],
78
+ category: "object",
79
+ },
80
+ {
81
+ term: "Order",
82
+ definition: "An order against a Service. Funds are escrowed; released via Progress + Allocation. " +
83
+ "Arb cases attach to orders for dispute resolution.",
84
+ aliases: ["订单"],
85
+ category: "object",
86
+ },
87
+ {
88
+ term: "Allocator",
89
+ definition: "Fund distribution rules. Priority: Amount → Rate → Surplus. first-Guard-wins. " +
90
+ "Locked on Service publish (order_allocators).",
91
+ aliases: ["分账器", "allocation"],
92
+ category: "fund",
93
+ },
94
+ {
95
+ term: "Allocation",
96
+ definition: "The act of distributing escrowed funds to recipients per an Allocator. " +
97
+ "Executed by the order holder or Permission holder.",
98
+ aliases: ["分账"],
99
+ category: "fund",
100
+ },
101
+ {
102
+ term: "Arbitration",
103
+ definition: "Independent arbitration service object. Configured with voting_guard, usage_guard, " +
104
+ "fee. Generates Arb cases per dispute. Third-party preferred over self-built.",
105
+ aliases: ["仲裁服务", "arb service"],
106
+ category: "object",
107
+ },
108
+ {
109
+ term: "Arb",
110
+ definition: "A single dispute case instance of an Arbitration. Has a state machine " +
111
+ "(dispute → confirm → vote → verdict → settle).",
112
+ aliases: ["仲裁案", "arb case"],
113
+ category: "object",
114
+ },
115
+ {
116
+ term: "compensation_fund",
117
+ definition: "A fund attached to a Service. Arbitration indemnity is drawn from it. " +
118
+ "Adequacy is a key trust signal for customers.",
119
+ aliases: ["赔偿基金", "赔偿金"],
120
+ category: "fund",
121
+ },
122
+ {
123
+ term: "buy_guard",
124
+ definition: "A Guard attached to a Service that gates purchasing. Validates customer eligibility.",
125
+ aliases: ["购买守卫"],
126
+ category: "acceptance",
127
+ },
128
+ {
129
+ term: "Sub-Order",
130
+ definition: "A child order in a cross-Machine supply chain. Introduced at a node with transparent " +
131
+ "suppliers; verified by Guard to originate from one of the declared suppliers.",
132
+ aliases: ["采购子订单", "suborder", "sub order"],
133
+ category: "object",
134
+ },
135
+ {
136
+ term: "Reward",
137
+ definition: "Incentive pool. claim is Guard-gated. guard_add supports Fixed or GuardU64Identifier " +
138
+ "(dynamic). Used for marketing (first-order, cumulative, referral).",
139
+ aliases: ["奖励", "reward pool"],
140
+ category: "fund",
141
+ },
142
+ {
143
+ term: "Demand",
144
+ definition: "A user's posted service request with optional reward. presenters submit proposals; " +
145
+ "Guard filters them. Matches Services for personalized acquisition.",
146
+ aliases: ["需求"],
147
+ category: "object",
148
+ },
149
+ {
150
+ term: "Personal",
151
+ definition: "Permanently public on-chain identity profile. Social links, reputation (likes/dislikes), " +
152
+ "personal info records. CRITICAL: everything here is PUBLIC forever.",
153
+ aliases: ["公开身份", "personal profile"],
154
+ category: "object",
155
+ },
156
+ {
157
+ term: "Contact",
158
+ definition: "Bridges a Service's um (contact) and the Messenger ims (messaging). Enables " +
159
+ "off-chain encrypted communication for pre-order negotiation & evidence.",
160
+ aliases: ["联系"],
161
+ category: "object",
162
+ },
163
+ ];
164
+ const ALIAS_INDEX = (() => {
165
+ const m = new Map();
166
+ for (const e of CONCEPT_GLOSSARY) {
167
+ m.set(e.term.toLowerCase(), e.term);
168
+ for (const a of e.aliases)
169
+ m.set(a.toLowerCase(), e.term);
170
+ }
171
+ return m;
172
+ })();
173
+ export function resolveTerm(alias) {
174
+ if (!alias)
175
+ return alias;
176
+ return ALIAS_INDEX.get(alias.toLowerCase()) ?? alias;
177
+ }
178
+ export function lookupEntry(term) {
179
+ const t = term.toLowerCase();
180
+ return CONCEPT_GLOSSARY.find((e) => e.term.toLowerCase() === t || e.aliases.some((a) => a.toLowerCase() === t));
181
+ }
182
+ export function validateText(text) {
183
+ const findings = [];
184
+ if (!text)
185
+ return findings;
186
+ const lower = text.toLowerCase();
187
+ for (const entry of CONCEPT_GLOSSARY) {
188
+ for (const alias of entry.aliases) {
189
+ const a = alias.toLowerCase();
190
+ if (entry.term.toLowerCase() === a)
191
+ continue;
192
+ if (lower.includes(a)) {
193
+ findings.push({ alias, canonical: entry.term });
194
+ }
195
+ }
196
+ }
197
+ return findings;
198
+ }
199
+ export function auditSchemaFields(obj) {
200
+ const findings = [];
201
+ for (const key of Object.keys(obj)) {
202
+ const canonical = ALIAS_INDEX.get(key.toLowerCase());
203
+ if (canonical && canonical !== key) {
204
+ findings.push({ alias: key, canonical });
205
+ }
206
+ }
207
+ return findings;
208
+ }
209
+ export const CONCEPT_GLOSSARY_VERSION = 1;
@@ -0,0 +1,19 @@
1
+ export interface GuardScene {
2
+ id: string;
3
+ name: string;
4
+ host_object: "Service" | "Machine" | "Arbitration" | "Reward" | "Repository" | "Progress" | "Demand" | "Standalone";
5
+ binding_field: string;
6
+ validation_scene: string;
7
+ pass_result: string;
8
+ fail_result: string;
9
+ submission_source: string;
10
+ special_constraints: string[];
11
+ common_patterns: string[];
12
+ mutable_after_publish: boolean;
13
+ r_rounds_focus: string[];
14
+ }
15
+ export declare const GUARD_SCENES: GuardScene[];
16
+ export declare function findScene(host_object: string, binding_field: string): GuardScene | undefined;
17
+ export declare function inferSceneFromAction(action: "buy" | "forward" | "allocate" | "claim_reward" | "vote" | "dispute" | "write_repository" | "submit_progress"): GuardScene | undefined;
18
+ export declare function getImmutableScenes(): GuardScene[];
19
+ export declare function getNumericIdentifierScenes(): GuardScene[];