@orcalang/orca-lang 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +128 -0
  3. package/dist/auth/index.d.ts +6 -0
  4. package/dist/auth/index.d.ts.map +1 -0
  5. package/dist/auth/index.js +6 -0
  6. package/dist/auth/index.js.map +1 -0
  7. package/dist/auth/lock.d.ts +2 -0
  8. package/dist/auth/lock.d.ts.map +1 -0
  9. package/dist/auth/lock.js +59 -0
  10. package/dist/auth/lock.js.map +1 -0
  11. package/dist/auth/providers/anthropic.d.ts +14 -0
  12. package/dist/auth/providers/anthropic.d.ts.map +1 -0
  13. package/dist/auth/providers/anthropic.js +145 -0
  14. package/dist/auth/providers/anthropic.js.map +1 -0
  15. package/dist/auth/providers/index.d.ts +3 -0
  16. package/dist/auth/providers/index.d.ts.map +1 -0
  17. package/dist/auth/providers/index.js +3 -0
  18. package/dist/auth/providers/index.js.map +1 -0
  19. package/dist/auth/providers/minimax.d.ts +6 -0
  20. package/dist/auth/providers/minimax.d.ts.map +1 -0
  21. package/dist/auth/providers/minimax.js +65 -0
  22. package/dist/auth/providers/minimax.js.map +1 -0
  23. package/dist/auth/refresh.d.ts +8 -0
  24. package/dist/auth/refresh.d.ts.map +1 -0
  25. package/dist/auth/refresh.js +104 -0
  26. package/dist/auth/refresh.js.map +1 -0
  27. package/dist/auth/store.d.ts +11 -0
  28. package/dist/auth/store.d.ts.map +1 -0
  29. package/dist/auth/store.js +63 -0
  30. package/dist/auth/store.js.map +1 -0
  31. package/dist/auth/types.d.ts +51 -0
  32. package/dist/auth/types.d.ts.map +1 -0
  33. package/dist/auth/types.js +2 -0
  34. package/dist/auth/types.js.map +1 -0
  35. package/dist/compiler/mermaid.d.ts +3 -0
  36. package/dist/compiler/mermaid.d.ts.map +1 -0
  37. package/dist/compiler/mermaid.js +86 -0
  38. package/dist/compiler/mermaid.js.map +1 -0
  39. package/dist/compiler/xstate.d.ts +15 -0
  40. package/dist/compiler/xstate.d.ts.map +1 -0
  41. package/dist/compiler/xstate.js +542 -0
  42. package/dist/compiler/xstate.js.map +1 -0
  43. package/dist/config/index.d.ts +3 -0
  44. package/dist/config/index.d.ts.map +1 -0
  45. package/dist/config/index.js +3 -0
  46. package/dist/config/index.js.map +1 -0
  47. package/dist/config/loader.d.ts +4 -0
  48. package/dist/config/loader.d.ts.map +1 -0
  49. package/dist/config/loader.js +109 -0
  50. package/dist/config/loader.js.map +1 -0
  51. package/dist/config/types.d.ts +13 -0
  52. package/dist/config/types.d.ts.map +1 -0
  53. package/dist/config/types.js +8 -0
  54. package/dist/config/types.js.map +1 -0
  55. package/dist/generators/index.d.ts +5 -0
  56. package/dist/generators/index.d.ts.map +1 -0
  57. package/dist/generators/index.js +5 -0
  58. package/dist/generators/index.js.map +1 -0
  59. package/dist/generators/registry.d.ts +12 -0
  60. package/dist/generators/registry.d.ts.map +1 -0
  61. package/dist/generators/registry.js +15 -0
  62. package/dist/generators/registry.js.map +1 -0
  63. package/dist/generators/typescript.d.ts +9 -0
  64. package/dist/generators/typescript.d.ts.map +1 -0
  65. package/dist/generators/typescript.js +55 -0
  66. package/dist/generators/typescript.js.map +1 -0
  67. package/dist/index.d.ts +10 -0
  68. package/dist/index.d.ts.map +1 -0
  69. package/dist/index.js +630 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/llm/anthropic.d.ts +14 -0
  72. package/dist/llm/anthropic.d.ts.map +1 -0
  73. package/dist/llm/anthropic.js +87 -0
  74. package/dist/llm/anthropic.js.map +1 -0
  75. package/dist/llm/grok.d.ts +13 -0
  76. package/dist/llm/grok.d.ts.map +1 -0
  77. package/dist/llm/grok.js +60 -0
  78. package/dist/llm/grok.js.map +1 -0
  79. package/dist/llm/index.d.ts +11 -0
  80. package/dist/llm/index.d.ts.map +1 -0
  81. package/dist/llm/index.js +23 -0
  82. package/dist/llm/index.js.map +1 -0
  83. package/dist/llm/ollama.d.ts +11 -0
  84. package/dist/llm/ollama.d.ts.map +1 -0
  85. package/dist/llm/ollama.js +51 -0
  86. package/dist/llm/ollama.js.map +1 -0
  87. package/dist/llm/openai.d.ts +13 -0
  88. package/dist/llm/openai.d.ts.map +1 -0
  89. package/dist/llm/openai.js +61 -0
  90. package/dist/llm/openai.js.map +1 -0
  91. package/dist/llm/provider.d.ts +32 -0
  92. package/dist/llm/provider.d.ts.map +1 -0
  93. package/dist/llm/provider.js +2 -0
  94. package/dist/llm/provider.js.map +1 -0
  95. package/dist/parser/ast-to-markdown.d.ts +3 -0
  96. package/dist/parser/ast-to-markdown.d.ts.map +1 -0
  97. package/dist/parser/ast-to-markdown.js +209 -0
  98. package/dist/parser/ast-to-markdown.js.map +1 -0
  99. package/dist/parser/ast.d.ts +183 -0
  100. package/dist/parser/ast.d.ts.map +1 -0
  101. package/dist/parser/ast.js +3 -0
  102. package/dist/parser/ast.js.map +1 -0
  103. package/dist/parser/markdown-parser.d.ts +8 -0
  104. package/dist/parser/markdown-parser.d.ts.map +1 -0
  105. package/dist/parser/markdown-parser.js +838 -0
  106. package/dist/parser/markdown-parser.js.map +1 -0
  107. package/dist/runtime/effects.d.ts +17 -0
  108. package/dist/runtime/effects.d.ts.map +1 -0
  109. package/dist/runtime/effects.js +28 -0
  110. package/dist/runtime/effects.js.map +1 -0
  111. package/dist/runtime/machine.d.ts +8 -0
  112. package/dist/runtime/machine.d.ts.map +1 -0
  113. package/dist/runtime/machine.js +158 -0
  114. package/dist/runtime/machine.js.map +1 -0
  115. package/dist/runtime/types.d.ts +37 -0
  116. package/dist/runtime/types.d.ts.map +1 -0
  117. package/dist/runtime/types.js +3 -0
  118. package/dist/runtime/types.js.map +1 -0
  119. package/dist/skills.d.ts +114 -0
  120. package/dist/skills.d.ts.map +1 -0
  121. package/dist/skills.js +1103 -0
  122. package/dist/skills.js.map +1 -0
  123. package/dist/tools.d.ts +18 -0
  124. package/dist/tools.d.ts.map +1 -0
  125. package/dist/tools.js +124 -0
  126. package/dist/tools.js.map +1 -0
  127. package/dist/verifier/completeness.d.ts +4 -0
  128. package/dist/verifier/completeness.d.ts.map +1 -0
  129. package/dist/verifier/completeness.js +82 -0
  130. package/dist/verifier/completeness.js.map +1 -0
  131. package/dist/verifier/determinism.d.ts +17 -0
  132. package/dist/verifier/determinism.d.ts.map +1 -0
  133. package/dist/verifier/determinism.js +301 -0
  134. package/dist/verifier/determinism.js.map +1 -0
  135. package/dist/verifier/properties.d.ts +6 -0
  136. package/dist/verifier/properties.d.ts.map +1 -0
  137. package/dist/verifier/properties.js +404 -0
  138. package/dist/verifier/properties.js.map +1 -0
  139. package/dist/verifier/structural.d.ts +50 -0
  140. package/dist/verifier/structural.d.ts.map +1 -0
  141. package/dist/verifier/structural.js +692 -0
  142. package/dist/verifier/structural.js.map +1 -0
  143. package/dist/verifier/types.d.ts +40 -0
  144. package/dist/verifier/types.d.ts.map +1 -0
  145. package/dist/verifier/types.js +2 -0
  146. package/dist/verifier/types.js.map +1 -0
  147. package/package.json +49 -0
  148. package/src/auth/index.ts +5 -0
  149. package/src/auth/lock.ts +71 -0
  150. package/src/auth/providers/anthropic.ts +192 -0
  151. package/src/auth/providers/index.ts +17 -0
  152. package/src/auth/providers/minimax.ts +100 -0
  153. package/src/auth/refresh.ts +138 -0
  154. package/src/auth/store.ts +75 -0
  155. package/src/auth/types.ts +62 -0
  156. package/src/compiler/mermaid.ts +109 -0
  157. package/src/compiler/xstate.ts +615 -0
  158. package/src/config/index.ts +2 -0
  159. package/src/config/loader.ts +122 -0
  160. package/src/config/types.ts +21 -0
  161. package/src/generators/index.ts +6 -0
  162. package/src/generators/registry.ts +27 -0
  163. package/src/generators/typescript.ts +67 -0
  164. package/src/index.ts +671 -0
  165. package/src/llm/anthropic.ts +102 -0
  166. package/src/llm/grok.ts +73 -0
  167. package/src/llm/index.ts +29 -0
  168. package/src/llm/ollama.ts +62 -0
  169. package/src/llm/openai.ts +74 -0
  170. package/src/llm/provider.ts +35 -0
  171. package/src/parser/ast-to-markdown.ts +220 -0
  172. package/src/parser/ast.ts +236 -0
  173. package/src/parser/markdown-parser.ts +844 -0
  174. package/src/runtime/effects.ts +48 -0
  175. package/src/runtime/machine.ts +201 -0
  176. package/src/runtime/types.ts +44 -0
  177. package/src/skills.ts +1339 -0
  178. package/src/tools.ts +144 -0
  179. package/src/verifier/completeness.ts +89 -0
  180. package/src/verifier/determinism.ts +328 -0
  181. package/src/verifier/properties.ts +507 -0
  182. package/src/verifier/structural.ts +803 -0
  183. package/src/verifier/types.ts +45 -0
