@narumitw/pi-starship 0.55.0 → 0.55.2

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.
Files changed (101) hide show
  1. package/README.md +21 -36
  2. package/dist/chunks/{chunk-UX6PBXVK.js → chunk-JO5PH6FN.js} +28 -110
  3. package/dist/chunks/chunk-JO5PH6FN.js.map +7 -0
  4. package/dist/chunks/{chunk-P4XMFSQW.js → chunk-YWY5RIDQ.js} +3 -7
  5. package/dist/chunks/chunk-YWY5RIDQ.js.map +7 -0
  6. package/dist/chunks/{chunk-EOGXAMTA.js → chunk-ZQZSXXPI.js} +1 -1
  7. package/dist/chunks/chunk-ZQZSXXPI.js.map +7 -0
  8. package/dist/chunks/{cloud-BKHYWCTA.js → cloud-C4VU3TX3.js} +7 -14
  9. package/dist/chunks/cloud-C4VU3TX3.js.map +7 -0
  10. package/dist/chunks/{commands-53ZO2JUK.js → commands-ATILSUVK.js} +13 -42
  11. package/dist/chunks/commands-ATILSUVK.js.map +7 -0
  12. package/dist/chunks/{deployment-RKKOEQQ2.js → deployment-FMNTYRBW.js} +6 -21
  13. package/dist/chunks/deployment-FMNTYRBW.js.map +7 -0
  14. package/dist/chunks/{development-BERD42HW.js → development-OUYXDPBS.js} +4 -8
  15. package/dist/chunks/development-OUYXDPBS.js.map +7 -0
  16. package/dist/chunks/{execution-42JTEY3N.js → execution-HJOGLMWD.js} +3 -3
  17. package/dist/chunks/execution-HJOGLMWD.js.map +7 -0
  18. package/dist/chunks/{languages-RMP6DW7H.js → languages-WXMF4GOF.js} +6 -22
  19. package/dist/chunks/languages-WXMF4GOF.js.map +7 -0
  20. package/dist/chunks/{package-LG5H7BBM.js → package-YXRZQAOV.js} +5 -14
  21. package/dist/chunks/package-YXRZQAOV.js.map +7 -0
  22. package/dist/index.ts +38 -53
  23. package/dist/index.ts.map +2 -2
  24. package/package.json +60 -61
  25. package/skills/configuring-pi-starship/references/runtime-and-security.md +5 -1
  26. package/skills/configuring-pi-starship/scripts/apply.mjs +43 -47
  27. package/skills/configuring-pi-starship/scripts/config-path.mjs +3 -3
  28. package/skills/configuring-pi-starship/scripts/script-support.mjs +6 -6
  29. package/skills/configuring-pi-starship/scripts/validate.mjs +18 -18
  30. package/src/command-configuration.ts +267 -286
  31. package/src/command-contract.ts +6 -6
  32. package/src/command-inspector.ts +27 -27
  33. package/src/command-preset-picker.ts +45 -50
  34. package/src/command-preview.ts +153 -166
  35. package/src/commands.ts +588 -618
  36. package/src/config.ts +580 -660
  37. package/src/effective-config.ts +46 -48
  38. package/src/format/formatter.ts +211 -227
  39. package/src/format/style.ts +205 -216
  40. package/src/modules/activity.ts +74 -74
  41. package/src/modules/brand.ts +9 -9
  42. package/src/modules/cache.ts +18 -18
  43. package/src/modules/catalog.ts +79 -83
  44. package/src/modules/cloud.ts +54 -54
  45. package/src/modules/context.ts +27 -27
  46. package/src/modules/cost.ts +23 -23
  47. package/src/modules/deployment.ts +45 -45
  48. package/src/modules/development.ts +80 -81
  49. package/src/modules/directory.ts +89 -113
  50. package/src/modules/display.ts +9 -9
  51. package/src/modules/execution.ts +62 -69
  52. package/src/modules/extension-status.ts +59 -64
  53. package/src/modules/fill.ts +10 -10
  54. package/src/modules/git/branch.ts +26 -26
  55. package/src/modules/git/commit.ts +21 -23
  56. package/src/modules/git/metrics.ts +22 -22
  57. package/src/modules/git/runtime.ts +299 -334
  58. package/src/modules/git/state.ts +17 -17
  59. package/src/modules/git/status.ts +77 -79
  60. package/src/modules/git/worktree.ts +10 -12
  61. package/src/modules/github-pr.ts +20 -20
  62. package/src/modules/helpers.ts +3 -3
  63. package/src/modules/index.ts +21 -21
  64. package/src/modules/inspection.ts +101 -108
  65. package/src/modules/languages.ts +52 -59
  66. package/src/modules/model.ts +57 -67
  67. package/src/modules/package.ts +12 -12
  68. package/src/modules/provider.ts +22 -24
  69. package/src/modules/render.ts +124 -140
  70. package/src/modules/thinking.ts +27 -26
  71. package/src/modules/time.ts +10 -13
  72. package/src/modules/tokens.ts +13 -13
  73. package/src/modules/truncation.ts +14 -17
  74. package/src/modules/turn.ts +9 -9
  75. package/src/modules/types.ts +125 -132
  76. package/src/modules/workspace-helpers.ts +4 -7
  77. package/src/pi-starship.ts +567 -571
  78. package/src/presets/catalog.ts +113 -113
  79. package/src/runtime/cloud.ts +122 -150
  80. package/src/runtime/command.ts +106 -108
  81. package/src/runtime/deployment.ts +150 -179
  82. package/src/runtime/development.ts +107 -124
  83. package/src/runtime/execution.ts +110 -124
  84. package/src/runtime/github-pr.ts +223 -252
  85. package/src/runtime/helpers.ts +186 -199
  86. package/src/runtime/languages.ts +149 -180
  87. package/src/runtime/package.ts +74 -87
  88. package/src/runtime/refresh-controller.ts +82 -86
  89. package/src/runtime/types.ts +38 -38
  90. package/src/runtime/workspace.ts +108 -116
  91. package/src/usage.ts +40 -40
  92. package/dist/chunks/chunk-EOGXAMTA.js.map +0 -7
  93. package/dist/chunks/chunk-P4XMFSQW.js.map +0 -7
  94. package/dist/chunks/chunk-UX6PBXVK.js.map +0 -7
  95. package/dist/chunks/cloud-BKHYWCTA.js.map +0 -7
  96. package/dist/chunks/commands-53ZO2JUK.js.map +0 -7
  97. package/dist/chunks/deployment-RKKOEQQ2.js.map +0 -7
  98. package/dist/chunks/development-BERD42HW.js.map +0 -7
  99. package/dist/chunks/execution-42JTEY3N.js.map +0 -7
  100. package/dist/chunks/languages-RMP6DW7H.js.map +0 -7
  101. package/dist/chunks/package-LG5H7BBM.js.map +0 -7
