@positronic/cli 0.0.55 → 0.0.57
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/cli.js +142 -2
- package/dist/src/commands/auth.js +98 -0
- package/dist/src/commands/brain.js +3 -2
- package/dist/src/commands/helpers.js +48 -10
- package/dist/src/commands/project-config-manager.js +119 -0
- package/dist/src/commands/users.js +91 -0
- package/dist/src/components/agent-chat-view.js +125 -0
- package/dist/src/components/auth-list.js +56 -0
- package/dist/src/components/auth-login.js +209 -0
- package/dist/src/components/auth-logout.js +75 -0
- package/dist/src/components/auth-status.js +88 -0
- package/dist/src/components/brain-run.js +287 -254
- package/dist/src/components/brain-top-table.js +4 -0
- package/dist/src/components/event-detail.js +364 -0
- package/dist/src/components/events-view.js +379 -0
- package/dist/src/components/state-view.js +52 -0
- package/dist/src/components/top-navigator.js +80 -6
- package/dist/src/components/types.js +1 -0
- package/dist/src/components/users-create.js +293 -0
- package/dist/src/components/users-delete.js +294 -0
- package/dist/src/components/users-keys-add.js +156 -0
- package/dist/src/components/users-keys-list.js +119 -0
- package/dist/src/components/users-keys-remove.js +299 -0
- package/dist/src/components/users-list.js +109 -0
- package/dist/src/components/watch-keyboard.js +136 -0
- package/dist/src/components/watch-machine.js +573 -0
- package/dist/src/components/watch-resolver.js +3 -2
- package/dist/src/components/watch.js +390 -36
- package/dist/src/hooks/useApi.js +80 -42
- package/dist/src/lib/request-signer.js +208 -0
- package/dist/src/lib/ssh-key-utils.js +212 -0
- package/dist/src/utils/agent-utils.js +107 -0
- package/dist/types/cli.d.ts.map +1 -1
- package/dist/types/commands/auth.d.ts +36 -0
- package/dist/types/commands/auth.d.ts.map +1 -0
- package/dist/types/commands/brain.d.ts +2 -1
- package/dist/types/commands/brain.d.ts.map +1 -1
- package/dist/types/commands/helpers.d.ts.map +1 -1
- package/dist/types/commands/project-config-manager.d.ts +43 -0
- package/dist/types/commands/project-config-manager.d.ts.map +1 -1
- package/dist/types/commands/users.d.ts +33 -0
- package/dist/types/commands/users.d.ts.map +1 -0
- package/dist/types/components/agent-chat-view.d.ts +12 -0
- package/dist/types/components/agent-chat-view.d.ts.map +1 -0
- package/dist/types/components/auth-list.d.ts +7 -0
- package/dist/types/components/auth-list.d.ts.map +1 -0
- package/dist/types/components/auth-login.d.ts +9 -0
- package/dist/types/components/auth-login.d.ts.map +1 -0
- package/dist/types/components/auth-logout.d.ts +8 -0
- package/dist/types/components/auth-logout.d.ts.map +1 -0
- package/dist/types/components/auth-status.d.ts +7 -0
- package/dist/types/components/auth-status.d.ts.map +1 -0
- package/dist/types/components/brain-run.d.ts +11 -1
- package/dist/types/components/brain-run.d.ts.map +1 -1
- package/dist/types/components/brain-top-table.d.ts.map +1 -1
- package/dist/types/components/event-detail.d.ts +10 -0
- package/dist/types/components/event-detail.d.ts.map +1 -0
- package/dist/types/components/events-view.d.ts +13 -0
- package/dist/types/components/events-view.d.ts.map +1 -0
- package/dist/types/components/state-view.d.ts +13 -0
- package/dist/types/components/state-view.d.ts.map +1 -0
- package/dist/types/components/top-navigator.d.ts.map +1 -1
- package/dist/types/components/types.d.ts +11 -0
- package/dist/types/components/types.d.ts.map +1 -0
- package/dist/types/components/users-create.d.ts +6 -0
- package/dist/types/components/users-create.d.ts.map +1 -0
- package/dist/types/components/users-delete.d.ts +7 -0
- package/dist/types/components/users-delete.d.ts.map +1 -0
- package/dist/types/components/users-keys-add.d.ts +8 -0
- package/dist/types/components/users-keys-add.d.ts.map +1 -0
- package/dist/types/components/users-keys-list.d.ts +6 -0
- package/dist/types/components/users-keys-list.d.ts.map +1 -0
- package/dist/types/components/users-keys-remove.d.ts +8 -0
- package/dist/types/components/users-keys-remove.d.ts.map +1 -0
- package/dist/types/components/users-list.d.ts +2 -0
- package/dist/types/components/users-list.d.ts.map +1 -0
- package/dist/types/components/watch-keyboard.d.ts +56 -0
- package/dist/types/components/watch-keyboard.d.ts.map +1 -0
- package/dist/types/components/watch-machine.d.ts +171 -0
- package/dist/types/components/watch-machine.d.ts.map +1 -0
- package/dist/types/components/watch-resolver.d.ts +2 -1
- package/dist/types/components/watch-resolver.d.ts.map +1 -1
- package/dist/types/components/watch.d.ts +2 -1
- package/dist/types/components/watch.d.ts.map +1 -1
- package/dist/types/hooks/useApi.d.ts.map +1 -1
- package/dist/types/hooks/useBrainMachine.d.ts +9 -3
- package/dist/types/hooks/useBrainMachine.d.ts.map +1 -1
- package/dist/types/lib/request-signer.d.ts +51 -0
- package/dist/types/lib/request-signer.d.ts.map +1 -0
- package/dist/types/lib/ssh-key-utils.d.ts +45 -0
- package/dist/types/lib/ssh-key-utils.d.ts.map +1 -0
- package/dist/types/utils/agent-utils.d.ts +20 -0
- package/dist/types/utils/agent-utils.d.ts.map +1 -0
- package/package.json +7 -4
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _array_without_holes(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
8
|
+
}
|
|
9
|
+
function _iterable_to_array(iter) {
|
|
10
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
11
|
+
}
|
|
12
|
+
function _non_iterable_spread() {
|
|
13
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
14
|
+
}
|
|
15
|
+
function _to_consumable_array(arr) {
|
|
16
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
17
|
+
}
|
|
18
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
19
|
+
if (!o) return;
|
|
20
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
21
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
22
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
23
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
24
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
25
|
+
}
|
|
26
|
+
import React from 'react';
|
|
27
|
+
import { Text, Box, useStdout, useInput } from 'ink';
|
|
28
|
+
export var AgentChatView = function(param) {
|
|
29
|
+
var label = param.label, agentStartEvent = param.agentStartEvent, rawResponseEvents = param.rawResponseEvents, scrollOffset = param.scrollOffset, onScrollChange = param.onScrollChange, _param_isActive = param.isActive, isActive = _param_isActive === void 0 ? true : _param_isActive;
|
|
30
|
+
var stdout = useStdout().stdout;
|
|
31
|
+
var terminalHeight = (stdout === null || stdout === void 0 ? void 0 : stdout.rows) || 24;
|
|
32
|
+
// Reserve lines for header, footer, margins
|
|
33
|
+
var maxLines = Math.max(5, terminalHeight - 6);
|
|
34
|
+
// Build content as array of lines
|
|
35
|
+
var lines = [];
|
|
36
|
+
// Prompt section
|
|
37
|
+
lines.push('Prompt:');
|
|
38
|
+
lines.push(JSON.stringify(agentStartEvent.prompt, null, 2));
|
|
39
|
+
lines.push('');
|
|
40
|
+
// System section (if present)
|
|
41
|
+
if (agentStartEvent.system) {
|
|
42
|
+
lines.push('System:');
|
|
43
|
+
lines.push(JSON.stringify(agentStartEvent.system, null, 2));
|
|
44
|
+
lines.push('');
|
|
45
|
+
}
|
|
46
|
+
// Messages section - each event now contains a single message
|
|
47
|
+
if (rawResponseEvents.length > 0) {
|
|
48
|
+
lines.push('Messages:');
|
|
49
|
+
lines.push('');
|
|
50
|
+
var currentIteration = 0;
|
|
51
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
52
|
+
try {
|
|
53
|
+
for(var _iterator = rawResponseEvents[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
54
|
+
var event = _step.value;
|
|
55
|
+
var _lines;
|
|
56
|
+
// Add iteration header when iteration changes
|
|
57
|
+
if (event.iteration !== currentIteration) {
|
|
58
|
+
currentIteration = event.iteration;
|
|
59
|
+
lines.push("--- Iteration ".concat(event.iteration, " ---"));
|
|
60
|
+
lines.push('');
|
|
61
|
+
}
|
|
62
|
+
// Each event contains a single message
|
|
63
|
+
var messageJson = JSON.stringify(event.message, null, 2);
|
|
64
|
+
(_lines = lines).push.apply(_lines, _to_consumable_array(messageJson.split('\n')));
|
|
65
|
+
lines.push('');
|
|
66
|
+
}
|
|
67
|
+
} catch (err) {
|
|
68
|
+
_didIteratorError = true;
|
|
69
|
+
_iteratorError = err;
|
|
70
|
+
} finally{
|
|
71
|
+
try {
|
|
72
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
73
|
+
_iterator.return();
|
|
74
|
+
}
|
|
75
|
+
} finally{
|
|
76
|
+
if (_didIteratorError) {
|
|
77
|
+
throw _iteratorError;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
} else {
|
|
82
|
+
lines.push('No response messages yet.');
|
|
83
|
+
}
|
|
84
|
+
var totalLines = lines.length;
|
|
85
|
+
var maxScroll = Math.max(0, totalLines - maxLines);
|
|
86
|
+
// Page size keeps 2 lines of context
|
|
87
|
+
var pageSize = Math.max(1, maxLines - 2);
|
|
88
|
+
// Handle scrolling
|
|
89
|
+
useInput(function(input, key) {
|
|
90
|
+
if (!isActive) return;
|
|
91
|
+
if (key.upArrow || input === 'k') {
|
|
92
|
+
onScrollChange(Math.max(0, scrollOffset - 1));
|
|
93
|
+
} else if (key.downArrow || input === 'j') {
|
|
94
|
+
onScrollChange(Math.min(maxScroll, scrollOffset + 1));
|
|
95
|
+
} else if (input === ' ' && !key.shift) {
|
|
96
|
+
// Space = page down
|
|
97
|
+
onScrollChange(Math.min(maxScroll, scrollOffset + pageSize));
|
|
98
|
+
} else if (input === ' ' && key.shift) {
|
|
99
|
+
// Shift+Space = page up
|
|
100
|
+
onScrollChange(Math.max(0, scrollOffset - pageSize));
|
|
101
|
+
}
|
|
102
|
+
}, {
|
|
103
|
+
isActive: isActive
|
|
104
|
+
});
|
|
105
|
+
var visibleLines = lines.slice(scrollOffset, scrollOffset + maxLines);
|
|
106
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
107
|
+
flexDirection: "column"
|
|
108
|
+
}, /*#__PURE__*/ React.createElement(Box, {
|
|
109
|
+
marginBottom: 1
|
|
110
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
111
|
+
bold: true,
|
|
112
|
+
color: "cyan"
|
|
113
|
+
}, 'Agent: "', label, '"')), /*#__PURE__*/ React.createElement(Box, {
|
|
114
|
+
flexDirection: "column",
|
|
115
|
+
marginLeft: 2
|
|
116
|
+
}, visibleLines.map(function(line, i) {
|
|
117
|
+
return /*#__PURE__*/ React.createElement(Text, {
|
|
118
|
+
key: scrollOffset + i
|
|
119
|
+
}, line);
|
|
120
|
+
})), totalLines > maxLines && /*#__PURE__*/ React.createElement(Box, {
|
|
121
|
+
marginTop: 1
|
|
122
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
123
|
+
dimColor: true
|
|
124
|
+
}, "Lines ", scrollOffset + 1, "-", Math.min(scrollOffset + maxLines, totalLines), " of ", totalLines)));
|
|
125
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Box, Text } from 'ink';
|
|
3
|
+
import { discoverSSHKeys, resolvePrivateKeyPath } from '../lib/ssh-key-utils.js';
|
|
4
|
+
export var AuthList = function(param) {
|
|
5
|
+
var configManager = param.configManager;
|
|
6
|
+
var discoveredKeys = discoverSSHKeys();
|
|
7
|
+
// Get the currently active key path for comparison
|
|
8
|
+
var configuredPath = configManager.getPrivateKeyPath();
|
|
9
|
+
var activeKeyPath = resolvePrivateKeyPath(configuredPath);
|
|
10
|
+
if (discoveredKeys.length === 0) {
|
|
11
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
12
|
+
flexDirection: "column",
|
|
13
|
+
paddingTop: 1,
|
|
14
|
+
paddingBottom: 1
|
|
15
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
16
|
+
color: "yellow"
|
|
17
|
+
}, "No SSH keys found in ~/.ssh/"), /*#__PURE__*/ React.createElement(Box, {
|
|
18
|
+
marginTop: 1
|
|
19
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
20
|
+
dimColor: true
|
|
21
|
+
}, "Generate a new SSH key with: ssh-keygen -t ed25519")));
|
|
22
|
+
}
|
|
23
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
24
|
+
flexDirection: "column",
|
|
25
|
+
paddingTop: 1,
|
|
26
|
+
paddingBottom: 1
|
|
27
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
28
|
+
bold: true
|
|
29
|
+
}, "Available SSH Keys (", discoveredKeys.length, "):"), /*#__PURE__*/ React.createElement(Box, {
|
|
30
|
+
marginTop: 1,
|
|
31
|
+
flexDirection: "column"
|
|
32
|
+
}, discoveredKeys.map(function(key, index) {
|
|
33
|
+
var displayPath = key.path.replace(process.env.HOME || '', '~');
|
|
34
|
+
var isActive = key.path === activeKeyPath;
|
|
35
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
36
|
+
key: key.path,
|
|
37
|
+
flexDirection: "column",
|
|
38
|
+
marginBottom: 1
|
|
39
|
+
}, /*#__PURE__*/ React.createElement(Text, null, isActive ? /*#__PURE__*/ React.createElement(Text, {
|
|
40
|
+
color: "green"
|
|
41
|
+
}, "* ") : /*#__PURE__*/ React.createElement(Text, null, " "), /*#__PURE__*/ React.createElement(Text, {
|
|
42
|
+
bold: true,
|
|
43
|
+
color: isActive ? 'green' : undefined
|
|
44
|
+
}, displayPath)), /*#__PURE__*/ React.createElement(Box, {
|
|
45
|
+
paddingLeft: 4
|
|
46
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
47
|
+
dimColor: true
|
|
48
|
+
}, key.algorithm, " - ", key.fingerprint, key.comment ? " (".concat(key.comment, ")") : '')));
|
|
49
|
+
})), /*#__PURE__*/ React.createElement(Box, {
|
|
50
|
+
marginTop: 1
|
|
51
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
52
|
+
dimColor: true
|
|
53
|
+
}, "* = currently active key")), /*#__PURE__*/ React.createElement(Box, null, /*#__PURE__*/ React.createElement(Text, {
|
|
54
|
+
dimColor: true
|
|
55
|
+
}, 'Run "px auth login" to configure which key to use.')));
|
|
56
|
+
};
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _array_with_holes(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return arr;
|
|
8
|
+
}
|
|
9
|
+
function _iterable_to_array_limit(arr, i) {
|
|
10
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
11
|
+
if (_i == null) return;
|
|
12
|
+
var _arr = [];
|
|
13
|
+
var _n = true;
|
|
14
|
+
var _d = false;
|
|
15
|
+
var _s, _e;
|
|
16
|
+
try {
|
|
17
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
18
|
+
_arr.push(_s.value);
|
|
19
|
+
if (i && _arr.length === i) break;
|
|
20
|
+
}
|
|
21
|
+
} catch (err) {
|
|
22
|
+
_d = true;
|
|
23
|
+
_e = err;
|
|
24
|
+
} finally{
|
|
25
|
+
try {
|
|
26
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
27
|
+
} finally{
|
|
28
|
+
if (_d) throw _e;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return _arr;
|
|
32
|
+
}
|
|
33
|
+
function _non_iterable_rest() {
|
|
34
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
35
|
+
}
|
|
36
|
+
function _sliced_to_array(arr, i) {
|
|
37
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
38
|
+
}
|
|
39
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
40
|
+
if (!o) return;
|
|
41
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
42
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
43
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
44
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
45
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
46
|
+
}
|
|
47
|
+
import React, { useState } from 'react';
|
|
48
|
+
import { Box, Text, useApp } from 'ink';
|
|
49
|
+
import { discoverSSHKeys, expandPath } from '../lib/ssh-key-utils.js';
|
|
50
|
+
import { resetRequestSigner } from '../lib/request-signer.js';
|
|
51
|
+
import { SelectList } from './select-list.js';
|
|
52
|
+
import { existsSync } from 'fs';
|
|
53
|
+
export var AuthLogin = function(param) {
|
|
54
|
+
var configManager = param.configManager, keyPath = param.keyPath, forProject = param.forProject;
|
|
55
|
+
var exit = useApp().exit;
|
|
56
|
+
var _useState = _sliced_to_array(useState(keyPath ? 'success' : 'selecting'), 2), state = _useState[0], setState = _useState[1];
|
|
57
|
+
var _useState1 = _sliced_to_array(useState(null), 2), error = _useState1[0], setError = _useState1[1];
|
|
58
|
+
var _useState2 = _sliced_to_array(useState(keyPath || null), 2), selectedPath = _useState2[0], setSelectedPath = _useState2[1];
|
|
59
|
+
var currentProject = configManager.getCurrentProject();
|
|
60
|
+
// If --project flag is used but no project is selected, show error
|
|
61
|
+
if (forProject && !currentProject) {
|
|
62
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
63
|
+
flexDirection: "column",
|
|
64
|
+
paddingTop: 1,
|
|
65
|
+
paddingBottom: 1
|
|
66
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
67
|
+
color: "red"
|
|
68
|
+
}, "Error: No project selected."), /*#__PURE__*/ React.createElement(Box, {
|
|
69
|
+
marginTop: 1
|
|
70
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
71
|
+
dimColor: true
|
|
72
|
+
}, 'Use "px project select" to select a project first, or omit --project to set the global default key.')));
|
|
73
|
+
}
|
|
74
|
+
// If --path is provided, validate and set directly
|
|
75
|
+
if (keyPath && state === 'success') {
|
|
76
|
+
var expandedPath = expandPath(keyPath);
|
|
77
|
+
if (!existsSync(expandedPath)) {
|
|
78
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
79
|
+
flexDirection: "column",
|
|
80
|
+
paddingTop: 1,
|
|
81
|
+
paddingBottom: 1
|
|
82
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
83
|
+
color: "red"
|
|
84
|
+
}, "Error: Key file not found at ", keyPath), /*#__PURE__*/ React.createElement(Box, {
|
|
85
|
+
marginTop: 1
|
|
86
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
87
|
+
dimColor: true
|
|
88
|
+
}, "Please verify the path and try again.")));
|
|
89
|
+
}
|
|
90
|
+
// Set the key
|
|
91
|
+
if (forProject && currentProject) {
|
|
92
|
+
var result = configManager.setProjectPrivateKeyPath(currentProject.name, keyPath);
|
|
93
|
+
if (!result.success) {
|
|
94
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
95
|
+
flexDirection: "column",
|
|
96
|
+
paddingTop: 1,
|
|
97
|
+
paddingBottom: 1
|
|
98
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
99
|
+
color: "red"
|
|
100
|
+
}, "Error: ", result.error));
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
configManager.setDefaultPrivateKeyPath(keyPath);
|
|
104
|
+
}
|
|
105
|
+
// Reset request signer to use new key
|
|
106
|
+
resetRequestSigner();
|
|
107
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
108
|
+
flexDirection: "column",
|
|
109
|
+
paddingTop: 1,
|
|
110
|
+
paddingBottom: 1
|
|
111
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
112
|
+
color: "green"
|
|
113
|
+
}, "SSH key configured successfully."), /*#__PURE__*/ React.createElement(Box, {
|
|
114
|
+
marginTop: 1,
|
|
115
|
+
paddingLeft: 2
|
|
116
|
+
}, /*#__PURE__*/ React.createElement(Text, null, /*#__PURE__*/ React.createElement(Text, {
|
|
117
|
+
bold: true
|
|
118
|
+
}, "Path:"), " ", keyPath)), /*#__PURE__*/ React.createElement(Box, {
|
|
119
|
+
paddingLeft: 2
|
|
120
|
+
}, /*#__PURE__*/ React.createElement(Text, null, /*#__PURE__*/ React.createElement(Text, {
|
|
121
|
+
bold: true
|
|
122
|
+
}, "Scope:"), ' ', forProject && currentProject ? 'project "'.concat(currentProject.name, '"') : 'global')));
|
|
123
|
+
}
|
|
124
|
+
// Interactive key selection
|
|
125
|
+
if (state === 'selecting') {
|
|
126
|
+
var discoveredKeys = discoverSSHKeys();
|
|
127
|
+
if (discoveredKeys.length === 0) {
|
|
128
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
129
|
+
flexDirection: "column",
|
|
130
|
+
paddingTop: 1,
|
|
131
|
+
paddingBottom: 1
|
|
132
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
133
|
+
color: "yellow"
|
|
134
|
+
}, "No SSH keys found in ~/.ssh/"), /*#__PURE__*/ React.createElement(Box, {
|
|
135
|
+
marginTop: 1
|
|
136
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
137
|
+
dimColor: true
|
|
138
|
+
}, "Generate a new SSH key with: ssh-keygen -t ed25519")), /*#__PURE__*/ React.createElement(Box, {
|
|
139
|
+
marginTop: 1
|
|
140
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
141
|
+
dimColor: true
|
|
142
|
+
}, "Or specify a custom path with: px auth login --path /path/to/key")));
|
|
143
|
+
}
|
|
144
|
+
var items = discoveredKeys.map(function(key) {
|
|
145
|
+
return {
|
|
146
|
+
id: key.path,
|
|
147
|
+
label: key.path.replace(process.env.HOME || '', '~'),
|
|
148
|
+
description: "".concat(key.algorithm, " - ").concat(key.fingerprint).concat(key.comment ? " (".concat(key.comment, ")") : '')
|
|
149
|
+
};
|
|
150
|
+
});
|
|
151
|
+
var handleSelect = function(item) {
|
|
152
|
+
var originalPath = item.id;
|
|
153
|
+
// Store with ~ prefix for portability
|
|
154
|
+
var displayPath = originalPath.replace(process.env.HOME || '', '~');
|
|
155
|
+
if (forProject && currentProject) {
|
|
156
|
+
var result = configManager.setProjectPrivateKeyPath(currentProject.name, displayPath);
|
|
157
|
+
if (!result.success) {
|
|
158
|
+
setError(result.error || 'Unknown error');
|
|
159
|
+
setState('error');
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
} else {
|
|
163
|
+
configManager.setDefaultPrivateKeyPath(displayPath);
|
|
164
|
+
}
|
|
165
|
+
// Reset request signer to use new key
|
|
166
|
+
resetRequestSigner();
|
|
167
|
+
setSelectedPath(displayPath);
|
|
168
|
+
setState('success');
|
|
169
|
+
};
|
|
170
|
+
var handleCancel = function() {
|
|
171
|
+
exit();
|
|
172
|
+
};
|
|
173
|
+
return /*#__PURE__*/ React.createElement(SelectList, {
|
|
174
|
+
items: items,
|
|
175
|
+
header: "Select an SSH key".concat(forProject && currentProject ? ' for project "'.concat(currentProject.name, '"') : ' (global)'),
|
|
176
|
+
onSelect: handleSelect,
|
|
177
|
+
onCancel: handleCancel,
|
|
178
|
+
footer: "Use arrow keys to navigate, Enter to select, q to cancel"
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
if (state === 'success' && selectedPath) {
|
|
182
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
183
|
+
flexDirection: "column",
|
|
184
|
+
paddingTop: 1,
|
|
185
|
+
paddingBottom: 1
|
|
186
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
187
|
+
color: "green"
|
|
188
|
+
}, "SSH key configured successfully."), /*#__PURE__*/ React.createElement(Box, {
|
|
189
|
+
marginTop: 1,
|
|
190
|
+
paddingLeft: 2
|
|
191
|
+
}, /*#__PURE__*/ React.createElement(Text, null, /*#__PURE__*/ React.createElement(Text, {
|
|
192
|
+
bold: true
|
|
193
|
+
}, "Path:"), " ", selectedPath)), /*#__PURE__*/ React.createElement(Box, {
|
|
194
|
+
paddingLeft: 2
|
|
195
|
+
}, /*#__PURE__*/ React.createElement(Text, null, /*#__PURE__*/ React.createElement(Text, {
|
|
196
|
+
bold: true
|
|
197
|
+
}, "Scope:"), ' ', forProject && currentProject ? 'project "'.concat(currentProject.name, '"') : 'global')));
|
|
198
|
+
}
|
|
199
|
+
if (state === 'error') {
|
|
200
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
201
|
+
flexDirection: "column",
|
|
202
|
+
paddingTop: 1,
|
|
203
|
+
paddingBottom: 1
|
|
204
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
205
|
+
color: "red"
|
|
206
|
+
}, "Error: ", error));
|
|
207
|
+
}
|
|
208
|
+
return null;
|
|
209
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Box, Text } from 'ink';
|
|
3
|
+
import { resetRequestSigner } from '../lib/request-signer.js';
|
|
4
|
+
export var AuthLogout = function(param) {
|
|
5
|
+
var configManager = param.configManager, forProject = param.forProject;
|
|
6
|
+
var currentProject = configManager.getCurrentProject();
|
|
7
|
+
// If --project flag is used but no project is selected, show error
|
|
8
|
+
if (forProject && !currentProject) {
|
|
9
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
10
|
+
flexDirection: "column",
|
|
11
|
+
paddingTop: 1,
|
|
12
|
+
paddingBottom: 1
|
|
13
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
14
|
+
color: "red"
|
|
15
|
+
}, "Error: No project selected."), /*#__PURE__*/ React.createElement(Box, {
|
|
16
|
+
marginTop: 1
|
|
17
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
18
|
+
dimColor: true
|
|
19
|
+
}, 'Use "px project select" to select a project first, or omit --project to clear the global default key.')));
|
|
20
|
+
}
|
|
21
|
+
if (forProject && currentProject) {
|
|
22
|
+
// Clear per-project key
|
|
23
|
+
var projectKeyPath = configManager.getProjectPrivateKeyPath(currentProject.name);
|
|
24
|
+
if (!projectKeyPath) {
|
|
25
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
26
|
+
flexDirection: "column",
|
|
27
|
+
paddingTop: 1,
|
|
28
|
+
paddingBottom: 1
|
|
29
|
+
}, /*#__PURE__*/ React.createElement(Text, null, 'No SSH key configured for project "', currentProject.name, '".'), /*#__PURE__*/ React.createElement(Box, {
|
|
30
|
+
marginTop: 1
|
|
31
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
32
|
+
dimColor: true
|
|
33
|
+
}, "Nothing to clear.")));
|
|
34
|
+
}
|
|
35
|
+
configManager.clearProjectPrivateKeyPath(currentProject.name);
|
|
36
|
+
resetRequestSigner();
|
|
37
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
38
|
+
flexDirection: "column",
|
|
39
|
+
paddingTop: 1,
|
|
40
|
+
paddingBottom: 1
|
|
41
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
42
|
+
color: "green"
|
|
43
|
+
}, 'SSH key cleared for project "', currentProject.name, '".'), /*#__PURE__*/ React.createElement(Box, {
|
|
44
|
+
marginTop: 1
|
|
45
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
46
|
+
dimColor: true
|
|
47
|
+
}, "The project will now use the global default key (if configured).")));
|
|
48
|
+
}
|
|
49
|
+
// Clear global default key
|
|
50
|
+
var globalKeyPath = configManager.getDefaultPrivateKeyPath();
|
|
51
|
+
if (!globalKeyPath) {
|
|
52
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
53
|
+
flexDirection: "column",
|
|
54
|
+
paddingTop: 1,
|
|
55
|
+
paddingBottom: 1
|
|
56
|
+
}, /*#__PURE__*/ React.createElement(Text, null, "No global SSH key configured."), /*#__PURE__*/ React.createElement(Box, {
|
|
57
|
+
marginTop: 1
|
|
58
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
59
|
+
dimColor: true
|
|
60
|
+
}, "Nothing to clear.")));
|
|
61
|
+
}
|
|
62
|
+
configManager.clearDefaultPrivateKeyPath();
|
|
63
|
+
resetRequestSigner();
|
|
64
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
65
|
+
flexDirection: "column",
|
|
66
|
+
paddingTop: 1,
|
|
67
|
+
paddingBottom: 1
|
|
68
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
69
|
+
color: "green"
|
|
70
|
+
}, "Global SSH key configuration cleared."), /*#__PURE__*/ React.createElement(Box, {
|
|
71
|
+
marginTop: 1
|
|
72
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
73
|
+
dimColor: true
|
|
74
|
+
}, "Requests will now use the default key (~/.ssh/id_rsa) unless POSITRONIC_PRIVATE_KEY is set.")));
|
|
75
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Box, Text } from 'ink';
|
|
3
|
+
import { resolvePrivateKeyPath } from '../lib/ssh-key-utils.js';
|
|
4
|
+
import { existsSync } from 'fs';
|
|
5
|
+
export var AuthStatus = function(param) {
|
|
6
|
+
var configManager = param.configManager;
|
|
7
|
+
var envPath = process.env.POSITRONIC_PRIVATE_KEY;
|
|
8
|
+
var globalKeyPath = configManager.getDefaultPrivateKeyPath();
|
|
9
|
+
var currentProject = configManager.getCurrentProject();
|
|
10
|
+
var projectKeyPath = currentProject ? configManager.getProjectPrivateKeyPath(currentProject.name) : undefined;
|
|
11
|
+
// Determine the active key path (what will actually be used)
|
|
12
|
+
var configuredPath = configManager.getPrivateKeyPath();
|
|
13
|
+
var activeKeyPath = resolvePrivateKeyPath(configuredPath);
|
|
14
|
+
var keyExists = existsSync(activeKeyPath);
|
|
15
|
+
// Determine which source is being used
|
|
16
|
+
var activeSource;
|
|
17
|
+
if (envPath) {
|
|
18
|
+
activeSource = 'environment variable';
|
|
19
|
+
} else if (projectKeyPath && currentProject) {
|
|
20
|
+
activeSource = 'project "'.concat(currentProject.name, '"');
|
|
21
|
+
} else if (globalKeyPath) {
|
|
22
|
+
activeSource = 'global config';
|
|
23
|
+
} else {
|
|
24
|
+
activeSource = 'default fallback';
|
|
25
|
+
}
|
|
26
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
27
|
+
flexDirection: "column",
|
|
28
|
+
paddingTop: 1,
|
|
29
|
+
paddingBottom: 1
|
|
30
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
31
|
+
bold: true
|
|
32
|
+
}, "Authentication Configuration"), /*#__PURE__*/ React.createElement(Box, {
|
|
33
|
+
marginTop: 1,
|
|
34
|
+
flexDirection: "column",
|
|
35
|
+
paddingLeft: 2
|
|
36
|
+
}, /*#__PURE__*/ React.createElement(Box, {
|
|
37
|
+
flexDirection: "column",
|
|
38
|
+
marginBottom: 1
|
|
39
|
+
}, /*#__PURE__*/ React.createElement(Text, null, /*#__PURE__*/ React.createElement(Text, {
|
|
40
|
+
bold: true
|
|
41
|
+
}, "Environment Variable:"), ' ', envPath ? /*#__PURE__*/ React.createElement(Text, {
|
|
42
|
+
color: "cyan"
|
|
43
|
+
}, envPath) : /*#__PURE__*/ React.createElement(Text, {
|
|
44
|
+
dimColor: true
|
|
45
|
+
}, "not set")), envPath && /*#__PURE__*/ React.createElement(Box, {
|
|
46
|
+
paddingLeft: 2
|
|
47
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
48
|
+
dimColor: true
|
|
49
|
+
}, "(POSITRONIC_PRIVATE_KEY - highest priority)"))), /*#__PURE__*/ React.createElement(Box, {
|
|
50
|
+
flexDirection: "column",
|
|
51
|
+
marginBottom: 1
|
|
52
|
+
}, /*#__PURE__*/ React.createElement(Text, null, /*#__PURE__*/ React.createElement(Text, {
|
|
53
|
+
bold: true
|
|
54
|
+
}, "Global Default Key:"), ' ', globalKeyPath ? /*#__PURE__*/ React.createElement(Text, {
|
|
55
|
+
color: "cyan"
|
|
56
|
+
}, globalKeyPath) : /*#__PURE__*/ React.createElement(Text, {
|
|
57
|
+
dimColor: true
|
|
58
|
+
}, "not configured"))), currentProject && /*#__PURE__*/ React.createElement(Box, {
|
|
59
|
+
flexDirection: "column",
|
|
60
|
+
marginBottom: 1
|
|
61
|
+
}, /*#__PURE__*/ React.createElement(Text, null, /*#__PURE__*/ React.createElement(Text, {
|
|
62
|
+
bold: true
|
|
63
|
+
}, "Project Key (", currentProject.name, "):"), ' ', projectKeyPath ? /*#__PURE__*/ React.createElement(Text, {
|
|
64
|
+
color: "cyan"
|
|
65
|
+
}, projectKeyPath) : /*#__PURE__*/ React.createElement(Text, {
|
|
66
|
+
dimColor: true
|
|
67
|
+
}, "not configured (uses global)"))), /*#__PURE__*/ React.createElement(Box, {
|
|
68
|
+
marginTop: 1,
|
|
69
|
+
flexDirection: "column"
|
|
70
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
71
|
+
bold: true
|
|
72
|
+
}, "Active Key:"), /*#__PURE__*/ React.createElement(Box, {
|
|
73
|
+
paddingLeft: 2,
|
|
74
|
+
flexDirection: "column"
|
|
75
|
+
}, /*#__PURE__*/ React.createElement(Text, null, "Path: ", /*#__PURE__*/ React.createElement(Text, {
|
|
76
|
+
color: keyExists ? 'green' : 'red'
|
|
77
|
+
}, activeKeyPath)), /*#__PURE__*/ React.createElement(Text, null, "Source: ", /*#__PURE__*/ React.createElement(Text, {
|
|
78
|
+
dimColor: true
|
|
79
|
+
}, activeSource)), /*#__PURE__*/ React.createElement(Text, null, "Status:", ' ', keyExists ? /*#__PURE__*/ React.createElement(Text, {
|
|
80
|
+
color: "green"
|
|
81
|
+
}, "key file found") : /*#__PURE__*/ React.createElement(Text, {
|
|
82
|
+
color: "red"
|
|
83
|
+
}, "key file not found"))))), !globalKeyPath && !envPath && !projectKeyPath && /*#__PURE__*/ React.createElement(Box, {
|
|
84
|
+
marginTop: 1
|
|
85
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
86
|
+
dimColor: true
|
|
87
|
+
}, 'Run "px auth login" to configure your SSH key for authentication.')));
|
|
88
|
+
};
|