@positronic/cli 0.0.34 → 0.0.36
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/dist/src/commands/helpers.js +28 -0
- package/dist/src/commands/server.js +69 -31
- package/dist/src/components/brain-history.js +1 -20
- package/dist/types/commands/helpers.d.ts +9 -0
- package/dist/types/commands/helpers.d.ts.map +1 -1
- package/dist/types/commands/server.d.ts.map +1 -1
- package/dist/types/components/brain-history.d.ts.map +1 -1
- package/package.json +4 -4
|
@@ -226,6 +226,7 @@ import * as http from 'http';
|
|
|
226
226
|
import * as https from 'https';
|
|
227
227
|
import { URL } from 'url';
|
|
228
228
|
import { createRequire } from 'module';
|
|
229
|
+
import * as dotenv from 'dotenv';
|
|
229
230
|
// API client configuration
|
|
230
231
|
var apiBaseUrl = null;
|
|
231
232
|
var isLocalDevMode = true;
|
|
@@ -944,6 +945,33 @@ export function scanLocalResources(resourcesDir) {
|
|
|
944
945
|
});
|
|
945
946
|
}).apply(this, arguments);
|
|
946
947
|
}
|
|
948
|
+
/**
|
|
949
|
+
* Generate TypeScript declarations for secrets from .env file
|
|
950
|
+
* This provides autocomplete for env.secrets.SECRET_NAME in brain steps
|
|
951
|
+
*/ export function generateSecretTypes(projectRootPath) {
|
|
952
|
+
var envPath = path.join(projectRootPath, '.env');
|
|
953
|
+
// If no .env file exists, generate a minimal valid module
|
|
954
|
+
if (!fs.existsSync(envPath)) {
|
|
955
|
+
return "// Generated by Positronic CLI\n// No .env file found - create one to get type-safe secrets\n\ndeclare module '@positronic/core' {\n interface Secrets {\n // Add secrets to your .env file and regenerate to get autocomplete\n }\n}\n\nexport {}; // Make this a module\n";
|
|
956
|
+
}
|
|
957
|
+
var envContent = fs.readFileSync(envPath, 'utf-8');
|
|
958
|
+
var parsed = dotenv.parse(envContent);
|
|
959
|
+
// Filter to only valid JavaScript identifiers
|
|
960
|
+
var secretNames = Object.keys(parsed).filter(isValidJSIdentifier);
|
|
961
|
+
// Generate interface properties
|
|
962
|
+
var properties = secretNames.map(function(name) {
|
|
963
|
+
return " ".concat(name, ": string | undefined;");
|
|
964
|
+
}).join('\n');
|
|
965
|
+
return "// Generated by Positronic CLI\n// This file provides TypeScript types for your secrets from .env\n\ndeclare module '@positronic/core' {\n interface Secrets {\n".concat(properties, "\n }\n}\n\nexport {}; // Make this a module\n");
|
|
966
|
+
}
|
|
967
|
+
/**
|
|
968
|
+
* Generate and write secrets type definitions
|
|
969
|
+
*/ export function generateAndWriteSecretTypes(projectRootPath) {
|
|
970
|
+
var typesFilePath = path.join(projectRootPath, 'secrets.d.ts');
|
|
971
|
+
var typeDefinitions = generateSecretTypes(projectRootPath);
|
|
972
|
+
fs.writeFileSync(typesFilePath, typeDefinitions, 'utf-8');
|
|
973
|
+
return path.relative(process.cwd(), typesFilePath);
|
|
974
|
+
}
|
|
947
975
|
/**
|
|
948
976
|
* Wait for resources to stabilize (indicating initial sync is complete)
|
|
949
977
|
*/ function waitForResources(maxWaitMs, startTime) {
|
|
@@ -225,7 +225,7 @@ import * as path from 'path';
|
|
|
225
225
|
import * as fs from 'fs';
|
|
226
226
|
import { spawn } from 'child_process';
|
|
227
227
|
import chokidar from 'chokidar';
|
|
228
|
-
import { syncResources, generateTypes } from './helpers.js';
|
|
228
|
+
import { syncResources, generateTypes, generateAndWriteSecretTypes } from './helpers.js';
|
|
229
229
|
export var ServerCommand = /*#__PURE__*/ function() {
|
|
230
230
|
"use strict";
|
|
231
231
|
function ServerCommand(server) {
|
|
@@ -238,7 +238,7 @@ export var ServerCommand = /*#__PURE__*/ function() {
|
|
|
238
238
|
key: "handle",
|
|
239
239
|
value: function handle(argv) {
|
|
240
240
|
return _async_to_generator(function() {
|
|
241
|
-
var _this, pidFile, existingPid, brainsDir, resourcesDir, serverHandle, watcher, logStream, logFilePath, logDir, logBoth, cleanup, isReady, syncResult, error, watchPaths, handleResourceChange, error1;
|
|
241
|
+
var _this, pidFile, existingPid, brainsDir, resourcesDir, serverHandle, watcher, logStream, logFilePath, logDir, logBoth, cleanup, isReady, syncResult, error, envFilePath, watchPaths, handleResourceChange, handleEnvChange, error1;
|
|
242
242
|
return _ts_generator(this, function(_state) {
|
|
243
243
|
switch(_state.label){
|
|
244
244
|
case 0:
|
|
@@ -433,6 +433,8 @@ export var ServerCommand = /*#__PURE__*/ function() {
|
|
|
433
433
|
];
|
|
434
434
|
case 7:
|
|
435
435
|
_state.sent();
|
|
436
|
+
// Generate secrets types from .env for autocomplete support
|
|
437
|
+
generateAndWriteSecretTypes(this.server.projectRootDir);
|
|
436
438
|
return [
|
|
437
439
|
3,
|
|
438
440
|
9
|
|
@@ -447,10 +449,12 @@ export var ServerCommand = /*#__PURE__*/ function() {
|
|
|
447
449
|
9
|
|
448
450
|
];
|
|
449
451
|
case 9:
|
|
450
|
-
// Watcher setup - target the user's brains and
|
|
452
|
+
// Watcher setup - target the user's brains, resources directories, and .env file
|
|
453
|
+
envFilePath = path.join(this.server.projectRootDir, '.env');
|
|
451
454
|
watchPaths = [
|
|
452
455
|
path.join(brainsDir, '*.ts'),
|
|
453
|
-
path.join(resourcesDir, '**/*')
|
|
456
|
+
path.join(resourcesDir, '**/*'),
|
|
457
|
+
envFilePath
|
|
454
458
|
];
|
|
455
459
|
watcher = chokidar.watch(watchPaths, {
|
|
456
460
|
ignored: [
|
|
@@ -488,42 +492,56 @@ export var ServerCommand = /*#__PURE__*/ function() {
|
|
|
488
492
|
});
|
|
489
493
|
}).call(_this);
|
|
490
494
|
};
|
|
495
|
+
handleEnvChange = function() {
|
|
496
|
+
generateAndWriteSecretTypes(_this.server.projectRootDir);
|
|
497
|
+
console.log('✅ Updated secrets.d.ts from .env');
|
|
498
|
+
};
|
|
491
499
|
watcher.on('add', function(filePath) {
|
|
492
500
|
return _async_to_generator(function() {
|
|
493
501
|
return _ts_generator(this, function(_state) {
|
|
494
502
|
switch(_state.label){
|
|
495
503
|
case 0:
|
|
504
|
+
if (!(filePath === envFilePath)) return [
|
|
505
|
+
3,
|
|
506
|
+
1
|
|
507
|
+
];
|
|
508
|
+
handleEnvChange();
|
|
509
|
+
return [
|
|
510
|
+
3,
|
|
511
|
+
5
|
|
512
|
+
];
|
|
513
|
+
case 1:
|
|
496
514
|
if (!filePath.startsWith(resourcesDir)) return [
|
|
497
515
|
3,
|
|
498
|
-
|
|
516
|
+
3
|
|
499
517
|
];
|
|
500
518
|
return [
|
|
501
519
|
4,
|
|
502
520
|
handleResourceChange()
|
|
503
521
|
];
|
|
504
|
-
case
|
|
522
|
+
case 2:
|
|
505
523
|
_state.sent();
|
|
506
524
|
return [
|
|
507
525
|
3,
|
|
508
|
-
|
|
526
|
+
5
|
|
509
527
|
];
|
|
510
|
-
case
|
|
528
|
+
case 3:
|
|
511
529
|
if (!filePath.startsWith(brainsDir)) return [
|
|
512
530
|
3,
|
|
513
|
-
|
|
531
|
+
5
|
|
514
532
|
];
|
|
515
533
|
if (!this.server.watch) return [
|
|
516
534
|
3,
|
|
517
|
-
|
|
535
|
+
5
|
|
518
536
|
];
|
|
519
537
|
return [
|
|
520
538
|
4,
|
|
521
539
|
this.server.watch(filePath, 'add')
|
|
522
540
|
];
|
|
523
|
-
case 3:
|
|
524
|
-
_state.sent();
|
|
525
|
-
_state.label = 4;
|
|
526
541
|
case 4:
|
|
542
|
+
_state.sent();
|
|
543
|
+
_state.label = 5;
|
|
544
|
+
case 5:
|
|
527
545
|
return [
|
|
528
546
|
2
|
|
529
547
|
];
|
|
@@ -535,37 +553,47 @@ export var ServerCommand = /*#__PURE__*/ function() {
|
|
|
535
553
|
return _ts_generator(this, function(_state) {
|
|
536
554
|
switch(_state.label){
|
|
537
555
|
case 0:
|
|
556
|
+
if (!(filePath === envFilePath)) return [
|
|
557
|
+
3,
|
|
558
|
+
1
|
|
559
|
+
];
|
|
560
|
+
handleEnvChange();
|
|
561
|
+
return [
|
|
562
|
+
3,
|
|
563
|
+
5
|
|
564
|
+
];
|
|
565
|
+
case 1:
|
|
538
566
|
if (!filePath.startsWith(resourcesDir)) return [
|
|
539
567
|
3,
|
|
540
|
-
|
|
568
|
+
3
|
|
541
569
|
];
|
|
542
570
|
return [
|
|
543
571
|
4,
|
|
544
572
|
handleResourceChange()
|
|
545
573
|
];
|
|
546
|
-
case
|
|
574
|
+
case 2:
|
|
547
575
|
_state.sent();
|
|
548
576
|
return [
|
|
549
577
|
3,
|
|
550
|
-
|
|
578
|
+
5
|
|
551
579
|
];
|
|
552
|
-
case
|
|
580
|
+
case 3:
|
|
553
581
|
if (!filePath.startsWith(brainsDir)) return [
|
|
554
582
|
3,
|
|
555
|
-
|
|
583
|
+
5
|
|
556
584
|
];
|
|
557
585
|
if (!this.server.watch) return [
|
|
558
586
|
3,
|
|
559
|
-
|
|
587
|
+
5
|
|
560
588
|
];
|
|
561
589
|
return [
|
|
562
590
|
4,
|
|
563
591
|
this.server.watch(filePath, 'change')
|
|
564
592
|
];
|
|
565
|
-
case 3:
|
|
566
|
-
_state.sent();
|
|
567
|
-
_state.label = 4;
|
|
568
593
|
case 4:
|
|
594
|
+
_state.sent();
|
|
595
|
+
_state.label = 5;
|
|
596
|
+
case 5:
|
|
569
597
|
return [
|
|
570
598
|
2
|
|
571
599
|
];
|
|
@@ -577,37 +605,47 @@ export var ServerCommand = /*#__PURE__*/ function() {
|
|
|
577
605
|
return _ts_generator(this, function(_state) {
|
|
578
606
|
switch(_state.label){
|
|
579
607
|
case 0:
|
|
608
|
+
if (!(filePath === envFilePath)) return [
|
|
609
|
+
3,
|
|
610
|
+
1
|
|
611
|
+
];
|
|
612
|
+
handleEnvChange();
|
|
613
|
+
return [
|
|
614
|
+
3,
|
|
615
|
+
5
|
|
616
|
+
];
|
|
617
|
+
case 1:
|
|
580
618
|
if (!filePath.startsWith(resourcesDir)) return [
|
|
581
619
|
3,
|
|
582
|
-
|
|
620
|
+
3
|
|
583
621
|
];
|
|
584
622
|
return [
|
|
585
623
|
4,
|
|
586
624
|
handleResourceChange()
|
|
587
625
|
];
|
|
588
|
-
case
|
|
626
|
+
case 2:
|
|
589
627
|
_state.sent();
|
|
590
628
|
return [
|
|
591
629
|
3,
|
|
592
|
-
|
|
630
|
+
5
|
|
593
631
|
];
|
|
594
|
-
case
|
|
632
|
+
case 3:
|
|
595
633
|
if (!filePath.startsWith(brainsDir)) return [
|
|
596
634
|
3,
|
|
597
|
-
|
|
635
|
+
5
|
|
598
636
|
];
|
|
599
637
|
if (!this.server.watch) return [
|
|
600
638
|
3,
|
|
601
|
-
|
|
639
|
+
5
|
|
602
640
|
];
|
|
603
641
|
return [
|
|
604
642
|
4,
|
|
605
643
|
this.server.watch(filePath, 'unlink')
|
|
606
644
|
];
|
|
607
|
-
case 3:
|
|
608
|
-
_state.sent();
|
|
609
|
-
_state.label = 4;
|
|
610
645
|
case 4:
|
|
646
|
+
_state.sent();
|
|
647
|
+
_state.label = 5;
|
|
648
|
+
case 5:
|
|
611
649
|
return [
|
|
612
650
|
2
|
|
613
651
|
];
|
|
@@ -147,24 +147,5 @@ export var BrainHistory = function(param) {
|
|
|
147
147
|
}, padRight(formatRelativeTime(run.createdAt), columns.when.width)), /*#__PURE__*/ React.createElement(Text, null, " "), /*#__PURE__*/ React.createElement(Text, null, padRight(duration, columns.duration.width)), /*#__PURE__*/ React.createElement(Text, null, " "), /*#__PURE__*/ React.createElement(Text, {
|
|
148
148
|
dimColor: true
|
|
149
149
|
}, padRight(run.startedAt ? formatDate(run.startedAt) : 'N/A', columns.startedAt.width)));
|
|
150
|
-
})
|
|
151
|
-
return r.status === STATUS.ERROR && r.error;
|
|
152
|
-
}).length > 0 && /*#__PURE__*/ React.createElement(Box, {
|
|
153
|
-
flexDirection: "column",
|
|
154
|
-
marginTop: 1
|
|
155
|
-
}, /*#__PURE__*/ React.createElement(Text, {
|
|
156
|
-
bold: true,
|
|
157
|
-
color: "red"
|
|
158
|
-
}, "Errors:"), data.runs.filter(function(r) {
|
|
159
|
-
return r.status === STATUS.ERROR && r.error;
|
|
160
|
-
}).map(function(run) {
|
|
161
|
-
return /*#__PURE__*/ React.createElement(Box, {
|
|
162
|
-
key: run.brainRunId,
|
|
163
|
-
marginLeft: 2
|
|
164
|
-
}, /*#__PURE__*/ React.createElement(Text, {
|
|
165
|
-
dimColor: true
|
|
166
|
-
}, run.brainRunId, ": "), /*#__PURE__*/ React.createElement(Text, {
|
|
167
|
-
color: "red"
|
|
168
|
-
}, typeof run.error === 'string' ? run.error : JSON.stringify(run.error)));
|
|
169
|
-
}))));
|
|
150
|
+
})));
|
|
170
151
|
};
|
|
@@ -51,6 +51,15 @@ export declare function syncResources(projectRootPath: string, client?: ApiClien
|
|
|
51
51
|
* Core type generation logic without UI dependencies
|
|
52
52
|
*/
|
|
53
53
|
export declare function generateTypes(projectRootPath: string, client?: ApiClient): Promise<string>;
|
|
54
|
+
/**
|
|
55
|
+
* Generate TypeScript declarations for secrets from .env file
|
|
56
|
+
* This provides autocomplete for env.secrets.SECRET_NAME in brain steps
|
|
57
|
+
*/
|
|
58
|
+
export declare function generateSecretTypes(projectRootPath: string): string;
|
|
59
|
+
/**
|
|
60
|
+
* Generate and write secrets type definitions
|
|
61
|
+
*/
|
|
62
|
+
export declare function generateAndWriteSecretTypes(projectRootPath: string): string;
|
|
54
63
|
/**
|
|
55
64
|
* Helper function to wait for server to be ready
|
|
56
65
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/commands/helpers.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/commands/helpers.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAStD,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,gBA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B,aAAa,CACjC,eAAe,EAAE,MAAM,EACvB,MAAM,GAAE,SAAqB,mBAoB9B;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAwCnE;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAO3E;AAsCD;;GAEG;AACH,wBAAsB,cAAc,CAClC,IAAI,CAAC,EAAE,MAAM,EACb,SAAS,SAAO,GACf,OAAO,CAAC,OAAO,CAAC,CAsBlB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,0BAA0B,CAC9C,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,MAAM,GAAE,SAAqB,EAC7B,UAAU,CAAC,EAAE,gBAAgB,EAC7B,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,IAAI,CAAC,CA2If"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/commands/server.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAEhD,OAAO,KAAK,EAAE,mBAAmB,EAAgB,MAAM,kBAAkB,CAAC;AAE1E,qBAAa,aAAa;IACZ,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,mBAAmB;IAEzC,MAAM,CAAC,IAAI,EAAE,kBAAkB,CAAC,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/commands/server.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAEhD,OAAO,KAAK,EAAE,mBAAmB,EAAgB,MAAM,kBAAkB,CAAC;AAE1E,qBAAa,aAAa;IACZ,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,mBAAmB;IAEzC,MAAM,CAAC,IAAI,EAAE,kBAAkB,CAAC,GAAG,CAAC;YAmP5B,cAAc;IA4C5B,OAAO,CAAC,cAAc;IAUtB,OAAO,CAAC,gBAAgB;YAUV,UAAU;CAiDzB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"brain-history.d.ts","sourceRoot":"","sources":["../../../src/components/brain-history.tsx"],"names":[],"mappings":"AAMA,UAAU,iBAAiB;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf;AAmFD,eAAO,MAAM,YAAY,GAAI,sBAAsB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"brain-history.d.ts","sourceRoot":"","sources":["../../../src/components/brain-history.tsx"],"names":[],"mappings":"AAMA,UAAU,iBAAiB;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf;AAmFD,eAAO,MAAM,YAAY,GAAI,sBAAsB,iBAAiB,4CA8FnE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@positronic/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.36",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"clean": "rm -rf tsconfig.tsbuildinfo dist node_modules"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@positronic/core": "^0.0.
|
|
27
|
-
"@positronic/spec": "^0.0.
|
|
28
|
-
"@positronic/template-new-project": "^0.0.
|
|
26
|
+
"@positronic/core": "^0.0.36",
|
|
27
|
+
"@positronic/spec": "^0.0.36",
|
|
28
|
+
"@positronic/template-new-project": "^0.0.36",
|
|
29
29
|
"caz": "^2.0.0",
|
|
30
30
|
"chokidar": "^3.6.0",
|
|
31
31
|
"dotenv": "^16.4.7",
|