@pmate/cli 0.46.2 → 0.47.0
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/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -94,41 +94,53 @@ function assertValidAppRef(appRef2) {
|
|
|
94
94
|
return parseNamespacedRef(appRef2, { entityLabel: "app ref" }).fullId;
|
|
95
95
|
}
|
|
96
96
|
function saveLoginSession(session, requestedApp = DEFAULT_APP_ID) {
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
);
|
|
97
|
+
const sessionPath = buildSessionStorePath();
|
|
98
|
+
(0, import_node_fs5.mkdirSync)(import_node_path6.default.dirname(sessionPath), { recursive: true, mode: 448 });
|
|
99
|
+
const lock = sessionPath + ".lock";
|
|
100
|
+
try {
|
|
101
|
+
(0, import_node_fs5.mkdirSync)(lock);
|
|
102
|
+
} catch {
|
|
103
|
+
throw new Error("Session store is busy; retry login.");
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
const store = loadExistingSessionStoreOrEmpty();
|
|
107
|
+
const app = assertValidAppRef(requestedApp);
|
|
108
|
+
const sessionApp = session.session?.identity?.app?.trim();
|
|
109
|
+
if (!sessionApp) {
|
|
110
|
+
throw new Error("Missing app in login session payload.");
|
|
111
|
+
}
|
|
112
|
+
const normalizedSessionApp = assertValidAppRef(sessionApp);
|
|
113
|
+
if (normalizedSessionApp !== app) {
|
|
114
|
+
throw new Error(
|
|
115
|
+
`Session app mismatch. requested=${app}, received=${normalizedSessionApp}`
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
const accountId = session.session.identity?.accountId?.trim();
|
|
119
|
+
const profileId = session.profileId?.trim();
|
|
120
|
+
const token = session.token?.trim();
|
|
121
|
+
const issuedAt = session.session.issuedAt?.trim();
|
|
122
|
+
const expiresAt = session.session.expiresAt?.trim();
|
|
123
|
+
if (!accountId || !profileId || !token || !issuedAt || !expiresAt) {
|
|
124
|
+
throw new Error("Invalid login session payload.");
|
|
125
|
+
}
|
|
126
|
+
const nextSession = {
|
|
127
|
+
token,
|
|
128
|
+
accountId,
|
|
129
|
+
profileId,
|
|
130
|
+
issuedAt,
|
|
131
|
+
expiresAt,
|
|
132
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
133
|
+
};
|
|
134
|
+
store.sessions[app] = nextSession;
|
|
135
|
+
store.activeAppRef = app;
|
|
136
|
+
writeSessionStore(store);
|
|
137
|
+
return {
|
|
138
|
+
app,
|
|
139
|
+
sessionPath: buildSessionStorePath()
|
|
140
|
+
};
|
|
141
|
+
} finally {
|
|
142
|
+
(0, import_node_fs5.rmSync)(lock, { recursive: true, force: true });
|
|
108
143
|
}
|
|
109
|
-
const accountId = session.session.identity?.accountId?.trim();
|
|
110
|
-
const profileId = session.profileId?.trim();
|
|
111
|
-
const token = session.token?.trim();
|
|
112
|
-
const issuedAt = session.session.issuedAt?.trim();
|
|
113
|
-
const expiresAt = session.session.expiresAt?.trim();
|
|
114
|
-
if (!accountId || !profileId || !token || !issuedAt || !expiresAt) {
|
|
115
|
-
throw new Error("Invalid login session payload.");
|
|
116
|
-
}
|
|
117
|
-
const nextSession = {
|
|
118
|
-
token,
|
|
119
|
-
accountId,
|
|
120
|
-
profileId,
|
|
121
|
-
issuedAt,
|
|
122
|
-
expiresAt,
|
|
123
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
124
|
-
};
|
|
125
|
-
store.sessions[app] = nextSession;
|
|
126
|
-
store.activeAppRef = app;
|
|
127
|
-
writeSessionStore(store);
|
|
128
|
-
return {
|
|
129
|
-
app,
|
|
130
|
-
sessionPath: buildSessionStorePath()
|
|
131
|
-
};
|
|
132
144
|
}
|
|
133
145
|
function readRequiredSession(options) {
|
|
134
146
|
const { sessionPath, store } = loadSessionStoreWithPath();
|
|
@@ -165,15 +177,7 @@ function loadExistingSessionStoreOrEmpty() {
|
|
|
165
177
|
sessions: {}
|
|
166
178
|
};
|
|
167
179
|
}
|
|
168
|
-
|
|
169
|
-
return loadSessionStore();
|
|
170
|
-
} catch {
|
|
171
|
-
return {
|
|
172
|
-
version: SESSION_STORE_VERSION,
|
|
173
|
-
activeAppRef: DEFAULT_APP_ID,
|
|
174
|
-
sessions: {}
|
|
175
|
-
};
|
|
176
|
-
}
|
|
180
|
+
return loadSessionStore();
|
|
177
181
|
}
|
|
178
182
|
function loadSessionStoreWithPath() {
|
|
179
183
|
const sessionPath = buildSessionStorePath();
|
|
@@ -271,9 +275,13 @@ function resolveReadApp(store, options) {
|
|
|
271
275
|
function writeSessionStore(store) {
|
|
272
276
|
const sessionPath = buildSessionStorePath();
|
|
273
277
|
(0, import_node_fs5.mkdirSync)(import_node_path6.default.dirname(sessionPath), { recursive: true });
|
|
274
|
-
(0,
|
|
275
|
-
|
|
276
|
-
|
|
278
|
+
const temporary = sessionPath + "." + (0, import_node_crypto2.randomUUID)() + ".tmp";
|
|
279
|
+
try {
|
|
280
|
+
(0, import_node_fs5.writeFileSync)(temporary, JSON.stringify(store, null, 2), { mode: 384, flag: "wx" });
|
|
281
|
+
(0, import_node_fs5.renameSync)(temporary, sessionPath);
|
|
282
|
+
} finally {
|
|
283
|
+
(0, import_node_fs5.rmSync)(temporary, { force: true });
|
|
284
|
+
}
|
|
277
285
|
try {
|
|
278
286
|
(0, import_node_fs5.chmodSync)(sessionPath, 384);
|
|
279
287
|
} catch {
|
|
@@ -285,12 +293,13 @@ function buildMissingSessionMessage(sessionPath, app) {
|
|
|
285
293
|
}
|
|
286
294
|
return `Missing session for app ${app} in ${sessionPath}. Run "pmate login --app ${app}" first.`;
|
|
287
295
|
}
|
|
288
|
-
var import_node_fs5, import_node_os5, import_node_path6, DEFAULT_APP_ID, SESSION_STORE_VERSION;
|
|
296
|
+
var import_node_fs5, import_node_os5, import_node_crypto2, import_node_path6, DEFAULT_APP_ID, SESSION_STORE_VERSION;
|
|
289
297
|
var init_sessionStore = __esm({
|
|
290
298
|
"src/sessionStore.ts"() {
|
|
291
299
|
"use strict";
|
|
292
300
|
import_node_fs5 = require("fs");
|
|
293
301
|
import_node_os5 = __toESM(require("os"));
|
|
302
|
+
import_node_crypto2 = require("crypto");
|
|
294
303
|
import_node_path6 = __toESM(require("path"));
|
|
295
304
|
init_namespacedRef();
|
|
296
305
|
DEFAULT_APP_ID = "pmate:factory";
|
|
@@ -9637,6 +9646,8 @@ async function fetchBotProfileId(options) {
|
|
|
9637
9646
|
}
|
|
9638
9647
|
|
|
9639
9648
|
// src/commands/LoginCommandHandler.ts
|
|
9649
|
+
var ExpiredLoginTokenError = class extends Error {
|
|
9650
|
+
};
|
|
9640
9651
|
var AUTH_UI_BASE_URL = "https://auth.pmate.chat";
|
|
9641
9652
|
var CALLBACK_PATH = "/pmate-login-callback";
|
|
9642
9653
|
var LOGIN_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
@@ -9649,12 +9660,48 @@ function buildHostedLoginUrl(redirectUrl, appId = DEFAULT_APP_ID) {
|
|
|
9649
9660
|
}
|
|
9650
9661
|
var LoginCommandHandler = class {
|
|
9651
9662
|
async handle(args) {
|
|
9663
|
+
if (args.tokenStdin) {
|
|
9664
|
+
if (!args.app?.trim()) throw new Error("--token-stdin requires --app");
|
|
9665
|
+
if (args.accessKey || args.accessKeyFile || args.accessKeyScan) throw new Error("Token and access-key login cannot be combined");
|
|
9666
|
+
const token = await this.readTokenInput();
|
|
9667
|
+
const appId = assertValidAppRef(args.app);
|
|
9668
|
+
let loginResponse;
|
|
9669
|
+
try {
|
|
9670
|
+
loginResponse = await this.exchangeSession(token, appId);
|
|
9671
|
+
} catch (error) {
|
|
9672
|
+
if (!(error instanceof ExpiredLoginTokenError)) throw error;
|
|
9673
|
+
await this.handleHostedLogin(args);
|
|
9674
|
+
return;
|
|
9675
|
+
}
|
|
9676
|
+
this.assertExpectedAccount(loginResponse, args);
|
|
9677
|
+
const profiles = await fetchProfiles({ token: loginResponse.token, app: appId, accountId: loginResponse.session.identity.accountId });
|
|
9678
|
+
const profileId = await this.resolveProfileId({ appId, requestedProfileId: args.profileId, selectProfile: args.selectProfile, profiles });
|
|
9679
|
+
const saved = saveLoginSession({ ...loginResponse, profileId }, appId);
|
|
9680
|
+
ui.success(`Logged in to ${saved.app}. Session saved to ${saved.sessionPath}`);
|
|
9681
|
+
return;
|
|
9682
|
+
}
|
|
9652
9683
|
if (args.accessKey || args.accessKeyFile || args.accessKeyScan) {
|
|
9653
9684
|
await this.handleAccessKeyLogin(args);
|
|
9654
9685
|
return;
|
|
9655
9686
|
}
|
|
9656
9687
|
await this.handleHostedLogin(args);
|
|
9657
9688
|
}
|
|
9689
|
+
assertExpectedAccount(session, args) {
|
|
9690
|
+
if (args.expectedAccount && session.session.identity.accountId !== args.expectedAccount) {
|
|
9691
|
+
throw new Error("Login Account differs from the expected Runtime Owner; session was not saved.");
|
|
9692
|
+
}
|
|
9693
|
+
}
|
|
9694
|
+
async readTokenInput() {
|
|
9695
|
+
if (process.stdin.isTTY) throw new Error("--token-stdin requires piped input");
|
|
9696
|
+
let input = "";
|
|
9697
|
+
for await (const chunk of process.stdin) {
|
|
9698
|
+
input += chunk.toString();
|
|
9699
|
+
if (Buffer.byteLength(input) > 16384) throw new Error("Token input is too large");
|
|
9700
|
+
}
|
|
9701
|
+
const token = input.trim();
|
|
9702
|
+
if (!token || /\s/.test(token)) throw new Error("Expected one non-empty token on stdin");
|
|
9703
|
+
return token;
|
|
9704
|
+
}
|
|
9658
9705
|
async handleHostedLogin(args) {
|
|
9659
9706
|
const callback = await this.startCallbackServer();
|
|
9660
9707
|
const appId = assertValidAppRef(args.app?.trim() || DEFAULT_APP_ID);
|
|
@@ -9675,6 +9722,7 @@ var LoginCommandHandler = class {
|
|
|
9675
9722
|
try {
|
|
9676
9723
|
const token = await callback.waitForToken;
|
|
9677
9724
|
const loginResponse = await this.exchangeSession(token, appId);
|
|
9725
|
+
this.assertExpectedAccount(loginResponse, args);
|
|
9678
9726
|
const profiles = await fetchProfiles({
|
|
9679
9727
|
token: loginResponse.token,
|
|
9680
9728
|
app: appId,
|
|
@@ -9700,6 +9748,7 @@ var LoginCommandHandler = class {
|
|
|
9700
9748
|
const resolved = await this.resolveAccessKeyInput(args);
|
|
9701
9749
|
const appId = assertValidAppRef(resolved.app);
|
|
9702
9750
|
const loginResponse = await this.exchangeAccessKeySession(resolved.secret, appId);
|
|
9751
|
+
this.assertExpectedAccount(loginResponse, args);
|
|
9703
9752
|
const profiles = await fetchProfiles({
|
|
9704
9753
|
token: loginResponse.token,
|
|
9705
9754
|
app: appId,
|
|
@@ -9726,10 +9775,8 @@ var LoginCommandHandler = class {
|
|
|
9726
9775
|
body: JSON.stringify({ app: appId })
|
|
9727
9776
|
});
|
|
9728
9777
|
if (!response.ok) {
|
|
9729
|
-
|
|
9730
|
-
throw new Error(
|
|
9731
|
-
`Failed to exchange app session (${response.status}): ${detail || response.statusText}`
|
|
9732
|
-
);
|
|
9778
|
+
if (response.status === 401) throw new ExpiredLoginTokenError("Login token is expired or invalid");
|
|
9779
|
+
throw new Error(`Failed to exchange app session (${response.status})`);
|
|
9733
9780
|
}
|
|
9734
9781
|
const resp = await response.json();
|
|
9735
9782
|
const returnedApp = resp?.data?.session?.identity?.app?.trim();
|
|
@@ -10087,7 +10134,7 @@ var import_fc20230330 = __toESM(require("@alicloud/fc20230330"));
|
|
|
10087
10134
|
var import_openapi_client = require("@alicloud/openapi-client");
|
|
10088
10135
|
var import_sts20150401 = __toESM(require("@alicloud/sts20150401"));
|
|
10089
10136
|
var import_ali_oss = __toESM(require("ali-oss"));
|
|
10090
|
-
var
|
|
10137
|
+
var import_node_crypto3 = require("crypto");
|
|
10091
10138
|
var import_node_fs6 = require("fs");
|
|
10092
10139
|
var import_node_path8 = __toESM(require("path"));
|
|
10093
10140
|
|
|
@@ -10858,7 +10905,7 @@ var AliyunService = class {
|
|
|
10858
10905
|
/** Compute MD5 for a file. */
|
|
10859
10906
|
static getFileMd5(filePath) {
|
|
10860
10907
|
return new Promise((resolve, reject) => {
|
|
10861
|
-
const hash = (0,
|
|
10908
|
+
const hash = (0, import_node_crypto3.createHash)("md5");
|
|
10862
10909
|
const stream = (0, import_node_fs6.createReadStream)(filePath);
|
|
10863
10910
|
stream.on("data", (chunk) => {
|
|
10864
10911
|
hash.update(chunk);
|
|
@@ -14757,7 +14804,7 @@ var QrcodeCommandHandler = class {
|
|
|
14757
14804
|
};
|
|
14758
14805
|
|
|
14759
14806
|
// src/commands/RandomCommandHandler.ts
|
|
14760
|
-
var
|
|
14807
|
+
var import_node_crypto4 = require("crypto");
|
|
14761
14808
|
var DEFAULT_TOKEN_LENGTH = 32;
|
|
14762
14809
|
var DEFAULT_EASY_WORDS = 3;
|
|
14763
14810
|
var DEFAULT_EASY_DIGITS = 2;
|
|
@@ -14923,7 +14970,7 @@ function randomString(length, charset) {
|
|
|
14923
14970
|
const max = Math.floor(256 / charsetLength) * charsetLength;
|
|
14924
14971
|
let result = "";
|
|
14925
14972
|
while (result.length < length) {
|
|
14926
|
-
const bytes = (0,
|
|
14973
|
+
const bytes = (0, import_node_crypto4.randomBytes)(Math.max(1, length - result.length));
|
|
14927
14974
|
for (const byte of bytes) {
|
|
14928
14975
|
if (byte >= max) {
|
|
14929
14976
|
continue;
|
|
@@ -14937,12 +14984,12 @@ function randomString(length, charset) {
|
|
|
14937
14984
|
return result;
|
|
14938
14985
|
}
|
|
14939
14986
|
function randomWord() {
|
|
14940
|
-
return EASY_WORDS[(0,
|
|
14987
|
+
return EASY_WORDS[(0, import_node_crypto4.randomInt)(0, EASY_WORDS.length)];
|
|
14941
14988
|
}
|
|
14942
14989
|
function randomDigits(count) {
|
|
14943
14990
|
let value = "";
|
|
14944
14991
|
for (let i = 0; i < count; i += 1) {
|
|
14945
|
-
value += (0,
|
|
14992
|
+
value += (0, import_node_crypto4.randomInt)(0, 10).toString();
|
|
14946
14993
|
}
|
|
14947
14994
|
return value;
|
|
14948
14995
|
}
|
|
@@ -15727,20 +15774,20 @@ var Im1BotClient = class {
|
|
|
15727
15774
|
};
|
|
15728
15775
|
|
|
15729
15776
|
// src/collectStore.ts
|
|
15730
|
-
var
|
|
15777
|
+
var import_node_crypto5 = require("crypto");
|
|
15731
15778
|
var import_node_fs13 = require("fs");
|
|
15732
15779
|
var import_node_os8 = __toESM(require("os"));
|
|
15733
15780
|
var import_node_path19 = __toESM(require("path"));
|
|
15734
15781
|
function resolveCollectTarget(input) {
|
|
15735
15782
|
const endpoint = input.endpoint ?? (input.source === "cc" ? "http://localhost:9223" : "http://localhost:9222");
|
|
15736
|
-
const sourceKey = input.source ?? `endpoint-${(0,
|
|
15783
|
+
const sourceKey = input.source ?? `endpoint-${(0, import_node_crypto5.createHash)("sha1").update(endpoint).digest("hex").slice(0, 8)}`;
|
|
15737
15784
|
const rootDir = import_node_path19.default.join(import_node_os8.default.homedir(), ".pmate", "collect", sourceKey);
|
|
15738
15785
|
return { sourceKey, endpoint, rootDir };
|
|
15739
15786
|
}
|
|
15740
15787
|
function toThreadKey(name) {
|
|
15741
15788
|
const normalized = name.trim().toLowerCase().replace(/[^a-z0-9\u4e00-\u9fff]+/g, "-").replace(/^-+|-+$/g, "");
|
|
15742
15789
|
const base = normalized || "thread";
|
|
15743
|
-
const suffix = (0,
|
|
15790
|
+
const suffix = (0, import_node_crypto5.createHash)("sha1").update(name).digest("hex").slice(0, 8);
|
|
15744
15791
|
return `${base}-${suffix}`;
|
|
15745
15792
|
}
|
|
15746
15793
|
async function readStoredThread(rootDir, threadKey) {
|
|
@@ -18519,7 +18566,7 @@ var import_sharp2 = __toESM(require("sharp"));
|
|
|
18519
18566
|
|
|
18520
18567
|
// src/desktopRelease.ts
|
|
18521
18568
|
init_sessionStore();
|
|
18522
|
-
var
|
|
18569
|
+
var import_node_crypto6 = require("crypto");
|
|
18523
18570
|
var import_node_fs21 = require("fs");
|
|
18524
18571
|
var import_node_path26 = __toESM(require("path"));
|
|
18525
18572
|
async function uploadDesktopArtifacts(directory, app, version, platform, arch) {
|
|
@@ -18533,7 +18580,7 @@ async function uploadDesktopArtifacts(directory, app, version, platform, arch) {
|
|
|
18533
18580
|
const artifacts = (0, import_node_fs21.readdirSync)(directory, { withFileTypes: true }).filter((entry) => entry.isFile() && (platform === "mac" ? /(?:\.(dmg|zip|blockmap)$|^latest-mac\.yml$)/i : /(?:\.(exe|zip|blockmap)$|^latest\.yml$)/i).test(entry.name)).sort((a, b) => a.name.localeCompare(b.name)).map((entry) => {
|
|
18534
18581
|
const bytes = (0, import_node_fs21.readFileSync)(import_node_path26.default.join(directory, entry.name));
|
|
18535
18582
|
const objectKey = prefix + entry.name;
|
|
18536
|
-
return { name: entry.name, objectKey, downloadUrl: url(objectKey), sha256: (0,
|
|
18583
|
+
return { name: entry.name, objectKey, downloadUrl: url(objectKey), sha256: (0, import_node_crypto6.createHash)("sha256").update(bytes).digest("hex"), size: bytes.length };
|
|
18537
18584
|
});
|
|
18538
18585
|
if (!artifacts.length) throw new Error("No desktop installers found to publish");
|
|
18539
18586
|
const manifestKey = prefix + "release.json";
|
|
@@ -18737,7 +18784,7 @@ function currentRepositoryRoot(repository, cwd = process.cwd()) {
|
|
|
18737
18784
|
|
|
18738
18785
|
// src/services/AndroidApkReleaseService.ts
|
|
18739
18786
|
var import_node_child_process12 = require("child_process");
|
|
18740
|
-
var
|
|
18787
|
+
var import_node_crypto7 = require("crypto");
|
|
18741
18788
|
var import_node_fs23 = require("fs");
|
|
18742
18789
|
var import_node_os12 = __toESM(require("os"));
|
|
18743
18790
|
var import_node_path28 = __toESM(require("path"));
|
|
@@ -19238,7 +19285,7 @@ function listVersionedToolCandidates(parentDir, relativeToolPath) {
|
|
|
19238
19285
|
}
|
|
19239
19286
|
function sha256File(filePath) {
|
|
19240
19287
|
return new Promise((resolve, reject) => {
|
|
19241
|
-
const hash = (0,
|
|
19288
|
+
const hash = (0, import_node_crypto7.createHash)("sha256");
|
|
19242
19289
|
const stream = (0, import_node_fs23.createReadStream)(filePath);
|
|
19243
19290
|
stream.on("data", (chunk) => hash.update(chunk));
|
|
19244
19291
|
stream.on("error", reject);
|
|
@@ -19257,7 +19304,7 @@ function capitalize(value) {
|
|
|
19257
19304
|
|
|
19258
19305
|
// src/services/HarmonyReleaseService.ts
|
|
19259
19306
|
var import_node_child_process13 = require("child_process");
|
|
19260
|
-
var
|
|
19307
|
+
var import_node_crypto8 = require("crypto");
|
|
19261
19308
|
var import_node_fs24 = require("fs");
|
|
19262
19309
|
var import_node_os13 = __toESM(require("os"));
|
|
19263
19310
|
var import_node_path29 = __toESM(require("path"));
|
|
@@ -19399,7 +19446,7 @@ function signingMaterial(values) {
|
|
|
19399
19446
|
return bytes;
|
|
19400
19447
|
};
|
|
19401
19448
|
const certificate = decode2("HARMONY_CERTIFICATE_BASE64");
|
|
19402
|
-
const fingerprint = new
|
|
19449
|
+
const fingerprint = new import_node_crypto8.X509Certificate(certificate).fingerprint256.replace(/:/g, "");
|
|
19403
19450
|
return { keystore: decode2("HARMONY_KEYSTORE_BASE64"), certificate, profile: decode2("HARMONY_PROFILE_BASE64"), fingerprint };
|
|
19404
19451
|
}
|
|
19405
19452
|
function assertHarmonyMetadata(raw, version) {
|
|
@@ -19409,7 +19456,7 @@ function assertHarmonyMetadata(raw, version) {
|
|
|
19409
19456
|
var withHarmonyPublicationLock = async (bucket2, key, publish) => {
|
|
19410
19457
|
if (!/^harmony\/[\w-]+\/[\w-]+\/\.publish-lock\.json$/.test(key)) throw new Error("Invalid HarmonyOS publication lock key");
|
|
19411
19458
|
await AliyunService.assertUnversionedBucket(bucket2);
|
|
19412
|
-
const owner = (0,
|
|
19459
|
+
const owner = (0, import_node_crypto8.randomUUID)();
|
|
19413
19460
|
try {
|
|
19414
19461
|
await AliyunService.uploadJsonObject(bucket2, key, { owner, createdAt: (/* @__PURE__ */ new Date()).toISOString() }, { "x-oss-forbid-overwrite": "true" });
|
|
19415
19462
|
} catch {
|
|
@@ -19481,9 +19528,9 @@ var HarmonyReleaseService = class {
|
|
|
19481
19528
|
const files = (0, import_node_fs24.readdirSync)(dist, { withFileTypes: true }).filter((e) => e.isFile() && /\.(app|hap)$/.test(e.name)).map((e) => import_node_path29.default.join(dist, e.name));
|
|
19482
19529
|
if (files.length !== 2 || files.filter((f) => f.endsWith(".app")).length !== 1 || files.filter((f) => f.endsWith(".hap")).length !== 1) throw new Error("HarmonyOS build must produce exactly one signed APP and one signed HAP");
|
|
19483
19530
|
const check = async (file, inspectMetadata) => {
|
|
19484
|
-
const id = (0,
|
|
19531
|
+
const id = (0, import_node_crypto8.createHash)("sha256").update(file).digest("hex").slice(0, 16), cert = import_node_path29.default.join(temp, `${id}.cer`);
|
|
19485
19532
|
await run2(tools.java, ["-jar", tools.signer, "verify-app", "-inFile", file, "-outCertChain", cert, "-outProfile", import_node_path29.default.join(temp, `${id}.p7b`)], opts);
|
|
19486
|
-
if (new
|
|
19533
|
+
if (new import_node_crypto8.X509Certificate((0, import_node_fs24.readFileSync)(cert)).fingerprint256.replace(/:/g, "") !== material.fingerprint) throw new Error("HarmonyOS signer certificate does not match service certificate");
|
|
19487
19534
|
if (inspectMetadata) assertHarmonyMetadata(JSON.parse(await run2("unzip", ["-p", file, "module.json"], { ...opts, capture: true })), version);
|
|
19488
19535
|
};
|
|
19489
19536
|
for (const file of files) {
|
|
@@ -19507,7 +19554,7 @@ var HarmonyReleaseService = class {
|
|
|
19507
19554
|
if (!size) throw new Error("Empty HarmonyOS artifact");
|
|
19508
19555
|
const target = import_node_path29.default.join(output, name);
|
|
19509
19556
|
(0, import_node_fs24.cpSync)(file, target);
|
|
19510
|
-
const hash = (0,
|
|
19557
|
+
const hash = (0, import_node_crypto8.createHash)("sha256");
|
|
19511
19558
|
for await (const chunk of (0, import_node_fs24.createReadStream)(target)) hash.update(chunk);
|
|
19512
19559
|
artifacts.push({ name, type: import_node_path29.default.extname(name).slice(1), objectKey: releasePrefix + name, downloadUrl: `${baseUrl}/${releasePrefix}${name}`, sha256: hash.digest("hex"), size });
|
|
19513
19560
|
}
|
|
@@ -19538,7 +19585,7 @@ var HarmonyReleaseService = class {
|
|
|
19538
19585
|
|
|
19539
19586
|
// src/services/IosBuildService.ts
|
|
19540
19587
|
var import_node_child_process14 = require("child_process");
|
|
19541
|
-
var
|
|
19588
|
+
var import_node_crypto9 = require("crypto");
|
|
19542
19589
|
var import_node_fs25 = require("fs");
|
|
19543
19590
|
var import_node_os14 = __toESM(require("os"));
|
|
19544
19591
|
var import_node_path30 = __toESM(require("path"));
|
|
@@ -19601,7 +19648,7 @@ var IosBuildService = class {
|
|
|
19601
19648
|
if (!bundleId || !/^\d+\.\d+(?:\.\d+)?$/.test(version ?? "") || !/^[A-Z0-9]{10}$/.test(team ?? "")) throw new Error("Missing or invalid bundle ID, MARKETING_VERSION or signing team; use --team if needed");
|
|
19602
19649
|
if (service.mobile && "bundleId" in service.mobile && service.mobile.bundleId !== bundleId) throw new Error("Service bundle ID does not match application target");
|
|
19603
19650
|
const currentBuild = iosBuildInteger(cfg.CURRENT_PROJECT_VERSION);
|
|
19604
|
-
const key = (0,
|
|
19651
|
+
const key = (0, import_node_crypto9.createHash)("sha256").update(bundleId).digest("hex");
|
|
19605
19652
|
const statePath = import_node_path30.default.join(root, `${key}.json`);
|
|
19606
19653
|
const lockPath = import_node_path30.default.join(root, `${key}.lock`);
|
|
19607
19654
|
let lock;
|
|
@@ -22980,7 +23027,7 @@ var RoleCommandHandler = class {
|
|
|
22980
23027
|
|
|
22981
23028
|
// src/commands/AccountCommandHandler.ts
|
|
22982
23029
|
var import_node_fs29 = require("fs");
|
|
22983
|
-
var
|
|
23030
|
+
var import_node_crypto10 = require("crypto");
|
|
22984
23031
|
var import_node_path34 = __toESM(require("path"));
|
|
22985
23032
|
init_sessionStore();
|
|
22986
23033
|
var AccountCommandHandler = class {
|
|
@@ -23625,7 +23672,7 @@ var AccountCommandHandler = class {
|
|
|
23625
23672
|
return process.env.HOME || process.env.USERPROFILE || process.cwd();
|
|
23626
23673
|
}
|
|
23627
23674
|
generateBotKeyFile(app, name) {
|
|
23628
|
-
const { publicKey, privateKey } = (0,
|
|
23675
|
+
const { publicKey, privateKey } = (0, import_node_crypto10.generateKeyPairSync)("ed25519");
|
|
23629
23676
|
return {
|
|
23630
23677
|
type: "pmate-bot-key",
|
|
23631
23678
|
version: 1,
|
|
@@ -23747,12 +23794,12 @@ var AccountCommandHandler = class {
|
|
|
23747
23794
|
});
|
|
23748
23795
|
}
|
|
23749
23796
|
signBotChallenge(challenge, privateKey) {
|
|
23750
|
-
const key = (0,
|
|
23797
|
+
const key = (0, import_node_crypto10.createPrivateKey)({
|
|
23751
23798
|
key: Buffer.from(privateKey, "base64url"),
|
|
23752
23799
|
format: "der",
|
|
23753
23800
|
type: "pkcs8"
|
|
23754
23801
|
});
|
|
23755
|
-
return (0,
|
|
23802
|
+
return (0, import_node_crypto10.sign)(
|
|
23756
23803
|
null,
|
|
23757
23804
|
Buffer.from(JSON.stringify({
|
|
23758
23805
|
id: challenge.id,
|
|
@@ -27273,7 +27320,7 @@ var HELP_TEXT = [
|
|
|
27273
27320
|
import_chalk4.default.bold("Commands:"),
|
|
27274
27321
|
` ${import_chalk4.default.cyan("list [path]")} List apps from .pmate.yaml in the target folder`,
|
|
27275
27322
|
` ${import_chalk4.default.cyan("login")} Log in and store a session in ~/.pmate/session.json`,
|
|
27276
|
-
` ${import_chalk4.default.gray(" [--app <app-id>] [--profile-id <id>] [--select-profile]")}`,
|
|
27323
|
+
` ${import_chalk4.default.gray(" [--app <app-id>] [--profile-id <id>] [--select-profile] [--token-stdin]")}`,
|
|
27277
27324
|
` ${import_chalk4.default.gray(" [--access-key [secret] | --access-key-file <path>]")}`,
|
|
27278
27325
|
` ${import_chalk4.default.cyan("add-dns")} Add a DNS record via Aliyun DNS`,
|
|
27279
27326
|
` ${import_chalk4.default.gray(" --type <t> --value <v> --rr <rr> [--ttl <n>] [--domain <name>]")}`,
|
|
@@ -27512,6 +27559,8 @@ function parseCommandArgs(args) {
|
|
|
27512
27559
|
let accessKeyFile;
|
|
27513
27560
|
let accessKeyScan = false;
|
|
27514
27561
|
let selectProfile = false;
|
|
27562
|
+
let tokenStdin = false;
|
|
27563
|
+
let expectedAccount;
|
|
27515
27564
|
while (rest.length > 0) {
|
|
27516
27565
|
const token = rest.shift();
|
|
27517
27566
|
switch (token) {
|
|
@@ -27531,6 +27580,12 @@ function parseCommandArgs(args) {
|
|
|
27531
27580
|
case "--access-key-file":
|
|
27532
27581
|
accessKeyFile = requireValue11(rest, token);
|
|
27533
27582
|
break;
|
|
27583
|
+
case "--expected-account":
|
|
27584
|
+
expectedAccount = requireValue11(rest, token);
|
|
27585
|
+
break;
|
|
27586
|
+
case "--token-stdin":
|
|
27587
|
+
tokenStdin = true;
|
|
27588
|
+
break;
|
|
27534
27589
|
case "--select-profile":
|
|
27535
27590
|
selectProfile = true;
|
|
27536
27591
|
break;
|
|
@@ -27544,7 +27599,9 @@ function parseCommandArgs(args) {
|
|
|
27544
27599
|
if (accessKeyScan && accessKeyFile) {
|
|
27545
27600
|
throw new Error("--access-key and --access-key-file are mutually exclusive");
|
|
27546
27601
|
}
|
|
27547
|
-
|
|
27602
|
+
if (tokenStdin && !app?.trim()) throw new Error("--token-stdin requires --app");
|
|
27603
|
+
if (tokenStdin && (accessKey || accessKeyFile || accessKeyScan)) throw new Error("--token-stdin cannot be combined with access-key login");
|
|
27604
|
+
return { type: "login" /* Login */, app, profileId, accessKey, accessKeyFile, accessKeyScan, selectProfile, ...tokenStdin ? { tokenStdin: true } : {}, ...expectedAccount ? { expectedAccount } : {} };
|
|
27548
27605
|
}
|
|
27549
27606
|
if (args.rest[0] === "add-dns") {
|
|
27550
27607
|
return parseAddDnsArgs(args.rest.slice(1));
|
|
@@ -10,20 +10,20 @@ function createAgentRuntime({ platform = process.platform, home = homedir(), exe
|
|
|
10
10
|
let identityEpoch=0
|
|
11
11
|
let identity
|
|
12
12
|
const run = execute || (async(file, args, cwd, timeout = 600000, credentials = {}) => {const resolved=await resolvePath();return new Promise((resolve, reject) => {
|
|
13
|
-
execFile(file, args, { cwd, timeout, maxBuffer: 4 * 1024 * 1024, env: { ...environment, ...credentials, PATH: resolved.path, GIT_TERMINAL_PROMPT: '0' } }, (error, stdout) => error ? reject(new Error(`${path.basename(file)}
|
|
13
|
+
execFile(file, args, { cwd, timeout, maxBuffer: 4 * 1024 * 1024, env: { ...environment, ...credentials, PATH: resolved.path, GIT_TERMINAL_PROMPT: '0' } }, (error, stdout, stderr) => error ? reject(new Error(`${path.basename(file)} 执行失败:${String(stderr||'').trim().slice(0,2000)||error.code||'未知错误'}`)) : resolve(stdout.trim()))
|
|
14
14
|
})})
|
|
15
15
|
const localExec=createLocalExecutor({home,environment,resolvePath})
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
if(
|
|
21
|
-
return
|
|
16
|
+
const ownerEnvironment=()=>({MERRY_RUNTIME_EXPECTED_USER:identity.accountId,PCS_AGENT_API_TOKEN:undefined,HEBO_MEMORY_TOKEN:undefined,PCS_AGENT_SESSION_SOURCE_FILE:undefined,PCS_AGENT_SESSION_MANAGED:'0',PCS_ISSUES_API_URL:'https://issue-api.pmate.chat',PCS_AGENT_ID:undefined,PCS_AGENT_RUN_ID:undefined,VEGA_RUN_TOKEN:undefined,VEGA_INPUT_ID:undefined})
|
|
17
|
+
const runtimeApi=async(method,input)=>{
|
|
18
|
+
if(!identity?.accountId)throw Error('请重新登录梅丽号以确认 Runtime Owner')
|
|
19
|
+
const epoch=identityEpoch,output=await run('merry-runtime',['api',method,'--request',JSON.stringify(input??{})],undefined,600000,ownerEnvironment())
|
|
20
|
+
if(epoch!==identityEpoch||!identity)throw Error('登录身份已改变,请重新打开页面')
|
|
21
|
+
return JSON.parse(output)
|
|
22
22
|
}
|
|
23
23
|
const invoke = async (method,input) => {
|
|
24
24
|
if(!methods.includes(method))throw new Error('ELECTRON_METHOD_UNAVAILABLE')
|
|
25
25
|
if(method==='capabilities')return methods
|
|
26
|
-
if(method==='local.info')return {platform,arch:process.arch,home}
|
|
26
|
+
if(method==='local.info')return {platform,arch:process.arch,home,stdin:true}
|
|
27
27
|
if(method==='local.exec'){
|
|
28
28
|
if(!identity)throw new Error('请先登录梅丽号')
|
|
29
29
|
const epoch=identityEpoch,result=await localExec(input)
|
|
@@ -32,34 +32,34 @@ function createAgentRuntime({ platform = process.platform, home = homedir(), exe
|
|
|
32
32
|
}
|
|
33
33
|
if(method==='scripts.run'&&input?.id==='runtime.models'&&input.args&&Object.keys(input.args).length===0)return modelCatalog({environment:{...environment,PATH:(await resolvePath()).path}})
|
|
34
34
|
if(method==='scripts.run')throw new Error('未知脚本操作')
|
|
35
|
-
if(method==='workspaces.list')return
|
|
35
|
+
if(method==='workspaces.list')return runtimeApi(method,input)
|
|
36
36
|
const {scope,id,config,expectedRevision}=input||{}
|
|
37
37
|
if(!scope||!['namespace','topic'].every(k=>typeof scope[k]==='string'&&/^[a-z0-9][a-z0-9_-]{0,127}$/.test(scope[k])))throw new Error('无效工作区')
|
|
38
38
|
const base=`/v2/topics/${encodeURIComponent(scope.namespace)}/${encodeURIComponent(scope.topic)}`
|
|
39
39
|
if(method==='runtime.inspect'){
|
|
40
|
-
if(!identity)throw new Error('
|
|
40
|
+
if(!identity?.accountId)throw new Error('请重新登录梅丽号以确认 Runtime Owner')
|
|
41
41
|
if(!['runs','run','run-logs'].includes(input.kind)||Object.keys(input).some(k=>!['scope','kind','agentId','runId','status'].includes(k)))throw new Error('无效的 Run 查询')
|
|
42
42
|
const epoch=identityEpoch
|
|
43
|
-
const output=await run('merry-runtime',['inspect','--request',JSON.stringify(input)],undefined,600000,
|
|
43
|
+
const output=await run('merry-runtime',['inspect','--request',JSON.stringify(input)],undefined,600000,ownerEnvironment())
|
|
44
44
|
if(epoch!==identityEpoch||!identity)throw new Error('登录身份已改变,请重新打开页面')
|
|
45
45
|
return JSON.parse(output)
|
|
46
46
|
}
|
|
47
|
-
if(method==='agents.list')return
|
|
48
|
-
if(method==='plugins.list')return
|
|
47
|
+
if(method==='agents.list')return runtimeApi(method,input)
|
|
48
|
+
if(method==='plugins.list')return runtimeApi(method,input)
|
|
49
49
|
if(typeof id!=='string'||!(method==='plugins.configure'?/^(?:[a-z][a-z0-9-]*:)?[a-z][a-z0-9-]*$/:/^0x[a-f0-9]{64}$/).test(id)||!config||typeof config!=='object'||Array.isArray(config))throw new Error('无效配置')
|
|
50
50
|
if(Object.hasOwn(config,'expectedRevision'))throw new Error('revision 必须单独指定')
|
|
51
51
|
if(method!=='agents.create'&&(!Number.isSafeInteger(expectedRevision)||expectedRevision<1))throw new Error('更新需要 revision')
|
|
52
52
|
if(method==='agents.create'&&expectedRevision!==undefined)throw new Error('创建不能指定 revision')
|
|
53
|
-
return
|
|
53
|
+
return runtimeApi(method,input)
|
|
54
54
|
}
|
|
55
55
|
return { invoke,
|
|
56
56
|
async configureIdentity(value, configure) {
|
|
57
57
|
const epoch=++identityEpoch;identity=undefined
|
|
58
58
|
const result=await configure(value)
|
|
59
|
-
if(epoch===identityEpoch)identity={appId:value.appId,
|
|
59
|
+
if(epoch===identityEpoch)identity={appId:value.appId,accountId:value.accountId}
|
|
60
60
|
return result
|
|
61
61
|
},
|
|
62
|
-
setIdentity(value) { identityEpoch++;identity=value ? {appId:value.appId,
|
|
62
|
+
setIdentity(value) { identityEpoch++;identity=value ? {appId:value.appId,accountId:value.accountId} : undefined }
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
function installAgentRuntime({ ipcMain, trusted, runtime }) {
|
|
@@ -8,9 +8,10 @@ function createLocalExecutor({home,environment,execute=execFile,resolvePath=crea
|
|
|
8
8
|
if(!input||typeof input.command!=='string'||!input.command||input.command.includes('\0')||!Array.isArray(input.args)||input.args.some(v=>typeof v!=='string'||v.includes('\0'))||input.args.length>256||input.args.some(v=>v.length>131072))throw Error('Invalid local command')
|
|
9
9
|
if(input.cwd!==undefined&&(typeof input.cwd!=='string'||!path.isAbsolute(input.cwd)||input.cwd.includes('\0')))throw Error('Invalid working directory')
|
|
10
10
|
if(input.env!==undefined&&(!input.env||typeof input.env!=='object'||Array.isArray(input.env)||Object.entries(input.env).some(([k,v])=>!k||k.includes('=')||k.includes('\0')||typeof v!=='string'||v.includes('\0'))))throw Error('Invalid process environment')
|
|
11
|
+
if(input.stdin!==undefined&&(typeof input.stdin!=='string'||Buffer.byteLength(input.stdin)>16384))throw Error('Invalid standard input')
|
|
11
12
|
const timeout=input.timeoutMs??10000
|
|
12
|
-
if(!Number.isSafeInteger(timeout)||timeout<100||timeout>
|
|
13
|
-
return resolvePath().then(({path:resolvedPath,warning})=>new Promise(resolve=>execute(input.command,input.args,{cwd:input.cwd,env:{...environment,PATH:resolvedPath,...input.env},shell:false,timeout,maxBuffer:1024*1024,windowsHide:true},(error,stdout,stderr)=>resolve({stdout:String(stdout??''),stderr:(error&&warning?warning+'\n':'')+String(stderr??''),exitCode:error?(typeof error.code==='number'?error.code:null):0,error:error?(error.code==='ENOENT'?'NOT_FOUND':error.code==='ERR_CHILD_PROCESS_STDIO_MAXBUFFER'?'OUTPUT_LIMIT':error.killed?'TIMEOUT':'PROCESS_FAILED'):undefined}))))
|
|
13
|
+
if(!Number.isSafeInteger(timeout)||timeout<100||timeout>360000)throw Error('Invalid command timeout')
|
|
14
|
+
return resolvePath().then(({path:resolvedPath,warning})=>new Promise(resolve=>{const child=execute(input.command,input.args,{cwd:input.cwd,env:{...environment,PATH:resolvedPath,...input.env},shell:false,timeout,maxBuffer:1024*1024,windowsHide:true},(error,stdout,stderr)=>resolve({stdout:String(stdout??''),stderr:(error&&warning?warning+'\n':'')+String(stderr??''),exitCode:error?(typeof error.code==='number'?error.code:null):0,error:error?(error.code==='ENOENT'?'NOT_FOUND':error.code==='ERR_CHILD_PROCESS_STDIO_MAXBUFFER'?'OUTPUT_LIMIT':error.killed?'TIMEOUT':'PROCESS_FAILED'):undefined}));if(input.stdin!==undefined){child.stdin?.on('error',()=>{});child.stdin?.end(input.stdin)}else child.stdin?.end()}))
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
module.exports={createLocalExecutor}
|