agent-state-machine 1.0.1 → 1.0.3

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/README.md CHANGED
@@ -11,14 +11,28 @@ You write normal `async/await` code. The runtime handles:
11
11
 
12
12
  ## Install
13
13
 
14
+ You need to install the package **globally** to get the CLI, and **locally** in your project so your workflow can import the library.
15
+
16
+ ### Global CLI
17
+ Provides the `state-machine` command.
18
+
14
19
  ```bash
15
- npm i agent-state-machine
20
+ # npm
21
+ npm i -g agent-state-machine
22
+
23
+ # pnpm
24
+ pnpm add -g agent-state-machine
16
25
  ```
17
26
 
18
- Global CLI:
27
+ ### Local Library
28
+ Required so your `workflow.js` can `import { agent, memory } from 'agent-state-machine'`.
19
29
 
20
30
  ```bash
21
- npm i -g agent-state-machine
31
+ # npm
32
+ npm i agent-state-machine
33
+
34
+ # pnpm (for monorepos/turbo, install in root)
35
+ pnpm add agent-state-machine -w
22
36
  ```
23
37
 
24
38
  Requirements: Node.js >= 16.
package/bin/cli.js CHANGED
@@ -2,16 +2,29 @@
2
2
 
3
3
  import path from 'path';
4
4
  import fs from 'fs';
5
- import { pathToFileURL } from 'url';
5
+ import { pathToFileURL, fileURLToPath } from 'url';
6
6
  import { WorkflowRuntime } from '../lib/index.js';
7
7
  import { setup } from '../lib/setup.js';
8
8
 
9
+ const __filename = fileURLToPath(import.meta.url);
10
+ const __dirname = path.dirname(__filename);
11
+
9
12
  const args = process.argv.slice(2);
10
13
  const command = args[0];
11
14
 
15
+ function getVersion() {
16
+ try {
17
+ const pkgPath = path.join(__dirname, '../package.json');
18
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
19
+ return pkg.version;
20
+ } catch {
21
+ return 'unknown';
22
+ }
23
+ }
24
+
12
25
  function printHelp() {
13
26
  console.log(`
14
- Agent State Machine CLI (Native JS Workflows Only)
27
+ Agent State Machine CLI (Native JS Workflows Only) v${getVersion()}
15
28
 
16
29
  Usage:
17
30
  state-machine --setup <workflow-name> Create a new workflow project
@@ -27,6 +40,7 @@ Usage:
27
40
  Options:
28
41
  --setup, -s Initialize a new workflow with directory structure
29
42
  --help, -h Show help
43
+ --version, -v Show version
30
44
 
31
45
  Workflow Structure:
32
46
  workflows/<name>/
@@ -143,6 +157,11 @@ async function runOrResume(workflowName) {
143
157
  }
144
158
 
145
159
  async function main() {
160
+ if (command === '--version' || command === '-v') {
161
+ console.log(getVersion());
162
+ process.exit(0);
163
+ }
164
+
146
165
  if (!command || command === 'help' || command === '--help' || command === '-h') {
147
166
  printHelp();
148
167
  process.exit(0);
@@ -12,18 +12,19 @@ import readline from 'readline';
12
12
  import { createMemoryProxy } from './memory.js';
13
13
 
14
14
  // Global runtime reference for agent() and memory access
15
- let currentRuntime = null;
15
+ // stored on globalThis to ensure singleton access across different module instances (CLI vs local)
16
+ const RUNTIME_KEY = Symbol.for('agent-state-machine.runtime');
16
17
 
17
18
  export function getCurrentRuntime() {
18
- return currentRuntime;
19
+ return globalThis[RUNTIME_KEY];
19
20
  }
20
21
 
21
22
  export function setCurrentRuntime(runtime) {
22
- currentRuntime = runtime;
23
+ globalThis[RUNTIME_KEY] = runtime;
23
24
  }
24
25
 
25
26
  export function clearCurrentRuntime() {
26
- currentRuntime = null;
27
+ globalThis[RUNTIME_KEY] = null;
27
28
  }
28
29
 
29
30
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-state-machine",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "type": "module",
5
5
  "description": "A workflow orchestrator for running agents and scripts in sequence with state management",
6
6
  "main": "lib/index.js",