@@ -0,0 +1,122 @@
1
+ import { readFileSync, existsSync } from 'fs';
2
+ import { join, dirname } from 'path';
3
+ import { homedir } from 'os';
4
+ import yaml from 'js-yaml';
5
+ import { OrcaConfig, DEFAULT_CONFIG } from './types.js';
6
+
7
+ let envLoaded = false;
8
+
9
+ function loadEnvFile(): void {
10
+ if (envLoaded) return;
11
+ envLoaded = true;
12
+
13
+ // Load from project root .env
14
+ const cwd = process.cwd();
15
+ const envPath = join(cwd, '.env');
16
+ if (existsSync(envPath)) {
17
+ const content = readFileSync(envPath, 'utf-8');
18
+ for (const line of content.split('\n')) {
19
+ const trimmed = line.trim();
20
+ if (!trimmed || trimmed.startsWith('#')) continue;
21
+ const eqIndex = trimmed.indexOf('=');
22
+ if (eqIndex === -1) continue;
23
+ const key = trimmed.slice(0, eqIndex).trim();
24
+ let value = trimmed.slice(eqIndex + 1).trim();
25
+ // Remove surrounding quotes
26
+ if ((value.startsWith('"') && value.endsWith('"')) ||
27
+ (value.startsWith("'") && value.endsWith("'"))) {
28
+ value = value.slice(1, -1);
29
+ }
30
+ if (key && !process.env[key]) {
31
+ process.env[key] = value;
32
+ }
33
+ }
34
+ }
35
+ }
36
+
37
+ function interpolateEnvVars(obj: unknown): unknown {
38
+ if (typeof obj === 'string') {
39
+ // Replace ${VAR_NAME} with environment variable value
40
+ return obj.replace(/\$\{([^}]+)\}/g, (_, varName) => {
41
+ const value = process.env[varName];
42
+ if (value === undefined) {
43
+ throw new Error(`Environment variable ${varName} is not set`);
44
+ }
45
+ return value;
46
+ });
47
+ }
48
+ if (Array.isArray(obj)) {
49
+ return obj.map(interpolateEnvVars);
50
+ }
51
+ if (obj !== null && typeof obj === 'object') {
52
+ const result: Record<string, unknown> = {};
53
+ for (const [key, value] of Object.entries(obj)) {
54
+ result[key] = interpolateEnvVars(value);
55
+ }
56
+ return result;
57
+ }
58
+ return obj;
59
+ }
60
+
61
+ function deepMerge(target: OrcaConfig, source: Partial<OrcaConfig>): OrcaConfig {
62
+ const result = { ...target };
63
+ for (const [key, value] of Object.entries(source)) {
64
+ if (value !== undefined && value !== null) {
65
+ (result as Record<string, unknown>)[key] = value;
66
+ }
67
+ }
68
+ return result;
69
+ }
70
+
71
+ export function loadConfig(configPath?: string): OrcaConfig {
72
+ loadEnvFile();
73
+ const configs: Partial<OrcaConfig>[] = [];
74
+
75
+ // 1. Global default
76
+ const globalConfigPath = join(homedir(), '.orca', 'default.yaml');
77
+ if (existsSync(globalConfigPath)) {
78
+ const content = readFileSync(globalConfigPath, 'utf-8');
79
+ const parsed = yaml.load(content) as Record<string, unknown>;
80
+ configs.push(interpolateEnvVars(parsed) as Partial<OrcaConfig>);
81
+ }
82
+
83
+ // 2. Project config (current working directory or specified path)
84
+ const projectConfigPath = configPath || findProjectConfig();
85
+ if (projectConfigPath && existsSync(projectConfigPath)) {
86
+ const content = readFileSync(projectConfigPath, 'utf-8');
87
+ const parsed = yaml.load(content) as Record<string, unknown>;
88
+ configs.push(interpolateEnvVars(parsed) as Partial<OrcaConfig>);
89
+ }
90
+
91
+ // 3. Merge all configs in order (later ones override earlier)
92
+ let result = DEFAULT_CONFIG;
93
+ for (const config of configs) {
94
+ result = deepMerge(result, config);
95
+ }
96
+
97
+ return result;
98
+ }
99
+
100
+ function findProjectConfig(): string | undefined {
101
+ const cwd = process.cwd();
102
+ const possiblePaths = [
103
+ join(cwd, 'orca.yaml'),
104
+ join(cwd, '.orca.yaml'),
105
+ join(cwd, 'orca', 'orca.yaml'),
106
+ ];
107
+
108
+ for (const path of possiblePaths) {
109
+ if (existsSync(path)) {
110
+ return path;
111
+ }
112
+ }
113
+
114
+ return undefined;
115
+ }
116
+
117
+ export function resolveConfigOverrides(
118
+ config: OrcaConfig,
119
+ overrides: Partial<OrcaConfig>
120
+ ): OrcaConfig {
121
+ return deepMerge(config, overrides);
122
+ }
@@ -0,0 +1,21 @@
1
+ export type LLMProviderType = 'anthropic' | 'openai' | 'ollama' | 'grok';
2
+
3
+ export type CodeGeneratorType = 'typescript' | 'python' | 'rust' | 'go';
4
+
5
+ export interface OrcaConfig {
6
+ provider: LLMProviderType;
7
+ model: string;
8
+ api_key?: string;
9
+ base_url?: string;
10
+ code_generator: CodeGeneratorType;
11
+ max_tokens?: number;
12
+ temperature?: number;
13
+ }
14
+
15
+ export const DEFAULT_CONFIG: OrcaConfig = {
16
+ provider: 'anthropic',
17
+ model: 'claude-sonnet-4-6',
18
+ code_generator: 'typescript',
19
+ max_tokens: 4096,
20
+ temperature: 0.7,
21
+ };
@@ -0,0 +1,6 @@
1
+ export type { CodeGenerator } from './registry.js';
2
+ export { registerCodeGenerator, getCodeGenerator, listCodeGenerators } from './registry.js';
3
+ export { TypeScriptCodeGenerator } from './typescript.js';
4
+
5
+ // Import to register generators
6
+ import './typescript.js';
@@ -0,0 +1,27 @@
1
+ import { ActionScaffold } from '../skills.js';
2
+ import { MachineDef } from '../parser/ast.js';
3
+ import { CodeGeneratorType } from '../config/types.js';
4
+
5
+ export interface CodeGenerator {
6
+ name(): string;
7
+ generate(actions: ActionScaffold[], machine: MachineDef): string;
8
+ generateAction(action: ActionScaffold, machine: MachineDef): string;
9
+ }
10
+
11
+ const generators = new Map<CodeGeneratorType, () => CodeGenerator>();
12
+
13
+ export function registerCodeGenerator(type: CodeGeneratorType, factory: () => CodeGenerator): void {
14
+ generators.set(type, factory);
15
+ }
16
+
17
+ export function getCodeGenerator(type: CodeGeneratorType): CodeGenerator {
18
+ const factory = generators.get(type);
19
+ if (!factory) {
20
+ throw new Error(`No code generator registered for type: ${type}`);
21
+ }
22
+ return factory();
23
+ }
24
+
25
+ export function listCodeGenerators(): CodeGeneratorType[] {
26
+ return Array.from(generators.keys());
27
+ }
@@ -0,0 +1,67 @@
1
+ import { CodeGenerator } from './registry.js';
2
+ import { ActionScaffold } from '../skills.js';
3
+ import { MachineDef } from '../parser/ast.js';
4
+
5
+ export class TypeScriptCodeGenerator implements CodeGenerator {
6
+ name(): string {
7
+ return 'typescript';
8
+ }
9
+
10
+ generate(actions: ActionScaffold[], machine: MachineDef): string {
11
+ const lines: string[] = [
12
+ `// Generated by Orca`,
13
+ `// Machine: ${machine.name}`,
14
+ '',
15
+ `export interface Context {`,
16
+ ];
17
+
18
+ // Generate context type from machine context
19
+ for (const field of machine.context) {
20
+ if (field.type) {
21
+ lines.push(` ${field.name}: ${field.type};`);
22
+ } else {
23
+ lines.push(` ${field.name}: string | number | boolean;`);
24
+ }
25
+ }
26
+
27
+ lines.push('}');
28
+ lines.push('');
29
+
30
+ // Generate event types
31
+ lines.push(`export type ${machine.name}Event = ${machine.events.map(e => `'${e}'`).join(' | ')};`);
32
+ lines.push('');
33
+
34
+ // Generate action functions
35
+ for (const action of actions) {
36
+ lines.push(this.generateAction(action, machine));
37
+ lines.push('');
38
+ }
39
+
40
+ return lines.join('\n');
41
+ }
42
+
43
+ generateAction(action: ActionScaffold, machine: MachineDef): string {
44
+ const ctxType = 'Context';
45
+
46
+ if (action.hasEffect && action.effectType) {
47
+ return `// Action: ${action.name}
48
+ // Effect: ${action.effectType}
49
+
50
+ export function ${action.name}(ctx: ${ctxType}, event: { type: ${machine.name}Event }): [${ctxType}, Effect<${action.effectType}>] {
51
+ // TODO: Implement action
52
+ return [ctx, { type: '${action.effectType}', payload: {} }];
53
+ }`;
54
+ }
55
+
56
+ return `// Action: ${action.name}
57
+
58
+ export function ${action.name}(ctx: ${ctxType}): ${ctxType} {
59
+ // TODO: Implement action
60
+ return { ...ctx };
61
+ }`;
62
+ }
63
+ }
64
+
65
+ // Register the TypeScript code generator
66
+ import { registerCodeGenerator } from './registry.js';
67
+ registerCodeGenerator('typescript', () => new TypeScriptCodeGenerator());