@gakr-gakr/codex 0.1.0 → 0.1.1

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 (115) hide show
  1. package/dist/client-DNN2uyJW.js +642 -0
  2. package/dist/client-factory-Bu9OClHJ.js +9 -0
  3. package/dist/command-formatters-BpPOTePl.js +520 -0
  4. package/dist/command-handlers-BBs7Vws9.js +1533 -0
  5. package/dist/compact-CDboBy7o.js +329 -0
  6. package/dist/computer-use-DCZB46Sw.js +367 -0
  7. package/dist/config-CLMSw0p2.js +510 -0
  8. package/dist/doctor-contract-api.js +53 -0
  9. package/dist/harness.js +51 -0
  10. package/dist/index.js +1171 -0
  11. package/dist/media-understanding-provider.js +335 -0
  12. package/dist/models-jLA2SIvd.js +110 -0
  13. package/dist/node-cli-sessions-BLRDs_US.js +1216 -0
  14. package/dist/plugin-activation-CEy_oYpx.js +452 -0
  15. package/dist/prompt-overlay.js +12 -0
  16. package/dist/protocol-C9UWI98H.js +9 -0
  17. package/dist/protocol-validators-BGBspNmF.js +5988 -0
  18. package/dist/provider-catalog.js +84 -0
  19. package/dist/provider-discovery.js +33 -0
  20. package/dist/provider.js +150 -0
  21. package/dist/rate-limit-cache-9LxQdE0K.js +24 -0
  22. package/dist/request-DbSPeTcV.js +89 -0
  23. package/dist/rolldown-runtime-DUslC3ob.js +14 -0
  24. package/dist/run-attempt-BoEwzQCv.js +5463 -0
  25. package/dist/session-binding-e2GFp9VH.js +222 -0
  26. package/dist/shared-client-D7Vy0glq.js +631 -0
  27. package/dist/side-question-BDLuEzFP.js +668 -0
  28. package/dist/test-api.js +49 -0
  29. package/dist/thread-lifecycle-Clo0EHMk.js +1565 -0
  30. package/dist/vision-tools-Cofrv35p.js +1379 -0
  31. package/package.json +16 -1
  32. package/doctor-contract-api.ts +0 -68
  33. package/harness.ts +0 -72
  34. package/index.ts +0 -124
  35. package/media-understanding-provider.ts +0 -521
  36. package/prompt-overlay.ts +0 -21
  37. package/provider-catalog.ts +0 -83
  38. package/provider-discovery.ts +0 -45
  39. package/provider.ts +0 -243
  40. package/src/app-server/app-inventory-cache.ts +0 -324
  41. package/src/app-server/approval-bridge.ts +0 -1211
  42. package/src/app-server/auth-bridge.ts +0 -614
  43. package/src/app-server/capabilities.ts +0 -27
  44. package/src/app-server/client-factory.ts +0 -24
  45. package/src/app-server/client.ts +0 -715
  46. package/src/app-server/compact.ts +0 -512
  47. package/src/app-server/computer-use.ts +0 -683
  48. package/src/app-server/config.ts +0 -1038
  49. package/src/app-server/context-engine-projection.ts +0 -403
  50. package/src/app-server/dynamic-tool-diagnostics.ts +0 -73
  51. package/src/app-server/dynamic-tool-profile.ts +0 -70
  52. package/src/app-server/dynamic-tools.ts +0 -623
  53. package/src/app-server/elicitation-bridge.ts +0 -783
  54. package/src/app-server/event-projector.ts +0 -2065
  55. package/src/app-server/image-payload-sanitizer.ts +0 -167
  56. package/src/app-server/local-runtime-attribution.ts +0 -39
  57. package/src/app-server/managed-binary.ts +0 -193
  58. package/src/app-server/models.ts +0 -172
  59. package/src/app-server/native-hook-relay.ts +0 -150
  60. package/src/app-server/native-subagent-task-mirror.ts +0 -497
  61. package/src/app-server/plugin-activation.ts +0 -283
  62. package/src/app-server/plugin-app-cache-key.ts +0 -74
  63. package/src/app-server/plugin-approval-roundtrip.ts +0 -122
  64. package/src/app-server/plugin-inventory.ts +0 -357
  65. package/src/app-server/plugin-thread-config.ts +0 -455
  66. package/src/app-server/protocol-generated/json/DynamicToolCallParams.json +0 -33
  67. package/src/app-server/protocol-generated/json/v2/ErrorNotification.json +0 -199
  68. package/src/app-server/protocol-generated/json/v2/GetAccountResponse.json +0 -102
  69. package/src/app-server/protocol-generated/json/v2/ModelListResponse.json +0 -227
  70. package/src/app-server/protocol-generated/json/v2/ThreadResumeResponse.json +0 -2630
  71. package/src/app-server/protocol-generated/json/v2/ThreadStartResponse.json +0 -2630
  72. package/src/app-server/protocol-generated/json/v2/TurnCompletedNotification.json +0 -1659
  73. package/src/app-server/protocol-generated/json/v2/TurnStartResponse.json +0 -1655
  74. package/src/app-server/protocol-validators.ts +0 -203
  75. package/src/app-server/protocol.ts +0 -520
  76. package/src/app-server/rate-limit-cache.ts +0 -48
  77. package/src/app-server/rate-limits.ts +0 -583
  78. package/src/app-server/request.ts +0 -73
  79. package/src/app-server/run-attempt.ts +0 -4862
  80. package/src/app-server/session-binding.ts +0 -398
  81. package/src/app-server/session-history.ts +0 -44
  82. package/src/app-server/shared-client.ts +0 -289
  83. package/src/app-server/side-question.ts +0 -1009
  84. package/src/app-server/test-support.ts +0 -48
  85. package/src/app-server/thread-lifecycle.ts +0 -959
  86. package/src/app-server/timeout.ts +0 -9
  87. package/src/app-server/tool-progress-normalization.ts +0 -77
  88. package/src/app-server/trajectory.ts +0 -368
  89. package/src/app-server/transcript-mirror.ts +0 -208
  90. package/src/app-server/transport-stdio.ts +0 -107
  91. package/src/app-server/transport-websocket.ts +0 -90
  92. package/src/app-server/transport.ts +0 -117
  93. package/src/app-server/user-input-bridge.ts +0 -316
  94. package/src/app-server/version.ts +0 -4
  95. package/src/app-server/vision-tools.ts +0 -12
  96. package/src/command-account.ts +0 -544
  97. package/src/command-formatters.ts +0 -426
  98. package/src/command-handlers.ts +0 -2021
  99. package/src/command-plugins-management.ts +0 -137
  100. package/src/command-rpc.ts +0 -142
  101. package/src/commands.ts +0 -65
  102. package/src/conversation-binding-data.ts +0 -124
  103. package/src/conversation-binding.ts +0 -561
  104. package/src/conversation-control.ts +0 -303
  105. package/src/conversation-turn-collector.ts +0 -186
  106. package/src/conversation-turn-input.ts +0 -106
  107. package/src/migration/apply.ts +0 -501
  108. package/src/migration/helpers.ts +0 -55
  109. package/src/migration/plan.ts +0 -461
  110. package/src/migration/provider.ts +0 -41
  111. package/src/migration/source.ts +0 -643
  112. package/src/migration/targets.ts +0 -25
  113. package/src/node-cli-sessions.ts +0 -711
  114. package/test-api.ts +0 -95
  115. package/tsconfig.json +0 -16
