@usestatemachines/cli 0.0.0-stage → 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 (169) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +34 -2
  3. package/dist/agents/bundled.d.ts +5 -0
  4. package/dist/agents/bundled.js +6 -0
  5. package/dist/agents/destinations.d.ts +13 -0
  6. package/dist/agents/destinations.js +16 -0
  7. package/dist/api-internal.d.ts +62 -0
  8. package/dist/api-internal.js +348 -0
  9. package/dist/bin.d.ts +2 -0
  10. package/dist/bin.js +4 -0
  11. package/dist/command.d.ts +119 -0
  12. package/dist/command.js +195 -0
  13. package/dist/commands/api/command.d.ts +15 -0
  14. package/dist/commands/api/command.js +38 -0
  15. package/dist/commands/api/run.d.ts +4 -0
  16. package/dist/commands/api/run.js +24 -0
  17. package/dist/commands/apps/command.d.ts +19 -0
  18. package/dist/commands/apps/command.js +29 -0
  19. package/dist/commands/apps/list.d.ts +8 -0
  20. package/dist/commands/apps/list.js +10 -0
  21. package/dist/commands/connect/command.d.ts +34 -0
  22. package/dist/commands/connect/command.js +70 -0
  23. package/dist/commands/connect/run.d.ts +10 -0
  24. package/dist/commands/connect/run.js +71 -0
  25. package/dist/commands/doctor/command.d.ts +29 -0
  26. package/dist/commands/doctor/command.js +36 -0
  27. package/dist/commands/doctor/run.d.ts +13 -0
  28. package/dist/commands/doctor/run.js +12 -0
  29. package/dist/commands/env/command.d.ts +5 -0
  30. package/dist/commands/env/command.js +19 -0
  31. package/dist/commands/env/pull.d.ts +6 -0
  32. package/dist/commands/env/pull.js +6 -0
  33. package/dist/commands/environments/command.d.ts +121 -0
  34. package/dist/commands/environments/command.js +170 -0
  35. package/dist/commands/environments/create.d.ts +9 -0
  36. package/dist/commands/environments/create.js +42 -0
  37. package/dist/commands/environments/delete.d.ts +7 -0
  38. package/dist/commands/environments/delete.js +48 -0
  39. package/dist/commands/environments/get.d.ts +39 -0
  40. package/dist/commands/environments/get.js +5 -0
  41. package/dist/commands/environments/list.d.ts +41 -0
  42. package/dist/commands/environments/list.js +18 -0
  43. package/dist/commands/environments/wait.d.ts +39 -0
  44. package/dist/commands/environments/wait.js +21 -0
  45. package/dist/commands/init/command.d.ts +68 -0
  46. package/dist/commands/init/command.js +90 -0
  47. package/dist/commands/init/run.d.ts +8 -0
  48. package/dist/commands/init/run.js +422 -0
  49. package/dist/commands/link/command.d.ts +13 -0
  50. package/dist/commands/link/command.js +32 -0
  51. package/dist/commands/link/run.d.ts +12 -0
  52. package/dist/commands/link/run.js +7 -0
  53. package/dist/commands/login/command.d.ts +1 -0
  54. package/dist/commands/login/command.js +43 -0
  55. package/dist/commands/login/run.d.ts +30 -0
  56. package/dist/commands/login/run.js +43 -0
  57. package/dist/commands/login/schema.d.ts +33 -0
  58. package/dist/commands/login/schema.js +33 -0
  59. package/dist/commands/logout/command.d.ts +1 -0
  60. package/dist/commands/logout/command.js +24 -0
  61. package/dist/commands/logout/run.d.ts +10 -0
  62. package/dist/commands/logout/run.js +19 -0
  63. package/dist/commands/logout/schema.d.ts +10 -0
  64. package/dist/commands/logout/schema.js +10 -0
  65. package/dist/commands/profiles/command.d.ts +2 -0
  66. package/dist/commands/profiles/command.js +29 -0
  67. package/dist/commands/profiles/list.d.ts +20 -0
  68. package/dist/commands/profiles/list.js +10 -0
  69. package/dist/commands/profiles/schema.d.ts +24 -0
  70. package/dist/commands/profiles/schema.js +19 -0
  71. package/dist/commands/profiles/use.d.ts +7 -0
  72. package/dist/commands/profiles/use.js +7 -0
  73. package/dist/commands/requests/command.d.ts +39 -0
  74. package/dist/commands/requests/command.js +65 -0
  75. package/dist/commands/requests/get.d.ts +32 -0
  76. package/dist/commands/requests/get.js +15 -0
  77. package/dist/commands/requests/list.d.ts +27 -0
  78. package/dist/commands/requests/list.js +25 -0
  79. package/dist/commands/snapshots/command.d.ts +48 -0
  80. package/dist/commands/snapshots/command.js +80 -0
  81. package/dist/commands/snapshots/create.d.ts +7 -0
  82. package/dist/commands/snapshots/create.js +26 -0
  83. package/dist/commands/snapshots/delete.d.ts +34 -0
  84. package/dist/commands/snapshots/delete.js +8 -0
  85. package/dist/commands/snapshots/get.d.ts +35 -0
  86. package/dist/commands/snapshots/get.js +5 -0
  87. package/dist/commands/snapshots/list.d.ts +37 -0
  88. package/dist/commands/snapshots/list.js +10 -0
  89. package/dist/commands/unlink/command.d.ts +1 -0
  90. package/dist/commands/unlink/command.js +15 -0
  91. package/dist/commands/unlink/run.d.ts +7 -0
  92. package/dist/commands/unlink/run.js +8 -0
  93. package/dist/commands/whoami/command.d.ts +28 -0
  94. package/dist/commands/whoami/command.js +44 -0
  95. package/dist/commands/whoami/run.d.ts +5 -0
  96. package/dist/commands/whoami/run.js +39 -0
  97. package/dist/commands/workspaces/command.d.ts +33 -0
  98. package/dist/commands/workspaces/command.js +73 -0
  99. package/dist/commands/workspaces/list.d.ts +5 -0
  100. package/dist/commands/workspaces/list.js +42 -0
  101. package/dist/commands/workspaces/use.d.ts +5 -0
  102. package/dist/commands/workspaces/use.js +18 -0
  103. package/dist/config/project.d.ts +21 -0
  104. package/dist/config/project.js +105 -0
  105. package/dist/config/schema.d.ts +616 -0
  106. package/dist/config/schema.js +282 -0
  107. package/dist/context-types.d.ts +89 -0
  108. package/dist/context-types.js +56 -0
  109. package/dist/context.d.ts +13 -0
  110. package/dist/context.js +290 -0
  111. package/dist/credentials/sealing.d.ts +10 -0
  112. package/dist/credentials/sealing.js +72 -0
  113. package/dist/credentials/store.d.ts +17 -0
  114. package/dist/credentials/store.js +156 -0
  115. package/dist/doctor.d.ts +4 -0
  116. package/dist/doctor.js +239 -0
  117. package/dist/env-file.d.ts +10 -0
  118. package/dist/env-file.js +254 -0
  119. package/dist/errors.d.ts +784 -0
  120. package/dist/errors.js +459 -0
  121. package/dist/flags.d.ts +22 -0
  122. package/dist/flags.js +56 -0
  123. package/dist/generated/internal.d.ts +138 -0
  124. package/dist/generated/internal.js +2627 -0
  125. package/dist/generated/retry.d.ts +1 -0
  126. package/dist/generated/retry.js +11 -0
  127. package/dist/help.d.ts +408 -0
  128. package/dist/help.js +220 -0
  129. package/dist/io-types.d.ts +127 -0
  130. package/dist/io-types.js +1 -0
  131. package/dist/io.d.ts +13 -0
  132. package/dist/io.js +1017 -0
  133. package/dist/keys.d.ts +50 -0
  134. package/dist/keys.js +691 -0
  135. package/dist/link.d.ts +6 -0
  136. package/dist/link.js +58 -0
  137. package/dist/login.d.ts +92 -0
  138. package/dist/login.js +965 -0
  139. package/dist/main.d.ts +2 -0
  140. package/dist/main.js +126 -0
  141. package/dist/native-helper.d.ts +1 -0
  142. package/dist/native-helper.js +2 -0
  143. package/dist/output.d.ts +8 -0
  144. package/dist/output.js +135 -0
  145. package/dist/parser.d.ts +28 -0
  146. package/dist/parser.js +250 -0
  147. package/dist/program-types.d.ts +67 -0
  148. package/dist/program-types.js +14 -0
  149. package/dist/programs.d.ts +2 -0
  150. package/dist/programs.js +44 -0
  151. package/dist/project-roots.d.ts +3 -0
  152. package/dist/project-roots.js +26 -0
  153. package/dist/prompt.d.ts +3 -0
  154. package/dist/prompt.js +61 -0
  155. package/dist/registry.d.ts +2 -0
  156. package/dist/registry.js +44 -0
  157. package/dist/resources/create.d.ts +9 -0
  158. package/dist/resources/create.js +55 -0
  159. package/dist/resources/read.d.ts +15 -0
  160. package/dist/resources/read.js +69 -0
  161. package/dist/resources/schema.d.ts +177 -0
  162. package/dist/resources/schema.js +158 -0
  163. package/dist/text.d.ts +3 -0
  164. package/dist/text.js +19 -0
  165. package/dist/update.d.ts +22 -0
  166. package/dist/update.js +126 -0
  167. package/dist/version.d.ts +2 -0
  168. package/dist/version.js +2 -0
  169. package/package.json +52 -3
