@invoke-cli/cli 0.1.5

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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/index.js +108 -0
  3. package/package.json +34 -0
  4. package/trace.js +51 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 joel4893
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/index.js ADDED
@@ -0,0 +1,108 @@
1
+
2
+
3
+ const { Command } = require('commander');
4
+ const chalk = require('chalk');
5
+ const fs = require('fs-extra');
6
+ const path = require('path');
7
+ <<<<<<< HEAD
8
+ const pkg = require(path.resolve(__dirname, 'package.json'));
9
+ =======
10
+ const pkg = require('./package.json');
11
+ >>>>>>> 7d261e9 (chore: align scope and versioning)
12
+
13
+ const program = new Command();
14
+ const CONTEXT_DIR = path.join(process.cwd(), '.agentgate');
15
+ const CONTEXT_FILE = path.join(CONTEXT_DIR, 'context.json');
16
+
17
+ function parseGitHubPath(input) {
18
+ <<<<<<< HEAD
19
+ // Handles https://github.com/owner/repo and git@github.com:owner/repo
20
+ const regex = /(?:https?:\/\/github\.com\/|git@github\.com:)([^/]+)\/([^/.]+?)(?:\.git)?(?:\/)?$/;
21
+ const match = input.match(regex);
22
+ =======
23
+ // Improved regex to handle trailing .git and slashes
24
+ const urlRegex = /github\.com\/([^/]+)\/([^/.]+?)(?:\.git)?(?:\/)?$/;
25
+ const match = input.match(urlRegex);
26
+ >>>>>>> 7d261e9 (chore: align scope and versioning)
27
+ return match ? `${match[1]}/${match[2]}` : input;
28
+ }
29
+
30
+ program
31
+ .name('agentgate')
32
+ .version(pkg.version);
33
+
34
+ program
35
+ .command('wrap')
36
+ .description('Prepare repository context')
37
+ .argument('<provider>', 'e.g., github')
38
+ .option('-p, --path <path>', 'Repository URL or owner/repo', '.')
39
+ .action(async (provider, options) => {
40
+ const normalizedProvider = provider.toLowerCase();
41
+ const supported = ['github'];
42
+
43
+ if (!supported.includes(normalizedProvider)) {
44
+ console.error(chalk.red(`Error: Unsupported provider "${provider}". Supported: ${supported.join(', ')}`));
45
+ process.exit(1);
46
+ }
47
+
48
+ let target = options.path;
49
+ if (normalizedProvider === 'github') target = parseGitHubPath(options.path);
50
+
51
+ console.log(chalk.blue(`[AgentGate] Wrapping ${chalk.bold(normalizedProvider)} repository: ${chalk.cyan(target)}...`));
52
+
53
+ const context = {
54
+ provider: normalizedProvider,
55
+ repoIdentifier: target,
56
+ timestamp: new Date().toISOString(),
57
+ status: 'wrapped'
58
+ };
59
+
60
+ try {
61
+ await fs.ensureDir(CONTEXT_DIR);
62
+ await fs.writeJson(CONTEXT_FILE, context, { spaces: 2 });
63
+ console.log(chalk.green(`✔ Context saved to .agentgate/context.json`));
64
+ } catch (err) {
65
+ console.error(chalk.red('Failed to save context:'), err.message);
66
+ }
67
+ });
68
+
69
+ program
70
+ .command('upload')
71
+ .description('Upload context to AgentGate')
72
+ .action(async () => {
73
+ if (!await fs.pathExists(CONTEXT_FILE)) {
74
+ console.error(chalk.red('Error: No context found. Run "agentgate wrap github --path <url>" first.'));
75
+ return;
76
+ }
77
+
78
+ <<<<<<< HEAD
79
+ const apiKey = process.env.AGENTGATE_API_KEY || process.env.TRACE_API_KEY;
80
+ if (!apiKey) {
81
+ console.warn(chalk.yellow('⚠ Warning: No AGENTGATE_API_KEY found in environment. The backend may reject this context.'));
82
+ }
83
+
84
+ try {
85
+ const context = await fs.readJson(CONTEXT_FILE);
86
+ console.log(chalk.blue(`[AgentGate] Synchronizing context for ${chalk.bold(context.repoIdentifier)} with backend...`));
87
+ =======
88
+ try {
89
+ const context = await fs.readJson(CONTEXT_FILE);
90
+ console.log(chalk.blue(`[AgentGate] Uploading context for ${chalk.bold(context.repoIdentifier)}...`));
91
+ >>>>>>> 7d261e9 (chore: align scope and versioning)
92
+
93
+ context.status = 'active';
94
+ context.lastUploaded = new Date().toISOString();
95
+
96
+ await fs.writeJson(CONTEXT_FILE, context, { spaces: 2 });
97
+ await new Promise(r => setTimeout(r, 500)); // Simulating network latency
98
+ <<<<<<< HEAD
99
+ console.log(chalk.green(`✔ Success: Repository context is now active.`));
100
+ =======
101
+ console.log(chalk.green('✔ Upload successful.'));
102
+ >>>>>>> 7d261e9 (chore: align scope and versioning)
103
+ } catch (err) {
104
+ console.error(chalk.red('Upload failed:'), err.message);
105
+ }
106
+ });
107
+
108
+ program.parse(process.argv);
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@invoke-cli/cli",
3
+ "version": "0.1.5",
4
+ "description": "Agentgate CLI and SDK",
5
+ "main": "trace.js",
6
+ "bin": {
7
+ "agentgate": "index.js"
8
+ },
9
+ "scripts": {
10
+ "build": "echo 'no build step'"
11
+ },
12
+ "files": [
13
+ "index.js",
14
+ "trace.js"
15
+ ],
16
+ "dependencies": {
17
+ "axios": "^1.6.0",
18
+ "axios-retry": "^4.5.0",
19
+ "chalk": "^4.1.2",
20
+ "commander": "^11.0.0",
21
+ "dotenv": "^16.4.5",
22
+ "fs-extra": "^11.1.1"
23
+ },
24
+ "engines": {
25
+ "node": ">=16.0.0"
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/joel4893/agentgate-cli.git"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ }
34
+ }
package/trace.js ADDED
@@ -0,0 +1,51 @@
1
+ const fs = require('fs-extra');
2
+ const path = require('path');
3
+ const axios = require('axios');
4
+
5
+ // Load .env from the project root where the CLI is being executed
6
+ require('dotenv').config({ path: path.resolve(process.cwd(), '.env') });
7
+
8
+ // Load package info once at startup
9
+ const pkg = require(path.resolve(__dirname, 'package.json'));
10
+
11
+ const trace = {
12
+ call: async (action, params) => {
13
+ // Get context from the local wrap
14
+ const contextPath = path.join(process.cwd(), '.agentgate', 'context.json');
15
+
16
+ <<<<<<< HEAD
17
+ if (!(await fs.pathExists(contextPath))) {
18
+ throw new Error("Local context not found. Run 'agentgate wrap' first.");
19
+ }
20
+ const context = await fs.readJson(contextPath);
21
+
22
+ // The SDK now points to the Agentgate Backend Service
23
+ const AGENTGATE_SERVER = process.env.AGENTGATE_API_URL || "http://localhost:8000/call";
24
+
25
+ try {
26
+ const response = await axios.post(AGENTGATE_SERVER, {
27
+ action,
28
+ repository: context.repoIdentifier,
29
+ parameters: params
30
+ }, {
31
+ timeout: 10000, // 10 second timeout
32
+ headers: {
33
+ 'User-Agent': `agentgate-cli-sdk/${pkg.version}`,
34
+ 'Content-Type': 'application/json'
35
+ }
36
+ });
37
+
38
+ return response.data;
39
+ } catch (error) {
40
+ // Controllable: The SDK can handle specific error types from the server
41
+ if (error.code === 'ECONNREFUSED') {
42
+ throw new Error("Agentgate Backend is offline. Reliability check failed.");
43
+ }
44
+ throw new Error(
45
+ `Agentgate [${error.response?.status || 'Network'}]: ${error.response?.data?.error || error.response?.statusText || error.message}`
46
+ );
47
+ }
48
+ }
49
+ };
50
+
51
+ module.exports = { trace };