@@ -7,338 +7,309 @@ const MAX_GH_OUTPUT_BYTES = 128 * 1024;
7
7
  const MAX_URL_LENGTH = 4_096;
8
8
  const MAX_CHECKS = 1_000;
9
9
  const MAX_FIELD_LENGTH = 128;
10
- const RFC3339_TIMESTAMP =
11
- /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d{1,9})?(?:Z|[+-](\d{2}):(\d{2}))$/u;
10
+ const RFC3339_TIMESTAMP = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d{1,9})?(?:Z|[+-](\d{2}):(\d{2}))$/u;
12
11
  export const TERMINAL_PR_LIFETIME_MS = 24 * 60 * 60 * 1_000;
13
12
 
14
13
  const GH_PR_FIELDS = [
15
- "number",
16
- "isDraft",
17
- "url",
18
- "state",
19
- "closedAt",
20
- "mergedAt",
21
- "reviewDecision",
22
- "statusCheckRollup",
14
+ "number",
15
+ "isDraft",
16
+ "url",
17
+ "state",
18
+ "closedAt",
19
+ "mergedAt",
20
+ "reviewDecision",
21
+ "statusCheckRollup",
23
22
  ] as const;
24
23
 
25
24
  interface GithubPrQueryOptions {
26
- platform?: NodeJS.Platform;
27
- environment?: Readonly<Record<string, string | undefined>>;
25
+ platform?: NodeJS.Platform;
26
+ environment?: Readonly<Record<string, string | undefined>>;
28
27
  }
