poke-gate 0.0.5 → 0.0.7
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/bin/poke-gate.js +22 -7
- package/clients/Poke macOS Gate/Poke macOS Gate/GateService.swift +78 -15
- package/clients/Poke macOS Gate/Poke macOS Gate/SettingsView.swift +67 -13
- package/clients/Poke macOS Gate/Poke macOS Gate.xcodeproj/project.pbxproj +2 -2
- package/clients/Poke macOS Gate/Poke macOS Gate.xcodeproj/project.xcworkspace/xcuserdata/fka.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/package.json +1 -1
- package/src/app.js +21 -0
package/bin/poke-gate.js
CHANGED
|
@@ -21,10 +21,20 @@ function saveConfig(config) {
|
|
|
21
21
|
writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2));
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
function loadPokeCredentials() {
|
|
25
|
+
try {
|
|
26
|
+
const creds = JSON.parse(readFileSync(join(CONFIG_DIR, "poke", "credentials.json"), "utf-8"));
|
|
27
|
+
if (creds.token) return creds.token;
|
|
28
|
+
} catch {}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
|
|
24
32
|
function resolveToken() {
|
|
25
33
|
if (process.env.POKE_API_KEY) return process.env.POKE_API_KEY;
|
|
26
34
|
const config = loadConfig();
|
|
27
35
|
if (config.apiKey) return config.apiKey;
|
|
36
|
+
const pokeCreds = loadPokeCredentials();
|
|
37
|
+
if (pokeCreds) return pokeCreds;
|
|
28
38
|
return null;
|
|
29
39
|
}
|
|
30
40
|
|
|
@@ -47,19 +57,24 @@ async function onboarding() {
|
|
|
47
57
|
console.log();
|
|
48
58
|
console.log(" ⚠ This grants full shell access. Only run on trusted networks.");
|
|
49
59
|
console.log();
|
|
50
|
-
console.log(" To get started,
|
|
60
|
+
console.log(" To get started, either:");
|
|
51
61
|
console.log();
|
|
52
|
-
console.log(" 1
|
|
53
|
-
console.log(" 2
|
|
54
|
-
console.log(" 3. Paste it below");
|
|
62
|
+
console.log(" Option 1: Run 'npx poke login' (recommended)");
|
|
63
|
+
console.log(" Option 2: Paste an API key from https://poke.com/kitchen/api-keys");
|
|
55
64
|
console.log();
|
|
56
65
|
|
|
57
|
-
const key = await ask(" API key: ");
|
|
66
|
+
const key = await ask(" API key (or press Enter if you ran poke login): ");
|
|
58
67
|
|
|
59
68
|
if (!key) {
|
|
69
|
+
const pokeCreds = loadPokeCredentials();
|
|
70
|
+
if (pokeCreds) {
|
|
71
|
+
console.log();
|
|
72
|
+
console.log(" Found poke login credentials! Starting...");
|
|
73
|
+
console.log();
|
|
74
|
+
return pokeCreds;
|
|
75
|
+
}
|
|
60
76
|
console.log();
|
|
61
|
-
console.log(" No
|
|
62
|
-
console.log(" export POKE_API_KEY=your_key_here");
|
|
77
|
+
console.log(" No credentials found. Run: npx poke login");
|
|
63
78
|
console.log();
|
|
64
79
|
process.exit(1);
|
|
65
80
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import Foundation
|
|
2
2
|
import Combine
|
|
3
|
-
import ScreenCaptureKit
|
|
4
3
|
|
|
5
4
|
@MainActor
|
|
6
5
|
class GateService: ObservableObject {
|
|
@@ -28,29 +27,17 @@ class GateService: ObservableObject {
|
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
var hasAPIKey: Bool {
|
|
31
|
-
|
|
32
|
-
return key != nil && !key!.isEmpty
|
|
30
|
+
resolveToken() != nil
|
|
33
31
|
}
|
|
34
32
|
|
|
35
33
|
func autoStartIfNeeded() {
|
|
36
34
|
guard !hasAutoStarted else { return }
|
|
37
35
|
hasAutoStarted = true
|
|
38
|
-
requestScreenCapturePermission()
|
|
39
36
|
if hasAPIKey {
|
|
40
37
|
start()
|
|
41
38
|
}
|
|
42
39
|
}
|
|
43
40
|
|
|
44
|
-
private func requestScreenCapturePermission() {
|
|
45
|
-
Task {
|
|
46
|
-
do {
|
|
47
|
-
_ = try await SCShareableContent.current
|
|
48
|
-
} catch {
|
|
49
|
-
appendLog("Screen capture permission not granted yet.")
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
41
|
func start() {
|
|
55
42
|
guard hasAPIKey else {
|
|
56
43
|
status = .error
|
|
@@ -123,7 +110,7 @@ class GateService: ObservableObject {
|
|
|
123
110
|
proc.arguments = ["-c", "npx -y poke-gate --verbose"]
|
|
124
111
|
proc.environment = ProcessInfo.processInfo.environment.merging(
|
|
125
112
|
[
|
|
126
|
-
"POKE_API_KEY":
|
|
113
|
+
"POKE_API_KEY": resolveToken() ?? "",
|
|
127
114
|
"PATH": fullPath,
|
|
128
115
|
],
|
|
129
116
|
uniquingKeysWith: { _, new in new }
|
|
@@ -238,4 +225,80 @@ class GateService: ObservableObject {
|
|
|
238
225
|
}
|
|
239
226
|
objectWillChange.send()
|
|
240
227
|
}
|
|
228
|
+
|
|
229
|
+
// MARK: - Poke Login Credentials
|
|
230
|
+
|
|
231
|
+
private var pokeCredentialsURL: URL {
|
|
232
|
+
let configDir: URL
|
|
233
|
+
if let xdg = ProcessInfo.processInfo.environment["XDG_CONFIG_HOME"] {
|
|
234
|
+
configDir = URL(fileURLWithPath: xdg)
|
|
235
|
+
} else {
|
|
236
|
+
configDir = FileManager.default.homeDirectoryForCurrentUser
|
|
237
|
+
.appendingPathComponent(".config")
|
|
238
|
+
}
|
|
239
|
+
return configDir
|
|
240
|
+
.appendingPathComponent("poke")
|
|
241
|
+
.appendingPathComponent("credentials.json")
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
var hasPokeLoginCredentials: Bool {
|
|
245
|
+
loadPokeLoginToken() != nil
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
func loadPokeLoginToken() -> String? {
|
|
249
|
+
guard let data = try? Data(contentsOf: pokeCredentialsURL),
|
|
250
|
+
let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
|
|
251
|
+
let token = json["token"] as? String else {
|
|
252
|
+
return nil
|
|
253
|
+
}
|
|
254
|
+
return token
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
var authSource: AuthSource {
|
|
258
|
+
get {
|
|
259
|
+
let config = (try? Data(contentsOf: configURL))
|
|
260
|
+
.flatMap { try? JSONSerialization.jsonObject(with: $0) as? [String: Any] }
|
|
261
|
+
if let source = config?["authSource"] as? String, source == "pokeLogin" {
|
|
262
|
+
return .pokeLogin
|
|
263
|
+
}
|
|
264
|
+
if loadAPIKey() != nil {
|
|
265
|
+
return .apiKey
|
|
266
|
+
}
|
|
267
|
+
if hasPokeLoginCredentials {
|
|
268
|
+
return .pokeLogin
|
|
269
|
+
}
|
|
270
|
+
return .none
|
|
271
|
+
}
|
|
272
|
+
set {
|
|
273
|
+
let dir = configURL.deletingLastPathComponent()
|
|
274
|
+
try? FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
|
|
275
|
+
var json: [String: Any] = [:]
|
|
276
|
+
if let data = try? Data(contentsOf: configURL),
|
|
277
|
+
let existing = try? JSONSerialization.jsonObject(with: data) as? [String: Any] {
|
|
278
|
+
json = existing
|
|
279
|
+
}
|
|
280
|
+
json["authSource"] = newValue == .pokeLogin ? "pokeLogin" : "apiKey"
|
|
281
|
+
if let data = try? JSONSerialization.data(withJSONObject: json, options: [.prettyPrinted]) {
|
|
282
|
+
try? data.write(to: configURL)
|
|
283
|
+
}
|
|
284
|
+
objectWillChange.send()
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
func resolveToken() -> String? {
|
|
289
|
+
switch authSource {
|
|
290
|
+
case .pokeLogin:
|
|
291
|
+
return loadPokeLoginToken()
|
|
292
|
+
case .apiKey:
|
|
293
|
+
return loadAPIKey()
|
|
294
|
+
case .none:
|
|
295
|
+
return loadAPIKey() ?? loadPokeLoginToken()
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
enum AuthSource {
|
|
300
|
+
case pokeLogin
|
|
301
|
+
case apiKey
|
|
302
|
+
case none
|
|
303
|
+
}
|
|
241
304
|
}
|
|
@@ -3,6 +3,7 @@ import SwiftUI
|
|
|
3
3
|
struct SettingsView: View {
|
|
4
4
|
@ObservedObject var service: GateService
|
|
5
5
|
@State private var apiKeyInput: String = ""
|
|
6
|
+
@State private var usePokeLogin: Bool = true
|
|
6
7
|
@Environment(\.dismiss) private var dismiss
|
|
7
8
|
|
|
8
9
|
var body: some View {
|
|
@@ -10,18 +11,64 @@ struct SettingsView: View {
|
|
|
10
11
|
Text("Poke Gate Settings")
|
|
11
12
|
.font(.headline)
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
Text("
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
Picker("Authentication", selection: $usePokeLogin) {
|
|
15
|
+
Text("Use poke login").tag(true)
|
|
16
|
+
Text("Use API key").tag(false)
|
|
17
|
+
}
|
|
18
|
+
.pickerStyle(.segmented)
|
|
19
|
+
|
|
20
|
+
if usePokeLogin {
|
|
21
|
+
VStack(alignment: .leading, spacing: 8) {
|
|
22
|
+
if service.hasPokeLoginCredentials {
|
|
23
|
+
Label("poke login credentials found", systemImage: "checkmark.circle.fill")
|
|
24
|
+
.foregroundStyle(.green)
|
|
25
|
+
.font(.subheadline)
|
|
26
|
+
} else {
|
|
27
|
+
Label("No credentials found", systemImage: "xmark.circle")
|
|
28
|
+
.foregroundStyle(.red)
|
|
29
|
+
.font(.subheadline)
|
|
30
|
+
|
|
31
|
+
Text("Run this in your terminal:")
|
|
32
|
+
.font(.caption)
|
|
33
|
+
.foregroundStyle(.secondary)
|
|
34
|
+
|
|
35
|
+
HStack {
|
|
36
|
+
Text("npx poke login")
|
|
37
|
+
.font(.system(.caption, design: .monospaced))
|
|
38
|
+
.padding(.horizontal, 8)
|
|
39
|
+
.padding(.vertical, 4)
|
|
40
|
+
.background(.quaternary)
|
|
41
|
+
.cornerRadius(4)
|
|
17
42
|
|
|
18
|
-
|
|
19
|
-
|
|
43
|
+
Button {
|
|
44
|
+
NSPasteboard.general.clearContents()
|
|
45
|
+
NSPasteboard.general.setString("npx poke login", forType: .string)
|
|
46
|
+
} label: {
|
|
47
|
+
Image(systemName: "doc.on.doc")
|
|
48
|
+
}
|
|
49
|
+
.buttonStyle(.plain)
|
|
50
|
+
}
|
|
20
51
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
52
|
+
Text("Then come back here and click Save.")
|
|
53
|
+
.font(.caption)
|
|
54
|
+
.foregroundStyle(.secondary)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
.frame(maxWidth: .infinity, alignment: .leading)
|
|
58
|
+
} else {
|
|
59
|
+
VStack(alignment: .leading, spacing: 8) {
|
|
60
|
+
Text("API Key")
|
|
61
|
+
.font(.subheadline)
|
|
62
|
+
.foregroundStyle(.secondary)
|
|
63
|
+
|
|
64
|
+
SecureField("Paste your API key", text: $apiKeyInput)
|
|
65
|
+
.textFieldStyle(.roundedBorder)
|
|
66
|
+
|
|
67
|
+
Link("Get your key at poke.com/kitchen/api-keys",
|
|
68
|
+
destination: URL(string: "https://poke.com/kitchen/api-keys")!)
|
|
69
|
+
.font(.caption)
|
|
70
|
+
.foregroundStyle(.blue)
|
|
71
|
+
}
|
|
25
72
|
}
|
|
26
73
|
|
|
27
74
|
HStack {
|
|
@@ -33,17 +80,24 @@ struct SettingsView: View {
|
|
|
33
80
|
Spacer()
|
|
34
81
|
|
|
35
82
|
Button("Save") {
|
|
36
|
-
|
|
83
|
+
if usePokeLogin {
|
|
84
|
+
service.authSource = .pokeLogin
|
|
85
|
+
} else {
|
|
86
|
+
service.apiKey = apiKeyInput
|
|
87
|
+
service.authSource = .apiKey
|
|
88
|
+
}
|
|
37
89
|
dismiss()
|
|
38
90
|
service.restart()
|
|
39
91
|
}
|
|
40
92
|
.keyboardShortcut(.defaultAction)
|
|
41
|
-
.disabled(apiKeyInput.isEmpty)
|
|
93
|
+
.disabled(!usePokeLogin && apiKeyInput.isEmpty)
|
|
94
|
+
.disabled(usePokeLogin && !service.hasPokeLoginCredentials)
|
|
42
95
|
}
|
|
43
96
|
}
|
|
44
97
|
.padding(20)
|
|
45
|
-
.frame(width:
|
|
98
|
+
.frame(width: 380)
|
|
46
99
|
.onAppear {
|
|
100
|
+
usePokeLogin = service.authSource != .apiKey
|
|
47
101
|
apiKeyInput = service.apiKey
|
|
48
102
|
}
|
|
49
103
|
}
|
|
@@ -264,7 +264,7 @@
|
|
|
264
264
|
"$(inherited)",
|
|
265
265
|
"@executable_path/../Frameworks",
|
|
266
266
|
);
|
|
267
|
-
MARKETING_VERSION = 0.0.
|
|
267
|
+
MARKETING_VERSION = 0.0.5;
|
|
268
268
|
PRODUCT_BUNDLE_IDENTIFIER = "dev.fka.Poke-macOS-Gate";
|
|
269
269
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
|
270
270
|
REGISTER_APP_GROUPS = YES;
|
|
@@ -296,7 +296,7 @@
|
|
|
296
296
|
"$(inherited)",
|
|
297
297
|
"@executable_path/../Frameworks",
|
|
298
298
|
);
|
|
299
|
-
MARKETING_VERSION = 0.0.
|
|
299
|
+
MARKETING_VERSION = 0.0.5;
|
|
300
300
|
PRODUCT_BUNDLE_IDENTIFIER = "dev.fka.Poke-macOS-Gate";
|
|
301
301
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
|
302
302
|
REGISTER_APP_GROUPS = YES;
|
|
Binary file
|
package/package.json
CHANGED
package/src/app.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { startMcpServer, enableLogging } from "./mcp-server.js";
|
|
2
2
|
import { startTunnel } from "./tunnel.js";
|
|
3
|
+
import { Poke } from "poke";
|
|
3
4
|
import { readFileSync } from "node:fs";
|
|
4
5
|
import { join } from "node:path";
|
|
5
6
|
import { homedir } from "node:os";
|
|
@@ -17,6 +18,11 @@ function resolveToken() {
|
|
|
17
18
|
if (cfg.apiKey) return cfg.apiKey;
|
|
18
19
|
} catch {}
|
|
19
20
|
|
|
21
|
+
try {
|
|
22
|
+
const creds = JSON.parse(readFileSync(join(configDir, "poke", "credentials.json"), "utf-8"));
|
|
23
|
+
if (creds.token) return creds.token;
|
|
24
|
+
} catch {}
|
|
25
|
+
|
|
20
26
|
return null;
|
|
21
27
|
}
|
|
22
28
|
|
|
@@ -50,6 +56,7 @@ async function main() {
|
|
|
50
56
|
case "connected":
|
|
51
57
|
log(`Tunnel connected (${data.connectionId})`);
|
|
52
58
|
log("Ready — your Poke agent can now access this machine.");
|
|
59
|
+
notifyPoke(data.connectionId);
|
|
53
60
|
break;
|
|
54
61
|
case "disconnected":
|
|
55
62
|
log("Tunnel disconnected. Reconnecting...");
|
|
@@ -72,6 +79,20 @@ async function main() {
|
|
|
72
79
|
}
|
|
73
80
|
}
|
|
74
81
|
|
|
82
|
+
async function notifyPoke(connectionId) {
|
|
83
|
+
try {
|
|
84
|
+
const poke = new Poke({ apiKey: API_KEY });
|
|
85
|
+
await poke.sendMessage(
|
|
86
|
+
`Poke macOS Gate is connected. Tunnel ID: ${connectionId}. ` +
|
|
87
|
+
`You now have access to this machine's terminal, files, and screen. ` +
|
|
88
|
+
`Use the available tools (run_command, read_file, write_file, list_directory, system_info, read_image, take_screenshot) to help the user.`
|
|
89
|
+
);
|
|
90
|
+
log("Notified Poke agent about connection.");
|
|
91
|
+
} catch (err) {
|
|
92
|
+
log(`Failed to notify Poke: ${err.message}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
75
96
|
process.on("SIGINT", () => {
|
|
76
97
|
log("Shutting down...");
|
|
77
98
|
process.exit(0);
|