@styx-api/core 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 (88) hide show
  1. package/dist/index.cjs +7947 -0
  2. package/dist/index.d.cts +1143 -0
  3. package/dist/index.d.cts.map +1 -0
  4. package/dist/index.d.mts +1143 -0
  5. package/dist/index.d.mts.map +1 -0
  6. package/dist/index.mjs +7877 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/package.json +55 -0
  9. package/src/backend/backend.ts +95 -0
  10. package/src/backend/boutiques/boutiques.ts +1049 -0
  11. package/src/backend/boutiques/index.ts +1 -0
  12. package/src/backend/code-builder.ts +49 -0
  13. package/src/backend/collect-field-info.ts +50 -0
  14. package/src/backend/collect-named-types.ts +103 -0
  15. package/src/backend/collect-output-fields.ts +222 -0
  16. package/src/backend/find-doc.ts +38 -0
  17. package/src/backend/find-struct-node.ts +66 -0
  18. package/src/backend/index.ts +39 -0
  19. package/src/backend/python/arg-builder.ts +454 -0
  20. package/src/backend/python/emit.ts +638 -0
  21. package/src/backend/python/index.ts +9 -0
  22. package/src/backend/python/outputs-emit.ts +430 -0
  23. package/src/backend/python/packaging.ts +173 -0
  24. package/src/backend/python/python.ts +558 -0
  25. package/src/backend/python/snippet.ts +84 -0
  26. package/src/backend/python/typemap.ts +131 -0
  27. package/src/backend/python/types.ts +8 -0
  28. package/src/backend/python/validate-emit.ts +356 -0
  29. package/src/backend/resolve-field-binding.ts +41 -0
  30. package/src/backend/resolve-output-tokens.ts +80 -0
  31. package/src/backend/schema/index.ts +2 -0
  32. package/src/backend/schema/jsonschema.ts +303 -0
  33. package/src/backend/scope.ts +50 -0
  34. package/src/backend/sig-entries.ts +97 -0
  35. package/src/backend/snippet-core.ts +185 -0
  36. package/src/backend/string-case.ts +30 -0
  37. package/src/backend/styxdefs-compat.ts +21 -0
  38. package/src/backend/type-keys.ts +52 -0
  39. package/src/backend/typescript/arg-builder.ts +420 -0
  40. package/src/backend/typescript/emit.ts +450 -0
  41. package/src/backend/typescript/index.ts +10 -0
  42. package/src/backend/typescript/outputs-emit.ts +389 -0
  43. package/src/backend/typescript/packaging.ts +130 -0
  44. package/src/backend/typescript/snippet.ts +60 -0
  45. package/src/backend/typescript/typemap.ts +47 -0
  46. package/src/backend/typescript/types.ts +8 -0
  47. package/src/backend/typescript/typescript.ts +507 -0
  48. package/src/backend/typescript/validate-emit.ts +341 -0
  49. package/src/backend/union-variants.ts +42 -0
  50. package/src/backend/validate-walk.ts +111 -0
  51. package/src/bindings/binding.ts +77 -0
  52. package/src/bindings/format.ts +176 -0
  53. package/src/bindings/index.ts +16 -0
  54. package/src/bindings/output-gate.ts +50 -0
  55. package/src/bindings/resolved-output.ts +56 -0
  56. package/src/bindings/types.ts +16 -0
  57. package/src/frontend/argdump/index.ts +1 -0
  58. package/src/frontend/argdump/parser.ts +914 -0
  59. package/src/frontend/boutiques/destruct-template.ts +50 -0
  60. package/src/frontend/boutiques/index.ts +1 -0
  61. package/src/frontend/boutiques/parser.ts +676 -0
  62. package/src/frontend/boutiques/split-command.ts +69 -0
  63. package/src/frontend/detect-format.ts +42 -0
  64. package/src/frontend/frontend.ts +31 -0
  65. package/src/frontend/index.ts +9 -0
  66. package/src/frontend/workbench/index.ts +1 -0
  67. package/src/frontend/workbench/parser.ts +351 -0
  68. package/src/index.ts +41 -0
  69. package/src/ir/builders.ts +69 -0
  70. package/src/ir/format.ts +157 -0
  71. package/src/ir/index.ts +32 -0
  72. package/src/ir/meta.ts +91 -0
  73. package/src/ir/node.ts +95 -0
  74. package/src/ir/passes/canonicalize.ts +108 -0
  75. package/src/ir/passes/flatten.ts +73 -0
  76. package/src/ir/passes/index.ts +7 -0
  77. package/src/ir/passes/pass.ts +86 -0
  78. package/src/ir/passes/pipeline.ts +21 -0
  79. package/src/ir/passes/remove-empty.ts +76 -0
  80. package/src/ir/passes/simplify.ts +179 -0
  81. package/src/ir/types.ts +15 -0
  82. package/src/manifest/context.ts +36 -0
  83. package/src/manifest/index.ts +3 -0
  84. package/src/manifest/types.ts +15 -0
  85. package/src/solver/assign-access.ts +218 -0
  86. package/src/solver/index.ts +4 -0
  87. package/src/solver/resolve-outputs.ts +233 -0
  88. package/src/solver/solver.ts +319 -0
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@styx-api/core",
3
+ "version": "0.1.0",
4
+ "description": "Styx compiler core: parses CLI tool descriptors (e.g. Boutiques), optimizes an IR, solves typed parameter bindings, and generates type-safe wrappers (TypeScript, Python, JSON Schema). Part of the Styx/NiWrap ecosystem.",
5
+ "keywords": [
6
+ "styx",
7
+ "niwrap",
8
+ "boutiques",
9
+ "code-generation",
10
+ "compiler",
11
+ "cli"
12
+ ],
13
+ "license": "MIT",
14
+ "homepage": "https://niwrap.dev/",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/styx-api/styx-ts.git",
18
+ "directory": "packages/core"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/styx-api/styx-ts/issues"
22
+ },
23
+ "type": "module",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.mts",
27
+ "development": "./src/index.ts",
28
+ "import": "./dist/index.mjs",
29
+ "require": "./dist/index.cjs"
30
+ }
31
+ },
32
+ "main": "./dist/index.cjs",
33
+ "module": "./dist/index.mjs",
34
+ "types": "./dist/index.d.mts",
35
+ "files": [
36
+ "dist",
37
+ "src",
38
+ "!src/**/*.test.ts",
39
+ "!src/**/test-helpers.ts"
40
+ ],
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "scripts": {
45
+ "build": "tsdown",
46
+ "dev": "tsdown --watch",
47
+ "prepublishOnly": "tsdown"
48
+ },
49
+ "devDependencies": {
50
+ "@types/node": "^25.0.3",
51
+ "rolldown": "1.0.0-rc.1",
52
+ "styxdefs": "^0.2.0",
53
+ "tsdown": "^0.20.1"
54
+ }
55
+ }
@@ -0,0 +1,95 @@
1
+ import type { BoundType } from "../bindings/index.js";
2
+ import type { AppMeta } from "../ir/index.js";
3
+ import type { CodegenContext, PackageMeta, ProjectMeta } from "../manifest/index.js";
4
+ import type { Scope } from "./scope.js";
5
+
6
+ export interface EmitResult {
7
+ files: Map<string, string>;
8
+ errors: EmitError[];
9
+ warnings: EmitWarning[];
10
+ }
11
+
12
+ export interface EmitError {
13
+ message: string;
14
+ }
15
+
16
+ export interface EmitWarning {
17
+ message: string;
18
+ }
19
+
20
+ /**
21
+ * What the suite-level dispatcher needs to route a config object to one app's
22
+ * dict-style executor, keyed by the root `@type` discriminator.
23
+ */
24
+ export interface AppEntrypoint {
25
+ /** Root `@type` discriminator value (`<package>/<app>`). */
26
+ type: string;
27
+ /**
28
+ * Dict-style execute function name - `<tool>Execute` / `<tool>_execute` for a
29
+ * struct root, `<tool>` for a non-struct root. Takes `(params, runner)`.
30
+ */
31
+ executeFn: string;
32
+ }
33
+
34
+ export interface EmittedApp extends EmitResult {
35
+ meta?: AppMeta;
36
+ /**
37
+ * Dispatch entrypoint, present when the app has a stable `@type` (both an id
38
+ * and a package name are known). Consumed by `emitPackage` to build the
39
+ * suite-level `execute(params, runner)` dispatcher.
40
+ */
41
+ entrypoint?: AppEntrypoint;
42
+ }
43
+
44
+ export interface EmittedPackage extends EmitResult {
45
+ meta?: PackageMeta;
46
+ }
47
+
48
+ /**
49
+ * A code generator for one target language. Implementations emit in up to
50
+ * three tiers; only `emitApp` is mandatory.
51
+ *
52
+ * The CLI's `--mode` flag selects which tiers run: `scripts` = `emitApp` only,
53
+ * `single` = `emitApp` + one `emitPackage`, `multi` = all three tiers.
54
+ *
55
+ * Paths in returned file maps are relative to the emit tier's natural root
56
+ * (package directory for app/package emit, project root for project emit).
57
+ * Orchestration is responsible for prefixing/merging the maps.
58
+ */
59
+ export interface Backend {
60
+ readonly name: string;
61
+ readonly target: string;
62
+ /**
63
+ * Emit the per-tool file(s) for one app. Mandatory.
64
+ *
65
+ * When emitting many tools into one suite barrel, pass a `scope` shared across
66
+ * the package (from `newPackageScope`) so emitted top-level names stay unique
67
+ * across tools - a flat `export *` / `from .x import *` re-export otherwise
68
+ * collides same-named types. Omit it for standalone single-tool emission.
69
+ */
70
+ emitApp(ctx: CodegenContext, scope?: Scope): EmittedApp;
71
+ /**
72
+ * Create a fresh symbol scope seeded with this backend's reserved words, to be
73
+ * shared across all `emitApp` calls for one package. Optional; callers fall
74
+ * back to per-tool scoping (still safe via name prefixing) when absent.
75
+ */
76
+ newPackageScope?(): Scope;
77
+ /**
78
+ * Emit suite-level files for a package containing many apps (e.g. the
79
+ * `__init__.py` re-exporting `from .bet import *` per tool, or an
80
+ * `index.ts` doing `export * from "./bet.js"`). Optional; defaulted to
81
+ * no-op by callers when absent.
82
+ */
83
+ emitPackage?(pkg: PackageMeta, apps: EmittedApp[]): EmittedPackage;
84
+ /**
85
+ * Emit project-level artifacts spanning many packages (e.g. root
86
+ * `pyproject.toml`, top-level `__init__.py`, runner helpers).
87
+ * Wired up by Plan 2's CLI catalog mode; backends opt in as needed.
88
+ */
89
+ emitProject?(proj: ProjectMeta, packages: EmittedPackage[]): EmitResult;
90
+ }
91
+
92
+ export interface TypeMap {
93
+ map(type: BoundType): string;
94
+ imports(type: BoundType): string[];
95
+ }