29
28
 
30
29
  interface CheckSummary {
31
- failed: number;
32
- pending: number;
33
- total: number;
30
+ failed: number;
31
+ pending: number;
32
+ total: number;
34
33
  }
35
34
 
36
35
  type PullRequestState = "OPEN" | "CLOSED" | "MERGED";
37
36
  type ReviewDecision = "APPROVED" | "CHANGES_REQUESTED" | "REVIEW_REQUIRED" | "";
38
37
 
39
38
  export function ghPrViewInvocation(platform: NodeJS.Platform = process.platform): {
40
- command: string;
41
- args: string[];
39
+ command: string;
40
+ args: string[];
42
41
  } {
43
- return {
44
- command: platform === "win32" ? "gh.exe" : "gh",
45
- args: ["pr", "view", "--json", GH_PR_FIELDS.join(",")],
46
- };
42
+ return {
43
+ command: platform === "win32" ? "gh.exe" : "gh",
44
+ args: ["pr", "view", "--json", GH_PR_FIELDS.join(",")],
45
+ };
47
46
  }
48
47
 
49
48
  export function githubPrEnvironment(
50
- source: Readonly<Record<string, string | undefined>> = process.env,
49
+ source: Readonly<Record<string, string | undefined>> = process.env,
51
50
  ): Record<string, string | undefined> {
52
- const environment: Record<string, string | undefined> = Object.create(null);
53
- for (const [name, value] of Object.entries(source)) {
54
- const normalized = name.toUpperCase();
55
- if (normalized === "GH_HOST" || normalized === "GH_REPO") continue;
56
- Object.defineProperty(environment, name, {
57
- value,
58
- writable: true,
59
- enumerable: true,
60
- configurable: true,
61
- });
62
- }
63
- return environment;
51
+ const environment: Record<string, string | undefined> = Object.create(null);
52
+ for (const [name, value] of Object.entries(source)) {
53
+ const normalized = name.toUpperCase();
54
+ if (normalized === "GH_HOST" || normalized === "GH_REPO") continue;
55
+ Object.defineProperty(environment, name, {
56
+ value,
57
+ writable: true,
58
+ enumerable: true,
59
+ configurable: true,
60
+ });
61
+ }
62
+ return environment;
64
63
  }
65
64
 
66
65
  export async function queryGithubPr(
67
- exec: WorkspaceExec,
68
- cwd: string,
69
- signal?: AbortSignal,
70
- now = Date.now(),
71
- options: GithubPrQueryOptions = {},
66
+ exec: WorkspaceExec,
67
+ cwd: string,
68
+ signal?: AbortSignal,
69
+ now = Date.now(),
70
+ options: GithubPrQueryOptions = {},
72
71
  ): Promise<GithubPrSnapshot | undefined> {
73
- const invocation = ghPrViewInvocation(options.platform);
74
- try {
75
- const result = await exec(invocation.command, invocation.args, {
76
- cwd,
77
- signal,
78
- timeout: GH_TIMEOUT_MS,
79
- maxOutputBytes: MAX_GH_OUTPUT_BYTES,
80
- environment: githubPrEnvironment(options.environment),
81
- });
82
- if (result.killed || result.code !== 0) return undefined;
83
- if (Buffer.byteLength(result.stdout) > MAX_GH_OUTPUT_BYTES) return undefined;
84
- return buildGithubPrSnapshot(JSON.parse(result.stdout), now);
85
- } catch {
86
- return undefined;
87
- }
72
+ const invocation = ghPrViewInvocation(options.platform);
73
+ try {
74
+ const result = await exec(invocation.command, invocation.args, {
75
+ cwd,
76
+ signal,
77
+ timeout: GH_TIMEOUT_MS,
78
+ maxOutputBytes: MAX_GH_OUTPUT_BYTES,
79
+ environment: githubPrEnvironment(options.environment),
80
+ });
81
+ if (result.killed || result.code !== 0) return undefined;
82
+ if (Buffer.byteLength(result.stdout) > MAX_GH_OUTPUT_BYTES) return undefined;
83
+ return buildGithubPrSnapshot(JSON.parse(result.stdout), now);
84
+ } catch {
85
+ return undefined;
86
+ }
88
87
  }
