@wowok/agent-mcp 2.3.13 → 2.3.16

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 (194) 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/industry-risks.d.ts +36 -0
  6. package/dist/customer/industry-risks.js +424 -0
  7. package/dist/customer/info-puzzle.d.ts +102 -0
  8. package/dist/customer/info-puzzle.js +312 -0
  9. package/dist/customer/order-monitor.d.ts +75 -0
  10. package/dist/customer/order-monitor.js +327 -0
  11. package/dist/customer/order-strategy.d.ts +36 -0
  12. package/dist/customer/order-strategy.js +373 -0
  13. package/dist/customer/post-purchase.d.ts +42 -0
  14. package/dist/customer/post-purchase.js +350 -0
  15. package/dist/customer/reminder-system.d.ts +42 -0
  16. package/dist/customer/reminder-system.js +295 -0
  17. package/dist/customer/risk-assessment.d.ts +8 -0
  18. package/dist/customer/risk-assessment.js +337 -0
  19. package/dist/customer/types.d.ts +193 -0
  20. package/dist/customer/types.js +13 -0
  21. package/dist/customer/user-preferences.d.ts +67 -0
  22. package/dist/customer/user-preferences.js +451 -0
  23. package/dist/experience/experience-reuse.d.ts +10 -0
  24. package/dist/experience/experience-reuse.js +103 -0
  25. package/dist/experience/index.d.ts +6 -0
  26. package/dist/experience/index.js +5 -0
  27. package/dist/experience/intent-distill.d.ts +3 -0
  28. package/dist/experience/intent-distill.js +83 -0
  29. package/dist/experience/realtime-feedback.d.ts +5 -0
  30. package/dist/experience/realtime-feedback.js +77 -0
  31. package/dist/experience/types.d.ts +50 -0
  32. package/dist/experience/types.js +1 -0
  33. package/dist/experience/user-profile.d.ts +25 -0
  34. package/dist/experience/user-profile.js +171 -0
  35. package/dist/harness/checkpoint.d.ts +8 -0
  36. package/dist/harness/checkpoint.js +129 -0
  37. package/dist/harness/index.d.ts +33 -0
  38. package/dist/harness/index.js +75 -0
  39. package/dist/harness/plan.d.ts +18 -0
  40. package/dist/harness/plan.js +252 -0
  41. package/dist/harness/recover.d.ts +17 -0
  42. package/dist/harness/recover.js +139 -0
  43. package/dist/harness/types.d.ts +137 -0
  44. package/dist/harness/types.js +1 -0
  45. package/dist/harness/verify.d.ts +42 -0
  46. package/dist/harness/verify.js +237 -0
  47. package/dist/index.js +667 -201
  48. package/dist/knowledge/acquisition-flywheel.d.ts +50 -0
  49. package/dist/knowledge/acquisition-flywheel.js +183 -0
  50. package/dist/knowledge/arbitration-trust.d.ts +24 -0
  51. package/dist/knowledge/arbitration-trust.js +117 -0
  52. package/dist/knowledge/audit-rules.d.ts +28 -0
  53. package/dist/knowledge/audit-rules.js +141 -0
  54. package/dist/knowledge/demand-matching.d.ts +29 -0
  55. package/dist/knowledge/demand-matching.js +132 -0
  56. package/dist/knowledge/dynamic-pricing.d.ts +31 -0
  57. package/dist/knowledge/dynamic-pricing.js +87 -0
  58. package/dist/knowledge/flywheel-loop.d.ts +87 -0
  59. package/dist/knowledge/flywheel-loop.js +378 -0
  60. package/dist/knowledge/glossary.d.ts +18 -0
  61. package/dist/knowledge/glossary.js +209 -0
  62. package/dist/knowledge/index.d.ts +64 -0
  63. package/dist/knowledge/index.js +66 -0
  64. package/dist/knowledge/industry-evolution.d.ts +82 -0
  65. package/dist/knowledge/industry-evolution.js +323 -0
  66. package/dist/knowledge/industry-generalizer.d.ts +17 -0
  67. package/dist/knowledge/industry-generalizer.js +381 -0
  68. package/dist/knowledge/industry-registry.d.ts +49 -0
  69. package/dist/knowledge/industry-registry.js +167 -0
  70. package/dist/knowledge/intent-metrics.d.ts +42 -0
  71. package/dist/knowledge/intent-metrics.js +566 -0
  72. package/dist/knowledge/process-model.d.ts +24 -0
  73. package/dist/knowledge/process-model.js +160 -0
  74. package/dist/knowledge/reputation-rules.d.ts +42 -0
  75. package/dist/knowledge/reputation-rules.js +99 -0
  76. package/dist/knowledge/reward-templates.d.ts +25 -0
  77. package/dist/knowledge/reward-templates.js +125 -0
  78. package/dist/knowledge/safety-rules.d.ts +36 -0
  79. package/dist/knowledge/safety-rules.js +171 -0
  80. package/dist/knowledge/tool-constraints.d.ts +30 -0
  81. package/dist/knowledge/tool-constraints.js +185 -0
  82. package/dist/knowledge/trust-metrics.d.ts +37 -0
  83. package/dist/knowledge/trust-metrics.js +138 -0
  84. package/dist/loop-engineering/aggregate.d.ts +50 -0
  85. package/dist/loop-engineering/aggregate.js +132 -0
  86. package/dist/loop-engineering/diagnose.d.ts +22 -0
  87. package/dist/loop-engineering/diagnose.js +273 -0
  88. package/dist/loop-engineering/improve.d.ts +26 -0
  89. package/dist/loop-engineering/improve.js +229 -0
  90. package/dist/loop-engineering/index.d.ts +4 -0
  91. package/dist/loop-engineering/index.js +4 -0
  92. package/dist/loop-engineering/pipeline.d.ts +17 -0
  93. package/dist/loop-engineering/pipeline.js +56 -0
  94. package/dist/mode-market/index.d.ts +3 -0
  95. package/dist/mode-market/index.js +3 -0
  96. package/dist/mode-market/registry.d.ts +53 -0
  97. package/dist/mode-market/registry.js +124 -0
  98. package/dist/mode-market/review.d.ts +27 -0
  99. package/dist/mode-market/review.js +214 -0
  100. package/dist/mode-market/submission.d.ts +25 -0
  101. package/dist/mode-market/submission.js +85 -0
  102. package/dist/project/graph.d.ts +71 -0
  103. package/dist/project/graph.js +314 -0
  104. package/dist/project/index.d.ts +62 -0
  105. package/dist/project/index.js +167 -0
  106. package/dist/project/namespace.d.ts +62 -0
  107. package/dist/project/namespace.js +181 -0
  108. package/dist/project/query.d.ts +40 -0
  109. package/dist/project/query.js +110 -0
  110. package/dist/safety/confirm-gate.d.ts +15 -0
  111. package/dist/safety/confirm-gate.js +44 -0
  112. package/dist/safety/index.d.ts +3 -0
  113. package/dist/safety/index.js +3 -0
  114. package/dist/safety/preview.d.ts +2 -0
  115. package/dist/safety/preview.js +36 -0
  116. package/dist/schema/call/allocation.d.ts +55 -40
  117. package/dist/schema/call/arbitration.d.ts +201 -186
  118. package/dist/schema/call/base.d.ts +2104 -24
  119. package/dist/schema/call/base.js +168 -22
  120. package/dist/schema/call/bridge-handler.js +36 -18
  121. package/dist/schema/call/bridge.d.ts +777 -120
  122. package/dist/schema/call/bridge.js +13 -2
  123. package/dist/schema/call/contact.d.ts +15 -0
  124. package/dist/schema/call/demand.d.ts +69 -54
  125. package/dist/schema/call/guard.d.ts +125 -80
  126. package/dist/schema/call/handler.d.ts +5 -1
  127. package/dist/schema/call/handler.js +108 -3
  128. package/dist/schema/call/index.d.ts +1 -0
  129. package/dist/schema/call/index.js +1 -0
  130. package/dist/schema/call/machine.d.ts +830 -800
  131. package/dist/schema/call/order.d.ts +27 -12
  132. package/dist/schema/call/payment.d.ts +15 -0
  133. package/dist/schema/call/permission.d.ts +15 -0
  134. package/dist/schema/call/personal.d.ts +15 -0
  135. package/dist/schema/call/progress.d.ts +21 -6
  136. package/dist/schema/call/proof.d.ts +42 -12
  137. package/dist/schema/call/proof.js +3 -3
  138. package/dist/schema/call/repository.d.ts +91 -76
  139. package/dist/schema/call/reward.d.ts +51 -36
  140. package/dist/schema/call/semantic.d.ts +24 -0
  141. package/dist/schema/call/semantic.js +981 -0
  142. package/dist/schema/call/service.d.ts +444 -429
  143. package/dist/schema/call/treasury.d.ts +219 -204
  144. package/dist/schema/common/index.js +3 -3
  145. package/dist/schema/local/index.d.ts +341 -74
  146. package/dist/schema/local/index.js +44 -7
  147. package/dist/schema/messenger/index.d.ts +1034 -92
  148. package/dist/schema/messenger/index.js +18 -0
  149. package/dist/schema/operations.d.ts +2634 -1817
  150. package/dist/schema/operations.js +16 -5
  151. package/dist/schema/query/index.d.ts +2293 -2289
  152. package/dist/schema/query/index.js +34 -28
  153. package/dist/schemas/account_operation.output.json +28 -16
  154. package/dist/schemas/account_operation.schema.json +2 -2
  155. package/dist/schemas/bridge_operation.output.json +520 -0
  156. package/dist/schemas/bridge_operation.schema.json +15 -0
  157. package/dist/schemas/guard2file.schema.json +15 -0
  158. package/dist/schemas/index.json +1 -1
  159. package/dist/schemas/local_info_operation.output.json +26 -0
  160. package/dist/schemas/local_info_operation.schema.json +1 -1
  161. package/dist/schemas/local_mark_operation.output.json +27 -1
  162. package/dist/schemas/local_mark_operation.schema.json +4 -4
  163. package/dist/schemas/machineNode2file.schema.json +15 -0
  164. package/dist/schemas/messenger_operation.output.json +549 -0
  165. package/dist/schemas/messenger_operation.schema.json +21 -0
  166. package/dist/schemas/onchain_events.output.json +3 -0
  167. package/dist/schemas/onchain_operations.output.json +814 -37
  168. package/dist/schemas/onchain_operations.schema.json +117 -40
  169. package/dist/schemas/onchain_operations_allocation.schema.json +26 -9
  170. package/dist/schemas/onchain_operations_arbitration.schema.json +26 -9
  171. package/dist/schemas/onchain_operations_contact.schema.json +26 -9
  172. package/dist/schemas/onchain_operations_demand.schema.json +26 -9
  173. package/dist/schemas/onchain_operations_gen_passport.schema.json +51 -17
  174. package/dist/schemas/onchain_operations_guard.schema.json +26 -9
  175. package/dist/schemas/onchain_operations_machine.schema.json +92 -32
  176. package/dist/schemas/onchain_operations_order.schema.json +26 -9
  177. package/dist/schemas/onchain_operations_payment.schema.json +26 -9
  178. package/dist/schemas/onchain_operations_permission.schema.json +26 -9
  179. package/dist/schemas/onchain_operations_personal.schema.json +26 -9
  180. package/dist/schemas/onchain_operations_progress.schema.json +26 -9
  181. package/dist/schemas/onchain_operations_repository.schema.json +26 -9
  182. package/dist/schemas/onchain_operations_reward.schema.json +26 -9
  183. package/dist/schemas/onchain_operations_service.schema.json +26 -9
  184. package/dist/schemas/onchain_operations_treasury.schema.json +26 -9
  185. package/dist/schemas/onchain_table_data.output.json +224 -69
  186. package/dist/schemas/onchain_table_data.schema.json +2 -2
  187. package/dist/schemas/query_toolkit.schema.json +5 -1
  188. package/dist/telemetry/index.d.ts +19 -0
  189. package/dist/telemetry/index.js +112 -0
  190. package/dist/telemetry/redact.d.ts +2 -0
  191. package/dist/telemetry/redact.js +23 -0
  192. package/dist/telemetry/storage.d.ts +8 -0
  193. package/dist/telemetry/storage.js +80 -0
  194. package/package.json +6 -3
