@punkcode/cli 0.1.9 → 0.1.10
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/cli.js +25 -11
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -320,6 +320,9 @@ function runClaude(options, callbacks) {
|
|
|
320
320
|
};
|
|
321
321
|
}
|
|
322
322
|
|
|
323
|
+
// src/commands/connect.ts
|
|
324
|
+
import fs3 from "fs";
|
|
325
|
+
|
|
323
326
|
// src/lib/device-info.ts
|
|
324
327
|
import os from "os";
|
|
325
328
|
import path from "path";
|
|
@@ -345,7 +348,15 @@ function getOrCreateDeviceId() {
|
|
|
345
348
|
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2) + "\n", "utf-8");
|
|
346
349
|
return id;
|
|
347
350
|
}
|
|
348
|
-
function
|
|
351
|
+
function getDefaultWorkingDirectory() {
|
|
352
|
+
try {
|
|
353
|
+
const config = JSON.parse(fs.readFileSync(CONFIG_FILE, "utf-8"));
|
|
354
|
+
if (config.defaultWorkingDirectory) return config.defaultWorkingDirectory;
|
|
355
|
+
} catch {
|
|
356
|
+
}
|
|
357
|
+
return path.join(os.homedir(), "punk");
|
|
358
|
+
}
|
|
359
|
+
function collectDeviceInfo(deviceId, customName, customTags, defaultCwd) {
|
|
349
360
|
if (customName) {
|
|
350
361
|
saveConfigField("deviceName", customName);
|
|
351
362
|
}
|
|
@@ -361,7 +372,7 @@ function collectDeviceInfo(deviceId, customName, customTags) {
|
|
|
361
372
|
arch: process.arch,
|
|
362
373
|
username: os.userInfo().username,
|
|
363
374
|
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
364
|
-
defaultWorkingDirectory:
|
|
375
|
+
defaultWorkingDirectory: defaultCwd || getDefaultWorkingDirectory(),
|
|
365
376
|
model: getModel(),
|
|
366
377
|
cpuModel: cpus.length > 0 ? cpus[0].model : "Unknown",
|
|
367
378
|
memoryGB: Math.round(os.totalmem() / 1024 ** 3),
|
|
@@ -1037,6 +1048,8 @@ async function connect(server, options) {
|
|
|
1037
1048
|
}
|
|
1038
1049
|
logger.info("All checks passed");
|
|
1039
1050
|
const deviceId = options.deviceId || getOrCreateDeviceId();
|
|
1051
|
+
const defaultCwd = options.cwd || getDefaultWorkingDirectory();
|
|
1052
|
+
fs3.mkdirSync(defaultCwd, { recursive: true });
|
|
1040
1053
|
const url = buildUrl(server);
|
|
1041
1054
|
let idToken;
|
|
1042
1055
|
if (options.token) {
|
|
@@ -1069,7 +1082,7 @@ async function connect(server, options) {
|
|
|
1069
1082
|
}, 3e4);
|
|
1070
1083
|
socket.on("connect", () => {
|
|
1071
1084
|
logger.info("Connected");
|
|
1072
|
-
const deviceInfo = collectDeviceInfo(deviceId, options.name, options.tag);
|
|
1085
|
+
const deviceInfo = collectDeviceInfo(deviceId, options.name, options.tag, defaultCwd);
|
|
1073
1086
|
socket.emit("register", deviceInfo, (response) => {
|
|
1074
1087
|
if (response.success) {
|
|
1075
1088
|
logger.info({ deviceId }, "Registered");
|
|
@@ -1088,12 +1101,12 @@ async function connect(server, options) {
|
|
|
1088
1101
|
});
|
|
1089
1102
|
socket.on("list-sessions", async (msg) => {
|
|
1090
1103
|
if (msg.type === "list-sessions") {
|
|
1091
|
-
handleListSessions(socket, msg);
|
|
1104
|
+
handleListSessions(socket, msg, defaultCwd);
|
|
1092
1105
|
}
|
|
1093
1106
|
});
|
|
1094
1107
|
socket.on("get-context", (msg) => {
|
|
1095
1108
|
if (msg.type === "get-context") {
|
|
1096
|
-
handleGetContext(socket, msg);
|
|
1109
|
+
handleGetContext(socket, msg, defaultCwd);
|
|
1097
1110
|
}
|
|
1098
1111
|
});
|
|
1099
1112
|
socket.on("get-commands", (msg) => {
|
|
@@ -1124,7 +1137,7 @@ async function connect(server, options) {
|
|
|
1124
1137
|
});
|
|
1125
1138
|
socket.on("reconnect", (attemptNumber) => {
|
|
1126
1139
|
logger.info({ attemptNumber }, "Reconnected");
|
|
1127
|
-
socket.emit("register", collectDeviceInfo(deviceId, options.name, options.tag));
|
|
1140
|
+
socket.emit("register", collectDeviceInfo(deviceId, options.name, options.tag, defaultCwd));
|
|
1128
1141
|
});
|
|
1129
1142
|
socket.on("connect_error", (err) => {
|
|
1130
1143
|
const { reason, ...detail } = formatConnectionError(err);
|
|
@@ -1270,9 +1283,9 @@ function handleCancel(id, activeSessions) {
|
|
|
1270
1283
|
logger.info({ sessionId: id }, "Session cancelled");
|
|
1271
1284
|
}
|
|
1272
1285
|
}
|
|
1273
|
-
async function handleListSessions(socket, msg) {
|
|
1286
|
+
async function handleListSessions(socket, msg, defaultCwd) {
|
|
1274
1287
|
const { id } = msg;
|
|
1275
|
-
const workingDirectory = msg.workingDirectory ??
|
|
1288
|
+
const workingDirectory = msg.workingDirectory ?? defaultCwd;
|
|
1276
1289
|
logger.info("Listing sessions...");
|
|
1277
1290
|
const sessions = await listSessions(workingDirectory);
|
|
1278
1291
|
send(socket, "response", { type: "sessions_list", sessions, requestId: id });
|
|
@@ -1305,8 +1318,9 @@ async function handleGetCommands(socket, msg) {
|
|
|
1305
1318
|
log2.error({ err }, "Commands error");
|
|
1306
1319
|
}
|
|
1307
1320
|
}
|
|
1308
|
-
async function handleGetContext(socket, msg) {
|
|
1309
|
-
const { id, sessionId
|
|
1321
|
+
async function handleGetContext(socket, msg, defaultCwd) {
|
|
1322
|
+
const { id, sessionId } = msg;
|
|
1323
|
+
const workingDirectory = msg.workingDirectory ?? defaultCwd;
|
|
1310
1324
|
const log2 = createChildLogger({ sessionId });
|
|
1311
1325
|
log2.info("Getting context...");
|
|
1312
1326
|
try {
|
|
@@ -1392,7 +1406,7 @@ function logout() {
|
|
|
1392
1406
|
|
|
1393
1407
|
// src/commands/index.ts
|
|
1394
1408
|
function registerCommands(program2) {
|
|
1395
|
-
program2.command("connect").argument("[server]", "Backend server URL", "https://api.punkcode.dev").description("Connect to backend server").option("-t, --token <token>", "Authentication token").option("-d, --device-id <deviceId>", "Device identifier (defaults to hostname)").option("-n, --name <name>", "Custom device display name").option("--tag <tag>", "Device tag (repeatable, e.g. --tag home --tag mac --tag docker)", (val, acc) => [...acc, val], []).action(connect);
|
|
1409
|
+
program2.command("connect").argument("[server]", "Backend server URL", "https://api.punkcode.dev").description("Connect to backend server").option("-t, --token <token>", "Authentication token").option("-d, --device-id <deviceId>", "Device identifier (defaults to hostname)").option("-n, --name <name>", "Custom device display name").option("--tag <tag>", "Device tag (repeatable, e.g. --tag home --tag mac --tag docker)", (val, acc) => [...acc, val], []).option("--cwd <directory>", "Working directory for sessions (default: ~/punk)").action(connect);
|
|
1396
1410
|
program2.command("login").description("Log in with your email and password").action(login);
|
|
1397
1411
|
program2.command("logout").description("Log out and clear stored credentials").action(logout);
|
|
1398
1412
|
}
|