@positronic/cli 0.0.3 → 0.0.4

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 (81) hide show
  1. package/dist/src/commands/helpers.js +11 -25
  2. package/dist/types/commands/helpers.d.ts.map +1 -1
  3. package/package.json +5 -1
  4. package/dist/src/commands/brain.test.js +0 -2936
  5. package/dist/src/commands/helpers.test.js +0 -832
  6. package/dist/src/commands/project.test.js +0 -1201
  7. package/dist/src/commands/resources.test.js +0 -2511
  8. package/dist/src/commands/schedule.test.js +0 -1235
  9. package/dist/src/commands/secret.test.d.js +0 -1
  10. package/dist/src/commands/secret.test.js +0 -761
  11. package/dist/src/commands/server.test.js +0 -1237
  12. package/dist/src/commands/test-utils.js +0 -737
  13. package/dist/src/components/secret-sync.js +0 -303
  14. package/dist/src/test/mock-api-client.js +0 -371
  15. package/dist/src/test/test-dev-server.js +0 -1376
  16. package/dist/types/commands/test-utils.d.ts +0 -45
  17. package/dist/types/commands/test-utils.d.ts.map +0 -1
  18. package/dist/types/components/secret-sync.d.ts +0 -9
  19. package/dist/types/components/secret-sync.d.ts.map +0 -1
  20. package/dist/types/test/mock-api-client.d.ts +0 -25
  21. package/dist/types/test/mock-api-client.d.ts.map +0 -1
  22. package/dist/types/test/test-dev-server.d.ts +0 -129
  23. package/dist/types/test/test-dev-server.d.ts.map +0 -1
  24. package/src/cli.ts +0 -997
  25. package/src/commands/backend.ts +0 -63
  26. package/src/commands/brain.test.ts +0 -1004
  27. package/src/commands/brain.ts +0 -215
  28. package/src/commands/helpers.test.ts +0 -487
  29. package/src/commands/helpers.ts +0 -870
  30. package/src/commands/project-config-manager.ts +0 -152
  31. package/src/commands/project.test.ts +0 -502
  32. package/src/commands/project.ts +0 -109
  33. package/src/commands/resources.test.ts +0 -1052
  34. package/src/commands/resources.ts +0 -97
  35. package/src/commands/schedule.test.ts +0 -481
  36. package/src/commands/schedule.ts +0 -65
  37. package/src/commands/secret.test.ts +0 -210
  38. package/src/commands/secret.ts +0 -50
  39. package/src/commands/server.test.ts +0 -493
  40. package/src/commands/server.ts +0 -353
  41. package/src/commands/test-utils.ts +0 -324
  42. package/src/components/brain-history.tsx +0 -198
  43. package/src/components/brain-list.tsx +0 -105
  44. package/src/components/brain-rerun.tsx +0 -111
  45. package/src/components/brain-show.tsx +0 -92
  46. package/src/components/error.tsx +0 -24
  47. package/src/components/project-add.tsx +0 -59
  48. package/src/components/project-create.tsx +0 -83
  49. package/src/components/project-list.tsx +0 -83
  50. package/src/components/project-remove.tsx +0 -55
  51. package/src/components/project-select.tsx +0 -200
  52. package/src/components/project-show.tsx +0 -58
  53. package/src/components/resource-clear.tsx +0 -127
  54. package/src/components/resource-delete.tsx +0 -160
  55. package/src/components/resource-list.tsx +0 -177
  56. package/src/components/resource-sync.tsx +0 -170
  57. package/src/components/resource-types.tsx +0 -55
  58. package/src/components/resource-upload.tsx +0 -182
  59. package/src/components/schedule-create.tsx +0 -90
  60. package/src/components/schedule-delete.tsx +0 -116
  61. package/src/components/schedule-list.tsx +0 -186
  62. package/src/components/schedule-runs.tsx +0 -151
  63. package/src/components/secret-bulk.tsx +0 -79
  64. package/src/components/secret-create.tsx +0 -49
  65. package/src/components/secret-delete.tsx +0 -41
  66. package/src/components/secret-list.tsx +0 -41
  67. package/src/components/watch.tsx +0 -155
  68. package/src/hooks/useApi.ts +0 -183
  69. package/src/positronic.ts +0 -40
  70. package/src/test/data/resources/config.json +0 -1
  71. package/src/test/data/resources/data/config.json +0 -1
  72. package/src/test/data/resources/data/logo.png +0 -2
  73. package/src/test/data/resources/docs/api.md +0 -3
  74. package/src/test/data/resources/docs/readme.md +0 -3
  75. package/src/test/data/resources/example.md +0 -3
  76. package/src/test/data/resources/file with spaces.txt +0 -1
  77. package/src/test/data/resources/readme.md +0 -3
  78. package/src/test/data/resources/test.txt +0 -1
  79. package/src/test/mock-api-client.ts +0 -145
  80. package/src/test/test-dev-server.ts +0 -1003
  81. package/tsconfig.json +0 -11
