@fro.bot/opencode-plugin 0.3.5 → 0.3.7
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
|
|
|
@@ -44,11 +44,36 @@ Every span carries `langfuse.session.id` set to the **root** session's id, so La
|
|
|
44
44
|
|
|
45
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` set to the fixed string `fro-bot run`, which Langfuse shows as the trace's name. No other span has it, and it holds no content.
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
### What a trace contains
|
|
48
|
+
|
|
49
|
+
Spans follow the OpenTelemetry GenAI conventions at the revision named in `genai-attributes.ts`: `invoke_agent <agent>` for a turn (or plain `invoke_agent` when no agent name is known), `chat <model>` for a model request, and `execute_tool <tool>` for a tool call. Identity and markers outside the conventions use the `fro_bot.` prefix. A field the plugin could not capture is left out and named in `fro_bot.span.gaps`; it is never filled with a guess. Every string is scrubbed before it leaves the process, the ones below included.
|
|
50
|
+
|
|
51
|
+
**Resource.** `service.name` is `fro-bot-opencode-plugin`. `service.version` is the plugin's own version, read when tracing starts from the `package.json` beside the built files (the release job writes the version there after the build, so it cannot be baked in at build time). `langfuse.release` carries the same value on the resource: Langfuse reads a release per observation, from the span and then the resource, so every span, root or child, has it, and no span sets it itself (`service.version` feeds Langfuse's separate `version` field). `fro_bot.opencode.version` is the host's OpenCode version (`Plugin.Context.app.version`). Each is left off when it cannot be read, is not a short version-like string, or the scrub would change it. None is ever sent altered.
|
|
52
|
+
|
|
53
|
+
**On every span.**
|
|
54
|
+
|
|
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
|
+
- `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
|
+
- 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
|
+
|
|
59
|
+
**Model requests (`chat`).**
|
|
60
|
+
|
|
61
|
+
- `fro_bot.request.kind`: `primary`, `title`, `compaction` or `generate`. A title or compaction request carries **no** `gen_ai.agent.name`: it is the framework's own request, and a framework constant is not an agent name. `fro_bot.request.kind` says what it is.
|
|
62
|
+
- `fro_bot.tool_definitions.count` and `fro_bot.tool_definitions.chars`: how many tools the request offered, and the serialized length in characters of the definitions the plugin captured (`gen_ai.tool.definitions` before any bound or scrub; 0 when none were offered). They describe what the plugin captured, not what the provider billed: the capture keeps a tool's name, description and input schema. Both are computed once per request and left off when the request's tool list was not captured.
|
|
63
|
+
- `fro_bot.usage.cost_usd`: the cost OpenCode reported, in USD, as a number. `langfuse.observation.cost_details` is the same cost as the JSON string `{"total": <usd>}`, which Langfuse uses **instead of** the cost it works out from usage and its price list. It is set only for a positive cost: OpenCode reports 0 for a model it has no price for, so a zero would switch off Langfuse's own estimate. It is left off when the cost is unknown or zero.
|
|
64
|
+
|
|
65
|
+
**Tool calls (`execute_tool`).**
|
|
66
|
+
|
|
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`; 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
|
+
- `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.
|
|
70
|
+
|
|
71
|
+
**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:
|
|
48
72
|
|
|
49
73
|
- `sessionId`: the telemetry session the Action computed, `<owner>/<repo>:<logical key>`: 1 to 200 characters, no control characters. The plugin sets `langfuse.session.id` to it **verbatim** on every span, and never derives or alters it. Every exported string is scrubbed, so a session id the scrub would change or withhold (a repository named `password-manager` reads as a name and a value) is never exported redacted, which would merge conversations into one session: that span falls back to the OpenCode root session instead. The Action avoids the fallback by passing the id through `scrubSafeSessionId` (`@fro-bot/runtime/tracing/session-id`) first, which returns the id as is when the scrub leaves it alone, else `sha256:` and 32 hex characters of its SHA-256, else none. Without it, and in every local session, `langfuse.session.id` stays the OpenCode root session as described above. **Upgrading:** turns exported before the Action sent a `sessionId` stay in Langfuse under the OpenCode root session id, and new Action turns use the qualified conversation key, so one conversation shows as two sessions across the upgrade. Every span of both kinds carries `fro_bot.root_session.id` (the OpenCode root session id, whatever `langfuse.session.id` is), so a dashboard or a query can still join the old and the new turns of a conversation on it. `session.id` and `gen_ai.conversation.id` keep each span's own OpenCode session either way.
|
|
50
74
|
- `invocationId`: a 1 to 200 character id for the Action step that started the server, with no control characters. Every span carries it as `fro_bot.invocation.id`, mirrored to `langfuse.trace.metadata.invocation_id`. It tells apart two steps of one job, which share `run_id`, `run_attempt` and `job`.
|
|
51
75
|
- `rootSpan`: `{"traceId": "<32 hex>", "spanId": "<16 hex>"}`, the run's root span. Lower-case hex only, neither id all zero, no other key. Each turn's root span (the `invoke_agent` span of the turn's root session, standalone compaction turns included) carries one OpenTelemetry **link** to it and no link attributes. Tempo follows links; Langfuse ignores them. The turn stays a trace of its own: nothing is re-parented.
|
|
76
|
+
- `serverUrl`: the GitHub server's origin, `GITHUB_SERVER_URL`, for example `https://github.com` or `https://ghe.example.com:8443`. It must be exactly an `https` origin (a host and an optional port, with at most one trailing slash), written the way a URL parser writes it back: a path, query, fragment, credentials, an upper-case host, a spelled-out default port or a non-ASCII host make the plugin refuse the document (`launcher-run-invalid`). It is at most 200 characters. The plugin builds each span's `cicd.pipeline.run.url.full` from it (see below), and sets no URL when the field is absent. **A plugin release older than this field refuses a document that carries it**, because it refuses every key it does not know and turns tracing off. The Action must therefore send `serverUrl` only to a plugin version that reads it.
|
|
52
77
|
|
|
53
78
|
The plugin refuses a launcher document over 4,096 characters, counted on the serialized value. Fields at their 200-character limits fit when they are ordinary text, but escapes make a document longer than its fields (a lone surrogate is six characters), so the Action's writer measures the serialized value and writes the tracing-off document instead of one the plugin would refuse.
|
|
54
79
|
|
package/dist/index.mjs
CHANGED
|
@@ -884,6 +884,24 @@ function parseTextField(value) {
|
|
|
884
884
|
if (typeof value !== "string" || value.length === 0 || value.length > 200) return void 0;
|
|
885
885
|
return hasControlCharacter(value) ? void 0 : value;
|
|
886
886
|
}
|
|
887
|
+
/**
|
|
888
|
+
* A GitHub server origin: exactly `https://<host>[:<port>]`, optionally with one trailing slash, no more. The text must be
|
|
889
|
+
* what the URL parser would write back, so nothing is rewritten or discarded on the way (a path, a query, a fragment,
|
|
890
|
+
* credentials, an upper-case host, a default port, a non-ASCII host all fail). Bounded like an identity field.
|
|
891
|
+
*/
|
|
892
|
+
function parseServerUrl(value) {
|
|
893
|
+
if (typeof value !== "string" || value.length === 0 || value.length > 200) return void 0;
|
|
894
|
+
if (hasControlCharacter(value)) return void 0;
|
|
895
|
+
let url;
|
|
896
|
+
try {
|
|
897
|
+
url = new URL(value);
|
|
898
|
+
} catch {
|
|
899
|
+
return;
|
|
900
|
+
}
|
|
901
|
+
if (url.protocol !== "https:" || url.username !== "" || url.password !== "") return void 0;
|
|
902
|
+
if (value !== url.origin && value !== `${url.origin}/`) return void 0;
|
|
903
|
+
return url.origin;
|
|
904
|
+
}
|
|
887
905
|
/** The launcher's optional run link fields. A field that is present and not acceptable refuses them all: `undefined`. */
|
|
888
906
|
function parseRunContext(document) {
|
|
889
907
|
const context = {};
|
|
@@ -902,6 +920,11 @@ function parseRunContext(document) {
|
|
|
902
920
|
if (invocationId === void 0) return void 0;
|
|
903
921
|
context.invocationId = invocationId;
|
|
904
922
|
}
|
|
923
|
+
if (Object.hasOwn(document, "serverUrl")) {
|
|
924
|
+
const serverUrl = parseServerUrl(document.serverUrl);
|
|
925
|
+
if (serverUrl === void 0) return void 0;
|
|
926
|
+
context.serverUrl = serverUrl;
|
|
927
|
+
}
|
|
905
928
|
return context;
|
|
906
929
|
}
|
|
907
930
|
/** Resolves the launcher variable's value. Pure: no environment, no file. */
|
|
@@ -928,7 +951,8 @@ function resolveLauncher(raw) {
|
|
|
928
951
|
], [
|
|
929
952
|
"rootSpan",
|
|
930
953
|
"sessionId",
|
|
931
|
-
"invocationId"
|
|
954
|
+
"invocationId",
|
|
955
|
+
"serverUrl"
|
|
932
956
|
])) return off("launcher-malformed");
|
|
933
957
|
const endpoint = parseRelayUrl(document.relay);
|
|
934
958
|
if (endpoint === void 0) return off("launcher-relay-invalid");
|
|
@@ -964,6 +988,17 @@ function readLauncherHost(env) {
|
|
|
964
988
|
if (!isRecord(document) || document.version !== 1) return void 0;
|
|
965
989
|
return document.host === "action" ? "action" : void 0;
|
|
966
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
|
+
}
|
|
967
1002
|
/** Header names the exporter or the transport owns. A user file cannot set them. */
|
|
968
1003
|
const REFUSED_HEADER_NAMES = /* @__PURE__ */ new Set([
|
|
969
1004
|
"host",
|
|
@@ -1161,13 +1196,14 @@ function resolveTracingSettings(input) {
|
|
|
1161
1196
|
*/
|
|
1162
1197
|
async function startTracing(host, settings, env, log) {
|
|
1163
1198
|
try {
|
|
1164
|
-
const handle = await (await import("./tracing-
|
|
1199
|
+
const handle = await (await import("./tracing-B58yZAvo.mjs")).startTracing({
|
|
1165
1200
|
session: host.session,
|
|
1166
1201
|
tool: { hook: async (name, callback) => name === "execute.before" ? host.tool.hook(name, callback) : host.tool.hook(name, callback) },
|
|
1167
1202
|
event: host.event
|
|
1168
1203
|
}, settings, {
|
|
1169
1204
|
env,
|
|
1170
|
-
log
|
|
1205
|
+
log,
|
|
1206
|
+
...typeof host.app?.version === "string" ? { opencodeVersion: host.app.version } : {}
|
|
1171
1207
|
});
|
|
1172
1208
|
return async () => {
|
|
1173
1209
|
try {
|
|
@@ -1183,13 +1219,16 @@ async function startTracing(host, settings, env, log) {
|
|
|
1183
1219
|
}
|
|
1184
1220
|
async function setupFroBotPlugin(host, options = {}) {
|
|
1185
1221
|
const env = options.env ?? process.env;
|
|
1186
|
-
const
|
|
1187
|
-
|
|
1188
|
-
guard
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1222
|
+
const launcher = readLauncherKind(env);
|
|
1223
|
+
if (launcher !== "none") {
|
|
1224
|
+
const guard = createSubagentResumeGuard({ actionHost: launcher === "action" });
|
|
1225
|
+
await host.tool.hook("execute.before", async (event) => {
|
|
1226
|
+
guard.before(event);
|
|
1227
|
+
});
|
|
1228
|
+
await host.tool.hook("execute.after", (event) => {
|
|
1229
|
+
guard.after(event);
|
|
1230
|
+
});
|
|
1231
|
+
}
|
|
1193
1232
|
const tools = createSessionTools({
|
|
1194
1233
|
client: createPluginSessionClient(host.session),
|
|
1195
1234
|
directory: host.location.directory
|