Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement →
Sign In

glm-coding

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

glm-coding - npm Package Compare versions

Comparing version
0.4.0
to
0.5.0
+4
templates/claude-code/CLAUDE.md
# 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
+89
-9

@@ -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",

@@ -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 @@