@reliverse/rempts-plugin-ai-detect 2.3.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/README.md +128 -0
- package/dist/mod.d.ts +30 -0
- package/dist/mod.js +71 -0
- package/package.json +35 -0
- package/src/mod.ts +136 -0
package/README.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# rempts-plugin-ai-detect
|
|
2
|
+
|
|
3
|
+
AI agent detection plugin for Rempts CLI framework. Detects when your CLI is running inside AI coding assistants like Claude, Cursor, GitHub Copilot, and more.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add rempts-plugin-ai-detect
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { createCLI } from '@reliverse/rempts-core'
|
|
15
|
+
import { aiAgentPlugin } from '@reliverse/rempts-plugin-ai-detect'
|
|
16
|
+
|
|
17
|
+
const cli = await createCLI({
|
|
18
|
+
name: 'my-cli',
|
|
19
|
+
version: '1.0.0',
|
|
20
|
+
plugins: [
|
|
21
|
+
aiAgentPlugin({
|
|
22
|
+
verbose: true // Log when AI agents are detected
|
|
23
|
+
})
|
|
24
|
+
]
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
// In your commands, you can access the detection results
|
|
28
|
+
cli.command({
|
|
29
|
+
name: 'info',
|
|
30
|
+
handler: async ({ context }) => {
|
|
31
|
+
if (context?.store.isAIAgent) {
|
|
32
|
+
console.log('Running in AI agent:', context.store.aiAgents.join(', '))
|
|
33
|
+
console.log('Detected env vars:', context.store.aiAgentEnvVars.join(', '))
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Options
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
interface AIDetectPluginOptions {
|
|
43
|
+
/**
|
|
44
|
+
* Additional custom AI agents to detect
|
|
45
|
+
*/
|
|
46
|
+
customAgents?: AIAgentInfo[]
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Whether to log detection results
|
|
50
|
+
* Default: false
|
|
51
|
+
*/
|
|
52
|
+
verbose?: boolean
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface AIAgentInfo {
|
|
56
|
+
name: string
|
|
57
|
+
envVars: string[]
|
|
58
|
+
detect: (env: NodeJS.ProcessEnv) => boolean
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Built-in Detections
|
|
63
|
+
|
|
64
|
+
The plugin detects the following AI agents out of the box:
|
|
65
|
+
|
|
66
|
+
- **Claude**: Detects Claude Code via `CLAUDECODE` environment variable
|
|
67
|
+
- **Cursor**: Detects Cursor via `CURSOR_AGENT` environment variable
|
|
68
|
+
|
|
69
|
+
## Custom Agents
|
|
70
|
+
|
|
71
|
+
You can add detection for additional AI agents:
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
aiAgentPlugin({
|
|
75
|
+
customAgents: [
|
|
76
|
+
{
|
|
77
|
+
name: 'github-copilot',
|
|
78
|
+
envVars: ['GITHUB_COPILOT_ENABLED'],
|
|
79
|
+
detect: (env) => !!env.GITHUB_COPILOT_ENABLED
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: 'my-custom-ai',
|
|
83
|
+
envVars: ['MY_AI_ACTIVE', 'MY_AI_VERSION'],
|
|
84
|
+
detect: (env) => env.MY_AI_ACTIVE === 'true'
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
})
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Store Properties
|
|
91
|
+
|
|
92
|
+
The plugin provides the following typed properties in the command context store:
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
interface AIDetectStore {
|
|
96
|
+
/** Whether any AI agent was detected */
|
|
97
|
+
isAIAgent: boolean
|
|
98
|
+
|
|
99
|
+
/** List of detected AI agent names */
|
|
100
|
+
aiAgents: string[]
|
|
101
|
+
|
|
102
|
+
/** Environment variables that triggered detection */
|
|
103
|
+
aiAgentEnvVars: string[]
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Environment Extensions
|
|
108
|
+
|
|
109
|
+
The plugin also extends the environment info:
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
// These properties are added to context.env
|
|
113
|
+
interface EnvironmentInfo {
|
|
114
|
+
isAIAgent: boolean
|
|
115
|
+
aiAgents: string[]
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Use Cases
|
|
120
|
+
|
|
121
|
+
- **Telemetry**: Track which AI assistants are using your CLI
|
|
122
|
+
- **Feature Flags**: Enable special features for AI environments
|
|
123
|
+
- **Debugging**: Add extra logging when running in AI assistants
|
|
124
|
+
- **Optimization**: Adjust output formatting for AI consumption
|
|
125
|
+
|
|
126
|
+
## License
|
|
127
|
+
|
|
128
|
+
MIT © blefnk
|
package/dist/mod.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI agent detection plugin for Rempts
|
|
3
|
+
* Detects various AI coding assistants from environment variables
|
|
4
|
+
*/
|
|
5
|
+
interface AIAgentInfo {
|
|
6
|
+
name: string;
|
|
7
|
+
envVars: string[];
|
|
8
|
+
detect: (env: NodeJS.ProcessEnv) => boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface AIDetectPluginOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Additional custom AI agents to detect
|
|
13
|
+
*/
|
|
14
|
+
customAgents?: AIAgentInfo[];
|
|
15
|
+
/**
|
|
16
|
+
* Whether to log detection results
|
|
17
|
+
* Default: false
|
|
18
|
+
*/
|
|
19
|
+
verbose?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface AIDetectStore {
|
|
22
|
+
isAIAgent: boolean;
|
|
23
|
+
aiAgents: string[];
|
|
24
|
+
aiAgentEnvVars: string[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* AI agent detection plugin factory
|
|
28
|
+
*/
|
|
29
|
+
export declare const aiAgentPlugin: any;
|
|
30
|
+
export default aiAgentPlugin;
|
package/dist/mod.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { createPlugin, createPluginStore } from "@reliverse/rempts-core/plugin";
|
|
2
|
+
const AI_AGENTS = [
|
|
3
|
+
{
|
|
4
|
+
name: "claude",
|
|
5
|
+
envVars: ["CLAUDECODE"],
|
|
6
|
+
detect: (env) => !!env.CLAUDECODE
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
name: "cursor",
|
|
10
|
+
envVars: ["CURSOR_AGENT"],
|
|
11
|
+
detect: (env) => !!env.CURSOR_AGENT
|
|
12
|
+
}
|
|
13
|
+
];
|
|
14
|
+
export const aiAgentPlugin = createPlugin(
|
|
15
|
+
(options = {}) => {
|
|
16
|
+
const agents = [...AI_AGENTS, ...options.customAgents || []];
|
|
17
|
+
return () => ({
|
|
18
|
+
// Define initial store state using Zustand
|
|
19
|
+
store: createPluginStore({
|
|
20
|
+
isAIAgent: false,
|
|
21
|
+
aiAgents: [],
|
|
22
|
+
aiAgentEnvVars: []
|
|
23
|
+
}),
|
|
24
|
+
beforeCommand(context) {
|
|
25
|
+
const env = process.env;
|
|
26
|
+
const detectedAgents = [];
|
|
27
|
+
const allDetectedEnvVars = [];
|
|
28
|
+
context.env.isAIAgent = false;
|
|
29
|
+
context.env.aiAgents = [];
|
|
30
|
+
for (const agent of agents) {
|
|
31
|
+
if (agent.detect(env)) {
|
|
32
|
+
detectedAgents.push(agent.name);
|
|
33
|
+
const detectedVars = agent.envVars.filter((v) => !!env[v]);
|
|
34
|
+
allDetectedEnvVars.push(...detectedVars);
|
|
35
|
+
if (options.verbose) {
|
|
36
|
+
console.log(`\u{1F916} AI agent detected: ${agent.name}`);
|
|
37
|
+
console.log(` Environment variables: ${detectedVars.join(", ")}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (detectedAgents.length > 0) {
|
|
42
|
+
context.env.isAIAgent = true;
|
|
43
|
+
context.env.aiAgents = detectedAgents;
|
|
44
|
+
if (context.store) {
|
|
45
|
+
context.store.setState({
|
|
46
|
+
isAIAgent: true,
|
|
47
|
+
aiAgents: detectedAgents,
|
|
48
|
+
aiAgentEnvVars: allDetectedEnvVars
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (options.verbose) {
|
|
52
|
+
if (detectedAgents.length === 1) {
|
|
53
|
+
console.log(`\u{1F916} AI agent detected: ${detectedAgents[0]}`);
|
|
54
|
+
} else {
|
|
55
|
+
console.log(`\u{1F916} Multiple AI agents detected: ${detectedAgents.join(", ")}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
if (context.store) {
|
|
60
|
+
context.store.setState({
|
|
61
|
+
isAIAgent: false,
|
|
62
|
+
aiAgents: [],
|
|
63
|
+
aiAgentEnvVars: []
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
export default aiAgentPlugin;
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@reliverse/rempts-plugin-ai-detect",
|
|
3
|
+
"version": "2.3.1",
|
|
4
|
+
"description": "AI agent detection plugin for Rempts - detects Claude, Cursor, Copilot and other AI coding assistants",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ai",
|
|
7
|
+
"claude",
|
|
8
|
+
"cli",
|
|
9
|
+
"copilot",
|
|
10
|
+
"cursor",
|
|
11
|
+
"plugin",
|
|
12
|
+
"rempts"
|
|
13
|
+
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"author": "bun dler Team",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"src"
|
|
19
|
+
],
|
|
20
|
+
"type": "module",
|
|
21
|
+
"main": "./src/mod.ts",
|
|
22
|
+
"types": "./src/mod.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/mod.d.ts",
|
|
26
|
+
"default": "./dist/mod.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@reliverse/rempts-core": "2.3.1"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
}
|
|
35
|
+
}
|
package/src/mod.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI agent detection plugin for Rempts
|
|
3
|
+
* Detects various AI coding assistants from environment variables
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { createPlugin, createPluginStore } from "@reliverse/rempts-core/plugin";
|
|
7
|
+
|
|
8
|
+
// Extend core interfaces with AI-specific fields
|
|
9
|
+
// declare module "@reliverse/rempts-core/plugin" {
|
|
10
|
+
// interface EnvironmentInfo {
|
|
11
|
+
// /** AI agent detected */
|
|
12
|
+
// isAIAgent: boolean;
|
|
13
|
+
|
|
14
|
+
// /** Detected AI agents */
|
|
15
|
+
// aiAgents: string[];
|
|
16
|
+
// }
|
|
17
|
+
// }
|
|
18
|
+
|
|
19
|
+
interface AIAgentInfo {
|
|
20
|
+
name: string;
|
|
21
|
+
envVars: string[];
|
|
22
|
+
detect: (env: NodeJS.ProcessEnv) => boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Known AI agents and their detection patterns
|
|
26
|
+
const AI_AGENTS: AIAgentInfo[] = [
|
|
27
|
+
{
|
|
28
|
+
name: "claude",
|
|
29
|
+
envVars: ["CLAUDECODE"],
|
|
30
|
+
detect: (env) => !!env.CLAUDECODE,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: "cursor",
|
|
34
|
+
envVars: ["CURSOR_AGENT"],
|
|
35
|
+
detect: (env) => !!env.CURSOR_AGENT,
|
|
36
|
+
},
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
export interface AIDetectPluginOptions {
|
|
40
|
+
/**
|
|
41
|
+
* Additional custom AI agents to detect
|
|
42
|
+
*/
|
|
43
|
+
customAgents?: AIAgentInfo[];
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Whether to log detection results
|
|
47
|
+
* Default: false
|
|
48
|
+
*/
|
|
49
|
+
verbose?: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface AIDetectStore {
|
|
53
|
+
isAIAgent: boolean;
|
|
54
|
+
aiAgents: string[];
|
|
55
|
+
aiAgentEnvVars: string[];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* AI agent detection plugin factory
|
|
60
|
+
*/
|
|
61
|
+
export const aiAgentPlugin = createPlugin<AIDetectPluginOptions | undefined, AIDetectStore>(
|
|
62
|
+
(options: AIDetectPluginOptions = {}) => {
|
|
63
|
+
const agents = [...AI_AGENTS, ...(options.customAgents || [])];
|
|
64
|
+
|
|
65
|
+
return () => ({
|
|
66
|
+
// Define initial store state using Zustand
|
|
67
|
+
store: createPluginStore<AIDetectStore>({
|
|
68
|
+
isAIAgent: false,
|
|
69
|
+
aiAgents: [] as string[],
|
|
70
|
+
aiAgentEnvVars: [] as string[],
|
|
71
|
+
}),
|
|
72
|
+
|
|
73
|
+
beforeCommand(context) {
|
|
74
|
+
const env = process.env;
|
|
75
|
+
const detectedAgents: string[] = [];
|
|
76
|
+
const allDetectedEnvVars: string[] = [];
|
|
77
|
+
|
|
78
|
+
// Initialize AI fields on the environment info
|
|
79
|
+
(context.env as any).isAIAgent = false;
|
|
80
|
+
(context.env as any).aiAgents = [];
|
|
81
|
+
|
|
82
|
+
// Check all known AI agents
|
|
83
|
+
for (const agent of agents) {
|
|
84
|
+
if (agent.detect(env)) {
|
|
85
|
+
detectedAgents.push(agent.name);
|
|
86
|
+
|
|
87
|
+
// Store detected environment variables for this agent
|
|
88
|
+
const detectedVars = agent.envVars.filter((v) => !!env[v]);
|
|
89
|
+
allDetectedEnvVars.push(...detectedVars);
|
|
90
|
+
|
|
91
|
+
// Log if verbose
|
|
92
|
+
if (options.verbose) {
|
|
93
|
+
console.log(`🤖 AI agent detected: ${agent.name}`);
|
|
94
|
+
console.log(` Environment variables: ${detectedVars.join(", ")}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Update context based on detection results
|
|
100
|
+
if (detectedAgents.length > 0) {
|
|
101
|
+
(context.env as any).isAIAgent = true;
|
|
102
|
+
(context.env as any).aiAgents = detectedAgents;
|
|
103
|
+
|
|
104
|
+
// Use type-safe store - TypeScript knows the exact types!
|
|
105
|
+
if (context.store) {
|
|
106
|
+
context.store.setState({
|
|
107
|
+
isAIAgent: true,
|
|
108
|
+
aiAgents: detectedAgents,
|
|
109
|
+
aiAgentEnvVars: allDetectedEnvVars,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (options.verbose) {
|
|
114
|
+
if (detectedAgents.length === 1) {
|
|
115
|
+
console.log(`🤖 AI agent detected: ${detectedAgents[0]}`);
|
|
116
|
+
} else {
|
|
117
|
+
console.log(`🤖 Multiple AI agents detected: ${detectedAgents.join(", ")}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
} else {
|
|
121
|
+
// Ensure fields are initialized even when no AI agent detected
|
|
122
|
+
if (context.store) {
|
|
123
|
+
context.store.setState({
|
|
124
|
+
isAIAgent: false,
|
|
125
|
+
aiAgents: [],
|
|
126
|
+
aiAgentEnvVars: [],
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
// Default export for convenience
|
|
136
|
+
export default aiAgentPlugin;
|