@@ -0,0 +1,77 @@
1
+ import { distillIntent, extractSignals } from "./intent-distill.js";
2
+ import { getProfile, updateFromOperation } from "./user-profile.js";
3
+ import { findMatches, recordSignature } from "./experience-reuse.js";
4
+ import { EXPERIENCE_LAYER_VERSION } from "./types.js";
5
+ export { EXPERIENCE_LAYER_VERSION };
6
+ export function getExperienceFeedback(operation_type, data, baseIntent) {
7
+ try {
8
+ const distilled = distillIntent(operation_type, data, baseIntent);
9
+ const matches = findMatches(distilled.primary_intent, operation_type, data, 3);
10
+ if (matches.length === 0)
11
+ return undefined;
12
+ const topMatch = matches[0];
13
+ const profile = getProfile();
14
+ return formatFeedback(topMatch, matches, distilled.scenario, profile);
15
+ }
16
+ catch {
17
+ return undefined;
18
+ }
19
+ }
20
+ export function recordOperationOutcome(operation_type, data, baseIntent, outcome, errorCode, referencedObjects = []) {
21
+ try {
22
+ const distilled = distillIntent(operation_type, data, baseIntent);
23
+ const signals = extractSignals(operation_type, data);
24
+ recordSignature({
25
+ intent: distilled.primary_intent,
26
+ scenario: distilled.scenario,
27
+ signals,
28
+ timestamp: Date.now(),
29
+ outcome,
30
+ error_code: errorCode,
31
+ });
32
+ updateFromOperation(distilled.primary_intent, distilled.scenario, outcome, errorCode, referencedObjects);
33
+ }
34
+ catch {
35
+ }
36
+ }
37
+ function formatFeedback(topMatch, allMatches, scenario, profile) {
38
+ const advice = buildAdviceText(topMatch, allMatches, profile);
39
+ const avoid = collectAvoidList(allMatches, profile);
40
+ const relevance = topMatch.relevance;
41
+ const matchedScenario = scenario ?? topMatch.signature.scenario;
42
+ const feedback = {};
43
+ if (advice)
44
+ feedback.advice = advice;
45
+ if (avoid.length > 0)
46
+ feedback.avoid = avoid;
47
+ if (relevance > 0)
48
+ feedback.relevance = Math.round(relevance * 100) / 100;
49
+ if (matchedScenario)
50
+ feedback.matched_scenario = matchedScenario;
51
+ return feedback;
52
+ }
53
+ function buildAdviceText(topMatch, allMatches, profile) {
54
+ const parts = [];
55
+ if (topMatch.signature.outcome === "success") {
56
+ parts.push(`Historically, ${topMatch.signature.intent} operation succeeded`);
57
+ }
58
+ else if (topMatch.signature.outcome === "failed") {
59
+ parts.push(`Historically, ${topMatch.signature.intent} operation failed (${topMatch.signature.error_code ?? "unknown error"}), pay special attention to parameters`);
60
+ }
61
+ if (profile.expertise_tier === "novice" && allMatches.length > 0) {
62
+ parts.push("It is recommended to carefully check parameters before executing");
63
+ }
64
+ return parts.join("; ") || topMatch.advice;
65
+ }
66
+ function collectAvoidList(matches, profile) {
67
+ const avoid = new Set();
68
+ for (const m of matches) {
69
+ for (const a of m.avoid) {
70
+ avoid.add(a);
71
+ }
72
+ }
73
+ for (const p of profile.frequent_pitfalls) {
74
+ avoid.add(`You often make mistakes at the ${p} step, please be especially careful`);
75
+ }
76
+ return Array.from(avoid).slice(0, 5);
77
+ }
@@ -0,0 +1,50 @@
1
+ export interface UserIntentSignature {
2
+ intent: string;
3
+ scenario?: string;
4
+ signals: Record<string, any>;
5
+ timestamp: number;
6
+ outcome: "success" | "failed" | "partial";
7
+ error_code?: string;
8
+ recovery_path?: string[];
9
+ }
10
+ export interface UserProfile {
11
+ expertise_tier: "novice" | "advanced" | "expert";
12
+ preferred_industries: string[];
13
+ risk_appetite: "conservative" | "balanced" | "aggressive";
14
+ frequent_pitfalls: string[];
15
+ reused_objects: string[];
16
+ preferred_confirmation: "minimal" | "standard" | "verbose";
17
+ total_operations: number;
18
+ success_rate: number;
19
+ last_updated: number;
20
+ buyer_signals?: BuyerSignals;
21
+ }
22
+ export interface BuyerSignals {
23
+ purchase_count: number;
24
+ avg_purchase_price_ratio: number;
25
+ discount_usage_count: number;
26
+ referral_usage_count: number;
27
+ dispute_count: number;
28
+ inferred_price_sensitivity?: "low" | "medium" | "high";
29
+ inferred_bargain_hunting?: number;
30
+ }
31
+ export interface DistilledIntent {
32
+ primary_intent: string;
33
+ secondary_intents: string[];
34
+ confidence: number;
35
+ urgency: "low" | "normal" | "high" | "critical";
36
+ scenario?: string;
37
+ }
38
+ export interface ExperienceMatch {
39
+ signature: UserIntentSignature;
40
+ relevance: number;
41
+ advice: string;
42
+ avoid: string[];
43
+ }
44
+ export interface ExperienceFeedback {
45
+ advice?: string;
46
+ avoid?: string[];
47
+ relevance?: number;
48
+ matched_scenario?: string;
49
+ }
50
+ export declare const EXPERIENCE_LAYER_VERSION = 1;
@@ -0,0 +1 @@
1
+ export const EXPERIENCE_LAYER_VERSION = 1;
@@ -0,0 +1,25 @@
1
+ import type { UserProfile, BuyerSignals } from "./types.js";
2
+ export declare function getProfile(): UserProfile;
3
+ export interface PurchaseOutcomeInput {
4
+ price: bigint;
5
+ avg_market_price?: bigint;
6
+ used_discount?: boolean;
7
+ used_referral?: boolean;
8
+ has_dispute?: boolean;
9
+ }
10
+ export declare function recordPurchaseOutcome(input: PurchaseOutcomeInput): void;
11
+ export declare function getBuyerSignals(): BuyerSignals;
12
+ export declare function updateFromOperation(intent: string, scenario: string | undefined, outcome: "success" | "failed" | "partial", errorCode: string | undefined, referencedObjects: string[]): void;
13
+ export declare function resetProfile(): void;
14
+ export declare function getProfileStats(): {
15
+ total_operations: number;
16
+ success_rate: number;
17
+ top_scenarios: Array<{
18
+ scenario: string;
19
+ count: number;
20
+ }>;
21
+ top_pitfalls: Array<{
22
+ error_code: string;
23
+ count: number;
24
+ }>;
25
+ };
@@ -0,0 +1,171 @@
1
+ let currentProfile = {
2
+ expertise_tier: "novice",
3
+ preferred_industries: [],
4
+ risk_appetite: "balanced",
5
+ frequent_pitfalls: [],
6
+ reused_objects: [],
7
+ preferred_confirmation: "standard",
8
+ total_operations: 0,
9
+ success_rate: 1.0,
10
+ last_updated: 0,
11
+ };
12
+ let buyerSignals = {
13
+ purchase_count: 0,
14
+ avg_purchase_price_ratio: 1.0,
15
+ discount_usage_count: 0,
16
+ referral_usage_count: 0,
17
+ dispute_count: 0,
18
+ };
19
+ let scenarioCounts = new Map();
20
+ let pitfallCounts = new Map();
21
+ let objectRefs = new Map();
22
+ let successCount = 0;
23
+ let totalCount = 0;
24
+ export function getProfile() {
25
+ return { ...currentProfile, buyer_signals: { ...buyerSignals } };
26
+ }
27
+ export function recordPurchaseOutcome(input) {
28
+ try {
29
+ buyerSignals.purchase_count++;
30
+ if (input.used_discount)
31
+ buyerSignals.discount_usage_count++;
32
+ if (input.used_referral)
33
+ buyerSignals.referral_usage_count++;
34
+ if (input.has_dispute)
35
+ buyerSignals.dispute_count++;
36
+ if (input.avg_market_price && input.avg_market_price > 0n) {
37
+ const ratio = Number((input.price * 100n) / input.avg_market_price) / 100;
38
+ const prevAvg = buyerSignals.avg_purchase_price_ratio;
39
+ const n = buyerSignals.purchase_count;
40
+ buyerSignals.avg_purchase_price_ratio = (prevAvg * (n - 1) + ratio) / n;
41
+ }
42
+ recomputeBuyerInferences();
43
+ }
44
+ catch {
45
+ }
46
+ }
47
+ function recomputeBuyerInferences() {
48
+ const n = buyerSignals.purchase_count;
49
+ if (n >= 3) {
50
+ const avgRatio = buyerSignals.avg_purchase_price_ratio;
51
+ if (avgRatio < 0.9) {
52
+ buyerSignals.inferred_price_sensitivity = "high";
53
+ }
54
+ else if (avgRatio > 1.1) {
55
+ buyerSignals.inferred_price_sensitivity = "low";
56
+ }
57
+ else {
58
+ buyerSignals.inferred_price_sensitivity = "medium";
59
+ }
60
+ }
61
+ if (n >= 2) {
62
+ const signalCount = buyerSignals.discount_usage_count + buyerSignals.referral_usage_count;
63
+ const ratio = signalCount / n;
64
+ buyerSignals.inferred_bargain_hunting = Math.min(1, ratio);
65
+ }
66
+ }
67
+ export function getBuyerSignals() {
68
+ return { ...buyerSignals };
69
+ }
70
+ export function updateFromOperation(intent, scenario, outcome, errorCode, referencedObjects) {
71
+ try {
72
+ totalCount++;
73
+ if (outcome === "success")
74
+ successCount++;
75
+ if (scenario) {
76
+ scenarioCounts.set(scenario, (scenarioCounts.get(scenario) ?? 0) + 1);
77
+ }
78
+ if (outcome !== "success" && errorCode) {
79
+ pitfallCounts.set(errorCode, (pitfallCounts.get(errorCode) ?? 0) + 1);
80
+ }
81
+ for (const obj of referencedObjects) {
82
+ objectRefs.set(obj, (objectRefs.get(obj) ?? 0) + 1);
83
+ }
84
+ currentProfile = recomputeProfile();
85
+ }
86
+ catch {
87
+ }
88
+ }
89
+ function recomputeProfile() {
90
+ const total = totalCount;
91
+ const successRate = total > 0 ? successCount / total : 1.0;
92
+ let tier = "novice";
93
+ if (total >= 50 && successRate >= 0.9)
94
+ tier = "expert";
95
+ else if (total >= 10 && successRate >= 0.7)
96
+ tier = "advanced";
97
+ const topScenarios = Array.from(scenarioCounts.entries())
98
+ .sort((a, b) => b[1] - a[1])
99
+ .slice(0, 3)
100
+ .map(([s]) => s);
101
+ let riskAppetite = "balanced";
102
+ if (total > 20 && successRate < 0.6)
103
+ riskAppetite = "aggressive";
104
+ else if (total > 20 && successRate > 0.95)
105
+ riskAppetite = "conservative";
106
+ const topPitfalls = Array.from(pitfallCounts.entries())
107
+ .filter(([, count]) => count >= 2)
108
+ .sort((a, b) => b[1] - a[1])
109
+ .slice(0, 3)
110
+ .map(([code]) => code);
111
+ const topObjects = Array.from(objectRefs.entries())
112
+ .filter(([, count]) => count >= 2)
113
+ .sort((a, b) => b[1] - a[1])
114
+ .slice(0, 5)
115
+ .map(([obj]) => obj);
116
+ let preferredConfirmation = "standard";
117
+ if (tier === "expert")
118
+ preferredConfirmation = "minimal";
119
+ else if (tier === "novice")
120
+ preferredConfirmation = "verbose";
121
+ return {
122
+ expertise_tier: tier,
123
+ preferred_industries: topScenarios,
124
+ risk_appetite: riskAppetite,
125
+ frequent_pitfalls: topPitfalls,
126
+ reused_objects: topObjects,
127
+ preferred_confirmation: preferredConfirmation,
128
+ total_operations: total,
129
+ success_rate: successRate,
130
+ last_updated: Date.now(),
131
+ };
132
+ }
133
+ export function resetProfile() {
134
+ currentProfile = {
135
+ expertise_tier: "novice",
136
+ preferred_industries: [],
137
+ risk_appetite: "balanced",
138
+ frequent_pitfalls: [],
139
+ reused_objects: [],
140
+ preferred_confirmation: "verbose",
141
+ total_operations: 0,
142
+ success_rate: 1.0,
143
+ last_updated: 0,
144
+ };
145
+ scenarioCounts = new Map();
146
+ pitfallCounts = new Map();
147
+ objectRefs = new Map();
148
+ successCount = 0;
149
+ totalCount = 0;
150
+ buyerSignals = {
151
+ purchase_count: 0,
152
+ avg_purchase_price_ratio: 1.0,
153
+ discount_usage_count: 0,
154
+ referral_usage_count: 0,
155
+ dispute_count: 0,
156
+ };
157
+ }
158
+ export function getProfileStats() {
159
+ return {
160
+ total_operations: totalCount,
161
+ success_rate: totalCount > 0 ? successCount / totalCount : 1.0,
162
+ top_scenarios: Array.from(scenarioCounts.entries())
163
+ .sort((a, b) => b[1] - a[1])
164
+ .slice(0, 5)
165
+ .map(([scenario, count]) => ({ scenario, count })),
166
+ top_pitfalls: Array.from(pitfallCounts.entries())
167
+ .sort((a, b) => b[1] - a[1])
168
+ .slice(0, 5)
169
+ .map(([error_code, count]) => ({ error_code, count })),
170
+ };
171
+ }
@@ -0,0 +1,8 @@
1
+ import type { Checkpoint } from "./types.js";
2
+ export declare function saveCheckpoint(cp: Checkpoint): void;
3
+ export declare function loadCheckpoint(taskId: string, checkpointId: string): Checkpoint | null;
4
+ export declare function loadLatestCheckpoint(taskId: string): Checkpoint | null;
5
+ export declare function listCheckpoints(taskId: string): Checkpoint[];
6
+ export declare function listTasks(): string[];
7
+ export declare function deleteCheckpoint(taskId: string, checkpointId: string): void;
8
+ export declare function createCheckpoint(taskId: string, phase: string, phaseStatus: Checkpoint["phase_status"], odgSnapshot: Checkpoint["odg_snapshot"], userDecisions: Record<string, unknown>, operationLog: Checkpoint["operation_log"], nextPhase: string, semanticSummary: Checkpoint["semantic_summary"]): Checkpoint;
@@ -0,0 +1,129 @@
1
+ import { existsSync, mkdirSync, writeFileSync, readFileSync, readdirSync, unlinkSync, openSync, closeSync } from "fs";
2
+ import { join } from "path";
3
+ import { homedir } from "os";
4
+ const CHECKPOINT_ROOT = join(homedir(), ".wowok", "checkpoints");
5
+ function getTaskDir(taskId) {
6
+ return join(CHECKPOINT_ROOT, taskId);
7
+ }
8
+ function getCheckpointPath(taskId, checkpointId) {
9
+ return join(getTaskDir(taskId), `${checkpointId}.json`);
10
+ }
11
+ function getLatestPath(taskId) {
12
+ return join(getTaskDir(taskId), "latest.json");
13
+ }
14
+ function acquireLock(filePath) {
15
+ const lockPath = filePath + ".lock";
16
+ try {
17
+ const fd = openSync(lockPath, "wx");
18
+ closeSync(fd);
19
+ return true;
20
+ }
21
+ catch {
22
+ return false;
23
+ }
24
+ }
25
+ function releaseLock(filePath) {
26
+ const lockPath = filePath + ".lock";
27
+ try {
28
+ unlinkSync(lockPath);
29
+ }
30
+ catch {
31
+ }
32
+ }
33
+ export function saveCheckpoint(cp) {
34
+ const taskDir = getTaskDir(cp.task_id);
35
+ if (!existsSync(taskDir)) {
36
+ mkdirSync(taskDir, { recursive: true });
37
+ }
38
+ const cpPath = getCheckpointPath(cp.task_id, cp.checkpoint_id);
39
+ const latestPath = getLatestPath(cp.task_id);
40
+ if (!acquireLock(cpPath)) {
41
+ throw new Error(`Cannot acquire lock for checkpoint ${cp.checkpoint_id} — another process may be writing`);
42
+ }
43
+ try {
44
+ writeFileSync(cpPath, JSON.stringify(cp, null, 2), "utf8");
45
+ writeFileSync(latestPath, JSON.stringify(cp, null, 2), "utf8");
46
+ }
47
+ finally {
48
+ releaseLock(cpPath);
49
+ }
50
+ }
51
+ export function loadCheckpoint(taskId, checkpointId) {
52
+ const cpPath = getCheckpointPath(taskId, checkpointId);
53
+ if (!existsSync(cpPath))
54
+ return null;
55
+ try {
56
+ const raw = readFileSync(cpPath, "utf8");
57
+ return JSON.parse(raw);
58
+ }
59
+ catch {
60
+ return null;
61
+ }
62
+ }
63
+ export function loadLatestCheckpoint(taskId) {
64
+ const latestPath = getLatestPath(taskId);
65
+ if (!existsSync(latestPath))
66
+ return null;
67
+ try {
68
+ const raw = readFileSync(latestPath, "utf8");
69
+ return JSON.parse(raw);
70
+ }
71
+ catch {
72
+ return null;
73
+ }
74
+ }
75
+ export function listCheckpoints(taskId) {
76
+ const taskDir = getTaskDir(taskId);
77
+ if (!existsSync(taskDir))
78
+ return [];
79
+ const files = readdirSync(taskDir)
80
+ .filter((f) => f.endsWith(".json") && f !== "latest.json")
81
+ .sort();
82
+ return files
83
+ .map((f) => {
84
+ try {
85
+ const raw = readFileSync(join(taskDir, f), "utf8");
86
+ return JSON.parse(raw);
87
+ }
88
+ catch {
89
+ return null;
90
+ }
91
+ })
92
+ .filter((cp) => cp !== null);
93
+ }
94
+ export function listTasks() {
95
+ if (!existsSync(CHECKPOINT_ROOT))
96
+ return [];
97
+ return readdirSync(CHECKPOINT_ROOT, { withFileTypes: true })
98
+ .filter((d) => d.isDirectory())
99
+ .map((d) => d.name);
100
+ }
101
+ export function deleteCheckpoint(taskId, checkpointId) {
102
+ const cpPath = getCheckpointPath(taskId, checkpointId);
103
+ if (existsSync(cpPath)) {
104
+ if (!acquireLock(cpPath)) {
105
+ throw new Error(`Cannot acquire lock for deletion of ${checkpointId}`);
106
+ }
107
+ try {
108
+ unlinkSync(cpPath);
109
+ }
110
+ finally {
111
+ releaseLock(cpPath);
112
+ }
113
+ }
114
+ }
115
+ export function createCheckpoint(taskId, phase, phaseStatus, odgSnapshot, userDecisions, operationLog, nextPhase, semanticSummary) {
116
+ const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
117
+ return {
118
+ checkpoint_id: `CP-${phase.replace(/\s+/g, "")}-${phaseStatus}-${timestamp}`,
119
+ task_id: taskId,
120
+ timestamp: new Date().toISOString(),
121
+ phase,
122
+ phase_status: phaseStatus,
123
+ odg_snapshot: odgSnapshot,
124
+ user_decisions: userDecisions,
125
+ operation_log: operationLog,
126
+ next_phase: nextPhase,
127
+ semantic_summary: semanticSummary,
128
+ };
129
+ }
@@ -0,0 +1,33 @@
1
+ export * from "./types.js";
2
+ export * from "./plan.js";
3
+ export * from "./verify.js";
4
+ export * from "./recover.js";
5
+ export * from "./checkpoint.js";
6
+ import type { DecisionPoint } from "./plan.js";
7
+ import type { VerifyInput } from "./verify.js";
8
+ import type { ODG, ExpectedResult, VerifyReport, RecoveryAction, Checkpoint } from "./types.js";
9
+ export declare class Harness {
10
+ private context;
11
+ plan(userInput: string, taskId?: string): ODG;
12
+ classifyIntent(userInput: string): import("./plan.js").IntentClassification;
13
+ getDecisions(odg: ODG): DecisionPoint[];
14
+ detectCycles(odg: ODG): string[] | null;
15
+ getScenarioRegistry(): import("./types.js").ScenarioTemplate[];
16
+ expect(operation: string, intent: string, operationType: string, data?: Record<string, unknown>): ExpectedResult;
17
+ verify(input: VerifyInput): VerifyReport;
18
+ recover(errorCode: string, operationId: string, context?: {
19
+ operation_type?: string;
20
+ data?: Record<string, unknown>;
21
+ }): RecoveryAction;
22
+ resetRecovery(operationId: string): void;
23
+ getBackoffDelay(attempt: number): number;
24
+ getRecoveryRules(): Record<string, import("./recover.js").RecoveryRule>;
25
+ checkpoint(taskId: string, phase: string, phaseStatus: Checkpoint["phase_status"], odgSnapshot: Checkpoint["odg_snapshot"], userDecisions: Record<string, unknown>, operationLog: Checkpoint["operation_log"], nextPhase: string, semanticSummary: Checkpoint["semantic_summary"]): Checkpoint;
26
+ loadCheckpoint(taskId: string): Checkpoint | null;
27
+ listCheckpoints(taskId: string): Checkpoint[];
28
+ listTasks(): string[];
29
+ setContext(key: string, value: unknown): void;
30
+ getContext<T>(key: string): T | undefined;
31
+ }
32
+ export declare function getHarness(): Harness;
33
+ export declare function setHarness(h: Harness): void;
@@ -0,0 +1,75 @@
1
+ export * from "./types.js";
2
+ export * from "./plan.js";
3
+ export * from "./verify.js";
4
+ export * from "./recover.js";
5
+ export * from "./checkpoint.js";
6
+ import { classifyIntent, generateODG, identifyDecisionPoints, detectCycles, SCENARIO_REGISTRY } from "./plan.js";
7
+ import { verify, generateExpected } from "./verify.js";
8
+ import { recover, resetAttempts, getBackoffDelay, RECOVERY_RULES } from "./recover.js";
9
+ import { saveCheckpoint, loadLatestCheckpoint, listCheckpoints, listTasks, createCheckpoint } from "./checkpoint.js";
10
+ export class Harness {
11
+ context = new Map();
12
+ plan(userInput, taskId) {
13
+ return generateODG(userInput, taskId);
14
+ }
15
+ classifyIntent(userInput) {
16
+ return classifyIntent(userInput);
17
+ }
18
+ getDecisions(odg) {
19
+ return identifyDecisionPoints(odg);
20
+ }
21
+ detectCycles(odg) {
22
+ return detectCycles(odg);
23
+ }
24
+ getScenarioRegistry() {
25
+ return SCENARIO_REGISTRY;
26
+ }
27
+ expect(operation, intent, operationType, data) {
28
+ return generateExpected(operation, intent, operationType, data);
29
+ }
30
+ verify(input) {
31
+ return verify(input);
32
+ }
33
+ recover(errorCode, operationId, context) {
34
+ return recover(errorCode, operationId, context);
35
+ }
36
+ resetRecovery(operationId) {
37
+ resetAttempts(operationId);
38
+ }
39
+ getBackoffDelay(attempt) {
40
+ return getBackoffDelay(attempt);
41
+ }
42
+ getRecoveryRules() {
43
+ return RECOVERY_RULES;
44
+ }
45
+ checkpoint(taskId, phase, phaseStatus, odgSnapshot, userDecisions, operationLog, nextPhase, semanticSummary) {
46
+ const cp = createCheckpoint(taskId, phase, phaseStatus, odgSnapshot, userDecisions, operationLog, nextPhase, semanticSummary);
47
+ saveCheckpoint(cp);
48
+ return cp;
49
+ }
50
+ loadCheckpoint(taskId) {
51
+ return loadLatestCheckpoint(taskId);
52
+ }
53
+ listCheckpoints(taskId) {
54
+ return listCheckpoints(taskId);
55
+ }
56
+ listTasks() {
57
+ return listTasks();
58
+ }
59
+ setContext(key, value) {
60
+ this.context.set(key, value);
61
+ }
62
+ getContext(key) {
63
+ return this.context.get(key);
64
+ }
65
+ }
66
+ let singleton = null;
67
+ export function getHarness() {
68
+ if (!singleton) {
69
+ singleton = new Harness();
70
+ }
71
+ return singleton;
72
+ }
73
+ export function setHarness(h) {
74
+ singleton = h;
75
+ }
@@ -0,0 +1,18 @@
1
+ import type { ODG, ScenarioTemplate } from "./types.js";
2
+ export declare const SCENARIO_REGISTRY: ScenarioTemplate[];
3
+ export interface IntentClassification {
4
+ scenario: string;
5
+ matched_keywords: string[];
6
+ confidence: number;
7
+ fallback: boolean;
8
+ }
9
+ export declare function classifyIntent(userInput: string): IntentClassification;
10
+ export declare function generateODG(userInput: string, taskId?: string): ODG;
11
+ export interface DecisionPoint {
12
+ round: string;
13
+ question: string;
14
+ options: string[];
15
+ default?: string;
16
+ }
17
+ export declare function identifyDecisionPoints(odg: ODG): DecisionPoint[];
18
+ export declare function detectCycles(odg: ODG): string[] | null;