@rine-network/cli 0.11.1 → 0.11.3
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/dist/main.js +53 -5
- package/package.json +2 -2
package/dist/main.js
CHANGED
|
@@ -1634,9 +1634,11 @@ function isRevoked(err) {
|
|
|
1634
1634
|
}
|
|
1635
1635
|
/**
|
|
1636
1636
|
* Resolve the HMAC secret: --secret-env > --secret-file > the persisted file.
|
|
1637
|
-
* Returns "" (
|
|
1638
|
-
* empty secret
|
|
1639
|
-
*
|
|
1637
|
+
* Returns "" (after a stderr warning naming the three sources tried) when none is
|
|
1638
|
+
* found. An empty secret is NOT safe to run with: an attacker who controls the
|
|
1639
|
+
* body can compute `HMAC("", body)` and forge a "verified" self-send (T1), so the
|
|
1640
|
+
* caller (runRelayLoop) HARD-REFUSES to start on an empty result — the relay never
|
|
1641
|
+
* enters the reconnect loop or opens the listener without a secret.
|
|
1640
1642
|
*/
|
|
1641
1643
|
function resolveSecret(opts, configDir, agentId) {
|
|
1642
1644
|
if (opts.secretEnv) {
|
|
@@ -1683,6 +1685,11 @@ async function runRelayLoop(ctx) {
|
|
|
1683
1685
|
const json = gOpts.json;
|
|
1684
1686
|
const port = parsePort(opts.port);
|
|
1685
1687
|
const secret = resolveSecret(opts, configDir, agentId);
|
|
1688
|
+
if (secret.length === 0) {
|
|
1689
|
+
printError(`No hook secret resolved for '${opts.hook}' — refusing to start. Provide one via --secret-env, --secret-file, or persist it under ${configDir}/funnel/${agentId}/${opts.hook}.secret.`);
|
|
1690
|
+
process.exitCode = 2;
|
|
1691
|
+
return;
|
|
1692
|
+
}
|
|
1686
1693
|
const options = { staging: opts.staging };
|
|
1687
1694
|
let backoff = 1;
|
|
1688
1695
|
let attempt = 0;
|
|
@@ -1845,6 +1852,44 @@ function hookLabel(hostname) {
|
|
|
1845
1852
|
return hostname.endsWith(".hook.rine.network") ? hostname.slice(0, -18) : hostname;
|
|
1846
1853
|
}
|
|
1847
1854
|
//#endregion
|
|
1855
|
+
//#region src/commands/stream-cursor.ts
|
|
1856
|
+
function cursorPath(configDir) {
|
|
1857
|
+
return join(configDir, "state", "stream-cursor.json");
|
|
1858
|
+
}
|
|
1859
|
+
function loadCursorMap(configDir) {
|
|
1860
|
+
try {
|
|
1861
|
+
const raw = fs.readFileSync(cursorPath(configDir), "utf-8");
|
|
1862
|
+
const parsed = JSON.parse(raw);
|
|
1863
|
+
return parsed && typeof parsed === "object" ? parsed : {};
|
|
1864
|
+
} catch {
|
|
1865
|
+
return {};
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
/** Return the last persisted event id for an agent, or undefined if none/unreadable. */
|
|
1869
|
+
function loadStreamCursor(configDir, agentId) {
|
|
1870
|
+
const value = loadCursorMap(configDir)[agentId];
|
|
1871
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
1872
|
+
}
|
|
1873
|
+
/** Persist the last-seen event id for an agent (best-effort, atomic, no-op if unchanged). */
|
|
1874
|
+
function saveStreamCursor(configDir, agentId, eventId) {
|
|
1875
|
+
if (!eventId) return;
|
|
1876
|
+
try {
|
|
1877
|
+
const map = loadCursorMap(configDir);
|
|
1878
|
+
if (map[agentId] === eventId) return;
|
|
1879
|
+
map[agentId] = eventId;
|
|
1880
|
+
const dir = join(configDir, "state");
|
|
1881
|
+
fs.mkdirSync(dir, {
|
|
1882
|
+
recursive: true,
|
|
1883
|
+
mode: 448
|
|
1884
|
+
});
|
|
1885
|
+
const path = cursorPath(configDir);
|
|
1886
|
+
const tmp = `${path}.tmp`;
|
|
1887
|
+
fs.writeFileSync(tmp, JSON.stringify(map), "utf-8");
|
|
1888
|
+
fs.renameSync(tmp, path);
|
|
1889
|
+
fs.chmodSync(path, 384);
|
|
1890
|
+
} catch {}
|
|
1891
|
+
}
|
|
1892
|
+
//#endregion
|
|
1848
1893
|
//#region src/commands/stream.ts
|
|
1849
1894
|
function emitLifecycle(gOpts, monitor, data) {
|
|
1850
1895
|
if (gOpts.json) {
|
|
@@ -1903,7 +1948,7 @@ function registerStream(program) {
|
|
|
1903
1948
|
let url = `${apiUrl}/agents/${agentId}/stream`;
|
|
1904
1949
|
if (opts.persistent) url += "?persistent=true";
|
|
1905
1950
|
const heartbeatTimeoutMs = Math.max(Number(opts.heartbeatTimeout) || 70, 10) * 1e3;
|
|
1906
|
-
let lastEventId;
|
|
1951
|
+
let lastEventId = loadStreamCursor(configDir, agentId);
|
|
1907
1952
|
let backoff = 1;
|
|
1908
1953
|
let attempt = 0;
|
|
1909
1954
|
let stopped = false;
|
|
@@ -1948,7 +1993,10 @@ function registerStream(program) {
|
|
|
1948
1993
|
headers,
|
|
1949
1994
|
onMessage: ({ event, data, id }) => {
|
|
1950
1995
|
resetHeartbeatTimer();
|
|
1951
|
-
if (id)
|
|
1996
|
+
if (id) {
|
|
1997
|
+
lastEventId = id;
|
|
1998
|
+
saveStreamCursor(configDir, agentId, id);
|
|
1999
|
+
}
|
|
1952
2000
|
if (gOpts.json) {
|
|
1953
2001
|
if (!opts.monitor || event === "message") console.log(JSON.stringify({
|
|
1954
2002
|
event,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rine-network/cli",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.3",
|
|
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.
|
|
31
|
+
"@rine-network/core": "^0.6.2",
|
|
32
32
|
"commander": "^12.0.0",
|
|
33
33
|
"eventsource-client": "^1.1.0"
|
|
34
34
|
},
|