89
88
 
90
- export function buildGithubPrSnapshot(
91
- value: unknown,
92
- now = Date.now(),
93
- ): GithubPrSnapshot | undefined {
94
- try {
95
- const pr = record(value);
96
- const number = positiveInteger(pr.number);
97
- const isDraft = requiredBoolean(pr.isDraft);
98
- const url = requiredBoundedString(pr.url, MAX_URL_LENGTH, true);
99
- const state = pullRequestState(pr.state);
100
- const closedAt = optionalTimestamp(pr.closedAt);
101
- const mergedAt = optionalTimestamp(pr.mergedAt);
102
- const reviewDecision = reviewDecisionValue(pr.reviewDecision);
103
- const checks = summarizeChecks(pr.statusCheckRollup);
104
- const expiresAt = terminalExpiry(state, closedAt, mergedAt);
105
- if (state !== "OPEN" && (expiresAt === undefined || now >= expiresAt)) return undefined;
89
+ export function buildGithubPrSnapshot(value: unknown, now = Date.now()): GithubPrSnapshot | undefined {
90
+ try {
91
+ const pr = record(value);
92
+ const number = positiveInteger(pr.number);
93
+ const isDraft = requiredBoolean(pr.isDraft);
94
+ const url = requiredBoundedString(pr.url, MAX_URL_LENGTH, true);
95
+ const state = pullRequestState(pr.state);
96
+ const closedAt = optionalTimestamp(pr.closedAt);
97
+ const mergedAt = optionalTimestamp(pr.mergedAt);
98
+ const reviewDecision = reviewDecisionValue(pr.reviewDecision);
99
+ const checks = summarizeChecks(pr.statusCheckRollup);
100
+ const expiresAt = terminalExpiry(state, closedAt, mergedAt);
101
+ if (state !== "OPEN" && (expiresAt === undefined || now >= expiresAt)) return undefined;
106
102
 
107
- const presentationState: GithubPrState =
108
- state === "MERGED" ? "merged" : state === "CLOSED" ? "closed" : isDraft ? "draft" : "open";
109
- const checksText = formatChecks(checks);
110
- const review = formatReview(reviewDecision);
111
- const status = compactStatus(presentationState, checks, checksText, review);
112
- const snapshot: GithubPrSnapshot = {
113
- number: String(number),
114
- link: osc8Link(url, `#${number}`),
115
- state: presentationState,
116
- checks: checksText,
117
- review,
118
- status,
119
- ...(expiresAt === undefined ? {} : { expiresAt }),
120
- };
121
- return Object.freeze(snapshot);
122
- } catch {
123
- return undefined;
124
- }
103
+ const presentationState: GithubPrState =
104
+ state === "MERGED" ? "merged" : state === "CLOSED" ? "closed" : isDraft ? "draft" : "open";
105
+ const checksText = formatChecks(checks);
106
+ const review = formatReview(reviewDecision);
107
+ const status = compactStatus(presentationState, checks, checksText, review);
108
+ const snapshot: GithubPrSnapshot = {
109
+ number: String(number),
110
+ link: osc8Link(url, `#${number}`),
111
+ state: presentationState,
112
+ checks: checksText,
113
+ review,
114
+ status,
115
+ ...(expiresAt === undefined ? {} : { expiresAt }),
116
+ };
117
+ return Object.freeze(snapshot);
118
+ } catch {
119
+ return undefined;
120
+ }
125
121
  }
126
122
 
127
123
  export function githubPrSnapshotEqual(
128
- left: GithubPrSnapshot | undefined,
129
- right: GithubPrSnapshot | undefined,
124
+ left: GithubPrSnapshot | undefined,
125
+ right: GithubPrSnapshot | undefined,
130
126
  ): boolean {
131
- return JSON.stringify(left) === JSON.stringify(right);
127
+ return JSON.stringify(left) === JSON.stringify(right);
132
128
  }
133
129
 
134
130
  function terminalExpiry(
135
- state: PullRequestState,
136
- closedAt: number | undefined,
137
- mergedAt: number | undefined,
131
+ state: PullRequestState,
132
+ closedAt: number | undefined,
133
+ mergedAt: number | undefined,
138
134
  ): number | undefined {
139
- if (state === "OPEN") return undefined;
140
- const terminalAt = state === "MERGED" ? mergedAt : closedAt;
141
- return terminalAt === undefined ? undefined : terminalAt + TERMINAL_PR_LIFETIME_MS;
135
+ if (state === "OPEN") return undefined;
136
+ const terminalAt = state === "MERGED" ? mergedAt : closedAt;
137
+ return terminalAt === undefined ? undefined : terminalAt + TERMINAL_PR_LIFETIME_MS;
142
138
  }
143
139
 
144
140
  function summarizeChecks(value: unknown): CheckSummary {
145
- if (!Array.isArray(value) || value.length > MAX_CHECKS) throw new Error("Invalid PR checks");
146
- const summary: CheckSummary = { failed: 0, pending: 0, total: value.length };
147
- for (const item of value) {
148
- const check = record(item);
149
- const state = optionalUppercase(check.state);
150
- const status = optionalUppercase(check.status);
151
- const conclusion = optionalUppercase(check.conclusion);
152
- if (state === "SUCCESS") continue;
153
- if (state === "FAILURE" || state === "ERROR") {
154
- summary.failed += 1;
155
- continue;
156
- }
157
- if (state === "PENDING" || state === "EXPECTED") {
158
- summary.pending += 1;
159
- continue;
160
- }
161
- if (status && status !== "COMPLETED") {
162
- summary.pending += 1;
163
- continue;
164
- }
165
- if (conclusion === "SUCCESS" || conclusion === "SKIPPED" || conclusion === "NEUTRAL") {
166
- continue;
167
- }
168
- if (
169
- conclusion === "FAILURE" ||
170
- conclusion === "CANCELLED" ||
171
- conclusion === "TIMED_OUT" ||
172
- conclusion === "ACTION_REQUIRED" ||
173
- conclusion === "STARTUP_FAILURE"
174
- ) {
175
- summary.failed += 1;
176
- continue;
177
- }
178
- summary.pending += 1;
179
- }
180
- return summary;
141
+ if (!Array.isArray(value) || value.length > MAX_CHECKS) throw new Error("Invalid PR checks");
142
+ const summary: CheckSummary = { failed: 0, pending: 0, total: value.length };
143
+ for (const item of value) {
144
+ const check = record(item);
145
+ const state = optionalUppercase(check.state);
146
+ const status = optionalUppercase(check.status);
147
+ const conclusion = optionalUppercase(check.conclusion);
148
+ if (state === "SUCCESS") continue;
149
+ if (state === "FAILURE" || state === "ERROR") {
150
+ summary.failed += 1;
151
+ continue;
152
+ }
153
+ if (state === "PENDING" || state === "EXPECTED") {
154
+ summary.pending += 1;
155
+ continue;
156
+ }
157
+ if (status && status !== "COMPLETED") {
158
+ summary.pending += 1;
159
+ continue;
160
+ }
161
+ if (conclusion === "SUCCESS" || conclusion === "SKIPPED" || conclusion === "NEUTRAL") {
162
+ continue;
163
+ }
164
+ if (
165
+ conclusion === "FAILURE" ||
166
+ conclusion === "CANCELLED" ||
167
+ conclusion === "TIMED_OUT" ||
168
+ conclusion === "ACTION_REQUIRED" ||
169
+ conclusion === "STARTUP_FAILURE"
170
+ ) {
171
+ summary.failed += 1;
172
+ continue;
173
+ }
174
+ summary.pending += 1;
175
+ }
176
+ return summary;
181
177
  }
182
178
 
183
179
  function formatChecks(checks: CheckSummary): string {
184
- if (checks.total === 0) return "-";
185
- const passed = checks.total - checks.failed - checks.pending;
186
- return [
187
- compactCount("✓", passed),
188
- compactCount("×", checks.failed),
189
- compactCount("…", checks.pending),
190
- ]
191
- .filter(Boolean)
192
- .join(" ");
180
+ if (checks.total === 0) return "-";
181
+ const passed = checks.total - checks.failed - checks.pending;
182
+ return [compactCount("✓", passed), compactCount("×", checks.failed), compactCount("…", checks.pending)]
183
+ .filter(Boolean)
184
+ .join(" ");
193
185
  }
194
186
 
195
187
  function compactCount(symbol: string, count: number): string {
196
- return count > 0 ? `${symbol}${count}` : "";
188
+ return count > 0 ? `${symbol}${count}` : "";
197
189
  }
198
190
 
199
191
  function formatReview(review: ReviewDecision): string {
200
- if (review === "APPROVED") return "R✓";
201
- if (review === "CHANGES_REQUESTED") return "R×";
202
- if (review === "REVIEW_REQUIRED") return "R?";
203
- return "";
192
+ if (review === "APPROVED") return "R✓";
193
+ if (review === "CHANGES_REQUESTED") return "R×";
194
+ if (review === "REVIEW_REQUIRED") return "R?";
195
+ return "";
204
196
  }
205
197
 
206
- function compactStatus(
207
- state: GithubPrState,
208
- checks: CheckSummary,
209
- checksText: string,
210
- review: string,
211
- ): string {
212
- if (state === "merged") return "M";
213
- if (state === "closed") return "C";
214
- if (state === "draft") return "D";
215
- if (checks.failed > 0) return compactCount("×", checks.failed);
216
- if (review === "R×") return review;
217
- if (checks.pending > 0) return compactCount("…", checks.pending);
218
- if (review === "R✓" || review === "R?") return review;
219
- return checksText;
198
+ function compactStatus(state: GithubPrState, checks: CheckSummary, checksText: string, review: string): string {
199
+ if (state === "merged") return "M";
200
+ if (state === "closed") return "C";
201
+ if (state === "draft") return "D";
202
+ if (checks.failed > 0) return compactCount("×", checks.failed);
203
+ if (review === "R×") return review;
204
+ if (checks.pending > 0) return compactCount("…", checks.pending);
205
+ if (review === "R✓" || review === "R?") return review;
206
+ return checksText;
220
207
  }
221
208
 
222
209
  function osc8Link(value: string, label: string): string {
223
- if (!getCapabilities().hyperlinks || hasTerminalControls(value)) return label;
224
- try {
225
- const url = new URL(value);
226
- if ((url.protocol !== "http:" && url.protocol !== "https:") || url.username || url.password) {
227
- return label;
228
- }
229
- const normalized = url.toString();
230
- if (normalized.length > MAX_URL_LENGTH || hasTerminalControls(normalized)) return label;
231
- return `\u001b]8;;${normalized}\u0007${label}\u001b]8;;\u0007`;
232
- } catch {
233
- return label;
234
- }
210
+ if (!getCapabilities().hyperlinks || hasTerminalControls(value)) return label;
211
+ try {
212
+ const url = new URL(value);
213
+ if ((url.protocol !== "http:" && url.protocol !== "https:") || url.username || url.password) {
214
+ return label;
215
+ }
216
+ const normalized = url.toString();
217
+ if (normalized.length > MAX_URL_LENGTH || hasTerminalControls(normalized)) return label;
218
+ return `\u001b]8;;${normalized}\u0007${label}\u001b]8;;\u0007`;
219
+ } catch {
220
+ return label;
221
+ }
235
222
  }
236
223
 
237
224
  function hasTerminalControls(value: string): boolean {
238
- return Array.from(value).some((character) => {
239
- const codePoint = character.codePointAt(0) ?? 0;
240
- return (
241
- codePoint <= 0x1f ||
242
- (codePoint >= 0x7f && codePoint <= 0x9f) ||
243
- (codePoint >= 0xd800 && codePoint <= 0xdfff)
244
- );
245
- });
225
+ return Array.from(value).some((character) => {
226
+ const codePoint = character.codePointAt(0) ?? 0;
227
+ return (
228
+ codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f) || (codePoint >= 0xd800 && codePoint <= 0xdfff)
229
+ );
230
+ });
246
231
  }
247
232
 
248
233
  function record(value: unknown): Record<string, unknown> {
249
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
250
- throw new Error("Expected PR object");
251
- }
252
- return value as Record<string, unknown>;
234
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
235
+ throw new Error("Expected PR object");
236
+ }
237
+ return value as Record<string, unknown>;
253
238
  }
