@juanbenjumea/pi-agy 0.6.11 → 0.7.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.
- package/CHANGELOG.md +15 -0
- package/README.md +59 -2
- package/extensions/commands.ts +66 -105
- package/extensions/index.ts +164 -47
- package/extensions/lib/args.ts +125 -0
- package/extensions/lib/cli.ts +31 -1223
- package/extensions/lib/command-args.ts +101 -0
- package/extensions/lib/config.ts +36 -1
- package/extensions/lib/confirm.ts +43 -0
- package/extensions/lib/doctor.ts +37 -1
- package/extensions/lib/inspect.ts +254 -0
- package/extensions/lib/lock.ts +1 -1
- package/extensions/lib/model-sort.ts +46 -0
- package/extensions/lib/provider-driver.ts +728 -0
- package/extensions/lib/provider-mcp.ts +580 -0
- package/extensions/lib/provider-models.ts +251 -0
- package/extensions/lib/provider.ts +1148 -0
- package/extensions/lib/retry.ts +34 -0
- package/extensions/lib/spawn.ts +411 -0
- package/extensions/lib/usage.ts +398 -0
- package/extensions/lib/verify.ts +11 -0
- package/package.json +6 -1
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Usage/quotas parsing and formatting.
|
|
3
|
+
*
|
|
4
|
+
* Split out of `lib/cli.ts`: pure payload normalization with no process,
|
|
5
|
+
* catalog, or spawn state, so it can be tested and reasoned about in isolation.
|
|
6
|
+
* `cli.ts` re-exports the public surface, so existing importers are untouched.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** A normalized model quota entry returned by agy's read-only usage command. */
|
|
10
|
+
export interface AgyQuotaEntry {
|
|
11
|
+
model: string;
|
|
12
|
+
window?: string;
|
|
13
|
+
remaining_fraction?: number;
|
|
14
|
+
remaining_requests?: number;
|
|
15
|
+
remaining_tokens?: number;
|
|
16
|
+
reset_at?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Best-effort quota snapshot; agy versions may expose different JSON shapes. */
|
|
20
|
+
export interface AgyUsageSnapshot {
|
|
21
|
+
fetched_at: string;
|
|
22
|
+
models: AgyQuotaEntry[];
|
|
23
|
+
raw_summary?: string;
|
|
24
|
+
error?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function usageError(message: string): AgyUsageSnapshot {
|
|
28
|
+
return {
|
|
29
|
+
fetched_at: new Date().toISOString(),
|
|
30
|
+
models: [],
|
|
31
|
+
error: message.slice(0, 2_000),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const MAX_USAGE_SUMMARY_CHARS = 12_000;
|
|
36
|
+
const MODEL_FIELD_KEYS = [
|
|
37
|
+
"model",
|
|
38
|
+
"model_id",
|
|
39
|
+
"modelId",
|
|
40
|
+
"model_name",
|
|
41
|
+
"modelName",
|
|
42
|
+
"displayName",
|
|
43
|
+
"label",
|
|
44
|
+
"group",
|
|
45
|
+
"family",
|
|
46
|
+
"pool",
|
|
47
|
+
// agy 1.2.6 usage groups carry the family in `name` ("Gemini Models",
|
|
48
|
+
// "Claude and GPT models"); the looksLikeModelName gate rejects the
|
|
49
|
+
// non-model names ("Weekly Limit Remaining", "usage", …) that also use it.
|
|
50
|
+
"name",
|
|
51
|
+
];
|
|
52
|
+
const REMAINING_FRACTION_KEYS = [
|
|
53
|
+
"remainingFraction",
|
|
54
|
+
"remaining_fraction",
|
|
55
|
+
"fractionRemaining",
|
|
56
|
+
];
|
|
57
|
+
const REMAINING_PERCENT_KEYS = ["remainingPercent", "remaining_percent"];
|
|
58
|
+
const REMAINING_REQUEST_KEYS = ["remainingRequests", "remaining_requests", "requestsRemaining"];
|
|
59
|
+
const REMAINING_TOKEN_KEYS = ["remainingTokens", "remaining_tokens", "tokensRemaining"];
|
|
60
|
+
const WINDOW_KEYS = ["window", "period", "quotaWindow", "duration"];
|
|
61
|
+
const RELATIVE_RESET_KEYS = ["resetsInSeconds", "resetAfterSeconds", "reset_after_seconds"];
|
|
62
|
+
const RESET_KEYS = [
|
|
63
|
+
"resetAt",
|
|
64
|
+
"reset_at",
|
|
65
|
+
"resetTime",
|
|
66
|
+
"reset_time",
|
|
67
|
+
"reset_timestamp",
|
|
68
|
+
"quotaResetTime",
|
|
69
|
+
"nextReset",
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
/** Normalize both documented and version-specific usage payloads. */
|
|
73
|
+
export function parseAgyUsage(output: string): AgyUsageSnapshot | undefined {
|
|
74
|
+
const raw = output.trim();
|
|
75
|
+
if (!raw) return undefined;
|
|
76
|
+
|
|
77
|
+
let parsed: unknown;
|
|
78
|
+
try {
|
|
79
|
+
parsed = JSON.parse(raw);
|
|
80
|
+
} catch {
|
|
81
|
+
const plainTextSnapshot = parsePlainTextUsage(raw);
|
|
82
|
+
if (plainTextSnapshot) return plainTextSnapshot;
|
|
83
|
+
const jsonLines = raw
|
|
84
|
+
.split("\n")
|
|
85
|
+
.map((line) => {
|
|
86
|
+
try {
|
|
87
|
+
return JSON.parse(line);
|
|
88
|
+
} catch {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
.filter((line): line is unknown => line !== undefined);
|
|
93
|
+
if (jsonLines.length > 0) {
|
|
94
|
+
const lineSnapshot = parseAgyUsage(JSON.stringify(jsonLines));
|
|
95
|
+
if (lineSnapshot?.models.length) return lineSnapshot;
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
fetched_at: new Date().toISOString(),
|
|
99
|
+
models: [],
|
|
100
|
+
raw_summary: raw.slice(0, MAX_USAGE_SUMMARY_CHARS),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const entries = new Map<string, AgyQuotaEntry>();
|
|
105
|
+
const visit = (value: unknown, hintedModel?: string, hintedWindow?: string): void => {
|
|
106
|
+
if (Array.isArray(value)) {
|
|
107
|
+
for (const item of value) visit(item, hintedModel, hintedWindow);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (!isRecord(value)) return;
|
|
111
|
+
|
|
112
|
+
const model = findModelName(value) ?? hintedModel;
|
|
113
|
+
const entry = model ? readQuotaEntry(model, value, hintedWindow) : undefined;
|
|
114
|
+
if (entry) {
|
|
115
|
+
const key = `${entry.model.toLowerCase()}\u0000${entry.window?.toLowerCase() ?? ""}`;
|
|
116
|
+
entries.set(key, mergeQuotaEntries(entries.get(key), entry));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
for (const [key, child] of Object.entries(value)) {
|
|
120
|
+
visit(
|
|
121
|
+
child,
|
|
122
|
+
model ?? (looksLikeModelName(key) ? key : undefined),
|
|
123
|
+
hintedWindow ?? quotaWindowName(key),
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
visit(parsed);
|
|
128
|
+
|
|
129
|
+
if (entries.size === 0 && isRunEnvelope(parsed)) return undefined;
|
|
130
|
+
|
|
131
|
+
const snapshot: AgyUsageSnapshot = {
|
|
132
|
+
fetched_at: new Date().toISOString(),
|
|
133
|
+
models: [...entries.values()].sort((a, b) => a.model.localeCompare(b.model)),
|
|
134
|
+
};
|
|
135
|
+
if (snapshot.models.length === 0) {
|
|
136
|
+
snapshot.raw_summary = JSON.stringify(parsed).slice(0, MAX_USAGE_SUMMARY_CHARS);
|
|
137
|
+
}
|
|
138
|
+
return snapshot;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function parsePlainTextUsage(raw: string): AgyUsageSnapshot | undefined {
|
|
142
|
+
const models: AgyQuotaEntry[] = [];
|
|
143
|
+
for (const line of raw.split("\n")) {
|
|
144
|
+
const match = /^\s*[-*]?\s*((?:gemini|claude|gpt(?:[- ]?oss))[^:\t—]+?)\s*(?::|\t|\s+—\s+|\s+-\s+)(.+)$/i.exec(line);
|
|
145
|
+
if (!match) continue;
|
|
146
|
+
let model = match[1].trim();
|
|
147
|
+
const values = match[2];
|
|
148
|
+
const modelWindowMatch = /\s*\((five[- ]hour|weekly|daily|monthly)\)\s*$/i.exec(model);
|
|
149
|
+
if (modelWindowMatch) model = model.slice(0, modelWindowMatch.index).trim();
|
|
150
|
+
const percentMatch = /(\d+(?:\.\d+)?)\s*%/.exec(values);
|
|
151
|
+
const requestMatch = /(\d[\d,]*)\s+(?:requests?|reqs?)\s*(?:left|remaining)?/i.exec(values);
|
|
152
|
+
const tokenMatch = /(\d[\d,]*)\s+tokens?\s*(?:left|remaining)?/i.exec(values);
|
|
153
|
+
const resetMatch = /\breset(?:s| at)?\s*(?:in|at)?\s+(.+)$/i.exec(values);
|
|
154
|
+
const windowMatch = /\b(five[- ]hour|weekly|daily|monthly)\b/i.exec(values);
|
|
155
|
+
const entry: AgyQuotaEntry = {
|
|
156
|
+
model,
|
|
157
|
+
window: modelWindowMatch?.[1] ?? windowMatch?.[1],
|
|
158
|
+
remaining_fraction: percentMatch ? Number(percentMatch[1]) / 100 : undefined,
|
|
159
|
+
remaining_requests: requestMatch ? Number(requestMatch[1].replace(/,/g, "")) : undefined,
|
|
160
|
+
remaining_tokens: tokenMatch ? Number(tokenMatch[1].replace(/,/g, "")) : undefined,
|
|
161
|
+
reset_at: resetMatch?.[1]?.trim(),
|
|
162
|
+
};
|
|
163
|
+
if (
|
|
164
|
+
entry.remaining_fraction !== undefined ||
|
|
165
|
+
entry.remaining_requests !== undefined ||
|
|
166
|
+
entry.remaining_tokens !== undefined ||
|
|
167
|
+
entry.reset_at ||
|
|
168
|
+
/\bexhausted\b/i.test(values)
|
|
169
|
+
) {
|
|
170
|
+
if (/\bexhausted\b/i.test(values)) entry.remaining_fraction = 0;
|
|
171
|
+
models.push(entry);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return models.length
|
|
175
|
+
? { fetched_at: new Date().toISOString(), models }
|
|
176
|
+
: undefined;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function isRunEnvelope(value: unknown): boolean {
|
|
180
|
+
if (!isRecord(value)) return false;
|
|
181
|
+
return value.event === "result" || isRecord(value.result);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Return true when a quota record explicitly says the model is exhausted. */
|
|
185
|
+
export function isAgyQuotaExhausted(entry: AgyQuotaEntry | undefined): boolean {
|
|
186
|
+
if (!entry) return false;
|
|
187
|
+
return (
|
|
188
|
+
(entry.remaining_fraction !== undefined && entry.remaining_fraction <= 0) ||
|
|
189
|
+
(entry.remaining_requests !== undefined && entry.remaining_requests <= 0) ||
|
|
190
|
+
(entry.remaining_tokens !== undefined && entry.remaining_tokens <= 0)
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** Find quota windows that correspond to a concrete agy model id or label. */
|
|
195
|
+
export function findAgyQuotaEntries(
|
|
196
|
+
snapshot: AgyUsageSnapshot | undefined,
|
|
197
|
+
selectedModel: string,
|
|
198
|
+
): AgyQuotaEntry[] {
|
|
199
|
+
if (!snapshot) return [];
|
|
200
|
+
return snapshot.models.filter((entry) => quotaModelsMatch(entry.model, selectedModel));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function quotaModelsMatch(left: string, right: string): boolean {
|
|
204
|
+
const normalize = (value: string) =>
|
|
205
|
+
value
|
|
206
|
+
.toLowerCase()
|
|
207
|
+
.replace(/\bthinking\b/g, "")
|
|
208
|
+
.replace(/[^a-z0-9]/g, "");
|
|
209
|
+
const leftNormalized = normalize(left);
|
|
210
|
+
const rightNormalized = normalize(right);
|
|
211
|
+
if (leftNormalized === rightNormalized) return true;
|
|
212
|
+
|
|
213
|
+
const leftGroup = quotaModelGroup(leftNormalized);
|
|
214
|
+
const rightGroup = quotaModelGroup(rightNormalized);
|
|
215
|
+
if (leftGroup && leftGroup === rightGroup && (isQuotaGroup(leftNormalized) || isQuotaGroup(rightNormalized))) {
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const leftTier = /(low|medium|high)$/.exec(leftNormalized)?.[1];
|
|
220
|
+
const rightTier = /(low|medium|high)$/.exec(rightNormalized)?.[1];
|
|
221
|
+
if (leftTier && rightTier) return false;
|
|
222
|
+
const leftBase = leftTier ? leftNormalized.slice(0, -leftTier.length) : leftNormalized;
|
|
223
|
+
const rightBase = rightTier ? rightNormalized.slice(0, -rightTier.length) : rightNormalized;
|
|
224
|
+
return leftBase === rightBase;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function quotaModelGroup(normalized: string): "gemini" | "claude-gpt" | undefined {
|
|
228
|
+
if (normalized.startsWith("gemini")) return "gemini";
|
|
229
|
+
if (normalized.startsWith("claude") || normalized.startsWith("gptoss")) return "claude-gpt";
|
|
230
|
+
return undefined;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function isQuotaGroup(normalized: string): boolean {
|
|
234
|
+
return /^(?:gemini(?:models)?|claude(?:andgpt)?models?|gptossmodels?)$/.test(normalized);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** Format a compact, agent-readable quota report for tool results and TUI status. */
|
|
238
|
+
export function formatAgyUsage(
|
|
239
|
+
snapshot: AgyUsageSnapshot | undefined,
|
|
240
|
+
selectedModel?: string,
|
|
241
|
+
): string | undefined {
|
|
242
|
+
if (!snapshot) return undefined;
|
|
243
|
+
if (snapshot.models.length === 0) {
|
|
244
|
+
if (snapshot.error) return `agy quota unavailable: ${snapshot.error}`;
|
|
245
|
+
return snapshot.raw_summary ? `agy quota snapshot: ${snapshot.raw_summary}` : undefined;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const selectedEntries = selectedModel ? findAgyQuotaEntries(snapshot, selectedModel) : [];
|
|
249
|
+
const selectedSet = new Set(selectedEntries);
|
|
250
|
+
const ordered = selectedEntries.length
|
|
251
|
+
? [...selectedEntries, ...snapshot.models.filter((entry) => !selectedSet.has(entry))]
|
|
252
|
+
: snapshot.models;
|
|
253
|
+
const lines = ordered.map((entry) => {
|
|
254
|
+
const values: string[] = [];
|
|
255
|
+
if (entry.window) values.push(`${entry.window} window`);
|
|
256
|
+
if (entry.remaining_fraction !== undefined) {
|
|
257
|
+
const percent = entry.remaining_fraction <= 1
|
|
258
|
+
? entry.remaining_fraction * 100
|
|
259
|
+
: entry.remaining_fraction;
|
|
260
|
+
values.push(`${formatNumber(percent)}% remaining`);
|
|
261
|
+
}
|
|
262
|
+
if (entry.remaining_requests !== undefined) {
|
|
263
|
+
values.push(`${formatNumber(entry.remaining_requests)} requests left`);
|
|
264
|
+
}
|
|
265
|
+
if (entry.remaining_tokens !== undefined) {
|
|
266
|
+
values.push(`${formatNumber(entry.remaining_tokens)} tokens left`);
|
|
267
|
+
}
|
|
268
|
+
if (entry.reset_at) values.push(`resets ${entry.reset_at}`);
|
|
269
|
+
return `- ${entry.model}: ${values.join(", ") || "quota reported without remaining amount"}`;
|
|
270
|
+
});
|
|
271
|
+
return `agy model quota (refreshed ${snapshot.fetched_at}):\n${lines.join("\n")}`;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
275
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function findModelName(value: Record<string, unknown>): string | undefined {
|
|
279
|
+
for (const key of MODEL_FIELD_KEYS) {
|
|
280
|
+
const candidate = value[key];
|
|
281
|
+
if (typeof candidate === "string" && looksLikeModelName(candidate)) return candidate;
|
|
282
|
+
}
|
|
283
|
+
return undefined;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function looksLikeModelName(value: string): boolean {
|
|
287
|
+
return /(?:gemini|claude|gpt[-_ ]?oss|flash|pro|sonnet|opus)/i.test(value);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function readQuotaEntry(
|
|
291
|
+
model: string,
|
|
292
|
+
value: Record<string, unknown>,
|
|
293
|
+
hintedWindow?: string,
|
|
294
|
+
): AgyQuotaEntry | undefined {
|
|
295
|
+
// Normalize window spellings ("5h" → "five-hour") so reports and merge
|
|
296
|
+
// keys stay consistent across CLI versions.
|
|
297
|
+
const rawWindow = readString(value, WINDOW_KEYS);
|
|
298
|
+
const window = (rawWindow ? quotaWindowName(rawWindow) ?? rawWindow : undefined) ?? hintedWindow;
|
|
299
|
+
const fraction = readNumber(value, REMAINING_FRACTION_KEYS);
|
|
300
|
+
const percent = readNumber(value, REMAINING_PERCENT_KEYS);
|
|
301
|
+
const normalizedFraction = fraction ?? (percent !== undefined ? percent / 100 : undefined);
|
|
302
|
+
const requests = readNumber(value, REMAINING_REQUEST_KEYS);
|
|
303
|
+
const tokens = readNumber(value, REMAINING_TOKEN_KEYS);
|
|
304
|
+
const reset = readReset(value, RESET_KEYS, RELATIVE_RESET_KEYS);
|
|
305
|
+
const exhausted =
|
|
306
|
+
value.exhausted === true || value.isExhausted === true || value.is_exhausted === true;
|
|
307
|
+
if (
|
|
308
|
+
// A disabled limit is not in effect and carries no availability signal —
|
|
309
|
+
// recording its remaining fraction would mislead model selection.
|
|
310
|
+
value.disabled === true ||
|
|
311
|
+
(normalizedFraction === undefined &&
|
|
312
|
+
requests === undefined &&
|
|
313
|
+
tokens === undefined &&
|
|
314
|
+
!reset &&
|
|
315
|
+
!exhausted)
|
|
316
|
+
) {
|
|
317
|
+
return undefined;
|
|
318
|
+
}
|
|
319
|
+
return {
|
|
320
|
+
model,
|
|
321
|
+
window,
|
|
322
|
+
remaining_fraction: exhausted ? 0 : normalizedFraction,
|
|
323
|
+
remaining_requests: requests,
|
|
324
|
+
remaining_tokens: tokens,
|
|
325
|
+
reset_at: reset,
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function quotaWindowName(value: string): string | undefined {
|
|
330
|
+
const normalized = value.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
331
|
+
if (normalized === "weekly") return "weekly";
|
|
332
|
+
if (normalized === "daily") return "daily";
|
|
333
|
+
if (normalized === "monthly") return "monthly";
|
|
334
|
+
if (normalized === "fivehour" || normalized === "5h") return "five-hour";
|
|
335
|
+
return undefined;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function mergeQuotaEntries(existing: AgyQuotaEntry | undefined, next: AgyQuotaEntry): AgyQuotaEntry {
|
|
339
|
+
return {
|
|
340
|
+
model: existing?.model ?? next.model,
|
|
341
|
+
window: existing?.window ?? next.window,
|
|
342
|
+
remaining_fraction: next.remaining_fraction ?? existing?.remaining_fraction,
|
|
343
|
+
remaining_requests: next.remaining_requests ?? existing?.remaining_requests,
|
|
344
|
+
remaining_tokens: next.remaining_tokens ?? existing?.remaining_tokens,
|
|
345
|
+
reset_at: next.reset_at ?? existing?.reset_at,
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function readNumber(value: Record<string, unknown>, keys: string[]): number | undefined {
|
|
350
|
+
for (const key of keys) {
|
|
351
|
+
const candidate = value[key];
|
|
352
|
+
const number = typeof candidate === "number" ? candidate : typeof candidate === "string" ? Number(candidate) : NaN;
|
|
353
|
+
if (Number.isFinite(number)) return number;
|
|
354
|
+
}
|
|
355
|
+
return undefined;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function readString(value: Record<string, unknown>, keys: string[]): string | undefined {
|
|
359
|
+
for (const key of keys) {
|
|
360
|
+
const candidate = value[key];
|
|
361
|
+
if (typeof candidate === "string" && candidate.trim()) return candidate.trim();
|
|
362
|
+
}
|
|
363
|
+
return undefined;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function readReset(
|
|
367
|
+
value: Record<string, unknown>,
|
|
368
|
+
keys: string[],
|
|
369
|
+
relativeKeys: string[],
|
|
370
|
+
): string | undefined {
|
|
371
|
+
for (const key of relativeKeys) {
|
|
372
|
+
const seconds = readNumber(value, [key]);
|
|
373
|
+
if (seconds !== undefined && seconds >= 0) return `in ${formatDuration(seconds)}`;
|
|
374
|
+
}
|
|
375
|
+
for (const key of keys) {
|
|
376
|
+
const candidate = value[key];
|
|
377
|
+
if (typeof candidate === "string" && candidate.trim()) return candidate.trim();
|
|
378
|
+
if (typeof candidate === "number" && Number.isFinite(candidate)) {
|
|
379
|
+
const milliseconds = candidate < 1e12 ? candidate * 1000 : candidate;
|
|
380
|
+
const date = new Date(milliseconds);
|
|
381
|
+
if (Number.isFinite(date.getTime())) return date.toISOString();
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return undefined;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function formatDuration(seconds: number): string {
|
|
388
|
+
if (seconds < 60) return `${Math.round(seconds)}s`;
|
|
389
|
+
const minutes = Math.round(seconds / 60);
|
|
390
|
+
if (minutes < 60) return `${minutes}m`;
|
|
391
|
+
const hours = Math.round(minutes / 60);
|
|
392
|
+
if (hours < 24) return `${hours}h`;
|
|
393
|
+
return `${Math.round(hours / 24)}d`;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function formatNumber(value: number): string {
|
|
397
|
+
return Number.isInteger(value) ? String(value) : value.toFixed(1).replace(/\.0$/, "");
|
|
398
|
+
}
|
package/extensions/lib/verify.ts
CHANGED
|
@@ -131,3 +131,14 @@ async function fileExists(filename: string): Promise<boolean> {
|
|
|
131
131
|
function runScript(runner: string, script: string): string {
|
|
132
132
|
return runner === "npm" && script === "test" ? "npm test" : `${runner} run ${script}`;
|
|
133
133
|
}
|
|
134
|
+
|
|
135
|
+
// Kept alongside detectVerifyCommand: tests imported it from cli in upstream.
|
|
136
|
+
export async function detectVerifyCommandFromPackageJson(cwd: string): Promise<string | null> {
|
|
137
|
+
try {
|
|
138
|
+
const pkg = JSON.parse(await readFile(path.join(cwd, "package.json"), "utf8"));
|
|
139
|
+
if (pkg?.scripts?.test) return "npm test";
|
|
140
|
+
} catch {
|
|
141
|
+
// ignore
|
|
142
|
+
}
|
|
143
|
+
return null;
|
|
144
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juanbenjumea/pi-agy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Reliable Antigravity delegation for Pi — quota-aware runs, resumable tasks, repo verification, cancellation, and trustworthy diff summaries.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,11 +45,13 @@
|
|
|
45
45
|
]
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
+
"@earendil-works/pi-ai": "*",
|
|
48
49
|
"@earendil-works/pi-coding-agent": "*",
|
|
49
50
|
"@earendil-works/pi-tui": "*",
|
|
50
51
|
"@sinclair/typebox": "*"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
54
|
+
"@earendil-works/pi-ai": "^0.86.1",
|
|
53
55
|
"@earendil-works/pi-coding-agent": "^0.86.1",
|
|
54
56
|
"@earendil-works/pi-tui": "^0.86.1",
|
|
55
57
|
"@sinclair/typebox": "^0.34.41",
|
|
@@ -58,5 +60,8 @@
|
|
|
58
60
|
},
|
|
59
61
|
"engines": {
|
|
60
62
|
"node": ">=20.3.0"
|
|
63
|
+
},
|
|
64
|
+
"dependencies": {
|
|
65
|
+
"@modelcontextprotocol/sdk": "^1.31.0"
|
|
61
66
|
}
|
|
62
67
|
}
|