@pmate/cli 0.49.6 → 0.50.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/README.md CHANGED
@@ -424,3 +424,21 @@ Permission risk: H requires an admin-level role, M requires maintainer or admin,
424
424
  A Bot Account may own multiple application Profiles. Normal registration ensures one initial Profile; explicit `account bot profile create` adds another Profile for testing or another role. Agent execution metadata uses the selected Profile ID, not the account name.
425
425
 
426
426
  Bot login and nickname updates accept `--profile-id 0x…`. With multiple Profiles, select the intended Profile explicitly. Login does not create a Profile or silently choose the first. The desktop Runtime editor also requires an existing canonical Bot Profile ID; plugin IDs retain their own namespace.
427
+
428
+ ## Account lookup
429
+
430
+ ### Background
431
+
432
+ `account view` separates basic identity from explicitly requested private fields. Looking up another account in an authorized App no longer requires account administration rights. Role bindings, sessions and credentials remain separate resources.
433
+
434
+ ```sh
435
+ pmate account view --app pmate:merry --nickname Arius --json
436
+ pmate account view --account <id> --json
437
+ pmate account view --account <id> --include private --json
438
+ ```
439
+
440
+ Nickname lookup requires `--app`; duplicate nicknames return candidates for selection by Account ID. ID lookups default to the authenticated session's App. An explicit different App requires platform `profile:read`; namespace-limited credentials cannot escape their namespace. The App flag filters profiles; it does not switch authentication identity or grant access.
441
+
442
+ The response remains a JSON array with `account`, `profiles`, and `nickNames`. Basic account fields are `id`, `createdAt`, `kind`, and optional `name`; profiles contain only `id`, `app`, `account`, `userName`, `nickName`, `avatar`. Even self/root lookups omit mobile by default. `--include private` adds mobile only for self or platform `account:read`; phone-number search always requires that permission before lookup, plus explicit private inclusion. Inaccessible and absent basic targets both return an empty array.
443
+
444
+ Migration: callers relying on the old aggregated `roles`, `session`, full profiles or implicit mobile must use the appropriate resource API or explicitly request private fields. Account list and app-users remain privileged administration commands and retain their existing contracts. Deploy the updated auth API before using these CLI options.
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;
@@ -379,6 +379,8 @@ type AccountCommandArgs = {
379
379
  account?: string;
380
380
  mobile?: string;
381
381
  nickName?: string;
382
+ app?: string;
383
+ include?: "private";
382
384
  baseUrl?: string;
383
385
  json: boolean;
384
386
  } | {
@@ -490,13 +492,22 @@ type AccountCommandArgs = {
490
492
  } | {
491
493
  type: Command.Account;
492
494
  action: "access-key-create";
493
- app: string;
495
+ configFile?: string;
496
+ app?: string;
494
497
  name: string;
495
498
  namespace?: string;
496
499
  expiresAt?: string;
497
500
  out?: string;
498
501
  baseUrl?: string;
499
502
  json: boolean;
503
+ } | {
504
+ type: Command.Account;
505
+ action: "access-key-config";
506
+ id: string;
507
+ configFile: string;
508
+ expectedVersion: number;
509
+ baseUrl?: string;
510
+ json: boolean;
500
511
  } | {
501
512
  type: Command.Account;
502
513
  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 !== options.expectedApp) {
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
- const dir = resolveAccessKeyDir(app);
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");
@@ -23420,7 +23417,7 @@ var AccountCommandHandler = class {
23420
23417
  "GET",
23421
23418
  `/accounts/view?${this.buildAccountViewQuery(args)}`
23422
23419
  );
23423
- this.renderAccountView(result.items, args.json);
23420
+ this.renderAccountLookup(result.items, args.json);
23424
23421
  return;
23425
23422
  }
23426
23423
  case "role-list": {
@@ -23730,9 +23727,8 @@ var AccountCommandHandler = class {
23730
23727
  "POST",
23731
23728
  "/access-keys",
23732
23729
  {
23733
- app: args.app,
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);
@@ -23820,6 +23821,8 @@ var AccountCommandHandler = class {
23820
23821
  if (args.account) params.set("account", args.account);
23821
23822
  if (args.mobile) params.set("mobile", args.mobile);
23822
23823
  if (args.nickName) params.set("nickName", args.nickName);
23824
+ if (args.app) params.set("app", args.app);
23825
+ if (args.include) params.set("include", args.include);
23823
23826
  return params.toString();
23824
23827
  }
23825
23828
  buildAccountListQuery(args) {
@@ -23896,6 +23899,19 @@ var AccountCommandHandler = class {
23896
23899
  ui.plain(item);
23897
23900
  }
23898
23901
  }
23902
+ renderAccountLookup(items, asJson) {
23903
+ if (asJson) {
23904
+ ui.plain(JSON.stringify(items, null, 2));
23905
+ return;
23906
+ }
23907
+ if (!items.length) {
23908
+ ui.warn("No accounts found in the visible scope.");
23909
+ return;
23910
+ }
23911
+ for (const item of items) {
23912
+ ui.info(item.account.id, { ...item.account, profiles: item.profiles, nickNames: item.nickNames });
23913
+ }
23914
+ }
23899
23915
  renderAccountView(items, asJson) {
23900
23916
  if (asJson) {
23901
23917
  ui.plain(JSON.stringify(items, null, 2));
@@ -24068,7 +24084,7 @@ var AccountCommandHandler = class {
24068
24084
  if (parsed.type !== "pmate-access-key" || parsed.version !== 1 || !parsed.id || !parsed.app || !parsed.secret || !parsed.expiresAt) {
24069
24085
  throw new Error(`Invalid PMate access key file: ${absolutePath}`);
24070
24086
  }
24071
- if (expectedApp && parsed.app !== expectedApp) {
24087
+ if (expectedApp && !(parsed.config ? parsed.config.apps === "*" || parsed.config.apps.includes(expectedApp) : parsed.app === expectedApp)) {
24072
24088
  throw new Error(`Access key app mismatch. expected=${expectedApp}, received=${parsed.app}`);
24073
24089
  }
24074
24090
  return parsed;
@@ -24078,14 +24094,15 @@ var AccountCommandHandler = class {
24078
24094
  type: "pmate-access-key",
24079
24095
  version: 1,
24080
24096
  id: result.key.id,
24081
- app: result.key.app,
24097
+ app: result.key.config ? result.key.config.apps === "*" || result.key.config.apps.length !== 1 ? "*" : result.key.config.apps[0] : result.key.app,
24098
+ ...result.key.config ? { config: result.key.config } : {},
24082
24099
  name: result.key.name,
24083
24100
  namespace: result.key.namespace,
24084
24101
  secret: result.secret,
24085
24102
  expiresAt: result.key.expiresAt,
24086
24103
  createdAt: result.key.createdAt
24087
24104
  };
24088
- const outPath = out ? this.resolveFilePath(out) : this.resolveDefaultAccessKeyPath(result.key.app, result.key.name);
24105
+ 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
24106
  (0, import_node_fs30.mkdirSync)(import_node_path35.default.dirname(outPath), { recursive: true });
24090
24107
  (0, import_node_fs30.writeFileSync)(outPath, JSON.stringify(keyFile, null, 2), { mode: 384 });
24091
24108
  (0, import_node_fs30.chmodSync)(outPath, 384);
@@ -24095,10 +24112,11 @@ var AccountCommandHandler = class {
24095
24112
  this.renderJson(result, true);
24096
24113
  return;
24097
24114
  }
24098
- const outPath = out ? this.resolveFilePath(out) : this.resolveDefaultAccessKeyPath(result.key.app, result.key.name);
24115
+ 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
24116
  ui.success(`Access key saved to ${outPath}`);
24100
24117
  ui.info(result.key.id, {
24101
- app: result.key.app,
24118
+ app: result.key.config ? result.key.config.apps === "*" || result.key.config.apps.length !== 1 ? "*" : result.key.config.apps[0] : result.key.app,
24119
+ ...result.key.config ? { config: result.key.config } : {},
24102
24120
  name: result.key.name,
24103
24121
  namespace: result.key.namespace,
24104
24122
  expiresAt: result.key.expiresAt
@@ -24115,7 +24133,8 @@ var AccountCommandHandler = class {
24115
24133
  }
24116
24134
  for (const item of items) {
24117
24135
  ui.info(item.id, {
24118
- app: item.app,
24136
+ apps: item.config?.apps ?? item.app,
24137
+ roles: item.config?.roles,
24119
24138
  name: item.name,
24120
24139
  namespace: item.namespace,
24121
24140
  status: item.status,
@@ -26274,7 +26293,7 @@ var rolePattern = /^[a-z0-9][a-z0-9_-]{0,62}(\/[a-z0-9][a-z0-9_-]{0,62})?$/;
26274
26293
  var permissionPattern = /^[a-z][a-z0-9-]*:[a-z][a-z0-9-]*$/;
26275
26294
  function parseRoleArgs(tokens) {
26276
26295
  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"] };
26296
+ 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
26297
  if (!actions[resource]) throw new Error("Missing role resource. Use: role definition|permission|grant|binding|migration|check");
26279
26298
  const action = resource === "check" ? "check" : rest.shift();
26280
26299
  if (!action) throw new Error("Missing role action");
@@ -26317,6 +26336,7 @@ function parseRoleArgs(tokens) {
26317
26336
  if (args.namespace && !/^(\*|[a-z0-9][a-z0-9_-]{0,62})$/.test(args.namespace)) throw new Error("Invalid namespace");
26318
26337
  if (args.scope && args.namespace) throw new Error("Choose --scope platform or --namespace, not both");
26319
26338
  if (resource === "permission" && action === "create" && !args.scopeType) throw new Error("Permission creation requires --scope-type platform|namespace");
26339
+ if (action === "delete" && !args.role) throw new Error("Missing --role");
26320
26340
  if (["add", "remove"].includes(action) && !args.role) throw new Error("Missing --role");
26321
26341
  if (resource === "binding" && ["add", "remove"].includes(action) && !args.account) throw new Error("Missing --account");
26322
26342
  if (resource === "grant" && action !== "list" || resource === "check") {
@@ -26425,7 +26445,8 @@ function parseAccountArgs(tokens) {
26425
26445
  let account2;
26426
26446
  let mobile;
26427
26447
  let nickName;
26428
- let profileId;
26448
+ let app;
26449
+ let include;
26429
26450
  let baseUrl3;
26430
26451
  let json2 = false;
26431
26452
  while (rest.length > 0) {
@@ -26443,6 +26464,13 @@ function parseAccountArgs(tokens) {
26443
26464
  case "--nickName":
26444
26465
  nickName = requireValue5(rest, token);
26445
26466
  break;
26467
+ case "--app":
26468
+ app = parseNamespacedRef(requireValue5(rest, token), { entityLabel: "app ref" }).fullId;
26469
+ break;
26470
+ case "--include":
26471
+ if (requireValue5(rest, token) !== "private") throw new Error("--include must be private");
26472
+ include = "private";
26473
+ break;
26446
26474
  case "--base-url":
26447
26475
  baseUrl3 = requireValue5(rest, token);
26448
26476
  break;
@@ -26460,15 +26488,19 @@ function parseAccountArgs(tokens) {
26460
26488
  const provided = [account2, mobile, nickName].filter(Boolean).length;
26461
26489
  if (provided !== 1) {
26462
26490
  throw new Error(
26463
- "Usage: account view (--account <id> | --mobile <mobile> | --nickname <nickname>) [--base-url <url>] [--json]"
26491
+ "Usage: account view (--account <id> | --mobile <mobile> | --nickname <nickname>) [--app <ns:id>] [--include private] [--base-url <url>] [--json]"
26464
26492
  );
26465
26493
  }
26494
+ if (nickName && !app) throw new Error("Nickname lookup requires --app <ns:id>");
26495
+ if (mobile && include !== "private") throw new Error("Mobile lookup requires --include private");
26466
26496
  return {
26467
26497
  type: "account" /* Account */,
26468
26498
  action,
26469
26499
  account: account2,
26470
26500
  mobile,
26471
26501
  nickName,
26502
+ ...app ? { app } : {},
26503
+ ...include ? { include } : {},
26472
26504
  baseUrl: baseUrl3,
26473
26505
  json: json2
26474
26506
  };
@@ -26710,6 +26742,8 @@ function parseAccountArgs(tokens) {
26710
26742
  let out;
26711
26743
  let key;
26712
26744
  let keyFile;
26745
+ let configFile;
26746
+ let expectedVersion;
26713
26747
  let gracePeriodSeconds;
26714
26748
  let baseUrl3;
26715
26749
  let json2 = false;
@@ -26721,6 +26755,12 @@ function parseAccountArgs(tokens) {
26721
26755
  entityLabel: "app ref"
26722
26756
  }).fullId;
26723
26757
  break;
26758
+ case "--config-file":
26759
+ configFile = requireValue5(rest, token);
26760
+ break;
26761
+ case "--expected-version":
26762
+ expectedVersion = Number(requireValue5(rest, token));
26763
+ break;
26724
26764
  case "--name":
26725
26765
  name = requireValue5(rest, token);
26726
26766
  break;
@@ -26752,7 +26792,7 @@ function parseAccountArgs(tokens) {
26752
26792
  json2 = true;
26753
26793
  break;
26754
26794
  default:
26755
- if ((keyAction === "rotate" || keyAction === "disable") && !token.startsWith("-")) {
26795
+ if ((keyAction === "rotate" || keyAction === "disable" || keyAction === "config") && !token.startsWith("-")) {
26756
26796
  if (id) {
26757
26797
  throw new Error(`Unexpected account access-key id: ${token}`);
26758
26798
  }
@@ -26763,10 +26803,14 @@ function parseAccountArgs(tokens) {
26763
26803
  }
26764
26804
  }
26765
26805
  if (keyAction === "create") {
26766
- if (!app || !name) {
26806
+ if (!app && !configFile || !name) {
26767
26807
  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
26808
  }
26769
- return { type: "account" /* Account */, action: "access-key-create", app, name, namespace: namespace2, expiresAt, out, baseUrl: baseUrl3, json: json2 };
26809
+ return { type: "account" /* Account */, action: "access-key-create", ...configFile ? { configFile } : {}, app, name, namespace: namespace2, expiresAt, out, baseUrl: baseUrl3, json: json2 };
26810
+ }
26811
+ if (keyAction === "config") {
26812
+ if (!id || !configFile || !Number.isSafeInteger(expectedVersion) || expectedVersion < 1) throw new Error("Usage: account access-key config <id> --config-file <json> --expected-version <version>");
26813
+ return { type: "account" /* Account */, action: "access-key-config", id, configFile, expectedVersion, baseUrl: baseUrl3, json: json2 };
26770
26814
  }
26771
26815
  if (keyAction === "list") {
26772
26816
  return { type: "account" /* Account */, action: "access-key-list", app, namespace: namespace2, baseUrl: baseUrl3, json: json2 };
@@ -27724,7 +27768,7 @@ var HELP_TEXT = [
27724
27768
  ` ${import_chalk4.default.gray(" bot profile create --app <ns:app> --name <name> --nickname <nickname> [--role <role>] [--base-url <url>] [--json]")}`,
27725
27769
  ` ${import_chalk4.default.gray(" bot profile update --app <ns:app> --name <name> --nickname <nickname> [--profile-id <id>] [--base-url <url>] [--json]")}`,
27726
27770
  ` ${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]")}`,
27771
+ ` ${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
27772
  ` ${import_chalk4.default.gray(" access-key list [--app <ns:app>] [--namespace <ns>] [--base-url <url>] [--json]")}`,
27729
27773
  ` ${import_chalk4.default.gray(" access-key rotate <id> [--expires-at <iso> | --expires-in <duration>] [--grace-period <duration>] [--out <path>] [--base-url <url>] [--json]")}`,
27730
27774
  ` ${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)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pmate/cli",
3
- "version": "0.49.6",
3
+ "version": "0.50.0",
4
4
  "description": "CLI utilities for the pMate project",
5
5
  "license": "MIT",
6
6
  "bin": {