@positronic/cli 0.0.56 → 0.0.58
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 +139 -0
- package/dist/src/commands/auth.js +111 -0
- package/dist/src/commands/helpers.js +68 -8
- 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-format-jwk-key.js +457 -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 +221 -25
- 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.js +357 -44
- package/dist/src/hooks/useApi.js +217 -45
- 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 +44 -0
- package/dist/types/commands/auth.d.ts.map +1 -0
- package/dist/types/commands/helpers.d.ts +4 -0
- 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-format-jwk-key.d.ts +6 -0
- package/dist/types/components/auth-format-jwk-key.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 +9 -7
- package/dist/types/components/events-view.d.ts.map +1 -1
- 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.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,457 @@
|
|
|
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 asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
10
|
+
try {
|
|
11
|
+
var info = gen[key](arg);
|
|
12
|
+
var value = info.value;
|
|
13
|
+
} catch (error) {
|
|
14
|
+
reject(error);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (info.done) {
|
|
18
|
+
resolve(value);
|
|
19
|
+
} else {
|
|
20
|
+
Promise.resolve(value).then(_next, _throw);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function _async_to_generator(fn) {
|
|
24
|
+
return function() {
|
|
25
|
+
var self = this, args = arguments;
|
|
26
|
+
return new Promise(function(resolve, reject) {
|
|
27
|
+
var gen = fn.apply(self, args);
|
|
28
|
+
function _next(value) {
|
|
29
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
30
|
+
}
|
|
31
|
+
function _throw(err) {
|
|
32
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
33
|
+
}
|
|
34
|
+
_next(undefined);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function _iterable_to_array_limit(arr, i) {
|
|
39
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
40
|
+
if (_i == null) return;
|
|
41
|
+
var _arr = [];
|
|
42
|
+
var _n = true;
|
|
43
|
+
var _d = false;
|
|
44
|
+
var _s, _e;
|
|
45
|
+
try {
|
|
46
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
47
|
+
_arr.push(_s.value);
|
|
48
|
+
if (i && _arr.length === i) break;
|
|
49
|
+
}
|
|
50
|
+
} catch (err) {
|
|
51
|
+
_d = true;
|
|
52
|
+
_e = err;
|
|
53
|
+
} finally{
|
|
54
|
+
try {
|
|
55
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
56
|
+
} finally{
|
|
57
|
+
if (_d) throw _e;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return _arr;
|
|
61
|
+
}
|
|
62
|
+
function _non_iterable_rest() {
|
|
63
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
64
|
+
}
|
|
65
|
+
function _sliced_to_array(arr, i) {
|
|
66
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
67
|
+
}
|
|
68
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
69
|
+
if (!o) return;
|
|
70
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
71
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
72
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
73
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
74
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
75
|
+
}
|
|
76
|
+
function _ts_generator(thisArg, body) {
|
|
77
|
+
var f, y, t, _ = {
|
|
78
|
+
label: 0,
|
|
79
|
+
sent: function() {
|
|
80
|
+
if (t[0] & 1) throw t[1];
|
|
81
|
+
return t[1];
|
|
82
|
+
},
|
|
83
|
+
trys: [],
|
|
84
|
+
ops: []
|
|
85
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
86
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
87
|
+
return this;
|
|
88
|
+
}), g;
|
|
89
|
+
function verb(n) {
|
|
90
|
+
return function(v) {
|
|
91
|
+
return step([
|
|
92
|
+
n,
|
|
93
|
+
v
|
|
94
|
+
]);
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function step(op) {
|
|
98
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
99
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
100
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
101
|
+
if (y = 0, t) op = [
|
|
102
|
+
op[0] & 2,
|
|
103
|
+
t.value
|
|
104
|
+
];
|
|
105
|
+
switch(op[0]){
|
|
106
|
+
case 0:
|
|
107
|
+
case 1:
|
|
108
|
+
t = op;
|
|
109
|
+
break;
|
|
110
|
+
case 4:
|
|
111
|
+
_.label++;
|
|
112
|
+
return {
|
|
113
|
+
value: op[1],
|
|
114
|
+
done: false
|
|
115
|
+
};
|
|
116
|
+
case 5:
|
|
117
|
+
_.label++;
|
|
118
|
+
y = op[1];
|
|
119
|
+
op = [
|
|
120
|
+
0
|
|
121
|
+
];
|
|
122
|
+
continue;
|
|
123
|
+
case 7:
|
|
124
|
+
op = _.ops.pop();
|
|
125
|
+
_.trys.pop();
|
|
126
|
+
continue;
|
|
127
|
+
default:
|
|
128
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
129
|
+
_ = 0;
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
133
|
+
_.label = op[1];
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
137
|
+
_.label = t[1];
|
|
138
|
+
t = op;
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
if (t && _.label < t[2]) {
|
|
142
|
+
_.label = t[2];
|
|
143
|
+
_.ops.push(op);
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
if (t[2]) _.ops.pop();
|
|
147
|
+
_.trys.pop();
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
op = body.call(thisArg, _);
|
|
151
|
+
} catch (e) {
|
|
152
|
+
op = [
|
|
153
|
+
6,
|
|
154
|
+
e
|
|
155
|
+
];
|
|
156
|
+
y = 0;
|
|
157
|
+
} finally{
|
|
158
|
+
f = t = 0;
|
|
159
|
+
}
|
|
160
|
+
if (op[0] & 5) throw op[1];
|
|
161
|
+
return {
|
|
162
|
+
value: op[0] ? op[1] : void 0,
|
|
163
|
+
done: true
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
import React, { useState, useEffect } from 'react';
|
|
168
|
+
import { Box, Text, useApp } from 'ink';
|
|
169
|
+
import { existsSync, readdirSync } from 'fs';
|
|
170
|
+
import { homedir } from 'os';
|
|
171
|
+
import { join } from 'path';
|
|
172
|
+
import { convertSSHPubKeyToJWK, expandPath } from '../lib/ssh-key-utils.js';
|
|
173
|
+
import { SelectList } from './select-list.js';
|
|
174
|
+
/**
|
|
175
|
+
* Discover available SSH public keys in ~/.ssh
|
|
176
|
+
*/ function discoverSSHPubKeys() {
|
|
177
|
+
var sshDir = join(homedir(), '.ssh');
|
|
178
|
+
if (!existsSync(sshDir)) {
|
|
179
|
+
return [];
|
|
180
|
+
}
|
|
181
|
+
var pubKeys = [];
|
|
182
|
+
try {
|
|
183
|
+
var files = readdirSync(sshDir);
|
|
184
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
185
|
+
try {
|
|
186
|
+
for(var _iterator = files[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
187
|
+
var file = _step.value;
|
|
188
|
+
if (file.endsWith('.pub')) {
|
|
189
|
+
var fullPath = join(sshDir, file);
|
|
190
|
+
pubKeys.push({
|
|
191
|
+
path: fullPath,
|
|
192
|
+
displayPath: "~/.ssh/".concat(file)
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
} catch (err) {
|
|
197
|
+
_didIteratorError = true;
|
|
198
|
+
_iteratorError = err;
|
|
199
|
+
} finally{
|
|
200
|
+
try {
|
|
201
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
202
|
+
_iterator.return();
|
|
203
|
+
}
|
|
204
|
+
} finally{
|
|
205
|
+
if (_didIteratorError) {
|
|
206
|
+
throw _iteratorError;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
} catch (e) {
|
|
211
|
+
return [];
|
|
212
|
+
}
|
|
213
|
+
return pubKeys;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Copy text to clipboard using pbcopy (macOS) or xclip (Linux)
|
|
217
|
+
*/ function copyToClipboard(text) {
|
|
218
|
+
return _async_to_generator(function() {
|
|
219
|
+
var spawn;
|
|
220
|
+
return _ts_generator(this, function(_state) {
|
|
221
|
+
switch(_state.label){
|
|
222
|
+
case 0:
|
|
223
|
+
return [
|
|
224
|
+
4,
|
|
225
|
+
import('child_process')
|
|
226
|
+
];
|
|
227
|
+
case 1:
|
|
228
|
+
spawn = _state.sent().spawn;
|
|
229
|
+
return [
|
|
230
|
+
2,
|
|
231
|
+
new Promise(function(resolve) {
|
|
232
|
+
var _proc_stdin, _proc_stdin1;
|
|
233
|
+
// Try pbcopy first (macOS)
|
|
234
|
+
var proc = spawn('pbcopy', [], {
|
|
235
|
+
stdio: [
|
|
236
|
+
'pipe',
|
|
237
|
+
'ignore',
|
|
238
|
+
'ignore'
|
|
239
|
+
]
|
|
240
|
+
});
|
|
241
|
+
proc.on('error', function() {
|
|
242
|
+
var _proc_stdin, _proc_stdin1;
|
|
243
|
+
// Try xclip (Linux)
|
|
244
|
+
proc = spawn('xclip', [
|
|
245
|
+
'-selection',
|
|
246
|
+
'clipboard'
|
|
247
|
+
], {
|
|
248
|
+
stdio: [
|
|
249
|
+
'pipe',
|
|
250
|
+
'ignore',
|
|
251
|
+
'ignore'
|
|
252
|
+
]
|
|
253
|
+
});
|
|
254
|
+
proc.on('error', function() {
|
|
255
|
+
resolve(false);
|
|
256
|
+
});
|
|
257
|
+
proc.on('close', function(code) {
|
|
258
|
+
resolve(code === 0);
|
|
259
|
+
});
|
|
260
|
+
(_proc_stdin = proc.stdin) === null || _proc_stdin === void 0 ? void 0 : _proc_stdin.write(text);
|
|
261
|
+
(_proc_stdin1 = proc.stdin) === null || _proc_stdin1 === void 0 ? void 0 : _proc_stdin1.end();
|
|
262
|
+
});
|
|
263
|
+
proc.on('close', function(code) {
|
|
264
|
+
resolve(code === 0);
|
|
265
|
+
});
|
|
266
|
+
(_proc_stdin = proc.stdin) === null || _proc_stdin === void 0 ? void 0 : _proc_stdin.write(text);
|
|
267
|
+
(_proc_stdin1 = proc.stdin) === null || _proc_stdin1 === void 0 ? void 0 : _proc_stdin1.end();
|
|
268
|
+
})
|
|
269
|
+
];
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
})();
|
|
273
|
+
}
|
|
274
|
+
export var AuthFormatJwkKey = function(param) {
|
|
275
|
+
var pubkeyPath = param.pubkeyPath;
|
|
276
|
+
var exit = useApp().exit;
|
|
277
|
+
var _useState = _sliced_to_array(useState(pubkeyPath ? 'success' : 'selecting'), 2), state = _useState[0], setState = _useState[1];
|
|
278
|
+
var _useState1 = _sliced_to_array(useState(null), 2), error = _useState1[0], setError = _useState1[1];
|
|
279
|
+
var _useState2 = _sliced_to_array(useState(null), 2), jwkOutput = _useState2[0], setJwkOutput = _useState2[1];
|
|
280
|
+
var _useState3 = _sliced_to_array(useState(null), 2), fingerprint = _useState3[0], setFingerprint = _useState3[1];
|
|
281
|
+
var _useState4 = _sliced_to_array(useState(false), 2), copiedToClipboard = _useState4[0], setCopiedToClipboard = _useState4[1];
|
|
282
|
+
var _useState5 = _sliced_to_array(useState(pubkeyPath || null), 2), selectedPath = _useState5[0], setSelectedPath = _useState5[1];
|
|
283
|
+
// Handle direct path provided via --pubkey
|
|
284
|
+
useEffect(function() {
|
|
285
|
+
if (pubkeyPath && state === 'success' && !jwkOutput) {
|
|
286
|
+
processKey(pubkeyPath);
|
|
287
|
+
}
|
|
288
|
+
}, [
|
|
289
|
+
pubkeyPath,
|
|
290
|
+
state,
|
|
291
|
+
jwkOutput
|
|
292
|
+
]);
|
|
293
|
+
var processKey = function(keyPath) {
|
|
294
|
+
return _async_to_generator(function() {
|
|
295
|
+
var expandedPath, keyInfo, jwkString, copied, err;
|
|
296
|
+
return _ts_generator(this, function(_state) {
|
|
297
|
+
switch(_state.label){
|
|
298
|
+
case 0:
|
|
299
|
+
_state.trys.push([
|
|
300
|
+
0,
|
|
301
|
+
2,
|
|
302
|
+
,
|
|
303
|
+
3
|
|
304
|
+
]);
|
|
305
|
+
expandedPath = expandPath(keyPath);
|
|
306
|
+
if (!existsSync(expandedPath)) {
|
|
307
|
+
setError("Public key file not found: ".concat(keyPath));
|
|
308
|
+
setState('error');
|
|
309
|
+
return [
|
|
310
|
+
2
|
|
311
|
+
];
|
|
312
|
+
}
|
|
313
|
+
keyInfo = convertSSHPubKeyToJWK(expandedPath);
|
|
314
|
+
jwkString = JSON.stringify(keyInfo.jwk, null, 2);
|
|
315
|
+
setJwkOutput(jwkString);
|
|
316
|
+
setFingerprint(keyInfo.fingerprint);
|
|
317
|
+
setSelectedPath(keyPath);
|
|
318
|
+
return [
|
|
319
|
+
4,
|
|
320
|
+
copyToClipboard(jwkString)
|
|
321
|
+
];
|
|
322
|
+
case 1:
|
|
323
|
+
copied = _state.sent();
|
|
324
|
+
setCopiedToClipboard(copied);
|
|
325
|
+
setState('success');
|
|
326
|
+
return [
|
|
327
|
+
3,
|
|
328
|
+
3
|
|
329
|
+
];
|
|
330
|
+
case 2:
|
|
331
|
+
err = _state.sent();
|
|
332
|
+
setError(err.message || 'Failed to convert key');
|
|
333
|
+
setState('error');
|
|
334
|
+
return [
|
|
335
|
+
3,
|
|
336
|
+
3
|
|
337
|
+
];
|
|
338
|
+
case 3:
|
|
339
|
+
return [
|
|
340
|
+
2
|
|
341
|
+
];
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
})();
|
|
345
|
+
};
|
|
346
|
+
// Check for available keys when in selecting state
|
|
347
|
+
var pubKeys = discoverSSHPubKeys();
|
|
348
|
+
if (state === 'selecting' && pubKeys.length === 0) {
|
|
349
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
350
|
+
flexDirection: "column",
|
|
351
|
+
paddingTop: 1,
|
|
352
|
+
paddingBottom: 1
|
|
353
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
354
|
+
color: "yellow"
|
|
355
|
+
}, "No SSH public keys found in ~/.ssh/"), /*#__PURE__*/ React.createElement(Box, {
|
|
356
|
+
marginTop: 1,
|
|
357
|
+
flexDirection: "column"
|
|
358
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
359
|
+
dimColor: true
|
|
360
|
+
}, "Generate a new SSH key with:"), /*#__PURE__*/ React.createElement(Box, {
|
|
361
|
+
marginLeft: 2,
|
|
362
|
+
marginTop: 1
|
|
363
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
364
|
+
color: "cyan"
|
|
365
|
+
}, 'ssh-keygen -t ed25519 -C "your-email@example.com"'))), /*#__PURE__*/ React.createElement(Box, {
|
|
366
|
+
marginTop: 1
|
|
367
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
368
|
+
dimColor: true
|
|
369
|
+
}, "Or specify a public key path with: px auth format-jwk-key --pubkey /path/to/key.pub")));
|
|
370
|
+
}
|
|
371
|
+
if (state === 'selecting') {
|
|
372
|
+
var items = pubKeys.map(function(key) {
|
|
373
|
+
return {
|
|
374
|
+
id: key.path,
|
|
375
|
+
label: key.displayPath,
|
|
376
|
+
description: ''
|
|
377
|
+
};
|
|
378
|
+
});
|
|
379
|
+
var handleSelect = function(item) {
|
|
380
|
+
return _async_to_generator(function() {
|
|
381
|
+
return _ts_generator(this, function(_state) {
|
|
382
|
+
switch(_state.label){
|
|
383
|
+
case 0:
|
|
384
|
+
return [
|
|
385
|
+
4,
|
|
386
|
+
processKey(item.id)
|
|
387
|
+
];
|
|
388
|
+
case 1:
|
|
389
|
+
_state.sent();
|
|
390
|
+
return [
|
|
391
|
+
2
|
|
392
|
+
];
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
})();
|
|
396
|
+
};
|
|
397
|
+
var handleCancel = function() {
|
|
398
|
+
exit();
|
|
399
|
+
};
|
|
400
|
+
return /*#__PURE__*/ React.createElement(SelectList, {
|
|
401
|
+
items: items,
|
|
402
|
+
header: "Select an SSH public key to convert to JWK format",
|
|
403
|
+
onSelect: handleSelect,
|
|
404
|
+
onCancel: handleCancel,
|
|
405
|
+
footer: "Use arrow keys to navigate, Enter to select, q to cancel"
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
if (state === 'error') {
|
|
409
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
410
|
+
flexDirection: "column",
|
|
411
|
+
paddingTop: 1,
|
|
412
|
+
paddingBottom: 1
|
|
413
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
414
|
+
color: "red"
|
|
415
|
+
}, "Error: ", error));
|
|
416
|
+
}
|
|
417
|
+
if (state === 'success' && jwkOutput) {
|
|
418
|
+
var displayPath = (selectedPath === null || selectedPath === void 0 ? void 0 : selectedPath.startsWith(homedir())) ? selectedPath.replace(homedir(), '~') : selectedPath;
|
|
419
|
+
return /*#__PURE__*/ React.createElement(Box, {
|
|
420
|
+
flexDirection: "column",
|
|
421
|
+
paddingTop: 1,
|
|
422
|
+
paddingBottom: 1
|
|
423
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
424
|
+
bold: true,
|
|
425
|
+
color: "green"
|
|
426
|
+
}, "JWK Public Key"), /*#__PURE__*/ React.createElement(Box, {
|
|
427
|
+
marginTop: 1
|
|
428
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
429
|
+
dimColor: true
|
|
430
|
+
}, "Source: ", displayPath)), fingerprint && /*#__PURE__*/ React.createElement(Box, null, /*#__PURE__*/ React.createElement(Text, {
|
|
431
|
+
dimColor: true
|
|
432
|
+
}, "Fingerprint: ", fingerprint)), /*#__PURE__*/ React.createElement(Box, {
|
|
433
|
+
marginTop: 1,
|
|
434
|
+
flexDirection: "column"
|
|
435
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
436
|
+
color: "cyan"
|
|
437
|
+
}, jwkOutput)), /*#__PURE__*/ React.createElement(Box, {
|
|
438
|
+
marginTop: 1
|
|
439
|
+
}, copiedToClipboard ? /*#__PURE__*/ React.createElement(Text, {
|
|
440
|
+
color: "green"
|
|
441
|
+
}, "Copied to clipboard.") : /*#__PURE__*/ React.createElement(Text, {
|
|
442
|
+
color: "yellow"
|
|
443
|
+
}, "Could not copy to clipboard - copy the value above manually.")), /*#__PURE__*/ React.createElement(Box, {
|
|
444
|
+
marginTop: 1,
|
|
445
|
+
flexDirection: "column"
|
|
446
|
+
}, /*#__PURE__*/ React.createElement(Text, {
|
|
447
|
+
bold: true
|
|
448
|
+
}, "Next steps:"), /*#__PURE__*/ React.createElement(Box, {
|
|
449
|
+
marginLeft: 2,
|
|
450
|
+
marginTop: 1,
|
|
451
|
+
flexDirection: "column"
|
|
452
|
+
}, /*#__PURE__*/ React.createElement(Text, null, "1. Go to Cloudflare dashboard"), /*#__PURE__*/ React.createElement(Text, null, "2. Navigate to Workers & Pages ", '>', " Your project ", '>', " Settings ", '>', " Variables and Secrets"), /*#__PURE__*/ React.createElement(Text, null, "3. Add a new secret named ", /*#__PURE__*/ React.createElement(Text, {
|
|
453
|
+
color: "cyan"
|
|
454
|
+
}, "ROOT_PUBLIC_KEY")), /*#__PURE__*/ React.createElement(Text, null, "4. Paste the JWK value above"))));
|
|
455
|
+
}
|
|
456
|
+
return null;
|
|
457
|
+
};
|
|
@@ -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
|
+
};
|