@tryvira/opencode 0.1.29 → 0.1.31

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.29
1
+ # `@tryvira/opencode` 0.1.31
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
@@ -1693,11 +1693,13 @@ var v2Plugin = Plugin.define({
1693
1693
  if (!bootstrapAiSystemId || !bootstrapConnectionId) {
1694
1694
  try {
1695
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);
1696
+ const systems = Array.isArray(listed?.body?.systems) ? listed.body.systems : [];
1697
+ const system = 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
1698
  if (system?.id) {
1698
1699
  const connections = await client.listSystemConnections(String(system.id));
1700
+ const connectionRows = Array.isArray(connections?.body?.connections) ? connections.body.connections : [];
1699
1701
  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)));
1702
+ const connection = connectionRows.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
1703
  if (connection?.id) {
1702
1704
  bootstrapAiSystemId = String(system.id);
1703
1705
  bootstrapConnectionId = String(connection.id);
@@ -1765,7 +1767,22 @@ var v2Plugin = Plugin.define({
1765
1767
  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 };
1766
1768
  };
1767
1769
  if (mode === "enforce" && options.permissionMode !== "deny" && ctx.permission?.hook) registrations.push(await ctx.permission.hook("evaluate", async (event) => {
1768
- desktopPermission.evaluate(event);
1770
+ const identity = sessionIdentity(event);
1771
+ const toolName = text2(event.action);
1772
+ if (!toolName) {
1773
+ event.effect = "deny";
1774
+ event.message = "Vira denied an unidentifiable tool request.";
1775
+ return;
1776
+ }
1777
+ 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) };
1778
+ const decision = await runtime.beforeTool(proposal);
1779
+ if (decision.decision === "ALLOW") {
1780
+ event.effect = "allow";
1781
+ event.message = "Vira authorized this tool request.";
1782
+ } else {
1783
+ event.effect = "deny";
1784
+ event.message = `Vira denied this tool request: ${text2(decision.reasonCode) || decision.decision}`;
1785
+ }
1769
1786
  }));
1770
1787
  registrations.push(await ctx.session.hook("context", async (event) => {
1771
1788
  const input = lastUserText(event);
@@ -1925,6 +1942,14 @@ var v1Fallback = { async server(rawContext = {}) {
1925
1942
  if (Object.keys(hostOptions).length) output.options = hostOptions;
1926
1943
  if (result.status === "applied" && result.projection) output.system = [...Array.isArray(output.system) ? output.system : [], result.projection];
1927
1944
  },
1945
+ "permission.ask": async (input, output) => {
1946
+ if (mode !== "enforce") return;
1947
+ const metadata = asRecord(input.metadata);
1948
+ const proposal = { ...identity(input), requestId: text2(input.messageID ?? input.requestId) || `opencode:${Date.now()}`, callId: required2(input.callID ?? input.id, "VIRA_HOST_TOOL_CALL_REQUIRED"), toolName: required2(metadata.tool ?? metadata.toolName ?? input.type, "VIRA_HOST_TOOL_NAME_REQUIRED"), args: asRecord(metadata.args ?? metadata.input ?? metadata.arguments), traceId: text2(input.traceID), turnId: text2(input.turnID) };
1949
+ const decision = await runtime.beforeTool(proposal);
1950
+ actionDecisions.set(contextKey(proposal) + ":" + proposal.callId, decision);
1951
+ output.status = decision.decision === "ALLOW" ? "allow" : "deny";
1952
+ },
1928
1953
  "tool.execute.before": async (input, output) => {
1929
1954
  const proposal = { ...identity(input), requestId: text2(input.messageID ?? input.requestId) || `opencode:${Date.now()}`, callId: required2(input.callID ?? input.id, "VIRA_HOST_TOOL_CALL_REQUIRED"), toolName: required2(input.tool ?? input.name, "VIRA_HOST_TOOL_NAME_REQUIRED"), args: asRecord(output.args ?? input.args ?? input.input), traceId: text2(input.traceID), turnId: text2(input.turnID) };
1930
1955
  const decision = await runtime.beforeTool(proposal);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryvira/opencode",
3
- "version": "0.1.29",
3
+ "version": "0.1.31",
4
4
  "description": "OpenCode V2 host lifecycle integration for Vira",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",