package/dist/text.js ADDED
@@ -0,0 +1,19 @@
1
+ import { stripVTControlCharacters } from 'node:util';
2
+ export function untrustedText(value) {
3
+ return stripVTControlCharacters(value).replace(/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/gu, '');
4
+ }
5
+ export function untrustedResult(value) {
6
+ if (typeof value === 'string') {
7
+ return untrustedText(value);
8
+ }
9
+ if (value === null || typeof value !== 'object') {
10
+ return value;
11
+ }
12
+ if (Array.isArray(value)) {
13
+ return value.map(untrustedResult);
14
+ }
15
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [
16
+ untrustedText(key),
17
+ untrustedResult(item),
18
+ ]));
19
+ }
@@ -0,0 +1,22 @@
1
+ import type { Presentation } from './context-types.js';
2
+ import type { EffectOptions, Io } from './io-types.js';
3
+ export interface LatestVersion {
4
+ readonly current: string;
5
+ readonly latest: string | null;
6
+ readonly newer: boolean;
7
+ readonly command: string;
8
+ }
9
+ export declare function updateCommand(io: Io): string;
10
+ export declare function checkLatest(input: {
11
+ io: Io;
12
+ version: string;
13
+ options?: EffectOptions;
14
+ }): Promise<LatestVersion>;
15
+ export declare function notifyUpdate(input: {
16
+ io: Io;
17
+ presentation: Presentation;
18
+ version: string;
19
+ agent: {
20
+ readonly name: string;
21
+ } | null;
22
+ }): Promise<void>;
package/dist/update.js ADDED
@@ -0,0 +1,126 @@
1
+ import { join } from 'node:path';
2
+ import { z } from 'zod';
3
+ import { withinDeadline } from './api-internal.js';
4
+ import { CliError } from './errors.js';
5
+ const versionSchema = z
6
+ .string()
7
+ .regex(/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/);
8
+ const cacheSchema = z.strictObject({
9
+ version: z.literal(1),
10
+ checkedAt: z.number().finite(),
11
+ latest: versionSchema.nullable(),
12
+ });
13
+ function newerVersion(latest, current) {
14
+ const target = latest.split(/[.-]/).slice(0, 3).map(Number);
15
+ const present = current.split(/[.-]/).slice(0, 3).map(Number);
16
+ for (let index = 0; index < 3; index++) {
17
+ const next = target[index] ?? 0;
18
+ const previous = present[index] ?? 0;
19
+ if (next !== previous) {
20
+ return next > previous;
21
+ }
22
+ }
23
+ return current.includes('-') && !latest.includes('-');
24
+ }
25
+ export function updateCommand(io) {
26
+ return io.host.environment.npm_command === 'exec' ||
27
+ /npx(?:-cli)?(?:\.js)?$/.test(io.host.environment.npm_execpath ?? '')
28
+ ? 'npx @usestatemachines/cli@latest'
29
+ : 'npm install --global @usestatemachines/cli@latest';
30
+ }
31
+ export async function checkLatest(input) {
32
+ const { io, version } = input;
33
+ const options = {
34
+ signal: input.options?.signal ?? io.signal,
35
+ deadline: Math.min(input.options?.deadline ?? Infinity, io.now() + 2000),
36
+ };
37
+ const path = join(io.host.configHome, 'update.json');
38
+ const make = (latest) => ({
39
+ current: version,
40
+ latest,
41
+ newer: latest !== null && newerVersion(latest, version),
42
+ command: updateCommand(io),
43
+ });
44
+ return withinDeadline(io, options, async (signal) => {
45
+ const effects = { ...options, signal };
46
+ const state = await io.files.withLock(join(io.host.configHome, '.update.lock'), effects, async () => {
47
+ const text = await io.files.read(path, effects);
48
+ let cached = null;
49
+ if (text !== null) {
50
+ try {
51
+ const result = cacheSchema.safeParse(JSON.parse(text));
52
+ if (result.success) {
53
+ cached = result.data;
54
+ }
55
+ }
56
+ catch { }
57
+ }
58
+ if (cached !== null &&
59
+ cached.checkedAt <= io.now() &&
60
+ io.now() - cached.checkedAt < 24 * 60 * 60 * 1000) {
61
+ return { kind: 'cached', latest: cached.latest };
62
+ }
63
+ const checkedAt = io.now();
64
+ await io.files.atomicWrite(path, JSON.stringify({ version: 1, checkedAt, latest: null }), 'private', effects);
65
+ return { kind: 'fetch', checkedAt };
66
+ });
67
+ if (state.kind === 'cached') {
68
+ return make(state.latest);
69
+ }
70
+ const environment = io.host.environment;
71
+ const lease = await io.http({
72
+ http: environment.HTTP_PROXY ?? environment.http_proxy ?? null,
73
+ https: environment.HTTPS_PROXY ?? environment.https_proxy ?? null,
74
+ noProxy: environment.NO_PROXY ?? environment.no_proxy ?? null,
75
+ }, effects);
76
+ try {
77
+ const response = await lease.fetch('https://registry.npmjs.org/@usestatemachines%2fcli/latest', { headers: { accept: 'application/json' }, redirect: 'manual', signal });
78
+ if (!response.ok) {
79
+ throw new CliError('cli.network');
80
+ }
81
+ const parsed = z
82
+ .object({ version: versionSchema })
83
+ .safeParse(await response.json());
84
+ if (!parsed.success) {
85
+ throw new CliError('cli.invalid_response');
86
+ }
87
+ await io.files.withLock(join(io.host.configHome, '.update.lock'), effects, async () => {
88
+ const text = await io.files.read(path, effects);
89
+ if (text === null) {
90
+ return;
91
+ }
92
+ const cached = cacheSchema.safeParse(JSON.parse(text));
93
+ if (cached.success && cached.data.checkedAt === state.checkedAt) {
94
+ await io.files.atomicWrite(path, JSON.stringify({
95
+ version: 1,
96
+ checkedAt: state.checkedAt,
97
+ latest: parsed.data.version,
98
+ }), 'private', effects);
99
+ }
100
+ });
101
+ return make(parsed.data.version);
102
+ }
103
+ finally {
104
+ await lease.close();
105
+ }
106
+ });
107
+ }
108
+ export async function notifyUpdate(input) {
109
+ const env = input.io.host.environment;
110
+ if (input.presentation.mode !== 'interactive' ||
111
+ input.agent !== null ||
112
+ env.CI !== undefined ||
113
+ env.STATEMACHINES_NO_UPDATE_NOTIFIER === '1' ||
114
+ env.NO_UPDATE_NOTIFIER !== undefined ||
115
+ env.npm_command === 'exec' ||
116
+ /npx/.test(env.npm_execpath ?? '')) {
117
+ return;
118
+ }
119
+ try {
120
+ const latest = await checkLatest(input);
121
+ if (latest.newer) {
122
+ await input.io.stderr.write(`State Machines CLI ${latest.latest} is available. Update with ${latest.command}.\n`);
123
+ }
124
+ }
125
+ catch { }
126
+ }
@@ -0,0 +1,2 @@
1
+ export declare const cliVersion = "0.1.0";
2
+ export declare const sdkVersion = "0.8.0";
@@ -0,0 +1,2 @@
1
+ export const cliVersion = '0.1.0';
2
+ export const sdkVersion = '0.8.0';
package/package.json CHANGED
@@ -1,6 +1,55 @@
1
1
  {
2
2
  "name": "@usestatemachines/cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Command-line client for State Machines",
5
+ "license": "MIT",
6
+ "homepage": "https://usestatemachines.com",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/statehq/state.git",
10
+ "directory": "packages/cli"
11
+ },
12
+ "author": "State Machines",
13
+ "type": "module",
14
+ "engines": {
15
+ "node": ">=20.20"
16
+ },
17
+ "bin": {
18
+ "statemachines": "dist/bin.js"
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "README.md",
23
+ "LICENSE"
24
+ ],
25
+ "dependencies": {
26
+ "@clack/prompts": "1.8.1",
27
+ "@usestatemachines/sdk": "0.8.0",
28
+ "@vercel/detect-agent": "1.2.5",
29
+ "cross-spawn": "7.0.6",
30
+ "open": "11.0.4",
31
+ "undici": "7.30.0",
32
+ "zod": "4.6.5"
33
+ },
34
+ "optionalDependencies": {
35
+ "@napi-rs/keyring": "2.1.1"
36
+ },
37
+ "devDependencies": {
38
+ "@types/cross-spawn": "6.0.6",
39
+ "@types/node": "24.13.4",
40
+ "esbuild": "0.28.2",
41
+ "msw": "2.15.0",
42
+ "typescript": "7.0.2",
43
+ "vitest": "5.0.1"
44
+ },
45
+ "scripts": {
46
+ "build": "node scripts/check-node.mjs && node scripts/build-version.mjs && node scripts/build-contracts.mjs && node scripts/build-agents.mjs && tsc --project tsconfig.build.json && node scripts/build-contracts.mjs --copy-runtime",
47
+ "typecheck": "node scripts/check-node.mjs && tsc --project tsconfig.json",
48
+ "lint": "node scripts/check-node.mjs && node scripts/build-version.mjs --check && node scripts/build-contracts.mjs --check && node scripts/build-agents.mjs --check && biome ci . && pnpm --dir ../.. exec eslint --config eslint.style.config.mjs packages/cli/src",
49
+ "startup:check": "node scripts/check-node.mjs && node scripts/check-startup.mjs",
50
+ "pack:check": "node scripts/check-node.mjs && node scripts/check-pack.mjs",
51
+ "snapshots:check": "node scripts/check-node.mjs && node scripts/check-snapshots.mjs",
52
+ "test": "node scripts/check-node.mjs && node scripts/test.mjs",
53
+ "test:local-stack": "node scripts/check-node.mjs && node scripts/check-local-stack.mjs"
54
+ }
6
55
  }