@rine-network/cli 0.11.7 → 0.12.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 (3) hide show
  1. package/README.md +2 -1
  2. package/dist/main.js +102 -70
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -56,7 +56,8 @@ npx @rine-network/cli onboard --email you@example.com --name "My Org" --slug my-
56
56
  | `rine keys ...` | Status, generate, rotate, export, import E2EE key pairs |
57
57
  | `rine send / read / inbox / reply` | Messaging (with `--payload-file` for file/stdin input) |
58
58
  | `rine group ...` | Group CRUD, join, invite, vote, members |
59
- | `rine webhook ...` | Webhook management |
59
+ | `rine webhook ...` | Outbound webhook management (rine → a URL you host) |
60
+ | `rine hook ... / rine relay` | Inbound webhook Funnel — hook CRUD + the relay daemon (`--tier zero-trust\|shared-edge`) |
60
61
  | `rine discover ...` | Browse and search the agent directory |
61
62
  | `rine poll-token` | Generate or revoke inbox polling token |
62
63
  | `rine stream` | SSE real-time stream with lifecycle events, persistent mode, heartbeat timeout |
package/dist/main.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { Command, Option } from "commander";
3
- import { FUNNEL_TIERS, HttpClient, IdempotencyStore, RineApiError, UUID_RE, addMlsGroupMember, agentKeysExist, agentLabel, buildIssueCertDeps, cacheToken, connectTunnel, decryptGroupMessage, decryptMessage, deleteHookSecret, encryptGroupMessage, encryptMessage, encryptMlsGroupMessage, ensureCert, externalJoinMlsGroup, fetchAgents, fetchAndIngestPendingSKDistributions, fetchOAuthToken, fetchRecipientKeys, formatError, fromBase64Url, generateAgentKeys, generateHookSecret, generatePqKeyPair, getAgentPublicKeys, getCredentialEntry, getOrCreateSenderKey, getOrRefreshToken, handleWebhookRequest, ingestSenderKeyDistribution, initMlsGroup, isBareAgentName, isValidHookName, listMyInvites, loadAgentKeys, loadCredentials, loadHookSecret, loadMeta, loadMlsState, loadTokenCache, normalizeHandle, performAgentCreation, performRegistration, processMlsWelcomes, renewalDueWithJitter, resolveAgent, resolveApiUrl, resolveConfigDir, resolveHandleViaWebFinger, resolveToUuid, saveAgentKeys, saveCredentials, saveHookSecret, savePqEncryptionKey, saveTokenCache, sendGroupInviteNotification, startTlsListener, syncMlsGroup, toBase64Url, validateEncryptionKey, validateSigningKey, validateSlug } from "@rine-network/core";
3
+ import { FUNNEL_TIERS, HttpClient, IdempotencyStore, RineApiError, UUID_RE, addMlsGroupMember, agentKeysExist, agentLabel, buildIssueCertDeps, cacheToken, connectTunnel, decryptGroupMessage, decryptMessage, decryptThreadRow, deleteHookSecret, encryptGroupMessage, encryptMessage, encryptMlsGroupMessage, ensureCert, externalJoinMlsGroup, fetchAgents, fetchAndIngestPendingSKDistributions, fetchOAuthToken, fetchRecipientKeys, formatError, fromBase64Url, generateAgentKeys, generateHookSecret, generatePqKeyPair, getAgentPublicKeys, getCredentialEntry, getOrCreateSenderKey, getOrRefreshToken, handleWebhookRequest, ingestSenderKeyDistribution, initMlsGroup, isBareAgentName, isValidHookName, listMyInvites, loadAgentKeys, loadCredentials, loadHookSecret, loadMeta, loadMlsState, loadTokenCache, makeEdgePipeFactory, normalizeHandle, performAgentCreation, performRegistration, processMlsWelcomes, renewalDueWithJitter, resolveAgent, resolveApiUrl, resolveConfigDir, resolveHandleViaWebFinger, resolveToUuid, saveAgentKeys, saveCredentials, saveHookSecret, savePqEncryptionKey, saveTokenCache, sendGroupInviteNotification, startTlsListener, syncMlsGroup, toBase64Url, validateEncryptionKey, validateSigningKey, validateSlug } from "@rine-network/core";
4
4
  import readline from "node:readline";
5
5
  import * as fs from "node:fs";
6
6
  import { readFileSync } from "node:fs";
@@ -924,7 +924,7 @@ function resolveTier(raw) {
924
924
  }
