@tryvira/opencode 0.1.28 → 0.1.30

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
@@ -1,4 +1,4 @@
1
- # `@tryvira/opencode` 0.1.28
1
+ # `@tryvira/opencode` 0.1.30
2
2
 
3
3
  OpenCode V2 server plugin for Vira host lifecycle governance. The package default
4
4
  exports the V2 setup surface plus a compatibility `server()` transport required
package/dist/index.js CHANGED
@@ -1688,6 +1688,24 @@ var v2Plugin = Plugin.define({
1688
1688
  }
1689
1689
  };
1690
1690
  const nativeConfirm = desktopPermission.confirm;
1691
+ let bootstrapAiSystemId = options.aiSystemId ?? env("VIRA_AI_SYSTEM_ID") ?? "";
1692
+ let bootstrapConnectionId = options.connectionId ?? env("VIRA_CONNECTION_ID") ?? "";
1693
+ if (!bootstrapAiSystemId || !bootstrapConnectionId) {
1694
+ try {
1695
+ const listed = await client.listAISystems();
1696
+ const system = listed?.body?.systems?.find((item) => String(item.name ?? "") === "OpenCode" && String(item.systemType ?? "") === "agent" && String(item.organizationId ?? "") === scope.organizationId && String(item.projectId ?? "") === scope.projectId && String(item.environmentId ?? "") === scope.environmentId);
1697
+ if (system?.id) {
1698
+ const connections = await client.listSystemConnections(String(system.id));
1699
+ const requested = new Set(openCodeConnectConfig(scope, options).capabilities);
1700
+ const connection = connections?.body?.connections?.find((item) => String(item.adapterType ?? "") === "custom-node" && requested.size <= (Array.isArray(item.capabilities) ? item.capabilities.length : 0) && [...requested].every((capability) => Array.isArray(item.capabilities) && item.capabilities.includes(capability)));
1701
+ if (connection?.id) {
1702
+ bootstrapAiSystemId = String(system.id);
1703
+ bootstrapConnectionId = String(connection.id);
1704
+ }
1705
+ }
1706
+ } catch {
1707
+ }
1708
+ }
1691
1709
  const runtime = createViraHostRuntime(client, { mode, capabilities, authorizeAction: options.authorizeAction ?? (async (proposal) => {
1692
1710
  const bound = actionContexts.get(contextKey(proposal));
1693
1711
  if (!bound) return { decision: "BLOCK", reasonCode: "RUNTIME_ACTION_CONTEXT_UNAVAILABLE" };
@@ -1711,9 +1729,9 @@ var v2Plugin = Plugin.define({
1711
1729
  if (!dataVersion) return { decision: "BLOCK", reasonCode: "RUNTIME_ACTION_DATA_VERSION_UNAVAILABLE" };
1712
1730
  const refs = Array.isArray(bound.context.signal_attestation_refs) ? bound.context.signal_attestation_refs : [];
1713
1731
  return authorizeWithOneShotCustomerConfirmation({ client, proposal, proposalBody, signalAttestationRefs: refs, executionId: bound.executionId, sessionId: proposal.sessionId ?? proposal.conversationId, dataVersion, scope, context: bound.context, confirmAction: options.confirmAction ?? nativeConfirm, approvalId: approval?.approvalId });
1714
- }), ...(options.aiSystemId ?? env("VIRA_AI_SYSTEM_ID")) && (options.connectionId ?? env("VIRA_CONNECTION_ID")) ? {} : { connect: openCodeConnectConfig(scope, options) } });
1715
- let connectedAiSystemId = options.aiSystemId ?? env("VIRA_AI_SYSTEM_ID") ?? "";
1716
- let connectedConnectionId = options.connectionId ?? env("VIRA_CONNECTION_ID") ?? "";
1732
+ }), ...bootstrapAiSystemId && bootstrapConnectionId ? {} : { connect: openCodeConnectConfig(scope, options) } });
1733
+ let connectedAiSystemId = bootstrapAiSystemId;
1734
+ let connectedConnectionId = bootstrapConnectionId;
1717
1735
  if (!connectedAiSystemId || !connectedConnectionId) {
1718
1736
  await runtime.connectOnce();
1719
1737
  const identity = runtime.getConnectionIdentity();
@@ -1747,7 +1765,22 @@ var v2Plugin = Plugin.define({
1747
1765
  return { ...scope, hostName: options.hostName ?? "opencode", hostVersion: hostVersionFor(options, ctx), aiSystemId: required2(connectedAiSystemId, "VIRA_HOST_AI_SYSTEM_REQUIRED"), connectionId: required2(connectedConnectionId, "VIRA_HOST_CONNECTION_REQUIRED"), conversationId: required2(event.conversationId ?? event.sessionID ?? event.sessionId ?? asRecord(event.session).id, "VIRA_HOST_SESSION_REQUIRED"), sessionId: sessionId || void 0 };
1748
1766
  };
1749
1767
  if (mode === "enforce" && options.permissionMode !== "deny" && ctx.permission?.hook) registrations.push(await ctx.permission.hook("evaluate", async (event) => {
1750
- desktopPermission.evaluate(event);
1768
+ const identity = sessionIdentity(event);
1769
+ const toolName = text2(event.action);
1770
+ if (!toolName) {
1771
+ event.effect = "deny";
1772
+ event.message = "Vira denied an unidentifiable tool request.";
1773
+ return;
1774
+ }
1775
+ const proposal = { ...identity, requestId: text2(event.messageID ?? event.requestId) || `opencode:${Date.now()}`, callId: text2(event.source?.id) || text2(event.messageID) || `permission:${Date.now()}`, toolName, args: asRecord(event.metadata ?? event.resources), traceId: text2(event.traceID), turnId: text2(event.turnID) };
1776
+ const decision = await runtime.beforeTool(proposal);
1777
+ if (decision.decision === "ALLOW") {
1778
+ event.effect = "allow";
1779
+ event.message = "Vira authorized this tool request.";
1780
+ } else {
1781
+ event.effect = "deny";
1782
+ event.message = `Vira denied this tool request: ${text2(decision.reasonCode) || decision.decision}`;
1783
+ }
1751
1784
  }));
1752
1785
  registrations.push(await ctx.session.hook("context", async (event) => {
1753
1786
  const input = lastUserText(event);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryvira/opencode",
3
- "version": "0.1.28",
3
+ "version": "0.1.30",
4
4
  "description": "OpenCode V2 host lifecycle integration for Vira",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",