@pmate/cli 0.17.7 → 0.18.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
@@ -133,6 +133,12 @@ type QuizCommandArgs = {
133
133
  paperId: string;
134
134
  apiBaseUrl?: string;
135
135
  linkBaseUrl?: string;
136
+ } | {
137
+ type: Command.Quiz;
138
+ action: "view";
139
+ paperId: string;
140
+ apiBaseUrl?: string;
141
+ linkBaseUrl?: string;
136
142
  };
137
143
  type LinearPrCommandArgs = {
138
144
  type: Command.Linear;
package/dist/index.js CHANGED
@@ -13043,6 +13043,7 @@ var LoginCommandHandler = class {
13043
13043
  const callback = await this.startCallbackServer();
13044
13044
  const appId = args.app?.trim() || DEFAULT_APP_ID;
13045
13045
  const loginUrl = buildHostedLoginUrl(callback.redirectUrl, appId);
13046
+ let savedSession = null;
13046
13047
  ui.info("Opening browser for login.", {
13047
13048
  url: loginUrl,
13048
13049
  app: appId
@@ -13058,11 +13059,15 @@ var LoginCommandHandler = class {
13058
13059
  try {
13059
13060
  const token = await callback.waitForToken;
13060
13061
  const loginResponse = await this.fetchSession(token, appId);
13061
- const saved = saveLoginSession(loginResponse, appId);
13062
- ui.success(`Logged in to ${saved.app}. Session saved to ${saved.sessionPath}`);
13062
+ savedSession = saveLoginSession(loginResponse, appId);
13063
13063
  } finally {
13064
13064
  await callback.close();
13065
13065
  }
13066
+ if (savedSession) {
13067
+ ui.success(
13068
+ `Logged in to ${savedSession.app}. Session saved to ${savedSession.sessionPath}`
13069
+ );
13070
+ }
13066
13071
  }
13067
13072
  async fetchSession(token, appId) {
13068
13073
  const url = new URL(`${AUTH_API_BASE_URL}/session`);
@@ -18058,6 +18063,40 @@ async function activateQuizPaper({
18058
18063
  data: activated
18059
18064
  };
18060
18065
  }
18066
+ async function viewQuizPaper({
18067
+ fetchImpl = fetch,
18068
+ apiBaseUrl,
18069
+ linkBaseUrl,
18070
+ paperId,
18071
+ token
18072
+ }) {
18073
+ const trimmedApiBaseUrl = apiBaseUrl.replace(/\/+$/, "");
18074
+ const trimmedLinkBaseUrl = linkBaseUrl.replace(/\/+$/, "");
18075
+ const previewLink = `${trimmedLinkBaseUrl}/?paper=${encodeURIComponent(paperId)}`;
18076
+ const data = await requestJson(
18077
+ fetchImpl,
18078
+ `${trimmedApiBaseUrl}/api/quiz/papers/${encodeURIComponent(paperId)}`,
18079
+ {
18080
+ method: "GET",
18081
+ headers: {
18082
+ Authorization: `Bearer ${token}`
18083
+ }
18084
+ },
18085
+ "\u67E5\u770B\u8BD5\u5377"
18086
+ );
18087
+ const payload = data ?? {};
18088
+ const status = payload.status;
18089
+ const paperStatus = status === "draft" || status === "active" ? status : "unknown";
18090
+ const stepCount = typeof payload.stepCount === "number" ? payload.stepCount : Array.isArray(payload.steps) ? payload.steps.length : void 0;
18091
+ return {
18092
+ apiBaseUrl: trimmedApiBaseUrl,
18093
+ paperId,
18094
+ previewLink,
18095
+ paperStatus,
18096
+ stepCount,
18097
+ data
18098
+ };
18099
+ }
18061
18100
 
18062
18101
  // src/commands/QuizCommandHandler.ts
18063
18102
  var QuizCommandHandler = class {
@@ -18075,6 +18114,20 @@ var QuizCommandHandler = class {
18075
18114
  ui.success("Quiz \u5DF2\u6FC0\u6D3B\u53D1\u5E03", result2.link);
18076
18115
  return;
18077
18116
  }
18117
+ if (args.action === "view") {
18118
+ const result2 = await viewQuizPaper({
18119
+ apiBaseUrl,
18120
+ linkBaseUrl,
18121
+ paperId: args.paperId,
18122
+ token: session.token
18123
+ });
18124
+ ui.success("Quiz \u8BD5\u5377\u5DF2\u627E\u5230", result2.previewLink);
18125
+ ui.info("\u72B6\u6001", result2.paperStatus);
18126
+ if (typeof result2.stepCount === "number") {
18127
+ ui.info("\u9898\u76EE\u6570", String(result2.stepCount));
18128
+ }
18129
+ return;
18130
+ }
18078
18131
  const resolvedFilePath = import_node_path14.default.resolve(process.cwd(), args.filePath);
18079
18132
  const payload = JSON.parse((0, import_node_fs9.readFileSync)(resolvedFilePath, "utf8"));
18080
18133
  const result = await publishQuizPaper({
@@ -20652,14 +20705,9 @@ function parseAgentArgs(tokens) {
20652
20705
  "Usage: agent view <ns:objectId> [--base-url <url>]"
20653
20706
  );
20654
20707
  }
20655
- let namespaceFromOption;
20656
20708
  while (rest.length > 0) {
20657
20709
  const token = rest.shift();
20658
20710
  switch (token) {
20659
- case "--ns":
20660
- case "--namespace":
20661
- namespaceFromOption = requireValue(rest, token);
20662
- break;
20663
20711
  case "--base-url":
20664
20712
  baseUrl = requireValue(rest, token);
20665
20713
  break;
@@ -20668,7 +20716,6 @@ function parseAgentArgs(tokens) {
20668
20716
  }
20669
20717
  }
20670
20718
  const parsed = parseNamespacedRef(ref, {
20671
- defaultNamespace: namespaceFromOption,
20672
20719
  entityLabel: "agent ref"
20673
20720
  });
20674
20721
  return {
@@ -21159,18 +21206,7 @@ function parseAppArgs(tokens) {
21159
21206
  "Usage: app view <ns:objectId> [--base-url <url>]"
21160
21207
  );
21161
21208
  }
21162
- let namespace;
21163
- while (rest.length > 0) {
21164
- const token = rest[0];
21165
- if (token === "--ns" || token === "--namespace") {
21166
- rest.shift();
21167
- namespace = requireValue4(rest, token);
21168
- continue;
21169
- }
21170
- break;
21171
- }
21172
21209
  const id = parseNamespacedRef(rawRef, {
21173
- defaultNamespace: namespace,
21174
21210
  entityLabel: "app ref"
21175
21211
  }).fullId;
21176
21212
  while (rest.length > 0) {
@@ -21344,25 +21380,17 @@ function parseServiceArgs(tokens) {
21344
21380
  if (!ref || ref.startsWith("-")) {
21345
21381
  throw new Error("Usage: service view <ns:objectId> [--base-url <url>]");
21346
21382
  }
21347
- let namespaceFromOption;
21348
21383
  while (rest.length > 0) {
21349
21384
  const token = rest.shift();
21350
21385
  switch (token) {
21351
21386
  case "--base-url":
21352
21387
  baseUrl = requireValue5(rest, token);
21353
21388
  break;
21354
- case "--ns":
21355
- case "--namespace":
21356
- namespaceFromOption = requireValue5(rest, token);
21357
- break;
21358
21389
  default:
21359
21390
  throw new Error(`Unknown service view option: ${token}`);
21360
21391
  }
21361
21392
  }
21362
- const parsedRef = parseNamespacedRef(ref, {
21363
- defaultNamespace: namespaceFromOption,
21364
- entityLabel: "service ref"
21365
- });
21393
+ const parsedRef = parseNamespacedRef(ref, { entityLabel: "service ref" });
21366
21394
  return {
21367
21395
  type: "service" /* Service */,
21368
21396
  action,
@@ -21377,7 +21405,6 @@ function parseServiceArgs(tokens) {
21377
21405
  if (!ref || ref.startsWith("-")) {
21378
21406
  throw new Error(`Usage: service ${action} <ns:objectId> [--base-url <url>] [--json]`);
21379
21407
  }
21380
- let namespaceFromOption;
21381
21408
  let cwd;
21382
21409
  let page = 0;
21383
21410
  let history = false;
@@ -21388,10 +21415,6 @@ function parseServiceArgs(tokens) {
21388
21415
  case "--base-url":
21389
21416
  baseUrl = requireValue5(rest, token);
21390
21417
  break;
21391
- case "--ns":
21392
- case "--namespace":
21393
- namespaceFromOption = requireValue5(rest, token);
21394
- break;
21395
21418
  case "--cwd":
21396
21419
  cwd = requireValue5(rest, token);
21397
21420
  break;
@@ -21411,10 +21434,7 @@ function parseServiceArgs(tokens) {
21411
21434
  throw new Error(`Unknown service ${action} option: ${token}`);
21412
21435
  }
21413
21436
  }
21414
- const parsedRef = parseNamespacedRef(ref, {
21415
- defaultNamespace: action === "deploy" || action === "init" || action === "log" ? namespaceFromOption : void 0,
21416
- entityLabel: "service ref"
21417
- });
21437
+ const parsedRef = parseNamespacedRef(ref, { entityLabel: "service ref" });
21418
21438
  const namespace = parsedRef.namespace;
21419
21439
  const name = parsedRef.objectId;
21420
21440
  if (action === "log") {
@@ -21802,9 +21822,10 @@ var HELP_TEXT = [
21802
21822
  ` ${import_chalk3.default.gray(" [--push] [--cwd <dir>]")}`,
21803
21823
  ` ${import_chalk3.default.cyan("summary")} Summarize a GitHub PR with AI`,
21804
21824
  ` ${import_chalk3.default.gray(" --pr <id> [--cwd <dir>]")}`,
21805
- ` ${import_chalk3.default.cyan("quiz")} Publish quiz papers to quiz-api`,
21825
+ ` ${import_chalk3.default.cyan("quiz")} Manage quiz papers on quiz-api`,
21806
21826
  ` ${import_chalk3.default.gray(" publish --file <json> --paper-id <id> [--activate]")}`,
21807
21827
  ` ${import_chalk3.default.gray(" activate --paper-id <id>")}`,
21828
+ ` ${import_chalk3.default.gray(" view --paper-id <id>")}`,
21808
21829
  ` ${import_chalk3.default.cyan("linear")} Create Linear issues`,
21809
21830
  ` ${import_chalk3.default.gray(" (default) create via REPL")}`,
21810
21831
  ` ${import_chalk3.default.gray(" create --repl [--cwd <dir>]")}`,
@@ -21847,7 +21868,7 @@ var HELP_TEXT = [
21847
21868
  ` ${import_chalk3.default.gray(" namespaces [--base-url <url>] [--json]")}`,
21848
21869
  ` ${import_chalk3.default.gray(" list [--namespace <ns>] [--base-url <url>] [--json]")}`,
21849
21870
  ` ${import_chalk3.default.gray(" get <ns:objectId> [--base-url <url>] [--json]")}`,
21850
- ` ${import_chalk3.default.gray(" view (<ns:objectId> | <id> --ns <namespace>) [--base-url <url>]")}`,
21871
+ ` ${import_chalk3.default.gray(" view <ns:objectId> [--base-url <url>]")}`,
21851
21872
  ` ${import_chalk3.default.gray(" create [<namespace>] --file <path> [--base-url <url>] [--json]")}`,
21852
21873
  ` ${import_chalk3.default.gray(" update <ns:objectId> --file <path> [--base-url <url>] [--json]")}`,
21853
21874
  ` ${import_chalk3.default.gray(" rename --from <id> --to <id> --ns <namespace> [--base-url <url>] [--json]")}`,
@@ -21875,7 +21896,7 @@ var HELP_TEXT = [
21875
21896
  ` ${import_chalk3.default.cyan("app")} Manage app registry entries via apps-api`,
21876
21897
  ` ${import_chalk3.default.gray(" list [--ns <namespace>] [--base-url <url>] [--json]")}`,
21877
21898
  ` ${import_chalk3.default.gray(" get <ns:objectId> [--base-url <url>] [--json]")}`,
21878
- ` ${import_chalk3.default.gray(" view (<ns:objectId> | <id> --ns <namespace>) [--base-url <url>]")}`,
21899
+ ` ${import_chalk3.default.gray(" view <ns:objectId> [--base-url <url>]")}`,
21879
21900
  ` ${import_chalk3.default.gray(" create --file <path> [--base-url <url>] [--json]")}`,
21880
21901
  ` ${import_chalk3.default.gray(" update <ns:objectId> --file <path> [--base-url <url>] [--json]")}`,
21881
21902
  ` ${import_chalk3.default.gray(" rename --from <id> --to <id> --ns <namespace> [--base-url <url>] [--json]")}`,
@@ -21884,7 +21905,7 @@ var HELP_TEXT = [
21884
21905
  ` ${import_chalk3.default.cyan("service")} Manage service registry entries via apps-api`,
21885
21906
  ` ${import_chalk3.default.gray(" list [--namespace <ns>] [--repo <owner/name|https://github.com/owner/name>] [--base-url <url>] [--json]")}`,
21886
21907
  ` ${import_chalk3.default.gray(" get <ns:objectId> [--base-url <url>] [--json]")}`,
21887
- ` ${import_chalk3.default.gray(" view (<ns:objectId> | <id> --ns <namespace>) [--base-url <url>]")}`,
21908
+ ` ${import_chalk3.default.gray(" view <ns:objectId> [--base-url <url>]")}`,
21888
21909
  ` ${import_chalk3.default.gray(" create --file <path> [--base-url <url>] [--json]")}`,
21889
21910
  ` ${import_chalk3.default.gray(" update <ns:objectId> --file <path> [--base-url <url>] [--json]")}`,
21890
21911
  ` ${import_chalk3.default.gray(" rename --from <id> --to <id> --ns <namespace> [--base-url <url>] [--json]")}`,
@@ -22401,7 +22422,7 @@ function parseQuizArgs(tokens) {
22401
22422
  const rest = [...tokens];
22402
22423
  const action = rest.shift();
22403
22424
  if (!action) {
22404
- throw new Error("Missing quiz action. Usage: quiz publish|activate");
22425
+ throw new Error("Missing quiz action. Usage: quiz publish|activate|view");
22405
22426
  }
22406
22427
  if (action === "publish") {
22407
22428
  let filePath;
@@ -22478,6 +22499,37 @@ function parseQuizArgs(tokens) {
22478
22499
  linkBaseUrl
22479
22500
  };
22480
22501
  }
22502
+ if (action === "view") {
22503
+ let paperId;
22504
+ let apiBaseUrl;
22505
+ let linkBaseUrl;
22506
+ while (rest.length > 0) {
22507
+ const token = rest.shift();
22508
+ switch (token) {
22509
+ case "--paper-id":
22510
+ paperId = requireValue8(rest, token);
22511
+ break;
22512
+ case "--base-url":
22513
+ apiBaseUrl = requireValue8(rest, token);
22514
+ break;
22515
+ case "--link-base":
22516
+ linkBaseUrl = requireValue8(rest, token);
22517
+ break;
22518
+ default:
22519
+ throw new Error(`Unknown quiz view option: ${token}`);
22520
+ }
22521
+ }
22522
+ if (!paperId) {
22523
+ throw new Error("Missing --paper-id. Usage: quiz view --paper-id <id>.");
22524
+ }
22525
+ return {
22526
+ type: "quiz" /* Quiz */,
22527
+ action: "view",
22528
+ paperId,
22529
+ apiBaseUrl,
22530
+ linkBaseUrl
22531
+ };
22532
+ }
22481
22533
  throw new Error(`Unknown quiz action: ${action}`);
22482
22534
  }
22483
22535
  function parseLinearArgs(tokens) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pmate/cli",
3
- "version": "0.17.7",
3
+ "version": "0.18.0",
4
4
  "description": "CLI utilities for the pMate project",
5
5
  "license": "MIT",
6
6
  "bin": {