@indexnetwork/cli 0.9.5 → 0.10.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.
Files changed (2) hide show
  1. package/dist/index.js +296 -9
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -1,11 +1,26 @@
1
1
  #!/usr/bin/env node
2
+ var __defProp = Object.defineProperty;
3
+ var __returnValue = (v) => v;
4
+ function __exportSetter(name, newValue) {
5
+ this[name] = __returnValue.bind(null, newValue);
6
+ }
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, {
10
+ get: all[name],
11
+ enumerable: true,
12
+ configurable: true,
13
+ set: __exportSetter.bind(all, name)
14
+ });
15
+ };
2
16
 
3
17
  // src/main.ts
4
18
  import { execFile } from "node:child_process";
5
19
 
6
20
  // src/args.parser.ts
7
- var KNOWN_COMMANDS = new Set(["login", "logout", "profile", "intent", "opportunity", "network", "conversation", "contact", "scrape", "onboarding", "sync", "help", "version"]);
21
+ var KNOWN_COMMANDS = new Set(["login", "logout", "profile", "intent", "opportunity", "negotiation", "network", "conversation", "contact", "scrape", "onboarding", "sync", "help", "version"]);
8
22
  var OPPORTUNITY_SUBCOMMANDS = new Set(["list", "show", "accept", "reject", "discover"]);
23
+ var NEGOTIATION_SUBCOMMANDS = new Set(["list", "show"]);
9
24
  var NETWORK_SUBCOMMANDS = new Set(["list", "create", "show", "join", "leave", "invite", "update", "delete"]);
10
25
  var CONVERSATION_SUBCOMMANDS = new Set(["list", "with", "show", "send", "stream", "sessions", "help"]);
