@gendigital/sage-opencode 0.10.0 → 0.12.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.
Files changed (48) hide show
  1. package/README.md +6 -6
  2. package/dist/bundled-dirs.d.ts +1 -1
  3. package/dist/bundled-dirs.d.ts.map +1 -1
  4. package/dist/bundled-dirs.js +1 -1
  5. package/dist/bundled-dirs.js.map +1 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +291 -71
  8. package/dist/index.js.map +1 -1
  9. package/dist/mcp-server.cjs +31882 -0
  10. package/dist/mcp-server.cjs.map +7 -0
  11. package/dist/plugin-discovery.d.ts +1 -0
  12. package/dist/plugin-discovery.d.ts.map +1 -1
  13. package/dist/plugin-discovery.js +27 -1
  14. package/dist/plugin-discovery.js.map +1 -1
  15. package/dist/startup-scan.d.ts +11 -3
  16. package/dist/startup-scan.d.ts.map +1 -1
  17. package/dist/startup-scan.js +60 -21
  18. package/dist/startup-scan.js.map +1 -1
  19. package/dist/tool-handler.d.ts +3 -2
  20. package/dist/tool-handler.d.ts.map +1 -1
  21. package/dist/tool-handler.js +22 -5
  22. package/dist/tool-handler.js.map +1 -1
  23. package/package.json +5 -3
  24. package/resources/threats/agent-layer.yaml +186 -0
  25. package/resources/threats/commands.yaml +24 -53
  26. package/resources/threats/credentials.yaml +12 -20
  27. package/resources/threats/dummy.yaml +44 -50
  28. package/resources/threats/files.yaml +34 -53
  29. package/resources/threats/mac-commands.yaml +20 -47
  30. package/resources/threats/mac-credentials.yaml +4 -12
  31. package/resources/threats/mac-files.yaml +5 -15
  32. package/resources/threats/mac-obfuscation.yaml +6 -13
  33. package/resources/threats/mac-persistence.yaml +11 -20
  34. package/resources/threats/mac-supply-chain.yaml +5 -8
  35. package/resources/threats/mitre.yaml +105 -167
  36. package/resources/threats/obfuscation.yaml +7 -15
  37. package/resources/threats/persistence.yaml +10 -17
  38. package/resources/threats/prompt-injection.yaml +92 -43
  39. package/resources/threats/self-defense.yaml +8 -12
  40. package/resources/threats/supply_chain.yaml +1 -2
  41. package/resources/threats/urls.yaml +9 -14
  42. package/resources/threats/win-commands.yaml +46 -106
  43. package/resources/threats/win-credentials.yaml +14 -24
  44. package/resources/threats/win-files.yaml +10 -20
  45. package/resources/threats/win-obfuscation.yaml +21 -37
  46. package/resources/threats/win-persistence.yaml +8 -16
  47. package/resources/threats/win-supply-chain.yaml +2 -3
  48. /package/resources/{allowlists → trusted-domains}/trusted-installer-domains.yaml +0 -0
package/README.md CHANGED
@@ -38,9 +38,9 @@ Add the plugin to your OpenCode config (`~/.config/opencode/opencode.json`):
38
38
  }
39
39
  ```
40
40
 
41
- Or [build from source](https://github.com/gendigitalinc/sage/blob/main/docs/getting-started.md#opencode).
41
+ Or [build from source](https://github.com/gendigitalinc/sage/blob/main/docs/user-guide.md#opencode).
42
42
 
43
- > To verify it's working, ask your agent to run `echo __sage_test_deny_cmd_a75bf229__`. Sage should block this harmless canary command.
43
+ > To verify it's working, ask your agent to run `echo diagmark_cmd_a75bf229`. Sage should block this harmless canary command.
44
44
 
45
45
  ## What Sage intercepts
46
46
 
@@ -80,12 +80,12 @@ Sage works out of the box with no configuration. To customize behavior, edit `~/
80
80
  }
