@eduardo191labs/opencode-free-pi 0.7.29 → 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 +21 -69
- package/dist/deps.d.ts +1 -4
- package/dist/legacy.d.ts +17 -0
- package/dist/legacy.js +58 -0
- package/dist/plugin.js +7 -84
- package/dist/session/tools.d.ts +1 -1
- package/dist/session/tools.js +0 -1
- package/dist/types.d.ts +0 -11
- package/package.json +2 -2
- package/src/deps.ts +1 -8
- package/src/legacy.ts +62 -0
- package/src/plugin.ts +8 -97
- package/src/session/tools.ts +0 -1
- package/src/types.ts +0 -18
- 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
|
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/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,18 @@ 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
|
-
log.info("Installed the native free-pi skill");
|
|
119
|
-
}
|
|
120
|
-
if (skill.skipped) {
|
|
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);
|
|
122
66
|
}
|
|
123
67
|
}
|
|
124
68
|
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);
|
|
69
|
+
log.warn("Could not remove the legacy free-pi agent/skill files", error);
|
|
142
70
|
}
|
|
143
71
|
const [catalogResult, registryResult, quotaResult] = await Promise.all([
|
|
144
72
|
settle(fetchCatalog(deps), undefined),
|
|
@@ -228,14 +156,9 @@ async function setup(ctx) {
|
|
|
228
156
|
editor.default.set(PROVIDER_ID, preferred);
|
|
229
157
|
});
|
|
230
158
|
const registrations = await registerSessionHooks(ctx, deps);
|
|
231
|
-
registrations.push(...nativeRegistrations);
|
|
232
159
|
const tools = [
|
|
233
160
|
{ name: "look_at_image", register: () => registerVisionTool(ctx, deps) },
|
|
234
161
|
{ name: "free_pi_usage", register: () => registerUsageTool(ctx, deps) },
|
|
235
|
-
{
|
|
236
|
-
name: "free_pi_subagent_read",
|
|
237
|
-
register: () => registerSubagentTool(ctx, deps),
|
|
238
|
-
},
|
|
239
162
|
{ name: "web", register: () => registerWebTools(ctx, deps) },
|
|
240
163
|
{ name: "generate_image", register: () => registerGenerateImageTool(ctx, deps) },
|
|
241
164
|
];
|
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/types.d.ts
CHANGED
|
@@ -298,14 +298,3 @@ export type SessionMessageInfo = {
|
|
|
298
298
|
[key: string]: unknown;
|
|
299
299
|
};
|
|
300
300
|
export type ReadContext = (sessionID: string) => Promise<readonly SessionMessageInfo[]>;
|
|
301
|
-
/** Minimal view of an OpenCode V2 session header. */
|
|
302
|
-
export type SubagentSessionInfo = {
|
|
303
|
-
id: string;
|
|
304
|
-
parentID?: string;
|
|
305
|
-
title?: string;
|
|
306
|
-
agent?: string;
|
|
307
|
-
outcome?: string;
|
|
308
|
-
updated?: number;
|
|
309
|
-
};
|
|
310
|
-
export type ReadSessionInfo = (sessionID: string) => Promise<SubagentSessionInfo | undefined>;
|
|
311
|
-
export type ListSubagentSessions = (parentID: string) => Promise<readonly SubagentSessionInfo[]>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eduardo191labs/opencode-free-pi",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.30",
|
|
4
4
|
"description": "Ad-supported free-pi provider plugin for OpenCode on Windows, Linux, macOS and Termux",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"scripts": {
|
|
25
25
|
"build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.json",
|
|
26
26
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
27
|
-
"test": "npm run build && node test/catalog.mjs && node test/smoke.mjs && node test/registry.mjs && node test/models.mjs && node test/live.mjs && node test/hooks.mjs && node test/errors.mjs && node test/overflow.mjs && node test/vision.mjs && node test/
|
|
27
|
+
"test": "npm run build && node test/catalog.mjs && node test/smoke.mjs && node test/registry.mjs && node test/models.mjs && node test/live.mjs && node test/hooks.mjs && node test/errors.mjs && node test/overflow.mjs && node test/vision.mjs && node test/legacy.mjs && node test/wire.mjs && node test/network.mjs && node test/tools.mjs && node test/slots.mjs",
|
|
28
28
|
"prepublishOnly": "npm run build",
|
|
29
29
|
"postinstall": "node scripts/postinstall.mjs"
|
|
30
30
|
},
|
package/src/deps.ts
CHANGED
|
@@ -4,20 +4,13 @@ import type { Credential } from "@opencode/schema/credential";
|
|
|
4
4
|
import type { Plugin } from "@opencode/plugin";
|
|
5
5
|
import type { Logger } from "./logging.js";
|
|
6
6
|
import type { RuntimeState } from "./state.js";
|
|
7
|
-
import type {
|
|
8
|
-
ListSubagentSessions,
|
|
9
|
-
ReadContext,
|
|
10
|
-
ReadSessionInfo,
|
|
11
|
-
} from "./types.js";
|
|
7
|
+
import type { ReadContext } from "./types.js";
|
|
12
8
|
|
|
13
9
|
export type Deps = {
|
|
14
10
|
readonly state: RuntimeState;
|
|
15
11
|
readonly log: Logger;
|
|
16
12
|
readonly activeCredential: () => Promise<Credential.Value | undefined>;
|
|
17
13
|
readonly readContext: ReadContext;
|
|
18
|
-
/** Session headers, used to prove a session is really this session's child. */
|
|
19
|
-
readonly readSession?: ReadSessionInfo;
|
|
20
|
-
readonly listSubagentSessions?: ListSubagentSessions;
|
|
21
14
|
/** Plugin-scoped durable storage, used to reconnect provider sessions. */
|
|
22
15
|
readonly storage?: Plugin.Context["storage"];
|
|
23
16
|
};
|
package/src/legacy.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
|
|
12
|
+
import { readFile, rm, rmdir } from "node:fs/promises";
|
|
13
|
+
import { homedir } from "node:os";
|
|
14
|
+
import { dirname, join } from "node:path";
|
|
15
|
+
|
|
16
|
+
const MARKER =
|
|
17
|
+
"<!-- managed by @eduardo191labs/opencode-free-pi; delete this line to keep your own copy -->";
|
|
18
|
+
|
|
19
|
+
const LEGACY_FILES = [
|
|
20
|
+
["agents", "free-pi", "scout.md"],
|
|
21
|
+
["agents", "free-pi", "planner.md"],
|
|
22
|
+
["agents", "free-pi", "worker.md"],
|
|
23
|
+
["agents", "free-pi", "reviewer.md"],
|
|
24
|
+
["skills", "free-pi", "SKILL.md"],
|
|
25
|
+
] as const;
|
|
26
|
+
|
|
27
|
+
/** OpenCode's user-wide config directory. */
|
|
28
|
+
export function openCodeConfigDir(): string {
|
|
29
|
+
const explicit = process.env.OPENCODE_CONFIG_DIR?.trim();
|
|
30
|
+
if (explicit) return explicit;
|
|
31
|
+
const xdg = process.env.XDG_CONFIG_HOME?.trim();
|
|
32
|
+
if (xdg) return join(xdg, "opencode");
|
|
33
|
+
return join(homedir(), ".config", "opencode");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Deletes the plugin-managed agent and skill files from previous versions and
|
|
38
|
+
* returns their paths. User-owned files are never touched.
|
|
39
|
+
*/
|
|
40
|
+
export async function removeLegacyFreePiFiles(
|
|
41
|
+
configDir = openCodeConfigDir(),
|
|
42
|
+
): Promise<string[]> {
|
|
43
|
+
const removed: string[] = [];
|
|
44
|
+
for (const parts of LEGACY_FILES) {
|
|
45
|
+
const path = join(configDir, ...parts);
|
|
46
|
+
try {
|
|
47
|
+
const current = await readFile(path, "utf8");
|
|
48
|
+
if (!current.slice(0, 1024).includes(MARKER)) continue;
|
|
49
|
+
await rm(path, { force: true });
|
|
50
|
+
removed.push(path);
|
|
51
|
+
} catch {
|
|
52
|
+
// Missing or unreadable: nothing to clean up.
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (removed.length > 0) {
|
|
56
|
+
// Drop the now-empty plugin folders without touching user-owned entries.
|
|
57
|
+
for (const parts of [["agents", "free-pi"], ["skills", "free-pi"]]) {
|
|
58
|
+
await rmdir(join(configDir, ...parts)).catch(() => undefined);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return removed;
|
|
62
|
+
}
|
package/src/plugin.ts
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
1
|
/** OpenCode V2 plugin entry point for free-pi. */
|
|
2
2
|
|
|
3
3
|
import { Plugin } from "@opencode/plugin";
|
|
4
|
-
import {
|
|
5
|
-
FREE_PI_SKILL,
|
|
6
|
-
FREE_PI_SKILL_DESCRIPTION,
|
|
7
|
-
FREE_PI_SKILL_ID,
|
|
8
|
-
FREE_PI_SKILL_NAME,
|
|
9
|
-
freePiSkillPath,
|
|
10
|
-
installFreePiAgents,
|
|
11
|
-
installFreePiSkill,
|
|
12
|
-
openCodeConfigDir,
|
|
13
|
-
} from "./agents/definitions.js";
|
|
14
4
|
import { fetchQuota } from "./api/quota.js";
|
|
15
5
|
import { closeFreePiSession } from "./api/session.js";
|
|
16
6
|
import { readCredentialsToken } from "./auth/credentials.js";
|
|
@@ -38,6 +28,7 @@ import type { Deps } from "./deps.js";
|
|
|
38
28
|
import type { ModelMap } from "./types.js";
|
|
39
29
|
import { registerIntegration } from "./integration/setup.js";
|
|
40
30
|
import { createLogger } from "./logging.js";
|
|
31
|
+
import { removeLegacyFreePiFiles } from "./legacy.js";
|
|
41
32
|
import { applyDirectNetwork } from "./network/direct.js";
|
|
42
33
|
import { subscribeEvents } from "./session/events.js";
|
|
43
34
|
import { registerSessionHooks } from "./session/hooks.js";
|
|
@@ -45,7 +36,6 @@ import { cancelAllFinalizeTimers } from "./session/track.js";
|
|
|
45
36
|
import { createRuntimeState } from "./state.js";
|
|
46
37
|
import { registerGenerateImageTool } from "./tools/image-generate.js";
|
|
47
38
|
import { registerUsageTool } from "./tools/usage.js";
|
|
48
|
-
import { registerSubagentTool } from "./tools/subagent.js";
|
|
49
39
|
import { registerVisionTool } from "./tools/vision.js";
|
|
50
40
|
import { registerWebTools } from "./tools/web.js";
|
|
51
41
|
import { settle } from "./utils/async.js";
|
|
@@ -82,95 +72,21 @@ async function setup(ctx: Plugin.Context): Promise<() => Promise<void>> {
|
|
|
82
72
|
return [];
|
|
83
73
|
}
|
|
84
74
|
},
|
|
85
|
-
readSession: async (sessionID) => {
|
|
86
|
-
try {
|
|
87
|
-
const info = await ctx.session.get({ sessionID });
|
|
88
|
-
return {
|
|
89
|
-
id: info.id,
|
|
90
|
-
parentID: info.parentID,
|
|
91
|
-
title: info.title,
|
|
92
|
-
agent: info.agent,
|
|
93
|
-
outcome: info.outcome,
|
|
94
|
-
updated: info.time?.updated,
|
|
95
|
-
};
|
|
96
|
-
} catch {
|
|
97
|
-
return undefined;
|
|
98
|
-
}
|
|
99
|
-
},
|
|
100
|
-
listSubagentSessions: async (parentID) => {
|
|
101
|
-
try {
|
|
102
|
-
const result = await ctx.session.list({ parentID, limit: 50 });
|
|
103
|
-
return (result.data ?? []).map((info) => ({
|
|
104
|
-
id: info.id,
|
|
105
|
-
parentID: info.parentID,
|
|
106
|
-
title: info.title,
|
|
107
|
-
agent: info.agent,
|
|
108
|
-
outcome: info.outcome,
|
|
109
|
-
updated: info.time?.updated,
|
|
110
|
-
}));
|
|
111
|
-
} catch {
|
|
112
|
-
return [];
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
75
|
storage: ctx.storage,
|
|
116
76
|
};
|
|
117
77
|
|
|
118
|
-
//
|
|
119
|
-
//
|
|
120
|
-
// so the picker, the subagent tool, permissions and reloads stay native.
|
|
121
|
-
const nativeRegistrations: Array<{ dispose: () => Promise<void> }> = [];
|
|
78
|
+
// Agents, skills and their prompts are OpenCode's. Remove the files earlier
|
|
79
|
+
// releases seeded so their prompts stop applying; user-owned files stay.
|
|
122
80
|
try {
|
|
123
|
-
const
|
|
124
|
-
if (
|
|
125
|
-
await ctx.agent.reload();
|
|
81
|
+
const removed = await removeLegacyFreePiFiles();
|
|
82
|
+
if (removed.length > 0) {
|
|
126
83
|
log.info(
|
|
127
|
-
`
|
|
128
|
-
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
if (agents.skipped.length > 0) {
|
|
132
|
-
log.warn(
|
|
133
|
-
"Left user-owned free-pi agent files untouched",
|
|
134
|
-
agents.skipped,
|
|
84
|
+
`Removed ${removed.length} legacy free-pi agent/skill file(s); OpenCode now owns them`,
|
|
85
|
+
removed,
|
|
135
86
|
);
|
|
136
87
|
}
|
|
137
88
|
} catch (error) {
|
|
138
|
-
log.warn("Could not
|
|
139
|
-
}
|
|
140
|
-
// OpenCode's own skill loader reads `skills/free-pi/SKILL.md`. Install the
|
|
141
|
-
// file first so the skill has a real path, supporting files and permissions
|
|
142
|
-
// like any other native skill; the transform below only fills the gap when
|
|
143
|
-
// the config directory is not writable.
|
|
144
|
-
try {
|
|
145
|
-
const skill = await installFreePiSkill();
|
|
146
|
-
if (skill.changed) {
|
|
147
|
-
await ctx.skill.reload();
|
|
148
|
-
log.info("Installed the native free-pi skill");
|
|
149
|
-
}
|
|
150
|
-
if (skill.skipped) {
|
|
151
|
-
log.warn(
|
|
152
|
-
"Left the user-owned free-pi skill file untouched",
|
|
153
|
-
freePiSkillPath(openCodeConfigDir()),
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
} catch (error) {
|
|
157
|
-
log.warn("Could not install the free-pi skill file", error);
|
|
158
|
-
}
|
|
159
|
-
try {
|
|
160
|
-
nativeRegistrations.push(
|
|
161
|
-
await ctx.skill.transform((editor) => {
|
|
162
|
-
if (editor.get(FREE_PI_SKILL_ID)) return;
|
|
163
|
-
editor.add({
|
|
164
|
-
id: FREE_PI_SKILL_ID,
|
|
165
|
-
name: FREE_PI_SKILL_NAME,
|
|
166
|
-
description: FREE_PI_SKILL_DESCRIPTION,
|
|
167
|
-
path: freePiSkillPath(openCodeConfigDir()),
|
|
168
|
-
content: FREE_PI_SKILL,
|
|
169
|
-
} as any);
|
|
170
|
-
}),
|
|
171
|
-
);
|
|
172
|
-
} catch (error) {
|
|
173
|
-
log.warn("Could not register the free-pi skill", error);
|
|
89
|
+
log.warn("Could not remove the legacy free-pi agent/skill files", error);
|
|
174
90
|
}
|
|
175
91
|
|
|
176
92
|
const [catalogResult, registryResult, quotaResult] = await Promise.all([
|
|
@@ -287,17 +203,12 @@ async function setup(ctx: Plugin.Context): Promise<() => Promise<void>> {
|
|
|
287
203
|
});
|
|
288
204
|
|
|
289
205
|
const registrations = await registerSessionHooks(ctx, deps);
|
|
290
|
-
registrations.push(...nativeRegistrations);
|
|
291
206
|
const tools: Array<{
|
|
292
207
|
name: string;
|
|
293
208
|
register: () => Promise<{ dispose: () => Promise<void> }>;
|
|
294
209
|
}> = [
|
|
295
210
|
{ name: "look_at_image", register: () => registerVisionTool(ctx, deps) },
|
|
296
211
|
{ name: "free_pi_usage", register: () => registerUsageTool(ctx, deps) },
|
|
297
|
-
{
|
|
298
|
-
name: "free_pi_subagent_read",
|
|
299
|
-
register: () => registerSubagentTool(ctx, deps),
|
|
300
|
-
},
|
|
301
212
|
{ name: "web", register: () => registerWebTools(ctx, deps) },
|
|
302
213
|
{ name: "generate_image", register: () => registerGenerateImageTool(ctx, deps) },
|
|
303
214
|
];
|