@@ -0,0 +1,520 @@
1
+ import { t as isJsonObject } from "./protocol-C9UWI98H.js";
2
+ //#region extensions/codex/src/app-server/rate-limits.ts
3
+ const CODEX_LIMIT_ID = "codex";
4
+ const LIMIT_WINDOW_KEYS = ["primary", "secondary"];
5
+ const ONE_SECOND_MS = 1e3;
6
+ const ONE_MINUTE_MS = 6e4;
7
+ const ONE_HOUR_MS = 60 * ONE_MINUTE_MS;
8
+ const ONE_DAY_MS = 24 * ONE_HOUR_MS;
9
+ function formatCodexUsageLimitErrorMessage(params) {
10
+ const message = normalizeText(params.message);
11
+ if (!isCodexUsageLimitError(params.codexErrorInfo, message)) return;
12
+ const nowMs = params.nowMs ?? Date.now();
13
+ const nextReset = selectNextRateLimitReset(params.rateLimits, nowMs);
14
+ const parts = ["You've reached your Codex subscription usage limit."];
15
+ if (nextReset) parts.push(`Next reset ${formatResetTime(nextReset.resetsAtMs, nowMs)}.`);
16
+ else {
17
+ const codexRetryHint = extractCodexRetryHint(message);
18
+ if (codexRetryHint) parts.push(`Codex says to try again ${codexRetryHint}.`);
19
+ else parts.push("Codex did not return a reset time for this limit.");
20
+ }
21
+ parts.push("Run /codex account for current usage details.");
22
+ return parts.join(" ");
23
+ }
24
+ function shouldRefreshCodexRateLimitsForUsageLimitMessage(message) {
25
+ const text = normalizeText(message);
26
+ return Boolean(text?.includes("You've reached your Codex subscription usage limit.") && !text.includes("Next reset "));
27
+ }
28
+ function summarizeCodexRateLimits(value, nowMs = Date.now()) {
29
+ const snapshots = collectCodexRateLimitSnapshots(value).filter(snapshotHasDisplayableData);
30
+ if (snapshots.length === 0) return;
31
+ const summaries = snapshots.slice(0, 4).map((snapshot) => summarizeRateLimitSnapshot(snapshot, nowMs)).filter((summary) => summary !== void 0);
32
+ return summaries.length > 0 ? summaries.join("; ") : void 0;
33
+ }
34
+ function hasCodexRateLimitSnapshots(value) {
35
+ return collectCodexRateLimitSnapshots(value).length > 0;
36
+ }
37
+ function summarizeCodexAccountRateLimits(value, nowMs = Date.now()) {
38
+ const summary = summarizeCodexAccountUsage(value, nowMs);
39
+ if (!summary) return;
40
+ if (!summary.blocked) return ["Codex is available."];
41
+ return [summary.blockedUntilText ? `Codex is paused until ${summary.blockedUntilText}.` : "Codex is paused by a usage limit.", summary.blockingReason ? `Your ${summary.blockingReason}.` : "Your Codex usage limit is reached."];
42
+ }
43
+ function resolveCodexUsageLimitResetAtMs(value, nowMs = Date.now()) {
44
+ return selectBlockingRateLimitReset(value, nowMs)?.resetsAtMs;
45
+ }
46
+ function summarizeCodexAccountUsage(value, nowMs = Date.now()) {
47
+ const snapshots = collectCodexRateLimitSnapshots(value).filter(snapshotHasDisplayableData);
48
+ if (snapshots.length === 0) return;
49
+ const usageSnapshot = snapshots.find(isCodexLimitSnapshot) ?? snapshots[0];
50
+ const blockedSnapshots = snapshots.filter(snapshotHasLimitBlock);
51
+ const blockingSnapshot = blockedSnapshots.find(isCodexLimitSnapshot) ?? blockedSnapshots[0] ?? void 0;
52
+ const blockingReset = blockingSnapshot ? selectSnapshotBlockingReset(blockingSnapshot, nowMs) : void 0;
53
+ const blockingPeriod = formatBlockingLimitPeriod(blockingReset?.windowDurationMins);
54
+ const blockedUntilText = blockingReset ? formatAccountResetTime(blockingReset.resetsAtMs, nowMs) : void 0;
55
+ const blockedResetRelative = blockingReset ? `in ${formatRelativeDuration(blockingReset.resetsAtMs - nowMs)}` : void 0;
56
+ const blockingReason = blockingPeriod ? `${blockingPeriod} Codex usage limit is reached` : blockingSnapshot ? "Codex usage limit is reached" : void 0;
57
+ return {
58
+ usageLine: formatUsageLine(usageSnapshot),
59
+ blocked: Boolean(blockingSnapshot),
60
+ ...blockingReset ? { blockedUntilMs: blockingReset.resetsAtMs } : {},
61
+ ...blockedUntilText ? { blockedUntilText } : {},
62
+ ...blockedResetRelative ? { blockedResetRelative } : {},
63
+ ...blockingPeriod ? { blockingPeriod } : {},
64
+ ...blockingReason ? { blockingReason } : {}
65
+ };
66
+ }
67
+ function isCodexUsageLimitError(codexErrorInfo, message) {
68
+ if (codexErrorInfo === "usageLimitExceeded") return true;
69
+ if (typeof codexErrorInfo === "string") {
70
+ if (codexErrorInfo.replace(/[_\s-]/gu, "").toLowerCase() === "usagelimitexceeded") return true;
71
+ }
72
+ return Boolean(message?.toLowerCase().includes("usage limit"));
73
+ }
74
+ function selectNextRateLimitReset(value, nowMs) {
75
+ const futureWindows = collectCodexRateLimitSnapshots(value).flatMap((snapshot) => LIMIT_WINDOW_KEYS.flatMap((key) => readRateLimitWindow(snapshot, key) ?? [])).filter((window) => window.resetsAtMs > nowMs);
76
+ if (futureWindows.length === 0) return;
77
+ const exhaustedWindows = futureWindows.filter((window) => window.usedPercent !== void 0 && window.usedPercent >= 100);
78
+ return (exhaustedWindows.length > 0 ? exhaustedWindows : futureWindows).toSorted((left, right) => left.resetsAtMs - right.resetsAtMs)[0];
79
+ }
80
+ function selectBlockingRateLimitReset(value, nowMs) {
81
+ const blockedSnapshots = collectCodexRateLimitSnapshots(value).filter(snapshotHasLimitBlock);
82
+ const blockingSnapshot = blockedSnapshots.find(isCodexLimitSnapshot) ?? blockedSnapshots[0] ?? void 0;
83
+ return blockingSnapshot ? selectSnapshotBlockingReset(blockingSnapshot, nowMs) : void 0;
84
+ }
85
+ function summarizeRateLimitSnapshot(snapshot, nowMs) {
86
+ const label = formatLimitLabel(snapshot);
87
+ const windows = LIMIT_WINDOW_KEYS.flatMap((key) => {
88
+ const window = readRateLimitWindow(snapshot, key);
89
+ return window ? [formatRateLimitWindow(key, window, nowMs)] : [];
90
+ });
91
+ const reachedType = readString$1(snapshot, "rateLimitReachedType") ?? readString$1(snapshot, "rate_limit_reached_type");
92
+ const suffix = reachedType ? ` (${formatReachedType(reachedType)})` : "";
93
+ if (windows.length > 0) return `${label}: ${windows.join(" · ")}${suffix}`;
94
+ if (reachedType) return `${label}: ${formatReachedType(reachedType)}`;
95
+ }
96
+ function collectCodexRateLimitSnapshots(value) {
97
+ const snapshots = [];
98
+ collectRateLimitSnapshots(value, snapshots, /* @__PURE__ */ new Set());
99
+ return snapshots;
100
+ }
101
+ function collectRateLimitSnapshots(value, snapshots, seen) {
102
+ if (Array.isArray(value)) {
103
+ for (const entry of value) collectRateLimitSnapshots(entry, snapshots, seen);
104
+ return;
105
+ }
106
+ if (!isJsonObject(value)) return;
107
+ if (isRateLimitSnapshot(value)) {
108
+ addRateLimitSnapshot(value, snapshots, seen);
109
+ return;
110
+ }
111
+ const byLimitId = value.rateLimitsByLimitId;
112
+ if (isJsonObject(byLimitId)) for (const key of sortedRateLimitKeys(Object.keys(byLimitId))) collectRateLimitSnapshots(byLimitId[key], snapshots, seen);
113
+ const snakeByLimitId = value.rate_limits_by_limit_id;
114
+ if (isJsonObject(snakeByLimitId)) for (const key of sortedRateLimitKeys(Object.keys(snakeByLimitId))) collectRateLimitSnapshots(snakeByLimitId[key], snapshots, seen);
115
+ collectRateLimitSnapshots(value.rateLimits, snapshots, seen);
116
+ collectRateLimitSnapshots(value.rate_limits, snapshots, seen);
117
+ collectRateLimitSnapshots(value.data, snapshots, seen);
118
+ collectRateLimitSnapshots(value.items, snapshots, seen);
119
+ }
120
+ function sortedRateLimitKeys(keys) {
121
+ return keys.toSorted((left, right) => {
122
+ if (left === CODEX_LIMIT_ID) return -1;
123
+ if (right === CODEX_LIMIT_ID) return 1;
124
+ return left.localeCompare(right);
125
+ });
126
+ }
127
+ function addRateLimitSnapshot(snapshot, snapshots, seen) {
128
+ const signature = [
129
+ readNullableString(snapshot, "limitId") ?? readNullableString(snapshot, "limit_id") ?? "",
130
+ readNullableString(snapshot, "limitName") ?? readNullableString(snapshot, "limit_name") ?? "",
131
+ formatWindowSignature(snapshot.primary),
132
+ formatWindowSignature(snapshot.secondary)
133
+ ].join("|");
134
+ if (seen.has(signature)) return;
135
+ seen.add(signature);
136
+ snapshots.push(snapshot);
137
+ }
138
+ function isRateLimitSnapshot(value) {
139
+ return isJsonObject(value.primary) || isJsonObject(value.secondary) || value.rateLimitReachedType !== void 0 || value.rate_limit_reached_type !== void 0 || value.limitId !== void 0 || value.limit_id !== void 0 || value.limitName !== void 0 || value.limit_name !== void 0;
140
+ }
141
+ function readRateLimitWindow(snapshot, key) {
142
+ const window = snapshot[key];
143
+ if (!isJsonObject(window)) return;
144
+ const resetsAt = readNumber(window, "resetsAt") ?? readNumber(window, "resets_at");
145
+ return {
146
+ ...typeof resetsAt === "number" && Number.isFinite(resetsAt) && resetsAt > 0 ? { resetsAtMs: resetsAt * 1e3 } : { resetsAtMs: 0 },
147
+ ...readOptionalNumberField(window, "usedPercent", "used_percent"),
148
+ ...readOptionalNumberField(window, "windowDurationMins", "window_duration_mins", "windowMinutes", "window_minutes")
149
+ };
150
+ }
151
+ function snapshotHasDisplayableData(snapshot) {
152
+ if (readString$1(snapshot, "rateLimitReachedType") ?? readString$1(snapshot, "rate_limit_reached_type")) return true;
153
+ return readWindowEntries(snapshot).some((entry) => entry.window.usedPercent !== void 0 || entry.window.resetsAtMs > 0);
154
+ }
155
+ function readOptionalNumberField(record, ...keys) {
156
+ const value = keys.map((key) => readNumber(record, key)).find((entry) => entry !== void 0);
157
+ if (value === void 0) return {};
158
+ return keys.some((key) => key.toLowerCase().includes("window")) ? { windowDurationMins: value } : { usedPercent: value };
159
+ }
160
+ function formatRateLimitWindow(key, window, nowMs) {
161
+ return `${key} ${formatRateLimitWindowDetails(window, nowMs)}`;
162
+ }
163
+ function formatRateLimitWindowDetails(window, nowMs) {
164
+ return `${window.usedPercent === void 0 ? "usage unknown" : `${Math.max(0, 100 - Math.round(window.usedPercent))}% left`}${window.resetsAtMs > nowMs ? ` ⏱${formatResetDuration(window.resetsAtMs, nowMs)}` : ""}`;
165
+ }
166
+ function formatLimitLabel(snapshot) {
167
+ const label = readNullableString(snapshot, "limitName") ?? readNullableString(snapshot, "limit_name") ?? readNullableString(snapshot, "limitId") ?? readNullableString(snapshot, "limit_id");
168
+ if (!label || label === CODEX_LIMIT_ID) return "Codex";
169
+ return label.replace(/[_-]+/gu, " ").replace(/\s+/gu, " ").trim();
170
+ }
171
+ function formatReachedType(value) {
172
+ return value.replace(/[_-]+/gu, " ").replace(/\s+/gu, " ").trim();
173
+ }
174
+ function formatResetTime(resetsAtMs, nowMs) {
175
+ return `in ${formatRelativeDuration(resetsAtMs - nowMs)}, ${formatCalendarResetTime(resetsAtMs, nowMs)}`;
176
+ }
177
+ function formatAccountResetTime(resetsAtMs, nowMs) {
178
+ return `${formatCalendarResetTime(resetsAtMs, nowMs)} (in ${formatRelativeDuration(resetsAtMs - nowMs)})`;
179
+ }
180
+ function snapshotHasLimitBlock(snapshot) {
181
+ return Boolean(readString$1(snapshot, "rateLimitReachedType") ?? readString$1(snapshot, "rate_limit_reached_type") ?? readWindowEntries(snapshot).some((entry) => entry.window.usedPercent !== void 0 && entry.window.usedPercent >= 100));
182
+ }
183
+ function isCodexLimitSnapshot(snapshot) {
184
+ const id = readNullableString(snapshot, "limitId") ?? readNullableString(snapshot, "limit_id");
185
+ return !id || id === CODEX_LIMIT_ID;
186
+ }
187
+ function selectSnapshotBlockingReset(snapshot, nowMs) {
188
+ const futureWindows = readWindowEntries(snapshot).map((entry) => entry.window).filter((window) => window.resetsAtMs > nowMs);
189
+ const exhaustedWindows = futureWindows.filter((window) => window.usedPercent !== void 0 && window.usedPercent >= 100);
190
+ const candidates = exhaustedWindows.length > 0 ? exhaustedWindows : futureWindows;
191
+ const resetSort = exhaustedWindows.length > 0 ? (left, right) => right.resetsAtMs - left.resetsAtMs : (left, right) => left.resetsAtMs - right.resetsAtMs;
192
+ return candidates.toSorted(resetSort)[0];
193
+ }
194
+ function readWindowEntries(snapshot) {
195
+ return LIMIT_WINDOW_KEYS.flatMap((key) => {
196
+ const window = readRateLimitWindow(snapshot, key);
197
+ return window ? [{
198
+ key,
199
+ window
200
+ }] : [];
201
+ });
202
+ }
203
+ function formatBlockingLimitPeriod(minutes) {
204
+ if (minutes === 10080) return "weekly";
205
+ if (minutes === 1440) return "daily";
206
+ if (minutes !== void 0 && minutes > 0 && minutes < 1440) return "short-term";
207
+ }
208
+ function formatUsageLine(snapshot) {
209
+ const windows = readWindowEntries(snapshot).filter((entry) => entry.window.usedPercent !== void 0).toSorted((left, right) => (right.window.windowDurationMins ?? 0) - (left.window.windowDurationMins ?? 0)).map((entry) => {
210
+ return `${formatUsageWindowLabel(entry.window.windowDurationMins)} ${Math.round(entry.window.usedPercent ?? 0)}%`;
211
+ });
212
+ return windows.length > 0 ? windows.join(" · ") : void 0;
213
+ }
214
+ function formatUsageWindowLabel(minutes) {
215
+ if (minutes === 10080) return "weekly";
216
+ if (minutes === 1440) return "daily";
217
+ if (minutes !== void 0 && minutes > 0 && minutes < 1440) return "short-term";
218
+ if (minutes !== void 0 && minutes > 0 && minutes % 1440 === 0) return `${minutes / 1440}-day`;
219
+ if (minutes !== void 0 && minutes > 0 && minutes % 60 === 0) return `${minutes / 60}-hour`;
220
+ return "usage";
221
+ }
222
+ function formatCalendarResetTime(resetsAtMs, nowMs) {
223
+ const resetDate = new Date(resetsAtMs);
224
+ const resetParts = new Intl.DateTimeFormat("en-US", {
225
+ month: "short",
226
+ day: "numeric",
227
+ ...resetDate.getFullYear() === new Date(nowMs).getFullYear() ? {} : { year: "numeric" },
228
+ hour: "numeric",
229
+ minute: "2-digit",
230
+ timeZoneName: "short"
231
+ }).formatToParts(resetDate);
232
+ const part = (type) => resetParts.find((entry) => entry.type === type)?.value;
233
+ const dateParts = [
234
+ part("month"),
235
+ part("day"),
236
+ part("year")
237
+ ].filter(Boolean);
238
+ return [
239
+ dateParts.length > 1 ? `${dateParts[0]} ${dateParts.slice(1).join(", ")}` : dateParts[0],
240
+ "at",
241
+ [
242
+ [part("hour"), part("minute")].filter(Boolean).join(":"),
243
+ part("dayPeriod"),
244
+ part("timeZoneName")
245
+ ].filter(Boolean).join(" ")
246
+ ].filter(Boolean).join(" ");
247
+ }
248
+ function formatRelativeDuration(durationMs) {
249
+ const safeMs = Math.max(1e3, durationMs);
250
+ if (safeMs < ONE_MINUTE_MS) return `${Math.ceil(safeMs / 1e3)} seconds`;
251
+ if (safeMs < ONE_HOUR_MS) {
252
+ const minutes = Math.ceil(safeMs / ONE_MINUTE_MS);
253
+ return `${minutes} ${minutes === 1 ? "minute" : "minutes"}`;
254
+ }
255
+ if (safeMs < ONE_DAY_MS) {
256
+ const hours = Math.ceil(safeMs / ONE_HOUR_MS);
257
+ return `${hours} ${hours === 1 ? "hour" : "hours"}`;
258
+ }
259
+ const days = Math.ceil(safeMs / ONE_DAY_MS);
260
+ return `${days} ${days === 1 ? "day" : "days"}`;
261
+ }
262
+ function formatResetDuration(resetsAtMs, nowMs) {
263
+ const durationMs = Math.round(Math.max(ONE_SECOND_MS, resetsAtMs - nowMs) / ONE_SECOND_MS) * ONE_SECOND_MS;
264
+ const days = Math.floor(durationMs / ONE_DAY_MS);
265
+ const hours = Math.floor(durationMs % ONE_DAY_MS / ONE_HOUR_MS);
266
+ const minutes = Math.floor(durationMs % ONE_HOUR_MS / ONE_MINUTE_MS);
267
+ const seconds = Math.floor(durationMs % ONE_MINUTE_MS / ONE_SECOND_MS);
268
+ if (days > 0) return hours > 0 ? `${days}d ${hours}h` : `${days}d`;
269
+ if (hours > 0) return minutes > 0 ? `${hours}h ${minutes}m` : `${hours}h`;
270
+ if (minutes > 0) return seconds > 0 ? `${minutes}m ${seconds}s` : `${minutes}m`;
271
+ return `${seconds}s`;
272
+ }
273
+ function formatWindowSignature(value) {
274
+ if (!isJsonObject(value)) return "";
275
+ return `${readNumber(value, "usedPercent") ?? readNumber(value, "used_percent") ?? ""}:${readNumber(value, "resetsAt") ?? readNumber(value, "resets_at") ?? ""}`;
276
+ }
277
+ function extractCodexRetryHint(message) {
278
+ if (!message) return;
279
+ const tryAgainAt = /\btry again\s+(at\s+[^.!?\n]+)(?:[.!?]|$)/iu.exec(message);
280
+ if (tryAgainAt?.[1]) return tryAgainAt[1].trim();
281
+ return /\btry again\s+((?:tomorrow|in\s+[^.!?\n]+)[^.!?\n]*)(?:[.!?]|$)/iu.exec(message)?.[1]?.trim();
282
+ }
283
+ function readString$1(record, key) {
284
+ const value = record[key];
285
+ return typeof value === "string" && value.trim() ? value.trim() : void 0;
286
+ }
287
+ function readNullableString(record, key) {
288
+ return readString$1(record, key) ?? void 0;
289
+ }
290
+ function readNumber(record, key) {
291
+ const value = record[key];
292
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
293
+ }
294
+ function normalizeText(value) {
295
+ const text = value?.trim();
296
+ return text ? text : void 0;
297
+ }
298
+ //#endregion
299
+ //#region extensions/codex/src/command-formatters.ts
300
+ function formatCodexStatus(probes) {
301
+ const lines = [`Codex app-server: ${probes.models.ok || probes.account.ok || probes.limits.ok || probes.mcps.ok || probes.skills.ok ? "connected" : "unavailable"}`];
302
+ if (probes.models.ok) lines.push(`Models: ${probes.models.value.models.map((model) => formatCodexDisplayText(model.id)).slice(0, 8).join(", ") || "none"}`);
303
+ else lines.push(`Models: ${formatCodexDisplayText(probes.models.error)}`);
304
+ lines.push(`Account: ${probes.account.ok ? formatCodexAccountSummary(probes.account.value) : formatCodexDisplayText(probes.account.error)}`);
305
+ lines.push(`Rate limits: ${probes.limits.ok ? formatCodexRateLimitSummary(probes.limits.value) : formatCodexDisplayText(probes.limits.error)}`);
306
+ lines.push(`MCP servers: ${probes.mcps.ok ? summarizeArrayLike(probes.mcps.value) : formatCodexDisplayText(probes.mcps.error)}`);
307
+ lines.push(`Skills: ${probes.skills.ok ? summarizeArrayLike(probes.skills.value) : formatCodexDisplayText(probes.skills.error)}`);
308
+ return lines.join("\n");
309
+ }
310
+ function formatModels(result) {
311
+ if (result.models.length === 0) return "No Codex app-server models returned.";
312
+ const lines = ["Codex models:", ...result.models.map((model) => `- ${formatCodexDisplayText(model.id)}${model.isDefault ? " (default)" : ""}`)];
313
+ if (result.truncated) lines.push("- More models available; output truncated.");
314
+ return lines.join("\n");
315
+ }
316
+ function formatThreads(response) {
317
+ const threads = extractArray(response);
318
+ if (threads.length === 0) return "No Codex threads returned.";
319
+ return ["Codex threads:", ...threads.slice(0, 10).map((thread) => {
320
+ const record = isJsonObject(thread) ? thread : {};
321
+ const id = readString(record, "threadId") ?? readString(record, "id") ?? "<unknown>";
322
+ const title = readString(record, "title") ?? readString(record, "name") ?? readString(record, "summary");
323
+ const details = [
324
+ readString(record, "model"),
325
+ readString(record, "cwd"),
326
+ readString(record, "updatedAt") ?? readString(record, "lastUpdatedAt")
327
+ ].filter((value) => Boolean(value));
328
+ return `- ${formatCodexDisplayText(id)}${title ? ` - ${formatCodexDisplayText(title)}` : ""}${details.length > 0 ? ` (${details.map(formatCodexDisplayText).join(", ")})` : ""}\n Resume: ${formatCodexResumeHint(id)}`;
329
+ })].join("\n");
330
+ }
331
+ function formatAccount(account, limits, authOverview) {
332
+ if (authOverview) return formatAccountAuthOverview(authOverview);
333
+ const formattedLimits = limits.ok ? formatCodexRateLimitDetails(limits.value) : formatCodexDisplayText(limits.error);
334
+ const rateLimitBlock = formattedLimits.startsWith("Codex is ") ? formattedLimits : formattedLimits.includes("\n") ? `Rate limits:\n${formattedLimits}` : `Rate limits: ${formattedLimits}`;
335
+ return [`Account: ${account.ok ? formatCodexAccountSummary(account.value) : formatCodexDisplayText(account.error)}`, rateLimitBlock].join("\n\n");
336
+ }
337
+ function formatAccountAuthOverview(overview) {
338
+ const lines = [];
339
+ if (overview.currentLine) lines.push(overview.currentLine, "");
340
+ if (overview.subscriptionLabel) {
341
+ lines.push(`Subscription ${overview.subscriptionLabel}`);
342
+ if (overview.subscriptionUsage) lines.push(` ${overview.subscriptionUsage}`);
343
+ lines.push("");
344
+ }
345
+ if (overview.rows.length > 0) {
346
+ lines.push(overview.orderTitle);
347
+ for (const [index, row] of overview.rows.entries()) lines.push(` ${index + 1}. ${row.label} ${row.kind} — ${formatAuthRowStatus(row)}`);
348
+ }
349
+ while (lines.at(-1) === "") lines.pop();
350
+ return lines.map(formatCodexAccountLine).join("\n");
351
+ }
352
+ function formatAuthRowStatus(row) {
353
+ return row.billingNote ? `${row.status} · ${row.billingNote}` : row.status;
354
+ }
355
+ function formatComputerUseStatus(status) {
356
+ const lines = [`Computer Use: ${status.ready ? "ready" : status.enabled ? "not ready" : "disabled"}`];
357
+ lines.push(`Plugin: ${formatCodexDisplayText(status.pluginName)} (${computerUsePluginState(status)})`);
358
+ lines.push(`MCP server: ${formatCodexDisplayText(status.mcpServerName)}${status.mcpServerAvailable ? ` (${status.tools.length} tools)` : " (unavailable)"}`);
359
+ if (status.marketplaceName) lines.push(`Marketplace: ${formatCodexDisplayText(status.marketplaceName)}`);
360
+ if (status.tools.length > 0) lines.push(`Tools: ${status.tools.slice(0, 8).map(formatCodexDisplayText).join(", ")}`);
361
+ lines.push(formatCodexDisplayText(status.message));
362
+ return lines.join("\n");
363
+ }
364
+ function computerUsePluginState(status) {
365
+ if (!status.installed) return "not installed";
366
+ return status.pluginEnabled ? "installed" : "installed, disabled";
367
+ }
368
+ function formatList(response, label) {
369
+ const entries = extractArray(response);
370
+ if (entries.length === 0) return `${label}: none returned.`;
371
+ return [`${label}:`, ...entries.slice(0, 25).map((entry) => {
372
+ const record = isJsonObject(entry) ? entry : {};
373
+ return `- ${formatCodexDisplayText(readString(record, "name") ?? readString(record, "id") ?? JSON.stringify(entry))}`;
374
+ })].join("\n");
375
+ }
376
+ const CODEX_RESUME_SAFE_THREAD_ID_PATTERN = /^[A-Za-z0-9._:-]+$/;
377
+ function formatCodexResumeHint(threadId) {
378
+ const safe = formatCodexTextForDisplay(threadId);
379
+ if (!CODEX_RESUME_SAFE_THREAD_ID_PATTERN.test(safe)) return "copy the thread id above and run /codex resume <thread-id>";
380
+ return `/codex resume ${safe}`;
381
+ }
382
+ function formatCodexDisplayText(value) {
383
+ return escapeCodexChatText(formatCodexTextForDisplay(value));
384
+ }
385
+ function formatCodexAccountSummary(value) {
386
+ const safe = formatCodexTextForDisplay(summarizeAccount(value));
387
+ return isLikelyEmailAddress(safe) ? escapeCodexChatTextPreservingAt(safe) : escapeCodexChatText(safe);
388
+ }
389
+ function formatCodexTextForDisplay(value) {
390
+ return sanitizeCodexTextForDisplay(value).trim() || "<unknown>";
391
+ }
392
+ function sanitizeCodexTextForDisplay(value) {
393
+ let safe = "";
394
+ for (const character of value) {
395
+ const codePoint = character.codePointAt(0);
396
+ safe += codePoint != null && isUnsafeDisplayCodePoint(codePoint) ? "?" : character;
397
+ }
398
+ return safe;
399
+ }
400
+ function escapeCodexChatText(value) {
401
+ return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("@", "@").replaceAll("`", "`").replaceAll("[", "[").replaceAll("]", "]").replaceAll("(", "(").replaceAll(")", ")").replaceAll("*", "∗").replaceAll("_", "_").replaceAll("~", "~").replaceAll("|", "|");
402
+ }
403
+ function escapeCodexChatTextPreservingAt(value) {
404
+ return escapeCodexChatText(value).replaceAll("@", "@");
405
+ }
406
+ function formatCodexAccountLine(value) {
407
+ if (value === "") return "";
408
+ const safe = sanitizeCodexTextForDisplay(value).trimEnd();
409
+ if (!safe.trim()) return "";
410
+ const emailPattern = /[^\s@<>()[\]`]+@[^\s@<>()[\]`]+\.[^\s@<>()[\]`]+/gu;
411
+ let formatted = "";
412
+ let lastIndex = 0;
413
+ for (const match of safe.matchAll(emailPattern)) {
414
+ const index = match.index ?? 0;
415
+ formatted += escapeCodexChatText(safe.slice(lastIndex, index));
416
+ formatted += escapeCodexChatTextPreservingAt(match[0]);
417
+ lastIndex = index + match[0].length;
418
+ }
419
+ formatted += escapeCodexChatText(safe.slice(lastIndex));
420
+ return formatted;
421
+ }
422
+ function isLikelyEmailAddress(value) {
423
+ return /^[^\s@<>()[\]`]+@[^\s@<>()[\]`]+\.[^\s@<>()[\]`]+$/.test(value);
424
+ }
425
+ function isUnsafeDisplayCodePoint(codePoint) {
426
+ return codePoint <= 31 || codePoint >= 127 && codePoint <= 159 || codePoint === 173 || codePoint === 1564 || codePoint === 6158 || codePoint >= 8203 && codePoint <= 8207 || codePoint >= 8234 && codePoint <= 8238 || codePoint >= 8288 && codePoint <= 8303 || codePoint === 65279 || codePoint >= 65529 && codePoint <= 65531 || codePoint >= 917504 && codePoint <= 917631;
427
+ }
428
+ function buildHelp() {
429
+ return [
430
+ "Codex commands:",
431
+ "- /codex status",
432
+ "- /codex models",
433
+ "- /codex threads [filter]",
434
+ "- /codex sessions --host <node> [filter]",
435
+ "- /codex resume <thread-id>",
436
+ "- /codex resume <session-id> --host <node> --bind here",
437
+ "- /codex bind [thread-id] [--cwd <path>] [--model <model>] [--provider <provider>]",
438
+ "- /codex binding",
439
+ "- /codex stop",
440
+ "- /codex steer <message>",
441
+ "- /codex model [model]",
442
+ "- /codex fast [on|off|status]",
443
+ "- /codex permissions [default|yolo|status]",
444
+ "- /codex detach",
445
+ "- /codex compact",
446
+ "- /codex review",
447
+ "- /codex diagnostics [note]",
448
+ "- /codex computer-use [status|install]",
449
+ "- /codex account",
450
+ "- /codex mcp",
451
+ "- /codex skills",
452
+ "- /codex plugins [list|enable|disable]"
453
+ ].join("\n");
454
+ }
455
+ function summarizeAccount(value) {
456
+ if (!isJsonObject(value)) return "unavailable";
457
+ const account = isJsonObject(value.account) ? value.account : value;
458
+ if (readString(account, "type") === "amazonBedrock") return "Amazon Bedrock";
459
+ return readString(account, "email") ?? readString(account, "accountEmail") ?? readString(account, "planType") ?? readString(account, "id") ?? "available";
460
+ }
461
+ function summarizeArrayLike(value) {
462
+ const entries = extractArray(value);
463
+ if (entries.length === 0) return "none returned";
464
+ return `${entries.length}`;
465
+ }
466
+ function formatCodexRateLimitSummary(value) {
467
+ const summary = summarizeCodexRateLimits(value);
468
+ if (summary) return formatCodexDisplayText(summary);
469
+ return formatCodexDisplayText(hasCodexRateLimitSnapshots(value) ? "none returned" : summarizeRateLimits(value));
470
+ }
471
+ function formatCodexRateLimitDetails(value) {
472
+ const lines = summarizeCodexAccountRateLimits(value);
473
+ if (!lines) return formatCodexDisplayText(hasCodexRateLimitSnapshots(value) ? "none returned" : summarizeRateLimits(value));
474
+ return lines.map(formatCodexDisplayText).join("\n");
475
+ }
476
+ function summarizeRateLimits(value) {
477
+ const entries = extractArray(value);
478
+ if (entries.length > 0) {
479
+ const count = entries.filter(isMeaningfulRateLimitSnapshot).length;
480
+ return count > 0 ? `${count}` : "none returned";
481
+ }
482
+ if (!isJsonObject(value)) return "none returned";
483
+ const keyed = value.rateLimitsByLimitId;
484
+ if (isJsonObject(keyed)) {
485
+ const count = Object.values(keyed).filter(isMeaningfulRateLimitSnapshot).length;
486
+ if (count > 0) return `${count}`;
487
+ }
488
+ return isMeaningfulRateLimitSnapshot(value.rateLimits) ? "1" : "none returned";
489
+ }
490
+ function isMeaningfulRateLimitSnapshot(value) {
491
+ if (!isJsonObject(value)) return false;
492
+ if (readString(value, "rateLimitReachedType") ?? readString(value, "rate_limit_reached_type")) return true;
493
+ return ["primary", "secondary"].some((key) => {
494
+ const window = value[key];
495
+ return isJsonObject(window) && Object.values(window).some((entry) => entry != null);
496
+ });
497
+ }
498
+ function extractArray(value) {
499
+ if (Array.isArray(value)) return value;
500
+ if (!isJsonObject(value)) return [];
501
+ for (const key of [
502
+ "data",
503
+ "items",
504
+ "threads",
505
+ "models",
506
+ "skills",
507
+ "servers",
508
+ "rateLimits"
509
+ ]) {
510
+ const child = value[key];
511
+ if (Array.isArray(child)) return child;
512
+ }
513
+ return [];
514
+ }
515
+ function readString(record, key) {
516
+ const value = record[key];
517
+ return typeof value === "string" && value.trim() ? value.trim() : void 0;
518
+ }
519
+ //#endregion
520
+ export { formatComputerUseStatus as a, formatThreads as c, resolveCodexUsageLimitResetAtMs as d, shouldRefreshCodexRateLimitsForUsageLimitMessage as f, formatCodexStatus as i, readString as l, formatAccount as n, formatList as o, summarizeCodexAccountUsage as p, formatCodexDisplayText as r, formatModels as s, buildHelp as t, formatCodexUsageLimitErrorMessage as u };