@fro.bot/opencode-plugin 0.3.4 → 0.3.6

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
@@ -44,19 +44,44 @@ 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
- **Joining a turn to its Action run.** The Action's launcher document (`OPENCODE_FROBOT_TRACING`) may carry three 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:
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`) 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
 
55
80
  The plugin refuses the file, logging one line with a fixed reason and no values, unless it is a regular file you own, private to you (mode `0600`: **no** read, write or execute bit set for group or others, since it can hold a collector credential), under 16 KiB, and not inside the project directory. It is not read on Windows. When tracing turns on, the plugin logs the collector's host name once.
56
81
 
57
- **This file is consent for the whole machine, under your account.** The plugin cannot tell your OpenCode processes apart. Any OpenCode you run here with no launcher variable and no headless marker exports its traces to the collector in this file. That includes an `opencode serve` you start by hand, the background service the interactive app connects to, and an editor integration or script that starts OpenCode for you. The one exception is a server another program embeds with `opencode serve --stdio` (the SDK, the Fro Bot Action, the gateway): it stays off, because the plugin cannot see its password. Name only machines you want traced, and delete the file to turn tracing off everywhere.
82
+ **This file is consent for the whole machine, under your account.** The plugin cannot tell your OpenCode processes apart. Any OpenCode you run here with no launcher variable and no headless marker exports its traces to the collector in this file. That includes the interactive app (also with `--standalone`, which runs a private `serve --stdio` backend), `opencode run`, an `opencode serve` you start by hand, the background service the interactive app connects to, and an editor integration or script that starts OpenCode for you. It also includes other programs on this machine that embed OpenCode with `serve --stdio` (an SDK client, for one): they trace under your file unless they pass `OPENCODE_CONFIG_CONTENT`. The command line does not matter, only the launcher variable and the headless markers. Name only machines you want traced, and delete the file to turn tracing off everywhere.
58
83
 
59
- `opencode run` starts a private `serve --stdio` server unless a background service is already running. That server counts as a headless host, so it does not trace. Trace a local session through the TUI or a plain `opencode serve`.
84
+ `opencode run` and the interactive app with `--standalone` start a private `serve --stdio` server unless a background service is already running. That server traces under a valid file like any other local session. The Fro Bot Action, workspace agent and gateway always set the launcher variable, so this file never applies to them.
60
85
 
61
86
  **Matching steps to requests.** A model step is matched to its request by time, and the plugin stops matching for a session, until its execution ends, whenever it cannot tell the owner apart (an earlier request still has no step, a clock step-back, a lost event). The requests it could not match export no step data, an incomplete outcome and the gap `step-binding-uncertain`; a request that never gets a step (OpenCode abandoning it after an overflow or transport recovery) costs the rest of that execution's step data.
62
87
 
package/dist/index.mjs CHANGED
@@ -773,19 +773,6 @@ function createSubagentResumeGuard(options) {
773
773
  const TRACING_LAUNCHER_ENV = "OPENCODE_FROBOT_TRACING";
774
774
  /** Variables a headless server (the Action, the workspace, any `opencode serve`) always has and a local session lacks. */
775
775
  const HEADLESS_MARKERS = ["OPENCODE_PASSWORD", "OPENCODE_CONFIG_CONTENT"];
776
- /**
777
- * True when the command line is `opencode … serve … --stdio`: a server a parent process embeds (an SDK client, a gateway,
778
- * the Action). `opencode serve --stdio` deletes `OPENCODE_PASSWORD` and `OPENCODE_SERVER_PASSWORD` from the process
779
- * environment before a plugin loads (measured on 2.3.2), so such a server started with only a password shows none of the
780
- * markers above. The command line is what still says so. A `serve` started by hand, or the background service
781
- * (`serve --service`; `--stdio` cannot be combined with it), is not embedded: the user's file is consent for those too.
782
- * The subcommand is the first non-option word after the program path; `--stdio` must come after it.
783
- */
784
- function isEmbeddedServe(argv) {
785
- const rest = argv.slice(2);
786
- const serve = rest.indexOf("serve");
787
- return serve !== -1 && rest.slice(serve + 1).includes("--stdio");
788
- }
789
776
  /** The user file, relative to the user's config directory. Not under `opencode/`: OpenCode reads nothing from here. */
790
777
  const USER_SETTINGS_RELATIVE_PATH = path.join("fro-bot", "opencode-plugin", "tracing.json");
791
778
  const SILENT_REASONS = /* @__PURE__ */ new Set([
@@ -897,6 +884,24 @@ function parseTextField(value) {
897
884
  if (typeof value !== "string" || value.length === 0 || value.length > 200) return void 0;
898
885
  return hasControlCharacter(value) ? void 0 : value;
899
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
+ }
900
905
  /** The launcher's optional run link fields. A field that is present and not acceptable refuses them all: `undefined`. */
901
906
  function parseRunContext(document) {
902
907
  const context = {};
@@ -915,6 +920,11 @@ function parseRunContext(document) {
915
920
  if (invocationId === void 0) return void 0;
916
921
  context.invocationId = invocationId;
917
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
+ }
918
928
  return context;
919
929
  }
920
930
  /** Resolves the launcher variable's value. Pure: no environment, no file. */
@@ -941,7 +951,8 @@ function resolveLauncher(raw) {
941
951
  ], [
942
952
  "rootSpan",
943
953
  "sessionId",
944
- "invocationId"
954
+ "invocationId",
955
+ "serverUrl"
945
956
  ])) return off("launcher-malformed");
946
957
  const endpoint = parseRelayUrl(document.relay);
947
958
  if (endpoint === void 0) return off("launcher-relay-invalid");
@@ -1152,7 +1163,7 @@ function resolveTracingSettings(input) {
1152
1163
  try {
1153
1164
  const launcher = env[TRACING_LAUNCHER_ENV];
1154
1165
  if (launcher !== void 0) return finish(resolveLauncher(launcher));
1155
- if (HEADLESS_MARKERS.some((marker) => env[marker] !== void 0) || isEmbeddedServe(input.argv ?? process.argv)) return finish(off("headless-host"));
1166
+ if (HEADLESS_MARKERS.some((marker) => env[marker] !== void 0)) return finish(off("headless-host"));
1156
1167
  const platform = input.platform ?? process.platform;
1157
1168
  const uid = input.uid ?? process.getuid?.();
1158
1169
  if (platform === "win32" || uid === void 0) return finish(off("unsupported-platform"));
@@ -1174,13 +1185,14 @@ function resolveTracingSettings(input) {
1174
1185
  */
1175
1186
  async function startTracing(host, settings, env, log) {
1176
1187
  try {
1177
- const handle = await (await import("./tracing-CHrTlTyx.mjs")).startTracing({
1188
+ const handle = await (await import("./tracing-B58yZAvo.mjs")).startTracing({
1178
1189
  session: host.session,
1179
1190
  tool: { hook: async (name, callback) => name === "execute.before" ? host.tool.hook(name, callback) : host.tool.hook(name, callback) },
1180
1191
  event: host.event
1181
1192
  }, settings, {
1182
1193
  env,
1183
- log
1194
+ log,
1195
+ ...typeof host.app?.version === "string" ? { opencodeVersion: host.app.version } : {}
1184
1196
  });
1185
1197
  return async () => {
1186
1198
  try {