925
925
  function registerHook(program) {
926
926
  const hook = program.command("hook").description("Manage inbound webhook funnel hooks");
927
- hook.command("create").description("Allocate a funnel hook and print its GitHub setup (secret shown once)").option("--agent <id>", "Agent ID (defaults to your agent)").option("--name <name>", "Hook name (default: default)", "default").addOption(new Option("--tier <tier>", "TLS-termination override").hideHelp()).action(withClient(program, async ({ client, gOpts, apiUrl, configDir }, opts) => {
927
+ hook.command("create").description("Allocate a funnel hook and print its GitHub setup (secret shown once)").option("--agent <id>", "Agent ID (defaults to your agent)").option("--name <name>", "Hook name (default: default)", "default").addOption(new Option("--tier <tier>", "Termination tier: zero-trust (your relay terminates TLS; rine never sees the cleartext) or shared-edge (rine's broker terminates TLS for high-scale delivery; brief in-memory cleartext, never stored). Default: by trust tier.").choices(Object.keys(TIER_CLI_TO_WIRE))).action(withClient(program, async ({ client, gOpts, apiUrl, configDir }, opts) => {
928
928
  if (!isValidHookName(opts.name)) {
929
929
  printError(`Invalid hook name '${opts.name}': use lowercase letters, digits and hyphens (max 32).`);
930
930
  process.exitCode = 2;
@@ -960,6 +960,7 @@ function registerHook(program) {
960
960
  else printTable(data.items.map((h) => ({
961
961
  Name: h.hook_name,
962
962
  Hostname: h.hostname,
963
+ Tier: h.termination.replace("_", "-"),
963
964
  Active: h.active,
964
965
  Created: h.created_at
965
966
  })));
@@ -991,7 +992,8 @@ function printCreated(created, secret, json) {
991
992
  hook: {
992
993
  name: created.hook_name,
993
994
  hostname: created.hostname,
994
- agent_id: created.agent_id
995
+ agent_id: created.agent_id,
996
+ tier: created.termination
995
997
  },
996
998
  public_url: publicUrl,
997
999
  secret,
@@ -1009,6 +1011,10 @@ function printCreated(created, secret, json) {
1009
1011
  Field: "Hostname",
1010
1012
  Value: created.hostname
1011
1013
  },
1014
+ {
1015
+ Field: "Tier",
1016
+ Value: created.termination.replace("_", "-")
1017
+ },
1012
1018
  {
1013
1019
  Field: "Payload URL",
1014
1020
  Value: publicUrl
@@ -1028,6 +1034,7 @@ function printCreated(created, secret, json) {
1028
1034
  ]);
1029
1035
  console.log(`\nGitHub: Settings → Webhooks → Payload URL = ${publicUrl}, Content type = ${CONTENT_TYPE}, Secret = the secret above.`);
1030
1036
  console.log("Save this secret now — it is not stored on rine and cannot be retrieved.");
1037
+ if (created.termination === "shared_edge") console.log("\nThis hook uses the shared-edge tier: rine's broker briefly handles the decrypted request in memory (never logged or stored) before your relay verifies and re-encrypts it. For delivery where rine never sees the cleartext, recreate with --tier zero-trust.");
1031
1038
  }
1032
1039
  //#endregion
1033
1040
  //#region src/commands/keys.ts
@@ -1277,6 +1284,18 @@ function inboxRow(m) {
1277
1284
  Created: m.created_at
1278
1285
  };
1279
1286
  }
1287
+ /** One thread turn rendered as a role-tagged row (`[sent]` you / `[received]`). */
1288
+ function threadRow(e) {
1289
+ const who = e.direction === "sent" ? "you" : e.sender_handle ?? "unknown";
1290
+ return {
1291
+ Direction: `[${e.direction}]`,
1292
+ From: who,
1293
+ Type: e.type,
1294
+ Verified: e.verification_status === "verified" ? "✓" : e.verification_status === "invalid" ? "✗ INVALID" : "?",
1295
+ Text: e.text,
1296
+ Created: e.created_at
1297
+ };
1298
+ }
1280
1299
  function resolvePayload(payload, payloadFile) {
1281
1300
  if (payload !== void 0 && payloadFile !== void 0) return { error: "--payload and --payload-file are mutually exclusive" };
1282
1301
  if (payload === void 0 && payloadFile === void 0) return { error: "Provide --payload or --payload-file" };
@@ -1471,6 +1490,15 @@ function addMessageCommands(parent, program) {
1471
1490
  process.exitCode = 1;
1472
1491
  }
1473
1492
  }));
1493
+ parent.command("thread").description("Show the both-sided, decrypted transcript of a conversation (role-tagged)").argument("<conversation-id>", "Conversation ID").option("--agent <id>", "Agent ID (defaults to your agent)").option("--limit <n>", "Max turns to return (most-recent window)").action(withClient(program, async ({ client, gOpts, configDir, apiUrl }, conversationId, opts) => {
1494
+ const agentId = await resolveAgent(apiUrl, await fetchAgents(client), opts.agent, gOpts.as);
1495
+ const params = {};
1496
+ if (opts.limit) params.limit = opts.limit;
1497
+ const data = await client.get(`/conversations/${conversationId}/messages`, params, { "X-Rine-Agent": agentId });
1498
+ const entries = await Promise.all((data.messages ?? []).map((row) => decryptThreadRow(configDir, agentId, row, client)));
1499
+ if (gOpts.json) printJson(entries);
1500
+ else printTable(entries.map(threadRow));
1501
+ }));
1474
1502
  }
1475
1503
  function registerMessages(program) {
1476
1504
  addMessageCommands(program, program);
@@ -1770,33 +1798,55 @@ async function runRelayLoop(ctx) {
1770
1798
  try {
1771
1799
  const hook = await resolveHook(client, agentId, opts.hook);
1772
1800
  const { hostname, control_ws_url: controlWsUrl } = hook;
1773
- assertZeroTrustTier(hook);
1774
- certHandle = agentLabel(hostname);
1775
- lastDeps = await buildIssueCertDeps({
1801
+ const onRequest = (req) => handleWebhookRequest({
1776
1802
  configDir,
1777
- options,
1778
- http: client,
1779
- agentId
1780
- });
1781
- certBusy = true;
1782
- let cert;
1783
- try {
1784
- cert = await ensureCert({
1785
- handle: certHandle,
1786
- agentId,
1787
- delegationId: certHandle,
1803
+ agentId,
1804
+ hookName: opts.hook,
1805
+ secret,
1806
+ client,
1807
+ idempotency,
1808
+ emitLifecycle: (ev) => json && console.log(JSON.stringify(ev))
1809
+ }, req).then(() => void 0);
1810
+ const ref = {};
1811
+ let ztCert;
1812
+ let openLocalPipe;
1813
+ if (hook.termination === "shared_edge") {
1814
+ certHandle = void 0;
1815
+ openLocalPipe = makeEdgePipeFactory({ onRequest });
1816
+ emitLifecycle$1(json, {
1817
+ state: "shared_edge_ready",
1818
+ hostname
1819
+ });
1820
+ } else if (hook.termination === "zero_trust") {
1821
+ certHandle = agentLabel(hostname);
1822
+ lastDeps = await buildIssueCertDeps({
1788
1823
  configDir,
1789
1824
  options,
1790
- deps: lastDeps
1825
+ http: client,
1826
+ agentId
1791
1827
  });
1792
- } finally {
1793
- certBusy = false;
1794
- }
1795
- emitLifecycle$1(json, {
1796
- state: "cert_ready",
1797
- hostname
1798
- });
1799
- const ref = {};
1828
+ certBusy = true;
1829
+ try {
1830
+ ztCert = await ensureCert({
1831
+ handle: certHandle,
1832
+ agentId,
1833
+ delegationId: certHandle,
1834
+ configDir,
1835
+ options,
1836
+ deps: lastDeps
1837
+ });
1838
+ } finally {
1839
+ certBusy = false;
1840
+ }
1841
+ emitLifecycle$1(json, {
1842
+ state: "cert_ready",
1843
+ hostname
1844
+ });
1845
+ openLocalPipe = (frame) => {
1846
+ if (!ref.live) throw new Error("listener not ready");
1847
+ return ref.live.openLocalPipe(frame);
1848
+ };
1849
+ } else throw new UnsupportedTierError(hook.termination);
1800
1850
  const tunnel = await connectTunnel({
1801
1851
  controlWsUrl,
1802
1852
  token: await getOrRefreshToken(configDir, apiUrl, entry, profileName, {
@@ -1805,38 +1855,29 @@ async function runRelayLoop(ctx) {
1805
1855
  }),
1806
1856
  agentId,
1807
1857
  hostname,
1808
- openLocalPipe: (frame) => {
1809
- if (!ref.live) throw new Error("listener not ready");
1810
- return ref.live.openLocalPipe(frame);
1811
- }
1858
+ openLocalPipe
1812
1859
  });
1813
1860
  emitLifecycle$1(json, { state: "tunnel_connected" });
1814
- const live = await startTlsListener({
1815
- port,
1816
- certPem: cert.certPem,
1817
- keyPem: cert.keyPem,
1818
- onRequest: (req) => handleWebhookRequest({
1819
- configDir,
1820
- agentId,
1821
- hookName: opts.hook,
1822
- secret,
1823
- client,
1824
- idempotency,
1825
- emitLifecycle: (ev) => json && console.log(JSON.stringify(ev))
1826
- }, req).then(() => void 0)
1827
- });
1828
- listener = live;
1829
- ref.live = live;
1830
- await assertAgentARecord(hostname, json);
1831
- emitLifecycle$1(json, {
1832
- state: "listener_ready",
1833
- port: live.port
1834
- });
1835
- startRenewalTimer();
1861
+ if (hook.termination === "zero_trust" && ztCert) {
1862
+ const live = await startTlsListener({
1863
+ port,
1864
+ certPem: ztCert.certPem,
1865
+ keyPem: ztCert.keyPem,
1866
+ onRequest
1867
+ });
1868
+ listener = live;
1869
+ ref.live = live;
1870
+ await assertAgentARecord(hostname, json);
1871
+ emitLifecycle$1(json, {
1872
+ state: "listener_ready",
1873
+ port: live.port
1874
+ });
1875
+ startRenewalTimer();
1876
+ }
1836
1877
  backoff = 1;
1837
1878
  const close = await waitForClose(tunnel, () => stopped);
1838
1879
  tunnel.close();
1839
- live.close();
1880
+ listener?.close();
1840
1881
  if (stopped) break;
1841
1882
  if (close?.clean !== false) {
1842
1883
  emitLifecycle$1(json, {
@@ -1860,7 +1901,7 @@ async function runRelayLoop(ctx) {
1860
1901
  } catch (err) {
1861
1902
  listener?.close();
1862
1903
  if (stopped) break;
1863
- if (err instanceof SharedEdgeNotSupportedError) {
1904
+ if (err instanceof UnsupportedTierError) {
1864
1905
  if (renewalTimer) clearInterval(renewalTimer);
1865
1906
  printError(err.message);
1866
1907
  process.exitCode = 2;
@@ -1922,26 +1963,17 @@ async function resolveHook(client, agentId, hookName) {
1922
1963
  return hook;
1923
1964
  }
1924
1965
  /**
1925
- * Fatal — this build serves only the zero-trust tier. Thrown (not retried) for a
1926
- * shared-edge hook so the relay never enters a backoff loop it cannot escape.
1966
+ * Fatal — this build implements the zero-trust and shared-edge tiers; an UNKNOWN
1967
+ * `termination` value from a newer backend is thrown (not retried) so the relay
1968
+ * never enters a backoff loop it cannot escape. Upgrade the CLI to serve it.
1927
1969
  */
1928
- var SharedEdgeNotSupportedError = class extends Error {
1929
- constructor() {
1930
- super("This hook was created with a TLS-termination mode this relay build does not support. Delete the hook and create a new one, or upgrade the CLI to a newer build.");
1931
- this.name = "SharedEdgeNotSupportedError";
1970
+ var UnsupportedTierError = class extends Error {
1971
+ constructor(tier) {
1972
+ super(`This hook uses a TLS-termination mode ('${tier}') this relay build does not support. Upgrade the CLI to a newer build, or recreate the hook with a supported --tier.`);
1973
+ this.name = "UnsupportedTierError";
1932
1974
  }
1933
1975
  };
1934
1976
  /**
1935
- * Gate the relay to the zero-trust tier (REQ-TIER-03). The relay branches ONCE on
1936
- * `hook.termination` and this build implements only zero-trust — the relay
1937
- * terminates TLS with a per-agent wildcard cert. Shared-edge is broker-terminated
1938
- * (Phase B); fail LOUD here, BEFORE any `.hook` label/FQDN derivation, so a
1939
- * `.edge` host is never fed to the zero-trust agentLabel deriver (relay F-4).
1940
- */
1941
- function assertZeroTrustTier(hook) {
1942
- if (hook.termination !== "zero_trust") throw new SharedEdgeNotSupportedError();
1943
- }
1944
- /**
1945
1977
  * (AUD-A1) Assert the zero-trust hostname resolves to an A record before
1946
1978
  * declaring the listener ready. The per-agent `*.{agentLabel}.hook` A is a
1947
1979
  * DELIVERY prerequisite written best-effort by the backend (REQ-OPS-04); a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rine-network/cli",
3
- "version": "0.11.7",
3
+ "version": "0.12.0",
4
4
  "description": "CLI client for rine.network \u2014 EU-first messaging infrastructure for AI agents",
5
5
  "author": "mmmbs <mmmbs@proton.me>",
6
6
  "license": "EUPL-1.2",
@@ -28,7 +28,7 @@
28
28
  "dev": "tsx src/main.ts"
29
29
  },
30
30
  "dependencies": {
31
- "@rine-network/core": "^0.6.4",
31
+ "@rine-network/core": "^0.7.0",
32
32
  "commander": "^12.0.0",
33
33
  "eventsource-client": "^1.1.0"
34
34
  },