@pmate/cli 0.17.8 → 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({
@@ -21769,9 +21822,10 @@ var HELP_TEXT = [
21769
21822
  ` ${import_chalk3.default.gray(" [--push] [--cwd <dir>]")}`,
21770
21823
  ` ${import_chalk3.default.cyan("summary")} Summarize a GitHub PR with AI`,
21771
21824
  ` ${import_chalk3.default.gray(" --pr <id> [--cwd <dir>]")}`,
21772
- ` ${import_chalk3.default.cyan("quiz")} Publish quiz papers to quiz-api`,
21825
+ ` ${import_chalk3.default.cyan("quiz")} Manage quiz papers on quiz-api`,
21773
21826
  ` ${import_chalk3.default.gray(" publish --file <json> --paper-id <id> [--activate]")}`,
21774
21827
  ` ${import_chalk3.default.gray(" activate --paper-id <id>")}`,
21828
+ ` ${import_chalk3.default.gray(" view --paper-id <id>")}`,
21775
21829
  ` ${import_chalk3.default.cyan("linear")} Create Linear issues`,
21776
21830
  ` ${import_chalk3.default.gray(" (default) create via REPL")}`,
21777
21831
  ` ${import_chalk3.default.gray(" create --repl [--cwd <dir>]")}`,
@@ -22368,7 +22422,7 @@ function parseQuizArgs(tokens) {
22368
22422
  const rest = [...tokens];
22369
22423
  const action = rest.shift();
22370
22424
  if (!action) {
22371
- throw new Error("Missing quiz action. Usage: quiz publish|activate");
22425
+ throw new Error("Missing quiz action. Usage: quiz publish|activate|view");
22372
22426
  }
22373
22427
  if (action === "publish") {
22374
22428
  let filePath;
@@ -22445,6 +22499,37 @@ function parseQuizArgs(tokens) {
22445
22499
  linkBaseUrl
22446
22500
  };
22447
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
+ }
22448
22533
  throw new Error(`Unknown quiz action: ${action}`);
22449
22534
  }
22450
22535
  function parseLinearArgs(tokens) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pmate/cli",
3
- "version": "0.17.8",
3
+ "version": "0.18.0",
4
4
  "description": "CLI utilities for the pMate project",
5
5
  "license": "MIT",
6
6
  "bin": {