coherence-cli 0.7.0 → 0.8.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.
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Services commands: services, service, services health, services deps
3
+ */
4
+
5
+ import { get } from "../api.mjs";
6
+
7
+ function truncate(str, len) {
8
+ if (!str) return "";
9
+ return str.length > len ? str.slice(0, len - 1) + "\u2026" : str;
10
+ }
11
+
12
+ export async function listServices() {
13
+ const raw = await get("/api/services");
14
+ const data = Array.isArray(raw) ? raw : raw?.services;
15
+ if (!data || !Array.isArray(data)) {
16
+ console.log("Could not fetch services.");
17
+ return;
18
+ }
19
+ if (data.length === 0) {
20
+ console.log("No services found.");
21
+ return;
22
+ }
23
+
24
+ console.log();
25
+ console.log(`\x1b[1m SERVICES\x1b[0m (${data.length})`);
26
+ console.log(` ${"─".repeat(60)}`);
27
+ for (const s of data) {
28
+ const name = truncate(s.name || s.id, 30);
29
+ const status = s.status || "?";
30
+ const dot = status === "healthy" || status === "up" ? "\x1b[32m●\x1b[0m" : status === "degraded" ? "\x1b[33m●\x1b[0m" : "\x1b[31m●\x1b[0m";
31
+ console.log(` ${dot} ${name.padEnd(32)} ${status}`);
32
+ }
33
+ console.log();
34
+ }
35
+
36
+ export async function showService(args) {
37
+ const id = args[0];
38
+ if (!id) {
39
+ console.log("Usage: cc service <id>");
40
+ return;
41
+ }
42
+ const data = await get(`/api/services/${encodeURIComponent(id)}`);
43
+ if (!data) {
44
+ console.log(`Service '${id}' not found.`);
45
+ return;
46
+ }
47
+
48
+ console.log();
49
+ console.log(`\x1b[1m ${data.name || data.id}\x1b[0m`);
50
+ console.log(` ${"─".repeat(50)}`);
51
+ if (data.id) console.log(` ID: ${data.id}`);
52
+ if (data.status) console.log(` Status: ${data.status}`);
53
+ if (data.version) console.log(` Version: ${data.version}`);
54
+ if (data.url) console.log(` URL: ${data.url}`);
55
+ if (data.uptime) console.log(` Uptime: ${data.uptime}`);
56
+ console.log();
57
+ }
58
+
59
+ export async function showServicesHealth() {
60
+ const data = await get("/api/services/health");
61
+ if (!data) {
62
+ console.log("Could not fetch services health.");
63
+ return;
64
+ }
65
+
66
+ console.log();
67
+ console.log(`\x1b[1m SERVICES HEALTH\x1b[0m`);
68
+ console.log(` ${"─".repeat(50)}`);
69
+ if (Array.isArray(data)) {
70
+ for (const s of data) {
71
+ const name = truncate(s.name || s.id, 25);
72
+ const status = s.status || s.health || "?";
73
+ const dot = status === "healthy" || status === "up" ? "\x1b[32m●\x1b[0m" : "\x1b[31m●\x1b[0m";
74
+ console.log(` ${dot} ${name.padEnd(27)} ${status}`);
75
+ }
76
+ } else if (typeof data === "object") {
77
+ for (const [key, val] of Object.entries(data)) {
78
+ console.log(` ${key}: ${JSON.stringify(val)}`);
79
+ }
80
+ }
81
+ console.log();
82
+ }
83
+
84
+ export async function showServicesDeps() {
85
+ const data = await get("/api/services/dependencies");
86
+ if (!data) {
87
+ console.log("Could not fetch service dependencies.");
88
+ return;
89
+ }
90
+
91
+ console.log();
92
+ console.log(`\x1b[1m SERVICE DEPENDENCIES\x1b[0m`);
93
+ console.log(` ${"─".repeat(50)}`);
94
+ if (Array.isArray(data)) {
95
+ for (const d of data) {
96
+ const from = truncate(d.from || d.service || "?", 20);
97
+ const to = truncate(d.to || d.depends_on || "?", 20);
98
+ console.log(` ${from.padEnd(22)} \x1b[2m→\x1b[0m ${to}`);
99
+ }
100
+ } else if (typeof data === "object") {
101
+ for (const [key, val] of Object.entries(data)) {
102
+ console.log(` ${key}: ${JSON.stringify(val)}`);
103
+ }
104
+ }
105
+ console.log();
106
+ }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Traceability commands: trace, trace coverage, trace idea, trace spec
3
+ */
4
+
5
+ import { get } from "../api.mjs";
6
+
7
+ function truncate(str, len) {
8
+ if (!str) return "";
9
+ return str.length > len ? str.slice(0, len - 1) + "\u2026" : str;
10
+ }
11
+
12
+ export async function showTraceability() {
13
+ const data = await get("/api/traceability");
14
+ if (!data) {
15
+ console.log("Could not fetch traceability.");
16
+ return;
17
+ }
18
+
19
+ console.log();
20
+ console.log(`\x1b[1m TRACEABILITY\x1b[0m`);
21
+ console.log(` ${"─".repeat(50)}`);
22
+ for (const [key, val] of Object.entries(data)) {
23
+ console.log(` ${key}: ${JSON.stringify(val)}`);
24
+ }
25
+ console.log();
26
+ }
27
+
28
+ export async function showCoverage() {
29
+ const data = await get("/api/traceability/coverage");
30
+ if (!data) {
31
+ console.log("Could not fetch traceability coverage.");
32
+ return;
33
+ }
34
+
35
+ console.log();
36
+ console.log(`\x1b[1m TRACEABILITY COVERAGE\x1b[0m`);
37
+ console.log(` ${"─".repeat(50)}`);
38
+ if (data.coverage != null) {
39
+ const pct = typeof data.coverage === "number" ? `${(data.coverage * 100).toFixed(1)}%` : data.coverage;
40
+ console.log(` Coverage: ${pct}`);
41
+ }
42
+ for (const [key, val] of Object.entries(data)) {
43
+ if (key !== "coverage") console.log(` ${key}: ${JSON.stringify(val)}`);
44
+ }
45
+ console.log();
46
+ }
47
+
48
+ export async function traceIdea(args) {
49
+ const id = args[0];
50
+ if (!id) {
51
+ console.log("Usage: cc trace idea <id>");
52
+ return;
53
+ }
54
+ const data = await get(`/api/traceability/idea/${encodeURIComponent(id)}`);
55
+ if (!data) {
56
+ console.log(`No traceability data for idea '${id}'.`);
57
+ return;
58
+ }
59
+
60
+ console.log();
61
+ console.log(`\x1b[1m TRACE: IDEA\x1b[0m ${id}`);
62
+ console.log(` ${"─".repeat(50)}`);
63
+ if (data.specs && Array.isArray(data.specs)) {
64
+ console.log(` Linked specs: ${data.specs.length}`);
65
+ for (const s of data.specs) {
66
+ console.log(` ${truncate(s.id || s.name || JSON.stringify(s), 50)}`);
67
+ }
68
+ }
69
+ if (data.contributions && Array.isArray(data.contributions)) {
70
+ console.log(` Contributions: ${data.contributions.length}`);
71
+ }
72
+ // Fallback
73
+ const shown = new Set(["specs", "contributions"]);
74
+ for (const [key, val] of Object.entries(data)) {
75
+ if (!shown.has(key)) console.log(` ${key}: ${JSON.stringify(val)}`);
76
+ }
77
+ console.log();
78
+ }
79
+
80
+ export async function traceSpec(args) {
81
+ const id = args[0];
82
+ if (!id) {
83
+ console.log("Usage: cc trace spec <id>");
84
+ return;
85
+ }
86
+ const data = await get(`/api/traceability/spec/${encodeURIComponent(id)}`);
87
+ if (!data) {
88
+ console.log(`No traceability data for spec '${id}'.`);
89
+ return;
90
+ }
91
+
92
+ console.log();
93
+ console.log(`\x1b[1m TRACE: SPEC\x1b[0m ${id}`);
94
+ console.log(` ${"─".repeat(50)}`);
95
+ if (data.ideas && Array.isArray(data.ideas)) {
96
+ console.log(` Linked ideas: ${data.ideas.length}`);
97
+ for (const i of data.ideas) {
98
+ console.log(` ${truncate(i.id || i.name || JSON.stringify(i), 50)}`);
99
+ }
100
+ }
101
+ // Fallback
102
+ const shown = new Set(["ideas"]);
103
+ for (const [key, val] of Object.entries(data)) {
104
+ if (!shown.has(key)) console.log(` ${key}: ${JSON.stringify(val)}`);
105
+ }
106
+ console.log();
107
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Treasury commands: treasury, treasury deposits, treasury deposit
3
+ */
4
+
5
+ import { get, post } from "../api.mjs";
6
+
7
+ export async function showTreasury() {
8
+ const data = await get("/api/treasury");
9
+ if (!data) {
10
+ console.log("Could not fetch treasury.");
11
+ return;
12
+ }
13
+
14
+ console.log();
15
+ console.log(`\x1b[1m TREASURY\x1b[0m`);
16
+ console.log(` ${"─".repeat(50)}`);
17
+ if (data.total != null) console.log(` Total: ${data.total}`);
18
+ if (data.balance != null) console.log(` Balance: ${data.balance}`);
19
+ if (data.deposits_count != null) console.log(` Deposits: ${data.deposits_count}`);
20
+ if (data.last_updated) console.log(` Updated: ${data.last_updated}`);
21
+ // Fallback: print all keys
22
+ const shown = new Set(["total", "balance", "deposits_count", "last_updated"]);
23
+ for (const [key, val] of Object.entries(data)) {
24
+ if (!shown.has(key) && val != null) {
25
+ console.log(` ${key}: ${JSON.stringify(val)}`);
26
+ }
27
+ }
28
+ console.log();
29
+ }
30
+
31
+ export async function showDeposits(args) {
32
+ const contributor = args[0];
33
+ if (!contributor) {
34
+ console.log("Usage: cc treasury deposits <contributor-id>");
35
+ return;
36
+ }
37
+ const data = await get(`/api/treasury/deposits/${encodeURIComponent(contributor)}`);
38
+ const deposits = Array.isArray(data) ? data : data?.deposits;
39
+ if (!deposits || !Array.isArray(deposits)) {
40
+ console.log(`No deposits found for '${contributor}'.`);
41
+ return;
42
+ }
43
+
44
+ console.log();
45
+ console.log(`\x1b[1m DEPOSITS\x1b[0m for ${contributor} (${deposits.length})`);
46
+ console.log(` ${"─".repeat(60)}`);
47
+ for (const d of deposits) {
48
+ const amount = d.amount != null ? `${d.amount}` : "?";
49
+ const asset = d.asset || d.asset_type || "";
50
+ const date = d.created_at ? d.created_at.slice(0, 10) : "";
51
+ console.log(` ${amount.padEnd(12)} ${asset.padEnd(15)} ${date}`);
52
+ }
53
+ console.log();
54
+ }
55
+
56
+ export async function makeDeposit(args) {
57
+ const amount = parseFloat(args[0]);
58
+ const asset = args[1];
59
+ if (isNaN(amount) || !asset) {
60
+ console.log("Usage: cc treasury deposit <amount> <asset>");
61
+ return;
62
+ }
63
+ const result = await post("/api/treasury/deposit", { amount, asset });
64
+ if (result) {
65
+ console.log(`\x1b[32m✓\x1b[0m Deposited ${amount} ${asset}`);
66
+ } else {
67
+ console.log("Deposit failed.");
68
+ }
69
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coherence-cli",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Coherence Network CLI \u2014 trace ideas from inception to payout, with fair attribution, coherence scoring, and 37 identity providers. No signup needed.",
5
5
  "type": "module",
6
6
  "bin": {