@pmate/cli 0.13.1 → 0.13.3
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/README.md +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +183 -271
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,6 +32,7 @@ pmate login --app @pmate/chat
|
|
|
32
32
|
pmate sts
|
|
33
33
|
pmate oss list
|
|
34
34
|
pmate oss upload --file ./path/to/file --key assets/file.txt
|
|
35
|
+
pmate oss upload --file ./path/to/file --key upload/file.txt --bucket parrot-static
|
|
35
36
|
pmate pr
|
|
36
37
|
pmate commit
|
|
37
38
|
pmate commit --push
|
package/dist/index.d.ts
CHANGED
|
@@ -61,6 +61,10 @@ type LogCommandArgs = {
|
|
|
61
61
|
type: Command.Log;
|
|
62
62
|
logApp: string;
|
|
63
63
|
logCwd: string;
|
|
64
|
+
logNamespace?: string;
|
|
65
|
+
logPage: number;
|
|
66
|
+
logHistory: boolean;
|
|
67
|
+
logSearch?: string;
|
|
64
68
|
};
|
|
65
69
|
type InitCommandArgs = {
|
|
66
70
|
type: Command.Init;
|
|
@@ -227,6 +231,7 @@ type OssCommandArgs = {
|
|
|
227
231
|
} | {
|
|
228
232
|
type: Command.Oss;
|
|
229
233
|
action: "upload";
|
|
234
|
+
bucket?: string;
|
|
230
235
|
filePath: string;
|
|
231
236
|
objectKey: string;
|
|
232
237
|
};
|
package/dist/index.js
CHANGED
|
@@ -12407,10 +12407,10 @@ function resolveHubBaseUrl(value) {
|
|
|
12407
12407
|
}
|
|
12408
12408
|
function readSessionToken() {
|
|
12409
12409
|
const sessionPath = import_node_path13.default.join(import_node_os4.default.homedir(), ".pmate", "session.json");
|
|
12410
|
-
if (!(0,
|
|
12410
|
+
if (!(0, import_node_fs9.existsSync)(sessionPath)) {
|
|
12411
12411
|
throw new Error(`Missing session file at ${sessionPath}. Run "pmate login" first.`);
|
|
12412
12412
|
}
|
|
12413
|
-
const raw = (0,
|
|
12413
|
+
const raw = (0, import_node_fs9.readFileSync)(sessionPath, "utf8");
|
|
12414
12414
|
const parsed = JSON.parse(raw);
|
|
12415
12415
|
const token = parsed.token?.trim();
|
|
12416
12416
|
if (!token) {
|
|
@@ -12427,11 +12427,11 @@ function unwrapAgentResult(value) {
|
|
|
12427
12427
|
}
|
|
12428
12428
|
return value;
|
|
12429
12429
|
}
|
|
12430
|
-
var
|
|
12430
|
+
var import_node_fs9, import_node_os4, import_node_path13, import_agent_sdk, DEFAULT_AGENT_API_BASE_URL, DEFAULT_AGENT_HUB_BASE_URL, DEFAULT_NAMESPACE, DEFAULT_FROM, AgentLlmClient;
|
|
12431
12431
|
var init_AgentLlmClient = __esm({
|
|
12432
12432
|
"src/llm/AgentLlmClient.ts"() {
|
|
12433
12433
|
"use strict";
|
|
12434
|
-
|
|
12434
|
+
import_node_fs9 = require("fs");
|
|
12435
12435
|
import_node_os4 = __toESM(require("os"));
|
|
12436
12436
|
import_node_path13 = __toESM(require("path"));
|
|
12437
12437
|
import_agent_sdk = __toESM(require_dist4());
|
|
@@ -12479,7 +12479,7 @@ __export(index_exports, {
|
|
|
12479
12479
|
parseCommandArgs: () => parseCommandArgs
|
|
12480
12480
|
});
|
|
12481
12481
|
module.exports = __toCommonJS(index_exports);
|
|
12482
|
-
var
|
|
12482
|
+
var import_node_fs16 = require("fs");
|
|
12483
12483
|
var import_node_path21 = __toESM(require("path"));
|
|
12484
12484
|
var import_chalk3 = __toESM(require("chalk"));
|
|
12485
12485
|
|
|
@@ -13298,7 +13298,7 @@ var AliyunService = class {
|
|
|
13298
13298
|
if (!accessKeyId) throw new Error("Missing aliyun.ak in ~/.pmate/config.yaml.");
|
|
13299
13299
|
if (!accessKeySecret) throw new Error("Missing aliyun.sk in ~/.pmate/config.yaml.");
|
|
13300
13300
|
const client = new import_ali_oss.default({ region, accessKeyId, accessKeySecret });
|
|
13301
|
-
const result = await client.listBuckets(
|
|
13301
|
+
const result = await client.listBuckets({});
|
|
13302
13302
|
const buckets = Array.isArray(result) ? result : result?.buckets ?? [];
|
|
13303
13303
|
return buckets.map(
|
|
13304
13304
|
(bucket) => typeof bucket === "string" ? bucket : bucket.name
|
|
@@ -14041,10 +14041,7 @@ var DeployCommandHandler = class {
|
|
|
14041
14041
|
};
|
|
14042
14042
|
|
|
14043
14043
|
// src/commands/LogCommandHandler.ts
|
|
14044
|
-
var import_node_fs6 = require("fs");
|
|
14045
|
-
var import_node_child_process3 = require("child_process");
|
|
14046
14044
|
var import_node_path8 = __toESM(require("path"));
|
|
14047
|
-
var import_node_module = require("module");
|
|
14048
14045
|
var LogCommandHandler = class {
|
|
14049
14046
|
async handle(args) {
|
|
14050
14047
|
const appName = args.logApp.trim();
|
|
@@ -14057,19 +14054,15 @@ var LogCommandHandler = class {
|
|
|
14057
14054
|
if (!appConfig) {
|
|
14058
14055
|
throw new Error(`No app named ${appName} found in ${configPath}`);
|
|
14059
14056
|
}
|
|
14060
|
-
|
|
14061
|
-
|
|
14062
|
-
|
|
14063
|
-
|
|
14064
|
-
|
|
14065
|
-
}
|
|
14066
|
-
|
|
14067
|
-
|
|
14068
|
-
|
|
14069
|
-
}
|
|
14070
|
-
throw new Error(
|
|
14071
|
-
`Logs are not supported for app type: ${appConfig.type}`
|
|
14072
|
-
);
|
|
14057
|
+
const namespace = args.logNamespace?.trim() || process.env.PMATE_LOG_NAMESPACE || "pmate";
|
|
14058
|
+
const page = await this.fetchLogPage(namespace, appName, {
|
|
14059
|
+
history: args.logHistory,
|
|
14060
|
+
page: args.logPage,
|
|
14061
|
+
search: args.logSearch
|
|
14062
|
+
});
|
|
14063
|
+
ui.title(`Logs for ${namespace}/${appName}`);
|
|
14064
|
+
ui.info("Source", { repoRoot, mode: args.logHistory ? "history" : "online" });
|
|
14065
|
+
this.renderPage(page);
|
|
14073
14066
|
}
|
|
14074
14067
|
resolveCwd(target) {
|
|
14075
14068
|
return target ? import_node_path8.default.resolve(process.cwd(), target) : process.cwd();
|
|
@@ -14082,136 +14075,46 @@ var LogCommandHandler = class {
|
|
|
14082
14075
|
repoRoot: loaded.rootDir
|
|
14083
14076
|
};
|
|
14084
14077
|
}
|
|
14085
|
-
|
|
14086
|
-
const
|
|
14087
|
-
|
|
14088
|
-
|
|
14089
|
-
|
|
14090
|
-
|
|
14091
|
-
|
|
14092
|
-
|
|
14093
|
-
|
|
14094
|
-
|
|
14095
|
-
|
|
14096
|
-
const appDir = resolveLocalAppDir(repoRoot, appName, appConfig.dir);
|
|
14097
|
-
const ecosystemPath = this.findEcosystemPath(appDir);
|
|
14098
|
-
if (!ecosystemPath) {
|
|
14099
|
-
return appName;
|
|
14100
|
-
}
|
|
14101
|
-
const ecosystem = this.loadEcosystemConfig(ecosystemPath);
|
|
14102
|
-
const name = this.extractPm2Name(ecosystem);
|
|
14103
|
-
return name ?? appName;
|
|
14104
|
-
}
|
|
14105
|
-
findEcosystemPath(appDir) {
|
|
14106
|
-
const cjs = import_node_path8.default.join(appDir, "ecosystem.config.cjs");
|
|
14107
|
-
if ((0, import_node_fs6.existsSync)(cjs)) {
|
|
14108
|
-
return cjs;
|
|
14109
|
-
}
|
|
14110
|
-
const js = import_node_path8.default.join(appDir, "ecosystem.config.js");
|
|
14111
|
-
if ((0, import_node_fs6.existsSync)(js)) {
|
|
14112
|
-
return js;
|
|
14113
|
-
}
|
|
14114
|
-
return null;
|
|
14115
|
-
}
|
|
14116
|
-
loadEcosystemConfig(filePath) {
|
|
14117
|
-
const requireFromHere = (0, import_node_module.createRequire)(__filename);
|
|
14118
|
-
try {
|
|
14119
|
-
const loaded = requireFromHere(filePath);
|
|
14120
|
-
return loaded?.default ?? loaded;
|
|
14121
|
-
} catch {
|
|
14122
|
-
return null;
|
|
14123
|
-
}
|
|
14124
|
-
}
|
|
14125
|
-
extractPm2Name(config) {
|
|
14126
|
-
if (!config || typeof config !== "object") {
|
|
14127
|
-
return void 0;
|
|
14128
|
-
}
|
|
14129
|
-
const raw = config;
|
|
14130
|
-
const apps = Array.isArray(raw.apps) ? raw.apps : raw.apps ? [raw.apps] : [];
|
|
14131
|
-
for (const item of apps) {
|
|
14132
|
-
if (!item || typeof item !== "object") {
|
|
14133
|
-
continue;
|
|
14134
|
-
}
|
|
14135
|
-
const name = item.name;
|
|
14136
|
-
if (typeof name === "string" && name.trim()) {
|
|
14137
|
-
return name.trim();
|
|
14138
|
-
}
|
|
14139
|
-
}
|
|
14140
|
-
return void 0;
|
|
14141
|
-
}
|
|
14142
|
-
runRemoteScriptLog(appName, appConfig) {
|
|
14143
|
-
const server = appConfig.server?.trim();
|
|
14144
|
-
if (!server) {
|
|
14145
|
-
throw new Error(`Missing server for ${appName} in .pmate.yaml`);
|
|
14146
|
-
}
|
|
14147
|
-
const repository = appConfig.repository?.trim();
|
|
14148
|
-
if (!repository) {
|
|
14149
|
-
throw new Error(`Missing repository for ${appName} in .pmate.yaml`);
|
|
14150
|
-
}
|
|
14151
|
-
const script = appConfig.script?.trim();
|
|
14152
|
-
if (!script) {
|
|
14153
|
-
throw new Error(`Missing script for ${appName} in .pmate.yaml`);
|
|
14078
|
+
async fetchLogPage(namespace, appName, options) {
|
|
14079
|
+
const baseUrl = (process.env.INDEXER_BASE_URL || "https://indexer.pmate.chat").replace(/\/$/, "");
|
|
14080
|
+
const chainId = process.env.BLOCKCHAIN_CHAIN_ID || "pmate";
|
|
14081
|
+
const action = options.history ? "list" : "search";
|
|
14082
|
+
const url = new URL(
|
|
14083
|
+
`/chains/${encodeURIComponent(chainId)}/namespaces/${encodeURIComponent(namespace)}/log/${encodeURIComponent(appName)}/${action}`,
|
|
14084
|
+
`${baseUrl}/`
|
|
14085
|
+
);
|
|
14086
|
+
url.searchParams.set("page_id", String(options.page));
|
|
14087
|
+
if (options.search && !options.history) {
|
|
14088
|
+
url.searchParams.set("keyword", options.search);
|
|
14154
14089
|
}
|
|
14155
|
-
const
|
|
14156
|
-
|
|
14157
|
-
|
|
14158
|
-
`cd "$HOME"`,
|
|
14159
|
-
`cd "${repoDir}"`,
|
|
14160
|
-
`if [ -f ~/.profile ]; then . ~/.profile; fi`,
|
|
14161
|
-
`if [ -f ~/.bashrc ]; then . ~/.bashrc; fi`,
|
|
14162
|
-
`"${scriptPath}" log`
|
|
14163
|
-
].join(" && ");
|
|
14164
|
-
return new Promise((resolve, reject) => {
|
|
14165
|
-
const target = `pmate@${server}`;
|
|
14166
|
-
const child = (0, import_node_child_process3.spawn)("ssh", buildSshBashArgs(target, command), {
|
|
14167
|
-
stdio: "inherit"
|
|
14168
|
-
});
|
|
14169
|
-
child.on("error", (error) => {
|
|
14170
|
-
reject(error);
|
|
14171
|
-
});
|
|
14172
|
-
child.on("close", (code, signal) => {
|
|
14173
|
-
if (code === 0 || code === 130 || signal === "SIGINT") {
|
|
14174
|
-
resolve();
|
|
14175
|
-
return;
|
|
14176
|
-
}
|
|
14177
|
-
reject(new Error(`ssh to ${server} exited with code ${code ?? "null"}`));
|
|
14178
|
-
});
|
|
14090
|
+
const response = await fetch(url.toString(), {
|
|
14091
|
+
method: "GET",
|
|
14092
|
+
headers: { Accept: "application/json" }
|
|
14179
14093
|
});
|
|
14094
|
+
const payload = await response.json();
|
|
14095
|
+
if (!response.ok || !payload.success || !payload.data) {
|
|
14096
|
+
throw new Error(payload.message || `Log request failed: ${response.status}`);
|
|
14097
|
+
}
|
|
14098
|
+
return payload.data;
|
|
14180
14099
|
}
|
|
14181
|
-
|
|
14182
|
-
|
|
14183
|
-
|
|
14184
|
-
|
|
14185
|
-
|
|
14186
|
-
|
|
14187
|
-
return new Promise((resolve, reject) => {
|
|
14188
|
-
const target = `pmate@${server}`;
|
|
14189
|
-
const command = [
|
|
14190
|
-
`if [ -f ~/.profile ]; then . ~/.profile; fi`,
|
|
14191
|
-
`if [ -f ~/.bashrc ]; then . ~/.bashrc; fi`,
|
|
14192
|
-
`pm2 logs "${appName}" --lines 200`
|
|
14193
|
-
].join(" && ");
|
|
14194
|
-
const child = (0, import_node_child_process3.spawn)("ssh", buildSshBashArgs(target, command), {
|
|
14195
|
-
stdio: "inherit"
|
|
14196
|
-
});
|
|
14197
|
-
child.on("error", (error) => {
|
|
14198
|
-
reject(error);
|
|
14199
|
-
});
|
|
14200
|
-
child.on("close", (code, signal) => {
|
|
14201
|
-
if (code === 0 || code === 130 || signal === "SIGINT") {
|
|
14202
|
-
resolve();
|
|
14203
|
-
return;
|
|
14204
|
-
}
|
|
14205
|
-
reject(new Error(`ssh to ${server} exited with code ${code ?? "null"}`));
|
|
14206
|
-
});
|
|
14100
|
+
renderPage(page) {
|
|
14101
|
+
ui.info("Page", {
|
|
14102
|
+
page: page.page,
|
|
14103
|
+
totalPage: page.totalPage,
|
|
14104
|
+
pageSize: page.pageSize,
|
|
14105
|
+
items: page.data.length
|
|
14207
14106
|
});
|
|
14107
|
+
for (const item of page.data) {
|
|
14108
|
+
const ts = new Date(item.time).toISOString();
|
|
14109
|
+
ui.plain(`${ts} [${item.type}] ${JSON.stringify(item.data)} #${item.hash}`);
|
|
14110
|
+
}
|
|
14208
14111
|
}
|
|
14209
14112
|
};
|
|
14210
14113
|
|
|
14211
14114
|
// src/commands/InitCommandHandler.ts
|
|
14212
|
-
var
|
|
14115
|
+
var import_node_fs6 = require("fs");
|
|
14213
14116
|
var import_node_path9 = __toESM(require("path"));
|
|
14214
|
-
var
|
|
14117
|
+
var import_node_child_process3 = require("child_process");
|
|
14215
14118
|
var import_promises2 = require("readline/promises");
|
|
14216
14119
|
var import_yaml2 = __toESM(require("yaml"));
|
|
14217
14120
|
|
|
@@ -14248,7 +14151,7 @@ var InitCommandHandler = class {
|
|
|
14248
14151
|
}
|
|
14249
14152
|
if (appConfig.type !== "rust") {
|
|
14250
14153
|
const appDir = resolveLocalAppDir(cwd, appName, appConfig.dir);
|
|
14251
|
-
if (!(0,
|
|
14154
|
+
if (!(0, import_node_fs6.existsSync)(appDir)) {
|
|
14252
14155
|
throw new Error(`No app folder found at ${appDir}`);
|
|
14253
14156
|
}
|
|
14254
14157
|
}
|
|
@@ -14415,11 +14318,8 @@ var InitCommandHandler = class {
|
|
|
14415
14318
|
if (subdomain) {
|
|
14416
14319
|
const serverAddress = await resolveServerAddress(server);
|
|
14417
14320
|
const templateName = serviceType === "ws" ? "nginx.ws.template" : "nginx.rest.template";
|
|
14418
|
-
const templatePath =
|
|
14419
|
-
|
|
14420
|
-
throw new Error(`Missing nginx template at ${templatePath}`);
|
|
14421
|
-
}
|
|
14422
|
-
const template = (0, import_node_fs7.readFileSync)(templatePath, "utf8");
|
|
14321
|
+
const templatePath = this.resolveTemplatePath(templateName);
|
|
14322
|
+
const template = (0, import_node_fs6.readFileSync)(templatePath, "utf8");
|
|
14423
14323
|
const host = `${subdomain}.pmate.chat`;
|
|
14424
14324
|
const rendered = template.replace(/\$\{\{PORT\}\}/g, String(port)).replace(/\$\{\{HOSTS\}\}/g, host).replace(/\$\{\{HOST\}\}/g, host);
|
|
14425
14325
|
const remotePath = `/etc/nginx/sites-enabled/${subdomain}.conf`;
|
|
@@ -14452,15 +14352,15 @@ var InitCommandHandler = class {
|
|
|
14452
14352
|
if (options.ensurePackageJson) {
|
|
14453
14353
|
const appDir = resolveLocalAppDir(cwd, appConfig.app, appConfig.dir);
|
|
14454
14354
|
ui.info(`Resolved appDir: ${appDir}`);
|
|
14455
|
-
if (!(0,
|
|
14355
|
+
if (!(0, import_node_fs6.existsSync)(appDir)) {
|
|
14456
14356
|
throw new Error(`Missing app folder at ${appDir}`);
|
|
14457
14357
|
}
|
|
14458
14358
|
const packageJsonPath = import_node_path9.default.join(appDir, "package.json");
|
|
14459
14359
|
ui.info(`Resolved package.json: ${packageJsonPath}`);
|
|
14460
|
-
if (!(0,
|
|
14360
|
+
if (!(0, import_node_fs6.existsSync)(packageJsonPath)) {
|
|
14461
14361
|
throw new Error(`Missing package.json at ${packageJsonPath}`);
|
|
14462
14362
|
}
|
|
14463
|
-
const pkgStat = (0,
|
|
14363
|
+
const pkgStat = (0, import_node_fs6.statSync)(packageJsonPath);
|
|
14464
14364
|
ui.info(
|
|
14465
14365
|
`package.json stat: isFile=${pkgStat.isFile()} isDirectory=${pkgStat.isDirectory()}`
|
|
14466
14366
|
);
|
|
@@ -14478,10 +14378,23 @@ var InitCommandHandler = class {
|
|
|
14478
14378
|
}
|
|
14479
14379
|
}
|
|
14480
14380
|
}
|
|
14381
|
+
resolveTemplatePath(templateName) {
|
|
14382
|
+
const candidates = [
|
|
14383
|
+
import_node_path9.default.join(__dirname, "templates", templateName),
|
|
14384
|
+
import_node_path9.default.join(__dirname, "..", "templates", templateName),
|
|
14385
|
+
import_node_path9.default.join(__dirname, "..", "src", "templates", templateName)
|
|
14386
|
+
];
|
|
14387
|
+
for (const candidate of candidates) {
|
|
14388
|
+
if ((0, import_node_fs6.existsSync)(candidate)) {
|
|
14389
|
+
return candidate;
|
|
14390
|
+
}
|
|
14391
|
+
}
|
|
14392
|
+
throw new Error(`Missing nginx template. Tried: ${candidates.join(", ")}`);
|
|
14393
|
+
}
|
|
14481
14394
|
writeRemoteConfig(server, content, remotePath) {
|
|
14482
14395
|
return new Promise((resolve, reject) => {
|
|
14483
14396
|
const target = `pmate@${server}`;
|
|
14484
|
-
const child = (0,
|
|
14397
|
+
const child = (0, import_node_child_process3.spawn)("ssh", [target, "sudo", "tee", remotePath], {
|
|
14485
14398
|
stdio: ["pipe", "inherit", "inherit"]
|
|
14486
14399
|
});
|
|
14487
14400
|
child.on("error", (error) => {
|
|
@@ -14504,7 +14417,7 @@ var InitCommandHandler = class {
|
|
|
14504
14417
|
reloadNginx(server) {
|
|
14505
14418
|
return new Promise((resolve, reject) => {
|
|
14506
14419
|
const target = `pmate@${server}`;
|
|
14507
|
-
const child = (0,
|
|
14420
|
+
const child = (0, import_node_child_process3.spawn)("ssh", [target, "sudo", "nginx", "-s", "reload"], {
|
|
14508
14421
|
stdio: ["ignore", "inherit", "inherit"]
|
|
14509
14422
|
});
|
|
14510
14423
|
child.on("error", (error) => {
|
|
@@ -14644,7 +14557,7 @@ var InitCommandHandler = class {
|
|
|
14644
14557
|
}
|
|
14645
14558
|
}
|
|
14646
14559
|
loadPackageJson(packageJsonPath) {
|
|
14647
|
-
const raw = (0,
|
|
14560
|
+
const raw = (0, import_node_fs6.readFileSync)(packageJsonPath, "utf8");
|
|
14648
14561
|
const parsed = JSON.parse(raw);
|
|
14649
14562
|
if (!parsed || typeof parsed !== "object") {
|
|
14650
14563
|
throw new Error(`Invalid package.json at ${packageJsonPath}`);
|
|
@@ -14653,13 +14566,13 @@ var InitCommandHandler = class {
|
|
|
14653
14566
|
}
|
|
14654
14567
|
writePackageJson(packageJsonPath, data) {
|
|
14655
14568
|
const serialized = JSON.stringify(data, null, 2);
|
|
14656
|
-
(0,
|
|
14569
|
+
(0, import_node_fs6.writeFileSync)(packageJsonPath, `${serialized}
|
|
14657
14570
|
`, "utf8");
|
|
14658
14571
|
}
|
|
14659
14572
|
writeConfig(cwd, config) {
|
|
14660
14573
|
const configPath = import_node_path9.default.join(cwd, ".pmate.yaml");
|
|
14661
14574
|
const serialized = import_yaml2.default.stringify(config).trimEnd();
|
|
14662
|
-
(0,
|
|
14575
|
+
(0, import_node_fs6.writeFileSync)(configPath, `${serialized}
|
|
14663
14576
|
`, "utf8");
|
|
14664
14577
|
}
|
|
14665
14578
|
async promptRequired(rl, question) {
|
|
@@ -14695,9 +14608,9 @@ var InitCommandHandler = class {
|
|
|
14695
14608
|
};
|
|
14696
14609
|
|
|
14697
14610
|
// src/commands/DevCommandHandler.ts
|
|
14698
|
-
var
|
|
14611
|
+
var import_node_fs7 = require("fs");
|
|
14699
14612
|
var import_node_path10 = __toESM(require("path"));
|
|
14700
|
-
var
|
|
14613
|
+
var import_node_child_process4 = require("child_process");
|
|
14701
14614
|
var DevCommandHandler = class {
|
|
14702
14615
|
async handle(args) {
|
|
14703
14616
|
const appName = args.devApp.trim();
|
|
@@ -14715,7 +14628,7 @@ var DevCommandHandler = class {
|
|
|
14715
14628
|
}
|
|
14716
14629
|
const appDir = resolveLocalAppDir(cwd, appName, appConfig.dir);
|
|
14717
14630
|
const packageJsonPath = import_node_path10.default.join(appDir, "package.json");
|
|
14718
|
-
if (!(0,
|
|
14631
|
+
if (!(0, import_node_fs7.existsSync)(packageJsonPath)) {
|
|
14719
14632
|
throw new Error(`No package.json found at ${packageJsonPath}`);
|
|
14720
14633
|
}
|
|
14721
14634
|
const pkg2 = this.loadPackageJson(packageJsonPath);
|
|
@@ -14735,7 +14648,7 @@ var DevCommandHandler = class {
|
|
|
14735
14648
|
return loadAppConfig(cwd);
|
|
14736
14649
|
}
|
|
14737
14650
|
loadPackageJson(packageJsonPath) {
|
|
14738
|
-
const raw = (0,
|
|
14651
|
+
const raw = (0, import_node_fs7.readFileSync)(packageJsonPath, "utf8");
|
|
14739
14652
|
const parsed = JSON.parse(raw);
|
|
14740
14653
|
if (!parsed || typeof parsed !== "object") {
|
|
14741
14654
|
throw new Error(`Invalid package.json at ${packageJsonPath}`);
|
|
@@ -14744,7 +14657,7 @@ var DevCommandHandler = class {
|
|
|
14744
14657
|
}
|
|
14745
14658
|
runCommand(command, args, cwd) {
|
|
14746
14659
|
return new Promise((resolve, reject) => {
|
|
14747
|
-
const child = (0,
|
|
14660
|
+
const child = (0, import_node_child_process4.spawn)(command, args, {
|
|
14748
14661
|
cwd,
|
|
14749
14662
|
stdio: "inherit"
|
|
14750
14663
|
});
|
|
@@ -14763,46 +14676,35 @@ var DevCommandHandler = class {
|
|
|
14763
14676
|
};
|
|
14764
14677
|
|
|
14765
14678
|
// src/commands/OssCommandHandler.ts
|
|
14766
|
-
var
|
|
14679
|
+
var import_node_fs8 = require("fs");
|
|
14767
14680
|
var import_node_path11 = __toESM(require("path"));
|
|
14768
|
-
var
|
|
14769
|
-
|
|
14681
|
+
var OssCommandHandler = class _OssCommandHandler {
|
|
14682
|
+
static {
|
|
14683
|
+
this.DEFAULT_BUCKET = "parrot-static";
|
|
14684
|
+
}
|
|
14770
14685
|
async handle(args) {
|
|
14771
14686
|
if (args.action === "list") {
|
|
14772
|
-
const
|
|
14773
|
-
if (
|
|
14687
|
+
const buckets = await AliyunService.listBuckets();
|
|
14688
|
+
if (buckets.length === 0) {
|
|
14774
14689
|
ui.warn("No buckets found for current access key.");
|
|
14775
14690
|
return;
|
|
14776
14691
|
}
|
|
14777
|
-
for (const
|
|
14778
|
-
ui.info(
|
|
14692
|
+
for (const bucket2 of buckets) {
|
|
14693
|
+
ui.info(bucket2);
|
|
14779
14694
|
}
|
|
14780
14695
|
return;
|
|
14781
14696
|
}
|
|
14782
14697
|
const resolvedFile = import_node_path11.default.resolve(process.cwd(), args.filePath);
|
|
14783
14698
|
this.assertFile(resolvedFile);
|
|
14784
14699
|
const objectKey = this.normalizeObjectKey(args.objectKey);
|
|
14785
|
-
const
|
|
14786
|
-
|
|
14787
|
-
ui.warn("No buckets found for current access key.");
|
|
14788
|
-
return;
|
|
14789
|
-
}
|
|
14790
|
-
const rl = (0, import_promises3.createInterface)({
|
|
14791
|
-
input: process.stdin,
|
|
14792
|
-
output: process.stdout
|
|
14793
|
-
});
|
|
14794
|
-
try {
|
|
14795
|
-
const bucket = await this.promptBucketSelection(rl, buckets);
|
|
14796
|
-
await AliyunService.uploadFile(resolvedFile, bucket, objectKey);
|
|
14797
|
-
} finally {
|
|
14798
|
-
rl.close();
|
|
14799
|
-
}
|
|
14700
|
+
const bucket = this.resolveBucket(args.bucket);
|
|
14701
|
+
await AliyunService.uploadFile(resolvedFile, bucket, objectKey);
|
|
14800
14702
|
}
|
|
14801
14703
|
assertFile(filePath) {
|
|
14802
|
-
if (!(0,
|
|
14704
|
+
if (!(0, import_node_fs8.existsSync)(filePath)) {
|
|
14803
14705
|
throw new Error(`File not found: ${filePath}`);
|
|
14804
14706
|
}
|
|
14805
|
-
const stat = (0,
|
|
14707
|
+
const stat = (0, import_node_fs8.statSync)(filePath);
|
|
14806
14708
|
if (!stat.isFile()) {
|
|
14807
14709
|
throw new Error(`Not a file: ${filePath}`);
|
|
14808
14710
|
}
|
|
@@ -14814,32 +14716,18 @@ var OssCommandHandler = class {
|
|
|
14814
14716
|
}
|
|
14815
14717
|
return normalized;
|
|
14816
14718
|
}
|
|
14817
|
-
|
|
14818
|
-
|
|
14819
|
-
|
|
14820
|
-
|
|
14821
|
-
});
|
|
14822
|
-
const normalized = buckets.map((bucket) => bucket.toLowerCase());
|
|
14823
|
-
while (true) {
|
|
14824
|
-
const answer = (await rl.question(
|
|
14825
|
-
`Select bucket (1-${buckets.length}): `
|
|
14826
|
-
)).trim().toLowerCase();
|
|
14827
|
-
const index = Number.parseInt(answer, 10);
|
|
14828
|
-
if (Number.isFinite(index) && index >= 1 && index <= buckets.length) {
|
|
14829
|
-
return buckets[index - 1];
|
|
14830
|
-
}
|
|
14831
|
-
const nameIndex = normalized.indexOf(answer);
|
|
14832
|
-
if (nameIndex >= 0) {
|
|
14833
|
-
return buckets[nameIndex];
|
|
14834
|
-
}
|
|
14835
|
-
ui.warn("Please choose a valid bucket number or name.");
|
|
14719
|
+
resolveBucket(value) {
|
|
14720
|
+
const normalized = value?.trim();
|
|
14721
|
+
if (normalized) {
|
|
14722
|
+
return normalized;
|
|
14836
14723
|
}
|
|
14724
|
+
return _OssCommandHandler.DEFAULT_BUCKET;
|
|
14837
14725
|
}
|
|
14838
14726
|
};
|
|
14839
14727
|
|
|
14840
14728
|
// src/commands/EnvCommandHandler.ts
|
|
14841
14729
|
var import_node_path12 = __toESM(require("path"));
|
|
14842
|
-
var
|
|
14730
|
+
var import_node_child_process5 = require("child_process");
|
|
14843
14731
|
var EnvCommandHandler = class {
|
|
14844
14732
|
async handle(args) {
|
|
14845
14733
|
const appName = args.envApp.trim();
|
|
@@ -15126,7 +15014,7 @@ var EnvCommandHandler = class {
|
|
|
15126
15014
|
runRemoteCommand(server, command) {
|
|
15127
15015
|
return new Promise((resolve, reject) => {
|
|
15128
15016
|
const target = `pmate@${server}`;
|
|
15129
|
-
const child = (0,
|
|
15017
|
+
const child = (0, import_node_child_process5.spawn)("ssh", buildSshBashArgs(target, command), {
|
|
15130
15018
|
stdio: "inherit"
|
|
15131
15019
|
});
|
|
15132
15020
|
child.on("error", (error) => {
|
|
@@ -15144,7 +15032,7 @@ var EnvCommandHandler = class {
|
|
|
15144
15032
|
runRemoteCommandCapture(server, command) {
|
|
15145
15033
|
return new Promise((resolve, reject) => {
|
|
15146
15034
|
const target = `pmate@${server}`;
|
|
15147
|
-
const child = (0,
|
|
15035
|
+
const child = (0, import_node_child_process5.spawn)("ssh", buildSshBashArgs(target, command), {
|
|
15148
15036
|
stdio: ["ignore", "pipe", "pipe"]
|
|
15149
15037
|
});
|
|
15150
15038
|
let output = "";
|
|
@@ -15193,7 +15081,7 @@ function formatEnvValue(value) {
|
|
|
15193
15081
|
}
|
|
15194
15082
|
|
|
15195
15083
|
// src/commands/PrCommandHandler.ts
|
|
15196
|
-
var
|
|
15084
|
+
var import_node_child_process6 = require("child_process");
|
|
15197
15085
|
var PrCommandHandler = class {
|
|
15198
15086
|
constructor(cwd = process.cwd()) {
|
|
15199
15087
|
this.cwd = cwd;
|
|
@@ -15665,7 +15553,7 @@ ${lines}`;
|
|
|
15665
15553
|
}
|
|
15666
15554
|
run(command, args, quietError = false, env, cwd) {
|
|
15667
15555
|
return new Promise((resolve, reject) => {
|
|
15668
|
-
const child = (0,
|
|
15556
|
+
const child = (0, import_node_child_process6.spawn)(command, args, {
|
|
15669
15557
|
stdio: quietError ? "ignore" : "inherit",
|
|
15670
15558
|
env: env ?? process.env,
|
|
15671
15559
|
cwd: cwd ?? this.cwd
|
|
@@ -15684,7 +15572,7 @@ ${lines}`;
|
|
|
15684
15572
|
}
|
|
15685
15573
|
runCapture(command, args, allowFailure = false, env, cwd) {
|
|
15686
15574
|
return new Promise((resolve, reject) => {
|
|
15687
|
-
const child = (0,
|
|
15575
|
+
const child = (0, import_node_child_process6.spawn)(command, args, {
|
|
15688
15576
|
stdio: ["ignore", "pipe", "pipe"],
|
|
15689
15577
|
env: env ?? process.env,
|
|
15690
15578
|
cwd: cwd ?? this.cwd
|
|
@@ -15825,7 +15713,7 @@ var CommitCommandHandler = class {
|
|
|
15825
15713
|
};
|
|
15826
15714
|
|
|
15827
15715
|
// src/commands/SummaryCommandHandler.ts
|
|
15828
|
-
var
|
|
15716
|
+
var import_node_child_process7 = require("child_process");
|
|
15829
15717
|
var import_node_path14 = __toESM(require("path"));
|
|
15830
15718
|
var SummaryCommandHandler = class {
|
|
15831
15719
|
async handle(args) {
|
|
@@ -15934,7 +15822,7 @@ var SummaryCommandHandler = class {
|
|
|
15934
15822
|
}
|
|
15935
15823
|
run(command, args, quietError = false, env, cwd) {
|
|
15936
15824
|
return new Promise((resolve, reject) => {
|
|
15937
|
-
const child = (0,
|
|
15825
|
+
const child = (0, import_node_child_process7.spawn)(command, args, {
|
|
15938
15826
|
stdio: quietError ? "ignore" : "inherit",
|
|
15939
15827
|
env: env ?? process.env,
|
|
15940
15828
|
cwd
|
|
@@ -15953,7 +15841,7 @@ var SummaryCommandHandler = class {
|
|
|
15953
15841
|
}
|
|
15954
15842
|
runCapture(command, args, allowFailure = false, env, cwd) {
|
|
15955
15843
|
return new Promise((resolve, reject) => {
|
|
15956
|
-
const child = (0,
|
|
15844
|
+
const child = (0, import_node_child_process7.spawn)(command, args, {
|
|
15957
15845
|
stdio: ["ignore", "pipe", "pipe"],
|
|
15958
15846
|
env: env ?? process.env,
|
|
15959
15847
|
cwd
|
|
@@ -16023,11 +15911,11 @@ function truncate2(value, limit) {
|
|
|
16023
15911
|
}
|
|
16024
15912
|
|
|
16025
15913
|
// src/commands/LinearCommandHandler.ts
|
|
16026
|
-
var
|
|
16027
|
-
var
|
|
15914
|
+
var import_node_child_process8 = require("child_process");
|
|
15915
|
+
var import_node_fs10 = require("fs");
|
|
16028
15916
|
var import_node_os5 = __toESM(require("os"));
|
|
16029
15917
|
var import_node_path15 = __toESM(require("path"));
|
|
16030
|
-
var
|
|
15918
|
+
var import_promises3 = require("readline/promises");
|
|
16031
15919
|
var import_openai = __toESM(require("openai"));
|
|
16032
15920
|
var import_sdk = require("@linear/sdk");
|
|
16033
15921
|
var ISSUE_SUMMARY_FIELDS = `
|
|
@@ -16878,7 +16766,7 @@ var LinearCommandHandler = class {
|
|
|
16878
16766
|
return accounts[index];
|
|
16879
16767
|
}
|
|
16880
16768
|
}
|
|
16881
|
-
const rl = (0,
|
|
16769
|
+
const rl = (0, import_promises3.createInterface)({
|
|
16882
16770
|
input: process.stdin,
|
|
16883
16771
|
output: process.stdout
|
|
16884
16772
|
});
|
|
@@ -16914,11 +16802,11 @@ var LinearCommandHandler = class {
|
|
|
16914
16802
|
}
|
|
16915
16803
|
readCachedLinearSelection(cwd) {
|
|
16916
16804
|
const selectionPath = this.getLinearSelectionPath();
|
|
16917
|
-
if (!(0,
|
|
16805
|
+
if (!(0, import_node_fs10.existsSync)(selectionPath)) {
|
|
16918
16806
|
return void 0;
|
|
16919
16807
|
}
|
|
16920
16808
|
try {
|
|
16921
|
-
const raw = (0,
|
|
16809
|
+
const raw = (0, import_node_fs10.readFileSync)(selectionPath, "utf8").trim();
|
|
16922
16810
|
if (!raw) return void 0;
|
|
16923
16811
|
const parsed = JSON.parse(raw);
|
|
16924
16812
|
const value = parsed[cwd];
|
|
@@ -16930,11 +16818,11 @@ var LinearCommandHandler = class {
|
|
|
16930
16818
|
writeCachedLinearSelection(cwd, title) {
|
|
16931
16819
|
const selectionPath = this.getLinearSelectionPath();
|
|
16932
16820
|
const dir = import_node_path15.default.dirname(selectionPath);
|
|
16933
|
-
(0,
|
|
16821
|
+
(0, import_node_fs10.mkdirSync)(dir, { recursive: true });
|
|
16934
16822
|
let data = {};
|
|
16935
|
-
if ((0,
|
|
16823
|
+
if ((0, import_node_fs10.existsSync)(selectionPath)) {
|
|
16936
16824
|
try {
|
|
16937
|
-
const raw = (0,
|
|
16825
|
+
const raw = (0, import_node_fs10.readFileSync)(selectionPath, "utf8").trim();
|
|
16938
16826
|
if (raw) {
|
|
16939
16827
|
data = JSON.parse(raw);
|
|
16940
16828
|
}
|
|
@@ -16943,7 +16831,7 @@ var LinearCommandHandler = class {
|
|
|
16943
16831
|
}
|
|
16944
16832
|
}
|
|
16945
16833
|
data[cwd] = title;
|
|
16946
|
-
(0,
|
|
16834
|
+
(0, import_node_fs10.writeFileSync)(selectionPath, `${JSON.stringify(data, null, 2)}
|
|
16947
16835
|
`, "utf8");
|
|
16948
16836
|
}
|
|
16949
16837
|
async lookupIssue(client, issueRef) {
|
|
@@ -17044,7 +16932,7 @@ var LinearCommandHandler = class {
|
|
|
17044
16932
|
ui.info(issue.description?.trim() ? issue.description : " (no description)");
|
|
17045
16933
|
}
|
|
17046
16934
|
async collectReplInput() {
|
|
17047
|
-
const rl = (0,
|
|
16935
|
+
const rl = (0, import_promises3.createInterface)({
|
|
17048
16936
|
input: process.stdin,
|
|
17049
16937
|
output: process.stdout
|
|
17050
16938
|
});
|
|
@@ -17104,7 +16992,7 @@ var LinearCommandHandler = class {
|
|
|
17104
16992
|
} else {
|
|
17105
16993
|
ui.info("Copy a screenshot to your clipboard, then press Enter.");
|
|
17106
16994
|
}
|
|
17107
|
-
const rl = (0,
|
|
16995
|
+
const rl = (0, import_promises3.createInterface)({
|
|
17108
16996
|
input: process.stdin,
|
|
17109
16997
|
output: process.stdout
|
|
17110
16998
|
});
|
|
@@ -17120,14 +17008,14 @@ var LinearCommandHandler = class {
|
|
|
17120
17008
|
if (process.platform !== "darwin") {
|
|
17121
17009
|
throw new Error("Screenshot capture only supports macOS.");
|
|
17122
17010
|
}
|
|
17123
|
-
const dir = await
|
|
17011
|
+
const dir = await import_node_fs10.promises.mkdtemp(import_node_path15.default.join(import_node_os5.default.tmpdir(), "pmate-screenshot-"));
|
|
17124
17012
|
const filePath = import_node_path15.default.join(dir, `screenshot-${index}.png`);
|
|
17125
17013
|
try {
|
|
17126
17014
|
const code = await this.run("screencapture", ["-i", "-x", filePath], true);
|
|
17127
17015
|
if (code !== 0) {
|
|
17128
17016
|
throw new Error("Screenshot capture canceled or failed.");
|
|
17129
17017
|
}
|
|
17130
|
-
const buffer = await
|
|
17018
|
+
const buffer = await import_node_fs10.promises.readFile(filePath);
|
|
17131
17019
|
if (buffer.length === 0) {
|
|
17132
17020
|
throw new Error("Screenshot capture produced an empty file.");
|
|
17133
17021
|
}
|
|
@@ -17139,7 +17027,7 @@ var LinearCommandHandler = class {
|
|
|
17139
17027
|
return { buffer, mime, filename: `screenshot-${index}.${extension}` };
|
|
17140
17028
|
} finally {
|
|
17141
17029
|
try {
|
|
17142
|
-
await
|
|
17030
|
+
await import_node_fs10.promises.rm(dir, { recursive: true, force: true });
|
|
17143
17031
|
} catch {
|
|
17144
17032
|
}
|
|
17145
17033
|
}
|
|
@@ -17283,17 +17171,17 @@ var LinearCommandHandler = class {
|
|
|
17283
17171
|
return compact.length > limit ? `${compact.slice(0, limit)}...` : compact;
|
|
17284
17172
|
}
|
|
17285
17173
|
async convertToPng(buffer, ext) {
|
|
17286
|
-
const dir = await
|
|
17174
|
+
const dir = await import_node_fs10.promises.mkdtemp(import_node_path15.default.join(import_node_os5.default.tmpdir(), "pmate-"));
|
|
17287
17175
|
const inputPath = import_node_path15.default.join(dir, `clipboard.${ext}`);
|
|
17288
17176
|
const outputPath = import_node_path15.default.join(dir, "clipboard.png");
|
|
17289
17177
|
try {
|
|
17290
|
-
await
|
|
17178
|
+
await import_node_fs10.promises.writeFile(inputPath, buffer);
|
|
17291
17179
|
const stderr = await this.runCapture(
|
|
17292
17180
|
"sips",
|
|
17293
17181
|
["-s", "format", "png", inputPath, "--out", outputPath],
|
|
17294
17182
|
true
|
|
17295
17183
|
);
|
|
17296
|
-
const out = await
|
|
17184
|
+
const out = await import_node_fs10.promises.readFile(outputPath);
|
|
17297
17185
|
if (this.detectImageMime(out) !== "image/png") {
|
|
17298
17186
|
throw new Error(
|
|
17299
17187
|
stderr?.trim() ? `Failed to convert clipboard ${ext} to PNG: ${stderr.trim()}` : `Failed to convert clipboard ${ext} to PNG.`
|
|
@@ -17302,14 +17190,14 @@ var LinearCommandHandler = class {
|
|
|
17302
17190
|
return out;
|
|
17303
17191
|
} finally {
|
|
17304
17192
|
try {
|
|
17305
|
-
await
|
|
17193
|
+
await import_node_fs10.promises.rm(dir, { recursive: true, force: true });
|
|
17306
17194
|
} catch {
|
|
17307
17195
|
}
|
|
17308
17196
|
}
|
|
17309
17197
|
}
|
|
17310
17198
|
captureClipboard(preferred) {
|
|
17311
17199
|
return new Promise((resolve, reject) => {
|
|
17312
|
-
const child = (0,
|
|
17200
|
+
const child = (0, import_node_child_process8.spawn)("pbpaste", ["-Prefer", preferred], {
|
|
17313
17201
|
stdio: ["ignore", "pipe", "pipe"]
|
|
17314
17202
|
});
|
|
17315
17203
|
const chunks = [];
|
|
@@ -17519,7 +17407,7 @@ var LinearCommandHandler = class {
|
|
|
17519
17407
|
}
|
|
17520
17408
|
run(command, args, quietError = false, env, cwd) {
|
|
17521
17409
|
return new Promise((resolve, reject) => {
|
|
17522
|
-
const child = (0,
|
|
17410
|
+
const child = (0, import_node_child_process8.spawn)(command, args, {
|
|
17523
17411
|
stdio: quietError ? "ignore" : "inherit",
|
|
17524
17412
|
env: env ?? process.env,
|
|
17525
17413
|
cwd
|
|
@@ -17538,7 +17426,7 @@ var LinearCommandHandler = class {
|
|
|
17538
17426
|
}
|
|
17539
17427
|
runCapture(command, args, allowFailure = false, env, cwd) {
|
|
17540
17428
|
return new Promise((resolve, reject) => {
|
|
17541
|
-
const child = (0,
|
|
17429
|
+
const child = (0, import_node_child_process8.spawn)(command, args, {
|
|
17542
17430
|
stdio: ["ignore", "pipe", "pipe"],
|
|
17543
17431
|
env: env ?? process.env,
|
|
17544
17432
|
cwd
|
|
@@ -17648,7 +17536,7 @@ function sleep(ms) {
|
|
|
17648
17536
|
}
|
|
17649
17537
|
|
|
17650
17538
|
// src/commands/NotionCommandHandler.ts
|
|
17651
|
-
var
|
|
17539
|
+
var import_node_fs11 = require("fs");
|
|
17652
17540
|
var import_node_path16 = __toESM(require("path"));
|
|
17653
17541
|
|
|
17654
17542
|
// src/services/NotionService.ts
|
|
@@ -17989,16 +17877,16 @@ var NotionCommandHandler = class {
|
|
|
17989
17877
|
return "";
|
|
17990
17878
|
}
|
|
17991
17879
|
const resolved = import_node_path16.default.resolve(process.cwd(), args.filePath);
|
|
17992
|
-
return (0,
|
|
17880
|
+
return (0, import_node_fs11.readFileSync)(resolved, "utf8");
|
|
17993
17881
|
}
|
|
17994
17882
|
};
|
|
17995
17883
|
|
|
17996
17884
|
// src/commands/QrcodeCommandHandler.ts
|
|
17997
|
-
var
|
|
17998
|
-
var
|
|
17885
|
+
var import_node_child_process9 = require("child_process");
|
|
17886
|
+
var import_node_fs12 = require("fs");
|
|
17999
17887
|
var import_node_os6 = __toESM(require("os"));
|
|
18000
17888
|
var import_node_path17 = __toESM(require("path"));
|
|
18001
|
-
var
|
|
17889
|
+
var import_promises4 = require("readline/promises");
|
|
18002
17890
|
var import_jsqr = __toESM(require("jsqr"));
|
|
18003
17891
|
var import_pngjs = require("pngjs");
|
|
18004
17892
|
var QrcodeCommandHandler = class {
|
|
@@ -18023,14 +17911,14 @@ var QrcodeCommandHandler = class {
|
|
|
18023
17911
|
ui.success("QR code value:", value);
|
|
18024
17912
|
} finally {
|
|
18025
17913
|
try {
|
|
18026
|
-
await
|
|
17914
|
+
await import_node_fs12.promises.rm(dir, { recursive: true, force: true });
|
|
18027
17915
|
} catch {
|
|
18028
17916
|
}
|
|
18029
17917
|
}
|
|
18030
17918
|
}
|
|
18031
17919
|
async captureScreenshot() {
|
|
18032
17920
|
ui.info("Capture a QR code screenshot now (macOS screencapture).");
|
|
18033
|
-
const rl = (0,
|
|
17921
|
+
const rl = (0, import_promises4.createInterface)({
|
|
18034
17922
|
input: process.stdin,
|
|
18035
17923
|
output: process.stdout
|
|
18036
17924
|
});
|
|
@@ -18039,13 +17927,13 @@ var QrcodeCommandHandler = class {
|
|
|
18039
17927
|
} finally {
|
|
18040
17928
|
rl.close();
|
|
18041
17929
|
}
|
|
18042
|
-
const dir = await
|
|
17930
|
+
const dir = await import_node_fs12.promises.mkdtemp(import_node_path17.default.join(import_node_os6.default.tmpdir(), "pmate-qrcode-"));
|
|
18043
17931
|
const filePath = import_node_path17.default.join(dir, "qrcode.png");
|
|
18044
17932
|
const code = await this.run("screencapture", ["-i", "-x", filePath], true);
|
|
18045
17933
|
if (code !== 0) {
|
|
18046
17934
|
throw new Error("Screenshot capture canceled or failed.");
|
|
18047
17935
|
}
|
|
18048
|
-
const buffer = await
|
|
17936
|
+
const buffer = await import_node_fs12.promises.readFile(filePath);
|
|
18049
17937
|
if (buffer.length === 0) {
|
|
18050
17938
|
throw new Error("Screenshot capture produced an empty file.");
|
|
18051
17939
|
}
|
|
@@ -18061,7 +17949,7 @@ var QrcodeCommandHandler = class {
|
|
|
18061
17949
|
async decodeQr(filePath) {
|
|
18062
17950
|
let buffer;
|
|
18063
17951
|
try {
|
|
18064
|
-
buffer = await
|
|
17952
|
+
buffer = await import_node_fs12.promises.readFile(filePath);
|
|
18065
17953
|
} catch {
|
|
18066
17954
|
return null;
|
|
18067
17955
|
}
|
|
@@ -18081,7 +17969,7 @@ var QrcodeCommandHandler = class {
|
|
|
18081
17969
|
return value ? value : null;
|
|
18082
17970
|
}
|
|
18083
17971
|
async promptValue(detected) {
|
|
18084
|
-
const rl = (0,
|
|
17972
|
+
const rl = (0, import_promises4.createInterface)({
|
|
18085
17973
|
input: process.stdin,
|
|
18086
17974
|
output: process.stdout
|
|
18087
17975
|
});
|
|
@@ -18102,7 +17990,7 @@ var QrcodeCommandHandler = class {
|
|
|
18102
17990
|
}
|
|
18103
17991
|
run(command, args, quietError = false, env, cwd) {
|
|
18104
17992
|
return new Promise((resolve, reject) => {
|
|
18105
|
-
const child = (0,
|
|
17993
|
+
const child = (0, import_node_child_process9.spawn)(command, args, {
|
|
18106
17994
|
stdio: quietError ? "ignore" : "inherit",
|
|
18107
17995
|
env: env ?? process.env,
|
|
18108
17996
|
cwd
|
|
@@ -18321,7 +18209,7 @@ function clampNumber(value, min, max, fallback) {
|
|
|
18321
18209
|
// src/commands/CollectCommandHandler.ts
|
|
18322
18210
|
var import_playwright = require("playwright");
|
|
18323
18211
|
var import_node_crypto3 = require("crypto");
|
|
18324
|
-
var
|
|
18212
|
+
var import_node_fs13 = require("fs");
|
|
18325
18213
|
var import_node_os7 = __toESM(require("os"));
|
|
18326
18214
|
var import_node_path18 = __toESM(require("path"));
|
|
18327
18215
|
var CollectCommandHandler = class {
|
|
@@ -18698,11 +18586,11 @@ async function toDisplayableImagePath(src) {
|
|
|
18698
18586
|
return src;
|
|
18699
18587
|
}
|
|
18700
18588
|
try {
|
|
18701
|
-
const stat = await
|
|
18589
|
+
const stat = await import_node_fs13.promises.stat(src);
|
|
18702
18590
|
if (!stat.isFile()) {
|
|
18703
18591
|
return src;
|
|
18704
18592
|
}
|
|
18705
|
-
const fh = await
|
|
18593
|
+
const fh = await import_node_fs13.promises.open(src, "r");
|
|
18706
18594
|
try {
|
|
18707
18595
|
const buf = Buffer.alloc(32);
|
|
18708
18596
|
const { bytesRead } = await fh.read(buf, 0, 32, 0);
|
|
@@ -18717,11 +18605,11 @@ async function toDisplayableImagePath(src) {
|
|
|
18717
18605
|
"messages",
|
|
18718
18606
|
"images"
|
|
18719
18607
|
);
|
|
18720
|
-
await
|
|
18608
|
+
await import_node_fs13.promises.mkdir(cacheDir, { recursive: true });
|
|
18721
18609
|
const base = (0, import_node_crypto3.createHash)("sha1").update(src).digest("hex");
|
|
18722
18610
|
const displayPath = import_node_path18.default.join(cacheDir, `${base}.${guessedExt}`);
|
|
18723
|
-
await
|
|
18724
|
-
await
|
|
18611
|
+
await import_node_fs13.promises.rm(displayPath, { force: true }).catch(() => void 0);
|
|
18612
|
+
await import_node_fs13.promises.copyFile(src, displayPath);
|
|
18725
18613
|
return displayPath;
|
|
18726
18614
|
} finally {
|
|
18727
18615
|
await fh.close();
|
|
@@ -18777,7 +18665,7 @@ function parseMessageText(raw) {
|
|
|
18777
18665
|
}
|
|
18778
18666
|
|
|
18779
18667
|
// src/commands/AgentCommandHandler.ts
|
|
18780
|
-
var
|
|
18668
|
+
var import_node_fs14 = require("fs");
|
|
18781
18669
|
var import_node_os8 = __toESM(require("os"));
|
|
18782
18670
|
var import_node_path19 = __toESM(require("path"));
|
|
18783
18671
|
var AgentCommandHandler = class {
|
|
@@ -18862,10 +18750,10 @@ var AgentCommandHandler = class {
|
|
|
18862
18750
|
}
|
|
18863
18751
|
readToken() {
|
|
18864
18752
|
const sessionPath = import_node_path19.default.join(import_node_os8.default.homedir(), ".pmate", "session.json");
|
|
18865
|
-
if (!(0,
|
|
18753
|
+
if (!(0, import_node_fs14.existsSync)(sessionPath)) {
|
|
18866
18754
|
throw new Error(`Missing session file at ${sessionPath}. Run "pmate login" first.`);
|
|
18867
18755
|
}
|
|
18868
|
-
const raw = (0,
|
|
18756
|
+
const raw = (0, import_node_fs14.readFileSync)(sessionPath, "utf8");
|
|
18869
18757
|
const parsed = JSON.parse(raw);
|
|
18870
18758
|
const token = parsed.token?.trim();
|
|
18871
18759
|
if (!token) {
|
|
@@ -18875,10 +18763,10 @@ var AgentCommandHandler = class {
|
|
|
18875
18763
|
}
|
|
18876
18764
|
readJsonFile(filePath) {
|
|
18877
18765
|
const absolutePath = import_node_path19.default.resolve(process.cwd(), filePath);
|
|
18878
|
-
if (!(0,
|
|
18766
|
+
if (!(0, import_node_fs14.existsSync)(absolutePath)) {
|
|
18879
18767
|
throw new Error(`JSON file not found: ${absolutePath}`);
|
|
18880
18768
|
}
|
|
18881
|
-
const raw = (0,
|
|
18769
|
+
const raw = (0, import_node_fs14.readFileSync)(absolutePath, "utf8");
|
|
18882
18770
|
try {
|
|
18883
18771
|
return JSON.parse(raw);
|
|
18884
18772
|
} catch (error) {
|
|
@@ -18947,7 +18835,7 @@ var AgentCommandHandler = class {
|
|
|
18947
18835
|
};
|
|
18948
18836
|
|
|
18949
18837
|
// src/commands/AppCommandHandler.ts
|
|
18950
|
-
var
|
|
18838
|
+
var import_node_fs15 = require("fs");
|
|
18951
18839
|
var import_node_os9 = __toESM(require("os"));
|
|
18952
18840
|
var import_node_path20 = __toESM(require("path"));
|
|
18953
18841
|
var AppCommandHandler = class {
|
|
@@ -19019,10 +18907,10 @@ var AppCommandHandler = class {
|
|
|
19019
18907
|
}
|
|
19020
18908
|
readToken() {
|
|
19021
18909
|
const sessionPath = import_node_path20.default.join(import_node_os9.default.homedir(), ".pmate", "session.json");
|
|
19022
|
-
if (!(0,
|
|
18910
|
+
if (!(0, import_node_fs15.existsSync)(sessionPath)) {
|
|
19023
18911
|
throw new Error(`Missing session file at ${sessionPath}. Run "pmate login" first.`);
|
|
19024
18912
|
}
|
|
19025
|
-
const raw = (0,
|
|
18913
|
+
const raw = (0, import_node_fs15.readFileSync)(sessionPath, "utf8");
|
|
19026
18914
|
const parsed = JSON.parse(raw);
|
|
19027
18915
|
const token = parsed.token?.trim();
|
|
19028
18916
|
if (!token) {
|
|
@@ -19032,10 +18920,10 @@ var AppCommandHandler = class {
|
|
|
19032
18920
|
}
|
|
19033
18921
|
readJsonFile(filePath) {
|
|
19034
18922
|
const absolutePath = import_node_path20.default.resolve(process.cwd(), filePath);
|
|
19035
|
-
if (!(0,
|
|
18923
|
+
if (!(0, import_node_fs15.existsSync)(absolutePath)) {
|
|
19036
18924
|
throw new Error(`JSON file not found: ${absolutePath}`);
|
|
19037
18925
|
}
|
|
19038
|
-
const raw = (0,
|
|
18926
|
+
const raw = (0, import_node_fs15.readFileSync)(absolutePath, "utf8");
|
|
19039
18927
|
try {
|
|
19040
18928
|
return JSON.parse(raw);
|
|
19041
18929
|
} catch (error) {
|
|
@@ -19088,9 +18976,9 @@ var AppCommandHandler = class {
|
|
|
19088
18976
|
};
|
|
19089
18977
|
|
|
19090
18978
|
// src/commands/VercelCommandHandler.ts
|
|
19091
|
-
var
|
|
18979
|
+
var import_node_child_process10 = require("child_process");
|
|
19092
18980
|
var import_node_util = require("util");
|
|
19093
|
-
var execFileAsync = (0, import_node_util.promisify)(
|
|
18981
|
+
var execFileAsync = (0, import_node_util.promisify)(import_node_child_process10.execFile);
|
|
19094
18982
|
function parseDeploymentTimestamp(deployment) {
|
|
19095
18983
|
const candidates = [deployment.createdAt, deployment.readyAt, deployment.ready];
|
|
19096
18984
|
for (const value of candidates) {
|
|
@@ -19452,7 +19340,7 @@ function requireValue2(tokens, optionName) {
|
|
|
19452
19340
|
|
|
19453
19341
|
// src/index.ts
|
|
19454
19342
|
var pkg = JSON.parse(
|
|
19455
|
-
(0,
|
|
19343
|
+
(0, import_node_fs16.readFileSync)(import_node_path21.default.resolve(__dirname, "..", "package.json"), "utf8")
|
|
19456
19344
|
);
|
|
19457
19345
|
var HELP_TEXT = [
|
|
19458
19346
|
import_chalk3.default.bold(`pmate v${pkg.version}`),
|
|
@@ -19476,8 +19364,8 @@ var HELP_TEXT = [
|
|
|
19476
19364
|
` ${import_chalk3.default.gray(" --create --name <bucket>")}`,
|
|
19477
19365
|
` ${import_chalk3.default.cyan("deploy")} Deploy or view logs for app dir from .pmate.yaml`,
|
|
19478
19366
|
` ${import_chalk3.default.gray(" <app-name> [deploy|logs] [--cwd <dir>]")}`,
|
|
19479
|
-
` ${import_chalk3.default.cyan("log")}
|
|
19480
|
-
` ${import_chalk3.default.gray(" <app-name> [--cwd <dir>]")}`,
|
|
19367
|
+
` ${import_chalk3.default.cyan("log")} Query app logs from the log indexer API`,
|
|
19368
|
+
` ${import_chalk3.default.gray(" <app-name> [--ns <namespace>] [--search <keyword>] [--page <n>] [--history] [--cwd <dir>]")}`,
|
|
19481
19369
|
` ${import_chalk3.default.cyan("init")} Initialize an app bucket + CDN`,
|
|
19482
19370
|
` ${import_chalk3.default.gray(" <app-name> [--cwd <dir>]")}`,
|
|
19483
19371
|
` ${import_chalk3.default.cyan("dev")} Run the dev script for app dir from .pmate.yaml`,
|
|
@@ -19838,7 +19726,9 @@ function parseDeployArgs(tokens) {
|
|
|
19838
19726
|
function parseLogArgs(tokens) {
|
|
19839
19727
|
const options = {
|
|
19840
19728
|
logApp: "",
|
|
19841
|
-
logCwd: process.cwd()
|
|
19729
|
+
logCwd: process.cwd(),
|
|
19730
|
+
logPage: 0,
|
|
19731
|
+
logHistory: false
|
|
19842
19732
|
};
|
|
19843
19733
|
const rest = [...tokens];
|
|
19844
19734
|
const appName = rest.shift();
|
|
@@ -19852,6 +19742,24 @@ function parseLogArgs(tokens) {
|
|
|
19852
19742
|
case "--cwd":
|
|
19853
19743
|
options.logCwd = requireValue3(rest, token);
|
|
19854
19744
|
break;
|
|
19745
|
+
case "--ns":
|
|
19746
|
+
options.logNamespace = requireValue3(rest, token);
|
|
19747
|
+
break;
|
|
19748
|
+
case "--page": {
|
|
19749
|
+
const value = requireValue3(rest, token);
|
|
19750
|
+
const page = Number.parseInt(value, 10);
|
|
19751
|
+
if (!Number.isFinite(page) || page < 0) {
|
|
19752
|
+
throw new Error(`Invalid log page: ${value}`);
|
|
19753
|
+
}
|
|
19754
|
+
options.logPage = page;
|
|
19755
|
+
break;
|
|
19756
|
+
}
|
|
19757
|
+
case "--history":
|
|
19758
|
+
options.logHistory = true;
|
|
19759
|
+
break;
|
|
19760
|
+
case "--search":
|
|
19761
|
+
options.logSearch = requireValue3(rest, token);
|
|
19762
|
+
break;
|
|
19855
19763
|
default:
|
|
19856
19764
|
throw new Error(`Unknown log option: ${token}`);
|
|
19857
19765
|
}
|
|
@@ -19919,11 +19827,15 @@ function parseOssArgs(tokens) {
|
|
|
19919
19827
|
if (action !== "upload") {
|
|
19920
19828
|
throw new Error(`Unknown oss action: ${action}`);
|
|
19921
19829
|
}
|
|
19830
|
+
let bucket;
|
|
19922
19831
|
let filePath;
|
|
19923
19832
|
let objectKey;
|
|
19924
19833
|
while (rest.length > 0) {
|
|
19925
19834
|
const token = rest.shift();
|
|
19926
19835
|
switch (token) {
|
|
19836
|
+
case "--bucket":
|
|
19837
|
+
bucket = requireValue3(rest, token);
|
|
19838
|
+
break;
|
|
19927
19839
|
case "--file":
|
|
19928
19840
|
filePath = requireValue3(rest, token);
|
|
19929
19841
|
break;
|
|
@@ -19940,7 +19852,7 @@ function parseOssArgs(tokens) {
|
|
|
19940
19852
|
if (!objectKey) {
|
|
19941
19853
|
throw new Error("Missing required option --key for oss upload");
|
|
19942
19854
|
}
|
|
19943
|
-
return { type: "oss" /* Oss */, action, filePath, objectKey };
|
|
19855
|
+
return { type: "oss" /* Oss */, action, bucket, filePath, objectKey };
|
|
19944
19856
|
}
|
|
19945
19857
|
function parseEnvArgs(tokens) {
|
|
19946
19858
|
const rest = [...tokens];
|