@invokehq/cli 0.1.11 → 0.1.13

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 (3) hide show
  1. package/index.js +109 -87
  2. package/package.json +1 -1
  3. package/trace.js +49 -49
package/index.js CHANGED
@@ -1,88 +1,110 @@
1
-
2
-
3
- const { Command } = require('commander');
4
- const chalk = require('chalk');
5
- const fs = require('fs-extra');
6
- const path = require('path');
7
- const pkg = require(path.resolve(__dirname, 'package.json'));
8
-
9
- const program = new Command();
10
- const CONTEXT_DIR = path.join(process.cwd(), '.agentgate');
11
- const CONTEXT_FILE = path.join(CONTEXT_DIR, 'context.json');
12
-
13
- function parseGitHubPath(input) {
14
- // Handles https://github.com/owner/repo and git@github.com:owner/repo
15
- const regex = /(?:https?:\/\/github\.com\/|git@github\.com:)([^/]+)\/([^/.]+?)(?:\.git)?(?:\/)?$/;
16
- const match = input.match(regex);
17
- return match ? `${match[1]}/${match[2]}` : input;
18
- }
19
-
20
- program
21
- .name('agentgate')
22
- .version(pkg.version);
23
-
24
- program
25
- .command('wrap')
26
- .description('Prepare repository context')
27
- .argument('<provider>', 'e.g., github')
28
- .option('-p, --path <path>', 'Repository URL or owner/repo', '.')
29
- .action(async (provider, options) => {
30
- const normalizedProvider = provider.toLowerCase();
31
- const supported = ['github'];
32
-
33
- if (!supported.includes(normalizedProvider)) {
34
- console.error(chalk.red(`Error: Unsupported provider "${provider}". Supported: ${supported.join(', ')}`));
35
- process.exit(1);
36
- }
37
-
38
- let target = options.path;
39
- if (normalizedProvider === 'github') target = parseGitHubPath(options.path);
40
-
41
- console.log(chalk.blue(`[AgentGate] Wrapping ${chalk.bold(normalizedProvider)} repository: ${chalk.cyan(target)}...`));
42
-
43
- const context = {
44
- provider: normalizedProvider,
45
- repoIdentifier: target,
46
- timestamp: new Date().toISOString(),
47
- status: 'wrapped'
48
- };
49
-
50
- try {
51
- await fs.ensureDir(CONTEXT_DIR);
52
- await fs.writeJson(CONTEXT_FILE, context, { spaces: 2 });
53
- console.log(chalk.green(`✔ Context saved to .agentgate/context.json`));
54
- } catch (err) {
55
- console.error(chalk.red('Failed to save context:'), err.message);
56
- }
57
- });
58
-
59
- program
60
- .command('upload')
61
- .description('Upload context to AgentGate')
62
- .action(async () => {
63
- if (!await fs.pathExists(CONTEXT_FILE)) {
64
- console.error(chalk.red('Error: No context found. Run "agentgate wrap github --path <url>" first.'));
65
- return;
66
- }
67
-
68
- const apiKey = process.env.AGENTGATE_API_KEY || process.env.TRACE_API_KEY;
69
- if (!apiKey) {
70
- console.warn(chalk.yellow('⚠ Warning: No AGENTGATE_API_KEY found in environment. The backend may reject this context.'));
71
- }
72
-
73
- try {
74
- const context = await fs.readJson(CONTEXT_FILE);
75
- console.log(chalk.blue(`[AgentGate] Synchronizing context for ${chalk.bold(context.repoIdentifier)} with backend...`));
76
-
77
- context.status = 'active';
78
- context.lastUploaded = new Date().toISOString();
79
-
80
- await fs.writeJson(CONTEXT_FILE, context, { spaces: 2 });
81
- await new Promise(r => setTimeout(r, 500)); // Simulating network latency
82
- console.log(chalk.green(`✔ Success: Repository context is now active.`));
83
- } catch (err) {
84
- console.error(chalk.red('Upload failed:'), err.message);
85
- }
86
- });
87
-
1
+ #!/usr/bin/env node
2
+ const { Command } = require('commander');
3
+ const chalk = require('chalk');
4
+ const fs = require('fs-extra');
5
+ const path = require('path');
6
+ const pkg = require(path.resolve(__dirname, 'package.json'));
7
+ const os = require('os');
8
+ const program = new Command();
9
+ const CONTEXT_DIR = path.join(process.cwd(), '.agentgate');
10
+ const CONTEXT_FILE = path.join(CONTEXT_DIR, 'context.json');
11
+
12
+ function parseGitHubPath(input) {
13
+ // Handles https://github.com/owner/repo and git@github.com:owner/repo
14
+ const regex = /(?:https?:\/\/github\.com\/|git@github\.com:)([^/]+)\/([^/.]+?)(?:\.git)?(?:\/)?$/;
15
+ const match = input.match(regex);
16
+ return match ? `${match[1]}/${match[2]}` : input;
17
+ }
18
+
19
+ program
20
+ .name('agentgate')
21
+ .version(pkg.version);
22
+
23
+ program
24
+ .command('login')
25
+ .description('Authenticate to your Invoke runtime')
26
+ .option('--api-key <key>', 'Invoke API key for non-interactive login')
27
+ .option('--base-url <url>', 'Invoke runtime URL', 'https://api.invokehq.run')
28
+ .action(async (options) => {
29
+ const apiKey = options.apiKey || process.env.INVOKE_API_KEY;
30
+
31
+ if (!apiKey) {
32
+ console.error('Missing API key. Set INVOKE_API_KEY or run: invoke login --api-key <key>');
33
+ process.exit(1);
34
+ }
35
+
36
+ await fs.ensureDir(path.join(os.homedir(), '.invoke'));
37
+ await fs.writeJson(path.join(os.homedir(), '.invoke', 'config.json'), {
38
+ baseUrl: options.baseUrl.replace(/\/+$/, ''),
39
+ apiKey,
40
+ updatedAt: new Date().toISOString()
41
+ }, { spaces: 2 });
42
+
43
+ console.log(`Logged in to Invoke (${options.baseUrl})`);
44
+ });
45
+
46
+ program
47
+ .command('wrap')
48
+ .description('Prepare repository context')
49
+ .argument('<provider>', 'e.g., github')
50
+ .option('-p, --path <path>', 'Repository URL or owner/repo', '.')
51
+ .action(async (provider, options) => {
52
+ const normalizedProvider = provider.toLowerCase();
53
+ const supported = ['github'];
54
+
55
+ if (!supported.includes(normalizedProvider)) {
56
+ console.error(chalk.red(`Error: Unsupported provider "${provider}". Supported: ${supported.join(', ')}`));
57
+ process.exit(1);
58
+ }
59
+
60
+ let target = options.path;
61
+ if (normalizedProvider === 'github') target = parseGitHubPath(options.path);
62
+
63
+ console.log(chalk.blue(`[AgentGate] Wrapping ${chalk.bold(normalizedProvider)} repository: ${chalk.cyan(target)}...`));
64
+
65
+ const context = {
66
+ provider: normalizedProvider,
67
+ repoIdentifier: target,
68
+ timestamp: new Date().toISOString(),
69
+ status: 'wrapped'
70
+ };
71
+
72
+ try {
73
+ await fs.ensureDir(CONTEXT_DIR);
74
+ await fs.writeJson(CONTEXT_FILE, context, { spaces: 2 });
75
+ console.log(chalk.green(`✔ Context saved to .agentgate/context.json`));
76
+ } catch (err) {
77
+ console.error(chalk.red('Failed to save context:'), err.message);
78
+ }
79
+ });
80
+
81
+ program
82
+ .command('upload')
83
+ .description('Upload context to AgentGate')
84
+ .action(async () => {
85
+ if (!await fs.pathExists(CONTEXT_FILE)) {
86
+ console.error(chalk.red('Error: No context found. Run "agentgate wrap github --path <url>" first.'));
87
+ return;
88
+ }
89
+
90
+ const apiKey = process.env.AGENTGATE_API_KEY || process.env.TRACE_API_KEY;
91
+ if (!apiKey) {
92
+ console.warn(chalk.yellow('⚠ Warning: No AGENTGATE_API_KEY found in environment. The backend may reject this context.'));
93
+ }
94
+
95
+ try {
96
+ const context = await fs.readJson(CONTEXT_FILE);
97
+ console.log(chalk.blue(`[AgentGate] Synchronizing context for ${chalk.bold(context.repoIdentifier)} with backend...`));
98
+
99
+ context.status = 'active';
100
+ context.lastUploaded = new Date().toISOString();
101
+
102
+ await fs.writeJson(CONTEXT_FILE, context, { spaces: 2 });
103
+ await new Promise(r => setTimeout(r, 500)); // Simulating network latency
104
+ console.log(chalk.green(`✔ Success: Repository context is now active.`));
105
+ } catch (err) {
106
+ console.error(chalk.red('Upload failed:'), err.message);
107
+ }
108
+ });
109
+
88
110
  program.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@invokehq/cli",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "Invoke CLI",
