| # GLM Code Generation | ||
| - `@glm`, `-glm`, `--glm` in prompt ā Auto-triggers GLM mode (hook) | ||
| - `/glm TASK` ā Explicit GLM command | ||
| - Always use `-o` for direct file save |
| # GLM Code Generation | ||
| Execute GLM CLI for code generation with automatic file saving. | ||
| ## Request | ||
| `$ARGUMENTS` | ||
| ## Instructions | ||
| 1. **Parse request**: Extract code description, target filepath, language, profile | ||
| 2. **Determine filepath**: If not specified, infer from context or ask user | ||
| 3. **Select profile** (optional): | ||
| - `frontend-design`: UI/UX, React, components | ||
| - `api-integration`: REST, GraphQL, OAuth | ||
| - `database-ops`: SQL, queries, migrations | ||
| - `web-crawler`: Web scraping, parsing | ||
| 4. **Complexity check**: | ||
| - Simple (<50 lines) / Medium (<200 lines) ā Proceed | ||
| - Complex (>200 lines, recursion, edge cases) ā Warn user, suggest Claude | ||
| 5. **Execute with -o for direct save**: | ||
| ```bash | ||
| glm -q "PROMPT" -o "FILEPATH" [-p PROFILE] | ||
| ``` | ||
| 6. **Verify**: Read generated file, check for issues | ||
| ## Examples | ||
| ``` | ||
| /glm REST API client for weather API ā src/api/weather.ts | ||
| /glm React button with hover state -p frontend-design ā components/Button.tsx | ||
| /glm ė³ė ¬ė” ģ¬ė¬ ķģ¼ ģģ±: utils, types, main | ||
| ``` |
| #!/bin/bash | ||
| # GLM Keyword Detector Hook | ||
| # Detects @glm, -glm, --glm in user prompts and injects GLM execution instructions | ||
| input=$(cat) | ||
| prompt=$(echo "$input" | jq -r '.prompt') | ||
| # Check for GLM keywords | ||
| if echo "$prompt" | grep -iE '(@glm|^-glm|[[:space:]]-glm|--glm)' > /dev/null; then | ||
| cat <<'EOF' | ||
| { | ||
| "hookSpecificOutput": { | ||
| "hookEventName": "UserPromptSubmit", | ||
| "additionalContext": "GLM MODE ACTIVATED:\n\n1. ALWAYS use `glm -q \"...\" -o FILEPATH` to save directly to file\n2. Determine appropriate filepath from context or ask user\n3. Profiles: -p frontend-design | api-integration | database-ops | web-crawler\n4. Complexity check: >200 lines or recursive ā warn user, suggest Claude\n5. After GLM execution, verify the generated file\n\nExample: glm -q \"Create a REST API client for weather\" -o src/api/weather.ts -p api-integration" | ||
| } | ||
| } | ||
| EOF | ||
| else | ||
| # No GLM keyword - allow normal processing | ||
| echo "" | ||
| fi | ||
| exit 0 |
@@ -5,3 +5,3 @@ /** | ||
| */ | ||
| import { cpSync, existsSync, mkdirSync, writeFileSync, readFileSync, appendFileSync } from 'fs'; | ||
| import { cpSync, existsSync, mkdirSync, writeFileSync, readFileSync, appendFileSync, chmodSync } from 'fs'; | ||
| import { join, dirname } from 'path'; | ||
@@ -76,6 +76,10 @@ import { fileURLToPath } from 'url'; | ||
| /** | ||
| * Update CLAUDE.md with GLM section | ||
| * Update CLAUDE.md with GLM section (from template) | ||
| */ | ||
| function updateClaudeMd(claudeMdPath) { | ||
| const glmSection = getGlmClaudeSection(); | ||
| function updateClaudeMd(claudeMdPath, templatePath) { | ||
| if (!existsSync(templatePath)) { | ||
| console.log(' ā ļø Claude Code template not found, skipping CLAUDE.md'); | ||
| return; | ||
| } | ||
| const glmSection = readFileSync(templatePath, 'utf-8'); | ||
| if (!existsSync(claudeMdPath)) { | ||
@@ -108,2 +112,72 @@ // Create new file | ||
| /** | ||
| * Install Claude Code integration (hooks, commands, CLAUDE.md) | ||
| */ | ||
| function installClaudeCodeIntegration(claudeDir, templatesDir) { | ||
| const claudeCodeTemplateDir = join(templatesDir, 'claude-code'); | ||
| if (!existsSync(claudeCodeTemplateDir)) { | ||
| console.log(' ā ļø Claude Code templates not found, skipping integration'); | ||
| return; | ||
| } | ||
| // Install hooks | ||
| const hooksSrc = join(claudeCodeTemplateDir, 'hooks'); | ||
| if (existsSync(hooksSrc)) { | ||
| const hooksDest = join(claudeDir, 'hooks'); | ||
| mkdirSync(hooksDest, { recursive: true }); | ||
| cpSync(hooksSrc, hooksDest, { recursive: true }); | ||
| // Make hook scripts executable | ||
| const hookScript = join(hooksDest, 'glm-detector.sh'); | ||
| if (existsSync(hookScript)) { | ||
| chmodSync(hookScript, 0o755); | ||
| console.log(` Installed: ${hookScript}`); | ||
| } | ||
| } | ||
| // Install commands | ||
| const commandsSrc = join(claudeCodeTemplateDir, 'commands'); | ||
| if (existsSync(commandsSrc)) { | ||
| const commandsDest = join(claudeDir, 'commands'); | ||
| mkdirSync(commandsDest, { recursive: true }); | ||
| cpSync(commandsSrc, commandsDest, { recursive: true }); | ||
| console.log(` Installed: /glm command`); | ||
| } | ||
| // Update settings.json with hook configuration | ||
| updateClaudeSettings(claudeDir); | ||
| } | ||
| /** | ||
| * Update ~/.claude/settings.json with hook configuration | ||
| */ | ||
| function updateClaudeSettings(claudeDir) { | ||
| const settingsPath = join(claudeDir, 'settings.json'); | ||
| const hookScript = join(claudeDir, 'hooks', 'glm-detector.sh'); | ||
| if (!existsSync(hookScript)) { | ||
| return; | ||
| } | ||
| let settings = {}; | ||
| // Read existing settings | ||
| if (existsSync(settingsPath)) { | ||
| try { | ||
| const content = readFileSync(settingsPath, 'utf-8'); | ||
| settings = JSON.parse(content); | ||
| } | ||
| catch { | ||
| console.log(' ā ļø Could not parse settings.json, creating new one'); | ||
| } | ||
| } | ||
| // Add hook configuration | ||
| if (!settings.hooks) { | ||
| settings.hooks = {}; | ||
| } | ||
| settings.hooks.UserPromptSubmit = [ | ||
| { | ||
| hooks: [ | ||
| { | ||
| type: 'command', | ||
| command: hookScript | ||
| } | ||
| ] | ||
| } | ||
| ]; | ||
| writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + '\n'); | ||
| console.log(` Updated: ${settingsPath}`); | ||
| } | ||
| /** | ||
| * Check for legacy MCP installation and offer migration | ||
@@ -224,8 +298,11 @@ */ | ||
| writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n'); | ||
| // Step 5: Update CLAUDE.md | ||
| console.log('š Setting up Claude integration...'); | ||
| // Step 5: Install Claude Code integration | ||
| console.log('š Setting up Claude Code integration...'); | ||
| mkdirSync(claudeDir, { recursive: true }); | ||
| // Install hooks, commands, and CLAUDE.md template | ||
| installClaudeCodeIntegration(claudeDir, templatesDir); | ||
| // Update CLAUDE.md | ||
| const claudeMdPath = join(claudeDir, 'CLAUDE.md'); | ||
| updateClaudeMd(claudeMdPath); | ||
| const claudeMdTemplate = join(templatesDir, 'claude-code', 'CLAUDE.md'); | ||
| updateClaudeMd(claudeMdPath, claudeMdTemplate); | ||
| // Done! | ||
@@ -244,5 +321,8 @@ console.log('\nā Installation complete!\n'); | ||
| console.log('šÆ Usage:\n'); | ||
| console.log(' glm -q "Create a function to parse JSON"'); | ||
| console.log(' glm -q "React component" -p frontend-design'); | ||
| console.log(' glm -q "Create a function to parse JSON" -o utils/parser.py'); | ||
| console.log(' glm -q "React component" -p frontend-design -o Button.tsx'); | ||
| console.log(' echo "Parse JSON" | glm -o parser.py\n'); | ||
| console.log('š” Claude Code integration:\n'); | ||
| console.log(' @glm Create a REST API client ā Auto-triggers GLM mode'); | ||
| console.log(' /glm REST API client ā src/api.ts\n'); | ||
| if (isGlobal) { | ||
@@ -249,0 +329,0 @@ console.log('š” The glm command is now available globally.'); |
+1
-1
| { | ||
| "name": "glm-coding", | ||
| "version": "0.4.0", | ||
| "version": "0.5.0", | ||
| "description": "GLM CLI - AI Code Generator with streaming output", | ||
@@ -5,0 +5,0 @@ "type": "module", |
+52
-0
@@ -130,2 +130,54 @@ # GLM CLI - AI Code Generator | ||
| ## Claude Code Integration | ||
| **NEW in v0.5.0:** `glm init` now automatically installs Claude Code integration! | ||
| When you run `glm init` or `glm init -g`, the installer automatically sets up: | ||
| ### 1. Hook System (Auto-Trigger) | ||
| **Detect keywords in your prompts:** | ||
| ``` | ||
| @glm Create a REST API client ā Automatically activates GLM mode | ||
| -glm Parse JSON with validation ā Activates GLM mode | ||
| --glm React button component ā Activates GLM mode | ||
| ``` | ||
| The hook injects GLM-specific instructions when keywords are detected. | ||
| ### 2. Slash Command | ||
| **Explicit GLM invocation:** | ||
| ``` | ||
| /glm REST API client ā src/api.ts | ||
| /glm fibonacci function ā utils/math.py | ||
| /glm ė³ė ¬ė” ģ¬ė¬ ķģ¼ ģģ± | ||
| ``` | ||
| ### 3. CLAUDE.md Instructions | ||
| Automatically adds GLM usage guidelines to `~/.claude/CLAUDE.md` or `.claude/CLAUDE.md` | ||
| ### What Gets Installed | ||
| ``` | ||
| ~/.claude/ | ||
| āāā hooks/ | ||
| ā āāā glm-detector.sh # Keyword detection hook | ||
| āāā commands/ | ||
| ā āāā glm.md # /glm slash command | ||
| āāā settings.json # Hook configuration (auto-updated) | ||
| āāā CLAUDE.md # GLM usage guidelines | ||
| ``` | ||
| ### Manual Installation (Optional) | ||
| If you prefer manual setup, the hook script is available at: | ||
| ```bash | ||
| ~/.claude/hooks/glm-detector.sh | ||
| ``` | ||
| To verify hook installation: | ||
| ```bash | ||
| # Check if hook is configured | ||
| cat ~/.claude/settings.json | grep -A 5 "UserPromptSubmit" | ||
| ``` | ||
| ## Configuration | ||
@@ -132,0 +184,0 @@ |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
123846
5.67%50
6.38%2538
3.25%478
12.21%