@fro.bot/opencode-plugin 0.3.6 → 0.3.8
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
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Fro Bot's plugin for [OpenCode](https://opencode.ai) V2 (v2.2.0 and later in the 2.x line). It gives the agent two things:
|
|
4
4
|
|
|
5
5
|
- **Session history tools.** `session_list`, `session_read`, `session_search` and `session_info` read the sessions of the current workspace. `session_read` and `session_search` cover a session's active context window: the messages since its last compaction, plus the compaction summary. Todos come from the last completed `todowrite` call in that window.
|
|
6
|
-
- **A subagent resume guard.**
|
|
6
|
+
- **A subagent resume guard, for Fro Bot's own launchers only.** It applies only when a Fro Bot launcher (the Action or the workspace) started the server, told by the launcher variable `OPENCODE_FROBOT_TRACING`. There, a `subagent` call that carries a `sessionID` is rejected before it runs, with a fixed message that holds no ids, unless it resumes a child this run dispatched from the same session and the Action started the server. With no launcher variable (a workstation, the TUI, `opencode run`, any consumer) the guard is not registered, and resumes behave as in stock OpenCode.
|
|
7
7
|
|
|
8
8
|
The plugin id is `fro-bot.opencode-plugin`. OpenCode V2 skips a plugin that fails to load and keeps serving, so anything that depends on this plugin should check `GET /api/plugin` for that id with status `active`.
|
|
9
9
|
|
|
@@ -40,9 +40,9 @@ To turn it on, create `~/.config/fro-bot/opencode-plugin/tracing.json` (under `$
|
|
|
40
40
|
- `headers` is optional, at most 16 entries. They carry your collector credential.
|
|
41
41
|
- `hosts` is **required**: one to 16 machine names, and tracing is on only on a machine named in it. A name matches the machine's host name exactly (ignoring case and a trailing dot), or, when it has no dot, the part of the host name before its first dot (`my-laptop` matches `my-laptop.local`). There are no wildcards. A copy of this file on any other machine does nothing there, silently.
|
|
42
42
|
|
|
43
|
-
Every span carries `langfuse.session.id` set to the **root** session's id, so Langfuse's Sessions view groups a subagent's spans with its parent's, while the standard `session.id` stays each span's own session. In the Action, each span also carries the run's repository, run id, attempt, job and trigger as `langfuse.trace.metadata.*` (`repository`, `run_id`, `run_attempt`, `job`, `trigger`), so Langfuse shows and filters by them; a local session has none of these.
|
|
43
|
+
Every span carries `langfuse.session.id` set to the **root** session's id, so Langfuse's Sessions view groups a subagent's spans with its parent's, while the standard `session.id` stays each span's own session. In the Action, each span also carries the run's repository, run id, attempt, job and trigger as `langfuse.trace.metadata.*` (`repository`, `run_id`, `run_attempt`, `job`, `trigger`), so Langfuse shows and filters by them; a local session has none of these run fields, and gets only the repository described under "What a trace contains".
|
|
44
44
|
|
|
45
|
-
The root span of every trace (a turn's `invoke_agent`, and the root of a late continuation trace) also carries `langfuse.trace.name
|
|
45
|
+
The root span of every trace (a turn's `invoke_agent`, and the root of a late continuation trace) also carries `langfuse.trace.name`, which Langfuse shows as the trace's name: the fixed string `fro-bot run` in an Action run, and `opencode session` in a local session. No other span has it, and it holds no content.
|
|
46
46
|
|
|
47
47
|
### What a trace contains
|
|
48
48
|
|
|
@@ -55,6 +55,8 @@ Spans follow the OpenTelemetry GenAI conventions at the revision named in `genai
|
|
|
55
55
|
- `langfuse.observation.type`: set explicitly, so Langfuse does not depend on mapping the operation name: `generation` on a model request, `agent` on `invoke_agent` and `tool` on a tool call.
|
|
56
56
|
- `fro_bot.outcome`: how the span ended. `ok`, `error` or `interrupted`. The Action's own lifecycle trace (`action.main` and its phases, exported by the Action, not by this plugin) also uses the attribute name `fro_bot.outcome`, with a different set of values: `succeeded`, `incomplete`, `failed`, `skipped` or `cancelled` (`src/shared/lifecycle-tracer.ts`), with `fro_bot.reason` for a stable reason code. A query on `fro_bot.outcome` must say which sender it means, by `service.name`.
|
|
57
57
|
- In an Action run, `cicd.pipeline.run.id` (the run id, the same value as `langfuse.trace.metadata.run_id`) and, when the launcher carried `serverUrl`, `cicd.pipeline.run.url.full`. The URL is GitHub's own form: `<server>/<owner>/<repo>/actions/runs/<run id>` for the first attempt (the API's `html_url` for attempt 1 has no `/attempts/` part) and `<server>/<owner>/<repo>/actions/runs/<run id>/attempts/<attempt>` for a re-run. It is left off when the repository, run id or attempt is not a plain `owner/repo` slug and digits, so a URL is never guessed. The `cicd.*` attributes belong to the core OpenTelemetry conventions (release-candidate stability), not to the GenAI revision the plugin pins.
|
|
58
|
+
- `langfuse.environment`: `automation` on every span of a trace whose **root** session id starts with `ses_aut_`, subagents of that root included, in a local session and in an Action run. Any other trace sets none, and Langfuse reads that as `default`. This is a **labelling convention, not proof of where a session came from**: `ses_aut_` is the prefix OpenCode's own automation sessions use, but any caller can create a session with such an id, and a session without it may still be automated. Do not use it to decide anything about trust or origin.
|
|
59
|
+
- `langfuse.trace.metadata.repository` (local session only): the `owner/repo` of the `origin` remote of the **root** session's directory (the one its `session.created` event named), falling back to the directory of the OpenCode location the plugin loaded in. It is looked up **once per trace**, when the trace's first span is built, and every span of that trace carries the answer or none does: a linked subagent created in another checkout, a root resumed with no creation event, and a lookup that finishes mid-trace cannot give one trace two repositories. The lookup never waits: it starts in the background when the server starts and when a session is created, and a trace whose lookup had not finished by its first span has no repository. It reads the checkout's git files with `node:fs/promises` alone (no `git` process): a `.git` directory, or a `.git` file naming a `gitdir` (a linked worktree's `commondir` is followed), in that directory or one of its parents. Each file is opened once, without following links and without blocking, and the open handle is checked before anything is read: only a regular file is read, up to a size bound, under one 250 ms budget per directory, and only one directory is looked up at a time (the slot is held until the read really returns, and a directory asked for while it is taken has no repository until a later trace asks again), so a named pipe, a symlink (a symlinked `.git` or `config` is not followed) or a slow disk leaves the repository unset and never stalls OpenCode. The config is read the way git reads it: the remote's name must be exactly `origin` (`[remote "Origin"]` is not it), repeated `[remote "origin"]` sections are merged and the first `url` wins, values may be quoted, and `#` and `;` comments after a header or a value are ignored. A line ending in a backslash joins the next line in git; this reader does not follow that, so a config with one before or inside the `origin` section leaves the repository unset rather than guess. Only a `github.com` remote is accepted, as `https://github.com/<owner>/<repo>`, `git@github.com:<owner>/<repo>` or `ssh://git@github.com/<owner>/<repo>` (with or without `.git`), and the owner and repo must follow GitHub's naming rules (an owner is at most 39 characters, a repo at most 100). Any other host (an enterprise server included), form or name leaves it unset, as does any read error; credentials in a remote are never exported. The answer is cached per directory (256 at most) for the life of the server, so a remote added later is not seen until it restarts. It is a **declared label read from a checkout, not a verified identity**: a checkout can point `origin` anywhere. An Action run keeps the repository its launcher declared and this is never read there.
|
|
58
60
|
|
|
59
61
|
**Model requests (`chat`).**
|
|
60
62
|
|
|
@@ -64,9 +66,9 @@ Spans follow the OpenTelemetry GenAI conventions at the revision named in `genai
|
|
|
64
66
|
|
|
65
67
|
**Tool calls (`execute_tool`).**
|
|
66
68
|
|
|
67
|
-
- `fro_bot.tool.outcome`: `success` (the tool ran and returned), `error` (it failed, or OpenCode refused the call), `rejected` (a permission rule or this plugin's subagent resume guard refused it before it ran: `error.type` is `permission.rejected` or `plugin.reuse-guard`) or `interrupted` (the turn was aborted while it ran).
|
|
69
|
+
- `fro_bot.tool.outcome`: `success` (the tool ran and returned), `error` (it failed, or OpenCode refused the call), `rejected` (a permission rule or this plugin's subagent resume guard refused it before it ran: `error.type` is `permission.rejected` or `plugin.reuse-guard`; the guard exists only when a Fro Bot launcher started the server, so local and consumer use never sees `plugin.reuse-guard`) or `interrupted` (the turn was aborted while it ran).
|
|
68
70
|
- `fro_bot.tool.offered`: `true` when the called name was in the tool list of the request that asked for the call, `false` when it was not. This covers OpenCode's two refusals (`Tool is not available for this request: <name>` and `No tool named "<name>" is currently available`) and a real tool that ran and failed. It is compared with the list the plugin captured when the request hook fired, not with the failure message. It is **left off** when the plugin cannot say: the call names no step, the step could not be matched to a request, an event was lost, the request's tool list was not captured or is incomplete (the snapshot left out an entry or cut the list at its bound), the provider ran the tool, or the tool's name is unknown. Unset means unknown, never `false`. The verdict is provisional until the request's step ends: a tool span that ends first is held (at most 256 at a time) until then, and exports **without** `offered` if the request turns uncertain (a loss), its execution ends, or the hold is full. The span itself always exports. A name that is not in the list but ran anyway (OpenCode runs a tool the request only offered inside Code Mode when it offered `execute`) is `false`.
|
|
69
|
-
- `gen_ai.agent.name`: the agent the `execute.before` hook reported; else the agent of the request (or its step) that asked for the call, when that binding was certain; else the agent of the session that owns the call. A call refused before any hook still names its agent, and a session that switched agents does not blame the first one.
|
|
71
|
+
- `gen_ai.agent.name`: the agent the `execute.before` hook reported; else the agent of the request (or its step) that asked for the call, when that binding was certain, and stayed certain until the span exported; else the agent of the session that owns the call, and none when no agent is known. The request's agent is as provisional as `fro_bot.tool.offered`: the span is held for either, and a binding that turns uncertain (a loss), a request that closes unsettled or a full hold queue takes the request's agent away along with the verdict. A call refused before any hook still names its agent, and a session that switched agents does not blame the first one.
|
|
70
72
|
|
|
71
73
|
**Joining a turn to its Action run.** The Action's launcher document (`OPENCODE_FROBOT_TRACING`) may carry four optional fields. The plugin accepts the document with or without them, refuses any other key, and turns tracing off, with a fixed reason and no value in the log line (`launcher-run-invalid`), when a field it carries is malformed:
|
|
72
74
|
|
package/dist/index.mjs
CHANGED
|
@@ -988,6 +988,17 @@ function readLauncherHost(env) {
|
|
|
988
988
|
if (!isRecord(document) || document.version !== 1) return void 0;
|
|
989
989
|
return document.host === "action" ? "action" : void 0;
|
|
990
990
|
}
|
|
991
|
+
/**
|
|
992
|
+
* Whether a Fro Bot launcher started this server, for the subagent resume guard: `'none'` when the launcher variable is
|
|
993
|
+
* absent (a workstation, the TUI, `opencode run`, any consumer), `'action'` when it names the Action (see
|
|
994
|
+
* `readLauncherHost`), and `'other'` for any variable that is present but does not: the workspace, an unknown host, or a
|
|
995
|
+
* malformed document. Presence alone means a Fro Bot launcher, so a present but unreadable variable stays fail-closed.
|
|
996
|
+
* Pure and never throws.
|
|
997
|
+
*/
|
|
998
|
+
function readLauncherKind(env) {
|
|
999
|
+
if (env["OPENCODE_FROBOT_TRACING"] === void 0) return "none";
|
|
1000
|
+
return readLauncherHost(env) === "action" ? "action" : "other";
|
|
1001
|
+
}
|
|
991
1002
|
/** Header names the exporter or the transport owns. A user file cannot set them. */
|
|
992
1003
|
const REFUSED_HEADER_NAMES = /* @__PURE__ */ new Set([
|
|
993
1004
|
"host",
|
|
@@ -1185,13 +1196,14 @@ function resolveTracingSettings(input) {
|
|
|
1185
1196
|
*/
|
|
1186
1197
|
async function startTracing(host, settings, env, log) {
|
|
1187
1198
|
try {
|
|
1188
|
-
const handle = await (await import("./tracing-
|
|
1199
|
+
const handle = await (await import("./tracing-BeMbWlwI.mjs")).startTracing({
|
|
1189
1200
|
session: host.session,
|
|
1190
1201
|
tool: { hook: async (name, callback) => name === "execute.before" ? host.tool.hook(name, callback) : host.tool.hook(name, callback) },
|
|
1191
1202
|
event: host.event
|
|
1192
1203
|
}, settings, {
|
|
1193
1204
|
env,
|
|
1194
1205
|
log,
|
|
1206
|
+
directory: host.location.directory,
|
|
1195
1207
|
...typeof host.app?.version === "string" ? { opencodeVersion: host.app.version } : {}
|
|
1196
1208
|
});
|
|
1197
1209
|
return async () => {
|
|
@@ -1208,13 +1220,16 @@ async function startTracing(host, settings, env, log) {
|
|
|
1208
1220
|
}
|
|
1209
1221
|
async function setupFroBotPlugin(host, options = {}) {
|
|
1210
1222
|
const env = options.env ?? process.env;
|
|
1211
|
-
const
|
|
1212
|
-
|
|
1213
|
-
guard
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1223
|
+
const launcher = readLauncherKind(env);
|
|
1224
|
+
if (launcher !== "none") {
|
|
1225
|
+
const guard = createSubagentResumeGuard({ actionHost: launcher === "action" });
|
|
1226
|
+
await host.tool.hook("execute.before", async (event) => {
|
|
1227
|
+
guard.before(event);
|
|
1228
|
+
});
|
|
1229
|
+
await host.tool.hook("execute.after", (event) => {
|
|
1230
|
+
guard.after(event);
|
|
1231
|
+
});
|
|
1232
|
+
}
|
|
1218
1233
|
const tools = createSessionTools({
|
|
1219
1234
|
client: createPluginSessionClient(host.session),
|
|
1220
1235
|
directory: host.location.directory
|