81
81
  ```
82
82
 
83
- See [Configuration](https://github.com/gendigitalinc/sage/blob/main/docs/configuration.md) for all options.
83
+ See [Configuration](https://github.com/gendigitalinc/sage/blob/main/docs/user-guide.md#configuration) for all options.
84
84
 
85
85
  ## Links
86
86
 
87
87
  - [User Guide](https://github.com/gendigitalinc/sage/blob/main/docs/user-guide.md) — verify install, handle alerts, manage false positives
88
- - [Configuration](https://github.com/gendigitalinc/sage/blob/main/docs/configuration.md) — all config options
89
- - [Exceptions](https://github.com/gendigitalinc/sage/blob/main/docs/exceptions.md) — pattern-based allow/deny rules
90
- - [Privacy](https://github.com/gendigitalinc/sage/blob/main/docs/privacy.md) — what data is sent, what stays local
88
+ - [Configuration](https://github.com/gendigitalinc/sage/blob/main/docs/user-guide.md#configuration) — all config options
89
+ - [Exceptions](https://github.com/gendigitalinc/sage/blob/main/docs/user-guide.md#exceptions) — pattern-based allow/deny rules
90
+ - [Privacy](https://github.com/gendigitalinc/sage/blob/main/docs/user-guide.md#privacy) — what data is sent, what stays local
91
91
  - [GitHub](https://github.com/gendigitalinc/sage)
@@ -6,7 +6,7 @@ export declare function getBundledDataDirs(): {
6
6
  pluginDir: string;
7
7
  packageRoot: string;
8
8
  threatsDir: string;
9
- allowlistsDir: string;
9
+ trustedDomainsDir: string;
10
10
  };
11
11
  export declare function getSageVersion(): string;
12
12
  //# sourceMappingURL=bundled-dirs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bundled-dirs.d.ts","sourceRoot":"","sources":["../src/bundled-dirs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,wBAAgB,kBAAkB,IAAI;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;CACtB,CASA;AAED,wBAAgB,cAAc,IAAI,MAAM,CASvC"}
1
+ {"version":3,"file":"bundled-dirs.d.ts","sourceRoot":"","sources":["../src/bundled-dirs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,wBAAgB,kBAAkB,IAAI;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;CAC1B,CASA;AAED,wBAAgB,cAAc,IAAI,MAAM,CASvC"}
@@ -12,7 +12,7 @@ export function getBundledDataDirs() {
12
12
  pluginDir,
13
13
  packageRoot,
14
14
  threatsDir: join(packageRoot, "resources", "threats"),
15
- allowlistsDir: join(packageRoot, "resources", "allowlists"),
15
+ trustedDomainsDir: join(packageRoot, "resources", "trusted-domains"),
16
16
  };
17
17
  }
18
18
  export function getSageVersion() {
@@ -1 +1 @@
1
- {"version":3,"file":"bundled-dirs.js","sourceRoot":"","sources":["../src/bundled-dirs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,UAAU,kBAAkB;IAMjC,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1D,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAC1C,OAAO;QACN,SAAS;QACT,WAAW;QACX,UAAU,EAAE,IAAI,CAAC,WAAW,EAAE,WAAW,EAAE,SAAS,CAAC;QACrD,aAAa,EAAE,IAAI,CAAC,WAAW,EAAE,WAAW,EAAE,YAAY,CAAC;KAC3D,CAAC;AACH,CAAC;AAED,MAAM,UAAU,cAAc;IAC7B,IAAI,CAAC;QACJ,MAAM,EAAE,WAAW,EAAE,GAAG,kBAAkB,EAAE,CAAC;QAC7C,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;QAClD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAA4B,CAAC;QAClF,OAAQ,GAAG,CAAC,OAAkB,IAAI,OAAO,CAAC;IAC3C,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,OAAO,CAAC;IAChB,CAAC;AACF,CAAC"}
1
+ {"version":3,"file":"bundled-dirs.js","sourceRoot":"","sources":["../src/bundled-dirs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,UAAU,kBAAkB;IAMjC,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1D,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAC1C,OAAO;QACN,SAAS;QACT,WAAW;QACX,UAAU,EAAE,IAAI,CAAC,WAAW,EAAE,WAAW,EAAE,SAAS,CAAC;QACrD,iBAAiB,EAAE,IAAI,CAAC,WAAW,EAAE,WAAW,EAAE,iBAAiB,CAAC;KACpE,CAAC;AACH,CAAC;AAED,MAAM,UAAU,cAAc;IAC7B,IAAI,CAAC;QACJ,MAAM,EAAE,WAAW,EAAE,GAAG,kBAAkB,EAAE,CAAC;QAC7C,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;QAClD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAA4B,CAAC;QAClF,OAAQ,GAAG,CAAC,OAAkB,IAAI,OAAO,CAAC;IAC3C,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,OAAO,CAAC;IAChB,CAAC;AACF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAWH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAQlD,eAAO,MAAM,UAAU,EAAE,MAoKxB,CAAC;AAEF,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAwBH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAmLlD,eAAO,MAAM,UAAU,EAAE,MAyOxB,CAAC;AAEF,eAAe,UAAU,CAAC"}
package/dist/index.js CHANGED
@@ -2,12 +2,164 @@
2
2
  * Sage OpenCode plugin.
3
3
  * Intercepts tool calls and uses @gendigital/sage-core to enforce security verdicts.
4
4
  */
5
- import { ApprovalStore, approveAction, createOperationalLogger, formatConfigurationWarnings, getConfigurationWarnings, loadConfig, resolveBranding, } from "@gendigital/sage-core";
5
+ import { mkdirSync, watchFile } from "node:fs";
6
+ import { dirname, join } from "node:path";
7
+ import { fileURLToPath } from "node:url";
8
+ import { ApprovalStore, approveAction, checkAllowlistMigration, createOperationalLogger, foreignSourceRuntime, formatAllowlistMigrationWarning, formatConfigurationWarnings, formatNoticeById, getConfigurationWarnings, loadConfig, loadSkillVerdictCache, resolveBranding, resolvePath, } from "@gendigital/sage-core";
6
9
  import { tool } from "@opencode-ai/plugin/tool";
7
10
  import { getBundledDataDirs } from "./bundled-dirs.js";
8
11
  import { createSessionScanHandler } from "./startup-scan.js";
9
12
  import { createToolHandlers } from "./tool-handler.js";
10
13
  const APPROVAL_STORE_CLEANUP_INTERVAL_MS = 5 * 60 * 1000; // 5 minutes
14
+ const DEFAULT_TOAST_DURATION_MS = 5000;
15
+ // The startup security summary lists every risky skill, so it's shown longer to
16
+ // give the user time to read the list before it dismisses.
17
+ const STARTUP_SUMMARY_DURATION_MS = 10_000;
18
+ // Module-scoped so repeated SagePlugin instantiations (OpenCode may load the
19
+ // plugin more than once) share a single watcher and one notified-set, instead
20
+ // of each instance attaching its own watcher and toasting the same verdict.
21
+ const notifiedSkillVerdicts = new Set();
22
+ let skillWatcherAttached = false;
23
+ // One scan per session, shared across instances: the entry guards against
24
+ // re-running the scan when session.updated fires repeatedly or on more than one
25
+ // plugin instance.
26
+ const sessionScanPromises = new Map();
27
+ const toastQueue = [];
28
+ let toastPumpRunning = false;
29
+ // Bound to a live client's showToast by the first instance (see SagePlugin).
30
+ let displayToast;
31
+ async function pumpToasts() {
32
+ if (toastPumpRunning)
33
+ return;
34
+ toastPumpRunning = true;
35
+ try {
36
+ while (toastQueue.length > 0) {
37
+ const next = toastQueue[0];
38
+ // No client bound yet — leave the item queued; a later enqueue resumes.
39
+ if (!displayToast || !next)
40
+ break;
41
+ displayToast(next.message, next.variant, next.durationMs);
42
+ toastQueue.shift();
43
+ // Hold the slot for this toast's full duration before showing the next,
44
+ // so a following toast can't replace it early (showToast overwrites).
45
+ await new Promise((resolve) => setTimeout(resolve, next.durationMs));
46
+ }
47
+ }
48
+ finally {
49
+ toastPumpRunning = false;
50
+ }
51
+ }
52
+ function enqueueToast(message, variant, durationMs = DEFAULT_TOAST_DURATION_MS) {
53
+ toastQueue.push({ message, variant, durationMs });
54
+ void pumpToasts();
55
+ }
56
+ // Shared dedup key across the two surfacing paths: the scan-findings popup keys
57
+ // on `finding.artifact` (which is `skillId.slice(0, 16)`), and the cache watcher
58
+ // keys on the full skillId — so both reduce to this 16-char content-hash prefix
59
+ // and `notifiedSkillVerdicts` never double-announces the same skill version.
60
+ function shortSkillId(skillId) {
61
+ return skillId.slice(0, 16);
62
+ }
63
+ /**
64
+ * Read `~/.sage/skill_verdict_cache.json` and return every HIGH/CRITICAL verdict
65
+ * relevant to this runtime — one per cache entry, NOT deduped, since dedup is
66
+ * caller-specific (the popup keys on current content, the toast queue on
67
+ * skillId). HIGH maps to the "WARNING" label. Verdicts sourced only from other
68
+ * agent runtimes are skipped so one host doesn't echo another's finds.
69
+ */
70
+ async function collectRiskySkills(agentRuntime) {
71
+ const cache = await loadSkillVerdictCache();
72
+ const out = [];
73
+ for (const [skillId, verdict] of Object.entries(cache.entries)) {
74
+ const risk = (verdict.verdict ?? "").toUpperCase();
75
+ if (risk !== "HIGH" && risk !== "CRITICAL")
76
+ continue;
77
+ if (foreignSourceRuntime(verdict.sources, agentRuntime))
78
+ continue;
79
+ const key = verdict.sources?.find((s) => s.containerKey)?.containerKey ||
80
+ verdict.skillName ||
81
+ skillId.slice(0, 16);
82
+ out.push({
83
+ skillId,
84
+ key,
85
+ severity: risk === "CRITICAL" ? "CRITICAL" : "WARNING",
86
+ summary: verdict.summary?.trim(),
87
+ });
88
+ }
89
+ return out;
90
+ }
91
+ /**
92
+ * Watch `~/.sage/skill_verdict_cache.json` and queue one toast per verdict the
93
+ * upload worker writes mid-session (it writes asynchronously, ~one session after
94
+ * discovery). The serial queue shows them one at a time so two skills finishing
95
+ * together are both seen.
96
+ *
97
+ * Verdicts cached by earlier sessions are *seeded silently* on attach — marked
98
+ * notified without a toast — because the plugin initialises before the TUI is
99
+ * ready to render toasts. Those are surfaced instead by the session-start
100
+ * summary popup (see `surfaceStartupSummary`), which runs after the scan when
101
+ * the TUI is up.
102
+ *
103
+ * Dedup keys on `skillId` (content hash), not the container key, so editing a
104
+ * skill — which yields a new hash under the same key — is treated as a new
105
+ * finding and re-announced rather than silently collapsed into the old one.
106
+ */
107
+ function setupSkillFindingsWatcher(logger, agentRuntime) {
108
+ if (skillWatcherAttached)
109
+ return;
110
+ const sageDir = resolvePath("~/.sage");
111
+ const seedNotified = async () => {
112
+ try {
113
+ for (const s of await collectRiskySkills(agentRuntime)) {
114
+ notifiedSkillVerdicts.add(shortSkillId(s.skillId));
115
+ }
116
+ }
117
+ catch (e) {
118
+ logger.debug("Skill verdict seed failed", { error: String(e) });
119
+ }
120
+ };
121
+ // Mid-session: queue one toast per newly written (not-yet-notified) verdict.
122
+ const announceNew = async () => {
123
+ try {
124
+ for (const s of await collectRiskySkills(agentRuntime)) {
125
+ const short = shortSkillId(s.skillId);
126
+ if (notifiedSkillVerdicts.has(short))
127
+ continue;
128
+ notifiedSkillVerdicts.add(short);
129
+ const detail = s.summary ? `${s.key} — ${s.summary}` : `${s.key} detected`;
130
+ logger.debug("Skill finding toast queued", { key: s.key, severity: s.severity });
131
+ enqueueToast(`${detail} (${s.severity})`, s.severity === "CRITICAL" ? "error" : "warning");
132
+ }
133
+ }
134
+ catch (e) {
135
+ logger.debug("Skill verdict watcher scan failed", { error: String(e) });
136
+ }
137
+ };
138
+ try {
139
+ mkdirSync(sageDir, { recursive: true });
140
+ void seedNotified();
141
+ // Poll the cache file with watchFile rather than watch() the directory.
142
+ // On Windows, fs.watch aborts the whole process (an uncatchable libuv
143
+ // assertion in fs-event.c) when the watched path is an 8.3 short name
144
+ // (e.g. an os.tmpdir() like C:\Users\FOO~1.BAR\...) or symlinked home.
145
+ // watchFile is stat-based polling — immune to that. A few seconds of
146
+ // latency for mid-session verdicts is fine (matches the statusline poll
147
+ // cadence used elsewhere). Handles a not-yet-existent file (polls until
148
+ // it appears).
149
+ const cacheFile = join(sageDir, "skill_verdict_cache.json");
150
+ const watcher = watchFile(cacheFile, { interval: 3000 }, (curr, prev) => {
151
+ if (curr.mtimeMs !== prev.mtimeMs)
152
+ void announceNew();
153
+ });
154
+ watcher.unref?.();
155
+ skillWatcherAttached = true;
156
+ logger.debug("Skill findings watcher attached", { cacheFile });
157
+ }
158
+ catch (e) {
159
+ // ~/.sage/ may be unwritable — no watcher, no notifications (fail-open).
160
+ logger.debug("Skill findings watcher setup failed", { error: String(e) });
161
+ }
162
+ }
11
163
  export const SagePlugin = async ({ client, directory }) => {
12
164
  const config = await loadConfig();
13
165
  const operationalLogger = createOperationalLogger(config.operational_logging, "opencode");
@@ -15,101 +167,169 @@ export const SagePlugin = async ({ client, directory }) => {
15
167
  const toolLogger = operationalLogger.forComponent("tool-handler");
16
168
  const scanLogger = operationalLogger.forComponent("startup-scan");
17
169
  const branding = resolveBranding(config.brand_key, logger);
170
+ const showToast = (msg, variant, durationMs = DEFAULT_TOAST_DURATION_MS) => {
171
+ client.tui
172
+ .showToast({
173
+ body: { title: branding.name, message: msg, variant, duration: durationMs },
174
+ })
175
+ .catch(() => { });
176
+ };
177
+ // Bind the module-scoped skill-toast queue to this (first) instance's client.
178
+ // The queue passes each item's own duration, which showToast honors.
179
+ displayToast ??= showToast;
18
180
  const warningMessage = formatConfigurationWarnings(await getConfigurationWarnings(undefined, logger), branding);
19
181
  if (warningMessage) {
20
182
  client.tui
21
183
  .showToast({
22
- body: { title: branding.name, message: warningMessage, variant: "warning", duration: 5000 },
184
+ body: {
185
+ title: branding.name,
186
+ message: warningMessage,
187
+ variant: "warning",
188
+ duration: DEFAULT_TOAST_DURATION_MS,
189
+ },
190
+ })
191
+ .catch(() => { });
192
+ }
193
+ const allowlistMigration = await checkAllowlistMigration();
194
+ if (allowlistMigration.needed) {
195
+ client.tui
196
+ .showToast({
197
+ body: {
198
+ title: branding.name,
199
+ message: formatAllowlistMigrationWarning(allowlistMigration.entryTypes, branding),
200
+ variant: "warning",
201
+ duration: 8000,
202
+ },
23
203
  })
24
204
  .catch(() => { });
25
205
  }
26
- const { threatsDir, allowlistsDir } = getBundledDataDirs();
206
+ const { threatsDir, trustedDomainsDir } = getBundledDataDirs();
27
207
  const approvalStore = new ApprovalStore();
28
- // State: track findings per session for one-shot injection
29
- const pendingFindingsBySession = new Map();
30
- // Track scanned sessions to avoid re-triggering on repeated session.updated events
31
- const scannedSessions = new Set();
208
+ // Watch for verdicts the upload worker writes mid-session (queued toasts).
209
+ // Verdicts cached by earlier sessions are surfaced by surfaceStartupSummary.
210
+ setupSkillFindingsWatcher(logger, "opencode");
211
+ // Surface the scan's structured findings after the scan (TUI ready). Findings
212
+ // are install- and content-accurate: the scan hashes current on-disk content
213
+ // and looks up its verdict, so a deleted skill isn't discovered and an edited
214
+ // skill is matched by its new hash — no cache re-derivation needed.
215
+ //
216
+ // Single startup surface: one summary toast listing every risky skill from
217
+ // this scan. Summarized skills are marked notified so the cache watcher does
218
+ // not also announce them per-skill; verdicts that land *after* the scan
219
+ // (worker uploads) are still surfaced individually by the watcher.
220
+ const surfaceStartupSummary = (scanResults) => {
221
+ try {
222
+ const skills = [];
223
+ const seen = new Set();
224
+ for (const result of scanResults) {
225
+ for (const finding of result.findings) {
226
+ if (finding.threatId !== "SKILL_CHECK")
227
+ continue;
228
+ if (finding.severity !== "critical" && finding.severity !== "warning")
229
+ continue;
230
+ if (seen.has(result.plugin.key))
231
+ continue;
232
+ seen.add(result.plugin.key);
233
+ skills.push({
234
+ key: result.plugin.key,
235
+ severity: finding.severity === "critical" ? "CRITICAL" : "WARNING",
236
+ finding,
237
+ });
238
+ }
239
+ }
240
+ if (skills.length === 0)
241
+ return;
242
+ // Mark every summarized skill as notified so the cache watcher doesn't
243
+ // also announce it per-skill. `finding.artifact` is the 16-char short
244
+ // hash — the same key the watcher dedups on. Verdicts that land after
245
+ // this scan (worker uploads) are still surfaced individually.
246
+ for (const s of skills) {
247
+ if (s.finding.artifact)
248
+ notifiedSkillVerdicts.add(s.finding.artifact);
249
+ }
250
+ // The summary: a single toast listing every risky skill, shown longer.
251
+ const hasCritical = skills.some((s) => s.severity === "CRITICAL");
252
+ const body = skills.map((s) => `${s.key} (${s.severity})`).join("\n");
253
+ enqueueToast(`${branding.name} detected ${skills.length} malicious/suspicious skill(s):\n${body}`, hasCritical ? "error" : "warning", STARTUP_SUMMARY_DURATION_MS);
254
+ }
255
+ catch (e) {
256
+ logger.debug("Skill summary popup failed", { error: String(e) });
257
+ }
258
+ };
32
259
  // Set up the cron job that cleans up the approval store.
33
260
  const interval = setInterval(() => {
34
261
  approvalStore.cleanup();
35
262
  }, APPROVAL_STORE_CLEANUP_INTERVAL_MS);
36
263
  interval.unref?.();
37
- const toolHandlers = createToolHandlers(toolLogger, approvalStore, threatsDir, allowlistsDir, {
38
- showToast: (msg, variant) => {
39
- client.tui
40
- .showToast({
41
- body: { title: branding.name, message: msg, variant, duration: 5000 },
42
- })
43
- .catch(() => { });
44
- },
45
- }, branding);
264
+ const toolHandlers = createToolHandlers(toolLogger, approvalStore, threatsDir, trustedDomainsDir, { showToast }, branding);
265
+ /**
266
+ * Run the session scan exactly once per session and cache the promise. The
267
+ * cached promise is the dedupe guard — a second call (repeated
268
+ * `session.updated`, or another plugin instance) returns the same
269
+ * in-flight/settled promise instead of re-scanning. The scan's structured
270
+ * findings drive the summary popup (see `surfaceStartupSummary`).
271
+ */
272
+ const scanSession = (sessionID) => {
273
+ if (sessionID === "unknown")
274
+ return Promise.resolve();
275
+ const existing = sessionScanPromises.get(sessionID);
276
+ if (existing)
277
+ return existing;
278
+ const promise = (async () => {
279
+ logger.debug(`${branding.name}: starting session scan`, { sessionID });
280
+ const scanHandler = createSessionScanHandler(scanLogger, directory,
281
+ // After the scan (TUI ready): summary popup from the structured findings.
282
+ surfaceStartupSummary, branding,
283
+ // One-time notices (e.g. skill-upload consent) as info toasts.
284
+ (noticeIds) => {
285
+ for (const id of noticeIds) {
286
+ const text = formatNoticeById(id, branding);
287
+ if (text)
288
+ enqueueToast(text, "info", STARTUP_SUMMARY_DURATION_MS);
289
+ }
290
+ });
291
+ await scanHandler();
292
+ })();
293
+ sessionScanPromises.set(sessionID, promise);
294
+ return promise;
295
+ };
46
296
  return {
47
- "tool.execute.before": toolHandlers["tool.execute.before"],
48
297
  /**
49
- * Inject plugin scan findings into first user message as <system-reminder>.
50
- * This approach leverages OpenCode's existing pattern of appending system
51
- * reminders to user messages (e.g., plan mode constraints), enabling the
52
- * agent to reason about security findings before tool execution. Appending
53
- * to assistant messages or system prompts was less effective.
298
+ * Register the Sage MCP server so sage_report_false_positive /
299
+ * sage_list_audit_entries are available as agent tools. OpenCode runs
300
+ * config hooks before MCP init, so mutating cfg.mcp here is sufficient.
301
+ * ??= ensures a user-supplied override in opencode.json is never clobbered.
54
302
  */
55
- "experimental.chat.messages.transform": async (_input, output) => {
56
- if (pendingFindingsBySession.size === 0)
57
- return;
58
- const userMessage = output.messages.filter((m) => m.info.role === "user");
59
- const message = userMessage[0];
60
- if (!message)
61
- return;
62
- const sessionID = message.info.sessionID;
63
- const findings = pendingFindingsBySession.get(sessionID);
64
- if (!findings)
303
+ config: async (cfg) => {
304
+ const dir = dirname(fileURLToPath(import.meta.url));
305
+ const serverPath = join(dir, "mcp-server.cjs");
306
+ // biome-ignore lint/suspicious/noExplicitAny: OpenCode Config.mcp types not exported
307
+ const mcp = cfg.mcp;
308
+ if (mcp?.sage)
65
309
  return;
66
- const textPart = {
67
- id: crypto.randomUUID(),
68
- sessionID,
69
- messageID: message.info.id,
70
- type: "text",
71
- text: [
72
- `<system-reminder>`,
73
- findings,
74
- "",
75
- "Inform the user about these security findings.",
76
- `</system-reminder>`,
77
- ].join("\n"),
78
- synthetic: true,
310
+ // biome-ignore lint/suspicious/noExplicitAny: assigning McpLocalConfig without importing its type
311
+ cfg.mcp = {
312
+ ...mcp,
313
+ sage: {
314
+ type: "local",
315
+ command: [process.execPath, serverPath],
316
+ environment: { BUN_BE_BUN: "1", SAGE_AGENT_RUNTIME: "opencode" },
317
+ enabled: true,
318
+ },
79
319
  };
80
- message.parts.push(textPart);
81
- logger.debug(`Injected sage plugin scan findings to user message`, {
82
- sessionID,
83
- findingsLength: findings.length,
84
- });
85
- pendingFindingsBySession.delete(sessionID);
86
320
  },
87
- // Trigger session scan on first session.updated event per session.
88
- // OpenCode >=1.3 replaced session.created with session.updated events.
321
+ "tool.execute.before": toolHandlers["tool.execute.before"],
322
+ // Run the session scan on the first session.updated event. It discovers
323
+ // skills, populates the verdict cache, and (post-scan, once the TUI is up)
324
+ // shows the summary popup. OpenCode >=1.3 replaced session.created with
325
+ // session.updated. Dedupe + the work live in scanSession.
89
326
  event: async ({ event }) => {
90
327
  if (event.type !== "session.updated")
91
328
  return;
92
329
  // biome-ignore lint/suspicious/noExplicitAny: Event types from SDK not fully typed
93
330
  const props = event.properties;
94
331
  const sessionID = props?.sessionID ?? props?.info?.id ?? "unknown";
95
- if (sessionID !== "unknown" && scannedSessions.has(sessionID))
96
- return;
97
- try {
98
- logger.debug(`${branding.name}: starting session scan`, { sessionID });
99
- const scanHandler = createSessionScanHandler(scanLogger, directory, (msg) => {
100
- pendingFindingsBySession.set(sessionID, msg);
101
- }, branding);
102
- await scanHandler();
103
- if (sessionID !== "unknown") {
104
- scannedSessions.add(sessionID);
105
- }
106
- }
107
- catch (error) {
108
- logger.error(`${branding.name} session scan failed (fail-open)`, {
109
- sessionID,
110
- error: String(error),
111
- });
112
- }
332
+ await scanSession(sessionID);
113
333
  },
114
334
  tool: {
115
335
  sage_approve: tool({
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,aAAa,EACb,aAAa,EACb,uBAAuB,EACvB,2BAA2B,EAC3B,wBAAwB,EACxB,UAAU,EACV,eAAe,GACf,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,MAAM,kCAAkC,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,YAAY;AAEtE,MAAM,CAAC,MAAM,UAAU,GAAW,KAAK,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE;IACjE,MAAM,MAAM,GAAG,MAAM,UAAU,EAAE,CAAC;IAClC,MAAM,iBAAiB,GAAG,uBAAuB,CAAC,MAAM,CAAC,mBAAmB,EAAE,UAAU,CAAC,CAAC;IAC1F,MAAM,MAAM,GAAG,iBAAiB,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;IACxD,MAAM,UAAU,GAAG,iBAAiB,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC;IAClE,MAAM,UAAU,GAAG,iBAAiB,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC;IAClE,MAAM,QAAQ,GAAG,eAAe,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAC3D,MAAM,cAAc,GAAG,2BAA2B,CACjD,MAAM,wBAAwB,CAAC,SAAS,EAAE,MAAM,CAAC,EACjD,QAAQ,CACR,CAAC;IACF,IAAI,cAAc,EAAE,CAAC;QACpB,MAAM,CAAC,GAAG;aACR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