@@ -1,155 +0,0 @@
1
- import React, { useState, useEffect } from 'react';
2
- import { Text, Box } from 'ink';
3
- import { EventSource } from 'eventsource';
4
- import type { BrainEvent, StepStatusEvent, BrainStartEvent, BrainErrorEvent } from '@positronic/core';
5
- import { BRAIN_EVENTS } from '@positronic/core';
6
- import type { SerializedStep } from '@positronic/core';
7
- import { STATUS } from '@positronic/core';
8
-
9
- type SerializedStepStatus = Omit<SerializedStep, 'patch'>;
10
-
11
- const getStatusIndicator = (status: SerializedStepStatus['status']) => {
12
- switch (status) {
13
- case STATUS.COMPLETE:
14
- return <Text color="green">&#10004;</Text>
15
- case STATUS.ERROR:
16
- return <Text color="red">&bull;</Text>
17
- case STATUS.RUNNING:
18
- return <Text color="white">&bull;</Text>
19
- case STATUS.PENDING:
20
- return <Text>&bull;</Text>
21
- default:
22
- return <Text>❓</Text>
23
- }
24
- };
25
-
26
- interface WatchStatusProps {
27
- steps: SerializedStepStatus[];
28
- brainTitle?: string;
29
- runId?: string;
30
- }
31
-
32
- const WatchStatus = ({ steps, brainTitle, runId }: WatchStatusProps) => {
33
- if (!steps || steps.length === 0) {
34
- return <Text>Waiting for brain steps...</Text>;
35
- }
36
-
37
- return (
38
- <Box flexDirection="column">
39
- {brainTitle && <Text bold>Brain: {brainTitle} Run ID: {runId}</Text>}
40
- <Box marginTop={1} marginBottom={1}>
41
- <Text bold>Steps:</Text>
42
- </Box>
43
- {steps.map((step) => (
44
- <Box key={step.id} marginLeft={1} marginBottom={1} flexDirection="row">
45
- <Box>
46
- <Text color={
47
- step.status === STATUS.COMPLETE ? 'green' :
48
- step.status === STATUS.ERROR ? 'red' :
49
- step.status === STATUS.RUNNING ? 'white' :
50
- step.status === STATUS.PENDING ? 'gray' :
51
- 'yellow'
52
- }>
53
- {getStatusIndicator(step.status)} {step.title}
54
- </Text>
55
- </Box>
56
- </Box>
57
- ))}
58
- </Box>
59
- );
60
- };
61
-
62
- interface WatchProps {
63
- runId: string;
64
- port: string;
65
- }
66
-
67
- export const Watch = ({ runId, port }: WatchProps) => {
68
- const [steps, setSteps] = useState<SerializedStepStatus[]>([]);
69
- const [brainTitle, setBrainTitle] = useState<string | undefined>(undefined);
70
- const [brainError, setBrainError] = useState<BrainErrorEvent | undefined>(undefined);
71
- const [error, setError] = useState<Error | null>(null);
72
- const [isConnected, setIsConnected] = useState<boolean>(false);
73
- const [isCompleted, setIsCompleted] = useState<boolean>(false);
74
-
75
- useEffect(() => {
76
- const baseUrl = `http://localhost:${port}`;
77
- const url = `${baseUrl}/brains/runs/${runId}/watch`;
78
- const es = new EventSource(url);
79
-
80
- setIsConnected(false);
81
- setError(null);
82
-
83
- es.onopen = () => {
84
- setIsConnected(true);
85
- setError(null);
86
- };
87
-
88
- es.onmessage = (event: MessageEvent) => {
89
- try {
90
- const eventData = JSON.parse(event.data) as BrainEvent;
91
- if (eventData.type === BRAIN_EVENTS.STEP_STATUS) {
92
- setSteps((eventData as StepStatusEvent).steps);
93
- }
94
-
95
- if (
96
- eventData.type === BRAIN_EVENTS.START ||
97
- eventData.type === BRAIN_EVENTS.RESTART
98
- ) {
99
- setBrainTitle((eventData as BrainStartEvent).brainTitle);
100
- setIsCompleted(false);
101
- }
102
-
103
- if (eventData.type === BRAIN_EVENTS.COMPLETE || eventData.type === BRAIN_EVENTS.ERROR) {
104
- setIsCompleted(true);
105
- }
106
-
107
- if (eventData.type === BRAIN_EVENTS.ERROR) {
108
- setBrainError(eventData);
109
- }
110
- } catch (e: any) {
111
- setError(new Error(`Error parsing event data: ${e.message}`));
112
- }
113
- };
114
-
115
- es.onerror = (err) => {
116
- // EventSource does not provide detailed error objects here, often just a generic Event
117
- setError(new Error(`Connection to ${url} failed. Ensure the server is running and accessible.`));
118
- setIsConnected(false);
119
- es.close();
120
- };
121
-
122
- // Cleanup function to close EventSource when component unmounts or runId/port changes
123
- return () => {
124
- es.close();
125
- };
126
- }, [runId, port]);
127
-
128
- if (!isConnected && steps.length === 0) {
129
- return <Text>Connecting to watch service...</Text>;
130
- }
131
-
132
- return (
133
- <Box flexDirection="column">
134
- <WatchStatus steps={steps} brainTitle={brainTitle} runId={runId} />
135
- {isCompleted && !error && !brainError && (
136
- <Box marginTop={1} borderStyle="round" borderColor="green" paddingX={1}>
137
- <Text color="green">Brain completed.</Text>
138
- </Box>
139
- )}
140
- {error && (
141
- <Box borderStyle="round" borderColor="red" padding={1}>
142
- <Text color="red">{error.message}</Text>
143
- <Text color="red">{error.stack}</Text>
144
- </Box>
145
- )}
146
- {brainError && (
147
- <Box borderStyle="round" borderColor="red" padding={1}>
148
- <Text color="red">{brainError.error.name}</Text>
149
- <Text color="red">{brainError.error.message}</Text>
150
- <Text color="red">{brainError.error.stack}</Text>
151
- </Box>
152
- )}
153
- </Box>
154
- );
155
- };
@@ -1,183 +0,0 @@
1
- import { useState, useEffect, useCallback } from 'react';
2
- import { apiClient } from '../commands/helpers.js';
3
-
4
- export function useApiGet<T>(endpoint: string, options?: any) {
5
- const [data, setData] = useState<T | null>(null);
6
- const [loading, setLoading] = useState(true);
7
- const [error, setError] = useState<{
8
- title: string;
9
- message: string;
10
- details?: string;
11
- } | null>(null);
12
-
13
- useEffect(() => {
14
- const fetchData = async () => {
15
- try {
16
- setLoading(true);
17
- setError(null);
18
-
19
- const response = await apiClient.fetch(endpoint, {
20
- method: 'GET',
21
- ...options,
22
- });
23
-
24
- if (response.status === 200) {
25
- const result = (await response.json()) as T;
26
- setData(result);
27
- } else {
28
- const errorText = await response.text();
29
- setError({
30
- title: 'Server Error',
31
- message: `Error fetching ${endpoint}: ${response.status} ${response.statusText}`,
32
- details: `Server response: ${errorText}`,
33
- });
34
- }
35
- } catch (err: any) {
36
- let errorDetails = err.message;
37
- if (err.code === 'ECONNREFUSED') {
38
- errorDetails =
39
- 'Connection refused. The server might not be running or is listening on a different port.';
40
- }
41
-
42
- setError({
43
- title: 'Connection Error',
44
- message: 'Error connecting to the local development server.',
45
- details: `Please ensure the server is running ('positronic server' or 'px s'). ${errorDetails}`,
46
- });
47
- } finally {
48
- setLoading(false);
49
- }
50
- };
51
-
52
- fetchData();
53
- }, [endpoint]);
54
-
55
- return { data, loading, error };
56
- }
57
-
58
- export function useApiPost<T>(endpoint: string, defaultOptions?: any) {
59
- const [data, setData] = useState<T | null>(null);
60
- const [loading, setLoading] = useState(false);
61
- const [error, setError] = useState<{
62
- title: string;
63
- message: string;
64
- details?: string;
65
- } | null>(null);
66
-
67
- const execute = useCallback(
68
- async (body?: any, options?: any) => {
69
- try {
70
- setLoading(true);
71
- setError(null);
72
-
73
- const response = await apiClient.fetch(endpoint, {
74
- method: 'POST',
75
- ...defaultOptions,
76
- ...options,
77
- body,
78
- });
79
-
80
- if (response.status === 200 || response.status === 201) {
81
- const result = (await response.json()) as T;
82
- setData(result);
83
- return result;
84
- } else {
85
- const errorText = await response.text();
86
- const errorObj = {
87
- title: 'Server Error',
88
- message: `Error posting to ${endpoint}: ${response.status} ${response.statusText}`,
89
- details: `Server response: ${errorText}`,
90
- };
91
- setError(errorObj);
92
- throw errorObj;
93
- }
94
- } catch (err: any) {
95
- // If it's already our error object, don't wrap it again
96
- if (err.title && err.message) {
97
- setError(err);
98
- throw err;
99
- }
100
-
101
- let errorDetails = err.message;
102
- if (err.code === 'ECONNREFUSED') {
103
- errorDetails =
104
- 'Connection refused. The server might not be running or is listening on a different port.';
105
- }
106
-
107
- const errorObj = {
108
- title: 'Connection Error',
109
- message: 'Error connecting to the local development server.',
110
- details: `Please ensure the server is running ('positronic server' or 'px s'). ${errorDetails}`,
111
- };
112
- setError(errorObj);
113
- throw errorObj;
114
- } finally {
115
- setLoading(false);
116
- }
117
- },
118
- [endpoint, defaultOptions]
119
- );
120
-
121
- return { data, loading, error, execute };
122
- }
123
-
124
- export function useApiDelete(resourceType: string) {
125
- const [loading, setLoading] = useState(false);
126
- const [error, setError] = useState<{
127
- title: string;
128
- message: string;
129
- details?: string;
130
- } | null>(null);
131
-
132
- const execute = useCallback(
133
- async (endpoint: string, options?: any) => {
134
- try {
135
- setLoading(true);
136
- setError(null);
137
-
138
- const response = await apiClient.fetch(endpoint, {
139
- method: 'DELETE',
140
- ...options,
141
- });
142
-
143
- if (response.status === 204 || response.status === 200) {
144
- return true;
145
- } else {
146
- const errorText = await response.text();
147
- const errorObj = {
148
- title: 'Server Error',
149
- message: `Error deleting ${resourceType}: ${response.status} ${response.statusText}`,
150
- details: `Server response: ${errorText}`,
151
- };
152
- setError(errorObj);
153
- throw errorObj;
154
- }
155
- } catch (err: any) {
156
- // If it's already our error object, don't wrap it again
157
- if (err.title && err.message) {
158
- setError(err);
159
- throw err;
160
- }
161
-
162
- let errorDetails = err.message;
163
- if (err.code === 'ECONNREFUSED') {
164
- errorDetails =
165
- 'Connection refused. The server might not be running or is listening on a different port.';
166
- }
167
-
168
- const errorObj = {
169
- title: 'Connection Error',
170
- message: 'Error connecting to the local development server.',
171
- details: `Please ensure the server is running ('positronic server' or 'px s'). ${errorDetails}`,
172
- };
173
- setError(errorObj);
174
- throw errorObj;
175
- } finally {
176
- setLoading(false);
177
- }
178
- },
179
- [resourceType]
180
- );
181
-
182
- return { loading, error, execute };
183
- }
package/src/positronic.ts DELETED
@@ -1,40 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import * as fs from 'fs';
4
- import * as path from 'path';
5
- import { buildCli } from './cli.js';
6
- import { render } from 'ink';
7
- import { createDevServer } from './commands/backend.js';
8
-
9
- function findProjectRootSync(startDir: string): string | null {
10
- let currentDir = path.resolve(startDir);
11
- while (true) {
12
- const configPath = path.join(currentDir, 'positronic.config.json');
13
- try {
14
- fs.accessSync(configPath);
15
- return currentDir;
16
- } catch (e) {
17
- const parentDir = path.dirname(currentDir);
18
- if (parentDir === currentDir) {
19
- return null;
20
- }
21
- currentDir = parentDir;
22
- }
23
- }
24
- }
25
-
26
- // Determine mode and project path once at the start
27
- const projectRootPath = findProjectRootSync(process.cwd());
28
- const server = projectRootPath
29
- ? await createDevServer(projectRootPath)
30
- : undefined;
31
-
32
- // Build and parse the CLI
33
- const cli = buildCli({
34
- server,
35
- exitProcess: true,
36
- render,
37
- });
38
-
39
- // Parse the arguments
40
- cli.parse();
@@ -1 +0,0 @@
1
- { "setting": true }
@@ -1 +0,0 @@
1
- {}
@@ -1,2 +0,0 @@
1
- �PNG
2
- 
@@ -1,3 +0,0 @@
1
- # API Documentation
2
-
3
- This is API documentation for testing purposes.
@@ -1,3 +0,0 @@
1
- # Readme
2
-
3
- This is a readme file in the docs directory.
@@ -1,3 +0,0 @@
1
- # Example
2
-
3
- This is an example markdown file for testing.
@@ -1 +0,0 @@
1
- content
@@ -1,3 +0,0 @@
1
- # README
2
-
3
- This is a README file for testing purposes.
@@ -1 +0,0 @@
1
- Test content
@@ -1,145 +0,0 @@
1
- import type { ApiClient } from '../commands/helpers.js';
2
-
3
- interface MockResource {
4
- key: string;
5
- type: 'text' | 'binary';
6
- path?: string;
7
- size: number;
8
- lastModified: string;
9
- local: boolean;
10
- }
11
-
12
- export class MockApiClient implements ApiClient {
13
- private resources: MockResource[] = [];
14
- private brainRuns: Map<string, any> = new Map();
15
-
16
- // Track all calls for assertions
17
- public calls: Array<{ path: string; options?: RequestInit }> = [];
18
-
19
- async fetch(path: string, options?: RequestInit): Promise<Response> {
20
- this.calls.push({ path, options });
21
-
22
- // Mock GET /resources
23
- if (path === '/resources' && (!options || options.method === 'GET')) {
24
- return new Response(
25
- JSON.stringify({
26
- resources: this.resources,
27
- truncated: false,
28
- count: this.resources.length,
29
- }),
30
- {
31
- status: 200,
32
- headers: { 'Content-Type': 'application/json' },
33
- }
34
- );
35
- }
36
-
37
- // Mock POST /resources
38
- if (path === '/resources' && options?.method === 'POST') {
39
- // Extract form data from the request
40
- const formData = options.body;
41
- if (formData && formData instanceof FormData) {
42
- const type = formData.get('type');
43
- const key = formData.get('key');
44
- const file = formData.get('file');
45
- const local = formData.get('local');
46
-
47
- if (type && key && file) {
48
- const newResource: MockResource = {
49
- key: key as string,
50
- type: type as 'text' | 'binary',
51
- size: (file as any).size || 100, // Mock size
52
- lastModified: new Date().toISOString(),
53
- local: local === 'true',
54
- };
55
-
56
- // Update existing or add new
57
- const existingIndex = this.resources.findIndex((r) => r.key === key);
58
- if (existingIndex >= 0) {
59
- this.resources[existingIndex] = newResource;
60
- } else {
61
- this.resources.push(newResource);
62
- }
63
-
64
- return new Response(JSON.stringify(newResource), {
65
- status: 201,
66
- headers: { 'Content-Type': 'application/json' },
67
- });
68
- }
69
- }
70
-
71
- return new Response('Bad Request', { status: 400 });
72
- }
73
-
74
- // Mock DELETE /resources (bulk delete all)
75
- if (path === '/resources' && options?.method === 'DELETE') {
76
- this.resources = [];
77
- return new Response(null, { status: 204 });
78
- }
79
-
80
- // Mock DELETE /resources/:key
81
- const deleteMatch = path.match(/^\/resources\/(.+)$/);
82
- if (deleteMatch && options?.method === 'DELETE') {
83
- const key = decodeURIComponent(deleteMatch[1]);
84
- const index = this.resources.findIndex((r) => r.key === key);
85
-
86
- if (index >= 0) {
87
- this.resources.splice(index, 1);
88
- }
89
-
90
- // Always return 204 for delete (idempotent)
91
- return new Response(null, { status: 204 });
92
- }
93
-
94
- // Mock POST /brains/runs
95
- if (path === '/brains/runs' && options?.method === 'POST') {
96
- if (typeof options.body === 'string') {
97
- const body = JSON.parse(options.body);
98
- const brainRunId = `run-${Date.now()}`;
99
- this.brainRuns.set(brainRunId, {
100
- brainName: body.brainName,
101
- id: brainRunId,
102
- });
103
-
104
- return new Response(JSON.stringify({ brainRunId }), {
105
- status: 201,
106
- headers: { 'Content-Type': 'application/json' },
107
- });
108
- }
109
- return new Response('Bad Request', { status: 400 });
110
- }
111
-
112
- // Default: Not found
113
- return new Response('Not Found', { status: 404 });
114
- }
115
-
116
- // Helper methods for test setup
117
- addResource(resource: MockResource) {
118
- this.resources.push(resource);
119
- }
120
-
121
- clearResources() {
122
- this.resources = [];
123
- }
124
-
125
- getResources() {
126
- return [...this.resources];
127
- }
128
-
129
- reset() {
130
- this.resources = [];
131
- this.brainRuns.clear();
132
- this.calls = [];
133
- }
134
- }
135
-
136
- // Factory function for creating mock clients with initial data
137
- export function createMockApiClient(
138
- initialResources?: MockResource[]
139
- ): MockApiClient {
140
- const client = new MockApiClient();
141
- if (initialResources) {
142
- initialResources.forEach((r) => client.addResource(r));
143
- }
144
- return client;
145
- }