@narumitw/pi-codex-usage 0.6.1 → 0.7.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/codex-usage.ts +43 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narumitw/pi-codex-usage",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "Pi extension that shows Codex ChatGPT subscription usage without requiring Codex CLI.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -18,6 +18,23 @@ const LIMIT_VALUE_COLUMN = 29;
18
18
  const MAX_ERROR_BODY_CHARS = 600;
19
19
  const RESET_FOREGROUND = "\x1b[39m";
20
20
 
21
+ interface CommandArgumentCompletion {
22
+ value: string;
23
+ label: string;
24
+ description?: string;
25
+ }
26
+
27
+ const COMMAND_COMPLETIONS: readonly CommandArgumentCompletion[] = [
28
+ { value: "--refresh", label: "--refresh", description: "Refresh usage instead of cached data" },
29
+ { value: "--no-statusline", label: "--no-statusline", description: "Do not update the statusline" },
30
+ {
31
+ value: "--clear-statusline",
32
+ label: "--clear-statusline",
33
+ description: "Clear the usage statusline",
34
+ },
35
+ { value: "--timeout ", label: "--timeout", description: "Set query timeout in seconds" },
36
+ ];
37
+
21
38
  type UsageSource = "pi-auth" | "codex-app-server";
22
39
  type PiModel = NonNullable<ExtensionContext["model"]>;
23
40
  export type CodexUsageModel = Pick<PiModel, "id" | "name" | "provider">;
@@ -259,6 +276,7 @@ export default function codexUsage(pi: ExtensionAPI) {
259
276
 
260
277
  pi.registerCommand(COMMAND_NAME, {
261
278
  description: "Show Codex ChatGPT subscription usage and rate-limit windows",
279
+ getArgumentCompletions: completeCodexStatusArguments,
262
280
  handler: async (args, ctx) => {
263
281
  try {
264
282
  const options = parseArgs(args);
@@ -351,6 +369,31 @@ export default function codexUsage(pi: ExtensionAPI) {
351
369
  });
352
370
  }
353
371
 
372
+ export function completeCodexStatusArguments(
373
+ argumentPrefix: string,
374
+ ): CommandArgumentCompletion[] | null {
375
+ const prefix = argumentPrefix.trimStart();
376
+ if (prefix === "") return [...COMMAND_COMPLETIONS];
377
+
378
+ const trailingSpace = /\s$/.test(prefix);
379
+ const tokens = prefix.trimEnd().split(/\s+/).filter(Boolean);
380
+ const previous = tokens.at(-1);
381
+ if (previous === "--timeout" && trailingSpace) return null;
382
+ if (!trailingSpace && tokens.at(-2) === "--timeout") return null;
383
+
384
+ const current = trailingSpace ? "" : (previous ?? "");
385
+ if (current && !current.startsWith("-")) return null;
386
+
387
+ const currentRaw = trailingSpace ? "" : (prefix.match(/\S+$/)?.[0] ?? "");
388
+ const completionPrefix = trailingSpace
389
+ ? prefix
390
+ : prefix.slice(0, prefix.length - currentRaw.length);
391
+ const matches = COMMAND_COMPLETIONS.filter((item) => item.value.startsWith(current));
392
+ return matches.length > 0
393
+ ? matches.map((item) => ({ ...item, value: `${completionPrefix}${item.value}` }))
394
+ : null;
395
+ }
396
+
354
397
  export function parseArgs(
355
398
  args: string,
356
399
  ): { ok: true; value: QueryUsageOptions } | { ok: false; error: string } {