254
239
 
255
240
  function positiveInteger(value: unknown): number {
256
- if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) {
257
- throw new Error("Invalid PR number");
258
- }
259
- return value;
241
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) {
242
+ throw new Error("Invalid PR number");
243
+ }
244
+ return value;
260
245
  }
261
246
 
262
247
  function requiredBoolean(value: unknown): boolean {
263
- if (typeof value !== "boolean") throw new Error("Invalid PR boolean");
264
- return value;
248
+ if (typeof value !== "boolean") throw new Error("Invalid PR boolean");
249
+ return value;
265
250
  }
266
251
 
267
252
  function requiredBoundedString(value: unknown, maxLength: number, allowEmpty = false): string {
268
- if (
269
- typeof value !== "string" ||
270
- value.length > maxLength ||
271
- (!allowEmpty && value.length === 0)
272
- ) {
273
- throw new Error("Invalid PR string");
274
- }
275
- return value;
253
+ if (typeof value !== "string" || value.length > maxLength || (!allowEmpty && value.length === 0)) {
254
+ throw new Error("Invalid PR string");
255
+ }
256
+ return value;
276
257
  }
277
258
 
278
259
  function optionalUppercase(value: unknown): string | undefined {
279
- if (value === null || value === undefined || value === "") return undefined;
280
- return requiredBoundedString(value, MAX_FIELD_LENGTH).toUpperCase();
260
+ if (value === null || value === undefined || value === "") return undefined;
261
+ return requiredBoundedString(value, MAX_FIELD_LENGTH).toUpperCase();
281
262
  }
