@indexnetwork/cli 0.7.0

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 ADDED
@@ -0,0 +1,163 @@
1
+ # Index CLI
2
+
3
+ Command-line interface for [Index Network](https://index.network). Chat with the AI agent, manage signals, and discover opportunities — all from your terminal.
4
+
5
+ > **Status: v0.5.0**
6
+ > Supports `login`, `chat`, `profile`, `intent` (signal management), `opportunity`, and `network` commands.
7
+
8
+ ## Quick Start
9
+
10
+ ```bash
11
+ # Build the binary
12
+ bun run build
13
+
14
+ # Authenticate (opens browser)
15
+ ./dist/index login
16
+
17
+ # Start chatting
18
+ ./dist/index conversation
19
+ ```
20
+
21
+ ## Commands
22
+
23
+ ### `index login`
24
+
25
+ Authenticate with Index Network. Opens a browser window that exchanges your existing session for a CLI token, or starts a fresh OAuth flow.
26
+
27
+ ```bash
28
+ index login # Browser-based auth (default)
29
+ index login --token <jwt> # Manual token (skip browser)
30
+ index login --api-url <url> # Custom server URL
31
+ ```
32
+
33
+ Credentials are stored in `~/.index/credentials.json`.
34
+
35
+ ### `index logout`
36
+
37
+ Clear stored credentials.
38
+
39
+ ```bash
40
+ index logout
41
+ ```
42
+
43
+ ### `index intent`
44
+
45
+ Manage your signals (intents). Create signals from natural language, list active signals, view details, and archive signals you no longer need.
46
+
47
+ ```bash
48
+ index intent list # List active signals
49
+ index intent list --archived # Include archived signals
50
+ index intent list --limit 5 # Limit to 5 results
51
+ index intent show <id> # Show full signal details
52
+ index intent create "Looking for a CTO" # Create from natural language
53
+ index intent archive <id> # Archive a signal
54
+ ```
55
+
56
+ ### `index conversation`
57
+
58
+ Unified conversation command for AI agent chat and human-to-human messaging. Supports streaming responses, inline markdown formatting, tool call indicators, and special blocks (signal proposals, opportunities).
59
+
60
+ ```bash
61
+ index conversation # Interactive AI chat REPL
62
+ index conversation "find me collaborators" # One-shot message to AI agent
63
+ index conversation --session <id> # Resume an AI chat session
64
+ index conversation sessions # List AI chat sessions
65
+ index conversation list # List all conversations (H2A + H2H)
66
+ index conversation with <user-id> # Open or resume a DM
67
+ index conversation show <id> # Show messages
68
+ index conversation send <id> <msg> # Send a message
69
+ index conversation stream # Real-time SSE stream
70
+ ```
71
+
72
+ ### `index profile`
73
+
74
+ View user profiles and trigger profile regeneration.
75
+
76
+ ```bash
77
+ index profile # Show your own profile
78
+ index profile show <user-id> # Show another user's profile
79
+ index profile sync # Regenerate your profile
80
+ ```
81
+
82
+ ### `index opportunity`
83
+
84
+ Browse and manage discovered opportunities.
85
+
86
+ ```bash
87
+ index opportunity list # List all opportunities
88
+ index opportunity list --status pending # Filter by status
89
+ index opportunity list --limit 5 # Limit results
90
+ index opportunity show <id> # Show full details
91
+ index opportunity accept <id> # Accept an opportunity
92
+ index opportunity reject <id> # Reject an opportunity
93
+ ```
94
+
95
+ Status values: `pending`, `accepted`, `rejected`, `expired`.
96
+
97
+ The `show` command displays a detailed card with parties (including valency roles: Helper, Seeker, Peer), reasoning, confidence, and presentation text.
98
+
99
+ ### `index network`
100
+
101
+ Manage networks (communities). List, create, join, leave, and invite members.
102
+
103
+ ```bash
104
+ index network list # List your networks
105
+ index network create "My Network" # Create a network
106
+ index network create "AI" --prompt "AI researchers" # Create with description
107
+ index network show <id> # Show details and members
108
+ index network join <id> # Join a public network
109
+ index network leave <id> # Leave a network
110
+ index network invite <id> user@email # Invite a user by email
111
+ ```
112
+
113
+
114
+ ## Options
115
+
116
+ | Flag | Short | Description |
117
+ |------|-------|-------------|
118
+ | `--api-url <url>` | | Override API server (default: `http://localhost:3000`) |
119
+ | `--token <token>` | `-t` | Provide bearer token directly |
120
+ | `--session <id>` | `-s` | Resume a specific chat session |
121
+ | `--list` | `-l` | List chat sessions |
122
+ | `--archived` | | Include archived signals (intent list) |
123
+ | `--status <status>` | | Filter opportunities by status |
124
+ | `--limit <n>` | | Limit number of results |
125
+ | `--prompt <text>` | `-p` | Network description (for `network create`) |
126
+ | `--help` | `-h` | Show help |
127
+ | `--version` | `-v` | Show version |
128
+
129
+ ## Development
130
+
131
+ ```bash
132
+ # Run directly with Bun (no build step)
133
+ bun src/main.ts chat
134
+
135
+ # Build a standalone binary
136
+ bun run build # outputs to dist/index
137
+
138
+ # Run tests
139
+ bun test
140
+ ```
141
+
142
+ ### Project Structure
143
+
144
+ ```
145
+ cli/
146
+ src/
147
+ main.ts Entry point, command routing
148
+ login.command.ts OAuth flow with local callback server
149
+ conversation.command.ts H2A agent chat + H2H messaging + SSE stream parser
150
+ network.command.ts Network subcommand handlers
151
+ output.ts Terminal formatting, colors, markdown renderer
152
+ api.client.ts Typed HTTP client for the protocol API
153
+ auth.store.ts Credential persistence (~/.index/credentials.json)
154
+ args.parser.ts CLI argument parser (Bun-native parseArgs)
155
+ sse.parser.ts Server-Sent Events parser
156
+ ```
157
+
158
+ ## Roadmap
159
+
160
+ Commands planned for future iterations:
161
+
162
+ - ~~`index network` — Manage indexes and memberships~~ (shipped!)
163
+ - ~~`index conversation` — H2H and A2A messaging~~ (shipped!)
package/bin/index.cjs ADDED
@@ -0,0 +1,110 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Thin bin shim for @indexnetwork/cli.
5
+ *
6
+ * Resolves and executes the platform-specific precompiled binary from
7
+ * the corresponding optional dependency package. If no platform binary
8
+ * is available, falls back to running the bundled JS via Node or Bun.
9
+ *
10
+ * This file must remain plain JavaScript (no TypeScript, no bundling)
11
+ * so it works immediately after npm install without a build step.
12
+ */
13
+
14
+ "use strict";
15
+
16
+ const { execFileSync } = require("child_process");
17
+ const { existsSync } = require("fs");
18
+ const path = require("path");
19
+
20
+ /**
21
+ * Construct the npm package name for the current platform binary.
22
+ *
23
+ * @param {string} os - The operating system (e.g. "linux", "darwin").
24
+ * @param {string} arch - The CPU architecture (e.g. "x64", "arm64").
25
+ * @returns {string} The scoped package name.
26
+ */
27
+ function platformPackageName(os, arch) {
28
+ return `@indexnetwork/cli-${os}-${arch}`;
29
+ }
30
+
31
+ /**
32
+ * Attempt to resolve the path to the platform binary.
33
+ *
34
+ * @returns {string|null} Absolute path to the binary, or null if not found.
35
+ */
36
+ function resolvePlatformBinary() {
37
+ const pkg = platformPackageName(process.platform, process.arch);
38
+
39
+ try {
40
+ // require.resolve finds the package in node_modules, even when hoisted
41
+ const pkgJson = require.resolve(`${pkg}/package.json`);
42
+ const pkgDir = path.dirname(pkgJson);
43
+ const binPath = path.join(pkgDir, "bin", "index");
44
+
45
+ if (existsSync(binPath)) {
46
+ return binPath;
47
+ }
48
+ } catch {
49
+ // Package not installed — expected on unsupported platforms
50
+ }
51
+
52
+ return null;
53
+ }
54
+
55
+ /**
56
+ * Resolve the bundled JS fallback path.
57
+ *
58
+ * @returns {string|null} Absolute path to dist/index.js, or null if not found.
59
+ */
60
+ function resolveFallbackJs() {
61
+ const fallback = path.join(__dirname, "..", "dist", "index.js");
62
+ if (existsSync(fallback)) {
63
+ return fallback;
64
+ }
65
+ return null;
66
+ }
67
+
68
+ // ── Main ──────────────────────────────────────────────────────────────
69
+
70
+ const args = process.argv.slice(2);
71
+
72
+ // Strategy 1: platform-specific precompiled binary
73
+ const binary = resolvePlatformBinary();
74
+ if (binary) {
75
+ try {
76
+ execFileSync(binary, args, { stdio: "inherit" });
77
+ } catch (err) {
78
+ process.exitCode = err.status || 1;
79
+ }
80
+ process.exit();
81
+ }
82
+
83
+ // Strategy 2: bundled JS fallback via bun or node
84
+ const fallbackJs = resolveFallbackJs();
85
+ if (fallbackJs) {
86
+ // Prefer bun if available, otherwise node
87
+ const runtime = (() => {
88
+ try {
89
+ execFileSync("bun", ["--version"], { stdio: "ignore" });
90
+ return "bun";
91
+ } catch {
92
+ return process.execPath; // node
93
+ }
94
+ })();
95
+
96
+ try {
97
+ execFileSync(runtime, [fallbackJs, ...args], { stdio: "inherit" });
98
+ } catch (err) {
99
+ process.exitCode = err.status || 1;
100
+ }
101
+ process.exit();
102
+ }
103
+
104
+ // No binary, no fallback — report error
105
+ console.error(
106
+ `@indexnetwork/cli: No precompiled binary found for ${process.platform}-${process.arch},\n` +
107
+ `and no bundled JS fallback available at dist/index.js.\n\n` +
108
+ `Try reinstalling: npm install -g @indexnetwork/cli`
109
+ );
110
+ process.exit(1);