@gandalfix/opencode-permission-export 1.0.0 → 1.0.1

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/dist/index.d.ts CHANGED
@@ -10,7 +10,7 @@ interface GroupOptions {
10
10
  excludeCommands?: string[];
11
11
  }
12
12
  declare function groupPermissions(events: PermissionEvent[], options?: GroupOptions): PermissionEvent[];
13
- declare function generateConfig(events: PermissionEvent[]): Record<string, unknown>;
13
+ declare function generateConfig(events: PermissionEvent[], skipGrouping?: boolean): Record<string, unknown>;
14
14
  export declare const PermissionExportPlugin: Plugin;
15
15
  export default PermissionExportPlugin;
16
16
  export { extractCommandGroup, groupPermissions, generateConfig };
package/dist/index.js CHANGED
@@ -78,8 +78,8 @@ function groupPermissions(events, options = {}) {
78
78
  }
79
79
  return Array.from(groups.values());
80
80
  }
81
- function generateConfig(events) {
82
- const grouped = groupPermissions(events);
81
+ function generateConfig(events, skipGrouping = false) {
82
+ const grouped = skipGrouping ? events : groupPermissions(events);
83
83
  const permission = {};
84
84
  for (const event of grouped) {
85
85
  if (!permission[event.tool]) {
@@ -110,8 +110,10 @@ export const PermissionExportPlugin = async (ctx) => {
110
110
  tool: {
111
111
  "export-permissions": tool({
112
112
  description: "Export granted permissions as opencode config snippet. Paste the output into your opencode.json.",
113
- args: {},
114
- async execute(_args, _context) {
113
+ args: {
114
+ format: tool.schema.enum(["combined", "individual"]).optional().default("combined").describe("Export format: 'combined' groups related commands (e.g., git:*), 'individual' exports each permission separately")
115
+ },
116
+ async execute(args, context) {
115
117
  if (!tracker.hasEvents()) {
116
118
  return "No permissions have been asked this session.";
117
119
  }
@@ -120,10 +122,12 @@ export const PermissionExportPlugin = async (ctx) => {
120
122
  const denied = tracker.getDenied();
121
123
  return `No permissions were granted. ${denied.length} request(s) were denied.`;
122
124
  }
123
- const config = generateConfig(granted);
125
+ const skipGrouping = args.format === "individual";
126
+ const config = generateConfig(granted, skipGrouping);
124
127
  const denied = tracker.getDenied();
125
128
  const deniedNote = denied.length > 0 ? `\n\nNote: ${denied.length} permission(s) were denied and not included.` : "";
126
- return `Copy this into your opencode.json:\n\n${JSON.stringify(config, null, 2)}${deniedNote}`;
129
+ const formatLabel = skipGrouping ? "individual" : "combined";
130
+ return `Copy this into your opencode.json (${formatLabel} format):\n\n${JSON.stringify(config, null, 2)}${deniedNote}`;
127
131
  },
128
132
  }),
129
133
  },
@@ -63,3 +63,16 @@ describe("generateConfig with grouping", () => {
63
63
  });
64
64
  });
65
65
  });
66
+ describe("generateConfig with skipGrouping", () => {
67
+ it("outputs individual permissions when skipGrouping is true", () => {
68
+ const events = [
69
+ { tool: "bash", pattern: "git status", outcome: "granted" },
70
+ { tool: "bash", pattern: "git diff", outcome: "granted" },
71
+ ];
72
+ const result = generateConfig(events, true);
73
+ expect(result.permission.bash).toEqual({
74
+ "git status": "allow",
75
+ "git diff": "allow",
76
+ });
77
+ });
78
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gandalfix/opencode-permission-export",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "OpenCode plugin to export granted permissions as config snippet",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",