@eduardo191labs/opencode-free-pi 0.7.29 → 0.7.31
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 +21 -69
- package/dist/auth/credential.d.ts +0 -1
- package/dist/auth/credential.js +1 -11
- package/dist/auth/credentials.d.ts +0 -1
- package/dist/auth/credentials.js +0 -8
- package/dist/auth/jwt.d.ts +1 -2
- package/dist/auth/jwt.js +0 -26
- package/dist/catalog/live.js +2 -2
- package/dist/constants.d.ts +0 -3
- package/dist/constants.js +0 -3
- package/dist/deps.d.ts +1 -4
- package/dist/errors/handle.js +0 -1
- package/dist/errors/limit.d.ts +0 -2
- package/dist/errors/limit.js +0 -14
- package/dist/legacy.d.ts +17 -0
- package/dist/legacy.js +58 -0
- package/dist/plugin.js +10 -84
- package/dist/session/overflow.d.ts +0 -1
- package/dist/session/overflow.js +0 -3
- package/dist/session/tools.d.ts +1 -1
- package/dist/session/tools.js +0 -1
- package/dist/state.d.ts +1 -4
- package/dist/state.js +0 -2
- package/dist/tools/api.d.ts +1 -1
- package/dist/tools/api.js +1 -1
- package/dist/tools/web.js +1 -1
- package/dist/types.d.ts +0 -23
- package/dist/utils/numbers.d.ts +0 -1
- package/dist/utils/numbers.js +0 -6
- package/package.json +2 -2
- package/src/auth/credential.ts +1 -13
- package/src/auth/credentials.ts +0 -8
- package/src/auth/jwt.ts +1 -31
- package/src/catalog/live.ts +1 -2
- package/src/constants.ts +0 -4
- package/src/deps.ts +1 -8
- package/src/errors/handle.ts +0 -1
- package/src/errors/limit.ts +0 -18
- package/src/legacy.ts +62 -0
- package/src/plugin.ts +11 -97
- package/src/session/hooks.ts +0 -1
- package/src/session/overflow.ts +0 -4
- package/src/session/tools.ts +0 -1
- package/src/state.ts +0 -6
- package/src/tools/api.ts +0 -1
- package/src/tools/usage.ts +0 -1
- package/src/tools/web.ts +1 -1
- package/src/types.ts +0 -31
- package/src/utils/numbers.ts +0 -8
- package/dist/agents/definitions.d.ts +0 -56
- package/dist/agents/definitions.js +0 -317
- package/dist/tools/subagent.d.ts +0 -29
- package/dist/tools/subagent.js +0 -197
- package/src/agents/definitions.ts +0 -354
- package/src/tools/subagent.ts +0 -271
package/README.md
CHANGED
|
@@ -280,7 +280,6 @@ demás modelos no las ven ni pueden ejecutarlas.
|
|
|
280
280
|
| `web_search` | Busca en la web y devuelve título, URL, fecha y texto de cada resultado. |
|
|
281
281
|
| `docs_lookup` | Consulta documentación actual de una librería o framework. |
|
|
282
282
|
| `free_pi_usage` | Muestra cuota restante, créditos, tokens y tier de la cuenta. |
|
|
283
|
-
| `free_pi_subagent_read` | Lee la transcripción de una sesión hija: prompts, herramientas y respuesta. |
|
|
284
283
|
|
|
285
284
|
`generate_image` acepta `prompt`, `aspect_ratio` (`1:1`, `16:9`, `9:16`, `4:3`,
|
|
286
285
|
`3:2`) y un `name` opcional para el archivo. Rechaza tipos que no sean PNG,
|
|
@@ -300,83 +299,36 @@ con su hora de recarga en ET, los créditos premium o de referidos y los tokens
|
|
|
300
299
|
de hoy y de por vida. Si el servidor asigna el carril lento, incluye el aviso
|
|
301
300
|
del CLI.
|
|
302
301
|
|
|
303
|
-
`free_pi_subagent_read` recibe el `sessionID` que devuelve la herramienta
|
|
304
|
-
`subagent` y devuelve la conversación de esa sesión hija: el prompt recibido,
|
|
305
|
-
cada llamada a herramienta con su entrada y su resultado, y el texto final del
|
|
306
|
-
subagente. Antes de leer comprueba con `session.get` que `parentID` sea la sesión
|
|
307
|
-
que llama, así que no puede abrir sesiones ajenas. Sin `sessionID` lista las
|
|
308
|
-
sesiones hijas de la sesión actual con su agente y su resultado. El transcript se
|
|
309
|
-
mantiene dentro de un presupuesto de caracteres (`maxChars`, 60k por defecto) y,
|
|
310
|
-
si no cabe, conserva los turnos más recientes y lo indica.
|
|
311
|
-
|
|
312
302
|
La compra de créditos y la guía de free-pi ya no se exponen como herramientas:
|
|
313
303
|
se resuelven en el dashboard y la documentación de free-pi, sin gastar cuota ni
|
|
314
304
|
añadir ruido al contexto.
|
|
315
305
|
|
|
316
|
-
## Agentes y
|
|
317
|
-
|
|
318
|
-
El CLI incluye cuatro personalidades de agente. El plugin las instala como
|
|
319
|
-
agentes Markdown nativos de OpenCode en el directorio global de configuración:
|
|
320
|
-
|
|
321
|
-
```text
|
|
322
|
-
~/.config/opencode/agents/free-pi/
|
|
323
|
-
├── scout.md → free-pi/scout
|
|
324
|
-
├── planner.md → free-pi/planner
|
|
325
|
-
├── worker.md → free-pi/worker
|
|
326
|
-
└── reviewer.md → free-pi/reviewer
|
|
327
|
-
```
|
|
328
|
-
|
|
329
|
-
| Agente | Uso |
|
|
330
|
-
| ----------------- | ---------------------------------------------------------------- |
|
|
331
|
-
| `free-pi/scout` | Reconocimiento de solo lectura; devuelve hallazgos estructurados. |
|
|
332
|
-
| `free-pi/planner` | Plan de implementación de solo lectura, listo para un worker. |
|
|
333
|
-
| `free-pi/worker` | Ejecuta una tarea completa en su propia ventana de contexto. |
|
|
334
|
-
| `free-pi/reviewer`| Revisión de solo lectura con archivo y línea. |
|
|
335
|
-
|
|
336
|
-
Usan `mode: all`, así que aparecen en el selector `/agents` de la TUI como
|
|
337
|
-
agente principal **y** se pueden lanzar con la herramienta `subagent` nativa.
|
|
338
|
-
Heredan el modelo free-pi de la sesión padre. Como subagentes corren en segundo
|
|
339
|
-
plano, comparten el allowance diario y envían su informe al agente principal.
|
|
340
|
-
Así se conservan las sesiones hijas, los permisos, la profundidad de subagentes
|
|
341
|
-
y el resto del comportamiento nativo.
|
|
342
|
-
|
|
343
|
-
La herramienta `subagent` es la de OpenCode y está disponible para **cualquier
|
|
344
|
-
modelo**, no solo para los agentes `free-pi/*`: también puede lanzarlos un
|
|
345
|
-
modelo de otro proveedor configurado en OpenCode. El plugin garantiza además que
|
|
346
|
-
todos los modelos gratuitos anuncien soporte de tools, de modo que el runner
|
|
347
|
-
nunca oculte `subagent` por una capacidad incorrecta de models.dev. Cuando el
|
|
348
|
-
hijo termina, OpenCode inyecta su informe en la sesión padre; para ver lo que
|
|
349
|
-
realmente ejecutó, el padre llama a `free_pi_subagent_read` con el `sessionID`
|
|
350
|
-
del hijo.
|
|
306
|
+
## Agentes y skills
|
|
351
307
|
|
|
352
|
-
|
|
353
|
-
|
|
308
|
+
Los agentes, sus prompts y las skills son de OpenCode. El plugin no define
|
|
309
|
+
personalidades, no escribe archivos en el directorio de configuración, no
|
|
310
|
+
registra skills y no inyecta instrucciones propias en la sesión. Se usan los
|
|
311
|
+
agentes nativos (`build`, `plan`, `general`, `explore`), los agentes y skills que
|
|
312
|
+
el usuario configure en OpenCode, y la herramienta `subagent` tal cual.
|
|
354
313
|
|
|
355
|
-
|
|
314
|
+
Las versiones anteriores del plugin dejaban cuatro agentes Markdown y una skill
|
|
315
|
+
en `~/.config/opencode`. Al arrancar, esta versión elimina solo esos archivos si
|
|
316
|
+
conservan su marca de gestión; cualquier archivo que el usuario haya editado o
|
|
317
|
+
reemplazado se respeta y sigue siendo de OpenCode.
|
|
356
318
|
|
|
357
|
-
|
|
319
|
+
La herramienta `subagent` está disponible para **cualquier** modelo, no solo
|
|
320
|
+
para los free-pi. El plugin garantiza además que todos los modelos gratuitos
|
|
321
|
+
anuncien soporte de tools, de modo que el runner nunca oculte `subagent` por una
|
|
322
|
+
capacidad incorrecta de models.dev. Cuando el hijo termina, OpenCode inyecta su
|
|
323
|
+
informe en la sesión padre y lo repite tras cada ronda posterior.
|
|
358
324
|
|
|
359
|
-
|
|
360
|
-
~/.config/opencode/skills/free-pi/SKILL.md
|
|
361
|
-
```
|
|
325
|
+
## Contexto y memoria
|
|
362
326
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
Cada petición principal de free-pi recibe además una guía breve que pide
|
|
370
|
-
delegar el trabajo grande en `free-pi/scout`, `free-pi/planner`,
|
|
371
|
-
`free-pi/worker` o `free-pi/reviewer` con `subagent`, cargar skills con `skill`
|
|
372
|
-
y seguir `AGENTS.md` en lugar de inventar convenciones. Esa guía solo se añade a
|
|
373
|
-
las peticiones de `free-pi` y `free-pi-defense`.
|
|
374
|
-
|
|
375
|
-
La memoria, las sesiones y el contexto son los de OpenCode: `AGENTS.md` y los
|
|
376
|
-
archivos de `instructions` se cargan de forma nativa, las sesiones persisten y
|
|
377
|
-
se reanudan, y la compactación pliega conversaciones largas en un resumen. El
|
|
378
|
-
plugin no crea archivos de memoria propios ni duplica el almacén de sesiones;
|
|
379
|
-
los hechos duraderos del proyecto van en `AGENTS.md`.
|
|
327
|
+
La memoria, las sesiones, el contexto y la compactación son los de OpenCode:
|
|
328
|
+
`AGENTS.md` y los archivos de `instructions` se cargan de forma nativa, las
|
|
329
|
+
sesiones persisten y se reanudan, y la compactación pliega conversaciones largas
|
|
330
|
+
en un resumen. El plugin no crea archivos de memoria propios, no duplica el
|
|
331
|
+
almacén de sesiones y no añade prompts de sistema propios.
|
|
380
332
|
|
|
381
333
|
Las herramientas `todo` y `ask_user` del CLI no se duplican: OpenCode ya tiene
|
|
382
334
|
un gestor de todos nativo y su propia herramienta de preguntas al usuario, con
|
|
@@ -2,4 +2,3 @@
|
|
|
2
2
|
import type { Credential } from "@opencode/schema/credential";
|
|
3
3
|
export declare function tokenFromCredential(credential: Credential.Value | undefined): string | undefined;
|
|
4
4
|
export declare function expiryFromCredential(credential: Credential.Value | undefined): number | undefined;
|
|
5
|
-
export declare function issuerFromCredential(credential: Credential.Value | undefined): string | undefined;
|
package/dist/auth/credential.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/** Translates OpenCode V2 credentials into free-pi tokens. */
|
|
2
|
-
import {
|
|
3
|
-
import { normalizeIssuer } from "../utils/urls.js";
|
|
2
|
+
import { tokenExpiry } from "./jwt.js";
|
|
4
3
|
export function tokenFromCredential(credential) {
|
|
5
4
|
if (!credential)
|
|
6
5
|
return undefined;
|
|
@@ -23,12 +22,3 @@ export function expiryFromCredential(credential) {
|
|
|
23
22
|
const token = tokenFromCredential(credential);
|
|
24
23
|
return token ? tokenExpiry(token) : undefined;
|
|
25
24
|
}
|
|
26
|
-
export function issuerFromCredential(credential) {
|
|
27
|
-
if (!credential)
|
|
28
|
-
return undefined;
|
|
29
|
-
if (credential.type === "oauth")
|
|
30
|
-
return decodeRefreshToken(credential.refresh)?.issuer;
|
|
31
|
-
if (credential.type === "key")
|
|
32
|
-
return normalizeIssuer(credential.metadata?.issuer);
|
|
33
|
-
return undefined;
|
|
34
|
-
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/** The free-pi credential file written by the free-pi CLI. */
|
|
2
2
|
import type { Credentials } from "../types.js";
|
|
3
3
|
export declare function credentialsPath(): string;
|
|
4
|
-
export declare function credentialsDisplayPath(): string;
|
|
5
4
|
export declare function readCredentials(): Promise<Credentials | undefined>;
|
|
6
5
|
export declare function readCredentialsToken(): Promise<string | undefined>;
|
|
7
6
|
export declare function writeCredentials(token: string, issuer?: string): Promise<void>;
|
package/dist/auth/credentials.js
CHANGED
|
@@ -9,14 +9,6 @@ export function credentialsPath() {
|
|
|
9
9
|
return resolve(override);
|
|
10
10
|
return join(homedir(), ".free-pi", "agent", "credentials.json");
|
|
11
11
|
}
|
|
12
|
-
export function credentialsDisplayPath() {
|
|
13
|
-
const override = process.env.FREEPI_CREDENTIALS_PATH?.trim();
|
|
14
|
-
if (override)
|
|
15
|
-
return override;
|
|
16
|
-
return process.platform === "win32"
|
|
17
|
-
? join("%USERPROFILE%", ".free-pi", "agent", "credentials.json")
|
|
18
|
-
: "~/.free-pi/agent/credentials.json";
|
|
19
|
-
}
|
|
20
12
|
export async function readCredentials() {
|
|
21
13
|
const envToken = process.env.FREEPI_JWT?.trim();
|
|
22
14
|
if (envToken)
|
package/dist/auth/jwt.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/** JWT and refresh-token encoding helpers. */
|
|
2
|
-
import type {
|
|
2
|
+
import type { JwtClaims } from "../types.js";
|
|
3
3
|
export declare function parseJwtClaims(token: string): JwtClaims | undefined;
|
|
4
4
|
export declare function tokenExpiry(token: string): number | undefined;
|
|
5
5
|
export declare function tokenNeedsRefresh(token: string, expires?: number): boolean;
|
|
6
6
|
export declare function encodeRefreshToken(token: string, issuer?: string): string;
|
|
7
|
-
export declare function decodeRefreshToken(value: string | undefined): Credentials | undefined;
|
package/dist/auth/jwt.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/** JWT and refresh-token encoding helpers. */
|
|
2
2
|
import { AUTH_SKEW_MS, REFRESH_PREFIX, } from "../constants.js";
|
|
3
|
-
import { normalizeIssuer } from "../utils/urls.js";
|
|
4
3
|
export function parseJwtClaims(token) {
|
|
5
4
|
const payload = token.split(".")[1];
|
|
6
5
|
if (!payload)
|
|
@@ -33,28 +32,3 @@ export function encodeRefreshToken(token, issuer) {
|
|
|
33
32
|
const payload = JSON.stringify(issuer ? { token, issuer } : { token });
|
|
34
33
|
return `${REFRESH_PREFIX}${Buffer.from(payload).toString("base64url")}`;
|
|
35
34
|
}
|
|
36
|
-
export function decodeRefreshToken(value) {
|
|
37
|
-
if (!value)
|
|
38
|
-
return undefined;
|
|
39
|
-
if (value.startsWith(REFRESH_PREFIX)) {
|
|
40
|
-
try {
|
|
41
|
-
const parsed = JSON.parse(Buffer.from(value.slice(REFRESH_PREFIX.length), "base64url").toString("utf8"));
|
|
42
|
-
if (typeof parsed.token === "string" && parsed.token.length > 0) {
|
|
43
|
-
const issuer = normalizeIssuer(parsed.issuer);
|
|
44
|
-
return issuer
|
|
45
|
-
? { token: parsed.token, issuer }
|
|
46
|
-
: { token: parsed.token };
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
catch { }
|
|
50
|
-
}
|
|
51
|
-
try {
|
|
52
|
-
const parsed = JSON.parse(value);
|
|
53
|
-
if (typeof parsed.token === "string" && parsed.token.length > 0) {
|
|
54
|
-
const issuer = normalizeIssuer(parsed.issuer);
|
|
55
|
-
return issuer ? { token: parsed.token, issuer } : { token: parsed.token };
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
catch { }
|
|
59
|
-
return { token: value };
|
|
60
|
-
}
|
package/dist/catalog/live.js
CHANGED
|
@@ -260,7 +260,7 @@ export function settleWindow(samples) {
|
|
|
260
260
|
* accepted probe, so a process that exits mid-verification keeps the smallest
|
|
261
261
|
* proven value instead of losing the whole run.
|
|
262
262
|
*/
|
|
263
|
-
async function commitWindow(
|
|
263
|
+
async function commitWindow(tokens, modelID) {
|
|
264
264
|
const limits = (cached ??= emptyLimits());
|
|
265
265
|
// The measured ceiling belongs to the model probed, not to every model: the
|
|
266
266
|
// gateway's limit is per model, and a global window taken from one model
|
|
@@ -344,7 +344,7 @@ export async function verifyGatewayWindow(deps, options = {}) {
|
|
|
344
344
|
const settled = settleWindow(samples);
|
|
345
345
|
if (settled) {
|
|
346
346
|
// Never go below the window that already worked for this account.
|
|
347
|
-
verified = await commitWindow(
|
|
347
|
+
verified = await commitWindow(Math.max(settled, floor), modelID);
|
|
348
348
|
}
|
|
349
349
|
if (accepted >= MAX_WINDOW)
|
|
350
350
|
break;
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
/** Identifiers and defaults shared by every part of the plugin. */
|
|
2
2
|
export declare const PROVIDER_ID = "free-pi";
|
|
3
3
|
export declare const DEFENSE_PROVIDER_ID = "free-pi-defense";
|
|
4
|
-
export declare const INTEGRATION_ID = "free-pi";
|
|
5
|
-
export declare const PROVIDER_NAME = "Free Pi";
|
|
6
|
-
export declare const DEFENSE_PROVIDER_NAME = "Free Pi Defense";
|
|
7
4
|
export declare const DEFAULT_BASE_URL = "https://api.freepi.ai";
|
|
8
5
|
export declare const DEFAULT_CLIENT_VERSION = "0.6.28";
|
|
9
6
|
export declare const CONSENT_VERSION = "4";
|
package/dist/constants.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
/** Identifiers and defaults shared by every part of the plugin. */
|
|
2
2
|
export const PROVIDER_ID = "free-pi";
|
|
3
3
|
export const DEFENSE_PROVIDER_ID = "free-pi-defense";
|
|
4
|
-
export const INTEGRATION_ID = PROVIDER_ID;
|
|
5
|
-
export const PROVIDER_NAME = "Free Pi";
|
|
6
|
-
export const DEFENSE_PROVIDER_NAME = "Free Pi Defense";
|
|
7
4
|
export const DEFAULT_BASE_URL = "https://api.freepi.ai";
|
|
8
5
|
export const DEFAULT_CLIENT_VERSION = "0.6.28";
|
|
9
6
|
export const CONSENT_VERSION = "4";
|
package/dist/deps.d.ts
CHANGED
|
@@ -3,15 +3,12 @@ import type { Credential } from "@opencode/schema/credential";
|
|
|
3
3
|
import type { Plugin } from "@opencode/plugin";
|
|
4
4
|
import type { Logger } from "./logging.js";
|
|
5
5
|
import type { RuntimeState } from "./state.js";
|
|
6
|
-
import type {
|
|
6
|
+
import type { ReadContext } from "./types.js";
|
|
7
7
|
export type Deps = {
|
|
8
8
|
readonly state: RuntimeState;
|
|
9
9
|
readonly log: Logger;
|
|
10
10
|
readonly activeCredential: () => Promise<Credential.Value | undefined>;
|
|
11
11
|
readonly readContext: ReadContext;
|
|
12
|
-
/** Session headers, used to prove a session is really this session's child. */
|
|
13
|
-
readonly readSession?: ReadSessionInfo;
|
|
14
|
-
readonly listSubagentSessions?: ListSubagentSessions;
|
|
15
12
|
/** Plugin-scoped durable storage, used to reconnect provider sessions. */
|
|
16
13
|
readonly storage?: Plugin.Context["storage"];
|
|
17
14
|
};
|
package/dist/errors/handle.js
CHANGED
|
@@ -8,7 +8,6 @@ export async function handleFreePiError(deps, error, opts = {}) {
|
|
|
8
8
|
const parsed = parseFreePiError(error, opts.allowRaw === true);
|
|
9
9
|
if (!parsed)
|
|
10
10
|
return;
|
|
11
|
-
deps.state.lastFreePiError = parsed;
|
|
12
11
|
if (parsed.status === 401 ||
|
|
13
12
|
parsed.code === "unauthorized" ||
|
|
14
13
|
parsed.code === "expired_token") {
|
package/dist/errors/limit.d.ts
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
* Rewrites long-lived free-pi limit responses so the client shows the friendly
|
|
3
3
|
* message instead of a raw 429. Mirrors the fetch wrapper used by the V1 plugin.
|
|
4
4
|
*/
|
|
5
|
-
/** The free-pi overflow code carried by a response, when it is one. */
|
|
6
|
-
export declare function overflowCodeOf(response: Response): Promise<string | undefined>;
|
|
7
5
|
/**
|
|
8
6
|
* Returns a replacement response when `response` is a free-pi context overflow.
|
|
9
7
|
* The replacement is a 400 with a message OpenCode recognizes as context
|
package/dist/errors/limit.js
CHANGED
|
@@ -105,20 +105,6 @@ function contextOverflowCode(body) {
|
|
|
105
105
|
catch { }
|
|
106
106
|
return undefined;
|
|
107
107
|
}
|
|
108
|
-
/** The free-pi overflow code carried by a response, when it is one. */
|
|
109
|
-
export async function overflowCodeOf(response) {
|
|
110
|
-
if (response.status !== 413 &&
|
|
111
|
-
response.status !== 429 &&
|
|
112
|
-
response.status !== 400)
|
|
113
|
-
return undefined;
|
|
114
|
-
const body = await response
|
|
115
|
-
.clone()
|
|
116
|
-
.text()
|
|
117
|
-
.catch(() => "");
|
|
118
|
-
if (!body)
|
|
119
|
-
return undefined;
|
|
120
|
-
return contextOverflowCode(body);
|
|
121
|
-
}
|
|
122
108
|
/**
|
|
123
109
|
* Returns a replacement response when `response` is a free-pi context overflow.
|
|
124
110
|
* The replacement is a 400 with a message OpenCode recognizes as context
|
package/dist/legacy.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-time cleanup for files older plugin versions wrote into OpenCode's config
|
|
3
|
+
* directory.
|
|
4
|
+
*
|
|
5
|
+
* Agents, skills and their prompts belong to OpenCode. Earlier releases seeded
|
|
6
|
+
* a free-pi skill and four Markdown agents next to the user's own files, which
|
|
7
|
+
* kept those prompts active after the plugin stopped owning them. This removes
|
|
8
|
+
* only files that still carry the old management marker; anything the user
|
|
9
|
+
* edited or replaced is left untouched.
|
|
10
|
+
*/
|
|
11
|
+
/** OpenCode's user-wide config directory. */
|
|
12
|
+
export declare function openCodeConfigDir(): string;
|
|
13
|
+
/**
|
|
14
|
+
* Deletes the plugin-managed agent and skill files from previous versions and
|
|
15
|
+
* returns their paths. User-owned files are never touched.
|
|
16
|
+
*/
|
|
17
|
+
export declare function removeLegacyFreePiFiles(configDir?: string): Promise<string[]>;
|
package/dist/legacy.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-time cleanup for files older plugin versions wrote into OpenCode's config
|
|
3
|
+
* directory.
|
|
4
|
+
*
|
|
5
|
+
* Agents, skills and their prompts belong to OpenCode. Earlier releases seeded
|
|
6
|
+
* a free-pi skill and four Markdown agents next to the user's own files, which
|
|
7
|
+
* kept those prompts active after the plugin stopped owning them. This removes
|
|
8
|
+
* only files that still carry the old management marker; anything the user
|
|
9
|
+
* edited or replaced is left untouched.
|
|
10
|
+
*/
|
|
11
|
+
import { readFile, rm, rmdir } from "node:fs/promises";
|
|
12
|
+
import { homedir } from "node:os";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
const MARKER = "<!-- managed by @eduardo191labs/opencode-free-pi; delete this line to keep your own copy -->";
|
|
15
|
+
const LEGACY_FILES = [
|
|
16
|
+
["agents", "free-pi", "scout.md"],
|
|
17
|
+
["agents", "free-pi", "planner.md"],
|
|
18
|
+
["agents", "free-pi", "worker.md"],
|
|
19
|
+
["agents", "free-pi", "reviewer.md"],
|
|
20
|
+
["skills", "free-pi", "SKILL.md"],
|
|
21
|
+
];
|
|
22
|
+
/** OpenCode's user-wide config directory. */
|
|
23
|
+
export function openCodeConfigDir() {
|
|
24
|
+
const explicit = process.env.OPENCODE_CONFIG_DIR?.trim();
|
|
25
|
+
if (explicit)
|
|
26
|
+
return explicit;
|
|
27
|
+
const xdg = process.env.XDG_CONFIG_HOME?.trim();
|
|
28
|
+
if (xdg)
|
|
29
|
+
return join(xdg, "opencode");
|
|
30
|
+
return join(homedir(), ".config", "opencode");
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Deletes the plugin-managed agent and skill files from previous versions and
|
|
34
|
+
* returns their paths. User-owned files are never touched.
|
|
35
|
+
*/
|
|
36
|
+
export async function removeLegacyFreePiFiles(configDir = openCodeConfigDir()) {
|
|
37
|
+
const removed = [];
|
|
38
|
+
for (const parts of LEGACY_FILES) {
|
|
39
|
+
const path = join(configDir, ...parts);
|
|
40
|
+
try {
|
|
41
|
+
const current = await readFile(path, "utf8");
|
|
42
|
+
if (!current.slice(0, 1024).includes(MARKER))
|
|
43
|
+
continue;
|
|
44
|
+
await rm(path, { force: true });
|
|
45
|
+
removed.push(path);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// Missing or unreadable: nothing to clean up.
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (removed.length > 0) {
|
|
52
|
+
// Drop the now-empty plugin folders without touching user-owned entries.
|
|
53
|
+
for (const parts of [["agents", "free-pi"], ["skills", "free-pi"]]) {
|
|
54
|
+
await rmdir(join(configDir, ...parts)).catch(() => undefined);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return removed;
|
|
58
|
+
}
|
package/dist/plugin.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/** OpenCode V2 plugin entry point for free-pi. */
|
|
2
2
|
import { Plugin } from "@opencode/plugin";
|
|
3
|
-
import { FREE_PI_SKILL, FREE_PI_SKILL_DESCRIPTION, FREE_PI_SKILL_ID, FREE_PI_SKILL_NAME, freePiSkillPath, installFreePiAgents, installFreePiSkill, openCodeConfigDir, } from "./agents/definitions.js";
|
|
4
3
|
import { fetchQuota } from "./api/quota.js";
|
|
5
4
|
import { closeFreePiSession } from "./api/session.js";
|
|
6
5
|
import { readCredentialsToken } from "./auth/credentials.js";
|
|
@@ -12,6 +11,7 @@ import { applyProvider } from "./catalog/v2.js";
|
|
|
12
11
|
import { CATALOG_RECOVERY_DELAYS_MS, CATALOG_RECOVERY_INTERVAL_MS, CATALOG_RECOVERY_LOG_EVERY, DEFAULT_FREE_MODEL_ID, DEFENSE_PROVIDER_ID, PROVIDER_ID, } from "./constants.js";
|
|
13
12
|
import { registerIntegration } from "./integration/setup.js";
|
|
14
13
|
import { createLogger } from "./logging.js";
|
|
14
|
+
import { removeLegacyFreePiFiles } from "./legacy.js";
|
|
15
15
|
import { applyDirectNetwork } from "./network/direct.js";
|
|
16
16
|
import { subscribeEvents } from "./session/events.js";
|
|
17
17
|
import { registerSessionHooks } from "./session/hooks.js";
|
|
@@ -19,7 +19,6 @@ import { cancelAllFinalizeTimers } from "./session/track.js";
|
|
|
19
19
|
import { createRuntimeState } from "./state.js";
|
|
20
20
|
import { registerGenerateImageTool } from "./tools/image-generate.js";
|
|
21
21
|
import { registerUsageTool } from "./tools/usage.js";
|
|
22
|
-
import { registerSubagentTool } from "./tools/subagent.js";
|
|
23
22
|
import { registerVisionTool } from "./tools/vision.js";
|
|
24
23
|
import { registerWebTools } from "./tools/web.js";
|
|
25
24
|
import { settle } from "./utils/async.js";
|
|
@@ -56,89 +55,21 @@ async function setup(ctx) {
|
|
|
56
55
|
return [];
|
|
57
56
|
}
|
|
58
57
|
},
|
|
59
|
-
readSession: async (sessionID) => {
|
|
60
|
-
try {
|
|
61
|
-
const info = await ctx.session.get({ sessionID });
|
|
62
|
-
return {
|
|
63
|
-
id: info.id,
|
|
64
|
-
parentID: info.parentID,
|
|
65
|
-
title: info.title,
|
|
66
|
-
agent: info.agent,
|
|
67
|
-
outcome: info.outcome,
|
|
68
|
-
updated: info.time?.updated,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
catch {
|
|
72
|
-
return undefined;
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
listSubagentSessions: async (parentID) => {
|
|
76
|
-
try {
|
|
77
|
-
const result = await ctx.session.list({ parentID, limit: 50 });
|
|
78
|
-
return (result.data ?? []).map((info) => ({
|
|
79
|
-
id: info.id,
|
|
80
|
-
parentID: info.parentID,
|
|
81
|
-
title: info.title,
|
|
82
|
-
agent: info.agent,
|
|
83
|
-
outcome: info.outcome,
|
|
84
|
-
updated: info.time?.updated,
|
|
85
|
-
}));
|
|
86
|
-
}
|
|
87
|
-
catch {
|
|
88
|
-
return [];
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
58
|
storage: ctx.storage,
|
|
92
59
|
};
|
|
93
|
-
//
|
|
94
|
-
//
|
|
95
|
-
// so the picker, the subagent tool, permissions and reloads stay native.
|
|
96
|
-
const nativeRegistrations = [];
|
|
97
|
-
try {
|
|
98
|
-
const agents = await installFreePiAgents();
|
|
99
|
-
if (agents.changed) {
|
|
100
|
-
await ctx.agent.reload();
|
|
101
|
-
log.info(`Installed ${agents.installed.length} native free-pi subagent(s)`, agents.installed);
|
|
102
|
-
}
|
|
103
|
-
if (agents.skipped.length > 0) {
|
|
104
|
-
log.warn("Left user-owned free-pi agent files untouched", agents.skipped);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
catch (error) {
|
|
108
|
-
log.warn("Could not install the free-pi subagents", error);
|
|
109
|
-
}
|
|
110
|
-
// OpenCode's own skill loader reads `skills/free-pi/SKILL.md`. Install the
|
|
111
|
-
// file first so the skill has a real path, supporting files and permissions
|
|
112
|
-
// like any other native skill; the transform below only fills the gap when
|
|
113
|
-
// the config directory is not writable.
|
|
60
|
+
// Agents, skills and their prompts are OpenCode's. Remove the files earlier
|
|
61
|
+
// releases seeded so their prompts stop applying; user-owned files stay.
|
|
114
62
|
try {
|
|
115
|
-
const
|
|
116
|
-
if (
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
log.warn("Left the user-owned free-pi skill file untouched", freePiSkillPath(openCodeConfigDir()));
|
|
63
|
+
const removed = await removeLegacyFreePiFiles();
|
|
64
|
+
if (removed.length > 0) {
|
|
65
|
+
log.info(`Removed ${removed.length} legacy free-pi agent/skill file(s); OpenCode now owns them`, removed);
|
|
66
|
+
// Let OpenCode's own registry drop the files it loaded from disk.
|
|
67
|
+
await ctx.agent.reload().catch(() => undefined);
|
|
68
|
+
await ctx.skill.reload().catch(() => undefined);
|
|
122
69
|
}
|
|
123
70
|
}
|
|
124
71
|
catch (error) {
|
|
125
|
-
log.warn("Could not
|
|
126
|
-
}
|
|
127
|
-
try {
|
|
128
|
-
nativeRegistrations.push(await ctx.skill.transform((editor) => {
|
|
129
|
-
if (editor.get(FREE_PI_SKILL_ID))
|
|
130
|
-
return;
|
|
131
|
-
editor.add({
|
|
132
|
-
id: FREE_PI_SKILL_ID,
|
|
133
|
-
name: FREE_PI_SKILL_NAME,
|
|
134
|
-
description: FREE_PI_SKILL_DESCRIPTION,
|
|
135
|
-
path: freePiSkillPath(openCodeConfigDir()),
|
|
136
|
-
content: FREE_PI_SKILL,
|
|
137
|
-
});
|
|
138
|
-
}));
|
|
139
|
-
}
|
|
140
|
-
catch (error) {
|
|
141
|
-
log.warn("Could not register the free-pi skill", error);
|
|
72
|
+
log.warn("Could not remove the legacy free-pi agent/skill files", error);
|
|
142
73
|
}
|
|
143
74
|
const [catalogResult, registryResult, quotaResult] = await Promise.all([
|
|
144
75
|
settle(fetchCatalog(deps), undefined),
|
|
@@ -228,14 +159,9 @@ async function setup(ctx) {
|
|
|
228
159
|
editor.default.set(PROVIDER_ID, preferred);
|
|
229
160
|
});
|
|
230
161
|
const registrations = await registerSessionHooks(ctx, deps);
|
|
231
|
-
registrations.push(...nativeRegistrations);
|
|
232
162
|
const tools = [
|
|
233
163
|
{ name: "look_at_image", register: () => registerVisionTool(ctx, deps) },
|
|
234
164
|
{ name: "free_pi_usage", register: () => registerUsageTool(ctx, deps) },
|
|
235
|
-
{
|
|
236
|
-
name: "free_pi_subagent_read",
|
|
237
|
-
register: () => registerSubagentTool(ctx, deps),
|
|
238
|
-
},
|
|
239
165
|
{ name: "web", register: () => registerWebTools(ctx, deps) },
|
|
240
166
|
{ name: "generate_image", register: () => registerGenerateImageTool(ctx, deps) },
|
|
241
167
|
];
|
|
@@ -46,7 +46,6 @@ export declare function profileRequest(body: string): RequestProfile;
|
|
|
46
46
|
* provider is failing, so compacting again cannot help.
|
|
47
47
|
*/
|
|
48
48
|
export declare function noteSpuriousOverflow(deps: Deps, sessionID: string): number;
|
|
49
|
-
export declare function clearSpuriousOverflows(deps: Deps, sessionID: string): void;
|
|
50
49
|
/** Whether the session has had enough spurious rejections to stop compacting. */
|
|
51
50
|
export declare function overflowingSpuriously(deps: Deps, sessionID: string): boolean;
|
|
52
51
|
/**
|
package/dist/session/overflow.js
CHANGED
|
@@ -109,9 +109,6 @@ export function noteSpuriousOverflow(deps, sessionID) {
|
|
|
109
109
|
}
|
|
110
110
|
return count;
|
|
111
111
|
}
|
|
112
|
-
export function clearSpuriousOverflows(deps, sessionID) {
|
|
113
|
-
deps.state.spuriousOverflows.delete(sessionID);
|
|
114
|
-
}
|
|
115
112
|
/** Whether the session has had enough spurious rejections to stop compacting. */
|
|
116
113
|
export function overflowingSpuriously(deps, sessionID) {
|
|
117
114
|
const entry = deps.state.spuriousOverflows.get(sessionID);
|
package/dist/session/tools.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ import type { Deps } from "../deps.js";
|
|
|
12
12
|
* served by another provider (see `hideFreePiTools`) and refuses to run them
|
|
13
13
|
* outside a free-pi session.
|
|
14
14
|
*/
|
|
15
|
-
export declare const FREE_PI_TOOL_NAMES: readonly ["look_at_image", "free_pi_usage", "
|
|
15
|
+
export declare const FREE_PI_TOOL_NAMES: readonly ["look_at_image", "free_pi_usage", "web_search", "docs_lookup", "generate_image"];
|
|
16
16
|
type ToolResultLike = {
|
|
17
17
|
metadata?: Record<string, unknown>;
|
|
18
18
|
};
|
package/dist/session/tools.js
CHANGED
package/dist/state.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Per-plugin-instance mutable state. */
|
|
2
|
-
import type { AdTurn, Catalog,
|
|
2
|
+
import type { AdTurn, Catalog, ModelRegistry, QuotaSnapshot, SessionResetOutcome, TokenCheckState, ToolStats, TrackedModel } from "./types.js";
|
|
3
3
|
export type RuntimeState = {
|
|
4
4
|
latestClientVersion: string;
|
|
5
5
|
providerToken?: string;
|
|
@@ -12,13 +12,10 @@ export type RuntimeState = {
|
|
|
12
12
|
registryPromise?: Promise<ModelRegistry | undefined>;
|
|
13
13
|
lastCatalogNotice?: string;
|
|
14
14
|
lastQuotaNotice?: string;
|
|
15
|
-
catalogModels: Catalog;
|
|
16
15
|
/** `provider/model` ids whose upstream accepts image input. */
|
|
17
16
|
imageModels: Set<string>;
|
|
18
17
|
quotaCache?: QuotaSnapshot;
|
|
19
18
|
quotaPromise?: Promise<QuotaSnapshot>;
|
|
20
|
-
lastQuotaRefreshAt: number;
|
|
21
|
-
lastFreePiError?: FreePiError;
|
|
22
19
|
lastErrorLogKey?: string;
|
|
23
20
|
lastErrorLogAt: number;
|
|
24
21
|
lastInvalidToken?: string;
|
package/dist/state.js
CHANGED
|
@@ -6,9 +6,7 @@ export function createRuntimeState() {
|
|
|
6
6
|
cachedCatalogAt: 0,
|
|
7
7
|
cachedRegistryAt: 0,
|
|
8
8
|
registryAttemptAt: 0,
|
|
9
|
-
catalogModels: {},
|
|
10
9
|
imageModels: new Set(),
|
|
11
|
-
lastQuotaRefreshAt: 0,
|
|
12
10
|
lastErrorLogAt: 0,
|
|
13
11
|
tokenChecks: new Map(),
|
|
14
12
|
sessionClosePromises: new Map(),
|
package/dist/tools/api.d.ts
CHANGED
|
@@ -50,5 +50,5 @@ export declare function freePiRequest(deps: Deps, options: RequestOptions): Prom
|
|
|
50
50
|
/** Maps a business error code to the CLI's wording, or keeps the HTTP text. */
|
|
51
51
|
export declare function mappedText(table: Record<string, string>, result: Extract<ApiResult, {
|
|
52
52
|
ok: false;
|
|
53
|
-
}
|
|
53
|
+
}>): string;
|
|
54
54
|
export {};
|
package/dist/tools/api.js
CHANGED
|
@@ -110,7 +110,7 @@ export async function freePiRequest(deps, options) {
|
|
|
110
110
|
};
|
|
111
111
|
}
|
|
112
112
|
/** Maps a business error code to the CLI's wording, or keeps the HTTP text. */
|
|
113
|
-
export function mappedText(table, result
|
|
113
|
+
export function mappedText(table, result) {
|
|
114
114
|
if (result.code === "no_token")
|
|
115
115
|
return NO_TOKEN_TEXT;
|
|
116
116
|
const mapped = table[result.code];
|
package/dist/tools/web.js
CHANGED
|
@@ -130,7 +130,7 @@ async function executeDocsLookup(deps, raw, context) {
|
|
|
130
130
|
label: "The documentation lookup",
|
|
131
131
|
});
|
|
132
132
|
if (!lookup.ok)
|
|
133
|
-
return fail(mappedText(ERRORS, lookup
|
|
133
|
+
return fail(mappedText(ERRORS, lookup));
|
|
134
134
|
const data = lookup.data ?? {};
|
|
135
135
|
deps.log.info("docs_lookup answered", {
|
|
136
136
|
library,
|