5
5
  "main": "trace.js",
6
6
  "bin": {
package/trace.js CHANGED
@@ -1,50 +1,50 @@
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
- if (!(await fs.pathExists(contextPath))) {
17
- throw new Error("Local context not found. Run 'agentgate wrap' first.");
18
- }
19
- const context = await fs.readJson(contextPath);
20
-
21
- // The SDK now points to the Agentgate Backend Service
22
- const AGENTGATE_SERVER = process.env.AGENTGATE_API_URL || "http://localhost:8000/call";
23
-
24
- try {
25
- const response = await axios.post(AGENTGATE_SERVER, {
26
- action,
27
- repository: context.repoIdentifier,
28
- parameters: params
29
- }, {
30
- timeout: 10000, // 10 second timeout
31
- headers: {
32
- 'User-Agent': `agentgate-cli-sdk/${pkg.version}`,
33
- 'Content-Type': 'application/json'
34
- }
35
- });
36
-
37
- return response.data;
38
- } catch (error) {
39
- // Controllable: The SDK can handle specific error types from the server
40
- if (error.code === 'ECONNREFUSED') {
41
- throw new Error("Agentgate Backend is offline. Reliability check failed.");
42
- }
43
- throw new Error(
44
- `Agentgate [${error.response?.status || 'Network'}]: ${error.response?.data?.error || error.response?.statusText || error.message}`
45
- );
46
- }
47
- }
48
- };
49
-
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
+ if (!(await fs.pathExists(contextPath))) {
17
+ throw new Error("Local context not found. Run 'agentgate wrap' first.");
18
+ }
19
+ const context = await fs.readJson(contextPath);
20
+
21
+ // The SDK now points to the Agentgate Backend Service
22
+ const AGENTGATE_SERVER = process.env.AGENTGATE_API_URL || "http://localhost:8000/call";
23
+
24
+ try {
25
+ const response = await axios.post(AGENTGATE_SERVER, {
26
+ action,
27
+ repository: context.repoIdentifier,
28
+ parameters: params
29
+ }, {
30
+ timeout: 10000, // 10 second timeout
31
+ headers: {
32
+ 'User-Agent': `agentgate-cli-sdk/${pkg.version}`,
33
+ 'Content-Type': 'application/json'
34
+ }
35
+ });
36
+
37
+ return response.data;
38
+ } catch (error) {
39
+ // Controllable: The SDK can handle specific error types from the server
40
+ if (error.code === 'ECONNREFUSED') {
41
+ throw new Error("Agentgate Backend is offline. Reliability check failed.");
42
+ }
43
+ throw new Error(
44
+ `Agentgate [${error.response?.status || 'Network'}]: ${error.response?.data?.error || error.response?.statusText || error.message}`
45
+ );
46
+ }
47
+ }
48
+ };
49
+
50
50
  module.exports = { trace };