@pmate/cli 0.49.5 → 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 +39 -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 {
|
|
@@ -22035,6 +22031,9 @@ function deploySshIdentityArgs(env = process.env) {
|
|
|
22035
22031
|
init_namespacedRef();
|
|
22036
22032
|
var ServiceCommandHandler = class {
|
|
22037
22033
|
async handle(args) {
|
|
22034
|
+
if (args.action === "deploy" && args.namespace === "pmate" && args.name === "merry-agents") {
|
|
22035
|
+
throw new Error("Merry Runtime is a local managed package. Use pmate install merry-runtime for installation and merry-runtime upgrade for updates; service deploy is retired.");
|
|
22036
|
+
}
|
|
22038
22037
|
const baseUrl2 = this.resolveBaseUrl(args.baseUrl);
|
|
22039
22038
|
const registry = new ServiceRegistryClient(baseUrl2);
|
|
22040
22039
|
const runtime = new ServiceRuntimeRunner(
|
|
@@ -23337,6 +23336,7 @@ var RoleCommandHandler = class {
|
|
|
23337
23336
|
const scope = args.scope === "platform" ? { type: "platform" } : { type: "namespace", namespace: args.namespace };
|
|
23338
23337
|
let result;
|
|
23339
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 });
|
|
23340
23340
|
else if (args.resource === "check") result = await request2("POST", "/authz/permission", { permission: args.permission, scope, ...args.account ? { account: args.account } : {} });
|
|
23341
23341
|
else if (args.action === "list") {
|
|
23342
23342
|
const data = await request2("GET", "/authorization");
|
|
@@ -23727,9 +23727,8 @@ var AccountCommandHandler = class {
|
|
|
23727
23727
|
"POST",
|
|
23728
23728
|
"/access-keys",
|
|
23729
23729
|
{
|
|
23730
|
-
|
|
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 } : {} },
|
|
23731
23731
|
name: args.name,
|
|
23732
|
-
namespace: args.namespace,
|
|
23733
23732
|
expiresAt: args.expiresAt
|
|
23734
23733
|
}
|
|
23735
23734
|
);
|
|
@@ -23737,6 +23736,11 @@ var AccountCommandHandler = class {
|
|
|
23737
23736
|
this.renderAccessKeyCreateResult(result, args.json, args.out);
|
|
23738
23737
|
return;
|
|
23739
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
|
+
}
|
|
23740
23744
|
case "access-key-list": {
|
|
23741
23745
|
const token = this.readToken();
|
|
23742
23746
|
const baseUrl2 = this.resolveAuthBaseUrl(args.baseUrl);
|
|
@@ -24065,7 +24069,7 @@ var AccountCommandHandler = class {
|
|
|
24065
24069
|
if (parsed.type !== "pmate-access-key" || parsed.version !== 1 || !parsed.id || !parsed.app || !parsed.secret || !parsed.expiresAt) {
|
|
24066
24070
|
throw new Error(`Invalid PMate access key file: ${absolutePath}`);
|
|
24067
24071
|
}
|
|
24068
|
-
if (expectedApp && parsed.app
|
|
24072
|
+
if (expectedApp && !(parsed.config ? parsed.config.apps === "*" || parsed.config.apps.includes(expectedApp) : parsed.app === expectedApp)) {
|
|
24069
24073
|
throw new Error(`Access key app mismatch. expected=${expectedApp}, received=${parsed.app}`);
|
|
24070
24074
|
}
|
|
24071
24075
|
return parsed;
|
|
@@ -24075,14 +24079,15 @@ var AccountCommandHandler = class {
|
|
|
24075
24079
|
type: "pmate-access-key",
|
|
24076
24080
|
version: 1,
|
|
24077
24081
|
id: result.key.id,
|
|
24078
|
-
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 } : {},
|
|
24079
24084
|
name: result.key.name,
|
|
24080
24085
|
namespace: result.key.namespace,
|
|
24081
24086
|
secret: result.secret,
|
|
24082
24087
|
expiresAt: result.key.expiresAt,
|
|
24083
24088
|
createdAt: result.key.createdAt
|
|
24084
24089
|
};
|
|
24085
|
-
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);
|
|
24086
24091
|
(0, import_node_fs30.mkdirSync)(import_node_path35.default.dirname(outPath), { recursive: true });
|
|
24087
24092
|
(0, import_node_fs30.writeFileSync)(outPath, JSON.stringify(keyFile, null, 2), { mode: 384 });
|
|
24088
24093
|
(0, import_node_fs30.chmodSync)(outPath, 384);
|
|
@@ -24092,10 +24097,11 @@ var AccountCommandHandler = class {
|
|
|
24092
24097
|
this.renderJson(result, true);
|
|
24093
24098
|
return;
|
|
24094
24099
|
}
|
|
24095
|
-
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);
|
|
24096
24101
|
ui.success(`Access key saved to ${outPath}`);
|
|
24097
24102
|
ui.info(result.key.id, {
|
|
24098
|
-
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 } : {},
|
|
24099
24105
|
name: result.key.name,
|
|
24100
24106
|
namespace: result.key.namespace,
|
|
24101
24107
|
expiresAt: result.key.expiresAt
|
|
@@ -24112,7 +24118,8 @@ var AccountCommandHandler = class {
|
|
|
24112
24118
|
}
|
|
24113
24119
|
for (const item of items) {
|
|
24114
24120
|
ui.info(item.id, {
|
|
24115
|
-
|
|
24121
|
+
apps: item.config?.apps ?? item.app,
|
|
24122
|
+
roles: item.config?.roles,
|
|
24116
24123
|
name: item.name,
|
|
24117
24124
|
namespace: item.namespace,
|
|
24118
24125
|
status: item.status,
|
|
@@ -26271,7 +26278,7 @@ var rolePattern = /^[a-z0-9][a-z0-9_-]{0,62}(\/[a-z0-9][a-z0-9_-]{0,62})?$/;
|
|
|
26271
26278
|
var permissionPattern = /^[a-z][a-z0-9-]*:[a-z][a-z0-9-]*$/;
|
|
26272
26279
|
function parseRoleArgs(tokens) {
|
|
26273
26280
|
const rest = [...tokens], resource = rest.shift();
|
|
26274
|
-
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"] };
|
|
26275
26282
|
if (!actions[resource]) throw new Error("Missing role resource. Use: role definition|permission|grant|binding|migration|check");
|
|
26276
26283
|
const action = resource === "check" ? "check" : rest.shift();
|
|
26277
26284
|
if (!action) throw new Error("Missing role action");
|
|
@@ -26314,6 +26321,7 @@ function parseRoleArgs(tokens) {
|
|
|
26314
26321
|
if (args.namespace && !/^(\*|[a-z0-9][a-z0-9_-]{0,62})$/.test(args.namespace)) throw new Error("Invalid namespace");
|
|
26315
26322
|
if (args.scope && args.namespace) throw new Error("Choose --scope platform or --namespace, not both");
|
|
26316
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");
|
|
26317
26325
|
if (["add", "remove"].includes(action) && !args.role) throw new Error("Missing --role");
|
|
26318
26326
|
if (resource === "binding" && ["add", "remove"].includes(action) && !args.account) throw new Error("Missing --account");
|
|
26319
26327
|
if (resource === "grant" && action !== "list" || resource === "check") {
|
|
@@ -26707,6 +26715,8 @@ function parseAccountArgs(tokens) {
|
|
|
26707
26715
|
let out;
|
|
26708
26716
|
let key;
|
|
26709
26717
|
let keyFile;
|
|
26718
|
+
let configFile;
|
|
26719
|
+
let expectedVersion;
|
|
26710
26720
|
let gracePeriodSeconds;
|
|
26711
26721
|
let baseUrl3;
|
|
26712
26722
|
let json2 = false;
|
|
@@ -26718,6 +26728,12 @@ function parseAccountArgs(tokens) {
|
|
|
26718
26728
|
entityLabel: "app ref"
|
|
26719
26729
|
}).fullId;
|
|
26720
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;
|
|
26721
26737
|
case "--name":
|
|
26722
26738
|
name = requireValue5(rest, token);
|
|
26723
26739
|
break;
|
|
@@ -26749,7 +26765,7 @@ function parseAccountArgs(tokens) {
|
|
|
26749
26765
|
json2 = true;
|
|
26750
26766
|
break;
|
|
26751
26767
|
default:
|
|
26752
|
-
if ((keyAction === "rotate" || keyAction === "disable") && !token.startsWith("-")) {
|
|
26768
|
+
if ((keyAction === "rotate" || keyAction === "disable" || keyAction === "config") && !token.startsWith("-")) {
|
|
26753
26769
|
if (id) {
|
|
26754
26770
|
throw new Error(`Unexpected account access-key id: ${token}`);
|
|
26755
26771
|
}
|
|
@@ -26760,10 +26776,14 @@ function parseAccountArgs(tokens) {
|
|
|
26760
26776
|
}
|
|
26761
26777
|
}
|
|
26762
26778
|
if (keyAction === "create") {
|
|
26763
|
-
if (!app || !name) {
|
|
26779
|
+
if (!app && !configFile || !name) {
|
|
26764
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]");
|
|
26765
26781
|
}
|
|
26766
|
-
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 };
|
|
26767
26787
|
}
|
|
26768
26788
|
if (keyAction === "list") {
|
|
26769
26789
|
return { type: "account" /* Account */, action: "access-key-list", app, namespace: namespace2, baseUrl: baseUrl3, json: json2 };
|
|
@@ -27721,7 +27741,7 @@ var HELP_TEXT = [
|
|
|
27721
27741
|
` ${import_chalk4.default.gray(" bot profile create --app <ns:app> --name <name> --nickname <nickname> [--role <role>] [--base-url <url>] [--json]")}`,
|
|
27722
27742
|
` ${import_chalk4.default.gray(" bot profile update --app <ns:app> --name <name> --nickname <nickname> [--profile-id <id>] [--base-url <url>] [--json]")}`,
|
|
27723
27743
|
` ${import_chalk4.default.gray(" bot nickname --app <ns:app> --name <name> --nickname <nickname> [--base-url <url>] [--json] (alias for profile update)")}`,
|
|
27724
|
-
` ${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]")}`,
|
|
27725
27745
|
` ${import_chalk4.default.gray(" access-key list [--app <ns:app>] [--namespace <ns>] [--base-url <url>] [--json]")}`,
|
|
27726
27746
|
` ${import_chalk4.default.gray(" access-key rotate <id> [--expires-at <iso> | --expires-in <duration>] [--grace-period <duration>] [--out <path>] [--base-url <url>] [--json]")}`,
|
|
27727
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)
|