@eduardo191labs/opencode-free-pi 0.7.27 → 0.7.30
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/README.md +48 -108
- package/dist/constants.d.ts +0 -22
- package/dist/constants.js +0 -22
- package/dist/deps.d.ts +1 -4
- package/dist/index.d.ts +1 -1
- package/dist/legacy.d.ts +17 -0
- package/dist/legacy.js +58 -0
- package/dist/plugin.js +7 -84
- package/dist/session/events.js +5 -12
- package/dist/session/hooks.js +9 -185
- package/dist/session/tools.d.ts +1 -1
- package/dist/session/tools.js +0 -1
- package/dist/session/track.d.ts +2 -0
- package/dist/session/track.js +5 -0
- package/dist/state.d.ts +1 -3
- package/dist/types.d.ts +0 -11
- package/package.json +2 -2
- package/src/constants.ts +0 -25
- package/src/deps.ts +1 -8
- package/src/index.ts +0 -1
- package/src/legacy.ts +62 -0
- package/src/plugin.ts +8 -97
- package/src/session/events.ts +5 -12
- package/src/session/hooks.ts +8 -224
- package/src/session/tools.ts +0 -1
- package/src/session/track.ts +11 -0
- package/src/state.ts +0 -3
- package/src/types.ts +0 -18
- package/dist/agents/definitions.d.ts +0 -56
- package/dist/agents/definitions.js +0 -317
- package/dist/session/title.d.ts +0 -18
- package/dist/session/title.js +0 -81
- package/dist/session/usage.d.ts +0 -5
- package/dist/session/usage.js +0 -32
- package/dist/tools/subagent.d.ts +0 -29
- package/dist/tools/subagent.js +0 -197
- package/src/agents/definitions.ts +0 -354
- package/src/session/title.ts +0 -90
- package/src/session/usage.ts +0 -46
- package/src/tools/subagent.ts +0 -271
package/src/session/events.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** Subscribes to core events that affect free-pi state. */
|
|
2
2
|
|
|
3
3
|
import type { Plugin } from "@opencode/plugin";
|
|
4
|
+
import { fetchQuota } from "../api/quota.js";
|
|
4
5
|
import { closeFreePiSession } from "../api/session.js";
|
|
5
6
|
import { readCredentialsToken } from "../auth/credentials.js";
|
|
6
7
|
import { tokenFromCredential } from "../auth/credential.js";
|
|
@@ -21,7 +22,6 @@ import {
|
|
|
21
22
|
import {
|
|
22
23
|
markWireSessionDirty,
|
|
23
24
|
} from "./wire.js";
|
|
24
|
-
import { recordUsage } from "./usage.js";
|
|
25
25
|
|
|
26
26
|
function isAbortLike(error: any): boolean {
|
|
27
27
|
if (!error) return false;
|
|
@@ -39,7 +39,6 @@ const EVENT_TYPES = [
|
|
|
39
39
|
"session.execution.succeeded",
|
|
40
40
|
"session.execution.failed",
|
|
41
41
|
"session.execution.interrupted",
|
|
42
|
-
"session.usage.updated",
|
|
43
42
|
"session.step.ended",
|
|
44
43
|
"session.deleted",
|
|
45
44
|
"location.shutdown",
|
|
@@ -124,6 +123,9 @@ async function handleEvent(
|
|
|
124
123
|
}
|
|
125
124
|
case "session.execution.succeeded": {
|
|
126
125
|
endExecution(deps, event.data?.sessionID);
|
|
126
|
+
// Usage and cost are OpenCode's; the free-pi account quota is not, so a
|
|
127
|
+
// finished turn is the moment to refresh the picker's access filter.
|
|
128
|
+
void fetchQuota(deps).catch(() => undefined);
|
|
127
129
|
return;
|
|
128
130
|
}
|
|
129
131
|
case "session.execution.interrupted": {
|
|
@@ -134,21 +136,12 @@ async function handleEvent(
|
|
|
134
136
|
endExecution(deps, sessionID);
|
|
135
137
|
return;
|
|
136
138
|
}
|
|
137
|
-
case "session.usage.updated": {
|
|
138
|
-
const sessionID = event.data?.sessionID;
|
|
139
|
-
if (typeof sessionID !== "string" || !isFreePiSession(deps, sessionID)) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
recordUsage(deps, sessionID, event.data?.cost, event.data?.tokens);
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
139
|
case "session.step.ended": {
|
|
146
140
|
const sessionID = event.data?.sessionID;
|
|
147
141
|
if (typeof sessionID !== "string" || !isFreePiSession(deps, sessionID)) {
|
|
148
142
|
return;
|
|
149
143
|
}
|
|
150
|
-
|
|
151
|
-
// Step tokens are per request; usage.updated is cumulative.
|
|
144
|
+
// Step tokens are per request; OpenCode owns cumulative usage.
|
|
152
145
|
noteStepTokens(
|
|
153
146
|
deps,
|
|
154
147
|
deps.state.trackedModels.get(sessionID)?.modelID ?? "",
|
package/src/session/hooks.ts
CHANGED
|
@@ -8,19 +8,10 @@ import { resolveToken } from "../auth/token.js";
|
|
|
8
8
|
import {
|
|
9
9
|
AD_CONTEXT_HEADER,
|
|
10
10
|
AD_CONTEXT_OPT_OUT,
|
|
11
|
-
CONCURRENT_RETRY_BASE_MS,
|
|
12
|
-
CONCURRENT_RETRY_MAX,
|
|
13
|
-
CONCURRENT_RETRY_MAX_DELAY_MS,
|
|
14
11
|
CONTEXT_WINDOW,
|
|
15
12
|
DEFENSE_PROVIDER_ID,
|
|
16
13
|
PROVIDER_ID,
|
|
17
|
-
RETRY_BASE_DELAY_MS,
|
|
18
|
-
RETRY_MAX_DELAY_MS,
|
|
19
|
-
RETRY_MAX_RETRIES,
|
|
20
14
|
SUBAGENT_HEADER,
|
|
21
|
-
TRANSPORT_RETRY_BASE_MS,
|
|
22
|
-
TRANSPORT_RETRY_MAX,
|
|
23
|
-
TRANSPORT_RETRY_MAX_DELAY_MS,
|
|
24
15
|
} from "../constants.js";
|
|
25
16
|
import { currentLiveLimits, noteRejectedPrompt } from "../catalog/live.js";
|
|
26
17
|
import type { Deps } from "../deps.js";
|
|
@@ -40,8 +31,7 @@ import {
|
|
|
40
31
|
spuriousOverflowResponse,
|
|
41
32
|
} from "./overflow.js";
|
|
42
33
|
import { rememberReplayBody, storedBody } from "./replay.js";
|
|
43
|
-
import {
|
|
44
|
-
import { rememberFreePiSession } from "./track.js";
|
|
34
|
+
import { rememberFreePiSession, rememberTrackedModel } from "./track.js";
|
|
45
35
|
import {
|
|
46
36
|
hydrateWireSessionID,
|
|
47
37
|
markWireSessionDirty,
|
|
@@ -56,14 +46,12 @@ import {
|
|
|
56
46
|
recordToolStart,
|
|
57
47
|
toolHeaders,
|
|
58
48
|
} from "./tools.js";
|
|
59
|
-
import { rememberTrackedModel } from "./usage.js";
|
|
60
49
|
|
|
61
50
|
type Registration = { dispose: () => Promise<void> };
|
|
62
51
|
type SessionHookName =
|
|
63
52
|
| "context"
|
|
64
53
|
| "compaction"
|
|
65
54
|
| "generate"
|
|
66
|
-
| "title"
|
|
67
55
|
| "model.request"
|
|
68
56
|
| "http.request"
|
|
69
57
|
| "http.response"
|
|
@@ -99,16 +87,6 @@ async function applyGeneration(
|
|
|
99
87
|
if (!isFreePiProvider(event.model?.providerID)) return;
|
|
100
88
|
rememberFreePiSession(deps, event.sessionID);
|
|
101
89
|
|
|
102
|
-
// V1 disabled the title agent. OpenCode still asks for a title, so answer
|
|
103
|
-
// from the first user message: no free-pi request, no ad impression, and the
|
|
104
|
-
// session leaves the "New session" state immediately.
|
|
105
|
-
if (kind === "title") {
|
|
106
|
-
event.result = localTitle(event.messages);
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// The title agent gets a local answer, so no free-pi request is made.
|
|
111
|
-
|
|
112
90
|
const modelID = event.model?.id;
|
|
113
91
|
// Remember the choice so a `model_requires_credits` failure can hide exactly
|
|
114
92
|
// the model that was rejected instead of the whole provider.
|
|
@@ -215,209 +193,16 @@ async function applyModelRequest(deps: Deps, event: any): Promise<void> {
|
|
|
215
193
|
}
|
|
216
194
|
}
|
|
217
195
|
|
|
218
|
-
/** `concurrent` is free-pi's per-session 429 ("one request at a time"). */
|
|
219
|
-
function isConcurrentFailure(error: any): boolean {
|
|
220
|
-
if (!error) return false;
|
|
221
|
-
const body =
|
|
222
|
-
typeof error.response?.body === "string" ? error.response.body : "";
|
|
223
|
-
const message = typeof error.message === "string" ? error.message : "";
|
|
224
|
-
return (
|
|
225
|
-
/one request at a time/i.test(message) ||
|
|
226
|
-
/one request at a time/i.test(body) ||
|
|
227
|
-
/"concurrent"/.test(body)
|
|
228
|
-
);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Limits and account blocks do not recover by retrying. pi's own retry helper
|
|
233
|
-
* treats them as terminal (`NON_RETRYABLE_PROVIDER_LIMIT_ERROR_PATTERN`), but
|
|
234
|
-
* OpenCode retries every 429 by default, which surfaces as an endless
|
|
235
|
-
* "Retrying…". The response rewrite turns most of these into a 400; this guard
|
|
236
|
-
* covers the rest and keeps the CLI's behavior.
|
|
237
|
-
*/
|
|
238
|
-
const TERMINAL_RETRY_CODES = new Set([
|
|
239
|
-
"daily_cap",
|
|
240
|
-
"hourly_ceiling",
|
|
241
|
-
"rolling_cap",
|
|
242
|
-
"global_cap",
|
|
243
|
-
"account_ceiling",
|
|
244
|
-
"free_usage_limit",
|
|
245
|
-
"premium_allowance",
|
|
246
|
-
"guest_allowance",
|
|
247
|
-
"model_requires_credits",
|
|
248
|
-
"insufficient_credits",
|
|
249
|
-
"ads_required",
|
|
250
|
-
"account_review",
|
|
251
|
-
"region_unavailable",
|
|
252
|
-
"unauthorized",
|
|
253
|
-
"expired_token",
|
|
254
|
-
"guest_login_required",
|
|
255
|
-
"consent_required",
|
|
256
|
-
"upgrade_required",
|
|
257
|
-
"reward_required",
|
|
258
|
-
"content_filter",
|
|
259
|
-
"subagents_unavailable",
|
|
260
|
-
]);
|
|
261
|
-
|
|
262
|
-
const TERMINAL_RETRY_PATTERN =
|
|
263
|
-
/free usage limit|monthly usage limit|available balance|insufficient_quota|out of budget|quota exceeded|billing|subscription_sharing_usage_limit_exceeded/i;
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* A request that never reached the gateway. `provider.transport` covers the
|
|
267
|
-
* typed path, while the pattern catches bare fetch errors. These are worth
|
|
268
|
-
* retrying beyond the usual budget: a brief offline moment or a background
|
|
269
|
-
* service restart is not a provider limit.
|
|
270
|
-
*/
|
|
271
|
-
const TRANSPORT_RETRY_PATTERN =
|
|
272
|
-
/ECONNREFUSED|ECONNRESET|ETIMEDOUT|ENOTFOUND|EHOSTUNREACH|ENETUNREACH|EAI_AGAIN|EPIPE|socket hang up|fetch failed|Unable to connect|connection (?:refused|reset)/i;
|
|
273
|
-
|
|
274
|
-
function isTransportFailure(error: any): boolean {
|
|
275
|
-
const type = typeof error?.type === "string" ? error.type : "";
|
|
276
|
-
if (/transport|network|connection/i.test(type)) return true;
|
|
277
|
-
const message = `${error?.message ?? ""}\n${error?.cause?.message ?? ""}`;
|
|
278
|
-
return TRANSPORT_RETRY_PATTERN.test(message);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
196
|
/**
|
|
282
|
-
*
|
|
283
|
-
*
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*/
|
|
288
|
-
function isServerFailure(error: any): boolean {
|
|
289
|
-
const status =
|
|
290
|
-
error?.response?.status ??
|
|
291
|
-
(typeof error?.status === "number" ? error.status : undefined);
|
|
292
|
-
if (typeof status === "number" && status >= 500 && status <= 599) {
|
|
293
|
-
return true;
|
|
294
|
-
}
|
|
295
|
-
const message = typeof error?.message === "string" ? error.message : "";
|
|
296
|
-
return /server error|temporarily unavailable|try again later|image_screen_unavailable/i.test(
|
|
297
|
-
message,
|
|
298
|
-
);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
function isTerminalFailure(error: any): boolean {
|
|
302
|
-
if (
|
|
303
|
-
error?.type === "aborted" ||
|
|
304
|
-
/aborted|cancelled|canceled|interrupted|AbortError/i.test(
|
|
305
|
-
`${error?.message ?? ""}`,
|
|
306
|
-
)
|
|
307
|
-
) {
|
|
308
|
-
return true;
|
|
309
|
-
}
|
|
310
|
-
const parsed = parseFreePiError(error, true);
|
|
311
|
-
if (parsed?.code && TERMINAL_RETRY_CODES.has(parsed.code)) return true;
|
|
312
|
-
const body =
|
|
313
|
-
typeof error?.response?.body === "string" ? error.response.body : "";
|
|
314
|
-
const message = typeof error?.message === "string" ? error.message : "";
|
|
315
|
-
return TERMINAL_RETRY_PATTERN.test(`${message}\n${body}`);
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* pi retries at most three times with `min(2s * 2^(n-1), 60s)`. OpenCode's
|
|
320
|
-
* `attempt` counts the initial call as 1, so pi's attempt is `attempt - 1`.
|
|
321
|
-
* Non-retryable decisions are left alone.
|
|
322
|
-
*
|
|
323
|
-
* The one exception is `concurrent`: OpenCode treats the free-pi 429 as fatal,
|
|
324
|
-
* and the server can leave a per-session lock behind that resets do not clear.
|
|
325
|
-
* Rotating the wire session id and retrying turns that into a normal retry.
|
|
197
|
+
* Retries belong to OpenCode's session runner: it decides whether an error is
|
|
198
|
+
* retryable, how many times, and the delay. The one thing the runner cannot
|
|
199
|
+
* know is that free-pi holds a per-session request slot and that a failed
|
|
200
|
+
* attempt can leave it marked busy, so the next attempt must use a fresh wire
|
|
201
|
+
* id. This hook only arms that rotation and never touches `decision`.
|
|
326
202
|
*/
|
|
327
203
|
function applyRetryPolicy(deps: Deps, event: any): void {
|
|
328
|
-
if (
|
|
329
|
-
|
|
330
|
-
event.decision = { retry: false };
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
const previous = wireSessionID(deps, event.sessionID);
|
|
334
|
-
const next = rotateWireSessionID(deps, event.sessionID);
|
|
335
|
-
// Releasing the old id cleans up an orphaned slot; a leaked live lock
|
|
336
|
-
// ignores reset, which is exactly why the next request uses a fresh id.
|
|
337
|
-
void closeFreePiSession(deps, previous).catch(() => undefined);
|
|
338
|
-
deps.log.info("free-pi session busy; retrying with a fresh session id", {
|
|
339
|
-
sessionID: event.sessionID,
|
|
340
|
-
from: previous,
|
|
341
|
-
to: next,
|
|
342
|
-
attempt: event.attempt,
|
|
343
|
-
});
|
|
344
|
-
event.decision = {
|
|
345
|
-
retry: true,
|
|
346
|
-
delay: Math.min(
|
|
347
|
-
CONCURRENT_RETRY_BASE_MS * 2 ** (event.attempt - 1),
|
|
348
|
-
CONCURRENT_RETRY_MAX_DELAY_MS,
|
|
349
|
-
),
|
|
350
|
-
};
|
|
351
|
-
return;
|
|
352
|
-
}
|
|
353
|
-
if (isTerminalFailure(event.error)) {
|
|
354
|
-
// Remember the broken stream too, so the next turn rotates its wire id
|
|
355
|
-
// instead of running into the stale per-session lock.
|
|
356
|
-
markWireSessionDirty(deps, event.sessionID);
|
|
357
|
-
event.decision = { retry: false };
|
|
358
|
-
return;
|
|
359
|
-
}
|
|
360
|
-
if (isTransportFailure(event.error)) {
|
|
361
|
-
if (event.attempt > TRANSPORT_RETRY_MAX + 1) {
|
|
362
|
-
event.decision = { retry: false };
|
|
363
|
-
return;
|
|
364
|
-
}
|
|
365
|
-
// A connection that dropped mid-turn can leave the gateway's per-session
|
|
366
|
-
// slot marked busy, so the next attempt should not reuse the wire id.
|
|
367
|
-
markWireSessionDirty(deps, event.sessionID);
|
|
368
|
-
const attempt = Math.max(1, event.attempt - 1);
|
|
369
|
-
event.decision = {
|
|
370
|
-
retry: true,
|
|
371
|
-
delay: Math.min(
|
|
372
|
-
TRANSPORT_RETRY_BASE_MS * 2 ** (attempt - 1),
|
|
373
|
-
TRANSPORT_RETRY_MAX_DELAY_MS,
|
|
374
|
-
),
|
|
375
|
-
};
|
|
376
|
-
deps.log.warn("free-pi could not be reached; retrying", {
|
|
377
|
-
sessionID: event.sessionID,
|
|
378
|
-
attempt: event.attempt,
|
|
379
|
-
delay: event.decision.delay,
|
|
380
|
-
error: typeof event.error?.message === "string" ? event.error.message : undefined,
|
|
381
|
-
});
|
|
382
|
-
return;
|
|
383
|
-
}
|
|
384
|
-
// A 5xx from the gateway (`image_screen_unavailable` was measured live as a
|
|
385
|
-
// 503) is the server having a bad moment, not the request being wrong. The
|
|
386
|
-
// default retry would stop after three attempts even though the outage
|
|
387
|
-
// usually clears in seconds, so treat it like a transport failure: rotate
|
|
388
|
-
// the wire id and keep trying within the transport budget.
|
|
389
|
-
if (isServerFailure(event.error)) {
|
|
390
|
-
if (event.attempt > TRANSPORT_RETRY_MAX + 1) {
|
|
391
|
-
event.decision = { retry: false };
|
|
392
|
-
return;
|
|
393
|
-
}
|
|
394
|
-
markWireSessionDirty(deps, event.sessionID);
|
|
395
|
-
const attempt = Math.max(1, event.attempt - 1);
|
|
396
|
-
event.decision = {
|
|
397
|
-
retry: true,
|
|
398
|
-
delay: Math.min(
|
|
399
|
-
TRANSPORT_RETRY_BASE_MS * 2 ** (attempt - 1),
|
|
400
|
-
TRANSPORT_RETRY_MAX_DELAY_MS,
|
|
401
|
-
),
|
|
402
|
-
};
|
|
403
|
-
deps.log.warn("free-pi returned a server error; retrying", {
|
|
404
|
-
sessionID: event.sessionID,
|
|
405
|
-
attempt: event.attempt,
|
|
406
|
-
delay: event.decision.delay,
|
|
407
|
-
error: typeof event.error?.message === "string" ? event.error.message : undefined,
|
|
408
|
-
});
|
|
409
|
-
return;
|
|
410
|
-
}
|
|
411
|
-
if (event.attempt > RETRY_MAX_RETRIES + 1) {
|
|
412
|
-
event.decision = { retry: false };
|
|
413
|
-
return;
|
|
414
|
-
}
|
|
415
|
-
if (!event.decision?.retry) return;
|
|
416
|
-
const attempt = Math.max(1, event.attempt - 1);
|
|
417
|
-
event.decision.delay = Math.min(
|
|
418
|
-
RETRY_BASE_DELAY_MS * 2 ** (attempt - 1),
|
|
419
|
-
RETRY_MAX_DELAY_MS,
|
|
420
|
-
);
|
|
204
|
+
if (event.decision?.retry !== true) return;
|
|
205
|
+
markWireSessionDirty(deps, event.sessionID);
|
|
421
206
|
}
|
|
422
207
|
|
|
423
208
|
/**
|
|
@@ -652,7 +437,6 @@ export async function registerSessionHooks(
|
|
|
652
437
|
registrations,
|
|
653
438
|
);
|
|
654
439
|
await hookForProviders(ctx, "generate", generation("generate"), registrations);
|
|
655
|
-
await hookForProviders(ctx, "title", generation("title"), registrations);
|
|
656
440
|
// The generation hooks above only run for free-pi providers. These unscoped
|
|
657
441
|
// ones strip the plugin's tools from every other provider's requests.
|
|
658
442
|
for (const name of ["context", "compaction", "generate"] as const) {
|
package/src/session/tools.ts
CHANGED
package/src/session/track.ts
CHANGED
|
@@ -17,6 +17,17 @@ import type { Deps } from "../deps.js";
|
|
|
17
17
|
import { trimMap, trimSet } from "../utils/async.js";
|
|
18
18
|
import { forgetWireSessionID, wireSessionID } from "./wire.js";
|
|
19
19
|
|
|
20
|
+
/** The model a session asked for, used by the tool gate and image handling. */
|
|
21
|
+
export function rememberTrackedModel(
|
|
22
|
+
deps: Deps,
|
|
23
|
+
sessionID: string,
|
|
24
|
+
providerID: string,
|
|
25
|
+
modelID: string,
|
|
26
|
+
): void {
|
|
27
|
+
trimMap(deps.state.trackedModels, 200);
|
|
28
|
+
deps.state.trackedModels.set(sessionID, { providerID, modelID });
|
|
29
|
+
}
|
|
30
|
+
|
|
20
31
|
export function rememberFreePiSession(deps: Deps, sessionID: string): void {
|
|
21
32
|
if (!sessionID) return;
|
|
22
33
|
const sessions = deps.state.freePiSessions;
|
package/src/state.ts
CHANGED
|
@@ -7,7 +7,6 @@ import type {
|
|
|
7
7
|
FreePiError,
|
|
8
8
|
ModelRegistry,
|
|
9
9
|
QuotaSnapshot,
|
|
10
|
-
RequestUsage,
|
|
11
10
|
SessionResetOutcome,
|
|
12
11
|
TokenCheckState,
|
|
13
12
|
ToolStats,
|
|
@@ -35,8 +34,6 @@ export type RuntimeState = {
|
|
|
35
34
|
quotaPromise?: Promise<QuotaSnapshot>;
|
|
36
35
|
lastQuotaRefreshAt: number;
|
|
37
36
|
|
|
38
|
-
lastUsage?: RequestUsage;
|
|
39
|
-
lastUsageMessageID?: string;
|
|
40
37
|
lastFreePiError?: FreePiError;
|
|
41
38
|
lastErrorLogKey?: string;
|
|
42
39
|
lastErrorLogAt: number;
|
package/src/types.ts
CHANGED
|
@@ -285,21 +285,3 @@ export type SessionMessageInfo =
|
|
|
285
285
|
export type ReadContext = (
|
|
286
286
|
sessionID: string,
|
|
287
287
|
) => Promise<readonly SessionMessageInfo[]>;
|
|
288
|
-
|
|
289
|
-
/** Minimal view of an OpenCode V2 session header. */
|
|
290
|
-
export type SubagentSessionInfo = {
|
|
291
|
-
id: string;
|
|
292
|
-
parentID?: string;
|
|
293
|
-
title?: string;
|
|
294
|
-
agent?: string;
|
|
295
|
-
outcome?: string;
|
|
296
|
-
updated?: number;
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
export type ReadSessionInfo = (
|
|
300
|
-
sessionID: string,
|
|
301
|
-
) => Promise<SubagentSessionInfo | undefined>;
|
|
302
|
-
|
|
303
|
-
export type ListSubagentSessions = (
|
|
304
|
-
parentID: string,
|
|
305
|
-
) => Promise<readonly SubagentSessionInfo[]>;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Native OpenCode agents for free-pi.
|
|
3
|
-
*
|
|
4
|
-
* The provider CLI ships four agent personalities (scout, planner, worker,
|
|
5
|
-
* reviewer) with their own prompts and tool access. OpenCode's V2 plugin API
|
|
6
|
-
* cannot add agents through `AgentEditor`, but it loads Markdown agents from the
|
|
7
|
-
* global config directory. Installing those files is the supported way to map
|
|
8
|
-
* the CLI agents onto OpenCode's native `subagent` tool, so child sessions,
|
|
9
|
-
* background reports, permissions and the agent picker keep working normally.
|
|
10
|
-
*
|
|
11
|
-
* They use `mode: all`: OpenCode only lists non-subagent agents in the `/agents`
|
|
12
|
-
* picker, and only agents whose mode is not `primary` can run through the
|
|
13
|
-
* `subagent` tool. `all` satisfies both, so the same personalities are
|
|
14
|
-
* selectable as the main agent and spawnable as children.
|
|
15
|
-
*
|
|
16
|
-
* Files live under `agents/free-pi/`, which makes their IDs `free-pi/scout`,
|
|
17
|
-
* `free-pi/planner`, `free-pi/worker` and `free-pi/reviewer`.
|
|
18
|
-
*/
|
|
19
|
-
export declare const FREE_PI_AGENT_IDS: readonly ["free-pi/scout", "free-pi/planner", "free-pi/worker", "free-pi/reviewer"];
|
|
20
|
-
export type FreePiAgentID = (typeof FREE_PI_AGENT_IDS)[number];
|
|
21
|
-
export declare const FREE_PI_SKILL_ID = "free-pi";
|
|
22
|
-
export declare const FREE_PI_SKILL_NAME = "free-pi";
|
|
23
|
-
export declare const FREE_PI_SKILL_DESCRIPTION = "How free-pi works in OpenCode: its tools, the installed native subagents, allowance and limits, and where sessions and memory live.";
|
|
24
|
-
export declare const FREE_PI_SKILL = "# free-pi in OpenCode\n\nfree-pi is a free, ad-supported provider for OpenCode. You sign in with GitHub\nand ads in the session pay for the inference; there is no model API key. The\nfree daily allowance is shared by every free-pi model and every tool that spends\nit.\n\n## Tools\n- `free_pi_usage` shows today's remaining allowance, credits, token counts and\n the account tier. Read-only.\n- `free_pi_subagent_read` reads the transcript of a child session started with\n the `subagent` tool: its prompts, every tool call with input and result, and\n its final answer. Read-only; omit `sessionID` to list this session's children.\n- `look_at_image` asks a vision model about a PNG, JPEG or WebP inside the\n project. Use it when the current model takes text only, or when the image is a\n file on disk and you want a targeted answer instead of attaching it.\n- `generate_image` draws one image from a prompt and saves it under `images/`.\n- `web_search` searches the web for current information.\n- `docs_lookup` looks up current library and framework documentation.\n\nEvery tool except `free_pi_usage` spends allowance. Usage limits\n(`daily_cap`, `rolling_cap`, concurrency) are terminal: stop and continue\nwithout the tool instead of retrying.\n\n## Subagents\n\nUse OpenCode's native subagent tool with the agents this plugin installs:\n\n| Agent | Use it for |\n| --- | --- |\n| `free-pi/scout` | Read-only recon: locate code and return structured findings. |\n| `free-pi/planner` | Read-only plan for a change, ready for a worker. |\n| `free-pi/worker` | Carry out one full task in its own context window. |\n| `free-pi/reviewer` | Read-only review with file and line references. |\n\nSubagents inherit the free-pi model, share the same daily allowance, and run as\nchild sessions in the background. Keep large exploration in a subagent so it\ndoes not fill your own context. Use OpenCode's agent picker or the `subagent`\ntool; do not try to launch them through shell commands. The `subagent` tool\nreturns the child `sessionID` and OpenCode injects the child's report when it\ngoes idle; call `free_pi_subagent_read` with that id to see what the child ran\nand why its answer says what it says.\n\n## Memory and sessions\n\nOpenCode owns memory and context: `AGENTS.md` and configured instruction files\nare loaded natively, sessions persist and resume, and compaction folds long\nconversations into a summary. Put durable project facts in `AGENTS.md` (or a\nfile listed under `instructions`) instead of repeating them in every prompt.\n\n## Native integrations\n\nMCP servers, skills, commands, references and permissions are configured in\nOpenCode as usual; free-pi does not replace them. Prefer those native features\nover running an external CLI.\n";
|
|
25
|
-
/**
|
|
26
|
-
* The same skill as a native `SKILL.md`. OpenCode discovers it from the global
|
|
27
|
-
* skills directory, so the file, its ID, its permissions and the `skill` tool
|
|
28
|
-
* all belong to OpenCode instead of a runtime registration.
|
|
29
|
-
*/
|
|
30
|
-
export declare const FREE_PI_SKILL_FILE = "---\nname: free-pi\ndescription: How free-pi works in OpenCode: its tools, the installed native subagents, allowance and limits, and where sessions and memory live.\n---\n\n<!-- managed by @eduardo191labs/opencode-free-pi; delete this line to keep your own copy -->\n\n# free-pi in OpenCode\n\nfree-pi is a free, ad-supported provider for OpenCode. You sign in with GitHub\nand ads in the session pay for the inference; there is no model API key. The\nfree daily allowance is shared by every free-pi model and every tool that spends\nit.\n\n## Tools\n- `free_pi_usage` shows today's remaining allowance, credits, token counts and\n the account tier. Read-only.\n- `free_pi_subagent_read` reads the transcript of a child session started with\n the `subagent` tool: its prompts, every tool call with input and result, and\n its final answer. Read-only; omit `sessionID` to list this session's children.\n- `look_at_image` asks a vision model about a PNG, JPEG or WebP inside the\n project. Use it when the current model takes text only, or when the image is a\n file on disk and you want a targeted answer instead of attaching it.\n- `generate_image` draws one image from a prompt and saves it under `images/`.\n- `web_search` searches the web for current information.\n- `docs_lookup` looks up current library and framework documentation.\n\nEvery tool except `free_pi_usage` spends allowance. Usage limits\n(`daily_cap`, `rolling_cap`, concurrency) are terminal: stop and continue\nwithout the tool instead of retrying.\n\n## Subagents\n\nUse OpenCode's native subagent tool with the agents this plugin installs:\n\n| Agent | Use it for |\n| --- | --- |\n| `free-pi/scout` | Read-only recon: locate code and return structured findings. |\n| `free-pi/planner` | Read-only plan for a change, ready for a worker. |\n| `free-pi/worker` | Carry out one full task in its own context window. |\n| `free-pi/reviewer` | Read-only review with file and line references. |\n\nSubagents inherit the free-pi model, share the same daily allowance, and run as\nchild sessions in the background. Keep large exploration in a subagent so it\ndoes not fill your own context. Use OpenCode's agent picker or the `subagent`\ntool; do not try to launch them through shell commands. The `subagent` tool\nreturns the child `sessionID` and OpenCode injects the child's report when it\ngoes idle; call `free_pi_subagent_read` with that id to see what the child ran\nand why its answer says what it says.\n\n## Memory and sessions\n\nOpenCode owns memory and context: `AGENTS.md` and configured instruction files\nare loaded natively, sessions persist and resume, and compaction folds long\nconversations into a summary. Put durable project facts in `AGENTS.md` (or a\nfile listed under `instructions`) instead of repeating them in every prompt.\n\n## Native integrations\n\nMCP servers, skills, commands, references and permissions are configured in\nOpenCode as usual; free-pi does not replace them. Prefer those native features\nover running an external CLI.\n";
|
|
31
|
-
/** OpenCode's user-wide config directory, where it loads custom agents. */
|
|
32
|
-
export declare function openCodeConfigDir(): string;
|
|
33
|
-
export declare function freePiAgentPath(configDir: string, id: FreePiAgentID): string;
|
|
34
|
-
export declare function freePiSkillPath(configDir: string): string;
|
|
35
|
-
export type AgentInstallResult = {
|
|
36
|
-
readonly installed: FreePiAgentID[];
|
|
37
|
-
readonly skipped: FreePiAgentID[];
|
|
38
|
-
readonly changed: boolean;
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Writes the bundled agents into the OpenCode config directory so OpenCode's
|
|
42
|
-
* own loader and agent picker own them. Existing files without our marker are
|
|
43
|
-
* treated as user-owned and left untouched.
|
|
44
|
-
*/
|
|
45
|
-
export declare function installFreePiAgents(configDir?: string): Promise<AgentInstallResult>;
|
|
46
|
-
export type SkillInstallResult = {
|
|
47
|
-
readonly installed: boolean;
|
|
48
|
-
readonly skipped: boolean;
|
|
49
|
-
readonly changed: boolean;
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* Writes the free-pi skill as `skills/free-pi/SKILL.md`, the layout OpenCode's
|
|
53
|
-
* own skill loader reads. A file without our marker is user-owned and stays
|
|
54
|
-
* untouched, exactly like the agent files.
|
|
55
|
-
*/
|
|
56
|
-
export declare function installFreePiSkill(configDir?: string): Promise<SkillInstallResult>;
|