11
26
  function parseArgs(args) {
@@ -16,22 +31,39 @@ function parseArgs(args) {
16
31
  if (args.length === 0) {
17
32
  return result;
18
33
  }
19
- const first = args[0];
20
- if (first === "--help" || first === "-h") {
21
- result.command = "help";
22
- return result;
34
+ let commandIndex = -1;
35
+ for (let j = 0;j < args.length; j++) {
36
+ const a = args[j];
37
+ if (a === "--api-url" || a === "--app-url" || a === "--token" || a === "-t") {
38
+ if (a === "--api-url")
39
+ result.apiUrl = args[j + 1];
40
+ else if (a === "--app-url")
41
+ result.appUrl = args[j + 1];
42
+ else
43
+ result.token = args[j + 1];
44
+ j++;
45
+ } else if (a === "--help" || a === "-h") {
46
+ result.command = "help";
47
+ return result;
48
+ } else if (a === "--version" || a === "-v") {
49
+ result.command = "version";
50
+ return result;
51
+ } else if (!a.startsWith("--")) {
52
+ commandIndex = j;
53
+ break;
54
+ }
23
55
  }
24
- if (first === "--version" || first === "-v") {
25
- result.command = "version";
56
+ if (commandIndex === -1) {
26
57
  return result;
27
58
  }
59
+ const first = args[commandIndex];
28
60
  if (!KNOWN_COMMANDS.has(first)) {
29
61
  result.command = "unknown";
30
62
  result.unknown = first;
31
63
  return result;
32
64
  }
33
65
  result.command = first;
34
- let i = 1;
66
+ let i = commandIndex + 1;
35
67
  const positionals = [];
36
68
  while (i < args.length) {
37
69
  const arg = args[i];
@@ -95,6 +127,9 @@ function parseArgs(args) {
95
127
  } else if (arg === "--details") {
96
128
  result.details = args[i + 1];
97
129
  i += 2;
130
+ } else if (arg === "--since") {
131
+ result.since = args[i + 1];
132
+ i += 2;
98
133
  } else if (arg.startsWith("--")) {
99
134
  i++;
100
135
  } else {
@@ -114,6 +149,16 @@ function parseArgs(args) {
114
149
  }
115
150
  return result;
116
151
  }
152
+ if (result.command === "negotiation") {
153
+ const sub = positionals[0];
154
+ if (sub && NEGOTIATION_SUBCOMMANDS.has(sub)) {
155
+ result.subcommand = sub;
156
+ if (positionals[1]) {
157
+ result.targetId = positionals[1];
158
+ }
159
+ }
160
+ return result;
161
+ }
117
162
  if (result.command === "profile" && positionals.length > 0) {
118
163
  const sub = positionals[0];
119
164
  if (sub === "show") {
@@ -410,6 +455,21 @@ class ApiClient {
410
455
  }
411
456
  return res;
412
457
  }
458
+ async listNegotiations(opts) {
459
+ const me = await this.getMe();
460
+ const params = new URLSearchParams;
461
+ if (opts?.limit)
462
+ params.set("limit", String(opts.limit));
463
+ if (opts?.offset)
464
+ params.set("offset", String(opts.offset));
465
+ if (opts?.since)
466
+ params.set("since", opts.since);
467
+ const qs = params.toString();
468
+ const path = qs ? `/api/users/${me.id}/negotiations?${qs}` : `/api/users/${me.id}/negotiations`;
469
+ const res = await this.get(path);
470
+ const body = await res.json();
471
+ return body.negotiations;
472
+ }
413
473
  async callTool(toolName, query = {}) {
414
474
  const res = await this.post(`/api/tools/${toolName}`, { query });
415
475
  return await res.json();
@@ -587,6 +647,57 @@ function callbackHtml(title, message) {
587
647
  </html>`;
588
648
  }
589
649
 
650
+ // src/output/index.ts
651
+ var exports_output = {};
652
+ __export(exports_output, {
653
+ wordWrap: () => wordWrap,
654
+ warn: () => warn,
655
+ toolActivity: () => toolActivity,
656
+ success: () => success,
657
+ stripAnsi: () => stripAnsi,
658
+ status: () => status,
659
+ sessionTable: () => sessionTable,
660
+ raw: () => raw,
661
+ profileCard: () => profileCard,
662
+ padTo: () => padTo,
663
+ opportunityTable: () => opportunityTable,
664
+ opportunityCard: () => opportunityCard,
665
+ networkTable: () => networkTable,
666
+ networkCard: () => networkCard,
667
+ messageList: () => messageList,
668
+ memberTable: () => memberTable,
669
+ intentTable: () => intentTable,
670
+ intentCard: () => intentCard,
671
+ info: () => info,
672
+ humanizeToolName: () => humanizeToolName,
673
+ heading: () => heading,
674
+ error: () => error,
675
+ dim: () => dim,
676
+ conversationTable: () => conversationTable,
677
+ conversationCard: () => conversationCard,
678
+ contactTable: () => contactTable,
679
+ confidenceBar: () => confidenceBar,
680
+ clearStatus: () => clearStatus,
681
+ chatHeader: () => chatHeader,
682
+ YELLOW: () => YELLOW,
683
+ WHITE: () => WHITE,
684
+ USER_PROMPT: () => USER_PROMPT,
685
+ RESET: () => RESET,
686
+ RED: () => RED,
687
+ PROMPT_STR: () => PROMPT_STR,
688
+ ORANGE: () => ORANGE,
689
+ MarkdownRenderer: () => MarkdownRenderer,
690
+ MAGENTA: () => MAGENTA,
691
+ ITALIC: () => ITALIC,
692
+ GREEN: () => GREEN,
693
+ GRAY: () => GRAY,
694
+ DIM: () => DIM,
695
+ CYAN: () => CYAN,
696
+ BOLD: () => BOLD,
697
+ BLUE: () => BLUE,
698
+ AGENT_TEXT: () => AGENT_TEXT
699
+ });
700
+
590
701
  // src/output/base.ts
591
702
  var RESET = "\x1B[0m";
592
703
  var BOLD = "\x1B[1m";
@@ -615,6 +726,9 @@ function success(message) {
615
726
  function info(message) {
616
727
  console.log(`${CYAN}${message}${RESET}`);
617
728
  }
729
+ function warn(message) {
730
+ console.log(`${YELLOW}${message}${RESET}`);
731
+ }
618
732
  function dim(message) {
619
733
  console.log(`${GRAY}${message}${RESET}`);
620
734
  }
@@ -630,6 +744,9 @@ function chatHeader() {
630
744
  console.log();
631
745
  }
632
746
  var PROMPT_STR = `${USER_PROMPT}${BOLD}> ${RESET}`;
747
+ function raw(text) {
748
+ process.stdout.write(text);
749
+ }
633
750
  function status(message) {
634
751
  process.stderr.write(`\r ${GRAY}${message}${RESET}\x1B[K`);
635
752
  }
@@ -1892,6 +2009,163 @@ async function discoverIntroduction(client, userA, userB, hint, json) {
1892
2009
  dim(` ${data.message}`);
1893
2010
  }
1894
2011
 
2012
+ // src/negotiation.command.ts
2013
+ var NEGOTIATION_HELP = `
2014
+ Usage:
2015
+ index negotiation list List your agent's negotiations
2016
+ index negotiation list --limit <n> Limit results
2017
+ index negotiation list --since <date|duration> Filter by time (ISO date or duration like 1h, 2d, 1w)
2018
+ index negotiation show <id> Show negotiation turn-by-turn details
2019
+ `;
2020
+ async function handleNegotiation(client, subcommand, options) {
2021
+ if (!subcommand) {
2022
+ if (options.json) {
2023
+ console.log(JSON.stringify({ error: "No subcommand provided" }));
2024
+ } else {
2025
+ console.log(NEGOTIATION_HELP);
2026
+ }
2027
+ return;
2028
+ }
2029
+ switch (subcommand) {
2030
+ case "list":
2031
+ await negotiationList(client, options.limit, options.since, options.json);
2032
+ return;
2033
+ case "show":
2034
+ if (!options.targetId) {
2035
+ error("Missing negotiation ID. Usage: index negotiation show <id>", 1);
2036
+ return;
2037
+ }
2038
+ await negotiationShow(client, options.targetId, options.json);
2039
+ return;
2040
+ default:
2041
+ error(`Unknown subcommand: ${subcommand}`, 1);
2042
+ return;
2043
+ }
2044
+ }
2045
+ function resolveSince(input) {
2046
+ const match = input.match(/^(\d+)([smhdw])$/);
2047
+ if (match) {
2048
+ const n = parseInt(match[1], 10);
2049
+ const unit = match[2];
2050
+ const ms = { s: 1000, m: 60000, h: 3600000, d: 86400000, w: 604800000 }[unit];
2051
+ return new Date(Date.now() - n * ms).toISOString();
2052
+ }
2053
+ const d = new Date(input);
2054
+ if (isNaN(d.getTime()))
2055
+ throw new Error(`Invalid --since value: "${input}". Use ISO date or duration like 1h, 2d, 1w.`);
2056
+ return d.toISOString();
2057
+ }
2058
+ async function negotiationList(client, limit, since, json) {
2059
+ const sinceIso = since ? resolveSince(since) : undefined;
2060
+ const negotiations = await client.listNegotiations({ limit, since: sinceIso });
2061
+ if (json) {
2062
+ console.log(JSON.stringify(negotiations));
2063
+ return;
2064
+ }
2065
+ heading("Negotiations");
2066
+ negotiationTable(negotiations);
2067
+ console.log();
2068
+ }
2069
+ async function negotiationShow(client, id, json) {
2070
+ const negotiations = await client.listNegotiations({ limit: 50 });
2071
+ const match = negotiations.find((n) => n.id === id || n.id.startsWith(id));
2072
+ if (!match) {
2073
+ error(`Negotiation not found: ${id}`, 1);
2074
+ return;
2075
+ }
2076
+ if (json) {
2077
+ console.log(JSON.stringify(match));
2078
+ return;
2079
+ }
2080
+ negotiationCard(match);
2081
+ }
2082
+ var { BOLD: BOLD2, RESET: RESET2, CYAN: CYAN2, GRAY: GRAY2, GREEN: GREEN2, YELLOW: YELLOW2, BLUE: BLUE2, DIM: DIM2 } = exports_output;
2083
+ function outcomeLabel(outcome) {
2084
+ if (!outcome)
2085
+ return `${GRAY2}unknown${RESET2}`;
2086
+ return outcome.hasOpportunity ? `${GREEN2}opportunity${RESET2}` : `${GRAY2}no match${RESET2}`;
2087
+ }
2088
+ function roleLabel2(role) {
2089
+ switch (role) {
2090
+ case "agent":
2091
+ return `${GREEN2}helper${RESET2}`;
2092
+ case "patient":
2093
+ return `${YELLOW2}seeker${RESET2}`;
2094
+ case "peer":
2095
+ return `${CYAN2}peer${RESET2}`;
2096
+ default:
2097
+ return `${GRAY2}-${RESET2}`;
2098
+ }
2099
+ }
2100
+ function negotiationTable(negotiations) {
2101
+ if (negotiations.length === 0) {
2102
+ dim(" No negotiations found.");
2103
+ return;
2104
+ }
2105
+ const idW = 8;
2106
+ const nameW = 22;
2107
+ const outcomeW = 14;
2108
+ const roleW = 8;
2109
+ const turnsW = 6;
2110
+ const dateW = 20;
2111
+ process.stdout.write(` ${BOLD2}${"ID".padEnd(idW)} ${"Counterparty".padEnd(nameW)} ${"Outcome".padEnd(outcomeW)} ${"Role".padEnd(roleW)} ${"Turns".padEnd(turnsW)} ${"Created".padEnd(dateW)}${RESET2}
2112
+ `);
2113
+ process.stdout.write(` ${GRAY2}${"-".repeat(idW)} ${"-".repeat(nameW)} ${"-".repeat(outcomeW)} ${"-".repeat(roleW)} ${"-".repeat(turnsW)} ${"-".repeat(dateW)}${RESET2}
2114
+ `);
2115
+ for (const n of negotiations) {
2116
+ const shortId = n.id.slice(0, 8);
2117
+ const name = (n.counterparty?.name ?? "Unknown").slice(0, nameW);
2118
+ const turns = String(n.outcome?.turnCount ?? n.turns?.length ?? "-");
2119
+ const date = n.createdAt ? new Date(n.createdAt).toLocaleDateString("en-US", {
2120
+ year: "numeric",
2121
+ month: "short",
2122
+ day: "numeric"
2123
+ }) : "-";
2124
+ const outcomeStr = outcomeLabel(n.outcome);
2125
+ const roleStr = roleLabel2(n.outcome?.role);
2126
+ process.stdout.write(` ${CYAN2}${shortId}${RESET2} ${name.padEnd(nameW)} ${outcomeStr}${padTo(outcomeW, stripAnsi(outcomeStr))} ${roleStr}${padTo(roleW, stripAnsi(roleStr))} ${turns.padEnd(turnsW)} ${GRAY2}${date}${RESET2}
2127
+ `);
2128
+ }
2129
+ }
2130
+ function negotiationCard(n) {
2131
+ console.log();
2132
+ console.log(` ${BOLD2}${CYAN2}Negotiation Details${RESET2}`);
2133
+ console.log(` ${GRAY2}${"─".repeat(60)}${RESET2}`);
2134
+ console.log(` ${BOLD2}ID${RESET2} ${GRAY2}${n.id}${RESET2}`);
2135
+ console.log(` ${BOLD2}Counterparty${RESET2} ${n.counterparty?.name ?? "Unknown"}`);
2136
+ console.log(` ${BOLD2}Outcome${RESET2} ${outcomeLabel(n.outcome)}`);
2137
+ console.log(` ${BOLD2}Your Role${RESET2} ${roleLabel2(n.outcome?.role)}`);
2138
+ console.log(` ${BOLD2}Turns${RESET2} ${n.outcome?.turnCount ?? n.turns?.length ?? "-"}`);
2139
+ console.log(` ${BOLD2}Created${RESET2} ${GRAY2}${new Date(n.createdAt).toLocaleString()}${RESET2}`);
2140
+ if (n.turns && n.turns.length > 0) {
2141
+ console.log();
2142
+ console.log(` ${BOLD2}Turn-by-Turn${RESET2}`);
2143
+ console.log(` ${GRAY2}${"─".repeat(60)}${RESET2}`);
2144
+ for (let i = 0;i < n.turns.length; i++) {
2145
+ const t = n.turns[i];
2146
+ const time = new Date(t.createdAt).toLocaleTimeString("en-US", {
2147
+ hour: "2-digit",
2148
+ minute: "2-digit",
2149
+ second: "2-digit"
2150
+ });
2151
+ const actionColor = t.action === "accept" ? GREEN2 : t.action === "reject" ? RED : BLUE2;
2152
+ console.log(` ${DIM2}Turn ${i + 1}${RESET2} ${CYAN2}${t.speaker?.name ?? "?"}${RESET2} ${actionColor}${t.action}${RESET2} ${GRAY2}${time}${RESET2}`);
2153
+ if (t.suggestedRoles) {
2154
+ console.log(` ${DIM2} roles: own=${t.suggestedRoles.ownUser ?? "?"} other=${t.suggestedRoles.otherUser ?? "?"}${RESET2}`);
2155
+ }
2156
+ if (t.reasoning) {
2157
+ const lines = wordWrap(t.reasoning, 72);
2158
+ for (const line of lines) {
2159
+ console.log(` ${DIM2} ${line}${RESET2}`);
2160
+ }
2161
+ }
2162
+ console.log();
2163
+ }
2164
+ }
2165
+ console.log(` ${GRAY2}${"─".repeat(60)}${RESET2}`);
2166
+ console.log();
2167
+ }
2168
+
1895
2169
  // src/network.command.ts
1896
2170
  var NETWORK_HELP = `
1897
2171
  Network Commands:
@@ -2664,7 +2938,7 @@ async function onboardingComplete(client, json) {
2664
2938
  // src/main.ts
2665
2939
  var DEFAULT_API_URL = "https://protocol.index.network";
2666
2940
  var DEFAULT_APP_URL = "https://index.network";
2667
- var VERSION = "0.9.5";
2941
+ var VERSION = "0.10.0";
2668
2942
  var HELP_TEXT = `
2669
2943
  Index CLI v${VERSION}
2670
2944
 
@@ -2697,6 +2971,10 @@ Usage:
2697
2971
  index intent link <id> <network-id> Link a signal to a network
2698
2972
  index intent unlink <id> <network-id> Unlink a signal from a network
2699
2973
  index intent links <id> Show linked networks for a signal
2974
+ index negotiation list List your agent's negotiations
2975
+ index negotiation list --limit <n> Limit results
2976
+ index negotiation list --since <t> Filter by time (ISO date or 1h, 2d, 1w)
2977
+ index negotiation show <id> Show negotiation turn-by-turn details (accepts short ID)
2700
2978
  index opportunity list List your opportunities
2701
2979
  index opportunity list --status <s> Filter by status (pending|accepted|rejected|expired)
2702
2980
  index opportunity list --limit <n> Limit results
@@ -2732,6 +3010,7 @@ Options:
2732
3010
  --archived Include archived signals (intent list)
2733
3011
  --status <status> Filter opportunities by status
2734
3012
  --limit <n> Limit number of results
3013
+ --since <date> Filter by time (ISO date or duration like 1h, 2d, 1w)
2735
3014
  --json Output raw JSON instead of formatted text
2736
3015
  --name <name> Name for contact add
2737
3016
  --gmail Import source flag for contact import
@@ -2854,6 +3133,14 @@ async function main() {
2854
3133
  introduce: args.introduce
2855
3134
  });
2856
3135
  return;
3136
+ case "negotiation":
3137
+ await handleNegotiation(client, args.subcommand, {
3138
+ targetId: args.targetId,
3139
+ limit: args.limit,
3140
+ since: args.since,
3141
+ json: args.json
3142
+ });
3143
+ return;
2857
3144
  case "network":
2858
3145
  await handleNetwork(client, args.subcommand, args.positionals ?? [], {
2859
3146
  prompt: args.prompt,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indexnetwork/cli",
3
- "version": "0.9.5",
3
+ "version": "0.10.0",
4
4
  "description": "Command-line interface for Index Network",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -20,10 +20,10 @@
20
20
  "publish:all": "bun scripts/publish.ts"
21
21
  },
22
22
  "optionalDependencies": {
23
- "@indexnetwork/cli-linux-x64": "0.9.5",
24
- "@indexnetwork/cli-linux-arm64": "0.9.5",
25
- "@indexnetwork/cli-darwin-x64": "0.9.5",
26
- "@indexnetwork/cli-darwin-arm64": "0.9.5"
23
+ "@indexnetwork/cli-linux-x64": "0.10.0",
24
+ "@indexnetwork/cli-linux-arm64": "0.10.0",
25
+ "@indexnetwork/cli-darwin-x64": "0.10.0",
26
+ "@indexnetwork/cli-darwin-arm64": "0.10.0"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/bun": "latest"