282
263
 
283
264
  function optionalTimestamp(value: unknown): number | undefined {
284
- if (value === null || value === undefined || value === "") return undefined;
285
- const text = requiredBoundedString(value, MAX_FIELD_LENGTH);
286
- const match = RFC3339_TIMESTAMP.exec(text);
287
- if (!match) throw new Error("Invalid PR timestamp");
288
- const [
289
- ,
290
- yearText,
291
- monthText,
292
- dayText,
293
- hourText,
294
- minuteText,
295
- secondText,
296
- offsetHourText,
297
- offsetMinuteText,
298
- ] = match;
299
- const year = Number(yearText);
300
- const month = Number(monthText);
301
- const day = Number(dayText);
302
- const hour = Number(hourText);
303
- const minute = Number(minuteText);
304
- const second = Number(secondText);
305
- const offsetHour = Number(offsetHourText ?? 0);
306
- const offsetMinute = Number(offsetMinuteText ?? 0);
307
- if (
308
- month < 1 ||
309
- month > 12 ||
310
- day < 1 ||
311
- day > daysInMonth(year, month) ||
312
- hour > 23 ||
313
- minute > 59 ||
314
- second > 59 ||
315
- offsetHour > 23 ||
316
- offsetMinute > 59
317
- ) {
318
- throw new Error("Invalid PR timestamp");
319
- }
320
- const timestamp = Date.parse(text);
321
- if (!Number.isFinite(timestamp)) throw new Error("Invalid PR timestamp");
322
- return timestamp;
265
+ if (value === null || value === undefined || value === "") return undefined;
266
+ const text = requiredBoundedString(value, MAX_FIELD_LENGTH);
267
+ const match = RFC3339_TIMESTAMP.exec(text);
268
+ if (!match) throw new Error("Invalid PR timestamp");
269
+ const [, yearText, monthText, dayText, hourText, minuteText, secondText, offsetHourText, offsetMinuteText] = match;
270
+ const year = Number(yearText);
271
+ const month = Number(monthText);
272
+ const day = Number(dayText);
273
+ const hour = Number(hourText);
274
+ const minute = Number(minuteText);
275
+ const second = Number(secondText);
276
+ const offsetHour = Number(offsetHourText ?? 0);
277
+ const offsetMinute = Number(offsetMinuteText ?? 0);
278
+ if (
279
+ month < 1 ||
280
+ month > 12 ||
281
+ day < 1 ||
282
+ day > daysInMonth(year, month) ||
283
+ hour > 23 ||
284
+ minute > 59 ||
285
+ second > 59 ||
286
+ offsetHour > 23 ||
287
+ offsetMinute > 59
288
+ ) {
289
+ throw new Error("Invalid PR timestamp");
290
+ }
291
+ const timestamp = Date.parse(text);
292
+ if (!Number.isFinite(timestamp)) throw new Error("Invalid PR timestamp");
293
+ return timestamp;
323
294
  }
