@yagnic/opencode-plugin 0.7.0 → 0.7.2

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 (3) hide show
  1. package/README.md +6 -0
  2. package/index.mjs +38 -5
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -51,6 +51,12 @@ prints it. Give it a short expiry and the narrowest scopes the tool needs. When
51
51
  your administrator removes the tool, the token stays in OpenCode until you
52
52
  remove it (`/connect`, or `opencode auth logout`): revoke it in the tool too.
53
53
 
54
+ When a tool signs you in with your own account (OAuth), its tools stay hidden
55
+ until you do: run `opencode mcp auth <tool>` (or, in the terminal interface,
56
+ type `/mcp` and pick the tool) and sign in in the browser that
57
+ opens. Until then, the agent is told which tools wait for your sign-in and
58
+ gives you that command, instead of saying the tool does not exist.
59
+
54
60
  ## When YAGNIC is unreachable
55
61
 
56
62
  The plugin re-reads your configuration every minute. If YAGNIC does not answer,
package/index.mjs CHANGED
@@ -1229,11 +1229,14 @@ async function registerV2Transforms(ctx, state) {
1229
1229
 
1230
1230
  // Rules: v2 reads `instructions` from its own config files only, which a
1231
1231
  // plugin cannot reach. They are added to the system prompt of every request
1232
- // instead (and of compactions, which rebuild the context), in every session.
1232
+ // instead (and of compactions, which rebuild the context), in every session,
1233
+ // with the servers still waiting for the developer to sign in.
1233
1234
  const addRules = (request) => {
1234
1235
  try {
1235
- const text = rulesText(deliveredRules(state.delivered))
1236
- if (text && Array.isArray(request?.system)) request.system.push({ type: "text", text })
1236
+ if (!Array.isArray(request?.system)) return
1237
+ for (const text of [rulesText(deliveredRules(state.delivered)), signInNotice(state.signIn, state.delivered?.config?.mcp)]) {
1238
+ if (text) request.system.push({ type: "text", text })
1239
+ }
1237
1240
  } catch {}
1238
1241
  }
1239
1242
  await ctx.session?.hook?.("context", addRules)
@@ -1342,6 +1345,34 @@ export function statusReport(mcp, servers, keys = new Map(), checks = new Map())
1342
1345
  return tools
1343
1346
  }
1344
1347
 
1348
+ // The delivered servers waiting for the developer to sign in (OAuth): their
1349
+ // tools are not loaded, so the agent cannot see them. Without a word about it,
1350
+ // the agent tells the developer the tool does not exist or is not configured.
1351
+ export function signInNeeded(mcp, servers) {
1352
+ return (Array.isArray(servers) ? servers : [])
1353
+ .filter((server) => Object.hasOwn(mcp ?? {}, server?.name) && server?.status?.status === "needs_auth")
1354
+ .map((server) => server.name)
1355
+ }
1356
+
1357
+ // What the agent is told about those servers, in every request: each one with
1358
+ // what the backend says it is for, so the agent can tell when a request needs it.
1359
+ export function signInNotice(names, mcp = {}) {
1360
+ if (!Array.isArray(names) || !names.length) return null
1361
+ const purpose = (name) => {
1362
+ const d = mcp?.[name]?.description
1363
+ return typeof d === "string" && d.trim() ? `: ${d.replace(/\s+/g, " ").trim().slice(0, 300)}` : ""
1364
+ }
1365
+ return [
1366
+ "MCP servers configured for the developer but waiting for them to sign in; their tools are not available until then:",
1367
+ ...names.map((name) => `- ${name}${purpose(name)}`),
1368
+ "When a request could be served by one of them, do not say it is missing, not configured or impossible:",
1369
+ "name it, say what it would do, and tell the developer how to sign in:",
1370
+ `run \`opencode mcp auth <server>\` in a terminal (for example \`opencode mcp auth ${names[0]}\`),`,
1371
+ "or, in OpenCode's terminal interface only, type `/mcp` and pick the server;",
1372
+ "then sign in in the browser that opens, and ask again.",
1373
+ ].join("\n")
1374
+ }
1375
+
1345
1376
  // Best effort, never throws: the HTTP status, or 0 when the backend did not answer.
1346
1377
  async function postStatus(platform, access, tools) {
1347
1378
  try {
@@ -1364,7 +1395,9 @@ async function reportStatus(ctx, state) {
1364
1395
  try {
1365
1396
  const mcp = state.delivered?.config?.mcp
1366
1397
  if (!mcp || !Object.keys(mcp).length) return
1367
- const tools = statusReport(mcp, (await ctx.mcp.list())?.data, state.keys, state.checks)
1398
+ const servers = (await ctx.mcp.list())?.data
1399
+ state.signIn = signInNeeded(mcp, servers)
1400
+ const tools = statusReport(mcp, servers, state.keys, state.checks)
1368
1401
  const body = JSON.stringify(tools)
1369
1402
  if (!Object.keys(tools).length || body === state.reported) return
1370
1403
  const credential = await activeCredential(ctx)
@@ -1499,7 +1532,7 @@ async function watchLogin(ctx, state) {
1499
1532
  // One file, both engines: opencode v1 reads `server` (it rejects a default export
1500
1533
  // with an id but no server()); v2 reads `setup`.
1501
1534
  export default {
1502
- id: "oidc-provider",
1535
+ id: "yagnic",
1503
1536
  server: SsoAuth,
1504
1537
  async setup(ctx) {
1505
1538
  const { provider } = await backend(ctx.options)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yagnic/opencode-plugin",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "OpenCode plugin (v1 and v2): OAuth/OIDC sign-in to a model gateway, plus per-user models, MCP servers, rules, agents and skills from its backend",
5
5
  "license": "Apache-2.0",
6
6
  "author": "YAGNIC",