@pinta-ai/pinta-opencode 0.1.0
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/CHANGELOG.md +17 -0
- package/LICENSE +136 -0
- package/README.md +121 -0
- package/dist/config.d.ts +27 -0
- package/dist/config.js +49 -0
- package/dist/config.js.map +1 -0
- package/dist/core/guard.d.ts +29 -0
- package/dist/core/guard.js +50 -0
- package/dist/core/guard.js.map +1 -0
- package/dist/core/otlp.d.ts +51 -0
- package/dist/core/otlp.js +135 -0
- package/dist/core/otlp.js.map +1 -0
- package/dist/core/redact.d.ts +57 -0
- package/dist/core/redact.js +141 -0
- package/dist/core/redact.js.map +1 -0
- package/dist/core/retry-queue.d.ts +14 -0
- package/dist/core/retry-queue.js +26 -0
- package/dist/core/retry-queue.js.map +1 -0
- package/dist/core/trace.d.ts +16 -0
- package/dist/core/trace.js +50 -0
- package/dist/core/trace.js.map +1 -0
- package/dist/core/transport.d.ts +20 -0
- package/dist/core/transport.js +69 -0
- package/dist/core/transport.js.map +1 -0
- package/dist/env-file.d.ts +4 -0
- package/dist/env-file.js +53 -0
- package/dist/env-file.js.map +1 -0
- package/dist/plugin.d.ts +27 -0
- package/dist/plugin.js +85 -0
- package/dist/plugin.js.map +1 -0
- package/dist/telemetry.d.ts +37 -0
- package/dist/telemetry.js +53 -0
- package/dist/telemetry.js.map +1 -0
- package/package.json +40 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 (unreleased)
|
|
4
|
+
|
|
5
|
+
Initial implementation — OTLP forwarder + guard for opencode, as an in-process plugin.
|
|
6
|
+
|
|
7
|
+
- Plugin entry (`PintaOpencode`) wiring `chat.message` (trace rotation), `event`
|
|
8
|
+
(lifecycle telemetry + flush on `session.idle`), `tool.execute.before`
|
|
9
|
+
(guard gate → DENY throws with reason), `tool.execute.after` (tool span).
|
|
10
|
+
- Core (ported from pinta-copilot): `otlp` (Bronze flattening, `ingest.type=opencode`),
|
|
11
|
+
`redact`, `transport` (in-memory retry), `trace` (in-memory, sessionID-keyed),
|
|
12
|
+
`guard` (50ms fail-open, decoupled from env).
|
|
13
|
+
- Config resolution: plugin options → `process.env` → `pinta-opencode.env`.
|
|
14
|
+
- Validated end-to-end against opencode 1.15.3 (ALLOW/DENY + OTLP collection).
|
|
15
|
+
See `HYPOTHESIS_VALIDATION.md` §10–13.
|
|
16
|
+
- Robustness (M2): 40 unit/integration tests incl. a real local collector+guard
|
|
17
|
+
harness covering ALLOW / DENY / fail-open / session.idle flush.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# PolyForm Noncommercial License 1.0.0
|
|
2
|
+
|
|
3
|
+
<https://polyformproject.org/licenses/noncommercial/1.0.0>
|
|
4
|
+
|
|
5
|
+
## Acceptance
|
|
6
|
+
|
|
7
|
+
In order to get any license under these terms, you must agree
|
|
8
|
+
to them as both strict obligations and conditions to all
|
|
9
|
+
your licenses.
|
|
10
|
+
|
|
11
|
+
## Copyright License
|
|
12
|
+
|
|
13
|
+
The licensor grants you a copyright license for the
|
|
14
|
+
software to do everything you might do with the software
|
|
15
|
+
that would otherwise infringe the licensor's copyright
|
|
16
|
+
in it for any permitted purpose. However, you may
|
|
17
|
+
only distribute the software according to [Distribution
|
|
18
|
+
License](#distribution-license) and make changes or new works
|
|
19
|
+
based on the software according to [Changes and New Works
|
|
20
|
+
License](#changes-and-new-works-license).
|
|
21
|
+
|
|
22
|
+
## Distribution License
|
|
23
|
+
|
|
24
|
+
The licensor grants you an additional copyright license to
|
|
25
|
+
distribute copies of the software. Your license to distribute
|
|
26
|
+
covers distributing the software with changes and new works
|
|
27
|
+
permitted by [Changes and New Works
|
|
28
|
+
License](#changes-and-new-works-license).
|
|
29
|
+
|
|
30
|
+
## Notices
|
|
31
|
+
|
|
32
|
+
You must ensure that anyone who gets a copy of any part of
|
|
33
|
+
the software from you also gets a copy of these terms or the
|
|
34
|
+
URL for them above, as well as copies of any plain-text lines
|
|
35
|
+
beginning with `Required Notice:` that the licensor provided
|
|
36
|
+
with the software. For example:
|
|
37
|
+
|
|
38
|
+
> Required Notice: Copyright Pinta AI (https://pinta.sh)
|
|
39
|
+
|
|
40
|
+
## Changes and New Works License
|
|
41
|
+
|
|
42
|
+
The licensor grants you an additional copyright license to make
|
|
43
|
+
changes and new works based on the software for any permitted
|
|
44
|
+
purpose.
|
|
45
|
+
|
|
46
|
+
## Patent License
|
|
47
|
+
|
|
48
|
+
The licensor grants you a patent license for the software that
|
|
49
|
+
covers patent claims the licensor can license, or becomes able
|
|
50
|
+
to license, that you would infringe by using the software.
|
|
51
|
+
|
|
52
|
+
## Noncommercial Purposes
|
|
53
|
+
|
|
54
|
+
Any noncommercial purpose is a permitted purpose.
|
|
55
|
+
|
|
56
|
+
## Personal Uses
|
|
57
|
+
|
|
58
|
+
Personal use for research, experiment, and testing for
|
|
59
|
+
the benefit of public knowledge, personal study, private
|
|
60
|
+
entertainment, hobby projects, amateur pursuits, or religious
|
|
61
|
+
observance, without any anticipated commercial application,
|
|
62
|
+
is use for a permitted purpose.
|
|
63
|
+
|
|
64
|
+
## Noncommercial Organizations
|
|
65
|
+
|
|
66
|
+
Use by any charitable organization, educational institution,
|
|
67
|
+
public research organization, public safety or health
|
|
68
|
+
organization, environmental protection organization, or
|
|
69
|
+
government institution is use for a permitted purpose
|
|
70
|
+
regardless of the source of funding or obligations resulting
|
|
71
|
+
from the funding.
|
|
72
|
+
|
|
73
|
+
## Fair Use
|
|
74
|
+
|
|
75
|
+
You may have "fair use" rights for the software under the
|
|
76
|
+
law. These terms do not limit them.
|
|
77
|
+
|
|
78
|
+
## No Other Rights
|
|
79
|
+
|
|
80
|
+
These terms do not allow you to sublicense or transfer any of
|
|
81
|
+
your licenses to anyone else, or prevent the licensor from
|
|
82
|
+
granting licenses to anyone else. These terms do not imply
|
|
83
|
+
any other licenses.
|
|
84
|
+
|
|
85
|
+
## Patent Defense
|
|
86
|
+
|
|
87
|
+
If you make any written claim that the software infringes or
|
|
88
|
+
contributes to infringement of any patent, your patent license
|
|
89
|
+
for the software granted under these terms ends immediately. If
|
|
90
|
+
your company makes such a claim, your patent license ends
|
|
91
|
+
immediately for work on behalf of your company.
|
|
92
|
+
|
|
93
|
+
## Violations
|
|
94
|
+
|
|
95
|
+
The first time you are notified in writing that you have
|
|
96
|
+
violated any of these terms, or done anything with the software
|
|
97
|
+
not covered by your licenses, your licenses can nonetheless
|
|
98
|
+
continue if you come into full compliance with these terms,
|
|
99
|
+
and take practical steps to correct past violations, within
|
|
100
|
+
32 days of receiving notice. Otherwise, all your licenses
|
|
101
|
+
end immediately.
|
|
102
|
+
|
|
103
|
+
## No Liability
|
|
104
|
+
|
|
105
|
+
***As far as the law allows, the software comes as is, without
|
|
106
|
+
any warranty or condition, and the licensor will not be liable
|
|
107
|
+
to you for any damages arising out of these terms or the use
|
|
108
|
+
or nature of the software, under any kind of legal claim.***
|
|
109
|
+
|
|
110
|
+
## Definitions
|
|
111
|
+
|
|
112
|
+
The **licensor** is the individual or entity offering these
|
|
113
|
+
terms, and the **software** is the software the licensor makes
|
|
114
|
+
available under these terms.
|
|
115
|
+
|
|
116
|
+
**You** refers to the individual or entity agreeing to these
|
|
117
|
+
terms.
|
|
118
|
+
|
|
119
|
+
**Your company** is any legal entity, sole proprietorship,
|
|
120
|
+
or other kind of organization that you work for, plus all
|
|
121
|
+
organizations that have control over, are under the control
|
|
122
|
+
of, or are under common control with that organization.
|
|
123
|
+
**Control** means ownership of substantially all the assets of
|
|
124
|
+
an entity, or the power to direct its management and policies
|
|
125
|
+
by vote, contract, or otherwise. Control can be direct or
|
|
126
|
+
indirect.
|
|
127
|
+
|
|
128
|
+
**Your licenses** are all the licenses granted to you for the
|
|
129
|
+
software under these terms.
|
|
130
|
+
|
|
131
|
+
**Use** means anything you do with the software requiring one
|
|
132
|
+
of your licenses.
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
Required Notice: Copyright (c) 2026 Pinta AI
|
package/README.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# pinta-opencode — OTLP forwarder + guard for opencode
|
|
2
|
+
|
|
3
|
+
Converts **opencode** session/tool events into OTLP/HTTP spans and forwards them to any OpenTelemetry-compatible collector, with an optional external **guard** that can allow/deny tool calls and surface a human-readable reason. Vendor-neutral. No Pinta CLI dependency. Identity is attached at the relay layer.
|
|
4
|
+
|
|
5
|
+
Unlike the Claude Code / Codex / Copilot adapters (which spawn a process per hook and talk over stdin/stdout), opencode loads plugins **in-process**. pinta-opencode is therefore a **single importable plugin module** — installed via `opencode.json` or a plugins-dir drop-in, no opencode source changes.
|
|
6
|
+
|
|
7
|
+
> Status: spec complete and validated end-to-end against **opencode 1.15.3**. See [`SPEC.md`](./SPEC.md), [`PLAN.md`](./PLAN.md), and the empirical record in [`HYPOTHESIS_VALIDATION.md`](./HYPOTHESIS_VALIDATION.md) (§10–13).
|
|
8
|
+
|
|
9
|
+
## How it hooks in
|
|
10
|
+
|
|
11
|
+
opencode fires plugin hooks around every built-in **and** MCP tool. This adapter uses only non-experimental hooks:
|
|
12
|
+
|
|
13
|
+
| Hook | Adapter does | Verified payload |
|
|
14
|
+
|---|---|---|
|
|
15
|
+
| `chat.message` | start a new trace (turn boundary) | `{ sessionID, agent, model, messageID, variant }` |
|
|
16
|
+
| `event` | lifecycle span (Bronze flatten) + flush on `session.idle` | `{ event: { id, type, properties } }`, every event carries `properties.sessionID` |
|
|
17
|
+
| `tool.execute.before` | query guard → **`throw` on DENY** + emit span | input `{ tool, sessionID, callID }`, output `{ args }` (full tool args, mutable) |
|
|
18
|
+
| `tool.execute.after` | tool-result span (incl. exit code) | output `{ title, output, metadata{ output, exit, truncated, … } }` |
|
|
19
|
+
|
|
20
|
+
> The `permission.ask` plugin hook is **declared but never triggered** in opencode — do not depend on it. Gating is done in `tool.execute.before` only.
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
Add to global `~/.config/opencode/opencode.json` (or a project `opencode.json`):
|
|
25
|
+
|
|
26
|
+
```jsonc
|
|
27
|
+
{
|
|
28
|
+
"plugin": [
|
|
29
|
+
["@pinta-ai/pinta-opencode", {
|
|
30
|
+
"endpoint": "https://your-collector.example.com/v1/traces",
|
|
31
|
+
"guard": "https://your-relay.example.com/guard"
|
|
32
|
+
}]
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
opencode installs the npm package on demand and checks `engines.opencode` for compatibility. Alternatively drop a single file into `~/.config/opencode/plugins/` (global) or `.opencode/plugins/` (project) — auto-discovered, no config edit.
|
|
38
|
+
|
|
39
|
+
> Managed installs (Pinta Manager) inject the same `plugin` line via the sidecar enroll module — no manual step.
|
|
40
|
+
|
|
41
|
+
## Configuration
|
|
42
|
+
|
|
43
|
+
Resolution order: **plugin options (2nd arg) → `process.env` → `~/.config/opencode/pinta-opencode.env`** (unset-only). Both options and env are visible at runtime (verified).
|
|
44
|
+
|
|
45
|
+
```env
|
|
46
|
+
# ~/.config/opencode/pinta-opencode.env
|
|
47
|
+
PINTA_OPENCODE_ENDPOINT=https://your-collector.example.com/v1/traces
|
|
48
|
+
PINTA_OPENCODE_TOKEN=YOUR-TOKEN
|
|
49
|
+
# optional: external guard (allow/deny tool calls)
|
|
50
|
+
PINTA_OPENCODE_GUARD=https://your-relay.example.com/guard
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
| Var (option / env) | Purpose |
|
|
54
|
+
|---|---|
|
|
55
|
+
| `endpoint` / `PINTA_OPENCODE_ENDPOINT` | Full OTLP/HTTP traces URL. Falls back to `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` → `OTEL_EXPORTER_OTLP_ENDPOINT` (+`/v1/traces`). No endpoint → telemetry disabled. |
|
|
56
|
+
| `headers` / `PINTA_OPENCODE_HEADERS` | `key=val,key=val` request headers (auth). Falls back to `OTEL_EXPORTER_OTLP_HEADERS`. |
|
|
57
|
+
| `guard` / `PINTA_OPENCODE_GUARD` | Optional. POST'd on `tool.execute.before`; a `DENY` blocks the tool. No endpoint → governance disabled. |
|
|
58
|
+
| `token` / `PINTA_OPENCODE_TOKEN` | Sent as `x-pinta-relay-token` on guard + OTLP. |
|
|
59
|
+
| `PINTA_OPENCODE_GUARD_TIMEOUT_MS` | Guard client timeout (default `50`; `300` recommended in production for cold-start). |
|
|
60
|
+
| `PINTA_OPENCODE_GUARD_DISABLED=1` | Force-disable the guard. |
|
|
61
|
+
|
|
62
|
+
Telemetry and governance are independent — endpoint only, guard only, both, or neither all work.
|
|
63
|
+
|
|
64
|
+
## Guard (allow / deny + reason)
|
|
65
|
+
|
|
66
|
+
On `tool.execute.before` the adapter POSTs to the guard endpoint (cc/codex/copilot contract — backend unchanged):
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
POST {guard} header: x-pinta-relay-token: {PINTA_RELAY_TOKEN}
|
|
70
|
+
body: { "input": { "spanId", "toolName", "toolInput", "rawTextFields": { "toolInput" } } }
|
|
71
|
+
200: { "decision": "ALLOW"|"DENY"|"REVIEW", "reason", "userMessage?", "durationMs?" }
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
A `DENY` becomes `throw new Error(userMessage ?? reason ?? "guard_deny")`. Verified effect: **only that tool is blocked** (`tool.execute.after` does not fire), the reason shows as `✗ … failed` + `Error: <reason>` to the model/TUI, and the session stays alive. `ALLOW`/`REVIEW` pass through.
|
|
75
|
+
|
|
76
|
+
Guard is **fail-open** (no endpoint / `PINTA_GUARD_DISABLED=1` / non-200 / timeout / error → allow), so it never breaks a session. The 50ms inline call does not block tool execution.
|
|
77
|
+
|
|
78
|
+
## Span conventions
|
|
79
|
+
|
|
80
|
+
| Attribute | Value |
|
|
81
|
+
|---|---|
|
|
82
|
+
| `ingest.type` | `"opencode"` (aware-backend discriminator) |
|
|
83
|
+
| `opencode.kind` | `event` \| `tool.before` \| `tool.after` |
|
|
84
|
+
| `opencode.event_type` | event type (`message.part.updated`, `session.idle`, …) |
|
|
85
|
+
| `opencode.<key>` | every other field (Bronze flattening, raw key preserved) |
|
|
86
|
+
| `pinta.guard.{decision,duration_ms,matched_rule,fail_open_reason}` | guard result |
|
|
87
|
+
| `service.name` | `"opencode"` · `telemetry.sdk.name` `"pinta-opencode"` |
|
|
88
|
+
|
|
89
|
+
Tool spans are built from `tool.execute.before/after` (richer: args, output, exit) rather than the event bus; `event` covers lifecycle and turn boundaries.
|
|
90
|
+
|
|
91
|
+
## Architecture
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
src/
|
|
95
|
+
├── plugin.ts # entry: export const PintaOpencode = async (input, options) => Hooks
|
|
96
|
+
├── config.ts # options → process.env → pinta-opencode.env (unset-only)
|
|
97
|
+
├── telemetry.ts # event → span (Bronze flatten), tool span from before/after
|
|
98
|
+
├── core/
|
|
99
|
+
│ ├── otlp.ts # Bronze flattening (opencode.*) + ingest.type + guard attrs
|
|
100
|
+
│ ├── trace.ts # ULID trace, keyed by sessionID, rotated on chat.message
|
|
101
|
+
│ ├── transport.ts # POST OTLP/HTTP traces (5s), in-memory retry queue
|
|
102
|
+
│ ├── retry-queue.ts # batched flush on next event
|
|
103
|
+
│ ├── guard.ts # POST PINTA_GUARD_ENDPOINT (50ms), fail-open
|
|
104
|
+
│ └── redact.ts # Tier-1 redaction + Tier-3 truncation
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
State lives in memory (keyed by `sessionID`) — opencode instantiates the plugin once per instance, so per-event file persistence is unnecessary (optional via `PINTA_PERSIST=1`).
|
|
108
|
+
|
|
109
|
+
## Development
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
bun install
|
|
113
|
+
bun run build # → dist/
|
|
114
|
+
bun test
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Compatibility: opencode **>= 1.15.0** (`engines.opencode`). Uses only non-experimental hooks.
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
|
|
121
|
+
[PolyForm Noncommercial 1.0.0](https://polyformproject.org/licenses/noncommercial/1.0.0) — see [LICENSE](LICENSE). Commercial use is not permitted; contact Pinta AI for a commercial license.
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Options object passed via `opencode.json` → `plugin:[["@pinta-ai/pinta-opencode", {…}]]`. */
|
|
2
|
+
export interface PintaOptions {
|
|
3
|
+
/** Full OTLP/HTTP traces URL. */
|
|
4
|
+
endpoint?: string;
|
|
5
|
+
/** `key=val,key=val` request headers, or a parsed record. */
|
|
6
|
+
headers?: string | Record<string, string>;
|
|
7
|
+
/** Guard policy server URL. */
|
|
8
|
+
guard?: string;
|
|
9
|
+
/** Relay token (sent as x-pinta-relay-token). */
|
|
10
|
+
token?: string;
|
|
11
|
+
/** Guard client timeout in ms (default 50). */
|
|
12
|
+
guardTimeoutMs?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface ResolvedConfig {
|
|
15
|
+
endpoint?: string;
|
|
16
|
+
headers: Record<string, string>;
|
|
17
|
+
guardEndpoint?: string;
|
|
18
|
+
relayToken?: string;
|
|
19
|
+
guardTimeoutMs: number;
|
|
20
|
+
guardDisabled: boolean;
|
|
21
|
+
serviceVersion: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Resolve runtime config. Precedence: plugin options → process.env →
|
|
25
|
+
* env-file (unset-only). Both options and env are visible at runtime (verified G5).
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveConfig(options?: PintaOptions): ResolvedConfig;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { loadEnvFile } from "./env-file.js";
|
|
2
|
+
function parseHeaders(raw) {
|
|
3
|
+
if (!raw)
|
|
4
|
+
return {};
|
|
5
|
+
if (typeof raw === "object")
|
|
6
|
+
return { ...raw };
|
|
7
|
+
const out = {};
|
|
8
|
+
for (const pair of raw.split(",")) {
|
|
9
|
+
const [k, ...rest] = pair.split("=");
|
|
10
|
+
if (k && rest.length > 0)
|
|
11
|
+
out[k.trim()] = rest.join("=").trim();
|
|
12
|
+
}
|
|
13
|
+
return out;
|
|
14
|
+
}
|
|
15
|
+
function resolveEndpoint(options) {
|
|
16
|
+
const full = options.endpoint ||
|
|
17
|
+
process.env.PINTA_OPENCODE_ENDPOINT ||
|
|
18
|
+
process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT;
|
|
19
|
+
if (full)
|
|
20
|
+
return full.replace(/\/+$/, "");
|
|
21
|
+
const base = process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
|
|
22
|
+
if (base)
|
|
23
|
+
return base.replace(/\/+$/, "") + "/v1/traces";
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Resolve runtime config. Precedence: plugin options → process.env →
|
|
28
|
+
* env-file (unset-only). Both options and env are visible at runtime (verified G5).
|
|
29
|
+
*/
|
|
30
|
+
export function resolveConfig(options = {}) {
|
|
31
|
+
loadEnvFile(); // lowest priority — fills only unset process.env keys
|
|
32
|
+
const relayToken = options.token || process.env.PINTA_OPENCODE_TOKEN || undefined;
|
|
33
|
+
const headers = parseHeaders(options.headers ?? process.env.PINTA_OPENCODE_HEADERS ?? process.env.OTEL_EXPORTER_OTLP_HEADERS);
|
|
34
|
+
// Auto-attach the relay token as a header if one is set and not already present.
|
|
35
|
+
if (relayToken && !Object.keys(headers).some((k) => k.toLowerCase() === "x-pinta-relay-token")) {
|
|
36
|
+
headers["x-pinta-relay-token"] = relayToken;
|
|
37
|
+
}
|
|
38
|
+
const guardTimeoutMs = options.guardTimeoutMs ?? (Number(process.env.PINTA_OPENCODE_GUARD_TIMEOUT_MS) || 50);
|
|
39
|
+
return {
|
|
40
|
+
endpoint: resolveEndpoint(options),
|
|
41
|
+
headers,
|
|
42
|
+
guardEndpoint: options.guard || process.env.PINTA_OPENCODE_GUARD || undefined,
|
|
43
|
+
relayToken,
|
|
44
|
+
guardTimeoutMs,
|
|
45
|
+
guardDisabled: process.env.PINTA_OPENCODE_GUARD_DISABLED === "1",
|
|
46
|
+
serviceVersion: process.env.OPENCODE_VERSION || "unknown",
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AA0B5C,SAAS,YAAY,CAAC,GAAgD;IACpE,IAAI,CAAC,GAAG;QAAE,OAAO,EAAE,CAAC;IACpB,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,EAAE,GAAG,GAAG,EAAE,CAAC;IAC/C,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QAClC,MAAM,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACrC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC;YAAE,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IAClE,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,eAAe,CAAC,OAAqB;IAC5C,MAAM,IAAI,GACR,OAAO,CAAC,QAAQ;QAChB,OAAO,CAAC,GAAG,CAAC,uBAAuB;QACnC,OAAO,CAAC,GAAG,CAAC,kCAAkC,CAAC;IACjD,IAAI,IAAI;QAAE,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC1C,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC;IACrD,IAAI,IAAI;QAAE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
toolName?: string;
|
|
4
|
+
toolInput?: unknown;
|
|
5
|
+
rawTextFields?: Record<string, string>;
|
|
6
|
+
}
|
|
7
|
+
export interface GuardResult {
|
|
8
|
+
decision: "ALLOW" | "DENY" | "REVIEW";
|
|
9
|
+
reason: string | null;
|
|
10
|
+
userMessage: string | null;
|
|
11
|
+
durationMs: number;
|
|
12
|
+
failOpenReason?: "timeout" | "refused" | "error";
|
|
13
|
+
}
|
|
14
|
+
export interface GuardOptions {
|
|
15
|
+
/** Hard timeout. 50ms default keeps the hook snappy; 300ms recommended in prod. */
|
|
16
|
+
timeoutMs?: number;
|
|
17
|
+
/** Sent as x-pinta-relay-token. */
|
|
18
|
+
token?: string;
|
|
19
|
+
/** Force-disable even if an endpoint is configured. */
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Query the external guard policy server. Fail-open on every error path
|
|
24
|
+
* (no endpoint / disabled / non-200 / timeout / throw → ALLOW). Options are
|
|
25
|
+
* passed explicitly (not read from process.env) because the opencode plugin
|
|
26
|
+
* is a long-lived in-process module whose config is resolved at init, after
|
|
27
|
+
* this module is already imported.
|
|
28
|
+
*/
|
|
29
|
+
export declare function evaluateGuard(input: GuardInput, endpoint: string | undefined, opts?: GuardOptions): Promise<GuardResult | null>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
function sleep(ms) {
|
|
2
|
+
return new Promise((_, reject) => setTimeout(() => {
|
|
3
|
+
const err = new Error("Guard request timed out");
|
|
4
|
+
err.name = "TimeoutError";
|
|
5
|
+
reject(err);
|
|
6
|
+
}, ms));
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Query the external guard policy server. Fail-open on every error path
|
|
10
|
+
* (no endpoint / disabled / non-200 / timeout / throw → ALLOW). Options are
|
|
11
|
+
* passed explicitly (not read from process.env) because the opencode plugin
|
|
12
|
+
* is a long-lived in-process module whose config is resolved at init, after
|
|
13
|
+
* this module is already imported.
|
|
14
|
+
*/
|
|
15
|
+
export async function evaluateGuard(input, endpoint, opts = {}) {
|
|
16
|
+
if (!endpoint)
|
|
17
|
+
return null;
|
|
18
|
+
if (opts.disabled)
|
|
19
|
+
return null;
|
|
20
|
+
const timeoutMs = opts.timeoutMs ?? 50;
|
|
21
|
+
const start = Date.now();
|
|
22
|
+
try {
|
|
23
|
+
const res = await Promise.race([
|
|
24
|
+
fetch(endpoint, {
|
|
25
|
+
method: "POST",
|
|
26
|
+
headers: {
|
|
27
|
+
"content-type": "application/json",
|
|
28
|
+
"x-pinta-relay-token": opts.token ?? "",
|
|
29
|
+
},
|
|
30
|
+
body: JSON.stringify({ input }),
|
|
31
|
+
}),
|
|
32
|
+
sleep(timeoutMs),
|
|
33
|
+
]);
|
|
34
|
+
if (res.status !== 200) {
|
|
35
|
+
return { decision: "ALLOW", reason: null, userMessage: null, durationMs: Date.now() - start, failOpenReason: "error" };
|
|
36
|
+
}
|
|
37
|
+
const body = (await res.json());
|
|
38
|
+
return {
|
|
39
|
+
decision: body.decision,
|
|
40
|
+
reason: body.reason,
|
|
41
|
+
userMessage: body.userMessage ?? null,
|
|
42
|
+
durationMs: body.durationMs ?? Date.now() - start,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
const reason = err.name === "TimeoutError" ? "timeout" : "error";
|
|
47
|
+
return { decision: "ALLOW", reason: null, userMessage: null, durationMs: Date.now() - start, failOpenReason: reason };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guard.js","sourceRoot":"","sources":["../../src/core/guard.ts"],"names":[],"mappings":"AA2BA,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAC/B,UAAU,CAAC,GAAG,EAAE;QACd,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,yBA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W,EAAE,IAAI,CAAC,WAAW,IAAI,IAAI;YACrC,UAAU,EAAE,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK;SAClD,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,MAAM,GAAmC,GAAa,CAAC,IAAI,KAAK,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;QAC3G,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,CAAC;IACxH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { GuardResult } from "./guard.js";
|
|
2
|
+
export interface OtlpAttribute {
|
|
3
|
+
key: string;
|
|
4
|
+
value: {
|
|
5
|
+
stringValue: string;
|
|
6
|
+
} | {
|
|
7
|
+
intValue: number;
|
|
8
|
+
} | {
|
|
9
|
+
doubleValue: number;
|
|
10
|
+
} | {
|
|
11
|
+
boolValue: boolean;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface OtlpSpan {
|
|
15
|
+
traceId: string;
|
|
16
|
+
spanId: string;
|
|
17
|
+
name: string;
|
|
18
|
+
kind: number;
|
|
19
|
+
startTimeUnixNano: string;
|
|
20
|
+
endTimeUnixNano: string;
|
|
21
|
+
attributes: OtlpAttribute[];
|
|
22
|
+
}
|
|
23
|
+
export interface ResourceSpans {
|
|
24
|
+
resource: {
|
|
25
|
+
attributes: OtlpAttribute[];
|
|
26
|
+
};
|
|
27
|
+
scopeSpans: Array<{
|
|
28
|
+
scope: {
|
|
29
|
+
name: string;
|
|
30
|
+
version: string;
|
|
31
|
+
};
|
|
32
|
+
spans: OtlpSpan[];
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
export interface OtlpPayload {
|
|
36
|
+
resourceSpans: ResourceSpans[];
|
|
37
|
+
}
|
|
38
|
+
/** Convert a 26-char Crockford ULID into 32 lowercase hex chars for an OTLP traceId. */
|
|
39
|
+
export declare function ulidToTraceId(ulid: string): string;
|
|
40
|
+
/** Generate a fresh 16-hex-char (8-byte) span ID. */
|
|
41
|
+
export declare function newSpanId(): string;
|
|
42
|
+
export declare function buildOtlpPayload(args: {
|
|
43
|
+
name: string;
|
|
44
|
+
traceId: string;
|
|
45
|
+
fields: Record<string, unknown>;
|
|
46
|
+
serviceVersion: string;
|
|
47
|
+
now?: number;
|
|
48
|
+
guard?: GuardResult | null;
|
|
49
|
+
}): OtlpPayload;
|
|
50
|
+
/** Concatenate per-event payloads' resourceSpans into one OTLP payload. */
|
|
51
|
+
export declare function mergeBatch(payloads: OtlpPayload[]): OtlpPayload;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import crypto from "crypto";
|
|
2
|
+
import os from "os";
|
|
3
|
+
import { redact, truncate } from "./redact.js";
|
|
4
|
+
const SDK_VERSION = "0.1.0"; // keep in sync with package.json
|
|
5
|
+
const CROCKFORD = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
6
|
+
/** Convert a 26-char Crockford ULID into 32 lowercase hex chars for an OTLP traceId. */
|
|
7
|
+
export function ulidToTraceId(ulid) {
|
|
8
|
+
if (ulid.length !== 26)
|
|
9
|
+
throw new Error(`ulidToTraceId: expected 26 chars, got ${ulid.length}`);
|
|
10
|
+
let n = 0n;
|
|
11
|
+
for (const ch of ulid) {
|
|
12
|
+
const idx = CROCKFORD.indexOf(ch);
|
|
13
|
+
if (idx < 0)
|
|
14
|
+
throw new Error(`ulidToTraceId: invalid Crockford char "${ch}"`);
|
|
15
|
+
n = (n << 5n) | BigInt(idx);
|
|
16
|
+
}
|
|
17
|
+
n &= (1n << 128n) - 1n;
|
|
18
|
+
return n.toString(16).padStart(32, "0");
|
|
19
|
+
}
|
|
20
|
+
/** Generate a fresh 16-hex-char (8-byte) span ID. */
|
|
21
|
+
export function newSpanId() {
|
|
22
|
+
return crypto.randomBytes(8).toString("hex");
|
|
23
|
+
}
|
|
24
|
+
/** Identifier/enum keys for which redaction is skipped (truncation still applies). */
|
|
25
|
+
const SKIP_REDACT_KEYS = new Set([
|
|
26
|
+
"opencode.kind",
|
|
27
|
+
"opencode.event_type",
|
|
28
|
+
"opencode.tool",
|
|
29
|
+
"opencode.session_id", "opencode.sessionID",
|
|
30
|
+
"opencode.call_id", "opencode.callID",
|
|
31
|
+
"opencode.agent",
|
|
32
|
+
"opencode.model",
|
|
33
|
+
"opencode.exit",
|
|
34
|
+
"opencode.truncated",
|
|
35
|
+
"opencode.title",
|
|
36
|
+
]);
|
|
37
|
+
/** Keys that may carry shell command / tool payload text → bash redaction context. */
|
|
38
|
+
const BASH_CONTEXT_KEYS = new Set([
|
|
39
|
+
"opencode.args",
|
|
40
|
+
"opencode.input",
|
|
41
|
+
"opencode.output",
|
|
42
|
+
"opencode.tool_input",
|
|
43
|
+
]);
|
|
44
|
+
function maybeRedactString(key, raw) {
|
|
45
|
+
const truncated = truncate(raw);
|
|
46
|
+
if (SKIP_REDACT_KEYS.has(key))
|
|
47
|
+
return truncated;
|
|
48
|
+
const context = BASH_CONTEXT_KEYS.has(key) ? "bash" : undefined;
|
|
49
|
+
return redact(truncated, { context });
|
|
50
|
+
}
|
|
51
|
+
/** Convert a JS value into an OTLP attribute value. Returns null to omit. */
|
|
52
|
+
function toOtlpValue(key, v) {
|
|
53
|
+
if (v === null || v === undefined)
|
|
54
|
+
return null;
|
|
55
|
+
switch (typeof v) {
|
|
56
|
+
case "string":
|
|
57
|
+
return { stringValue: maybeRedactString(key, v) };
|
|
58
|
+
case "boolean":
|
|
59
|
+
return { boolValue: v };
|
|
60
|
+
case "number":
|
|
61
|
+
return Number.isInteger(v) ? { intValue: v } : { doubleValue: v };
|
|
62
|
+
case "object":
|
|
63
|
+
try {
|
|
64
|
+
return { stringValue: maybeRedactString(key, JSON.stringify(v)) };
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return { stringValue: maybeRedactString(key, String(v)) };
|
|
68
|
+
}
|
|
69
|
+
default:
|
|
70
|
+
return { stringValue: maybeRedactString(key, String(v)) };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** Bronze flattening: every field becomes an `opencode.<key>` attribute, losslessly. */
|
|
74
|
+
function flattenFields(fields) {
|
|
75
|
+
// Discriminator first so aware-backend's detectIngestType hits it cheaply.
|
|
76
|
+
const out = [{ key: "ingest.type", value: { stringValue: "opencode" } }];
|
|
77
|
+
for (const [k, v] of Object.entries(fields)) {
|
|
78
|
+
const key = `opencode.${k}`;
|
|
79
|
+
const value = toOtlpValue(key, v);
|
|
80
|
+
if (value === null)
|
|
81
|
+
continue;
|
|
82
|
+
out.push({ key, value });
|
|
83
|
+
}
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
function resourceAttrs(serviceVersion) {
|
|
87
|
+
return [
|
|
88
|
+
{ key: "service.name", value: { stringValue: "opencode" } },
|
|
89
|
+
{ key: "service.version", value: { stringValue: serviceVersion } },
|
|
90
|
+
{ key: "telemetry.sdk.name", value: { stringValue: "pinta-opencode" } },
|
|
91
|
+
{ key: "telemetry.sdk.language", value: { stringValue: "nodejs" } },
|
|
92
|
+
{ key: "telemetry.sdk.version", value: { stringValue: SDK_VERSION } },
|
|
93
|
+
{ key: "process.pid", value: { intValue: process.pid } },
|
|
94
|
+
{ key: "process.owner", value: { stringValue: os.userInfo().username } },
|
|
95
|
+
{ key: "host.name", value: { stringValue: os.hostname() } },
|
|
96
|
+
{ key: "host.arch", value: { stringValue: os.arch() } },
|
|
97
|
+
];
|
|
98
|
+
}
|
|
99
|
+
export function buildOtlpPayload(args) {
|
|
100
|
+
const ts = args.now ?? Date.now();
|
|
101
|
+
const tsNano = (BigInt(ts) * 1000000n).toString();
|
|
102
|
+
const attrs = flattenFields(args.fields);
|
|
103
|
+
if (args.guard) {
|
|
104
|
+
attrs.push({ key: "pinta.guard.decision", value: { stringValue: args.guard.decision.toLowerCase() } }, { key: "pinta.guard.duration_ms", value: { intValue: args.guard.durationMs } });
|
|
105
|
+
if (args.guard.reason)
|
|
106
|
+
attrs.push({ key: "pinta.guard.matched_rule", value: { stringValue: args.guard.reason } });
|
|
107
|
+
if (args.guard.failOpenReason)
|
|
108
|
+
attrs.push({ key: "pinta.guard.fail_open_reason", value: { stringValue: args.guard.failOpenReason } });
|
|
109
|
+
}
|
|
110
|
+
const span = {
|
|
111
|
+
traceId: ulidToTraceId(args.traceId),
|
|
112
|
+
spanId: newSpanId(),
|
|
113
|
+
name: args.name,
|
|
114
|
+
kind: 1, // SPAN_KIND_INTERNAL
|
|
115
|
+
startTimeUnixNano: tsNano,
|
|
116
|
+
endTimeUnixNano: tsNano,
|
|
117
|
+
attributes: attrs,
|
|
118
|
+
};
|
|
119
|
+
return {
|
|
120
|
+
resourceSpans: [
|
|
121
|
+
{
|
|
122
|
+
resource: { attributes: resourceAttrs(args.serviceVersion) },
|
|
123
|
+
scopeSpans: [{ scope: { name: "pinta-opencode", version: SDK_VERSION }, spans: [span] }],
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/** Concatenate per-event payloads' resourceSpans into one OTLP payload. */
|
|
129
|
+
export function mergeBatch(payloads) {
|
|
130
|
+
const out = [];
|
|
131
|
+
for (const p of payloads)
|
|
132
|
+
out.push(...p.resourceSpans);
|
|
133
|
+
return { resourceSpans: out };
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=otlp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otlp.js","sourceRoot":"","sources":["../../src/core/otlp.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM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