@elaraai/e3-cli 0.0.1-alpha.2
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.
- package/LICENSE.md +50 -0
- package/README.md +121 -0
- package/dist/src/cli-test-helpers.d.ts +17 -0
- package/dist/src/cli-test-helpers.d.ts.map +1 -0
- package/dist/src/cli-test-helpers.js +48 -0
- package/dist/src/cli-test-helpers.js.map +1 -0
- package/dist/src/cli.d.ts +7 -0
- package/dist/src/cli.d.ts.map +1 -0
- package/dist/src/cli.js +144 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/commands/convert.d.ts +11 -0
- package/dist/src/commands/convert.d.ts.map +1 -0
- package/dist/src/commands/convert.impl.d.ts +31 -0
- package/dist/src/commands/convert.impl.d.ts.map +1 -0
- package/dist/src/commands/convert.impl.js +197 -0
- package/dist/src/commands/convert.impl.js.map +1 -0
- package/dist/src/commands/convert.js +11 -0
- package/dist/src/commands/convert.js.map +1 -0
- package/dist/src/commands/gc.d.ts +12 -0
- package/dist/src/commands/gc.d.ts.map +1 -0
- package/dist/src/commands/gc.js +44 -0
- package/dist/src/commands/gc.js.map +1 -0
- package/dist/src/commands/get.d.ts +11 -0
- package/dist/src/commands/get.d.ts.map +1 -0
- package/dist/src/commands/get.js +60 -0
- package/dist/src/commands/get.js.map +1 -0
- package/dist/src/commands/init.d.ts +9 -0
- package/dist/src/commands/init.d.ts.map +1 -0
- package/dist/src/commands/init.js +33 -0
- package/dist/src/commands/init.js.map +1 -0
- package/dist/src/commands/list.d.ts +9 -0
- package/dist/src/commands/list.d.ts.map +1 -0
- package/dist/src/commands/list.js +54 -0
- package/dist/src/commands/list.js.map +1 -0
- package/dist/src/commands/logs.d.ts +11 -0
- package/dist/src/commands/logs.d.ts.map +1 -0
- package/dist/src/commands/logs.js +179 -0
- package/dist/src/commands/logs.js.map +1 -0
- package/dist/src/commands/package.d.ts +23 -0
- package/dist/src/commands/package.d.ts.map +1 -0
- package/dist/src/commands/package.js +78 -0
- package/dist/src/commands/package.js.map +1 -0
- package/dist/src/commands/run.d.ts +12 -0
- package/dist/src/commands/run.d.ts.map +1 -0
- package/dist/src/commands/run.js +99 -0
- package/dist/src/commands/run.js.map +1 -0
- package/dist/src/commands/set.d.ts +11 -0
- package/dist/src/commands/set.d.ts.map +1 -0
- package/dist/src/commands/set.js +129 -0
- package/dist/src/commands/set.js.map +1 -0
- package/dist/src/commands/start.d.ts +13 -0
- package/dist/src/commands/start.d.ts.map +1 -0
- package/dist/src/commands/start.js +111 -0
- package/dist/src/commands/start.js.map +1 -0
- package/dist/src/commands/status.d.ts +9 -0
- package/dist/src/commands/status.d.ts.map +1 -0
- package/dist/src/commands/status.js +157 -0
- package/dist/src/commands/status.js.map +1 -0
- package/dist/src/commands/workspace.d.ts +30 -0
- package/dist/src/commands/workspace.d.ts.map +1 -0
- package/dist/src/commands/workspace.js +106 -0
- package/dist/src/commands/workspace.js.map +1 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +6 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/utils.d.ts +28 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +45 -0
- package/dist/src/utils.js.map +1 -0
- package/package.json +50 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Business Source License 1.1
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Elara AI Pty Ltd
|
|
4
|
+
|
|
5
|
+
## License
|
|
6
|
+
|
|
7
|
+
**Licensor:** Elara AI Pty Ltd
|
|
8
|
+
|
|
9
|
+
**Licensed Work:** @elaraai/e3-cli
|
|
10
|
+
|
|
11
|
+
**Change Date:** Four years from the date of each release
|
|
12
|
+
|
|
13
|
+
**Change License:** AGPL-3.0
|
|
14
|
+
|
|
15
|
+
## Terms
|
|
16
|
+
|
|
17
|
+
The Licensed Work is provided under the terms of the Business Source License 1.1 as detailed below.
|
|
18
|
+
|
|
19
|
+
### Grant of Rights
|
|
20
|
+
|
|
21
|
+
The Licensor grants you the right to copy, modify, create derivative works, redistribute, and make non-production use of the Licensed Work.
|
|
22
|
+
|
|
23
|
+
### Production Use Limitation
|
|
24
|
+
|
|
25
|
+
**"Production Use"** means any use by or on behalf of a for-profit entity, other than for evaluation, testing, or development purposes.
|
|
26
|
+
|
|
27
|
+
Production Use requires a separate commercial license from the Licensor.
|
|
28
|
+
|
|
29
|
+
### Change Date
|
|
30
|
+
|
|
31
|
+
On the Change Date (four years after each release), the Licensed Work will be made available under the Change License (AGPL-3.0).
|
|
32
|
+
|
|
33
|
+
### No Warranty
|
|
34
|
+
|
|
35
|
+
THE LICENSED WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. THE LICENSOR DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
36
|
+
|
|
37
|
+
## Commercial Licensing
|
|
38
|
+
|
|
39
|
+
To obtain a commercial license for Production Use, contact:
|
|
40
|
+
|
|
41
|
+
**Email:** support@elara.ai
|
|
42
|
+
**Website:** https://elaraai.com
|
|
43
|
+
|
|
44
|
+
## Governing Law
|
|
45
|
+
|
|
46
|
+
This license is governed by the laws of New South Wales, Australia.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
*Elara AI Pty Ltd*
|
package/README.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# @elaraai/e3-cli
|
|
2
|
+
|
|
3
|
+
Command-line interface for e3 (East Execution Engine).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @elaraai/e3-cli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Commands
|
|
12
|
+
|
|
13
|
+
### Repository
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
e3 init <repo> # Initialize a new repository
|
|
17
|
+
e3 status <repo> # Show repository status
|
|
18
|
+
e3 gc <repo> [--dry-run] # Remove unreferenced objects
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Packages
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
e3 package import <repo> <zip> # Import package from .zip
|
|
25
|
+
e3 package export <repo> <pkg> <zip> # Export package to .zip
|
|
26
|
+
e3 package list <repo> # List installed packages
|
|
27
|
+
e3 package remove <repo> <pkg> # Remove a package
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Workspaces
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
e3 workspace create <repo> <name> # Create empty workspace
|
|
34
|
+
e3 workspace deploy <repo> <ws> <pkg> # Deploy package to workspace
|
|
35
|
+
e3 workspace export <repo> <ws> <zip> # Export workspace as package
|
|
36
|
+
e3 workspace list <repo> # List workspaces
|
|
37
|
+
e3 workspace remove <repo> <ws> # Remove workspace
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Data
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
e3 list <repo> [path] # List workspaces or tree contents
|
|
44
|
+
e3 get <repo> <path> [-f format] # Get dataset value (east/json/beast2)
|
|
45
|
+
e3 set <repo> <path> <file> # Set dataset value from file
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Execution
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
e3 run <repo> <task> [inputs...] # Run task ad-hoc
|
|
52
|
+
e3 start <repo> <ws> # Execute tasks in workspace
|
|
53
|
+
e3 logs <repo> <path> [--follow] # View task logs
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Utilities
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
e3 convert [input] --to <format> # Convert between .east/.json/.beast2
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Example
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
# Initialize repository and import a package
|
|
66
|
+
e3 init ./my-project
|
|
67
|
+
e3 package import ./my-project ./greeting-pkg-1.0.0.zip
|
|
68
|
+
|
|
69
|
+
# Create workspace and deploy package
|
|
70
|
+
e3 workspace create ./my-project dev
|
|
71
|
+
e3 workspace deploy ./my-project dev greeting-pkg@1.0.0
|
|
72
|
+
|
|
73
|
+
# Set input and run
|
|
74
|
+
e3 set ./my-project dev.inputs.name ./name.east
|
|
75
|
+
e3 start ./my-project dev
|
|
76
|
+
|
|
77
|
+
# Get results
|
|
78
|
+
e3 get ./my-project dev.tasks.shout.output
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## License
|
|
82
|
+
|
|
83
|
+
BSL 1.1. See [LICENSE.md](./LICENSE.md).
|
|
84
|
+
|
|
85
|
+
### Ecosystem
|
|
86
|
+
|
|
87
|
+
- **[East Node](https://github.com/elaraai/east-node)**: Node.js platform functions for I/O, databases, and system operations. Connect East programs to filesystems, SQL/NoSQL databases, cloud storage, and network services.
|
|
88
|
+
- [@elaraai/east-node-std](https://www.npmjs.com/package/@elaraai/east-node-std): Filesystem, console, HTTP fetch, crypto, random distributions, timestamps
|
|
89
|
+
- [@elaraai/east-node-io](https://www.npmjs.com/package/@elaraai/east-node-io): SQLite, PostgreSQL, MySQL, MongoDB, S3, FTP, SFTP
|
|
90
|
+
- [@elaraai/east-node-cli](https://www.npmjs.com/package/@elaraai/east-node-cli): CLI for running East IR programs in Node.js
|
|
91
|
+
|
|
92
|
+
- **[East Python](https://github.com/elaraai/east-py)**: Python runtime and platform functions for data science and machine learning. Execute East programs with access to optimization solvers, gradient boosting, neural networks, and model explainability.
|
|
93
|
+
- [@elaraai/east-py-datascience](https://www.npmjs.com/package/@elaraai/east-py-datascience): TypeScript types for optimization, gradient boosting, neural networks, explainability
|
|
94
|
+
|
|
95
|
+
- **[East UI](https://github.com/elaraai/east-ui)**: East types and expressions for building dashboards and interactive layouts. Define UIs as data structures that render consistently across React, web, and other environments.
|
|
96
|
+
- [@elaraai/east-ui](https://www.npmjs.com/package/@elaraai/east-ui): 50+ typed UI components for layouts, forms, charts, tables, dialogs
|
|
97
|
+
- [@elaraai/east-ui-components](https://www.npmjs.com/package/@elaraai/east-ui-components): React renderer with Chakra UI styling
|
|
98
|
+
|
|
99
|
+
- **[e3 - East Execution Engine](https://github.com/elaraai/e3)**: Durable execution engine for running East pipelines at scale. Features Git-like content-addressable storage, automatic memoization, task queuing, and real-time monitoring.
|
|
100
|
+
- [@elaraai/e3](https://www.npmjs.com/package/@elaraai/e3): SDK for authoring e3 packages with typed tasks and pipelines
|
|
101
|
+
- [@elaraai/e3-core](https://www.npmjs.com/package/@elaraai/e3-core): Git-like object store, task queue, result caching
|
|
102
|
+
- [@elaraai/e3-types](https://www.npmjs.com/package/@elaraai/e3-types): Shared type definitions for e3 packages
|
|
103
|
+
- [@elaraai/e3-cli](https://www.npmjs.com/package/@elaraai/e3-cli): `e3 init`, `e3 run`, `e3 logs` commands for managing and monitoring tasks
|
|
104
|
+
- [@elaraai/e3-api-client](https://www.npmjs.com/package/@elaraai/e3-api-client): HTTP client for remote e3 servers
|
|
105
|
+
- [@elaraai/e3-api-server](https://www.npmjs.com/package/@elaraai/e3-api-server): REST API server for e3 repositories
|
|
106
|
+
|
|
107
|
+
## Links
|
|
108
|
+
|
|
109
|
+
- [East Language](https://github.com/elaraai/east)
|
|
110
|
+
- [East Python Runtime](https://github.com/elaraai/east-py)
|
|
111
|
+
- [Elara AI](https://elaraai.com/)
|
|
112
|
+
- [Issues](https://github.com/elaraai/e3/issues)
|
|
113
|
+
- support@elara.ai
|
|
114
|
+
|
|
115
|
+
## About Elara
|
|
116
|
+
|
|
117
|
+
East is developed by [Elara AI Pty Ltd](https://elaraai.com/), an AI-powered platform that creates economic digital twins of businesses that optimize performance. Elara combines business objectives, decisions and data to help organizations make data-driven decisions across operations, purchasing, sales and customer engagement, and project and investment planning. East powers the computational layer of Elara solutions, enabling the expression of complex business logic and data in a simple, type-safe and portable language.
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
*Developed by [Elara AI Pty Ltd](https://elaraai.com/)*
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Create a temporary directory for CLI testing
|
|
7
|
+
*/
|
|
8
|
+
export declare function createTestDir(): string;
|
|
9
|
+
/**
|
|
10
|
+
* Remove a temporary test directory
|
|
11
|
+
*/
|
|
12
|
+
export declare function removeTestDir(testDir: string): void;
|
|
13
|
+
/**
|
|
14
|
+
* Write a test file to the test directory
|
|
15
|
+
*/
|
|
16
|
+
export declare function writeTestFile(testDir: string, filename: string, content: string | Buffer): string;
|
|
17
|
+
//# sourceMappingURL=cli-test-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-test-helpers.d.ts","sourceRoot":"","sources":["../../src/cli-test-helpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAqBH;;GAEG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAKtC;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAMnD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GAAG,MAAM,GACvB,MAAM,CAIR"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Test helpers for CLI command testing
|
|
7
|
+
*
|
|
8
|
+
* Provides utilities for:
|
|
9
|
+
* - Creating temporary test directories
|
|
10
|
+
* - Writing test input files
|
|
11
|
+
* - Cleaning up after tests
|
|
12
|
+
*/
|
|
13
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
import { tmpdir } from 'node:os';
|
|
16
|
+
import { writeFileSync } from 'node:fs';
|
|
17
|
+
/**
|
|
18
|
+
* Track parent temp directories for cleanup
|
|
19
|
+
*/
|
|
20
|
+
const tempDirParents = new Map();
|
|
21
|
+
/**
|
|
22
|
+
* Create a temporary directory for CLI testing
|
|
23
|
+
*/
|
|
24
|
+
export function createTestDir() {
|
|
25
|
+
const parentDir = mkdtempSync(join(tmpdir(), 'e3-cli-test-'));
|
|
26
|
+
const testDir = join(parentDir, 'test');
|
|
27
|
+
tempDirParents.set(testDir, parentDir);
|
|
28
|
+
return testDir;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Remove a temporary test directory
|
|
32
|
+
*/
|
|
33
|
+
export function removeTestDir(testDir) {
|
|
34
|
+
const parentDir = tempDirParents.get(testDir);
|
|
35
|
+
if (parentDir) {
|
|
36
|
+
rmSync(parentDir, { recursive: true, force: true });
|
|
37
|
+
tempDirParents.delete(testDir);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Write a test file to the test directory
|
|
42
|
+
*/
|
|
43
|
+
export function writeTestFile(testDir, filename, content) {
|
|
44
|
+
const filePath = join(testDir, filename);
|
|
45
|
+
writeFileSync(filePath, content);
|
|
46
|
+
return filePath;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=cli-test-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-test-helpers.js","sourceRoot":"","sources":["../../src/cli-test-helpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC;;GAEG;AACH,MAAM,cAAc,GAAG,IAAI,GAAG,EAAkB,CAAC;AAEjD;;GAEG;AACH,MAAM,UAAU,aAAa;IAC3B,MAAM,SAAS,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,cAAc,CAAC,CAAC,CAAC;IAC9D,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IACxC,cAAc,CAAC,GAAG,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IACvC,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,OAAe;IAC3C,MAAM,SAAS,GAAG,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC9C,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACpD,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAC3B,OAAe,EACf,QAAgB,EAChB,OAAwB;IAExB,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACzC,aAAa,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACjC,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";AAEA;;;GAGG"}
|
package/dist/src/cli.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
#!/usr/bin/env -S node --stack-size=8192
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
4
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* e3 CLI - East Execution Engine command-line interface
|
|
8
|
+
*
|
|
9
|
+
* All commands take a repository path as the first argument (`.` for current directory).
|
|
10
|
+
*/
|
|
11
|
+
import { Command } from 'commander';
|
|
12
|
+
import { initCommand } from './commands/init.js';
|
|
13
|
+
import { packageCommand } from './commands/package.js';
|
|
14
|
+
import { workspaceCommand } from './commands/workspace.js';
|
|
15
|
+
import { listCommand } from './commands/list.js';
|
|
16
|
+
import { getCommand } from './commands/get.js';
|
|
17
|
+
import { setCommand } from './commands/set.js';
|
|
18
|
+
import { startCommand } from './commands/start.js';
|
|
19
|
+
import { runCommand } from './commands/run.js';
|
|
20
|
+
import { logsCommand } from './commands/logs.js';
|
|
21
|
+
import { statusCommand } from './commands/status.js';
|
|
22
|
+
import { gcCommand } from './commands/gc.js';
|
|
23
|
+
import { convertCommand } from './commands/convert.js';
|
|
24
|
+
const program = new Command();
|
|
25
|
+
program
|
|
26
|
+
.name('e3')
|
|
27
|
+
.description('East Execution Engine - Execute tasks across multiple runtimes')
|
|
28
|
+
.version('0.0.1-alpha.0');
|
|
29
|
+
// Repository commands
|
|
30
|
+
program
|
|
31
|
+
.command('init <repo>')
|
|
32
|
+
.description('Initialize a new e3 repository')
|
|
33
|
+
.action(initCommand);
|
|
34
|
+
program
|
|
35
|
+
.command('status <repo> [workspace]')
|
|
36
|
+
.description('Show repository status, or detailed workspace status if workspace provided')
|
|
37
|
+
.action(statusCommand);
|
|
38
|
+
program
|
|
39
|
+
.command('gc <repo>')
|
|
40
|
+
.description('Remove unreferenced objects')
|
|
41
|
+
.option('--dry-run', 'Report what would be deleted without deleting')
|
|
42
|
+
.option('--min-age <ms>', 'Minimum file age in ms before deletion', '60000')
|
|
43
|
+
.action(gcCommand);
|
|
44
|
+
// Package commands
|
|
45
|
+
program
|
|
46
|
+
.command('package')
|
|
47
|
+
.description('Package operations')
|
|
48
|
+
.addCommand(new Command('import')
|
|
49
|
+
.description('Import package from .zip file')
|
|
50
|
+
.argument('<repo>', 'Repository path')
|
|
51
|
+
.argument('<zipPath>', 'Path to .zip file')
|
|
52
|
+
.action(packageCommand.import))
|
|
53
|
+
.addCommand(new Command('export')
|
|
54
|
+
.description('Export package to .zip file')
|
|
55
|
+
.argument('<repo>', 'Repository path')
|
|
56
|
+
.argument('<pkg>', 'Package name[@version]')
|
|
57
|
+
.argument('<zipPath>', 'Output .zip path')
|
|
58
|
+
.action(packageCommand.export))
|
|
59
|
+
.addCommand(new Command('list')
|
|
60
|
+
.description('List installed packages')
|
|
61
|
+
.argument('<repo>', 'Repository path')
|
|
62
|
+
.action(packageCommand.list))
|
|
63
|
+
.addCommand(new Command('remove')
|
|
64
|
+
.description('Remove a package')
|
|
65
|
+
.argument('<repo>', 'Repository path')
|
|
66
|
+
.argument('<pkg>', 'Package name[@version]')
|
|
67
|
+
.action(packageCommand.remove));
|
|
68
|
+
// Workspace commands
|
|
69
|
+
program
|
|
70
|
+
.command('workspace')
|
|
71
|
+
.description('Workspace operations')
|
|
72
|
+
.addCommand(new Command('create')
|
|
73
|
+
.description('Create an empty workspace')
|
|
74
|
+
.argument('<repo>', 'Repository path')
|
|
75
|
+
.argument('<name>', 'Workspace name')
|
|
76
|
+
.action(workspaceCommand.create))
|
|
77
|
+
.addCommand(new Command('deploy')
|
|
78
|
+
.description('Deploy a package to a workspace')
|
|
79
|
+
.argument('<repo>', 'Repository path')
|
|
80
|
+
.argument('<ws>', 'Workspace name')
|
|
81
|
+
.argument('<pkg>', 'Package name[@version]')
|
|
82
|
+
.action(workspaceCommand.deploy))
|
|
83
|
+
.addCommand(new Command('export')
|
|
84
|
+
.description('Export workspace as a package')
|
|
85
|
+
.argument('<repo>', 'Repository path')
|
|
86
|
+
.argument('<ws>', 'Workspace name')
|
|
87
|
+
.argument('<zipPath>', 'Output .zip path')
|
|
88
|
+
.option('--name <name>', 'Package name (default: deployed package name)')
|
|
89
|
+
.option('--version <version>', 'Package version (default: auto-generated)')
|
|
90
|
+
.action(workspaceCommand.export))
|
|
91
|
+
.addCommand(new Command('list')
|
|
92
|
+
.description('List workspaces')
|
|
93
|
+
.argument('<repo>', 'Repository path')
|
|
94
|
+
.action(workspaceCommand.list))
|
|
95
|
+
.addCommand(new Command('remove')
|
|
96
|
+
.description('Remove a workspace')
|
|
97
|
+
.argument('<repo>', 'Repository path')
|
|
98
|
+
.argument('<ws>', 'Workspace name')
|
|
99
|
+
.action(workspaceCommand.remove));
|
|
100
|
+
// Dataset commands
|
|
101
|
+
program
|
|
102
|
+
.command('list <repo> [path]')
|
|
103
|
+
.description('List workspaces or tree contents at path (ws.path.to.tree)')
|
|
104
|
+
.action(listCommand);
|
|
105
|
+
program
|
|
106
|
+
.command('get <repo> <path>')
|
|
107
|
+
.description('Get dataset value at path (ws.path.to.dataset)')
|
|
108
|
+
.option('-f, --format <format>', 'Output format: east, json, beast2', 'east')
|
|
109
|
+
.action(getCommand);
|
|
110
|
+
program
|
|
111
|
+
.command('set <repo> <path> <file>')
|
|
112
|
+
.description('Set dataset value from file (ws.path.to.dataset)')
|
|
113
|
+
.option('--type <typespec>', 'Type specification in .east format (required for .json/.csv files)')
|
|
114
|
+
.action(setCommand);
|
|
115
|
+
// Execution commands
|
|
116
|
+
program
|
|
117
|
+
.command('run <repo> <task> [inputs...]')
|
|
118
|
+
.description('Run task ad-hoc (task format: pkg/task or pkg@version/task)')
|
|
119
|
+
.option('-o, --output <path>', 'Output file path')
|
|
120
|
+
.option('--force', 'Force re-execution even if cached')
|
|
121
|
+
.action(runCommand);
|
|
122
|
+
program
|
|
123
|
+
.command('start <repo> <ws>')
|
|
124
|
+
.description('Execute tasks in a workspace')
|
|
125
|
+
.option('--filter <pattern>', 'Only run tasks matching pattern')
|
|
126
|
+
.option('--concurrency <n>', 'Max concurrent tasks', '4')
|
|
127
|
+
.option('--force', 'Force re-execution even if cached')
|
|
128
|
+
.action(startCommand);
|
|
129
|
+
program
|
|
130
|
+
.command('logs <repo> <path>')
|
|
131
|
+
.description('View task logs (path format: ws or ws.taskName)')
|
|
132
|
+
.option('--follow', 'Follow log output')
|
|
133
|
+
.action(logsCommand);
|
|
134
|
+
// Utility commands
|
|
135
|
+
program
|
|
136
|
+
.command('convert [input]')
|
|
137
|
+
.description('Convert between .east, .json, and .beast2 formats')
|
|
138
|
+
.option('--from <format>', 'Input format: east, json, beast2 (default: auto-detect)')
|
|
139
|
+
.option('--to <format>', 'Output format: east, json, beast2', 'east')
|
|
140
|
+
.option('-o, --output <path>', 'Output file path (default: stdout)')
|
|
141
|
+
.option('--type <typespec>', 'Type specification in .east format')
|
|
142
|
+
.action(convertCommand);
|
|
143
|
+
program.parse();
|
|
144
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";AAEA;;;GAGG;AAEH;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C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AEtB,OAAO;KACJ,OAAO,CAAC,mBAAmB,CAAC;KAC5B,WAAW,CAAC,8BAA8B,CAAC;KAC3C,MAAM,CAAC,oBAAoB,EAAE,iCAAiC,CAAC;KAC/D,MAAM,CAAC,mBAAmB,EAAE,sBAAsB,EAAE,GAAG,CAAC;KACxD,MAAM,CAAC,SAAS,EAAE,mCAAmC,CAAC;KACtD,MAAM,CAAC,YAAY,CAAC,CAAC;AAExB,OAAO;KACJ,OAAO,CAAC,oBAAoB,CAAC;KAC7B,WAAW,CAAC,iDAAiD,CAAC;KAC9D,MAAM,CAAC,UAAU,EAAE,mBAAmB,CAAC;KACvC,MAAM,CAAC,WAAW,CAAC,CAAC;AAEvB,mBAAmB;AACnB,OAAO;KACJ,OAAO,CAAC,iBAAiB,CAAC;KAC1B,WAAW,CAAC,mDAAmD,CAAC;KAChE,MAAM,CAAC,iBAAiB,EAAE,yDAAyD,CAAC;KACpF,MAAM,CAAC,eAAe,EAAE,mCAAmC,EAAE,MAAM,CAAC;KACpE,MAAM,CAAC,qBAAqB,EAAE,oCAAoC,CAAC;KACnE,MAAM,CAAC,mBAAmB,EAAE,oCAAoC,CAAC;KACjE,MAAM,CAAC,cAAc,CAAC,CAAC;AAE1B,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* e3 convert command - Transform data between .east, .json, and .beast2 formats
|
|
7
|
+
*
|
|
8
|
+
* Re-exports the existing convert logic.
|
|
9
|
+
*/
|
|
10
|
+
export { convertFile as convertCommand } from './convert.impl.js';
|
|
11
|
+
//# sourceMappingURL=convert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../../src/commands/convert.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AAEH,OAAO,EAAE,WAAW,IAAI,cAAc,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Output format type (type is output-only)
|
|
7
|
+
*/
|
|
8
|
+
export type ConvertFormat = 'east' | 'json' | 'beast2' | 'type';
|
|
9
|
+
/**
|
|
10
|
+
* Input format type (no 'type' as input)
|
|
11
|
+
*/
|
|
12
|
+
export type InputFormat = 'east' | 'json' | 'beast2';
|
|
13
|
+
/**
|
|
14
|
+
* Conversion result
|
|
15
|
+
*/
|
|
16
|
+
export interface ConvertResult {
|
|
17
|
+
success: boolean;
|
|
18
|
+
data?: string | Buffer;
|
|
19
|
+
format?: ConvertFormat;
|
|
20
|
+
error?: Error;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Core logic for converting between formats
|
|
24
|
+
* Supports .beast2 (self-describing), .east (with parseInferred or --type), .json (with --type), and stdin
|
|
25
|
+
*/
|
|
26
|
+
export declare function convertCore(inputPath: string | null, toFormat: ConvertFormat, outputPath?: string, typeSpec?: string, fromFormat?: InputFormat): Promise<ConvertResult>;
|
|
27
|
+
/**
|
|
28
|
+
* CLI handler for the convert command
|
|
29
|
+
*/
|
|
30
|
+
export declare function convertFile(inputPath: string | undefined, toFormat?: ConvertFormat, outputPath?: string, typeSpec?: string, fromFormat?: InputFormat): Promise<void>;
|
|
31
|
+
//# sourceMappingURL=convert.impl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.impl.d.ts","sourceRoot":"","sources":["../../../src/commands/convert.impl.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAkBH;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;AAEhE;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAcD;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,QAAQ,EAAE,aAAa,EACvB,UAAU,CAAC,EAAE,MAAM,EACnB,QAAQ,CAAC,EAAE,MAAM,EACjB,UAAU,CAAC,EAAE,WAAW,GACvB,OAAO,CAAC,aAAa,CAAC,CAmJxB;AAED;;GAEG;AACH,wBAAsB,WAAW,CAC/B,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,QAAQ,GAAE,aAAsB,EAChC,UAAU,CAAC,EAAE,MAAM,EACnB,QAAQ,CAAC,EAAE,MAAM,EACjB,UAAU,CAAC,EAAE,WAAW,GACvB,OAAO,CAAC,IAAI,CAAC,CAmBf"}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* e3 convert command - Transform data between .east, .json, and .beast2 formats
|
|
7
|
+
*/
|
|
8
|
+
import * as fs from 'fs/promises';
|
|
9
|
+
import { decodeBeast2, printFor, toJSONFor, parseFor, fromJSONFor, encodeBeast2For, parseInferred, printType, } from '@elaraai/east';
|
|
10
|
+
/**
|
|
11
|
+
* Detect format from file extension
|
|
12
|
+
*/
|
|
13
|
+
function detectFormat(filePath) {
|
|
14
|
+
const ext = filePath.slice(filePath.lastIndexOf('.'));
|
|
15
|
+
if (ext === '.east')
|
|
16
|
+
return 'east';
|
|
17
|
+
if (ext === '.json')
|
|
18
|
+
return 'json';
|
|
19
|
+
if (ext === '.beast2')
|
|
20
|
+
return 'beast2';
|
|
21
|
+
throw new Error(`Cannot detect format from extension: ${ext} (expected .east, .json, or .beast2)`);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Core logic for converting between formats
|
|
25
|
+
* Supports .beast2 (self-describing), .east (with parseInferred or --type), .json (with --type), and stdin
|
|
26
|
+
*/
|
|
27
|
+
export async function convertCore(inputPath, toFormat, outputPath, typeSpec, fromFormat) {
|
|
28
|
+
try {
|
|
29
|
+
let type;
|
|
30
|
+
let value;
|
|
31
|
+
let detectedFormat;
|
|
32
|
+
// Read input data
|
|
33
|
+
let inputData;
|
|
34
|
+
if (inputPath === null) {
|
|
35
|
+
// Read from stdin
|
|
36
|
+
const chunks = [];
|
|
37
|
+
for await (const chunk of process.stdin) {
|
|
38
|
+
chunks.push(chunk);
|
|
39
|
+
}
|
|
40
|
+
inputData = Buffer.concat(chunks);
|
|
41
|
+
// Detect format if not explicitly specified
|
|
42
|
+
if (fromFormat) {
|
|
43
|
+
detectedFormat = fromFormat;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
// Try to detect format from content
|
|
47
|
+
if (inputData.length > 0 && inputData[0] === 0x42) {
|
|
48
|
+
// Beast2 files typically start with 'B' (0x42) magic byte
|
|
49
|
+
detectedFormat = 'beast2';
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
// Assume text format - default to .east unless explicitly JSON-like
|
|
53
|
+
const content = inputData.toString('utf-8').trim();
|
|
54
|
+
// Only treat as JSON if it looks like a JSON object with quotes around keys
|
|
55
|
+
if (content.startsWith('{') && content.includes('"')) {
|
|
56
|
+
detectedFormat = 'json';
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
// Default to .east (handles arrays, structs, primitives, etc.)
|
|
60
|
+
detectedFormat = 'east';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
// Read from file
|
|
67
|
+
inputData = await fs.readFile(inputPath);
|
|
68
|
+
// Use explicit format if provided, otherwise detect from extension
|
|
69
|
+
if (fromFormat) {
|
|
70
|
+
detectedFormat = fromFormat;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
detectedFormat = detectFormat(inputPath);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// Parse type specification if provided (in .east format)
|
|
77
|
+
let providedType;
|
|
78
|
+
if (typeSpec) {
|
|
79
|
+
const [parsedType, _] = parseInferred(typeSpec);
|
|
80
|
+
providedType = parsedType;
|
|
81
|
+
}
|
|
82
|
+
// Decode input based on format
|
|
83
|
+
if (detectedFormat === 'beast2') {
|
|
84
|
+
// Beast2 is self-describing
|
|
85
|
+
const decoded = decodeBeast2(inputData);
|
|
86
|
+
type = decoded.type;
|
|
87
|
+
value = decoded.value;
|
|
88
|
+
}
|
|
89
|
+
else if (detectedFormat === 'east') {
|
|
90
|
+
// For .east, try parseInferred first, then use providedType
|
|
91
|
+
const content = inputData.toString('utf-8');
|
|
92
|
+
if (providedType) {
|
|
93
|
+
// Use provided type
|
|
94
|
+
const parser = parseFor(providedType);
|
|
95
|
+
const result = parser(content);
|
|
96
|
+
if (!result.success) {
|
|
97
|
+
throw new Error(`Failed to parse .east with provided type: ${result.error}`);
|
|
98
|
+
}
|
|
99
|
+
type = providedType;
|
|
100
|
+
value = result.value;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
// Use parseInferred
|
|
104
|
+
const [parsedType, parsedValue] = parseInferred(content);
|
|
105
|
+
type = parsedType;
|
|
106
|
+
value = parsedValue;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
// JSON format - requires type
|
|
111
|
+
if (!providedType) {
|
|
112
|
+
throw new Error('JSON format requires --type to be specified');
|
|
113
|
+
}
|
|
114
|
+
const content = inputData.toString('utf-8');
|
|
115
|
+
const jsonValue = JSON.parse(content);
|
|
116
|
+
const fromJSON = fromJSONFor(providedType);
|
|
117
|
+
type = providedType;
|
|
118
|
+
value = fromJSON(jsonValue);
|
|
119
|
+
}
|
|
120
|
+
// If already in target format and no output path, just return
|
|
121
|
+
// (but not if outputting type, which is always computed)
|
|
122
|
+
if (detectedFormat === toFormat && !outputPath && inputPath !== null) {
|
|
123
|
+
return {
|
|
124
|
+
success: true,
|
|
125
|
+
data: inputData,
|
|
126
|
+
format: toFormat,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
// Encode to target format
|
|
130
|
+
let outputData;
|
|
131
|
+
if (toFormat === 'type') {
|
|
132
|
+
// Output the type instead of the value (always in .east format)
|
|
133
|
+
const typeString = printType(type);
|
|
134
|
+
outputData = typeString;
|
|
135
|
+
}
|
|
136
|
+
else if (toFormat === 'east') {
|
|
137
|
+
const printer = printFor(type);
|
|
138
|
+
outputData = printer(value);
|
|
139
|
+
}
|
|
140
|
+
else if (toFormat === 'json') {
|
|
141
|
+
const toJSON = toJSONFor(type);
|
|
142
|
+
const jsonResult = toJSON(value);
|
|
143
|
+
outputData = JSON.stringify(jsonResult, null, 2);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
// beast2
|
|
147
|
+
const encoder = encodeBeast2For(type);
|
|
148
|
+
outputData = Buffer.from(encoder(value));
|
|
149
|
+
}
|
|
150
|
+
// Write to output file if specified
|
|
151
|
+
if (outputPath) {
|
|
152
|
+
if (outputData instanceof Buffer) {
|
|
153
|
+
await fs.writeFile(outputPath, outputData);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
await fs.writeFile(outputPath, outputData, 'utf-8');
|
|
157
|
+
}
|
|
158
|
+
return {
|
|
159
|
+
success: true,
|
|
160
|
+
format: toFormat,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
success: true,
|
|
165
|
+
data: outputData,
|
|
166
|
+
format: toFormat,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
return {
|
|
171
|
+
success: false,
|
|
172
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* CLI handler for the convert command
|
|
178
|
+
*/
|
|
179
|
+
export async function convertFile(inputPath, toFormat = 'east', outputPath, typeSpec, fromFormat) {
|
|
180
|
+
// If no input path, use stdin
|
|
181
|
+
const actualInputPath = inputPath === undefined || inputPath === '-' ? null : inputPath;
|
|
182
|
+
const result = await convertCore(actualInputPath, toFormat, outputPath, typeSpec, fromFormat);
|
|
183
|
+
if (!result.success) {
|
|
184
|
+
console.error(`Error: Failed to convert: ${result.error?.message}`);
|
|
185
|
+
process.exit(1);
|
|
186
|
+
}
|
|
187
|
+
// Output the data to stdout if no output file specified
|
|
188
|
+
if (!outputPath && result.data) {
|
|
189
|
+
if (result.data instanceof Buffer) {
|
|
190
|
+
process.stdout.write(result.data);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
console.log(result.data);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=convert.impl.js.map
|