@pmate/cli 0.49.6 → 0.49.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/dist/index.d.ts +11 -2
- package/dist/index.js +36 -19
- package/dist/templates/electron/agent-runtime.cjs +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -343,7 +343,7 @@ type RoleCommandArgs = {
|
|
|
343
343
|
riskModel?: boolean;
|
|
344
344
|
type: Command.Role;
|
|
345
345
|
resource: "definition" | "permission" | "grant" | "binding" | "migration" | "check";
|
|
346
|
-
action: "list" | "create" | "update" | "add" | "remove" | "preview" | "apply" | "check";
|
|
346
|
+
action: "list" | "create" | "update" | "delete" | "add" | "remove" | "preview" | "apply" | "check";
|
|
347
347
|
role?: string;
|
|
348
348
|
permission?: string;
|
|
349
349
|
account?: string;
|
|
@@ -490,13 +490,22 @@ type AccountCommandArgs = {
|
|
|
490
490
|
} | {
|
|
491
491
|
type: Command.Account;
|
|
492
492
|
action: "access-key-create";
|
|
493
|
-
|
|
493
|
+
configFile?: string;
|
|
494
|
+
app?: string;
|
|
494
495
|
name: string;
|
|
495
496
|
namespace?: string;
|
|
496
497
|
expiresAt?: string;
|
|
497
498
|
out?: string;
|
|
498
499
|
baseUrl?: string;
|
|
499
500
|
json: boolean;
|
|
501
|
+
} | {
|
|
502
|
+
type: Command.Account;
|
|
503
|
+
action: "access-key-config";
|
|
504
|
+
id: string;
|
|
505
|
+
configFile: string;
|
|
506
|
+
expectedVersion: number;
|
|
507
|
+
baseUrl?: string;
|
|
508
|
+
json: boolean;
|
|
500
509
|
} | {
|
|
501
510
|
type: Command.Account;
|
|
502
511
|
action: "access-key-list";
|
package/dist/index.js
CHANGED
|
@@ -9724,7 +9724,7 @@ function readAccessKeyFile(filePath, options = {}) {
|
|
|
9724
9724
|
if (!isAccessKeyFile(parsed)) {
|
|
9725
9725
|
throw new Error(`Invalid PMate access key file: ${absolutePath}`);
|
|
9726
9726
|
}
|
|
9727
|
-
if (options.expectedApp && parsed.app
|
|
9727
|
+
if (options.expectedApp && !(parsed.config ? parsed.config.apps === "*" || parsed.config.apps.includes(options.expectedApp) : parsed.app === options.expectedApp)) {
|
|
9728
9728
|
throw new Error(
|
|
9729
9729
|
`Access key app mismatch. expected=${options.expectedApp}, received=${parsed.app}`
|
|
9730
9730
|
);
|
|
@@ -9732,11 +9732,7 @@ function readAccessKeyFile(filePath, options = {}) {
|
|
|
9732
9732
|
return parsed;
|
|
9733
9733
|
}
|
|
9734
9734
|
function scanAccessKeyFiles(app) {
|
|
9735
|
-
|
|
9736
|
-
if (!(0, import_node_fs5.existsSync)(dir)) {
|
|
9737
|
-
return [];
|
|
9738
|
-
}
|
|
9739
|
-
return (0, import_node_fs5.readdirSync)(dir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".access-key.json")).map((entry) => import_node_path6.default.join(dir, entry.name)).flatMap((filePath) => {
|
|
9735
|
+
return [resolveAccessKeyDir(app), resolveAccessKeyDir("__shared__")].filter(import_node_fs5.existsSync).flatMap((dir) => (0, import_node_fs5.readdirSync)(dir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".access-key.json")).map((entry) => import_node_path6.default.join(dir, entry.name))).flatMap((filePath) => {
|
|
9740
9736
|
try {
|
|
9741
9737
|
return [{ filePath, key: readAccessKeyFile(filePath, { expectedApp: app }) }];
|
|
9742
9738
|
} catch {
|
|
@@ -23340,6 +23336,7 @@ var RoleCommandHandler = class {
|
|
|
23340
23336
|
const scope = args.scope === "platform" ? { type: "platform" } : { type: "namespace", namespace: args.namespace };
|
|
23341
23337
|
let result;
|
|
23342
23338
|
if (args.resource === "migration") result = await request2("POST", args.riskModel ? "/authorization/migrate-risk" : "/authorization/migrate", { dryRun: args.action !== "apply" });
|
|
23339
|
+
else if (args.resource === "definition" && args.action === "delete") result = await request2("DELETE", "/authorization/roles", { roleId: args.role });
|
|
23343
23340
|
else if (args.resource === "check") result = await request2("POST", "/authz/permission", { permission: args.permission, scope, ...args.account ? { account: args.account } : {} });
|
|
23344
23341
|
else if (args.action === "list") {
|
|
23345
23342
|
const data = await request2("GET", "/authorization");
|
|
@@ -23730,9 +23727,8 @@ var AccountCommandHandler = class {
|
|
|
23730
23727
|
"POST",
|
|
23731
23728
|
"/access-keys",
|
|
23732
23729
|
{
|
|
23733
|
-
|
|
23730
|
+
config: args.configFile ? JSON.parse((0, import_node_fs30.readFileSync)(args.configFile, "utf8")) : { version: 1, apps: [args.app], roles: "*", ...args.namespace ? { namespace: args.namespace } : {} },
|
|
23734
23731
|
name: args.name,
|
|
23735
|
-
namespace: args.namespace,
|
|
23736
23732
|
expiresAt: args.expiresAt
|
|
23737
23733
|
}
|
|
23738
23734
|
);
|
|
@@ -23740,6 +23736,11 @@ var AccountCommandHandler = class {
|
|
|
23740
23736
|
this.renderAccessKeyCreateResult(result, args.json, args.out);
|
|
23741
23737
|
return;
|
|
23742
23738
|
}
|
|
23739
|
+
case "access-key-config": {
|
|
23740
|
+
const result = await this.request(this.resolveAuthBaseUrl(args.baseUrl), this.readToken(), "PUT", `/access-keys/${encodeURIComponent(args.id)}/config`, { config: JSON.parse((0, import_node_fs30.readFileSync)(args.configFile, "utf8")), expectedVersion: args.expectedVersion });
|
|
23741
|
+
this.renderJson(result, args.json);
|
|
23742
|
+
return;
|
|
23743
|
+
}
|
|
23743
23744
|
case "access-key-list": {
|
|
23744
23745
|
const token = this.readToken();
|
|
23745
23746
|
const baseUrl2 = this.resolveAuthBaseUrl(args.baseUrl);
|
|
@@ -24068,7 +24069,7 @@ var AccountCommandHandler = class {
|
|
|
24068
24069
|
if (parsed.type !== "pmate-access-key" || parsed.version !== 1 || !parsed.id || !parsed.app || !parsed.secret || !parsed.expiresAt) {
|
|
24069
24070
|
throw new Error(`Invalid PMate access key file: ${absolutePath}`);
|
|
24070
24071
|
}
|
|
24071
|
-
if (expectedApp && parsed.app
|
|
24072
|
+
if (expectedApp && !(parsed.config ? parsed.config.apps === "*" || parsed.config.apps.includes(expectedApp) : parsed.app === expectedApp)) {
|
|
24072
24073
|
throw new Error(`Access key app mismatch. expected=${expectedApp}, received=${parsed.app}`);
|
|
24073
24074
|
}
|
|
24074
24075
|
return parsed;
|
|
@@ -24078,14 +24079,15 @@ var AccountCommandHandler = class {
|
|
|
24078
24079
|
type: "pmate-access-key",
|
|
24079
24080
|
version: 1,
|
|
24080
24081
|
id: result.key.id,
|
|
24081
|
-
app: result.key.app,
|
|
24082
|
+
app: result.key.config ? result.key.config.apps === "*" || result.key.config.apps.length !== 1 ? "*" : result.key.config.apps[0] : result.key.app,
|
|
24083
|
+
...result.key.config ? { config: result.key.config } : {},
|
|
24082
24084
|
name: result.key.name,
|
|
24083
24085
|
namespace: result.key.namespace,
|
|
24084
24086
|
secret: result.secret,
|
|
24085
24087
|
expiresAt: result.key.expiresAt,
|
|
24086
24088
|
createdAt: result.key.createdAt
|
|
24087
24089
|
};
|
|
24088
|
-
const outPath = out ? this.resolveFilePath(out) : this.resolveDefaultAccessKeyPath(result.key.app, result.key.name);
|
|
24090
|
+
const outPath = out ? this.resolveFilePath(out) : this.resolveDefaultAccessKeyPath(result.key.config ? result.key.config.apps === "*" || result.key.config.apps.length !== 1 ? "__shared__" : result.key.config.apps[0] : result.key.app, result.key.name);
|
|
24089
24091
|
(0, import_node_fs30.mkdirSync)(import_node_path35.default.dirname(outPath), { recursive: true });
|
|
24090
24092
|
(0, import_node_fs30.writeFileSync)(outPath, JSON.stringify(keyFile, null, 2), { mode: 384 });
|
|
24091
24093
|
(0, import_node_fs30.chmodSync)(outPath, 384);
|
|
@@ -24095,10 +24097,11 @@ var AccountCommandHandler = class {
|
|
|
24095
24097
|
this.renderJson(result, true);
|
|
24096
24098
|
return;
|
|
24097
24099
|
}
|
|
24098
|
-
const outPath = out ? this.resolveFilePath(out) : this.resolveDefaultAccessKeyPath(result.key.app, result.key.name);
|
|
24100
|
+
const outPath = out ? this.resolveFilePath(out) : this.resolveDefaultAccessKeyPath(result.key.config ? result.key.config.apps === "*" || result.key.config.apps.length !== 1 ? "__shared__" : result.key.config.apps[0] : result.key.app, result.key.name);
|
|
24099
24101
|
ui.success(`Access key saved to ${outPath}`);
|
|
24100
24102
|
ui.info(result.key.id, {
|
|
24101
|
-
app: result.key.app,
|
|
24103
|
+
app: result.key.config ? result.key.config.apps === "*" || result.key.config.apps.length !== 1 ? "*" : result.key.config.apps[0] : result.key.app,
|
|
24104
|
+
...result.key.config ? { config: result.key.config } : {},
|
|
24102
24105
|
name: result.key.name,
|
|
24103
24106
|
namespace: result.key.namespace,
|
|
24104
24107
|
expiresAt: result.key.expiresAt
|
|
@@ -24115,7 +24118,8 @@ var AccountCommandHandler = class {
|
|
|
24115
24118
|
}
|
|
24116
24119
|
for (const item of items) {
|
|
24117
24120
|
ui.info(item.id, {
|
|
24118
|
-
|
|
24121
|
+
apps: item.config?.apps ?? item.app,
|
|
24122
|
+
roles: item.config?.roles,
|
|
24119
24123
|
name: item.name,
|
|
24120
24124
|
namespace: item.namespace,
|
|
24121
24125
|
status: item.status,
|
|
@@ -26274,7 +26278,7 @@ var rolePattern = /^[a-z0-9][a-z0-9_-]{0,62}(\/[a-z0-9][a-z0-9_-]{0,62})?$/;
|
|
|
26274
26278
|
var permissionPattern = /^[a-z][a-z0-9-]*:[a-z][a-z0-9-]*$/;
|
|
26275
26279
|
function parseRoleArgs(tokens) {
|
|
26276
26280
|
const rest = [...tokens], resource = rest.shift();
|
|
26277
|
-
const actions = { definition: ["list", "create", "update"], permission: ["list", "create", "update"], grant: ["list", "add", "remove"], binding: ["list", "add", "remove"], migration: ["preview", "apply"], check: ["check"] };
|
|
26281
|
+
const actions = { definition: ["list", "create", "update", "delete"], permission: ["list", "create", "update"], grant: ["list", "add", "remove"], binding: ["list", "add", "remove"], migration: ["preview", "apply"], check: ["check"] };
|
|
26278
26282
|
if (!actions[resource]) throw new Error("Missing role resource. Use: role definition|permission|grant|binding|migration|check");
|
|
26279
26283
|
const action = resource === "check" ? "check" : rest.shift();
|
|
26280
26284
|
if (!action) throw new Error("Missing role action");
|
|
@@ -26317,6 +26321,7 @@ function parseRoleArgs(tokens) {
|
|
|
26317
26321
|
if (args.namespace && !/^(\*|[a-z0-9][a-z0-9_-]{0,62})$/.test(args.namespace)) throw new Error("Invalid namespace");
|
|
26318
26322
|
if (args.scope && args.namespace) throw new Error("Choose --scope platform or --namespace, not both");
|
|
26319
26323
|
if (resource === "permission" && action === "create" && !args.scopeType) throw new Error("Permission creation requires --scope-type platform|namespace");
|
|
26324
|
+
if (action === "delete" && !args.role) throw new Error("Missing --role");
|
|
26320
26325
|
if (["add", "remove"].includes(action) && !args.role) throw new Error("Missing --role");
|
|
26321
26326
|
if (resource === "binding" && ["add", "remove"].includes(action) && !args.account) throw new Error("Missing --account");
|
|
26322
26327
|
if (resource === "grant" && action !== "list" || resource === "check") {
|
|
@@ -26710,6 +26715,8 @@ function parseAccountArgs(tokens) {
|
|
|
26710
26715
|
let out;
|
|
26711
26716
|
let key;
|
|
26712
26717
|
let keyFile;
|
|
26718
|
+
let configFile;
|
|
26719
|
+
let expectedVersion;
|
|
26713
26720
|
let gracePeriodSeconds;
|
|
26714
26721
|
let baseUrl3;
|
|
26715
26722
|
let json2 = false;
|
|
@@ -26721,6 +26728,12 @@ function parseAccountArgs(tokens) {
|
|
|
26721
26728
|
entityLabel: "app ref"
|
|
26722
26729
|
}).fullId;
|
|
26723
26730
|
break;
|
|
26731
|
+
case "--config-file":
|
|
26732
|
+
configFile = requireValue5(rest, token);
|
|
26733
|
+
break;
|
|
26734
|
+
case "--expected-version":
|
|
26735
|
+
expectedVersion = Number(requireValue5(rest, token));
|
|
26736
|
+
break;
|
|
26724
26737
|
case "--name":
|
|
26725
26738
|
name = requireValue5(rest, token);
|
|
26726
26739
|
break;
|
|
@@ -26752,7 +26765,7 @@ function parseAccountArgs(tokens) {
|
|
|
26752
26765
|
json2 = true;
|
|
26753
26766
|
break;
|
|
26754
26767
|
default:
|
|
26755
|
-
if ((keyAction === "rotate" || keyAction === "disable") && !token.startsWith("-")) {
|
|
26768
|
+
if ((keyAction === "rotate" || keyAction === "disable" || keyAction === "config") && !token.startsWith("-")) {
|
|
26756
26769
|
if (id) {
|
|
26757
26770
|
throw new Error(`Unexpected account access-key id: ${token}`);
|
|
26758
26771
|
}
|
|
@@ -26763,10 +26776,14 @@ function parseAccountArgs(tokens) {
|
|
|
26763
26776
|
}
|
|
26764
26777
|
}
|
|
26765
26778
|
if (keyAction === "create") {
|
|
26766
|
-
if (!app || !name) {
|
|
26779
|
+
if (!app && !configFile || !name) {
|
|
26767
26780
|
throw new Error("Usage: account access-key create --app <ns:app> --name <name> [--expires-at <iso> | --expires-in <duration>] [--namespace <ns>] [--out <path>] [--base-url <url>] [--json]");
|
|
26768
26781
|
}
|
|
26769
|
-
return { type: "account" /* Account */, action: "access-key-create", app, name, namespace: namespace2, expiresAt, out, baseUrl: baseUrl3, json: json2 };
|
|
26782
|
+
return { type: "account" /* Account */, action: "access-key-create", ...configFile ? { configFile } : {}, app, name, namespace: namespace2, expiresAt, out, baseUrl: baseUrl3, json: json2 };
|
|
26783
|
+
}
|
|
26784
|
+
if (keyAction === "config") {
|
|
26785
|
+
if (!id || !configFile || !Number.isSafeInteger(expectedVersion) || expectedVersion < 1) throw new Error("Usage: account access-key config <id> --config-file <json> --expected-version <version>");
|
|
26786
|
+
return { type: "account" /* Account */, action: "access-key-config", id, configFile, expectedVersion, baseUrl: baseUrl3, json: json2 };
|
|
26770
26787
|
}
|
|
26771
26788
|
if (keyAction === "list") {
|
|
26772
26789
|
return { type: "account" /* Account */, action: "access-key-list", app, namespace: namespace2, baseUrl: baseUrl3, json: json2 };
|
|
@@ -27724,7 +27741,7 @@ var HELP_TEXT = [
|
|
|
27724
27741
|
` ${import_chalk4.default.gray(" bot profile create --app <ns:app> --name <name> --nickname <nickname> [--role <role>] [--base-url <url>] [--json]")}`,
|
|
27725
27742
|
` ${import_chalk4.default.gray(" bot profile update --app <ns:app> --name <name> --nickname <nickname> [--profile-id <id>] [--base-url <url>] [--json]")}`,
|
|
27726
27743
|
` ${import_chalk4.default.gray(" bot nickname --app <ns:app> --name <name> --nickname <nickname> [--base-url <url>] [--json] (alias for profile update)")}`,
|
|
27727
|
-
` ${import_chalk4.default.gray(" access-key create --app <ns:app> --name <name> [--expires-at <iso> | --expires-in <duration>] [--namespace <ns>] [--out <path>] [--base-url <url>] [--json]")}`,
|
|
27744
|
+
` ${import_chalk4.default.gray(" access-key create --config-file <json> | --app <ns:app> --name <name> [--expires-at <iso> | --expires-in <duration>] [--namespace <ns>] [--out <path>] [--base-url <url>] [--json]")}`,
|
|
27728
27745
|
` ${import_chalk4.default.gray(" access-key list [--app <ns:app>] [--namespace <ns>] [--base-url <url>] [--json]")}`,
|
|
27729
27746
|
` ${import_chalk4.default.gray(" access-key rotate <id> [--expires-at <iso> | --expires-in <duration>] [--grace-period <duration>] [--out <path>] [--base-url <url>] [--json]")}`,
|
|
27730
27747
|
` ${import_chalk4.default.gray(" access-key disable <id> [--base-url <url>] [--json]")}`,
|
|
@@ -11,7 +11,7 @@ function createAgentRuntime({ platform = process.platform, home = homedir(), exe
|
|
|
11
11
|
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()))
|
|
12
12
|
})})
|
|
13
13
|
const localExec=createLocalExecutor({home,environment,resolvePath})
|
|
14
|
-
const ownerEnvironment=()=>({MERRY_RUNTIME_EXPECTED_USER:undefined,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})
|
|
14
|
+
const ownerEnvironment=()=>({MERRY_RUNTIME_EXPECTED_USER:undefined,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',PMATE_AGENT_API_URL:'https://agent-api.pmate.chat',PCS_AGENT_ID:undefined,PCS_AGENT_RUN_ID:undefined,VEGA_RUN_TOKEN:undefined,VEGA_INPUT_ID:undefined})
|
|
15
15
|
const runtimeApi=async(method,input)=>{
|
|
16
16
|
const output=await run('merry-runtime',['api',method,'--request',JSON.stringify(input??{})],undefined,600000,ownerEnvironment())
|
|
17
17
|
return JSON.parse(output)
|