324
295
 
325
296
  function daysInMonth(year: number, month: number): number {
326
- if (month === 2) {
327
- const leapYear = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
328
- return leapYear ? 29 : 28;
329
- }
330
- return month === 4 || month === 6 || month === 9 || month === 11 ? 30 : 31;
297
+ if (month === 2) {
298
+ const leapYear = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
299
+ return leapYear ? 29 : 28;
300
+ }
301
+ return month === 4 || month === 6 || month === 9 || month === 11 ? 30 : 31;
331
302
  }
332
303
 
333
304
  function pullRequestState(value: unknown): PullRequestState {
334
- if (value === "OPEN" || value === "CLOSED" || value === "MERGED") return value;
335
- throw new Error("Invalid PR state");
305
+ if (value === "OPEN" || value === "CLOSED" || value === "MERGED") return value;
306
+ throw new Error("Invalid PR state");
336
307
  }
337
308
 
338
309
  function reviewDecisionValue(value: unknown): ReviewDecision {
339
- if (value === null || value === undefined || value === "" || value === "UNKNOWN") return "";
340
- if (value === "APPROVED" || value === "CHANGES_REQUESTED" || value === "REVIEW_REQUIRED") {
341
- return value;
342
- }
343
- throw new Error("Invalid PR review decision");
310
+ if (value === null || value === undefined || value === "" || value === "UNKNOWN") return "";
311
+ if (value === "APPROVED" || value === "CHANGES_REQUESTED" || value === "REVIEW_REQUIRED") {
312
+ return value;
313
+ }
314
+ throw new Error("Invalid PR review decision");
344
315
  }