@mcp-graph-workflow/mcp-graph 5.19.2 → 5.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/dist/core/context/compact-context.d.ts +2 -1
  2. package/dist/core/context/compact-context.d.ts.map +1 -1
  3. package/dist/core/context/compact-context.js +29 -16
  4. package/dist/core/context/compact-context.js.map +1 -1
  5. package/dist/core/context/context-assembler.d.ts +9 -0
  6. package/dist/core/context/context-assembler.d.ts.map +1 -1
  7. package/dist/core/context/context-assembler.js +25 -2
  8. package/dist/core/context/context-assembler.js.map +1 -1
  9. package/dist/core/context/rag-context.d.ts +9 -0
  10. package/dist/core/context/rag-context.d.ts.map +1 -1
  11. package/dist/core/context/rag-context.js +29 -3
  12. package/dist/core/context/rag-context.js.map +1 -1
  13. package/dist/core/context/task-context-cache.d.ts +33 -0
  14. package/dist/core/context/task-context-cache.d.ts.map +1 -0
  15. package/dist/core/context/task-context-cache.js +61 -0
  16. package/dist/core/context/task-context-cache.js.map +1 -0
  17. package/dist/core/designer/interface-checker.d.ts.map +1 -1
  18. package/dist/core/designer/interface-checker.js +2 -1
  19. package/dist/core/designer/interface-checker.js.map +1 -1
  20. package/dist/core/rag/multi-strategy-retrieval.d.ts.map +1 -1
  21. package/dist/core/rag/multi-strategy-retrieval.js +3 -6
  22. package/dist/core/rag/multi-strategy-retrieval.js.map +1 -1
  23. package/dist/core/rag/phase-boost-cache.d.ts +20 -0
  24. package/dist/core/rag/phase-boost-cache.d.ts.map +1 -0
  25. package/dist/core/rag/phase-boost-cache.js +50 -0
  26. package/dist/core/rag/phase-boost-cache.js.map +1 -0
  27. package/dist/core/rag/query-cache.d.ts +6 -8
  28. package/dist/core/rag/query-cache.d.ts.map +1 -1
  29. package/dist/core/rag/query-cache.js +21 -38
  30. package/dist/core/rag/query-cache.js.map +1 -1
  31. package/dist/core/rag/rag-pipeline.d.ts.map +1 -1
  32. package/dist/core/rag/rag-pipeline.js +14 -3
  33. package/dist/core/rag/rag-pipeline.js.map +1 -1
  34. package/dist/core/rag/tfidf-embedding-cache.d.ts +20 -0
  35. package/dist/core/rag/tfidf-embedding-cache.d.ts.map +1 -0
  36. package/dist/core/rag/tfidf-embedding-cache.js +46 -0
  37. package/dist/core/rag/tfidf-embedding-cache.js.map +1 -0
  38. package/dist/core/store/graph-snapshot-cache.d.ts +40 -0
  39. package/dist/core/store/graph-snapshot-cache.d.ts.map +1 -0
  40. package/dist/core/store/graph-snapshot-cache.js +39 -0
  41. package/dist/core/store/graph-snapshot-cache.js.map +1 -0
  42. package/dist/core/store/knowledge-store.d.ts +11 -0
  43. package/dist/core/store/knowledge-store.d.ts.map +1 -1
  44. package/dist/core/store/knowledge-store.js +48 -1
  45. package/dist/core/store/knowledge-store.js.map +1 -1
  46. package/dist/core/store/migrations.d.ts.map +1 -1
  47. package/dist/core/store/migrations.js +9 -0
  48. package/dist/core/store/migrations.js.map +1 -1
  49. package/dist/core/translation/ir/ir-converter.d.ts +17 -0
  50. package/dist/core/translation/ir/ir-converter.d.ts.map +1 -0
  51. package/dist/core/translation/ir/ir-converter.js +103 -0
  52. package/dist/core/translation/ir/ir-converter.js.map +1 -0
  53. package/dist/core/translation/ir/ir-types.d.ts +50 -0
  54. package/dist/core/translation/ir/ir-types.d.ts.map +1 -0
  55. package/dist/core/translation/ir/ir-types.js +42 -0
  56. package/dist/core/translation/ir/ir-types.js.map +1 -0
  57. package/dist/core/translation/memory/translation-memory.d.ts +66 -0
  58. package/dist/core/translation/memory/translation-memory.d.ts.map +1 -0
  59. package/dist/core/translation/memory/translation-memory.js +85 -0
  60. package/dist/core/translation/memory/translation-memory.js.map +1 -0
  61. package/dist/core/translation/parsers/csharp-parser-adapter.d.ts +9 -0
  62. package/dist/core/translation/parsers/csharp-parser-adapter.d.ts.map +1 -0
  63. package/dist/core/translation/parsers/csharp-parser-adapter.js +61 -0
  64. package/dist/core/translation/parsers/csharp-parser-adapter.js.map +1 -0
  65. package/dist/core/translation/parsers/go-parser-adapter.d.ts +9 -0
  66. package/dist/core/translation/parsers/go-parser-adapter.d.ts.map +1 -0
  67. package/dist/core/translation/parsers/go-parser-adapter.js +40 -0
  68. package/dist/core/translation/parsers/go-parser-adapter.js.map +1 -0
  69. package/dist/core/translation/parsers/java-parser-adapter.d.ts +9 -0
  70. package/dist/core/translation/parsers/java-parser-adapter.d.ts.map +1 -0
  71. package/dist/core/translation/parsers/java-parser-adapter.js +48 -0
  72. package/dist/core/translation/parsers/java-parser-adapter.js.map +1 -0
  73. package/dist/core/translation/parsers/ruby-parser-adapter.d.ts +9 -0
  74. package/dist/core/translation/parsers/ruby-parser-adapter.d.ts.map +1 -0
  75. package/dist/core/translation/parsers/ruby-parser-adapter.js +45 -0
  76. package/dist/core/translation/parsers/ruby-parser-adapter.js.map +1 -0
  77. package/dist/core/translation/parsers/rust-parser-adapter.d.ts +9 -0
  78. package/dist/core/translation/parsers/rust-parser-adapter.d.ts.map +1 -0
  79. package/dist/core/translation/parsers/rust-parser-adapter.js +47 -0
  80. package/dist/core/translation/parsers/rust-parser-adapter.js.map +1 -0
  81. package/dist/core/translation/pipeline/translation-pipeline.d.ts +42 -0
  82. package/dist/core/translation/pipeline/translation-pipeline.d.ts.map +1 -0
  83. package/dist/core/translation/pipeline/translation-pipeline.js +127 -0
  84. package/dist/core/translation/pipeline/translation-pipeline.js.map +1 -0
  85. package/dist/core/translation/repair/repair-loop.d.ts +40 -0
  86. package/dist/core/translation/repair/repair-loop.d.ts.map +1 -0
  87. package/dist/core/translation/repair/repair-loop.js +68 -0
  88. package/dist/core/translation/repair/repair-loop.js.map +1 -0
  89. package/dist/core/translation/rules/python-to-ts-rules.d.ts +7 -0
  90. package/dist/core/translation/rules/python-to-ts-rules.d.ts.map +1 -0
  91. package/dist/core/translation/rules/python-to-ts-rules.js +160 -0
  92. package/dist/core/translation/rules/python-to-ts-rules.js.map +1 -0
  93. package/dist/core/translation/rules/rule-engine.d.ts +38 -0
  94. package/dist/core/translation/rules/rule-engine.d.ts.map +1 -0
  95. package/dist/core/translation/rules/rule-engine.js +95 -0
  96. package/dist/core/translation/rules/rule-engine.js.map +1 -0
  97. package/dist/core/translation/rules/rule-schema.d.ts +53 -0
  98. package/dist/core/translation/rules/rule-schema.d.ts.map +1 -0
  99. package/dist/core/translation/rules/rule-schema.js +62 -0
  100. package/dist/core/translation/rules/rule-schema.js.map +1 -0
  101. package/dist/core/translation/rules/ts-to-python-rules.d.ts +7 -0
  102. package/dist/core/translation/rules/ts-to-python-rules.d.ts.map +1 -0
  103. package/dist/core/translation/rules/ts-to-python-rules.js +188 -0
  104. package/dist/core/translation/rules/ts-to-python-rules.js.map +1 -0
  105. package/dist/core/translation/ucr/construct-seed-data.json +7132 -0
  106. package/dist/core/translation/validators/code-validator.d.ts +30 -0
  107. package/dist/core/translation/validators/code-validator.d.ts.map +1 -0
  108. package/dist/core/translation/validators/code-validator.js +159 -0
  109. package/dist/core/translation/validators/code-validator.js.map +1 -0
  110. package/dist/mcp/code-intelligence-wrapper.d.ts.map +1 -1
  111. package/dist/mcp/code-intelligence-wrapper.js +9 -7
  112. package/dist/mcp/code-intelligence-wrapper.js.map +1 -1
  113. package/dist/mcp/tools/metrics.d.ts.map +1 -1
  114. package/dist/mcp/tools/metrics.js +5 -1
  115. package/dist/mcp/tools/metrics.js.map +1 -1
  116. package/package.json +7 -5
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Python → TS translation rules.
3
+ * Covers ~60-70% of common constructs deterministically.
4
+ */
5
+ import type { RuleSet } from "./rule-schema.js";
6
+ export declare const PYTHON_TO_TS_RULES: RuleSet;
7
+ //# sourceMappingURL=python-to-ts-rules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"python-to-ts-rules.d.ts","sourceRoot":"","sources":["../../../../src/core/translation/rules/python-to-ts-rules.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD,eAAO,MAAM,kBAAkB,EAAE,OA8JhC,CAAC"}
@@ -0,0 +1,160 @@
1
+ export const PYTHON_TO_TS_RULES = {
2
+ id: "python-to-ts",
3
+ sourceLanguage: "python",
4
+ targetLanguage: "typescript",
5
+ version: "1.0.0",
6
+ rules: [
7
+ // Control flow
8
+ {
9
+ id: "py_ts_if",
10
+ irNodeType: "IfStatement",
11
+ sourceLanguage: "python",
12
+ targetLanguage: "typescript",
13
+ condition: { irNodeType: "IfStatement" },
14
+ transformation: { template: "if ({{condition}}) {\n {{body}}\n} else {\n {{elseBody}}\n}" },
15
+ confidence: 1.0,
16
+ },
17
+ {
18
+ id: "py_ts_for",
19
+ irNodeType: "ForLoop",
20
+ sourceLanguage: "python",
21
+ targetLanguage: "typescript",
22
+ condition: { irNodeType: "ForLoop" },
23
+ transformation: { template: "for (const {{variable}} of {{iterable}}) {\n {{body}}\n}" },
24
+ confidence: 0.9,
25
+ },
26
+ {
27
+ id: "py_ts_while",
28
+ irNodeType: "WhileLoop",
29
+ sourceLanguage: "python",
30
+ targetLanguage: "typescript",
31
+ condition: { irNodeType: "WhileLoop" },
32
+ transformation: { template: "while ({{condition}}) {\n {{body}}\n}" },
33
+ confidence: 1.0,
34
+ },
35
+ {
36
+ id: "py_ts_return",
37
+ irNodeType: "ReturnStatement",
38
+ sourceLanguage: "python",
39
+ targetLanguage: "typescript",
40
+ condition: { irNodeType: "ReturnStatement" },
41
+ transformation: { template: "return {{expression}};" },
42
+ confidence: 1.0,
43
+ },
44
+ // Functions
45
+ {
46
+ id: "py_ts_fn",
47
+ irNodeType: "FunctionDecl",
48
+ sourceLanguage: "python",
49
+ targetLanguage: "typescript",
50
+ condition: { irNodeType: "FunctionDecl" },
51
+ transformation: { template: "function {{name}}({{params}}): {{returnType}} {\n {{body}}\n}" },
52
+ confidence: 1.0,
53
+ },
54
+ {
55
+ id: "py_ts_arrow",
56
+ irNodeType: "ArrowFunction",
57
+ sourceLanguage: "python",
58
+ targetLanguage: "typescript",
59
+ condition: { irNodeType: "ArrowFunction" },
60
+ transformation: { template: "const {{name}} = ({{params}}) => {{expression}};" },
61
+ confidence: 0.8,
62
+ },
63
+ {
64
+ id: "py_ts_method",
65
+ irNodeType: "MethodDecl",
66
+ sourceLanguage: "python",
67
+ targetLanguage: "typescript",
68
+ condition: { irNodeType: "MethodDecl" },
69
+ transformation: { template: "{{name}}({{params}}): {{returnType}} {\n {{body}}\n}" },
70
+ confidence: 0.95,
71
+ },
72
+ // Async
73
+ {
74
+ id: "py_ts_async",
75
+ irNodeType: "AsyncFunction",
76
+ sourceLanguage: "python",
77
+ targetLanguage: "typescript",
78
+ condition: { irNodeType: "AsyncFunction" },
79
+ transformation: { template: "async function {{name}}({{params}}): Promise<{{returnType}}> {\n {{body}}\n}" },
80
+ confidence: 1.0,
81
+ },
82
+ {
83
+ id: "py_ts_await",
84
+ irNodeType: "AwaitExpr",
85
+ sourceLanguage: "python",
86
+ targetLanguage: "typescript",
87
+ condition: { irNodeType: "AwaitExpr" },
88
+ transformation: { template: "await {{expression}}" },
89
+ confidence: 1.0,
90
+ },
91
+ // Classes
92
+ {
93
+ id: "py_ts_class",
94
+ irNodeType: "ClassDecl",
95
+ sourceLanguage: "python",
96
+ targetLanguage: "typescript",
97
+ condition: { irNodeType: "ClassDecl" },
98
+ transformation: { template: "class {{name}}{{extends}} {\n {{body}}\n}" },
99
+ confidence: 0.95,
100
+ },
101
+ {
102
+ id: "py_ts_interface",
103
+ irNodeType: "InterfaceDecl",
104
+ sourceLanguage: "python",
105
+ targetLanguage: "typescript",
106
+ condition: { irNodeType: "InterfaceDecl" },
107
+ transformation: { template: "interface {{name}} {\n {{body}}\n}" },
108
+ confidence: 0.85,
109
+ },
110
+ // Error handling
111
+ {
112
+ id: "py_ts_try",
113
+ irNodeType: "TryCatch",
114
+ sourceLanguage: "python",
115
+ targetLanguage: "typescript",
116
+ condition: { irNodeType: "TryCatch" },
117
+ transformation: { template: "try {\n {{body}}\n} catch ({{errorVar}}) {\n {{catchBody}}\n}" },
118
+ confidence: 1.0,
119
+ },
120
+ {
121
+ id: "py_ts_throw",
122
+ irNodeType: "ThrowStatement",
123
+ sourceLanguage: "python",
124
+ targetLanguage: "typescript",
125
+ condition: { irNodeType: "ThrowStatement" },
126
+ transformation: { template: "throw new {{exception}};" },
127
+ confidence: 0.9,
128
+ },
129
+ // Modules
130
+ {
131
+ id: "py_ts_import",
132
+ irNodeType: "Import",
133
+ sourceLanguage: "python",
134
+ targetLanguage: "typescript",
135
+ condition: { irNodeType: "Import" },
136
+ transformation: { template: "import { {{names}} } from '{{module}}';" },
137
+ confidence: 0.85,
138
+ },
139
+ {
140
+ id: "py_ts_export",
141
+ irNodeType: "Export",
142
+ sourceLanguage: "python",
143
+ targetLanguage: "typescript",
144
+ condition: { irNodeType: "Export" },
145
+ transformation: { template: "export { {{names}} };" },
146
+ confidence: 0.8,
147
+ },
148
+ // Variables
149
+ {
150
+ id: "py_ts_var",
151
+ irNodeType: "VariableDecl",
152
+ sourceLanguage: "python",
153
+ targetLanguage: "typescript",
154
+ condition: { irNodeType: "VariableDecl" },
155
+ transformation: { template: "const {{name}}: {{type}} = {{value}};" },
156
+ confidence: 0.9,
157
+ },
158
+ ],
159
+ };
160
+ //# sourceMappingURL=python-to-ts-rules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"python-to-ts-rules.js","sourceRoot":"","sources":["../../../../src/core/translation/rules/python-to-ts-rules.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,kBAAkB,GAAY;IACzC,EAAE,EAAE,cAAc;IAClB,cAAc,EAAE,QAAQ;IACxB,cAAc,EAAE,YAAY;IAC5B,OAAO,EAAE,OAAO;IAChB,KAAK,EAAE;QACL,eAAe;QACf;YACE,EAAE,EAAE,UAAU;YACd,UAAU,EAAE,aAAa;YACzB,cAAc,EAAE,QAAQ;YACxB,cAAc,EAAE,YAAY;YAC5B,SAAS,EAAE,EAAE,UAAU,EAAE,aAAa,EAAE;YACxC,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 @@
1
+ /**
2
+ * Rule Engine — matches IR nodes against translation rules and applies transformations.
3
+ *
4
+ * Given a RuleSet and IR nodes, finds the best matching rule for each node.
5
+ * Unmatched nodes are flagged for AI fallback.
6
+ */
7
+ import type { RuleSet, TranslationRule } from "./rule-schema.js";
8
+ import type { IRNode } from "../ir/ir-types.js";
9
+ export interface RuleMatchResult {
10
+ node: IRNode;
11
+ rule: TranslationRule;
12
+ confidence: number;
13
+ }
14
+ export interface ApplyRulesResult {
15
+ matched: RuleMatchResult[];
16
+ unmatched: IRNode[];
17
+ }
18
+ export declare class RuleEngine {
19
+ private rulesByType;
20
+ constructor(ruleSet: RuleSet);
21
+ /** Number of rules loaded. */
22
+ get ruleCount(): number;
23
+ /**
24
+ * Find the best matching rule for an IR node.
25
+ * Returns undefined if no rule matches (node should go to AI fallback).
26
+ */
27
+ matchRule(node: IRNode): RuleMatchResult | undefined;
28
+ /**
29
+ * Apply rules to a list of IR nodes.
30
+ * Returns matched nodes (with their rules) and unmatched nodes (for AI fallback).
31
+ */
32
+ applyRules(nodes: IRNode[]): ApplyRulesResult;
33
+ /**
34
+ * Check if an IR node matches a rule's condition.
35
+ */
36
+ private matchesCondition;
37
+ }
38
+ //# sourceMappingURL=rule-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rule-engine.d.ts","sourceRoot":"","sources":["../../../../src/core/translation/rules/rule-engine.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAIhD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,eAAe,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,eAAe,EAAE,CAAC;IAC3B,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB;AAID,qBAAa,UAAU;IACrB,OAAO,CAAC,WAAW,CAA6C;gBAEpD,OAAO,EAAE,OAAO;IAS5B,8BAA8B;IAC9B,IAAI,SAAS,IAAI,MAAM,CAMtB;IAED;;;OAGG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IA4BpD;;;OAGG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,gBAAgB;IAgB7C;;OAEG;IACH,OAAO,CAAC,gBAAgB;CAmBzB"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Rule Engine — matches IR nodes against translation rules and applies transformations.
3
+ *
4
+ * Given a RuleSet and IR nodes, finds the best matching rule for each node.
5
+ * Unmatched nodes are flagged for AI fallback.
6
+ */
7
+ // ── Rule Engine ────────────────────────────────────
8
+ export class RuleEngine {
9
+ rulesByType = new Map();
10
+ constructor(ruleSet) {
11
+ // Index rules by irNodeType for O(1) lookup
12
+ for (const rule of ruleSet.rules) {
13
+ const existing = this.rulesByType.get(rule.irNodeType) ?? [];
14
+ existing.push(rule);
15
+ this.rulesByType.set(rule.irNodeType, existing);
16
+ }
17
+ }
18
+ /** Number of rules loaded. */
19
+ get ruleCount() {
20
+ let count = 0;
21
+ for (const rules of this.rulesByType.values()) {
22
+ count += rules.length;
23
+ }
24
+ return count;
25
+ }
26
+ /**
27
+ * Find the best matching rule for an IR node.
28
+ * Returns undefined if no rule matches (node should go to AI fallback).
29
+ */
30
+ matchRule(node) {
31
+ const candidates = this.rulesByType.get(node.type);
32
+ if (!candidates || candidates.length === 0) {
33
+ return undefined;
34
+ }
35
+ // Find best match by condition + highest confidence
36
+ let bestRule;
37
+ let bestConfidence = -1;
38
+ for (const rule of candidates) {
39
+ if (!this.matchesCondition(node, rule))
40
+ continue;
41
+ if (rule.confidence > bestConfidence) {
42
+ bestConfidence = rule.confidence;
43
+ bestRule = rule;
44
+ }
45
+ }
46
+ if (!bestRule)
47
+ return undefined;
48
+ return {
49
+ node,
50
+ rule: bestRule,
51
+ confidence: bestConfidence,
52
+ };
53
+ }
54
+ /**
55
+ * Apply rules to a list of IR nodes.
56
+ * Returns matched nodes (with their rules) and unmatched nodes (for AI fallback).
57
+ */
58
+ applyRules(nodes) {
59
+ const matched = [];
60
+ const unmatched = [];
61
+ for (const node of nodes) {
62
+ const result = this.matchRule(node);
63
+ if (result) {
64
+ matched.push(result);
65
+ }
66
+ else {
67
+ unmatched.push(node);
68
+ }
69
+ }
70
+ return { matched, unmatched };
71
+ }
72
+ /**
73
+ * Check if an IR node matches a rule's condition.
74
+ */
75
+ matchesCondition(node, rule) {
76
+ // Type must match
77
+ if (rule.condition.irNodeType !== node.type)
78
+ return false;
79
+ // Optional: check hasChildren
80
+ if (rule.condition.hasChildren !== undefined) {
81
+ const hasChildren = node.children.length > 0;
82
+ if (rule.condition.hasChildren !== hasChildren)
83
+ return false;
84
+ }
85
+ // Optional: check metadata
86
+ if (rule.condition.metadata) {
87
+ for (const [key, value] of Object.entries(rule.condition.metadata)) {
88
+ if (node.metadata?.[key] !== value)
89
+ return false;
90
+ }
91
+ }
92
+ return true;
93
+ }
94
+ }
95
+ //# sourceMappingURL=rule-engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rule-engine.js","sourceRoot":"","sources":["../../../../src/core/translation/rules/rule-engine.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAkBH,sDAAsD;AAEtD,MAAM,OAAO,UAAU;IACb,WAAW,GAAmC,IAAI,GAAG,EAAE,CAAC;IAEhE,YAAY,OAAgB;QAC1B,4CAA4C;QAC5C,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;YACjC,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;YAC7D,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACpB,IAAI,CAAC,WAAW,CA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M,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YACpC,IAAI,MAAM,EAAE,CAAC;gBACX,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACvB,CAAC;iBAAM,CAAC;gBACN,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACvB,CAAC;QACH,CAAC;QAED,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;IAChC,CAAC;IAED;;OAEG;IACK,gBAAgB,CAAC,IAAY,EAAE,IAAqB;QAC1D,kBAAkB;QAClB,IAAI,IAAI,CAAC,SAAS,CAAC,UAAU,KAAK,IAAI,CAAC,IAAI;YAAE,OAAO,KAAK,CAAC;QAE1D,8BAA8B;QAC9B,IAAI,IAAI,CAAC,SAAS,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;YAC7C,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;YAC7C,IAAI,IAAI,CAAC,SAAS,CAAC,WAAW,KAAK,WAAW;gBAAE,OAAO,KAAK,CAAC;QAC/D,CAAC;QAED,2BAA2B;QAC3B,IAAI,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;YAC5B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACnE,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,KAAK,KAAK;oBAAE,OAAO,KAAK,CAAC;YACnD,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Rule Schema — Zod schemas for declarative translation rules.
3
+ *
4
+ * Each rule maps an IR node type (condition) to a target syntax template (transformation).
5
+ * Rules are organized in rule sets per language pair (e.g., ts-to-python.json).
6
+ */
7
+ import { z } from "zod/v4";
8
+ export declare const TranslationRuleSchema: z.ZodObject<{
9
+ id: z.ZodString;
10
+ irNodeType: z.ZodString;
11
+ sourceLanguage: z.ZodString;
12
+ targetLanguage: z.ZodString;
13
+ condition: z.ZodObject<{
14
+ irNodeType: z.ZodString;
15
+ hasChildren: z.ZodOptional<z.ZodBoolean>;
16
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
17
+ }, z.core.$strip>;
18
+ transformation: z.ZodObject<{
19
+ template: z.ZodString;
20
+ notes: z.ZodOptional<z.ZodString>;
21
+ }, z.core.$strip>;
22
+ confidence: z.ZodNumber;
23
+ }, z.core.$strip>;
24
+ export type TranslationRule = z.infer<typeof TranslationRuleSchema>;
25
+ export declare const RuleSetSchema: z.ZodObject<{
26
+ id: z.ZodString;
27
+ sourceLanguage: z.ZodString;
28
+ targetLanguage: z.ZodString;
29
+ version: z.ZodString;
30
+ rules: z.ZodArray<z.ZodObject<{
31
+ id: z.ZodString;
32
+ irNodeType: z.ZodString;
33
+ sourceLanguage: z.ZodString;
34
+ targetLanguage: z.ZodString;
35
+ condition: z.ZodObject<{
36
+ irNodeType: z.ZodString;
37
+ hasChildren: z.ZodOptional<z.ZodBoolean>;
38
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
39
+ }, z.core.$strip>;
40
+ transformation: z.ZodObject<{
41
+ template: z.ZodString;
42
+ notes: z.ZodOptional<z.ZodString>;
43
+ }, z.core.$strip>;
44
+ confidence: z.ZodNumber;
45
+ }, z.core.$strip>>;
46
+ }, z.core.$strip>;
47
+ export type RuleSet = z.infer<typeof RuleSetSchema>;
48
+ /**
49
+ * Load and validate a rule set from a raw object (e.g., parsed JSON).
50
+ * Throws on validation failure.
51
+ */
52
+ export declare function loadRuleSet(raw: unknown): RuleSet;
53
+ //# sourceMappingURL=rule-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rule-schema.d.ts","sourceRoot":"","sources":["../../../../src/core/translation/rules/rule-schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAwB3B,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;iBAehC,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAIpE,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;iBAWxB,CAAC;AAEH,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAIpD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAEjD"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Rule Schema — Zod schemas for declarative translation rules.
3
+ *
4
+ * Each rule maps an IR node type (condition) to a target syntax template (transformation).
5
+ * Rules are organized in rule sets per language pair (e.g., ts-to-python.json).
6
+ */
7
+ import { z } from "zod/v4";
8
+ // ── Rule Condition ─────────────────────────────────
9
+ const RuleConditionSchema = z.object({
10
+ /** IR node type to match. */
11
+ irNodeType: z.string(),
12
+ /** Optional: require the node to have children. */
13
+ hasChildren: z.boolean().optional(),
14
+ /** Optional: match by construct metadata key/value. */
15
+ metadata: z.record(z.string(), z.unknown()).optional(),
16
+ });
17
+ // ── Rule Transformation ────────────────────────────
18
+ const RuleTransformationSchema = z.object({
19
+ /** Target syntax template with {{placeholders}}. */
20
+ template: z.string().min(1),
21
+ /** Optional: notes about the transformation for humans. */
22
+ notes: z.string().optional(),
23
+ });
24
+ // ── Translation Rule ───────────────────────────────
25
+ export const TranslationRuleSchema = z.object({
26
+ /** Unique rule ID. */
27
+ id: z.string().min(1),
28
+ /** IR node type this rule applies to. */
29
+ irNodeType: z.string().min(1),
30
+ /** Source language (e.g., "typescript"). */
31
+ sourceLanguage: z.string().min(1),
32
+ /** Target language (e.g., "python"). */
33
+ targetLanguage: z.string().min(1),
34
+ /** Condition to match IR nodes. */
35
+ condition: RuleConditionSchema,
36
+ /** Transformation template for target language. */
37
+ transformation: RuleTransformationSchema,
38
+ /** Confidence of this rule (0-1). */
39
+ confidence: z.number().min(0).max(1),
40
+ });
41
+ // ── Rule Set ───────────────────────────────────────
42
+ export const RuleSetSchema = z.object({
43
+ /** Rule set ID (e.g., "ts-to-python"). */
44
+ id: z.string().min(1),
45
+ /** Source language for all rules in this set. */
46
+ sourceLanguage: z.string().min(1),
47
+ /** Target language for all rules in this set. */
48
+ targetLanguage: z.string().min(1),
49
+ /** Semantic version of this rule set. */
50
+ version: z.string().min(1),
51
+ /** Rules in this set (at least 1). */
52
+ rules: z.array(TranslationRuleSchema).min(1),
53
+ });
54
+ // ── Loader ─────────────────────────────────────────
55
+ /**
56
+ * Load and validate a rule set from a raw object (e.g., parsed JSON).
57
+ * Throws on validation failure.
58
+ */
59
+ export function loadRuleSet(raw) {
60
+ return RuleSetSchema.parse(raw);
61
+ }
62
+ //# sourceMappingURL=rule-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rule-schema.js","sourceRoot":"","sources":["../../../../src/core/translation/rules/rule-schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAE3B,sDAAsD;AAEtD,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,6BAA6B;IAC7B,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,mDAAmD;IACnD,WAAW,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IACnC,uDAAuD;IACvD,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,EAAE;CACvD,CAAC,CAAC;AAEH,sDAAsD;AAEtD,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC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CAAC,CAAC,CAAC;IAC1B,sCAAsC;IACtC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;CAC7C,CAAC,CAAC;AAIH,sDAAsD;AAEtD;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,GAAY;IACtC,OAAO,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AAClC,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * TS → Python translation rules.
3
+ * Covers ~60-70% of common constructs deterministically.
4
+ */
5
+ import type { RuleSet } from "./rule-schema.js";
6
+ export declare const TS_TO_PYTHON_RULES: RuleSet;
7
+ //# sourceMappingURL=ts-to-python-rules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ts-to-python-rules.d.ts","sourceRoot":"","sources":["../../../../src/core/translation/rules/ts-to-python-rules.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD,eAAO,MAAM,kBAAkB,EAAE,OA0LhC,CAAC"}
@@ -0,0 +1,188 @@
1
+ export const TS_TO_PYTHON_RULES = {
2
+ id: "ts-to-python",
3
+ sourceLanguage: "typescript",
4
+ targetLanguage: "python",
5
+ version: "1.0.0",
6
+ rules: [
7
+ // Control flow
8
+ {
9
+ id: "ts_py_if",
10
+ irNodeType: "IfStatement",
11
+ sourceLanguage: "typescript",
12
+ targetLanguage: "python",
13
+ condition: { irNodeType: "IfStatement" },
14
+ transformation: { template: "if {{condition}}:\n {{body}}\nelse:\n {{elseBody}}" },
15
+ confidence: 1.0,
16
+ },
17
+ {
18
+ id: "ts_py_for",
19
+ irNodeType: "ForLoop",
20
+ sourceLanguage: "typescript",
21
+ targetLanguage: "python",
22
+ condition: { irNodeType: "ForLoop" },
23
+ transformation: { template: "for {{variable}} in {{iterable}}:\n {{body}}" },
24
+ confidence: 0.9,
25
+ },
26
+ {
27
+ id: "ts_py_while",
28
+ irNodeType: "WhileLoop",
29
+ sourceLanguage: "typescript",
30
+ targetLanguage: "python",
31
+ condition: { irNodeType: "WhileLoop" },
32
+ transformation: { template: "while {{condition}}:\n {{body}}" },
33
+ confidence: 1.0,
34
+ },
35
+ {
36
+ id: "ts_py_switch",
37
+ irNodeType: "SwitchCase",
38
+ sourceLanguage: "typescript",
39
+ targetLanguage: "python",
40
+ condition: { irNodeType: "SwitchCase" },
41
+ transformation: { template: "match {{expression}}:\n case {{pattern}}:\n {{body}}", notes: "Python 3.10+ match/case" },
42
+ confidence: 0.8,
43
+ },
44
+ {
45
+ id: "ts_py_return",
46
+ irNodeType: "ReturnStatement",
47
+ sourceLanguage: "typescript",
48
+ targetLanguage: "python",
49
+ condition: { irNodeType: "ReturnStatement" },
50
+ transformation: { template: "return {{expression}}" },
51
+ confidence: 1.0,
52
+ },
53
+ // Functions
54
+ {
55
+ id: "ts_py_fn",
56
+ irNodeType: "FunctionDecl",
57
+ sourceLanguage: "typescript",
58
+ targetLanguage: "python",
59
+ condition: { irNodeType: "FunctionDecl" },
60
+ transformation: { template: "def {{name}}({{params}}):\n {{body}}" },
61
+ confidence: 1.0,
62
+ },
63
+ {
64
+ id: "ts_py_arrow",
65
+ irNodeType: "ArrowFunction",
66
+ sourceLanguage: "typescript",
67
+ targetLanguage: "python",
68
+ condition: { irNodeType: "ArrowFunction" },
69
+ transformation: { template: "{{name}} = lambda {{params}}: {{expression}}", notes: "Single-expression arrows; multi-line needs def" },
70
+ confidence: 0.7,
71
+ },
72
+ {
73
+ id: "ts_py_method",
74
+ irNodeType: "MethodDecl",
75
+ sourceLanguage: "typescript",
76
+ targetLanguage: "python",
77
+ condition: { irNodeType: "MethodDecl" },
78
+ transformation: { template: "def {{name}}(self, {{params}}):\n {{body}}" },
79
+ confidence: 0.95,
80
+ },
81
+ // Async
82
+ {
83
+ id: "ts_py_async",
84
+ irNodeType: "AsyncFunction",
85
+ sourceLanguage: "typescript",
86
+ targetLanguage: "python",
87
+ condition: { irNodeType: "AsyncFunction" },
88
+ transformation: { template: "async def {{name}}({{params}}):\n {{body}}" },
89
+ confidence: 1.0,
90
+ },
91
+ {
92
+ id: "ts_py_await",
93
+ irNodeType: "AwaitExpr",
94
+ sourceLanguage: "typescript",
95
+ targetLanguage: "python",
96
+ condition: { irNodeType: "AwaitExpr" },
97
+ transformation: { template: "await {{expression}}" },
98
+ confidence: 1.0,
99
+ },
100
+ // Classes
101
+ {
102
+ id: "ts_py_class",
103
+ irNodeType: "ClassDecl",
104
+ sourceLanguage: "typescript",
105
+ targetLanguage: "python",
106
+ condition: { irNodeType: "ClassDecl" },
107
+ transformation: { template: "class {{name}}{{extends}}:\n {{body}}" },
108
+ confidence: 0.95,
109
+ },
110
+ {
111
+ id: "ts_py_interface",
112
+ irNodeType: "InterfaceDecl",
113
+ sourceLanguage: "typescript",
114
+ targetLanguage: "python",
115
+ condition: { irNodeType: "InterfaceDecl" },
116
+ transformation: { template: "class {{name}}(Protocol):\n {{body}}", notes: "Python Protocol for structural typing" },
117
+ confidence: 0.8,
118
+ },
119
+ {
120
+ id: "ts_py_property",
121
+ irNodeType: "PropertyDecl",
122
+ sourceLanguage: "typescript",
123
+ targetLanguage: "python",
124
+ condition: { irNodeType: "PropertyDecl" },
125
+ transformation: { template: "{{name}}: {{type}} = {{default}}" },
126
+ confidence: 0.85,
127
+ },
128
+ // Error handling
129
+ {
130
+ id: "ts_py_try",
131
+ irNodeType: "TryCatch",
132
+ sourceLanguage: "typescript",
133
+ targetLanguage: "python",
134
+ condition: { irNodeType: "TryCatch" },
135
+ transformation: { template: "try:\n {{body}}\nexcept {{errorType}} as {{errorVar}}:\n {{catchBody}}" },
136
+ confidence: 1.0,
137
+ },
138
+ {
139
+ id: "ts_py_throw",
140
+ irNodeType: "ThrowStatement",
141
+ sourceLanguage: "typescript",
142
+ targetLanguage: "python",
143
+ condition: { irNodeType: "ThrowStatement" },
144
+ transformation: { template: "raise {{exception}}" },
145
+ confidence: 1.0,
146
+ },
147
+ // Modules
148
+ {
149
+ id: "ts_py_import",
150
+ irNodeType: "Import",
151
+ sourceLanguage: "typescript",
152
+ targetLanguage: "python",
153
+ condition: { irNodeType: "Import" },
154
+ transformation: { template: "from {{module}} import {{names}}" },
155
+ confidence: 0.9,
156
+ },
157
+ {
158
+ id: "ts_py_export",
159
+ irNodeType: "Export",
160
+ sourceLanguage: "typescript",
161
+ targetLanguage: "python",
162
+ condition: { irNodeType: "Export" },
163
+ transformation: { template: "# export: {{names}} (Python uses __all__)", notes: "Python has no direct export — use __all__" },
164
+ confidence: 0.6,
165
+ },
166
+ // Variables
167
+ {
168
+ id: "ts_py_var",
169
+ irNodeType: "VariableDecl",
170
+ sourceLanguage: "typescript",
171
+ targetLanguage: "python",
172
+ condition: { irNodeType: "VariableDecl" },
173
+ transformation: { template: "{{name}} = {{value}}" },
174
+ confidence: 1.0,
175
+ },
176
+ // Types
177
+ {
178
+ id: "ts_py_type",
179
+ irNodeType: "TypeAnnotation",
180
+ sourceLanguage: "typescript",
181
+ targetLanguage: "python",
182
+ condition: { irNodeType: "TypeAnnotation" },
183
+ transformation: { template: "{{name}}: {{type}}", notes: "Python type hints" },
184
+ confidence: 0.85,
185
+ },
186
+ ],
187
+ };
188
+ //# sourceMappingURL=ts-to-python-rules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ts-to-python-rules.js","sourceRoot":"","sources":["../../../../src/core/translation/rules/ts-to-python-rules.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,kBAAkB,GAAY;IACzC,EAAE,EAAE,cAAc;IAClB,cAAc,EAAE,YAAY;IAC5B,cAAc,EAAE,QAAQ;IACxB,OAAO,EAAE,OAAO;IAChB,KAAK,EAAE;QACL,eAAe;QACf;YACE,EAAE,EAAE,UAAU;YACd,UAAU,EAAE,aAAa;YACzB,cAAc,EAAE,YAAY;YAC5B,cAAc,EAAE,QAAQ;YACxB,SAAS,EAAE,EAAE,UAAU,EAAE,aAAa,EA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