@codemieai/code 0.0.33 โ 0.0.35
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 +78 -7
- package/bin/codemie-claude-acp.js +21 -0
- package/bin/codemie-opencode.js +11 -0
- package/bin/codemie.js +13 -0
- package/dist/agents/codemie-code/agent.d.ts +38 -4
- package/dist/agents/codemie-code/agent.d.ts.map +1 -1
- package/dist/agents/codemie-code/agent.js +333 -178
- package/dist/agents/codemie-code/agent.js.map +1 -1
- package/dist/agents/codemie-code/index.d.ts +2 -1
- package/dist/agents/codemie-code/index.d.ts.map +1 -1
- package/dist/agents/codemie-code/index.js +36 -7
- package/dist/agents/codemie-code/index.js.map +1 -1
- package/dist/agents/codemie-code/prompts.d.ts +12 -5
- package/dist/agents/codemie-code/prompts.d.ts.map +1 -1
- package/dist/agents/codemie-code/prompts.js +53 -6
- package/dist/agents/codemie-code/prompts.js.map +1 -1
- package/dist/agents/codemie-code/toolMetadata.d.ts.map +1 -1
- package/dist/agents/codemie-code/toolMetadata.js +9 -8
- package/dist/agents/codemie-code/toolMetadata.js.map +1 -1
- package/dist/agents/codemie-code/tools/assistant-invocation.d.ts +47 -0
- package/dist/agents/codemie-code/tools/assistant-invocation.d.ts.map +1 -0
- package/dist/agents/codemie-code/tools/assistant-invocation.js +129 -0
- package/dist/agents/codemie-code/tools/assistant-invocation.js.map +1 -0
- package/dist/agents/codemie-code/tools/index.d.ts +70 -4
- package/dist/agents/codemie-code/tools/index.d.ts.map +1 -1
- package/dist/agents/codemie-code/tools/index.js +57 -44
- package/dist/agents/codemie-code/tools/index.js.map +1 -1
- package/dist/agents/codemie-code/tools/planning.d.ts +6 -5
- package/dist/agents/codemie-code/tools/planning.d.ts.map +1 -1
- package/dist/agents/codemie-code/tools/planning.js +12 -10
- package/dist/agents/codemie-code/tools/planning.js.map +1 -1
- package/dist/agents/codemie-code/types.d.ts +27 -3
- package/dist/agents/codemie-code/types.d.ts.map +1 -1
- package/dist/agents/codemie-code/types.js +24 -0
- package/dist/agents/codemie-code/types.js.map +1 -1
- package/dist/agents/codemie-code/ui/autocomplete.d.ts +98 -0
- package/dist/agents/codemie-code/ui/autocomplete.d.ts.map +1 -0
- package/dist/agents/codemie-code/ui/autocomplete.js +145 -0
- package/dist/agents/codemie-code/ui/autocomplete.js.map +1 -0
- package/dist/agents/codemie-code/ui/keyHandlers.d.ts +112 -0
- package/dist/agents/codemie-code/ui/keyHandlers.d.ts.map +1 -0
- package/dist/agents/codemie-code/ui/keyHandlers.js +415 -0
- package/dist/agents/codemie-code/ui/keyHandlers.js.map +1 -0
- package/dist/agents/codemie-code/ui/mentions.d.ts +86 -0
- package/dist/agents/codemie-code/ui/mentions.d.ts.map +1 -0
- package/dist/agents/codemie-code/ui/mentions.js +122 -0
- package/dist/agents/codemie-code/ui/mentions.js.map +1 -0
- package/dist/agents/codemie-code/ui/terminalCodes.d.ts +38 -0
- package/dist/agents/codemie-code/ui/terminalCodes.d.ts.map +1 -0
- package/dist/agents/codemie-code/ui/terminalCodes.js +42 -0
- package/dist/agents/codemie-code/ui/terminalCodes.js.map +1 -0
- package/dist/agents/codemie-code/ui/todoPanel.d.ts.map +1 -1
- package/dist/agents/codemie-code/ui/todoPanel.js +3 -4
- package/dist/agents/codemie-code/ui/todoPanel.js.map +1 -1
- package/dist/agents/codemie-code/ui.d.ts +8 -7
- package/dist/agents/codemie-code/ui.d.ts.map +1 -1
- package/dist/agents/codemie-code/ui.js +87 -145
- package/dist/agents/codemie-code/ui.js.map +1 -1
- package/dist/agents/core/AgentCLI.d.ts +5 -0
- package/dist/agents/core/AgentCLI.d.ts.map +1 -1
- package/dist/agents/core/AgentCLI.js +25 -1
- package/dist/agents/core/AgentCLI.js.map +1 -1
- package/dist/agents/core/BaseAgentAdapter.d.ts.map +1 -1
- package/dist/agents/core/BaseAgentAdapter.js +90 -27
- package/dist/agents/core/BaseAgentAdapter.js.map +1 -1
- package/dist/agents/core/extension/BaseExtensionInstaller.d.ts +7 -1
- package/dist/agents/core/extension/BaseExtensionInstaller.d.ts.map +1 -1
- package/dist/agents/core/extension/BaseExtensionInstaller.js +58 -15
- package/dist/agents/core/extension/BaseExtensionInstaller.js.map +1 -1
- package/dist/agents/core/session/BaseSessionAdapter.d.ts +25 -0
- package/dist/agents/core/session/BaseSessionAdapter.d.ts.map +1 -1
- package/dist/agents/core/session/discovery-types.d.ts +53 -0
- package/dist/agents/core/session/discovery-types.d.ts.map +1 -0
- package/dist/agents/core/session/discovery-types.js +8 -0
- package/dist/agents/core/session/discovery-types.js.map +1 -0
- package/dist/agents/core/types.d.ts +62 -0
- package/dist/agents/core/types.d.ts.map +1 -1
- package/dist/agents/plugins/claude/claude-acp.plugin.d.ts +27 -0
- package/dist/agents/plugins/claude/claude-acp.plugin.d.ts.map +1 -0
- package/dist/agents/plugins/claude/claude-acp.plugin.js +63 -0
- package/dist/agents/plugins/claude/claude-acp.plugin.js.map +1 -0
- package/dist/agents/plugins/claude/claude-message-types.d.ts +1 -0
- package/dist/agents/plugins/claude/claude-message-types.d.ts.map +1 -1
- package/dist/agents/plugins/claude/claude.plugin.d.ts +44 -1
- package/dist/agents/plugins/claude/claude.plugin.d.ts.map +1 -1
- package/dist/agents/plugins/claude/claude.plugin.js +263 -12
- package/dist/agents/plugins/claude/claude.plugin.js.map +1 -1
- package/dist/agents/plugins/claude/claude.session.d.ts.map +1 -1
- package/dist/agents/plugins/claude/claude.session.js +14 -7
- package/dist/agents/plugins/claude/claude.session.js.map +1 -1
- package/dist/agents/plugins/claude/plugin/.claude-plugin/plugin.json +1 -1
- package/dist/agents/plugins/claude/plugin/README.md +40 -2
- package/dist/agents/plugins/claude/plugin/claude-templates/README.md +5 -5
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/CLAUDE.md.template +177 -436
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/agents/code-review-agent-template.md.template +49 -82
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/agents/refactor-cleaner-agent.md.template +337 -0
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/agents/solution-architect-agent.md.template +129 -419
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/agents/unit-tester-agent.md.template +146 -693
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/api/api-patterns.md.template +110 -138
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/architecture/architecture.md.template +197 -0
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/data/database-patterns.md.template +171 -91
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/development/development-practices.md.template +219 -131
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/security/security-practices.md.template +223 -98
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/standards/code-quality.md.template +131 -95
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/testing/testing-patterns.md.template +247 -75
- package/dist/agents/plugins/claude/plugin/commands/README.md +133 -0
- package/dist/agents/plugins/claude/plugin/commands/codemie-init.md +336 -544
- package/dist/agents/plugins/claude/plugin/commands/codemie-subagents.md +233 -504
- package/dist/agents/plugins/claude/plugin/commands/memory-add.md +311 -30
- package/dist/agents/plugins/claude/plugin/commands/memory-refresh.md +218 -39
- package/dist/agents/plugins/claude/session/processors/claude.conversations-processor.d.ts.map +1 -1
- package/dist/agents/plugins/claude/session/processors/claude.conversations-processor.js +43 -8
- package/dist/agents/plugins/claude/session/processors/claude.conversations-processor.js.map +1 -1
- package/dist/agents/plugins/claude/session/processors/claude.metrics-processor.d.ts.map +1 -1
- package/dist/agents/plugins/claude/session/processors/claude.metrics-processor.js +68 -40
- package/dist/agents/plugins/claude/session/processors/claude.metrics-processor.js.map +1 -1
- package/dist/agents/plugins/gemini/gemini.plugin.d.ts.map +1 -1
- package/dist/agents/plugins/gemini/gemini.plugin.js +0 -3
- package/dist/agents/plugins/gemini/gemini.plugin.js.map +1 -1
- package/dist/agents/plugins/opencode/index.d.ts +8 -0
- package/dist/agents/plugins/opencode/index.d.ts.map +1 -0
- package/dist/agents/plugins/opencode/index.js +12 -0
- package/dist/agents/plugins/opencode/index.js.map +1 -0
- package/dist/agents/plugins/opencode/opencode-message-types.d.ts +207 -0
- package/dist/agents/plugins/opencode/opencode-message-types.d.ts.map +1 -0
- package/dist/agents/plugins/opencode/opencode-message-types.js +59 -0
- package/dist/agents/plugins/opencode/opencode-message-types.js.map +1 -0
- package/dist/agents/plugins/opencode/opencode-model-configs.d.ts +65 -0
- package/dist/agents/plugins/opencode/opencode-model-configs.d.ts.map +1 -0
- package/dist/agents/plugins/opencode/opencode-model-configs.js +184 -0
- package/dist/agents/plugins/opencode/opencode-model-configs.js.map +1 -0
- package/dist/agents/plugins/opencode/opencode.paths.d.ts +62 -0
- package/dist/agents/plugins/opencode/opencode.paths.d.ts.map +1 -0
- package/dist/agents/plugins/opencode/opencode.paths.js +148 -0
- package/dist/agents/plugins/opencode/opencode.paths.js.map +1 -0
- package/dist/agents/plugins/opencode/opencode.plugin.d.ts +35 -0
- package/dist/agents/plugins/opencode/opencode.plugin.d.ts.map +1 -0
- package/dist/agents/plugins/opencode/opencode.plugin.js +338 -0
- package/dist/agents/plugins/opencode/opencode.plugin.js.map +1 -0
- package/dist/agents/plugins/opencode/opencode.session.d.ts +77 -0
- package/dist/agents/plugins/opencode/opencode.session.d.ts.map +1 -0
- package/dist/agents/plugins/opencode/opencode.session.js +424 -0
- package/dist/agents/plugins/opencode/opencode.session.js.map +1 -0
- package/dist/agents/plugins/opencode/opencode.storage-utils.d.ts +25 -0
- package/dist/agents/plugins/opencode/opencode.storage-utils.d.ts.map +1 -0
- package/dist/agents/plugins/opencode/opencode.storage-utils.js +96 -0
- package/dist/agents/plugins/opencode/opencode.storage-utils.js.map +1 -0
- package/dist/agents/plugins/opencode/session/processors/opencode.conversations-processor.d.ts +30 -0
- package/dist/agents/plugins/opencode/session/processors/opencode.conversations-processor.d.ts.map +1 -0
- package/dist/agents/plugins/opencode/session/processors/opencode.conversations-processor.js +116 -0
- package/dist/agents/plugins/opencode/session/processors/opencode.conversations-processor.js.map +1 -0
- package/dist/agents/plugins/opencode/session/processors/opencode.metrics-processor.d.ts +102 -0
- package/dist/agents/plugins/opencode/session/processors/opencode.metrics-processor.d.ts.map +1 -0
- package/dist/agents/plugins/opencode/session/processors/opencode.metrics-processor.js +584 -0
- package/dist/agents/plugins/opencode/session/processors/opencode.metrics-processor.js.map +1 -0
- package/dist/agents/registry.d.ts +1 -1
- package/dist/agents/registry.d.ts.map +1 -1
- package/dist/agents/registry.js +5 -1
- package/dist/agents/registry.js.map +1 -1
- package/dist/cli/commands/assistants/chat.d.ts +11 -0
- package/dist/cli/commands/assistants/chat.d.ts.map +1 -0
- package/dist/cli/commands/assistants/chat.js +201 -0
- package/dist/cli/commands/assistants/chat.js.map +1 -0
- package/dist/cli/commands/assistants/constants.d.ts +81 -0
- package/dist/cli/commands/assistants/constants.d.ts.map +1 -0
- package/dist/cli/commands/assistants/constants.js +75 -0
- package/dist/cli/commands/assistants/constants.js.map +1 -0
- package/dist/cli/commands/assistants/generators/claude-agent-generator.d.ts +26 -0
- package/dist/cli/commands/assistants/generators/claude-agent-generator.d.ts.map +1 -0
- package/dist/cli/commands/assistants/generators/claude-agent-generator.js +115 -0
- package/dist/cli/commands/assistants/generators/claude-agent-generator.js.map +1 -0
- package/dist/cli/commands/assistants/index.d.ts +11 -0
- package/dist/cli/commands/assistants/index.d.ts.map +1 -0
- package/dist/cli/commands/assistants/index.js +28 -0
- package/dist/cli/commands/assistants/index.js.map +1 -0
- package/dist/cli/commands/assistants/list.d.ts +11 -0
- package/dist/cli/commands/assistants/list.d.ts.map +1 -0
- package/dist/cli/commands/assistants/list.js +323 -0
- package/dist/cli/commands/assistants/list.js.map +1 -0
- package/dist/cli/commands/doctor/checks/AgentsCheck.d.ts +5 -0
- package/dist/cli/commands/doctor/checks/AgentsCheck.d.ts.map +1 -1
- package/dist/cli/commands/doctor/checks/AgentsCheck.js +29 -0
- package/dist/cli/commands/doctor/checks/AgentsCheck.js.map +1 -1
- package/dist/cli/commands/install.d.ts.map +1 -1
- package/dist/cli/commands/install.js +104 -13
- package/dist/cli/commands/install.js.map +1 -1
- package/dist/cli/commands/opencode-metrics.d.ts +13 -0
- package/dist/cli/commands/opencode-metrics.d.ts.map +1 -0
- package/dist/cli/commands/opencode-metrics.js +200 -0
- package/dist/cli/commands/opencode-metrics.js.map +1 -0
- package/dist/cli/commands/self-update.d.ts +3 -0
- package/dist/cli/commands/self-update.d.ts.map +1 -0
- package/dist/cli/commands/self-update.js +55 -0
- package/dist/cli/commands/self-update.js.map +1 -0
- package/dist/cli/commands/setup.d.ts.map +1 -1
- package/dist/cli/commands/setup.js +113 -0
- package/dist/cli/commands/setup.js.map +1 -1
- package/dist/cli/commands/skill.d.ts +6 -0
- package/dist/cli/commands/skill.d.ts.map +1 -0
- package/dist/cli/commands/skill.js +196 -0
- package/dist/cli/commands/skill.js.map +1 -0
- package/dist/cli/commands/update.d.ts.map +1 -1
- package/dist/cli/commands/update.js +34 -6
- package/dist/cli/commands/update.js.map +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +12 -4
- package/dist/cli/index.js.map +1 -1
- package/dist/env/types.d.ts +13 -0
- package/dist/env/types.d.ts.map +1 -1
- package/dist/env/types.js +1 -1
- package/dist/env/types.js.map +1 -1
- package/dist/migrations/003-remove-hooks-node.migration.d.ts +22 -0
- package/dist/migrations/003-remove-hooks-node.migration.d.ts.map +1 -0
- package/dist/migrations/003-remove-hooks-node.migration.js +103 -0
- package/dist/migrations/003-remove-hooks-node.migration.js.map +1 -0
- package/dist/migrations/index.d.ts +1 -0
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +1 -1
- package/dist/migrations/index.js.map +1 -1
- package/dist/providers/plugins/sso/sso.http-client.js +2 -2
- package/dist/providers/plugins/sso/sso.http-client.js.map +1 -1
- package/dist/providers/plugins/sso/sso.setup-steps.d.ts.map +1 -1
- package/dist/providers/plugins/sso/sso.setup-steps.js +14 -10
- package/dist/providers/plugins/sso/sso.setup-steps.js.map +1 -1
- package/dist/skills/core/SkillDiscovery.d.ts +83 -0
- package/dist/skills/core/SkillDiscovery.d.ts.map +1 -0
- package/dist/skills/core/SkillDiscovery.js +237 -0
- package/dist/skills/core/SkillDiscovery.js.map +1 -0
- package/dist/skills/core/SkillManager.d.ts +86 -0
- package/dist/skills/core/SkillManager.d.ts.map +1 -0
- package/dist/skills/core/SkillManager.js +155 -0
- package/dist/skills/core/SkillManager.js.map +1 -0
- package/dist/skills/core/types.d.ts +120 -0
- package/dist/skills/core/types.d.ts.map +1 -0
- package/dist/skills/core/types.js +20 -0
- package/dist/skills/core/types.js.map +1 -0
- package/dist/skills/index.d.ts +12 -0
- package/dist/skills/index.d.ts.map +1 -0
- package/dist/skills/index.js +12 -0
- package/dist/skills/index.js.map +1 -0
- package/dist/skills/utils/content-loader.d.ts +25 -0
- package/dist/skills/utils/content-loader.d.ts.map +1 -0
- package/dist/skills/utils/content-loader.js +161 -0
- package/dist/skills/utils/content-loader.js.map +1 -0
- package/dist/skills/utils/frontmatter.d.ts +60 -0
- package/dist/skills/utils/frontmatter.d.ts.map +1 -0
- package/dist/skills/utils/frontmatter.js +114 -0
- package/dist/skills/utils/frontmatter.js.map +1 -0
- package/dist/skills/utils/pattern-matcher.d.ts +60 -0
- package/dist/skills/utils/pattern-matcher.d.ts.map +1 -0
- package/dist/skills/utils/pattern-matcher.js +97 -0
- package/dist/skills/utils/pattern-matcher.js.map +1 -0
- package/dist/utils/auth.d.ts +22 -0
- package/dist/utils/auth.d.ts.map +1 -0
- package/dist/utils/auth.js +50 -0
- package/dist/utils/auth.js.map +1 -0
- package/dist/utils/cli-updater.d.ts +70 -0
- package/dist/utils/cli-updater.d.ts.map +1 -0
- package/dist/utils/cli-updater.js +339 -0
- package/dist/utils/cli-updater.js.map +1 -0
- package/dist/utils/config.d.ts +6 -1
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +13 -0
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/installation-detector.d.ts +22 -0
- package/dist/utils/installation-detector.d.ts.map +1 -0
- package/dist/utils/installation-detector.js +49 -0
- package/dist/utils/installation-detector.js.map +1 -0
- package/dist/utils/native-installer.d.ts +49 -0
- package/dist/utils/native-installer.d.ts.map +1 -0
- package/dist/utils/native-installer.js +225 -0
- package/dist/utils/native-installer.js.map +1 -0
- package/dist/utils/processes.js +1 -1
- package/dist/utils/profile.d.ts +2 -0
- package/dist/utils/profile.d.ts.map +1 -1
- package/dist/utils/profile.js +5 -0
- package/dist/utils/profile.js.map +1 -1
- package/dist/utils/sdk-client.d.ts +15 -0
- package/dist/utils/sdk-client.d.ts.map +1 -0
- package/dist/utils/sdk-client.js +92 -0
- package/dist/utils/sdk-client.js.map +1 -0
- package/dist/utils/version-utils.d.ts +50 -0
- package/dist/utils/version-utils.d.ts.map +1 -0
- package/dist/utils/version-utils.js +92 -0
- package/dist/utils/version-utils.js.map +1 -0
- package/package.json +11 -3
- package/scripts/copy-mr-skill-to-global.ts +252 -0
- package/scripts/demo-hooks.sh +125 -0
- package/scripts/test-hooks.sh +196 -0
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/INDEX.md +0 -205
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/TEMPLATE_SIZES.md +0 -74
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/architecture/layered-architecture.md.template +0 -143
- package/dist/agents/plugins/claude/plugin/claude-templates/templates/guides/architecture/project-structure.md.template +0 -127
- package/dist/agents/plugins/claude/plugin/commands/codemie-pr.md +0 -25
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Copy /mr skill from project scope to global scope
|
|
5
|
+
*
|
|
6
|
+
* This script copies the project-level /mr skill to ~/.claude/skills/mr/
|
|
7
|
+
* making it available globally across all projects.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* npm run build && node dist/scripts/copy-mr-skill-to-global.js
|
|
11
|
+
* OR
|
|
12
|
+
* npx tsx scripts/copy-mr-skill-to-global.ts
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import * as fs from 'fs/promises';
|
|
16
|
+
import * as path from 'path';
|
|
17
|
+
import { parseFrontmatter } from '../src/skills/utils/frontmatter.js';
|
|
18
|
+
import { SkillMetadataSchema } from '../src/skills/core/types.js';
|
|
19
|
+
import { resolveHomeDir } from '../src/utils/paths.js';
|
|
20
|
+
import { SkillManager } from '../src/skills/index.js';
|
|
21
|
+
import * as readline from 'readline';
|
|
22
|
+
|
|
23
|
+
interface CopyResult {
|
|
24
|
+
success: boolean;
|
|
25
|
+
message: string;
|
|
26
|
+
copiedFiles?: string[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Validate source skill exists and has valid frontmatter
|
|
31
|
+
*/
|
|
32
|
+
async function validateSourceSkill(sourceDir: string): Promise<void> {
|
|
33
|
+
const skillPath = path.join(sourceDir, 'SKILL.md');
|
|
34
|
+
|
|
35
|
+
// Check file exists
|
|
36
|
+
try {
|
|
37
|
+
await fs.access(skillPath, fs.constants.R_OK);
|
|
38
|
+
} catch {
|
|
39
|
+
throw new Error(`Source skill not found: ${skillPath}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Validate frontmatter
|
|
43
|
+
const content = await fs.readFile(skillPath, 'utf-8');
|
|
44
|
+
const { metadata } = parseFrontmatter(content, skillPath);
|
|
45
|
+
const validated = SkillMetadataSchema.parse(metadata);
|
|
46
|
+
|
|
47
|
+
console.log(`โ Source skill validated: ${validated.name}`);
|
|
48
|
+
console.log(` Description: ${validated.description}`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Check if target already exists and prompt user for overwrite
|
|
53
|
+
*/
|
|
54
|
+
async function checkTargetConflict(targetDir: string): Promise<void> {
|
|
55
|
+
const targetSkillPath = path.join(targetDir, 'SKILL.md');
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
await fs.access(targetSkillPath, fs.constants.F_OK);
|
|
59
|
+
|
|
60
|
+
// File exists - prompt user
|
|
61
|
+
const rl = readline.createInterface({
|
|
62
|
+
input: process.stdin,
|
|
63
|
+
output: process.stdout
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const answer = await new Promise<string>((resolve) => {
|
|
67
|
+
rl.question(
|
|
68
|
+
`\nโ ๏ธ Global /mr skill already exists. Overwrite? (y/N): `,
|
|
69
|
+
resolve
|
|
70
|
+
);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
rl.close();
|
|
74
|
+
|
|
75
|
+
if (answer.toLowerCase() !== 'y') {
|
|
76
|
+
console.log('โ Operation cancelled by user');
|
|
77
|
+
process.exit(0);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Create backup before overwriting
|
|
81
|
+
const backupDir = `${targetDir}.backup-${Date.now()}`;
|
|
82
|
+
await fs.rename(targetDir, backupDir);
|
|
83
|
+
console.log(`โ Backup created: ${backupDir}`);
|
|
84
|
+
} catch {
|
|
85
|
+
// File doesn't exist - proceed
|
|
86
|
+
console.log('โ No conflict detected');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Create necessary directories for the skill
|
|
92
|
+
*/
|
|
93
|
+
async function prepareDirectories(targetDir: string): Promise<void> {
|
|
94
|
+
// Create main directory
|
|
95
|
+
await fs.mkdir(targetDir, { recursive: true });
|
|
96
|
+
|
|
97
|
+
// Create references subdirectory
|
|
98
|
+
const refsDir = path.join(targetDir, 'references');
|
|
99
|
+
await fs.mkdir(refsDir, { recursive: true });
|
|
100
|
+
|
|
101
|
+
console.log(`โ Directories created: ${targetDir}`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Copy all skill files from source to target
|
|
106
|
+
*/
|
|
107
|
+
async function copySkillFiles(
|
|
108
|
+
sourceDir: string,
|
|
109
|
+
targetDir: string
|
|
110
|
+
): Promise<string[]> {
|
|
111
|
+
const filesToCopy = [
|
|
112
|
+
{ source: 'SKILL.md', target: 'SKILL.md' },
|
|
113
|
+
{ source: 'references/branch-naming.md', target: 'references/branch-naming.md' },
|
|
114
|
+
{ source: 'references/examples.md', target: 'references/examples.md' },
|
|
115
|
+
];
|
|
116
|
+
|
|
117
|
+
const copiedFiles: string[] = [];
|
|
118
|
+
|
|
119
|
+
for (const { source, target } of filesToCopy) {
|
|
120
|
+
const sourcePath = path.join(sourceDir, source);
|
|
121
|
+
const targetPath = path.join(targetDir, target);
|
|
122
|
+
|
|
123
|
+
// Ensure subdirectory exists
|
|
124
|
+
const targetSubdir = path.dirname(targetPath);
|
|
125
|
+
await fs.mkdir(targetSubdir, { recursive: true });
|
|
126
|
+
|
|
127
|
+
// Copy file
|
|
128
|
+
await fs.copyFile(sourcePath, targetPath);
|
|
129
|
+
copiedFiles.push(source);
|
|
130
|
+
|
|
131
|
+
console.log(`โ Copied: ${source}`);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return copiedFiles;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Validate the copied skill has valid frontmatter
|
|
139
|
+
*/
|
|
140
|
+
async function validateCopiedSkill(skillPath: string): Promise<void> {
|
|
141
|
+
// Verify file exists
|
|
142
|
+
await fs.access(skillPath, fs.constants.R_OK);
|
|
143
|
+
|
|
144
|
+
// Validate frontmatter
|
|
145
|
+
const content = await fs.readFile(skillPath, 'utf-8');
|
|
146
|
+
const { metadata } = parseFrontmatter(content, skillPath);
|
|
147
|
+
SkillMetadataSchema.parse(metadata);
|
|
148
|
+
|
|
149
|
+
console.log(`โ Copied skill validated successfully`);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Test that the skill is discoverable by SkillManager
|
|
154
|
+
*/
|
|
155
|
+
async function testDiscovery(): Promise<void> {
|
|
156
|
+
const manager = SkillManager.getInstance();
|
|
157
|
+
manager.reload(); // Clear cache
|
|
158
|
+
|
|
159
|
+
const skills = await manager.listSkills({
|
|
160
|
+
cwd: process.cwd(),
|
|
161
|
+
forceReload: true,
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
const mrSkills = skills.filter(s => s.metadata.name === 'mr');
|
|
165
|
+
|
|
166
|
+
if (mrSkills.length > 0) {
|
|
167
|
+
console.log(`โ Skill discoverable (${mrSkills.length} instance(s) found)`);
|
|
168
|
+
mrSkills.forEach(skill => {
|
|
169
|
+
console.log(` Source: ${skill.source}`);
|
|
170
|
+
console.log(` Priority: ${skill.computedPriority}`);
|
|
171
|
+
console.log(` Path: ${skill.filePath}`);
|
|
172
|
+
});
|
|
173
|
+
} else {
|
|
174
|
+
console.warn('โ ๏ธ Skill not immediately discoverable (may need agent restart)');
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Print success message with next steps
|
|
180
|
+
*/
|
|
181
|
+
function printSuccess(targetDir: string, files: string[]): void {
|
|
182
|
+
console.log('\n' + '='.repeat(60));
|
|
183
|
+
console.log('โ
Successfully copied /mr skill to global scope!');
|
|
184
|
+
console.log('='.repeat(60));
|
|
185
|
+
console.log(`\n๐ Location: ${targetDir}`);
|
|
186
|
+
console.log(`๐ Files copied: ${files.length}`);
|
|
187
|
+
console.log(`\n๐ Next steps:`);
|
|
188
|
+
console.log(`1. The skill is now available globally across all projects`);
|
|
189
|
+
console.log(`2. Use /mr in any project to create pull requests`);
|
|
190
|
+
console.log(`3. Run "codemie skill list" to verify it's loaded`);
|
|
191
|
+
console.log(`4. Run "codemie skill reload" to refresh if needed`);
|
|
192
|
+
console.log(`\n๐ก Tip: Project-level skills (if present) take priority over global skills.\n`);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Print error message with troubleshooting tips
|
|
197
|
+
*/
|
|
198
|
+
function printError(error: unknown): void {
|
|
199
|
+
console.error('\n' + '='.repeat(60));
|
|
200
|
+
console.error('โ Failed to copy /mr skill');
|
|
201
|
+
console.error('='.repeat(60));
|
|
202
|
+
console.error(`\nError: ${error instanceof Error ? error.message : String(error)}`);
|
|
203
|
+
if (error instanceof Error && error.stack) {
|
|
204
|
+
console.error(`\nStack trace:\n${error.stack}`);
|
|
205
|
+
}
|
|
206
|
+
console.error(`\n๐ Troubleshooting:`);
|
|
207
|
+
console.error(`- Check source exists: .codemie/skills/mr/SKILL.md`);
|
|
208
|
+
console.error(`- Check permissions: ~/.claude/skills/`);
|
|
209
|
+
console.error(`- Check disk space: df -h ~`);
|
|
210
|
+
console.error(`- Validate frontmatter: codemie skill validate\n`);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Main execution function
|
|
215
|
+
*/
|
|
216
|
+
async function main(): Promise<void> {
|
|
217
|
+
try {
|
|
218
|
+
console.log('\n๐ Starting /mr skill copy to global scope...\n');
|
|
219
|
+
|
|
220
|
+
// Phase 1: Validate source
|
|
221
|
+
console.log('Phase 1: Validating source skill...');
|
|
222
|
+
const sourceDir = path.join(process.cwd(), '.codemie', 'skills', 'mr');
|
|
223
|
+
await validateSourceSkill(sourceDir);
|
|
224
|
+
|
|
225
|
+
// Phase 2: Check target
|
|
226
|
+
console.log('\nPhase 2: Checking target location...');
|
|
227
|
+
const targetDir = resolveHomeDir('.claude/skills/mr');
|
|
228
|
+
await checkTargetConflict(targetDir);
|
|
229
|
+
|
|
230
|
+
// Phase 3: Prepare directories
|
|
231
|
+
console.log('\nPhase 3: Preparing directories...');
|
|
232
|
+
await prepareDirectories(targetDir);
|
|
233
|
+
|
|
234
|
+
// Phase 4: Copy files
|
|
235
|
+
console.log('\nPhase 4: Copying skill files...');
|
|
236
|
+
const files = await copySkillFiles(sourceDir, targetDir);
|
|
237
|
+
|
|
238
|
+
// Phase 5: Validate
|
|
239
|
+
console.log('\nPhase 5: Validating copied skill...');
|
|
240
|
+
await validateCopiedSkill(path.join(targetDir, 'SKILL.md'));
|
|
241
|
+
await testDiscovery();
|
|
242
|
+
|
|
243
|
+
// Phase 6: Success feedback
|
|
244
|
+
printSuccess(targetDir, files);
|
|
245
|
+
} catch (error) {
|
|
246
|
+
printError(error);
|
|
247
|
+
process.exit(1);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Run main function
|
|
252
|
+
main();
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Demo script for testing hooks in codemie-code
|
|
3
|
+
|
|
4
|
+
set -e
|
|
5
|
+
|
|
6
|
+
GREEN='\033[0;32m'
|
|
7
|
+
BLUE='\033[0;34m'
|
|
8
|
+
YELLOW='\033[1;33m'
|
|
9
|
+
RED='\033[0;31m'
|
|
10
|
+
NC='\033[0m'
|
|
11
|
+
|
|
12
|
+
echo -e "${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
|
|
13
|
+
echo -e "${BLUE} CodeMie Hooks Demo${NC}"
|
|
14
|
+
echo -e "${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
|
|
15
|
+
echo ""
|
|
16
|
+
|
|
17
|
+
# Check if config exists
|
|
18
|
+
if [ ! -f ~/.codemie/codemie-cli.config.json ]; then
|
|
19
|
+
echo -e "${RED}โ Configuration file not found${NC}"
|
|
20
|
+
exit 1
|
|
21
|
+
fi
|
|
22
|
+
|
|
23
|
+
# Show configured hooks
|
|
24
|
+
echo -e "${GREEN}โ Configuration loaded${NC}"
|
|
25
|
+
echo ""
|
|
26
|
+
echo "Configured Hooks:"
|
|
27
|
+
echo "โโโโโโโโโโโโโโโโ"
|
|
28
|
+
|
|
29
|
+
# PreToolUse
|
|
30
|
+
echo -e "${YELLOW}PreToolUse:${NC}"
|
|
31
|
+
echo " โข Matcher: Bash"
|
|
32
|
+
echo " โข Action: Block 'rm -rf' commands"
|
|
33
|
+
echo " โข Script: ~/.codemie/test-hooks/pre-tool-hook.sh"
|
|
34
|
+
|
|
35
|
+
echo ""
|
|
36
|
+
echo -e "${YELLOW}PostToolUse:${NC}"
|
|
37
|
+
echo " โข Matcher: * (all tools)"
|
|
38
|
+
echo " โข Action: Log all tool usage"
|
|
39
|
+
echo " โข Script: ~/.codemie/test-hooks/post-tool-hook.sh"
|
|
40
|
+
|
|
41
|
+
echo ""
|
|
42
|
+
echo -e "${YELLOW}UserPromptSubmit:${NC}"
|
|
43
|
+
echo " โข Action: Add context to prompts"
|
|
44
|
+
echo " โข Script: ~/.codemie/test-hooks/prompt-hook.sh"
|
|
45
|
+
|
|
46
|
+
echo ""
|
|
47
|
+
echo -e "${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
|
|
48
|
+
echo ""
|
|
49
|
+
|
|
50
|
+
# Clear logs for clean test
|
|
51
|
+
rm -f ~/.codemie/hook-test.log
|
|
52
|
+
rm -f ~/.codemie/tool-usage.log
|
|
53
|
+
echo -e "${GREEN}โ Logs cleared for clean test${NC}"
|
|
54
|
+
echo ""
|
|
55
|
+
|
|
56
|
+
# Show test scenarios
|
|
57
|
+
echo -e "${BLUE}Test Scenarios:${NC}"
|
|
58
|
+
echo "โโโโโโโโโโโโโโโโ"
|
|
59
|
+
echo ""
|
|
60
|
+
|
|
61
|
+
echo -e "${YELLOW}Scenario 1: PreToolUse Hook Blocks Dangerous Command${NC}"
|
|
62
|
+
echo " Try: \"run the command: rm -rf /tmp/test\""
|
|
63
|
+
echo " Expected: Hook blocks it with error"
|
|
64
|
+
echo ""
|
|
65
|
+
|
|
66
|
+
echo -e "${YELLOW}Scenario 2: PreToolUse Hook Allows Safe Command${NC}"
|
|
67
|
+
echo " Try: \"run the command: echo 'Hello World'\""
|
|
68
|
+
echo " Expected: Command executes normally"
|
|
69
|
+
echo ""
|
|
70
|
+
|
|
71
|
+
echo -e "${YELLOW}Scenario 3: PostToolUse Hook Logs Tools${NC}"
|
|
72
|
+
echo " Try: \"read package.json and show me the name\""
|
|
73
|
+
echo " Expected: Tool usage logged to ~/.codemie/tool-usage.log"
|
|
74
|
+
echo ""
|
|
75
|
+
|
|
76
|
+
echo -e "${YELLOW}Scenario 4: UserPromptSubmit Hook Adds Context${NC}"
|
|
77
|
+
echo " Try any prompt and check if context is added"
|
|
78
|
+
echo " Expected: Agent has context about working directory"
|
|
79
|
+
echo ""
|
|
80
|
+
|
|
81
|
+
echo -e "${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
|
|
82
|
+
echo ""
|
|
83
|
+
|
|
84
|
+
echo -e "${GREEN}Monitoring:${NC}"
|
|
85
|
+
echo " Watch hooks in real-time:"
|
|
86
|
+
echo " ${BLUE}tail -f ~/.codemie/logs/debug-\$(date +%Y-%m-%d).log | grep -i hook${NC}"
|
|
87
|
+
echo ""
|
|
88
|
+
echo " Check hook logs after test:"
|
|
89
|
+
echo " ${BLUE}cat ~/.codemie/hook-test.log${NC}"
|
|
90
|
+
echo " ${BLUE}cat ~/.codemie/tool-usage.log${NC}"
|
|
91
|
+
echo ""
|
|
92
|
+
|
|
93
|
+
echo -e "${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
|
|
94
|
+
echo ""
|
|
95
|
+
|
|
96
|
+
# Ask if user wants to set API key
|
|
97
|
+
echo -e "${YELLOW}โ Important: You need a valid API key to run codemie-code${NC}"
|
|
98
|
+
echo ""
|
|
99
|
+
echo "Options:"
|
|
100
|
+
echo " 1. Set CODEMIE_API_KEY environment variable"
|
|
101
|
+
echo " 2. Update ~/.codemie/codemie-cli.config.json with your key"
|
|
102
|
+
echo " 3. Run: codemie setup"
|
|
103
|
+
echo ""
|
|
104
|
+
|
|
105
|
+
read -p "Do you have an API key configured? (y/n) " -n 1 -r
|
|
106
|
+
echo
|
|
107
|
+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
|
108
|
+
echo ""
|
|
109
|
+
echo -e "${YELLOW}Please configure your API key first:${NC}"
|
|
110
|
+
echo " export CODEMIE_API_KEY='your-key-here'"
|
|
111
|
+
echo ""
|
|
112
|
+
echo "Then run:"
|
|
113
|
+
echo " ${BLUE}codemie-code${NC}"
|
|
114
|
+
echo ""
|
|
115
|
+
exit 0
|
|
116
|
+
fi
|
|
117
|
+
|
|
118
|
+
echo ""
|
|
119
|
+
echo -e "${GREEN}Starting codemie-code with hooks enabled...${NC}"
|
|
120
|
+
echo ""
|
|
121
|
+
echo -e "${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
|
|
122
|
+
echo ""
|
|
123
|
+
|
|
124
|
+
# Start codemie-code
|
|
125
|
+
codemie-code
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Quick Hooks System Test Script
|
|
3
|
+
# Tests the hooks implementation with example scenarios
|
|
4
|
+
|
|
5
|
+
set -e
|
|
6
|
+
|
|
7
|
+
HOOKS_DIR="$HOME/.codemie/test-hooks"
|
|
8
|
+
LOG_FILE="$HOME/.codemie/hook-test.log"
|
|
9
|
+
TEST_CONFIG="$HOME/.codemie/test-hooks-config.json"
|
|
10
|
+
|
|
11
|
+
echo "๐งช CodeMie Hooks System Test"
|
|
12
|
+
echo "=============================="
|
|
13
|
+
echo ""
|
|
14
|
+
|
|
15
|
+
# Colors for output
|
|
16
|
+
GREEN='\033[0;32m'
|
|
17
|
+
RED='\033[0;31m'
|
|
18
|
+
YELLOW='\033[1;33m'
|
|
19
|
+
NC='\033[0m' # No Color
|
|
20
|
+
|
|
21
|
+
# Check if jq is installed
|
|
22
|
+
if ! command -v jq &> /dev/null; then
|
|
23
|
+
echo -e "${RED}โ Error: jq is required but not installed${NC}"
|
|
24
|
+
echo "Install with: brew install jq (macOS) or apt-get install jq (Linux)"
|
|
25
|
+
exit 1
|
|
26
|
+
fi
|
|
27
|
+
|
|
28
|
+
# Create test hooks directory
|
|
29
|
+
echo "๐ Setting up test environment..."
|
|
30
|
+
mkdir -p "$HOOKS_DIR"
|
|
31
|
+
|
|
32
|
+
# Create PreToolUse hook (blocks rm -rf)
|
|
33
|
+
cat > "$HOOKS_DIR/pre-tool-hook.sh" << 'EOF'
|
|
34
|
+
#!/bin/bash
|
|
35
|
+
TOOL_NAME=$(echo "$CODEMIE_HOOK_INPUT" | jq -r '.tool_name')
|
|
36
|
+
echo "[PreToolUse] Tool: $TOOL_NAME" >> ~/.codemie/hook-test.log
|
|
37
|
+
|
|
38
|
+
if [[ "$TOOL_NAME" == "Bash" ]]; then
|
|
39
|
+
COMMAND=$(echo "$CODEMIE_HOOK_INPUT" | jq -r '.tool_input.command')
|
|
40
|
+
if [[ "$COMMAND" =~ "rm -rf" ]]; then
|
|
41
|
+
echo '{"decision": "block", "reason": "Dangerous command blocked: rm -rf"}'
|
|
42
|
+
exit 0
|
|
43
|
+
fi
|
|
44
|
+
fi
|
|
45
|
+
|
|
46
|
+
echo '{"decision": "allow"}'
|
|
47
|
+
exit 0
|
|
48
|
+
EOF
|
|
49
|
+
|
|
50
|
+
# Create PostToolUse hook (logs all usage)
|
|
51
|
+
cat > "$HOOKS_DIR/post-tool-hook.sh" << 'EOF'
|
|
52
|
+
#!/bin/bash
|
|
53
|
+
TOOL_NAME=$(echo "$CODEMIE_HOOK_INPUT" | jq -r '.tool_name')
|
|
54
|
+
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
|
|
55
|
+
echo "[$TIMESTAMP] Tool: $TOOL_NAME" >> ~/.codemie/tool-usage.log
|
|
56
|
+
echo '{"decision": "allow"}'
|
|
57
|
+
exit 0
|
|
58
|
+
EOF
|
|
59
|
+
|
|
60
|
+
# Create UserPromptSubmit hook (adds context)
|
|
61
|
+
cat > "$HOOKS_DIR/prompt-hook.sh" << 'EOF'
|
|
62
|
+
#!/bin/bash
|
|
63
|
+
echo "{
|
|
64
|
+
\"decision\": \"allow\",
|
|
65
|
+
\"additionalContext\": \"Test context: Working in $(pwd)\"
|
|
66
|
+
}"
|
|
67
|
+
exit 0
|
|
68
|
+
EOF
|
|
69
|
+
|
|
70
|
+
# Make scripts executable
|
|
71
|
+
chmod +x "$HOOKS_DIR"/*.sh
|
|
72
|
+
|
|
73
|
+
echo -e "${GREEN}โ Test hooks created${NC}"
|
|
74
|
+
echo ""
|
|
75
|
+
|
|
76
|
+
# Run tests
|
|
77
|
+
echo "๐งช Running Hook Tests..."
|
|
78
|
+
echo "----------------------"
|
|
79
|
+
|
|
80
|
+
# Clear logs
|
|
81
|
+
rm -f "$LOG_FILE" "$HOME/.codemie/tool-usage.log"
|
|
82
|
+
|
|
83
|
+
# Test 1: PreToolUse allows safe commands
|
|
84
|
+
echo -n "Test 1: PreToolUse allows safe commands... "
|
|
85
|
+
export CODEMIE_HOOK_INPUT='{"hook_event_name":"PreToolUse","tool_name":"Bash","tool_input":{"command":"ls -la"},"session_id":"test","cwd":"'$(pwd)'"}'
|
|
86
|
+
RESULT=$("$HOOKS_DIR/pre-tool-hook.sh")
|
|
87
|
+
EXIT_CODE=$?
|
|
88
|
+
|
|
89
|
+
if [[ $EXIT_CODE -eq 0 ]] && echo "$RESULT" | jq -e '.decision == "allow"' > /dev/null 2>&1; then
|
|
90
|
+
echo -e "${GREEN}โ PASS${NC}"
|
|
91
|
+
else
|
|
92
|
+
echo -e "${RED}โ FAIL${NC}"
|
|
93
|
+
echo " Expected: allow, Got: $RESULT"
|
|
94
|
+
fi
|
|
95
|
+
|
|
96
|
+
# Test 2: PreToolUse blocks dangerous commands
|
|
97
|
+
echo -n "Test 2: PreToolUse blocks dangerous commands... "
|
|
98
|
+
export CODEMIE_HOOK_INPUT='{"hook_event_name":"PreToolUse","tool_name":"Bash","tool_input":{"command":"rm -rf /test"},"session_id":"test","cwd":"'$(pwd)'"}'
|
|
99
|
+
RESULT=$("$HOOKS_DIR/pre-tool-hook.sh")
|
|
100
|
+
EXIT_CODE=$?
|
|
101
|
+
|
|
102
|
+
if [[ $EXIT_CODE -eq 0 ]] && echo "$RESULT" | jq -e '.decision == "block"' > /dev/null 2>&1; then
|
|
103
|
+
echo -e "${GREEN}โ PASS${NC}"
|
|
104
|
+
else
|
|
105
|
+
echo -e "${RED}โ FAIL${NC}"
|
|
106
|
+
echo " Expected: block, Got: $RESULT"
|
|
107
|
+
fi
|
|
108
|
+
|
|
109
|
+
# Test 3: PreToolUse blocks specific tool
|
|
110
|
+
echo -n "Test 3: PreToolUse logs to file... "
|
|
111
|
+
if [ -f "$LOG_FILE" ] && grep -q "PreToolUse" "$LOG_FILE"; then
|
|
112
|
+
echo -e "${GREEN}โ PASS${NC}"
|
|
113
|
+
else
|
|
114
|
+
echo -e "${RED}โ FAIL${NC}"
|
|
115
|
+
echo " Expected log file with PreToolUse entries"
|
|
116
|
+
fi
|
|
117
|
+
|
|
118
|
+
# Test 4: PostToolUse creates logs
|
|
119
|
+
echo -n "Test 4: PostToolUse creates usage logs... "
|
|
120
|
+
export CODEMIE_HOOK_INPUT='{"hook_event_name":"PostToolUse","tool_name":"Read","session_id":"test","cwd":"'$(pwd)'"}'
|
|
121
|
+
RESULT=$("$HOOKS_DIR/post-tool-hook.sh")
|
|
122
|
+
|
|
123
|
+
if [ -f "$HOME/.codemie/tool-usage.log" ] && grep -q "Tool: Read" "$HOME/.codemie/tool-usage.log"; then
|
|
124
|
+
echo -e "${GREEN}โ PASS${NC}"
|
|
125
|
+
else
|
|
126
|
+
echo -e "${RED}โ FAIL${NC}"
|
|
127
|
+
echo " Expected usage log with Read entry"
|
|
128
|
+
fi
|
|
129
|
+
|
|
130
|
+
# Test 5: UserPromptSubmit adds context
|
|
131
|
+
echo -n "Test 5: UserPromptSubmit adds context... "
|
|
132
|
+
export CODEMIE_HOOK_INPUT='{"hook_event_name":"UserPromptSubmit","prompt":"test prompt","session_id":"test","cwd":"'$(pwd)'"}'
|
|
133
|
+
RESULT=$("$HOOKS_DIR/prompt-hook.sh")
|
|
134
|
+
|
|
135
|
+
if echo "$RESULT" | jq -e '.additionalContext != null' > /dev/null 2>&1; then
|
|
136
|
+
echo -e "${GREEN}โ PASS${NC}"
|
|
137
|
+
else
|
|
138
|
+
echo -e "${RED}โ FAIL${NC}"
|
|
139
|
+
echo " Expected additionalContext in result"
|
|
140
|
+
fi
|
|
141
|
+
|
|
142
|
+
# Test 6: Hook JSON output is valid
|
|
143
|
+
echo -n "Test 6: Hook output is valid JSON... "
|
|
144
|
+
export CODEMIE_HOOK_INPUT='{"hook_event_name":"PreToolUse","tool_name":"Test","session_id":"test","cwd":"'$(pwd)'"}'
|
|
145
|
+
RESULT=$("$HOOKS_DIR/pre-tool-hook.sh")
|
|
146
|
+
|
|
147
|
+
if echo "$RESULT" | jq '.' > /dev/null 2>&1; then
|
|
148
|
+
echo -e "${GREEN}โ PASS${NC}"
|
|
149
|
+
else
|
|
150
|
+
echo -e "${RED}โ FAIL${NC}"
|
|
151
|
+
echo " Hook output is not valid JSON: $RESULT"
|
|
152
|
+
fi
|
|
153
|
+
|
|
154
|
+
# Test 7: Hook execution time
|
|
155
|
+
echo -n "Test 7: Hook performance (< 100ms)... "
|
|
156
|
+
export CODEMIE_HOOK_INPUT='{"hook_event_name":"PreToolUse","tool_name":"Test","session_id":"test","cwd":"'$(pwd)'"}'
|
|
157
|
+
START=$(date +%s%N)
|
|
158
|
+
"$HOOKS_DIR/pre-tool-hook.sh" > /dev/null
|
|
159
|
+
END=$(date +%s%N)
|
|
160
|
+
DURATION=$(( ($END - $START) / 1000000 )) # Convert to milliseconds
|
|
161
|
+
|
|
162
|
+
if [ $DURATION -lt 100 ]; then
|
|
163
|
+
echo -e "${GREEN}โ PASS${NC} (${DURATION}ms)"
|
|
164
|
+
else
|
|
165
|
+
echo -e "${YELLOW}โ SLOW${NC} (${DURATION}ms)"
|
|
166
|
+
fi
|
|
167
|
+
|
|
168
|
+
echo ""
|
|
169
|
+
echo "๐ Test Summary"
|
|
170
|
+
echo "----------------------"
|
|
171
|
+
echo "Test hooks created at: $HOOKS_DIR"
|
|
172
|
+
echo "Logs created at:"
|
|
173
|
+
echo " - $LOG_FILE"
|
|
174
|
+
echo " - $HOME/.codemie/tool-usage.log"
|
|
175
|
+
echo ""
|
|
176
|
+
echo -e "${YELLOW}Next Steps:${NC}"
|
|
177
|
+
echo "1. Review test hooks: ls -la $HOOKS_DIR"
|
|
178
|
+
echo "2. Check logs: cat $LOG_FILE"
|
|
179
|
+
echo "3. View full testing guide: docs/HOOKS_TESTING.md"
|
|
180
|
+
echo "4. Configure hooks in your profile: ~/.codemie/codemie-cli.config.json"
|
|
181
|
+
echo ""
|
|
182
|
+
echo "Example configuration:"
|
|
183
|
+
echo ' "hooks": {'
|
|
184
|
+
echo ' "PreToolUse": ['
|
|
185
|
+
echo ' {'
|
|
186
|
+
echo ' "matcher": "Bash",'
|
|
187
|
+
echo ' "hooks": [{'
|
|
188
|
+
echo ' "type": "command",'
|
|
189
|
+
echo " \"command\": \"$HOOKS_DIR/pre-tool-hook.sh\","
|
|
190
|
+
echo ' "timeout": 5000'
|
|
191
|
+
echo ' }]'
|
|
192
|
+
echo ' }'
|
|
193
|
+
echo ' ]'
|
|
194
|
+
echo ' }'
|
|
195
|
+
echo ""
|
|
196
|
+
echo -e "${GREEN}โ All basic tests passed!${NC}"
|