@fro.bot/opencode-plugin 0.3.0 → 0.3.1
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,7 +44,7 @@ Every span carries `langfuse.session.id` set to the **root** session's id, so La
|
|
|
44
44
|
|
|
45
45
|
**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:
|
|
46
46
|
|
|
47
|
-
- `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 (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. `session.id` and `gen_ai.conversation.id` keep each span's own OpenCode session either way.
|
|
47
|
+
- `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.
|
|
48
48
|
- `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`.
|
|
49
49
|
- `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.
|
|
50
50
|
|
package/dist/index.mjs
CHANGED
|
@@ -1092,7 +1092,7 @@ function resolveTracingSettings(input) {
|
|
|
1092
1092
|
*/
|
|
1093
1093
|
async function startTracing(host, settings, env, log) {
|
|
1094
1094
|
try {
|
|
1095
|
-
const handle = await (await import("./tracing-
|
|
1095
|
+
const handle = await (await import("./tracing-B4QJ2-E2.mjs")).startTracing({
|
|
1096
1096
|
session: host.session,
|
|
1097
1097
|
tool: { hook: async (name, callback) => name === "execute.before" ? host.tool.hook(name, callback) : host.tool.hook(name, callback) },
|
|
1098
1098
|
event: host.event
|
|
@@ -3834,8 +3834,6 @@ const SCRUB_PATTERNS = [
|
|
|
3834
3834
|
];
|
|
3835
3835
|
/** Env names whose value the literal pass removes. `OPENCODE_PASSWORD` is the server's own credential. */
|
|
3836
3836
|
const SECRET_ENV_NAME = /SECRET|TOKEN|PASSWORD|PASSWD|PASSPHRASE|CREDENTIAL|API_?KEY|PRIVATE_?KEY|ACCESS_?KEY|AUTHORIZATION/i;
|
|
3837
|
-
const MIN_LITERAL_CHARS = 8;
|
|
3838
|
-
const MAX_LITERAL_CHARS = 4096;
|
|
3839
3837
|
const MAX_LITERALS = 128;
|
|
3840
3838
|
/**
|
|
3841
3839
|
* The forms of one secret to remove: the value, and its JSON-escaped text when that differs. None for a value outside the
|
|
@@ -3843,9 +3841,9 @@ const MAX_LITERALS = 128;
|
|
|
3843
3841
|
* secret anyone typed.
|
|
3844
3842
|
*/
|
|
3845
3843
|
function literalForms(value) {
|
|
3846
|
-
if (value === void 0 || value.length <
|
|
3844
|
+
if (value === void 0 || value.length < 8 || value.length > 65536) return [];
|
|
3847
3845
|
const escaped = JSON.stringify(value).slice(1, -1);
|
|
3848
|
-
return escaped !== value && escaped.length <=
|
|
3846
|
+
return escaped !== value && escaped.length <= 131072 ? [value, escaped] : [value];
|
|
3849
3847
|
}
|
|
3850
3848
|
/**
|
|
3851
3849
|
* The literal secrets to remove: from the environment once, raw and JSON-escaped, longest first and at most `MAX_LITERALS`.
|
|
@@ -3862,14 +3860,74 @@ function collectLiterals(env, extra = []) {
|
|
|
3862
3860
|
return [...found].toSorted((a, b) => b.length - a.length).slice(0, MAX_LITERALS);
|
|
3863
3861
|
}
|
|
3864
3862
|
/**
|
|
3863
|
+
* Literals longer than this are searched with a search that cannot go quadratic. `String.prototype.indexOf` is fast (native,
|
|
3864
|
+
* and skips ahead on a mismatch) but not linear in the worst case: V8 takes seconds to search a megabyte for a 64 KiB literal
|
|
3865
|
+
* when each alignment matches almost to the end. Short literals are bounded by their own length, so they stay native.
|
|
3866
|
+
*/
|
|
3867
|
+
const NATIVE_SEARCH_MAX_CHARS = 64;
|
|
3868
|
+
/** Where a literal can resume after a partial match: `table[i]` is the length of the longest proper border of `literal[0..i]`. */
|
|
3869
|
+
function failureTable(literal) {
|
|
3870
|
+
const table = new Int32Array(literal.length);
|
|
3871
|
+
for (let index = 1, matched = 0; index < literal.length; index += 1) {
|
|
3872
|
+
while (matched > 0 && literal.charCodeAt(index) !== literal.charCodeAt(matched)) matched = table[matched - 1] ?? 0;
|
|
3873
|
+
if (literal.charCodeAt(index) === literal.charCodeAt(matched)) matched += 1;
|
|
3874
|
+
table[index] = matched;
|
|
3875
|
+
}
|
|
3876
|
+
return table;
|
|
3877
|
+
}
|
|
3878
|
+
function createLiteralSearch() {
|
|
3879
|
+
const tables = /* @__PURE__ */ new Map();
|
|
3880
|
+
const tableOf = (literal) => {
|
|
3881
|
+
let table = tables.get(literal);
|
|
3882
|
+
if (table === void 0) {
|
|
3883
|
+
table = failureTable(literal);
|
|
3884
|
+
tables.set(literal, table);
|
|
3885
|
+
}
|
|
3886
|
+
return table;
|
|
3887
|
+
};
|
|
3888
|
+
const scan = (text, literal, found) => {
|
|
3889
|
+
const table = tableOf(literal);
|
|
3890
|
+
for (let index = 0, matched = 0; index < text.length; index += 1) {
|
|
3891
|
+
const code = text.charCodeAt(index);
|
|
3892
|
+
while (matched > 0 && code !== literal.charCodeAt(matched)) matched = table[matched - 1] ?? 0;
|
|
3893
|
+
if (code === literal.charCodeAt(matched)) matched += 1;
|
|
3894
|
+
if (matched === literal.length) {
|
|
3895
|
+
if (found(index + 1)) return;
|
|
3896
|
+
matched = table[matched - 1] ?? 0;
|
|
3897
|
+
}
|
|
3898
|
+
}
|
|
3899
|
+
};
|
|
3900
|
+
return {
|
|
3901
|
+
each: (text, literal, found) => {
|
|
3902
|
+
if (literal.length <= NATIVE_SEARCH_MAX_CHARS) {
|
|
3903
|
+
for (let at = text.indexOf(literal); at !== -1; at = text.indexOf(literal, at + 1)) found(at, at + literal.length);
|
|
3904
|
+
return;
|
|
3905
|
+
}
|
|
3906
|
+
scan(text, literal, (end) => {
|
|
3907
|
+
found(end - literal.length, end);
|
|
3908
|
+
return false;
|
|
3909
|
+
});
|
|
3910
|
+
},
|
|
3911
|
+
has: (text, literal) => {
|
|
3912
|
+
if (literal.length <= NATIVE_SEARCH_MAX_CHARS) return text.includes(literal);
|
|
3913
|
+
let seen = false;
|
|
3914
|
+
scan(text, literal, () => {
|
|
3915
|
+
seen = true;
|
|
3916
|
+
return true;
|
|
3917
|
+
});
|
|
3918
|
+
return seen;
|
|
3919
|
+
}
|
|
3920
|
+
};
|
|
3921
|
+
}
|
|
3922
|
+
/**
|
|
3865
3923
|
* The environment's literal secrets as a matcher: every occurrence of each, overlapping ones included (the union covers a
|
|
3866
3924
|
* secret that overlaps itself or another). The literals were collected once at start; they are never named.
|
|
3867
3925
|
*/
|
|
3868
|
-
function literalMatcher(literals) {
|
|
3926
|
+
function literalMatcher(literals, search = createLiteralSearch()) {
|
|
3869
3927
|
return {
|
|
3870
3928
|
id: "environment-literal",
|
|
3871
3929
|
find: (text, _lower, emit) => {
|
|
3872
|
-
for (const literal of literals)
|
|
3930
|
+
for (const literal of literals) search.each(text, literal, emit);
|
|
3873
3931
|
}
|
|
3874
3932
|
};
|
|
3875
3933
|
}
|
|
@@ -3946,7 +4004,8 @@ function createScrubber(options = {}) {
|
|
|
3946
4004
|
const ceiling = options.limits?.inputCeilingChars ?? DEFAULT_CONTENT_LIMITS.inputCeilingChars;
|
|
3947
4005
|
const literals = [...collectLiterals(options.env ?? {}, options.extraSecrets)];
|
|
3948
4006
|
const known = new Set(literals);
|
|
3949
|
-
const
|
|
4007
|
+
const search = createLiteralSearch();
|
|
4008
|
+
const matchers = [...options.patterns ?? SCRUB_PATTERNS, literalMatcher(literals, search)];
|
|
3950
4009
|
let survivals = 0;
|
|
3951
4010
|
return {
|
|
3952
4011
|
addLiterals: (values) => {
|
|
@@ -3958,7 +4017,7 @@ function createScrubber(options = {}) {
|
|
|
3958
4017
|
},
|
|
3959
4018
|
inputCeilingChars: ceiling,
|
|
3960
4019
|
survived: (text) => {
|
|
3961
|
-
for (const literal of literals) if (
|
|
4020
|
+
for (const literal of literals) if (search.has(text, literal)) {
|
|
3962
4021
|
survivals += 1;
|
|
3963
4022
|
return true;
|
|
3964
4023
|
}
|
|
@@ -5674,6 +5733,17 @@ function toPendingSpan(record, options = {}) {
|
|
|
5674
5733
|
case "invoke_agent": return invokeSpan(record, options);
|
|
5675
5734
|
}
|
|
5676
5735
|
}
|
|
5736
|
+
const SESSION_ATTRIBUTE = "langfuse.session.id";
|
|
5737
|
+
/**
|
|
5738
|
+
* Whether the span carries the launcher's session id exactly as given. Equal text is not enough: a value the scrubber withheld
|
|
5739
|
+
* is exported as the fixed marker `[omitted]`, so an id that is literally `[omitted]` would equal its own withheld form. The
|
|
5740
|
+
* omission status the scrub wrote (`<attribute>:<reason>`) is what says whether it was withheld.
|
|
5741
|
+
*/
|
|
5742
|
+
function sessionIdExportedAsGiven(span, sessionId) {
|
|
5743
|
+
if (span.attributes[SESSION_ATTRIBUTE] !== sessionId) return false;
|
|
5744
|
+
const omitted = span.attributes[MARKER.omitted];
|
|
5745
|
+
return !(Array.isArray(omitted) && omitted.some((entry) => typeof entry === "string" && entry.startsWith(`${SESSION_ATTRIBUTE}:`)));
|
|
5746
|
+
}
|
|
5677
5747
|
/**
|
|
5678
5748
|
* Record to an exportable span: attributes, then the one scrubbing pass.
|
|
5679
5749
|
*
|
|
@@ -5684,7 +5754,7 @@ function toPendingSpan(record, options = {}) {
|
|
|
5684
5754
|
*/
|
|
5685
5755
|
function toExportSpan(record, options, scrubber, limits) {
|
|
5686
5756
|
const span = scrubSpan(toPendingSpan(record, options), scrubber, limits);
|
|
5687
|
-
if (options.sessionId === void 0 || span
|
|
5757
|
+
if (options.sessionId === void 0 || sessionIdExportedAsGiven(span, options.sessionId)) return span;
|
|
5688
5758
|
return scrubSpan(toPendingSpan(record, {
|
|
5689
5759
|
...options,
|
|
5690
5760
|
sessionId: void 0
|
|
@@ -7526,19 +7596,26 @@ function observeHook(name, payload, at, snapshot = {}) {
|
|
|
7526
7596
|
function toolErrorType(type, message) {
|
|
7527
7597
|
return message === "Session reuse is disabled in this environment. Start a new task and include the context it needs." ? "plugin.reuse-guard" : type;
|
|
7528
7598
|
}
|
|
7529
|
-
/** How far into a report's text the
|
|
7599
|
+
/** How far into a report's text the subagent header is looked for. */
|
|
7530
7600
|
const REPORT_HEADER_WINDOW = 400;
|
|
7531
7601
|
/**
|
|
7532
|
-
* The
|
|
7533
|
-
*
|
|
7534
|
-
*
|
|
7602
|
+
* The two header forms a subagent report opens with. OpenCode 2.3.2 writes `<subagent sessionID=… state=… …>`; 2.4.1
|
|
7603
|
+
* (upstream #64971) writes `<background-result kind="subagent" sessionID=… state=… …>`. A `<background-result>` of any
|
|
7604
|
+
* other kind (`shell`, `image`, `codemode`) is not a subagent report.
|
|
7605
|
+
*/
|
|
7606
|
+
const REPORT_HEADER_PREFIXES = ["<subagent ", "<background-result kind=\"subagent\" "];
|
|
7607
|
+
/**
|
|
7608
|
+
* The state a subagent report carries. The report's own header is the truth (`<subagent … state="running" …>` on 2.3.2,
|
|
7609
|
+
* `<background-result kind="subagent" … state="running" …>` on 2.4.1): the item's `metadata.state` says `completed` even
|
|
7610
|
+
* on the interim report a parent gets while the child's own background work still runs. Reads only the head of the text,
|
|
7611
|
+
* by `indexOf`, so cost does not grow with a report's size.
|
|
7535
7612
|
*/
|
|
7536
7613
|
function reportStateOf(text, metadata) {
|
|
7537
7614
|
if (typeof text === "string") {
|
|
7538
7615
|
const head = text.slice(0, REPORT_HEADER_WINDOW);
|
|
7539
7616
|
const close = head.indexOf(">");
|
|
7540
7617
|
const marker = head.indexOf(" state=\"");
|
|
7541
|
-
if (head.startsWith(
|
|
7618
|
+
if (REPORT_HEADER_PREFIXES.some((prefix) => head.startsWith(prefix)) && marker !== -1 && (close === -1 || marker < close)) {
|
|
7542
7619
|
const from = marker + 8;
|
|
7543
7620
|
const to = head.indexOf("\"", from);
|
|
7544
7621
|
if (to !== -1) return head.slice(from, to);
|
|
@@ -7877,4 +7954,4 @@ async function startTracing(host, settings, options) {
|
|
|
7877
7954
|
}
|
|
7878
7955
|
export { startTracing };
|
|
7879
7956
|
|
|
7880
|
-
//# sourceMappingURL=tracing-
|
|
7957
|
+
//# sourceMappingURL=tracing-B4QJ2-E2.mjs.map
|