@yukikisaku/pi-reset-codex 0.1.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/LICENSE +21 -0
- package/README.md +35 -0
- package/codex-app-server.ts +267 -0
- package/index.ts +130 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 yuki-kisaku
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# pi-reset-codex
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Use an earned Codex reset credit from inside Pi.
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
Requires the `codex` CLI, an authenticated Codex account, and an account with reset-credit support. The extension starts `codex app-server` locally and calls its rate-limit reset methods.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
pi install npm:@yukikisaku/pi-reset-codex
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
Run `/reset-codex`. Pi shows current weekly usage and available reset credits before asking for confirmation. Confirming consumes one earned reset credit, changes the Codex weekly usage limit state, and reduces the available reset-credit count by one. The extension does not provide an undo action. After the reset, Pi refreshes the displayed usage and remaining credits.
|
|
20
|
+
|
|
21
|
+
## Configuration
|
|
22
|
+
|
|
23
|
+
Set `CODEX_BIN` if the Codex executable is not named `codex`.
|
|
24
|
+
|
|
25
|
+
## Uninstallation
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
pi uninstall npm:@yukikisaku/pi-reset-codex
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Remove any package-specific configuration described above if you no longer need it.
|
|
32
|
+
|
|
33
|
+
## License
|
|
34
|
+
|
|
35
|
+
MIT © yuki-kisaku. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { spawn, type ChildProcessWithoutNullStreams } from "node:child_process";
|
|
2
|
+
|
|
3
|
+
export type RateLimitWindow = {
|
|
4
|
+
usedPercent: number;
|
|
5
|
+
windowDurationMins?: number | null;
|
|
6
|
+
resetsAt?: number | null;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type RateLimitSnapshot = {
|
|
10
|
+
limitId?: string | null;
|
|
11
|
+
limitName?: string | null;
|
|
12
|
+
primary?: RateLimitWindow | null;
|
|
13
|
+
secondary?: RateLimitWindow | null;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type AccountRateLimits = {
|
|
17
|
+
rateLimits: RateLimitSnapshot;
|
|
18
|
+
rateLimitsByLimitId?: Record<string, RateLimitSnapshot> | null;
|
|
19
|
+
rateLimitResetCredits?: {
|
|
20
|
+
availableCount: number;
|
|
21
|
+
} | null;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type ResetOutcome = "reset" | "nothingToReset" | "noCredit" | "alreadyRedeemed";
|
|
25
|
+
|
|
26
|
+
export type ConsumeResetResponse = {
|
|
27
|
+
outcome: ResetOutcome;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type CodexAppServerOptions = {
|
|
31
|
+
command?: string;
|
|
32
|
+
args?: string[];
|
|
33
|
+
timeoutMs?: number;
|
|
34
|
+
env?: NodeJS.ProcessEnv;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
type PendingRequest = {
|
|
38
|
+
resolve: (value: unknown) => void;
|
|
39
|
+
reject: (error: Error) => void;
|
|
40
|
+
timer: NodeJS.Timeout;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
type RpcResponse = {
|
|
44
|
+
id?: number | string;
|
|
45
|
+
result?: unknown;
|
|
46
|
+
error?: {
|
|
47
|
+
code?: number;
|
|
48
|
+
message?: string;
|
|
49
|
+
data?: unknown;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const CLIENT_INFO = {
|
|
54
|
+
name: "pi-reset-codex",
|
|
55
|
+
title: "Pi Codex Reset",
|
|
56
|
+
version: "0.1.0",
|
|
57
|
+
};
|
|
58
|
+
const DEFAULT_TIMEOUT_MS = 15_000;
|
|
59
|
+
const WEEK_MINUTES = 7 * 24 * 60;
|
|
60
|
+
const WEEK_TOLERANCE_MINUTES = 5;
|
|
61
|
+
const STDERR_LIMIT = 8_192;
|
|
62
|
+
|
|
63
|
+
function errorMessage(error: unknown): string {
|
|
64
|
+
return error instanceof Error ? error.message : String(error);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function rpcErrorMessage(error: NonNullable<RpcResponse["error"]>): string {
|
|
68
|
+
const code = typeof error.code === "number" ? ` (${error.code})` : "";
|
|
69
|
+
return `${error.message ?? "Codex App Server request failed"}${code}`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export class CodexAppServerClient {
|
|
73
|
+
private readonly command: string;
|
|
74
|
+
private readonly args: string[];
|
|
75
|
+
private readonly timeoutMs: number;
|
|
76
|
+
private readonly env: NodeJS.ProcessEnv;
|
|
77
|
+
private child?: ChildProcessWithoutNullStreams;
|
|
78
|
+
private startPromise?: Promise<void>;
|
|
79
|
+
private stdoutBuffer = "";
|
|
80
|
+
private stderrBuffer = "";
|
|
81
|
+
private nextId = 0;
|
|
82
|
+
private readonly pending = new Map<number, PendingRequest>();
|
|
83
|
+
private closed = false;
|
|
84
|
+
|
|
85
|
+
constructor(options: CodexAppServerOptions = {}) {
|
|
86
|
+
this.command = options.command ?? process.env.CODEX_BIN ?? "codex";
|
|
87
|
+
this.args = options.args ?? [];
|
|
88
|
+
this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
89
|
+
this.env = options.env ?? process.env;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
start(): Promise<void> {
|
|
93
|
+
if (this.startPromise) return this.startPromise;
|
|
94
|
+
this.startPromise = this.initialize();
|
|
95
|
+
return this.startPromise;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async request<T>(method: string, params?: unknown): Promise<T> {
|
|
99
|
+
await this.start();
|
|
100
|
+
return this.requestRaw<T>(method, params);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async close(): Promise<void> {
|
|
104
|
+
if (this.closed) return;
|
|
105
|
+
this.closed = true;
|
|
106
|
+
const child = this.child;
|
|
107
|
+
if (!child) return;
|
|
108
|
+
|
|
109
|
+
for (const pending of this.pending.values()) {
|
|
110
|
+
clearTimeout(pending.timer);
|
|
111
|
+
pending.reject(new Error("Codex App Server connection closed"));
|
|
112
|
+
}
|
|
113
|
+
this.pending.clear();
|
|
114
|
+
|
|
115
|
+
if (child.exitCode !== null || child.signalCode !== null) return;
|
|
116
|
+
child.stdin.end();
|
|
117
|
+
child.kill("SIGTERM");
|
|
118
|
+
await new Promise<void>(resolve => {
|
|
119
|
+
const timer = setTimeout(() => {
|
|
120
|
+
if (child.exitCode === null && child.signalCode === null) child.kill("SIGKILL");
|
|
121
|
+
resolve();
|
|
122
|
+
}, 500);
|
|
123
|
+
child.once("exit", () => {
|
|
124
|
+
clearTimeout(timer);
|
|
125
|
+
resolve();
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private async initialize(): Promise<void> {
|
|
131
|
+
if (this.closed) throw new Error("Codex App Server client is closed");
|
|
132
|
+
const child = spawn(this.command, [...this.args, "app-server"], {
|
|
133
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
134
|
+
env: this.env,
|
|
135
|
+
});
|
|
136
|
+
this.child = child;
|
|
137
|
+
child.stdout.setEncoding("utf8");
|
|
138
|
+
child.stderr.setEncoding("utf8");
|
|
139
|
+
child.stdout.on("data", chunk => this.handleStdout(String(chunk)));
|
|
140
|
+
child.stderr.on("data", chunk => {
|
|
141
|
+
this.stderrBuffer = (this.stderrBuffer + String(chunk)).slice(-STDERR_LIMIT);
|
|
142
|
+
});
|
|
143
|
+
child.once("error", error => this.failAll(new Error(`Codexを起動できません: ${error.message}`)));
|
|
144
|
+
child.once("exit", (code, signal) => {
|
|
145
|
+
if (this.closed) return;
|
|
146
|
+
const detail = this.stderrBuffer.trim();
|
|
147
|
+
const suffix = detail ? `: ${detail}` : "";
|
|
148
|
+
this.failAll(new Error(`Codex App Serverが終了しました (code=${code}, signal=${signal})${suffix}`));
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
try {
|
|
152
|
+
await this.requestRaw("initialize", { clientInfo: CLIENT_INFO });
|
|
153
|
+
this.send({ method: "initialized", params: {} });
|
|
154
|
+
} catch (error) {
|
|
155
|
+
await this.close();
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private requestRaw<T>(method: string, params?: unknown): Promise<T> {
|
|
161
|
+
const id = this.nextId++;
|
|
162
|
+
return new Promise<T>((resolve, reject) => {
|
|
163
|
+
const timer = setTimeout(() => {
|
|
164
|
+
this.pending.delete(id);
|
|
165
|
+
reject(new Error(`Codex App Serverが${this.timeoutMs}ms以内に応答しませんでした: ${method}`));
|
|
166
|
+
}, this.timeoutMs);
|
|
167
|
+
this.pending.set(id, {
|
|
168
|
+
resolve: value => resolve(value as T),
|
|
169
|
+
reject,
|
|
170
|
+
timer,
|
|
171
|
+
});
|
|
172
|
+
try {
|
|
173
|
+
this.send(params === undefined ? { method, id } : { method, id, params });
|
|
174
|
+
} catch (error) {
|
|
175
|
+
clearTimeout(timer);
|
|
176
|
+
this.pending.delete(id);
|
|
177
|
+
reject(new Error(`Codex App Serverへの送信に失敗しました: ${errorMessage(error)}`));
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
private send(message: unknown): void {
|
|
183
|
+
const child = this.child;
|
|
184
|
+
if (!child || child.stdin.destroyed || !child.stdin.writable) {
|
|
185
|
+
throw new Error("Codex App Serverの標準入力を利用できません");
|
|
186
|
+
}
|
|
187
|
+
child.stdin.write(`${JSON.stringify(message)}\n`);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
private handleStdout(chunk: string): void {
|
|
191
|
+
this.stdoutBuffer += chunk;
|
|
192
|
+
while (true) {
|
|
193
|
+
const newline = this.stdoutBuffer.indexOf("\n");
|
|
194
|
+
if (newline < 0) return;
|
|
195
|
+
const line = this.stdoutBuffer.slice(0, newline).replace(/\r$/, "");
|
|
196
|
+
this.stdoutBuffer = this.stdoutBuffer.slice(newline + 1);
|
|
197
|
+
if (line.trim() === "") continue;
|
|
198
|
+
let message: RpcResponse;
|
|
199
|
+
try {
|
|
200
|
+
message = JSON.parse(line) as RpcResponse;
|
|
201
|
+
} catch (error) {
|
|
202
|
+
this.failAll(new Error(`Codex App Serverから不正なJSONを受信しました: ${errorMessage(error)}`));
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
if (typeof message.id !== "number") continue;
|
|
206
|
+
const pending = this.pending.get(message.id);
|
|
207
|
+
if (!pending) continue;
|
|
208
|
+
clearTimeout(pending.timer);
|
|
209
|
+
this.pending.delete(message.id);
|
|
210
|
+
if (message.error) pending.reject(new Error(rpcErrorMessage(message.error)));
|
|
211
|
+
else pending.resolve(message.result);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
private failAll(error: Error): void {
|
|
216
|
+
for (const pending of this.pending.values()) {
|
|
217
|
+
clearTimeout(pending.timer);
|
|
218
|
+
pending.reject(error);
|
|
219
|
+
}
|
|
220
|
+
this.pending.clear();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
async function runCodexRequest<T>(method: string, params: unknown, options: CodexAppServerOptions): Promise<T> {
|
|
225
|
+
const client = new CodexAppServerClient(options);
|
|
226
|
+
try {
|
|
227
|
+
return await client.request<T>(method, params);
|
|
228
|
+
} finally {
|
|
229
|
+
await client.close();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export function readAccountRateLimits(options: CodexAppServerOptions = {}): Promise<AccountRateLimits> {
|
|
234
|
+
return runCodexRequest<AccountRateLimits>("account/rateLimits/read", undefined, options);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export function consumeRateLimitResetCredit(
|
|
238
|
+
idempotencyKey: string,
|
|
239
|
+
options: CodexAppServerOptions = {},
|
|
240
|
+
): Promise<ConsumeResetResponse> {
|
|
241
|
+
return runCodexRequest<ConsumeResetResponse>(
|
|
242
|
+
"account/rateLimitResetCredit/consume",
|
|
243
|
+
{ idempotencyKey },
|
|
244
|
+
options,
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export function getWeeklyWindow(rateLimits: AccountRateLimits): RateLimitWindow | undefined {
|
|
249
|
+
const snapshots: RateLimitSnapshot[] = [];
|
|
250
|
+
const byId = rateLimits.rateLimitsByLimitId;
|
|
251
|
+
if (byId?.codex) snapshots.push(byId.codex);
|
|
252
|
+
if (byId) {
|
|
253
|
+
for (const [id, snapshot] of Object.entries(byId)) {
|
|
254
|
+
if (id !== "codex") snapshots.push(snapshot);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if (!snapshots.includes(rateLimits.rateLimits)) snapshots.push(rateLimits.rateLimits);
|
|
258
|
+
|
|
259
|
+
for (const snapshot of snapshots) {
|
|
260
|
+
for (const window of [snapshot.primary, snapshot.secondary]) {
|
|
261
|
+
if (!window || typeof window.windowDurationMins !== "number") continue;
|
|
262
|
+
if (Math.abs(window.windowDurationMins - WEEK_MINUTES) <= WEEK_TOLERANCE_MINUTES) return window;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return undefined;
|
|
267
|
+
}
|
package/index.ts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
consumeRateLimitResetCredit,
|
|
7
|
+
getWeeklyWindow,
|
|
8
|
+
readAccountRateLimits,
|
|
9
|
+
type AccountRateLimits,
|
|
10
|
+
type ConsumeResetResponse,
|
|
11
|
+
type ResetOutcome,
|
|
12
|
+
} from "./codex-app-server.ts";
|
|
13
|
+
|
|
14
|
+
const COMMAND = "reset-codex";
|
|
15
|
+
const STATUS_KEY = "pi-reset-codex";
|
|
16
|
+
|
|
17
|
+
export type ResetCodexDependencies = {
|
|
18
|
+
readRateLimits: () => Promise<AccountRateLimits>;
|
|
19
|
+
consumeReset: (idempotencyKey: string) => Promise<ConsumeResetResponse>;
|
|
20
|
+
createIdempotencyKey: () => string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const defaultDependencies: ResetCodexDependencies = {
|
|
24
|
+
readRateLimits: readAccountRateLimits,
|
|
25
|
+
consumeReset: consumeRateLimitResetCredit,
|
|
26
|
+
createIdempotencyKey: randomUUID,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
function availableCount(rateLimits: AccountRateLimits): number | undefined {
|
|
30
|
+
const count = rateLimits.rateLimitResetCredits?.availableCount;
|
|
31
|
+
return typeof count === "number" ? count : undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function formatUsage(rateLimits: AccountRateLimits): string {
|
|
35
|
+
const weekly = getWeeklyWindow(rateLimits);
|
|
36
|
+
return weekly ? `${weekly.usedPercent}%` : "不明";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function formatCount(count: number | undefined): string {
|
|
40
|
+
return count === undefined ? "不明" : `${count}回`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function notify(
|
|
44
|
+
ctx: ExtensionCommandContext,
|
|
45
|
+
message: string,
|
|
46
|
+
type: "info" | "warning" | "error" = "info",
|
|
47
|
+
): void {
|
|
48
|
+
if (ctx.mode === "print") {
|
|
49
|
+
console.log(message);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (ctx.mode === "json") return;
|
|
53
|
+
ctx.ui.notify(message, type);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function outcomeMessage(outcome: Exclude<ResetOutcome, "reset" | "alreadyRedeemed">): string {
|
|
57
|
+
if (outcome === "nothingToReset") return "現在リセットできるCodex利用枠はありません。";
|
|
58
|
+
return "利用可能なCodexリセット権がありません。";
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function showSuccess(
|
|
62
|
+
ctx: ExtensionCommandContext,
|
|
63
|
+
before: AccountRateLimits,
|
|
64
|
+
dependencies: ResetCodexDependencies,
|
|
65
|
+
): Promise<void> {
|
|
66
|
+
ctx.ui.setStatus(STATUS_KEY, "Codex limitを再確認中…");
|
|
67
|
+
try {
|
|
68
|
+
const after = await dependencies.readRateLimits();
|
|
69
|
+
notify(
|
|
70
|
+
ctx,
|
|
71
|
+
`Codex weekly limitをリセットしました(${formatUsage(before)} → ${formatUsage(after)}、残り${formatCount(availableCount(after))})。`,
|
|
72
|
+
"info",
|
|
73
|
+
);
|
|
74
|
+
} catch {
|
|
75
|
+
notify(ctx, "Codex weekly limitをリセットしました。最新状態の再取得には失敗しました。", "warning");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function createResetCodexHandler(dependencies: ResetCodexDependencies = defaultDependencies) {
|
|
80
|
+
return async (args: string, ctx: ExtensionCommandContext): Promise<void> => {
|
|
81
|
+
if (args.trim() !== "") {
|
|
82
|
+
notify(ctx, "/reset-codex に引数はありません。", "warning");
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (!ctx.hasUI) {
|
|
86
|
+
notify(ctx, "/reset-codex はPiの対話モードで実行してください。", "warning");
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
ctx.ui.setStatus(STATUS_KEY, "Codex limitを確認中…");
|
|
91
|
+
try {
|
|
92
|
+
const before = await dependencies.readRateLimits();
|
|
93
|
+
const count = availableCount(before);
|
|
94
|
+
if (count !== undefined && count <= 0) {
|
|
95
|
+
notify(ctx, "利用可能なCodexリセット権がありません。", "warning");
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
ctx.ui.setStatus(STATUS_KEY, undefined);
|
|
100
|
+
const confirmed = await ctx.ui.confirm(
|
|
101
|
+
"Codex weekly limitをリセット?",
|
|
102
|
+
`獲得済みリセット権を1回使用します。\n現在のweekly使用率: ${formatUsage(before)}\n利用可能: ${formatCount(count)}`,
|
|
103
|
+
);
|
|
104
|
+
if (!confirmed) {
|
|
105
|
+
notify(ctx, "Codex limitのリセットをキャンセルしました。", "info");
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
ctx.ui.setStatus(STATUS_KEY, "Codex weekly limitをリセット中…");
|
|
110
|
+
const result = await dependencies.consumeReset(dependencies.createIdempotencyKey());
|
|
111
|
+
if (result.outcome === "reset" || result.outcome === "alreadyRedeemed") {
|
|
112
|
+
await showSuccess(ctx, before, dependencies);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
notify(ctx, outcomeMessage(result.outcome), "warning");
|
|
116
|
+
} catch (error) {
|
|
117
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
118
|
+
notify(ctx, `Codex weekly limitのリセットに失敗しました: ${message}`, "error");
|
|
119
|
+
} finally {
|
|
120
|
+
ctx.ui.setStatus(STATUS_KEY, undefined);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export default function piCodexResetExtension(pi: ExtensionAPI) {
|
|
126
|
+
pi.registerCommand(COMMAND, {
|
|
127
|
+
description: "獲得済みのリセット権でCodex weekly limitをリセットする",
|
|
128
|
+
handler: createResetCodexHandler(),
|
|
129
|
+
});
|
|
130
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yukikisaku/pi-reset-codex",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Use an earned Codex reset credit from inside Pi.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "yuki-kisaku",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/yukikisaku/pi-reset-codex.git"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/yukikisaku/pi-reset-codex#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/yukikisaku/pi-reset-codex/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"pi-package",
|
|
18
|
+
"pi-extension"
|
|
19
|
+
],
|
|
20
|
+
"files": [
|
|
21
|
+
"index.ts",
|
|
22
|
+
"codex-app-server.ts"
|
|
23
|
+
],
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=20"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@earendil-works/pi-coding-agent": "*"
|
|
32
|
+
},
|
|
33
|
+
"pi": {
|
|
34
|
+
"extensions": [
|
|
35
|
+
"./index.ts"
|
|
36
|
+
]
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"test": "node --no-warnings ./test/smoke.ts"
|
|
40
|
+
}
|
|
41
|
+
}
|