cc-permissions 0.1.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.
- package/LICENSE +14 -0
- package/README.md +230 -0
- package/dist/analyze.d.ts +10 -0
- package/dist/analyze.d.ts.map +1 -0
- package/dist/analyze.js +213 -0
- package/dist/analyze.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +348 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/output.d.ts +83 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +178 -0
- package/dist/output.js.map +1 -0
- package/dist/permissions.d.ts +32 -0
- package/dist/permissions.d.ts.map +1 -0
- package/dist/permissions.js +98 -0
- package/dist/permissions.js.map +1 -0
- package/dist/templates/cache.d.ts +71 -0
- package/dist/templates/cache.d.ts.map +1 -0
- package/dist/templates/cache.js +137 -0
- package/dist/templates/cache.js.map +1 -0
- package/dist/templates/dotnet.d.ts +3 -0
- package/dist/templates/dotnet.d.ts.map +1 -0
- package/dist/templates/dotnet.js +76 -0
- package/dist/templates/dotnet.js.map +1 -0
- package/dist/templates/general.d.ts +3 -0
- package/dist/templates/general.d.ts.map +1 -0
- package/dist/templates/general.js +59 -0
- package/dist/templates/general.js.map +1 -0
- package/dist/templates/index.d.ts +32 -0
- package/dist/templates/index.d.ts.map +1 -0
- package/dist/templates/index.js +54 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/loader.d.ts +19 -0
- package/dist/templates/loader.d.ts.map +1 -0
- package/dist/templates/loader.js +221 -0
- package/dist/templates/loader.js.map +1 -0
- package/dist/templates/python.d.ts +3 -0
- package/dist/templates/python.d.ts.map +1 -0
- package/dist/templates/python.js +110 -0
- package/dist/templates/python.js.map +1 -0
- package/dist/templates/remote.d.ts +45 -0
- package/dist/templates/remote.d.ts.map +1 -0
- package/dist/templates/remote.js +147 -0
- package/dist/templates/remote.js.map +1 -0
- package/dist/templates/web.d.ts +3 -0
- package/dist/templates/web.d.ts.map +1 -0
- package/dist/templates/web.js +101 -0
- package/dist/templates/web.js.map +1 -0
- package/dist/types.d.ts +44 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/dist/version.d.ts +53 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +118 -0
- package/dist/version.js.map +1 -0
- package/package.json +54 -0
- package/templates/android.jsonc +99 -0
- package/templates/aws.jsonc +113 -0
- package/templates/azure.jsonc +103 -0
- package/templates/database.jsonc +133 -0
- package/templates/docker.jsonc +115 -0
- package/templates/dotnet.jsonc +80 -0
- package/templates/flutter.jsonc +106 -0
- package/templates/gcp.jsonc +110 -0
- package/templates/git.jsonc +52 -0
- package/templates/github.jsonc +132 -0
- package/templates/go.jsonc +75 -0
- package/templates/ios.jsonc +98 -0
- package/templates/java.jsonc +93 -0
- package/templates/kubernetes.jsonc +114 -0
- package/templates/nodejs.jsonc +105 -0
- package/templates/php.jsonc +107 -0
- package/templates/python.jsonc +114 -0
- package/templates/ruby.jsonc +99 -0
- package/templates/rust.jsonc +97 -0
- package/templates/shell.jsonc +73 -0
- package/templates/template.schema.json +102 -0
- package/templates/terraform.jsonc +96 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
BSD Zero Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DanielCarmingham
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
9
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
10
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
11
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
12
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
|
+
PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
# cc-permissions
|
|
2
|
+
|
|
3
|
+
**Thoughtful permission configs for Claude Code without the container overhead.**
|
|
4
|
+
|
|
5
|
+
## The Problem
|
|
6
|
+
|
|
7
|
+
Claude Code users face a frustrating choice:
|
|
8
|
+
|
|
9
|
+
- **Docker sandbox + `--dangerously-skip-permissions`**: Safe and convenient, but requires container setup and deals with overhead
|
|
10
|
+
- **Native execution**: No containers, but constant permission prompts interrupt your workflow
|
|
11
|
+
|
|
12
|
+
Neither option is ideal for users who want native performance with intentional control.
|
|
13
|
+
|
|
14
|
+
## Our Solution
|
|
15
|
+
|
|
16
|
+
A middle ground: generate thoughtful permission configurations that reduce prompt fatigue while maintaining deliberate control over what Claude Code can do.
|
|
17
|
+
|
|
18
|
+
**Important**: This approach is inherently less safe than a fully isolated environment—there's no sandbox. Users accept this tradeoff in exchange for avoiding container overhead while having more control than `--dangerously-skip-permissions` alone.
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
# Run directly with npx (no install needed)
|
|
24
|
+
npx cc-permissions
|
|
25
|
+
|
|
26
|
+
# Or install globally
|
|
27
|
+
npm install -g cc-permissions
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Claude Code Plugin
|
|
31
|
+
|
|
32
|
+
Install as a Claude Code plugin for integrated commands:
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
/plugin install DanielCarmingham/cc-permissions
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Then use:
|
|
39
|
+
- `/cc-permissions:analyze` - Scan project and recommend templates
|
|
40
|
+
- `/cc-permissions:template nodejs,python` - Generate from specific templates
|
|
41
|
+
- `/cc-permissions:list` - List available templates
|
|
42
|
+
- `/cc-permissions:apply` - Apply permissions to settings
|
|
43
|
+
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
### Quick Start
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# Analyze your project and apply recommended permissions
|
|
50
|
+
cc-permissions --apply
|
|
51
|
+
|
|
52
|
+
# Or be more specific
|
|
53
|
+
cc-permissions --apply --level permissive
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Generate Permissions from a Template
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
# Generate standard web development permissions
|
|
60
|
+
cc-permissions template nodejs --level standard
|
|
61
|
+
|
|
62
|
+
# Combine multiple templates
|
|
63
|
+
cc-permissions template nodejs,python --level standard
|
|
64
|
+
|
|
65
|
+
# Apply directly to .claude/settings.json (creates backup)
|
|
66
|
+
cc-permissions template nodejs --apply
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Analyze Your Project
|
|
70
|
+
|
|
71
|
+
Scan your project and get template recommendations:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
cc-permissions analyze
|
|
75
|
+
cc-permissions analyze ./path/to/project
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### List Available Templates
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
cc-permissions list
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Check Version
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
cc-permissions -v # or --version
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Permission Levels
|
|
91
|
+
|
|
92
|
+
Levels are cumulative—each level includes everything from the previous level:
|
|
93
|
+
|
|
94
|
+
| Level | Description | Use Case |
|
|
95
|
+
|-------|-------------|----------|
|
|
96
|
+
| `restrictive` | Read-only operations (git status, npm list, etc.) | Code review, exploration |
|
|
97
|
+
| `standard` | Dev workflow (+ git commit/push, npm run/build/test) | Day-to-day development |
|
|
98
|
+
| `permissive` | Few guardrails (+ npm install, most commands except banned) | Trusted projects, greenfield |
|
|
99
|
+
|
|
100
|
+
## Available Templates
|
|
101
|
+
|
|
102
|
+
| Template | Description |
|
|
103
|
+
|----------|-------------|
|
|
104
|
+
| `shell` | Git and common CLI tools (ls, cat, grep, find, etc.) |
|
|
105
|
+
| `nodejs` | Node.js, npm, and common frontend tooling |
|
|
106
|
+
| `python` | pip, python, venv, pytest, and common data tools |
|
|
107
|
+
| `dotnet` | dotnet CLI, NuGet, MSBuild |
|
|
108
|
+
|
|
109
|
+
Combine templates with commas: `cc-permissions template shell,nodejs,python`
|
|
110
|
+
|
|
111
|
+
Run `cc-permissions list` to see all available templates.
|
|
112
|
+
|
|
113
|
+
## Apply Options
|
|
114
|
+
|
|
115
|
+
Control where permissions are written with `--scope` or `--output`:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
# Project settings (default) - .claude/settings.json
|
|
119
|
+
cc-permissions --apply --scope project
|
|
120
|
+
|
|
121
|
+
# User/global settings - ~/.claude/settings.json
|
|
122
|
+
cc-permissions --apply --scope user
|
|
123
|
+
|
|
124
|
+
# Local settings (gitignored) - .claude/settings.local.json
|
|
125
|
+
cc-permissions --apply --scope local
|
|
126
|
+
|
|
127
|
+
# Custom file path
|
|
128
|
+
cc-permissions --apply --output ./my-permissions.json
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
| Scope | File | Use Case |
|
|
132
|
+
|-------|------|----------|
|
|
133
|
+
| `project` | `.claude/settings.json` | Shared team settings (commit to repo) |
|
|
134
|
+
| `user` / `global` | `~/.claude/settings.json` | Personal defaults across all projects |
|
|
135
|
+
| `local` | `.claude/settings.local.json` | Personal overrides (gitignored) |
|
|
136
|
+
|
|
137
|
+
**Tip:** Options support prefix matching—use `-l r` for `--level restrictive` or `-s u` for `--scope user`.
|
|
138
|
+
|
|
139
|
+
## Output Formats
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
# JSON only (default) - pipe to .claude/settings.json
|
|
143
|
+
cc-permissions template nodejs --format json
|
|
144
|
+
|
|
145
|
+
# Human-readable summary
|
|
146
|
+
cc-permissions template nodejs --format summary
|
|
147
|
+
|
|
148
|
+
# Both JSON and summary
|
|
149
|
+
cc-permissions template nodejs --format both
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Who This Is For
|
|
153
|
+
|
|
154
|
+
- Developers who prefer native execution over containers
|
|
155
|
+
- Users tired of repetitive permission prompts
|
|
156
|
+
- Teams wanting consistent permission policies across projects
|
|
157
|
+
|
|
158
|
+
## Contributing Templates
|
|
159
|
+
|
|
160
|
+
Templates are located in the `templates/` directory.
|
|
161
|
+
|
|
162
|
+
### Template Structure
|
|
163
|
+
|
|
164
|
+
Each template is a `.jsonc` file with comments allowed:
|
|
165
|
+
|
|
166
|
+
```jsonc
|
|
167
|
+
{
|
|
168
|
+
"$schema": "./template.schema.json",
|
|
169
|
+
"name": "my-template",
|
|
170
|
+
"description": "Brief description of what this template covers",
|
|
171
|
+
"levels": {
|
|
172
|
+
"restrictive": [
|
|
173
|
+
// Read-only commands (exploration, status checks)
|
|
174
|
+
{ "command": "mytool status", "description": "Check status" }
|
|
175
|
+
],
|
|
176
|
+
"standard": [
|
|
177
|
+
// Dev workflow commands (builds, tests, commits)
|
|
178
|
+
{ "command": "mytool build", "description": "Build project" }
|
|
179
|
+
],
|
|
180
|
+
"permissive": [
|
|
181
|
+
// Commands with broader access (installs, publishes)
|
|
182
|
+
{ "command": "mytool install *", "description": "Install packages" }
|
|
183
|
+
]
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Permission Level Guidelines
|
|
189
|
+
|
|
190
|
+
| Level | Purpose | Examples |
|
|
191
|
+
|-------|---------|----------|
|
|
192
|
+
| `restrictive` | Read-only, safe to run anytime | `git status`, `npm list`, `cargo check` |
|
|
193
|
+
| `standard` | Normal dev workflow | `git commit`, `npm test`, `cargo build` |
|
|
194
|
+
| `permissive` | Broader access, use with caution | `npm install`, `cargo publish` |
|
|
195
|
+
|
|
196
|
+
Each level is cumulative—`standard` includes everything from `restrictive`, and `permissive` includes everything from `standard`.
|
|
197
|
+
|
|
198
|
+
## Safety
|
|
199
|
+
|
|
200
|
+
All generated configs include a deny list of dangerous patterns:
|
|
201
|
+
- `rm -rf` - Recursive force delete
|
|
202
|
+
- `sudo` - Privilege escalation
|
|
203
|
+
- `curl | bash` / `wget | sh` - Remote code execution
|
|
204
|
+
- And more...
|
|
205
|
+
|
|
206
|
+
## Publishing (for maintainers)
|
|
207
|
+
|
|
208
|
+
Version management is done through npm scripts:
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
npm run version:show # Show current version
|
|
212
|
+
npm run version:bump patch # 0.1.0 → 0.1.1
|
|
213
|
+
npm run version:bump minor # 0.1.0 → 0.2.0
|
|
214
|
+
npm run version:bump major # 0.1.0 → 1.0.0
|
|
215
|
+
npm run version:set 2.0.0 # Set exact version
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
To publish:
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
npm login # first time only
|
|
222
|
+
npm run version:bump patch # bump version (also: minor, major)
|
|
223
|
+
npm publish # publishes to npm
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
A prepublish check automatically prevents publishing a version that already exists on npm.
|
|
227
|
+
|
|
228
|
+
## License
|
|
229
|
+
|
|
230
|
+
0BSD
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AnalysisResult } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Analyze a directory to recommend templates.
|
|
4
|
+
*/
|
|
5
|
+
export declare function analyzeDirectory(dir: string): AnalysisResult;
|
|
6
|
+
/**
|
|
7
|
+
* Format analysis result for display.
|
|
8
|
+
*/
|
|
9
|
+
export declare function formatAnalysisResult(result: AnalysisResult): string;
|
|
10
|
+
//# sourceMappingURL=analyze.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyze.d.ts","sourceRoot":"","sources":["../src/analyze.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAoC,MAAM,YAAY,CAAC;AA8HnF;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CA8D5D;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CA8BnE"}
|
package/dist/analyze.js
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { readdirSync, existsSync, statSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join, resolve, relative } from "node:path";
|
|
3
|
+
import { PermissionLevel } from "./types.js";
|
|
4
|
+
import { getTemplates } from "./templates/loader.js";
|
|
5
|
+
/**
|
|
6
|
+
* Check if a file exists in the directory.
|
|
7
|
+
* Supports glob patterns like "*.csproj"
|
|
8
|
+
*/
|
|
9
|
+
function fileExists(dir, pattern) {
|
|
10
|
+
try {
|
|
11
|
+
if (pattern.includes("*")) {
|
|
12
|
+
// Simple glob matching for extensions
|
|
13
|
+
const ext = pattern.replace("*", "");
|
|
14
|
+
const files = readdirSync(dir);
|
|
15
|
+
const match = files.find((f) => f.endsWith(ext));
|
|
16
|
+
return match ? join(dir, match) : null;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
const filePath = join(dir, pattern);
|
|
20
|
+
if (existsSync(filePath)) {
|
|
21
|
+
return filePath;
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Check if a directory exists in the given path.
|
|
32
|
+
* Supports patterns like ".git/", ".github/workflows/", "*.xcodeproj/"
|
|
33
|
+
*/
|
|
34
|
+
function directoryExists(dir, pattern) {
|
|
35
|
+
try {
|
|
36
|
+
// Remove trailing slash if present
|
|
37
|
+
const dirPattern = pattern.endsWith("/") ? pattern.slice(0, -1) : pattern;
|
|
38
|
+
if (dirPattern.includes("*")) {
|
|
39
|
+
// Simple glob matching for directory names
|
|
40
|
+
const suffix = dirPattern.replace("*", "");
|
|
41
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
42
|
+
const match = entries.find((e) => e.isDirectory() && e.name.endsWith(suffix));
|
|
43
|
+
return match ? join(dir, match.name) : null;
|
|
44
|
+
}
|
|
45
|
+
else if (dirPattern.includes("/")) {
|
|
46
|
+
// Nested directory path like ".github/workflows"
|
|
47
|
+
const fullPath = join(dir, dirPattern);
|
|
48
|
+
if (existsSync(fullPath) && statSync(fullPath).isDirectory()) {
|
|
49
|
+
return fullPath;
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
// Simple directory name like ".git"
|
|
55
|
+
const fullPath = join(dir, dirPattern);
|
|
56
|
+
if (existsSync(fullPath) && statSync(fullPath).isDirectory()) {
|
|
57
|
+
return fullPath;
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Check if a file contains specific text.
|
|
68
|
+
*/
|
|
69
|
+
function fileContains(dir, filename, searchText) {
|
|
70
|
+
const filePath = join(dir, filename);
|
|
71
|
+
if (!existsSync(filePath))
|
|
72
|
+
return false;
|
|
73
|
+
try {
|
|
74
|
+
const stat = statSync(filePath);
|
|
75
|
+
if (!stat.isFile())
|
|
76
|
+
return false;
|
|
77
|
+
const content = readFileSync(filePath, "utf-8");
|
|
78
|
+
return content.includes(searchText);
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Detect if a template should be recommended based on its detection rules.
|
|
86
|
+
* Returns the detected file/directory path if found, null otherwise.
|
|
87
|
+
*/
|
|
88
|
+
function detectTemplate(dir, detection) {
|
|
89
|
+
if (!detection)
|
|
90
|
+
return null;
|
|
91
|
+
// Check if always recommended
|
|
92
|
+
if (detection.always) {
|
|
93
|
+
return "always";
|
|
94
|
+
}
|
|
95
|
+
// Check simple file patterns
|
|
96
|
+
if (detection.files) {
|
|
97
|
+
for (const pattern of detection.files) {
|
|
98
|
+
const found = fileExists(dir, pattern);
|
|
99
|
+
if (found)
|
|
100
|
+
return found;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// Check directory patterns
|
|
104
|
+
if (detection.directories) {
|
|
105
|
+
for (const pattern of detection.directories) {
|
|
106
|
+
const found = directoryExists(dir, pattern);
|
|
107
|
+
if (found)
|
|
108
|
+
return found;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// Check content patterns
|
|
112
|
+
if (detection.contentPatterns) {
|
|
113
|
+
for (const { file, contains } of detection.contentPatterns) {
|
|
114
|
+
if (fileContains(dir, file, contains)) {
|
|
115
|
+
return join(dir, file);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Analyze a directory to recommend templates.
|
|
123
|
+
*/
|
|
124
|
+
export function analyzeDirectory(dir) {
|
|
125
|
+
const absoluteDir = resolve(dir);
|
|
126
|
+
const detectedFiles = [];
|
|
127
|
+
const recommendedTemplates = new Set();
|
|
128
|
+
// Load templates to get detection rules
|
|
129
|
+
let templates;
|
|
130
|
+
try {
|
|
131
|
+
templates = getTemplates();
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
// If templates can't be loaded, return minimal result with shell
|
|
135
|
+
return {
|
|
136
|
+
detectedFiles: [],
|
|
137
|
+
recommendedTemplates: ["shell"],
|
|
138
|
+
suggestedLevel: PermissionLevel.Restrictive,
|
|
139
|
+
suggestedCommand: "cc-permissions --apply --level restrictive",
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
// Check each template's detection rules
|
|
143
|
+
for (const [name, template] of Object.entries(templates)) {
|
|
144
|
+
const detected = detectTemplate(absoluteDir, template.detection);
|
|
145
|
+
if (detected) {
|
|
146
|
+
recommendedTemplates.add(name);
|
|
147
|
+
// Track detected files/directories (but not "always" marker)
|
|
148
|
+
if (detected !== "always") {
|
|
149
|
+
const relativePath = relative(absoluteDir, detected) || detected;
|
|
150
|
+
if (!detectedFiles.includes(relativePath)) {
|
|
151
|
+
detectedFiles.push(relativePath);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// Ensure shell is always included (even if template loading worked but shell wasn't auto-detected)
|
|
157
|
+
recommendedTemplates.add("shell");
|
|
158
|
+
// Determine suggested level based on number of templates
|
|
159
|
+
// More templates = more complex project = likely needs standard
|
|
160
|
+
const templateCount = recommendedTemplates.size;
|
|
161
|
+
let suggestedLevel;
|
|
162
|
+
if (templateCount <= 1) {
|
|
163
|
+
suggestedLevel = PermissionLevel.Restrictive;
|
|
164
|
+
}
|
|
165
|
+
else if (templateCount <= 3) {
|
|
166
|
+
suggestedLevel = PermissionLevel.Standard;
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
suggestedLevel = PermissionLevel.Standard; // Stay at standard, don't auto-suggest permissive
|
|
170
|
+
}
|
|
171
|
+
const templateNames = Array.from(recommendedTemplates);
|
|
172
|
+
const suggestedCommand = suggestedLevel === PermissionLevel.Standard
|
|
173
|
+
? `cc-permissions --apply`
|
|
174
|
+
: `cc-permissions --apply --level ${suggestedLevel}`;
|
|
175
|
+
return {
|
|
176
|
+
detectedFiles,
|
|
177
|
+
recommendedTemplates: templateNames,
|
|
178
|
+
suggestedLevel,
|
|
179
|
+
suggestedCommand,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Format analysis result for display.
|
|
184
|
+
*/
|
|
185
|
+
export function formatAnalysisResult(result) {
|
|
186
|
+
const lines = [
|
|
187
|
+
`Project Analysis`,
|
|
188
|
+
`================`,
|
|
189
|
+
``,
|
|
190
|
+
];
|
|
191
|
+
if (result.detectedFiles.length === 0) {
|
|
192
|
+
lines.push(`No specific project files detected.`);
|
|
193
|
+
lines.push(`Recommending shell template only.`);
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
lines.push(`Detected Files:`);
|
|
197
|
+
for (const file of result.detectedFiles) {
|
|
198
|
+
lines.push(` - ${file}`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
lines.push(``);
|
|
202
|
+
lines.push(`Recommended Templates:`);
|
|
203
|
+
for (const template of result.recommendedTemplates) {
|
|
204
|
+
lines.push(` - ${template}`);
|
|
205
|
+
}
|
|
206
|
+
lines.push(``);
|
|
207
|
+
lines.push(`Suggested Level: ${result.suggestedLevel}`);
|
|
208
|
+
lines.push(``);
|
|
209
|
+
lines.push(`Suggested Command:`);
|
|
210
|
+
lines.push(` ${result.suggestedCommand}`);
|
|
211
|
+
return lines.join("\n");
|
|
212
|
+
}
|
|
213
|
+
//# sourceMappingURL=analyze.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyze.js","sourceRoot":"","sources":["../src/analyze.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAEpD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,uBAA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