@rine-network/cli 0.25.0 → 0.26.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 +1 -1
- package/dist/main.js +148 -60
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -115,7 +115,7 @@ An agent is named by ID, handle or unique name; a name that matches no agent, or
|
|
|
115
115
|
|
|
116
116
|
`rine org rules show` lists the organisation's rules and `rine org rules set <rule> <mode>` changes one (`off`, `report` or `enforce`; not every rule takes `report`).
|
|
117
117
|
|
|
118
|
-
A delegated key lets a person or system suspend, freeze
|
|
118
|
+
A delegated key lets a person or system suspend, freeze, resume, read the event or metadata logs, or write counterparty and rules entries without holding the org key. Scopes: `events:read`, `metadata:read`, `counterparty:write`, `policy:write`, `suspend`, `freeze`, `resume`. It cannot read messages or create keys:
|
|
119
119
|
|
|
120
120
|
```sh
|
|
121
121
|
rine org delegate create --name oncall --scope suspend,freeze,resume
|
package/dist/main.js
CHANGED
|
@@ -670,19 +670,31 @@ function toAgentRow(a, opts = {}) {
|
|
|
670
670
|
}
|
|
671
671
|
//#endregion
|
|
672
672
|
//#region src/prompt.ts
|
|
673
|
-
|
|
674
|
-
|
|
673
|
+
const NON_TTY_ANSWER_TIMEOUT_MS = 3e4;
|
|
674
|
+
/** Read one line; undefined when stdin ends without an answer. */
|
|
675
|
+
function readAnswer(question) {
|
|
676
|
+
if (process.stdin.isTTY !== true) process.stderr.write("stdin is not a terminal: this question needs a person to answer it.\n");
|
|
675
677
|
const rl = readline.createInterface({
|
|
676
678
|
input: process.stdin,
|
|
677
679
|
output: process.stdout
|
|
678
680
|
});
|
|
679
681
|
return new Promise((resolve) => {
|
|
682
|
+
const timer = process.stdin.isTTY === true ? void 0 : setTimeout(() => rl.close(), NON_TTY_ANSWER_TIMEOUT_MS);
|
|
683
|
+
rl.once("close", () => {
|
|
684
|
+
clearTimeout(timer);
|
|
685
|
+
resolve(void 0);
|
|
686
|
+
});
|
|
680
687
|
rl.question(question, (answer) => {
|
|
681
|
-
|
|
688
|
+
clearTimeout(timer);
|
|
682
689
|
resolve(answer.trim());
|
|
690
|
+
rl.close();
|
|
683
691
|
});
|
|
684
692
|
});
|
|
685
693
|
}
|
|
694
|
+
/** Prompt for a plain-text value on stdout/stdin. Empty when stdin ends without an answer. */
|
|
695
|
+
async function promptText(question) {
|
|
696
|
+
return await readAnswer(question) ?? "";
|
|
697
|
+
}
|
|
686
698
|
/** Prompt for a secret value with hidden input (raw mode). */
|
|
687
699
|
async function promptPassword(question) {
|
|
688
700
|
return new Promise((resolve) => {
|
|
@@ -710,7 +722,12 @@ async function promptPassword(question) {
|
|
|
710
722
|
}
|
|
711
723
|
/** Prompt for yes/no confirmation (defaults to No). Returns true if user types y/Y. */
|
|
712
724
|
async function promptConfirm(question) {
|
|
713
|
-
|
|
725
|
+
const answer = await readAnswer(`${question} [y/N] `);
|
|
726
|
+
if (answer === void 0) {
|
|
727
|
+
process.stderr.write("\nno answer (not a terminal): nothing was changed. This needs a person at a terminal — ask the user to run the command in their own terminal, outside this session.\n");
|
|
728
|
+
return false;
|
|
729
|
+
}
|
|
730
|
+
return answer.toLowerCase() === "y";
|
|
714
731
|
}
|
|
715
732
|
//#endregion
|
|
716
733
|
//#region src/commands/agent-exposure-create.ts
|
|
@@ -3144,7 +3161,7 @@ function resolveTier(raw) {
|
|
|
3144
3161
|
}
|
|
3145
3162
|
function registerHook(program) {
|
|
3146
3163
|
const hook = program.command("hook").description("Manage inbound webhook funnel hooks");
|
|
3147
|
-
hook.command("create").description("Allocate a funnel hook
|
|
3164
|
+
hook.command("create").description("Allocate a funnel hook: a public HTTPS URL whose webhook calls reach this agent through rine relay (prints the URL, the secret once and GitHub setup steps)").addOption(actorOption()).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, dirs: { configDir }, actingAgent }, opts) => {
|
|
3148
3165
|
if (refuseHookName(opts.name, hookNameError(opts.name))) return;
|
|
3149
3166
|
let tier;
|
|
3150
3167
|
try {
|
|
@@ -5203,7 +5220,7 @@ async function revoke(ctx, ref) {
|
|
|
5203
5220
|
else printText(`Delegated key ${id} revoked. Its next request is refused; tokens it already holds stop working with it.`);
|
|
5204
5221
|
}
|
|
5205
5222
|
function registerOrgDelegate(org, program) {
|
|
5206
|
-
const delegate = org.command("delegate").description("Delegated keys
|
|
5223
|
+
const delegate = org.command("delegate").description("Delegated keys limited to the scopes you give: read events or metadata, write allow and block entries or rules, suspend, freeze, resume");
|
|
5207
5224
|
delegate.command("create").description("Create a delegated key and a profile of the same name that signs with it").requiredOption("--name <name>", "Key and profile name").requiredOption("--scope <scopes>", "Comma-separated: events:read, metadata:read, suspend, freeze, resume, counterparty:write, policy:write").option("--public-key <base64url>", "Register this public key instead of generating one; no private key or profile is kept here").action(withClient(program, create));
|
|
5208
5225
|
delegate.command("list").description("List delegated keys").action(withClient(program, async ({ client, gOpts }) => {
|
|
5209
5226
|
const all = await listDelegates(client);
|
|
@@ -6024,6 +6041,50 @@ function registerOrgEventsTail(org, program) {
|
|
|
6024
6041
|
}));
|
|
6025
6042
|
}
|
|
6026
6043
|
//#endregion
|
|
6044
|
+
//#region src/commands/org-counterparties-notes.ts
|
|
6045
|
+
/** What `org counterparties allow|block` tells the caller before it writes: the entry's reach and its limits. */
|
|
6046
|
+
const RULE_OF = {
|
|
6047
|
+
[RuleDirection.Inbound]: PolicyRule.ExternalInbound,
|
|
6048
|
+
[RuleDirection.Outbound]: PolicyRule.ExternalOutbound
|
|
6049
|
+
};
|
|
6050
|
+
/** The way to turn a rule on that leaves the entry doing what its decision means. */
|
|
6051
|
+
function enforceHint(rule, decision) {
|
|
6052
|
+
return decision === Decision.Block ? `A block list works under enforce with the default allow: rine org rules set ${rule} enforce --default allow.` : `Enforce with the default deny refuses every organisation without an allow entry, so run rine org rules preview ${rule} first, then rine org rules set ${rule} enforce (--default allow|deny).`;
|
|
6053
|
+
}
|
|
6054
|
+
/**
|
|
6055
|
+
* Lines for each chosen direction whose rule is not enforced (the entry decides nothing yet), then the
|
|
6056
|
+
* whole-organisation line. `policy` is `undefined` when the key cannot read it: the rule notes are skipped.
|
|
6057
|
+
*/
|
|
6058
|
+
function entryNotes(policy, directions, decision, ref, theirAgent) {
|
|
6059
|
+
const notes = [];
|
|
6060
|
+
for (const direction of directions) {
|
|
6061
|
+
const rule = RULE_OF[direction];
|
|
6062
|
+
const mode = policy?.rules[rule].mode;
|
|
6063
|
+
if (mode !== void 0 && mode !== RuleMode.Enforce) notes.push(`${rule} is ${mode}, so this entry has no effect until the rule is enforce. ${enforceHint(rule, decision)}`);
|
|
6064
|
+
}
|
|
6065
|
+
if (ref.indexOf("@") > 0 && theirAgent === void 0) notes.push(`${ref} is an agent handle: this entry covers its whole organisation. Add --their-agent ${ref} to cover only that agent.`);
|
|
6066
|
+
return notes;
|
|
6067
|
+
}
|
|
6068
|
+
/** The policy, or `undefined` when the key lacks `policy:write`: a `counterparty:write` key still writes entries. */
|
|
6069
|
+
async function readPolicy(read) {
|
|
6070
|
+
try {
|
|
6071
|
+
return await read();
|
|
6072
|
+
} catch (err) {
|
|
6073
|
+
if (err instanceof RineApiError && err.status === 403) return void 0;
|
|
6074
|
+
throw err;
|
|
6075
|
+
}
|
|
6076
|
+
}
|
|
6077
|
+
const NOT_FOUND = "Counterparty not found. A slug resolves only for an organisation your agents have already exchanged messages with, and a new one can take a minute to appear; an agent handle or the organisation id resolves for any live organisation.";
|
|
6078
|
+
/** Awaits the lookup, rewording its 404 with the way out; any other error passes unchanged. */
|
|
6079
|
+
async function withMissHint(lookup) {
|
|
6080
|
+
try {
|
|
6081
|
+
return await lookup;
|
|
6082
|
+
} catch (err) {
|
|
6083
|
+
if (err instanceof RineApiError && err.status === 404) throw new Error(NOT_FOUND);
|
|
6084
|
+
throw err;
|
|
6085
|
+
}
|
|
6086
|
+
}
|
|
6087
|
+
//#endregion
|
|
6027
6088
|
//#region src/commands/org-rules-words.ts
|
|
6028
6089
|
/** The text `rine org rules` prints in one place. */
|
|
6029
6090
|
const NOT_COVERING_OUTBOUND = "Does not cover groups: members from any organisation can still join and post. In sender-key groups, members from organisations this rule refuses cannot read your posts once your key changes, and get no notice of invitations. MLS groups are not affected.";
|
|
@@ -6127,38 +6188,6 @@ function stoppedLines(r) {
|
|
|
6127
6188
|
return [`Lowered ${r.stopped} agents to the rule's limit.`];
|
|
6128
6189
|
}
|
|
6129
6190
|
//#endregion
|
|
6130
|
-
//#region src/commands/runtime-warning.ts
|
|
6131
|
-
/**
|
|
6132
|
-
* Detect that the CLI runs inside an agent runtime, so a rule change can warn first.
|
|
6133
|
-
* Warn, never block: the command still runs. One table of markers; each is an environment
|
|
6134
|
-
* variable that runtime sets for the processes it starts (the OpenClaw and Hermes rigs and
|
|
6135
|
-
* Claude Code in `compose.openclaw.yml`, `compose.hermes.yml` and `compose.cc.yml`).
|
|
6136
|
-
*/
|
|
6137
|
-
const RUNTIME_MARKERS = [
|
|
6138
|
-
{
|
|
6139
|
-
runtime: "Claude Code",
|
|
6140
|
-
vars: ["CLAUDECODE", "CLAUDE_CODE_ENTRYPOINT"]
|
|
6141
|
-
},
|
|
6142
|
-
{
|
|
6143
|
-
runtime: "OpenClaw",
|
|
6144
|
-
vars: ["OPENCLAW_STATE_DIR", "OPENCLAW_CONFIG_PATH"]
|
|
6145
|
-
},
|
|
6146
|
-
{
|
|
6147
|
-
runtime: "Hermes",
|
|
6148
|
-
vars: ["HERMES_HOME", "HERMES_SESSION_KEY"]
|
|
6149
|
-
}
|
|
6150
|
-
];
|
|
6151
|
-
/** The warning printed before a rule change inside an agent runtime. */
|
|
6152
|
-
const RUNTIME_WARNING = "This looks like an agent's environment. Change rules from a machine that runs no agents: an agent with a shell here can read your organisation key.";
|
|
6153
|
-
/** The runtime whose marker is set (non-empty) in `env`, or `undefined` in a plain shell. */
|
|
6154
|
-
function runtimeOf(env = process.env) {
|
|
6155
|
-
return RUNTIME_MARKERS.find((m) => m.vars.some((v) => env[v]))?.runtime;
|
|
6156
|
-
}
|
|
6157
|
-
/** Print the runtime warning on stderr when a runtime marker is set. */
|
|
6158
|
-
function warnInAgentRuntime(env = process.env) {
|
|
6159
|
-
if (runtimeOf(env) !== void 0) printError(RUNTIME_WARNING);
|
|
6160
|
-
}
|
|
6161
|
-
//#endregion
|
|
6162
6191
|
//#region src/commands/org-counterparties-write.ts
|
|
6163
6192
|
function directionsOf(opts) {
|
|
6164
6193
|
if ([
|
|
@@ -6180,8 +6209,8 @@ async function openGroups(ctx) {
|
|
|
6180
6209
|
}
|
|
6181
6210
|
}
|
|
6182
6211
|
/** The counterparty write, plus the group check with `--groups`. */
|
|
6183
|
-
async function describe(ctx, ref, groups) {
|
|
6184
|
-
const c = await lookupCounterparty(ctx.client, ref);
|
|
6212
|
+
async function describe(ctx, ref, groups, policy) {
|
|
6213
|
+
const c = await withMissHint(lookupCounterparty(ctx.client, ref));
|
|
6185
6214
|
const domains = c.proven_domains.length > 0 ? `Proven domain: ${c.proven_domains.join(", ")}.` : "No proven domain. Names and slugs are chosen by whoever registers them.";
|
|
6186
6215
|
const lines = [
|
|
6187
6216
|
`${c.name} org ${c.org_id.slice(0, 8)}… tier ${c.tier}`,
|
|
@@ -6189,10 +6218,7 @@ async function describe(ctx, ref, groups) {
|
|
|
6189
6218
|
`Check this code with a contact at ${c.name}:`,
|
|
6190
6219
|
` ${orgWords(c.org_id)}`
|
|
6191
6220
|
];
|
|
6192
|
-
if (groups)
|
|
6193
|
-
const covered = (await getPolicy(ctx.client)).groups_covered;
|
|
6194
|
-
lines.push(groupsAllowLine(await openGroups(ctx), covered));
|
|
6195
|
-
}
|
|
6221
|
+
if (groups) lines.push(groupsAllowLine(await openGroups(ctx), policy?.groups_covered ?? false));
|
|
6196
6222
|
if (!ctx.gOpts.json) for (const l of lines) printText(l);
|
|
6197
6223
|
return c.org_id;
|
|
6198
6224
|
}
|
|
@@ -6203,13 +6229,15 @@ async function theirAgentId(ctx, ref) {
|
|
|
6203
6229
|
}
|
|
6204
6230
|
function decide(program, parent, decision) {
|
|
6205
6231
|
const verb = decision === Decision.Allow ? "Allow" : "Block";
|
|
6206
|
-
const cmd = parent.command(decision).description(`${verb} an organisation
|
|
6232
|
+
const cmd = parent.command(decision).description(`${verb} an organisation in the message rules. An agent handle covers its whole organisation; to ${decision} only one agent, also pass its handle, e.g. --their-agent kofi@acme.rine.network`).argument("<ref>", "Organisation id, an agent handle (its whole organisation), or the slug of an organisation you have dealt with. Use the handle your contact gave you, or confirm a directory match with the user").option("--outbound", "Our agents sending to it").option("--inbound", "Its agents sending to ours").option("--both", "Both directions (the default)").option("--agent <ours>", "Only for one of our agents").option("--their-agent <handle>", "Only for this agent of the organisation, not the whole organisation").requiredOption("--reason <text>", "Why, required; kept with the entry").option("--yes", decision === Decision.Allow ? "Skip confirmation prompt, including the check-code confirmation: compare the code with your contact first" : "Skip confirmation prompt");
|
|
6207
6233
|
if (decision === Decision.Allow) cmd.option("--groups", "Also let it join your open groups once the group rule is on");
|
|
6208
6234
|
cmd.action(withClient(program, async (ctx, ref, opts) => {
|
|
6235
|
+
if (ctx.gOpts.json && !opts.yes) throw new Error("--json needs --yes: JSON output shows no confirmation or check code. Run it without --json to see them; add --yes only once the person has compared the code with their contact.");
|
|
6209
6236
|
const directions = directionsOf(opts);
|
|
6210
|
-
|
|
6211
|
-
const orgId = await describe(ctx, ref, opts.groups === true);
|
|
6212
|
-
if (!
|
|
6237
|
+
const policy = ctx.gOpts.json && opts.groups !== true ? void 0 : await readPolicy(() => getPolicy(ctx.client));
|
|
6238
|
+
const orgId = await describe(ctx, ref, opts.groups === true, policy);
|
|
6239
|
+
if (!ctx.gOpts.json) for (const note of entryNotes(policy, directions, decision, ref, opts.theirAgent)) printText(note);
|
|
6240
|
+
if (!opts.yes) {
|
|
6213
6241
|
if (!await promptConfirm(`${verb} ${directions.join(" and ")}?`)) return;
|
|
6214
6242
|
}
|
|
6215
6243
|
const ours = opts.agent && await resolveAgent$1(ctx, opts.agent);
|
|
@@ -6234,8 +6262,7 @@ function decide(program, parent, decision) {
|
|
|
6234
6262
|
function registerCounterpartyWrites(counterparties, program) {
|
|
6235
6263
|
decide(program, counterparties, Decision.Allow);
|
|
6236
6264
|
decide(program, counterparties, Decision.Block);
|
|
6237
|
-
counterparties.command("remove <id>").description("Remove an allow or block entry (an id from `counterparties entries`)").requiredOption("--reason <text>", "Why").action(withClient(program, async ({ client, gOpts }, id, opts) => {
|
|
6238
|
-
warnInAgentRuntime();
|
|
6265
|
+
counterparties.command("remove <id>").description("Remove an allow or block entry (an id from `counterparties entries`)").requiredOption("--reason <text>", "Why, required; kept with the entry").option("--yes", "Accepted and ignored: remove never prompts").action(withClient(program, async ({ client, gOpts }, id, opts) => {
|
|
6239
6266
|
await deleteAllow(client, id, opts.reason);
|
|
6240
6267
|
printMutationOk("Entry removed", gOpts.json);
|
|
6241
6268
|
}));
|
|
@@ -6247,6 +6274,7 @@ function registerCounterpartyWrites(counterparties, program) {
|
|
|
6247
6274
|
Direction: e.direction,
|
|
6248
6275
|
Decision: e.decision,
|
|
6249
6276
|
Org: e.counterparty_org_id,
|
|
6277
|
+
"Their agent": e.counterparty_agent_id ?? "any",
|
|
6250
6278
|
Scope: e.scope_agent_id ?? "org",
|
|
6251
6279
|
Groups: e.groups ? "yes" : "no",
|
|
6252
6280
|
Reason: e.reason
|
|
@@ -6270,7 +6298,7 @@ async function listAll(ctx) {
|
|
|
6270
6298
|
return all;
|
|
6271
6299
|
}
|
|
6272
6300
|
function registerOrgCounterparties(org, program) {
|
|
6273
|
-
registerCounterpartyWrites(org.command("counterparties").description("
|
|
6301
|
+
registerCounterpartyWrites(org.command("counterparties").description("Allow or block other organisations and their agents in the message rules, and list who your agents talk to").action(withClient(program, async (ctx) => {
|
|
6274
6302
|
const all = await listAll(ctx);
|
|
6275
6303
|
const since = Date.now() - WEEK_MS;
|
|
6276
6304
|
const fresh = all.filter((c) => Date.parse(c.first_seen) >= since);
|
|
@@ -6537,11 +6565,10 @@ async function patchOf(ctx, policy, rule, mode, opts) {
|
|
|
6537
6565
|
}
|
|
6538
6566
|
}
|
|
6539
6567
|
function registerRulesSet(rules, program) {
|
|
6540
|
-
rules.command("set <rule> <mode>").description("Set a rule's mode
|
|
6568
|
+
rules.command("set <rule> <mode>").description("Set a rule's mode: external_inbound, external_outbound and external_groups take off|report|enforce; new_agents, directory_listing, webhook_hosts, funnel and acting_as take off|enforce").option("--default <deny|allow>", "Message rules: what no entry decides").option("--host <pattern>", "webhook_hosts: an allowed host (repeatable)", collect, []).option("--agent <agent>", "acting_as: an agent that acts only with its own key (repeatable)", collect, []).option("--max <preset>", "directory_listing: the most agents may show (private, findable or listed)").option("--max-directory <on|off>", "directory_listing ceiling: directory listing").option("--max-card <on|off>", "directory_listing ceiling: profile card").option("--max-a2a <on|off>", "directory_listing ceiling: A2A discovery").option("--max-did <on|off>", "directory_listing ceiling: DID document").option("--yes", "Accepted and ignored: set never prompts").action(withClient(program, async (ctx, ruleName, modeName, opts) => {
|
|
6541
6569
|
const rule = pick("rule", Object.values(PolicyRule), ruleName);
|
|
6542
6570
|
const mode = pick(`${rule} mode`, RULE_MODES[rule], modeName);
|
|
6543
6571
|
onlyWhereApplicable(rule, opts);
|
|
6544
|
-
warnInAgentRuntime();
|
|
6545
6572
|
const current = await getPolicy(ctx.client);
|
|
6546
6573
|
const policy = await patchRules(ctx.client, current.version, await patchOf(ctx, current, rule, mode, opts));
|
|
6547
6574
|
if (ctx.gOpts.json) return printJson(policy);
|
|
@@ -6594,9 +6621,7 @@ function registerOrgRules(org, program) {
|
|
|
6594
6621
|
for (const line of previewLines$1(preview)) printText(line);
|
|
6595
6622
|
}));
|
|
6596
6623
|
rules.command("stop-existing <rule>").description("Stop what an enforced rule found already standing (webhook_hosts, funnel, directory_listing)").action(withClient(program, async ({ client, gOpts }, name) => {
|
|
6597
|
-
const
|
|
6598
|
-
warnInAgentRuntime();
|
|
6599
|
-
const result = await stopExisting(client, rule);
|
|
6624
|
+
const result = await stopExisting(client, ruleArg(name, STOPPABLE));
|
|
6600
6625
|
if (gOpts.json) return printJson(result);
|
|
6601
6626
|
for (const line of stoppedLines(result)) printText(line);
|
|
6602
6627
|
}));
|
|
@@ -6878,8 +6903,8 @@ function relayRefusal(err, opts, dir, agentId) {
|
|
|
6878
6903
|
* events (lifecycle events NEVER carry a body) and maps its outcome to the exit
|
|
6879
6904
|
* code.
|
|
6880
6905
|
*/
|
|
6881
|
-
/** Where the relay's events go: JSON lines on stdout under `--json`, the pause
|
|
6882
|
-
function eventPrinter(json, verbose) {
|
|
6906
|
+
/** Where the relay's events go: JSON lines on stdout under `--json`, the pause and stop notices and `--verbose` errors on stderr. */
|
|
6907
|
+
function eventPrinter(json, verbose, hookName) {
|
|
6883
6908
|
return (event) => {
|
|
6884
6909
|
switch (event.type) {
|
|
6885
6910
|
case "lifecycle":
|
|
@@ -6888,6 +6913,7 @@ function eventPrinter(json, verbose) {
|
|
|
6888
6913
|
data: event.data
|
|
6889
6914
|
}));
|
|
6890
6915
|
else if (event.data.state === "tunnel_paused") process.stderr.write(`${event.data.message}\n`);
|
|
6916
|
+
else if (event.data.state === "tunnel_revoked") process.stderr.write(`relay stopped: the server no longer accepts hook '${hookName}' (it was deleted, or its binding was revoked). \`rine hook list\` shows this agent's hooks; \`rine hook create --name ${hookName}\` makes a new one.\n`);
|
|
6891
6917
|
return;
|
|
6892
6918
|
case "request":
|
|
6893
6919
|
if (json) console.log(JSON.stringify(event.event));
|
|
@@ -6927,7 +6953,7 @@ function registerRelay(program) {
|
|
|
6927
6953
|
secret,
|
|
6928
6954
|
staging: opts.staging,
|
|
6929
6955
|
signal: controller.signal,
|
|
6930
|
-
onEvent: eventPrinter(gOpts.json, opts.verbose),
|
|
6956
|
+
onEvent: eventPrinter(gOpts.json, opts.verbose, opts.hook),
|
|
6931
6957
|
mintToken: tokenFor(agentId),
|
|
6932
6958
|
seams: relaySeams(core, resolve4)
|
|
6933
6959
|
});
|
|
@@ -7040,6 +7066,15 @@ function saveStreamCursor(configDir, agentId, eventId) {
|
|
|
7040
7066
|
}
|
|
7041
7067
|
//#endregion
|
|
7042
7068
|
//#region src/commands/stream-lifecycle.ts
|
|
7069
|
+
/** The `--json` line format, for `stream --help`. */
|
|
7070
|
+
const STREAM_JSON_HELP = `
|
|
7071
|
+
With --json, stdout is one JSON object per line:
|
|
7072
|
+
{"event":"message","id":"<event id>","data":"<message row as a JSON string>"}
|
|
7073
|
+
{"event":"heartbeat","id":...,"data":"..."} (left out with --monitor)
|
|
7074
|
+
{"event":"lifecycle","data":{"state":"connecting|connected|reconnecting|stopped", ...}}
|
|
7075
|
+
The message row is inside "data" and is a string: parse it a second time to read
|
|
7076
|
+
its "id", "type", "sender_handle" and "created_at". With --monitor, lifecycle
|
|
7077
|
+
lines go to stderr and stdout carries message lines only.`;
|
|
7043
7078
|
/** One lifecycle event, on stdout (JSON mode) or stderr (`--monitor`, so stdout stays messages only). */
|
|
7044
7079
|
function emitLifecycle(gOpts, monitor, data) {
|
|
7045
7080
|
if (gOpts.json) {
|
|
@@ -7372,7 +7407,7 @@ async function exitWhenFlushed(code, flushWaitMs = FLUSH_WAIT_MS) {
|
|
|
7372
7407
|
//#endregion
|
|
7373
7408
|
//#region src/commands/stream.ts
|
|
7374
7409
|
function registerStream(program) {
|
|
7375
|
-
program.command("stream").description("Stream incoming messages via SSE").addOption(actorOption("which agent is acting, and whose messages stream (name, handle, or agent ID)")).option("--verbose", "Show heartbeats and reconnect details").option("--persistent", "Disable server-side connection timeout").option("--heartbeat-timeout <seconds>", "Seconds of silence before reconnecting (default: 70)", "70").option("--monitor", "Suppress non-message stdout (for CC plugin monitors)").option("--hide-control", STREAM_HIDE_CONTROL_HELP).action(async (opts, command) => {
|
|
7410
|
+
program.command("stream").description("Stream incoming messages via SSE").addHelpText("after", STREAM_JSON_HELP).addOption(actorOption("which agent is acting, and whose messages stream (name, handle, or agent ID)")).option("--verbose", "Show heartbeats and reconnect details").option("--persistent", "Disable server-side connection timeout").option("--heartbeat-timeout <seconds>", "Seconds of silence before reconnecting (default: 70)", "70").option("--monitor", "Suppress non-message stdout (for CC plugin monitors)").option("--hide-control", STREAM_HIDE_CONTROL_HELP).action(async (opts, command) => {
|
|
7376
7411
|
try {
|
|
7377
7412
|
const gOpts = program.opts();
|
|
7378
7413
|
const apiUrl = resolveApiUrl();
|
|
@@ -11936,6 +11971,50 @@ function registerWallet(program) {
|
|
|
11936
11971
|
})), program);
|
|
11937
11972
|
}
|
|
11938
11973
|
//#endregion
|
|
11974
|
+
//#region src/commands/runtime-warning.ts
|
|
11975
|
+
/**
|
|
11976
|
+
* Detect that the CLI runs inside an agent runtime, so a command that signs with the org key
|
|
11977
|
+
* can warn first. Warn, never block: the command still runs. One table of markers; each is an environment
|
|
11978
|
+
* variable that runtime sets for the processes it starts (the OpenClaw and Hermes rigs and
|
|
11979
|
+
* Claude Code in `compose.openclaw.yml`, `compose.hermes.yml` and `compose.cc.yml`).
|
|
11980
|
+
*/
|
|
11981
|
+
const RUNTIME_MARKERS = [
|
|
11982
|
+
{
|
|
11983
|
+
runtime: "Claude Code",
|
|
11984
|
+
vars: ["CLAUDECODE", "CLAUDE_CODE_ENTRYPOINT"]
|
|
11985
|
+
},
|
|
11986
|
+
{
|
|
11987
|
+
runtime: "OpenClaw",
|
|
11988
|
+
vars: ["OPENCLAW_STATE_DIR", "OPENCLAW_CONFIG_PATH"]
|
|
11989
|
+
},
|
|
11990
|
+
{
|
|
11991
|
+
runtime: "Hermes",
|
|
11992
|
+
vars: ["HERMES_HOME", "HERMES_SESSION_KEY"]
|
|
11993
|
+
}
|
|
11994
|
+
];
|
|
11995
|
+
/** The two commands that create the org key: there is no other machine to run them from yet. */
|
|
11996
|
+
const KEY_CREATING = new Set(["register", "onboard"]);
|
|
11997
|
+
/** The warning printed before a command that signs with the org key, inside an agent runtime. */
|
|
11998
|
+
const orgKeyWarning = (runtime, path) => `This looks like an agent's environment (${runtime}). rine ${path} signs with your org key, and an agent with a shell here can read that key. Run org-key commands from a machine that runs no agents: https://docs.rine.network/how-to/org-rules/`;
|
|
11999
|
+
/** The runtime whose marker is set (non-empty) in `env`, or `undefined` in a plain shell. */
|
|
12000
|
+
function runtimeOf(env = process.env) {
|
|
12001
|
+
return RUNTIME_MARKERS.find((m) => m.vars.some((v) => env[v]))?.runtime;
|
|
12002
|
+
}
|
|
12003
|
+
/**
|
|
12004
|
+
* Before every Admin-tier command except the two that create the org key, print the warning
|
|
12005
|
+
* on stderr when a runtime marker is set. It runs before the action body, so before any
|
|
12006
|
+
* confirmation, and prints under `--yes` and `--json` too; stdout is untouched.
|
|
12007
|
+
*/
|
|
12008
|
+
function warnBeforeOrgKey(program) {
|
|
12009
|
+
program.hook("preAction", (_, action) => {
|
|
12010
|
+
const runtime = runtimeOf();
|
|
12011
|
+
if (runtime === void 0) return;
|
|
12012
|
+
const path = commandPath(action);
|
|
12013
|
+
if (KEY_CREATING.has(path)) return;
|
|
12014
|
+
if (operationByCli(path)?.tier === OpTier.Admin) printError(orgKeyWarning(runtime, path));
|
|
12015
|
+
});
|
|
12016
|
+
}
|
|
12017
|
+
//#endregion
|
|
11939
12018
|
//#region src/commands/webhook.ts
|
|
11940
12019
|
function registerWebhook(program) {
|
|
11941
12020
|
const webhook = program.command("webhook").description("Manage webhooks");
|
|
@@ -12008,8 +12087,16 @@ function registerWebhook(program) {
|
|
|
12008
12087
|
//#endregion
|
|
12009
12088
|
//#region src/program.ts
|
|
12010
12089
|
const { version } = createRequire(import.meta.url)("../package.json");
|
|
12090
|
+
/** Printed above `Usage:` on the root help, so the first screen names what an agent looks for. */
|
|
12091
|
+
const HELP_HEAD = `rine: end-to-end encrypted messaging between AI agents.
|
|
12092
|
+
Docs: https://docs.rine.network/ · For AI agents: https://rine.network/skill.md
|
|
12093
|
+
Who may message your agents: rine org rules, rine org counterparties. What an agent shows: rine agent exposure.
|
|
12094
|
+
Delegated keys: rine org delegate. Spend policy: rine wallet policy. Verify a peer: rine agent verify.
|
|
12095
|
+
Watch for new messages: rine stream. Org-wide reader: rine tui.
|
|
12096
|
+
`;
|
|
12011
12097
|
function buildProgram() {
|
|
12012
12098
|
const program = new Command("rine").version(version).description("rine.network CLI — messaging infrastructure for AI agents").option("--profile <name>", "profile to use (default: the owner's org profile, else \"default\")").option("--json", "output as JSON").option("--as <agent>", "which agent is acting — the retired spelling of --agent (name, handle, or agent ID)");
|
|
12099
|
+
program.addHelpText("before", HELP_HEAD);
|
|
12013
12100
|
registerAuth(program);
|
|
12014
12101
|
registerRegister(program);
|
|
12015
12102
|
registerOnboard(program);
|
|
@@ -12033,6 +12120,7 @@ function buildProgram() {
|
|
|
12033
12120
|
registerIdentity(program);
|
|
12034
12121
|
registerCatalog(program);
|
|
12035
12122
|
refuseOutsideAgentTier(program);
|
|
12123
|
+
warnBeforeOrgKey(program);
|
|
12036
12124
|
return program;
|
|
12037
12125
|
}
|
|
12038
12126
|
//#endregion
|
package/package.json
CHANGED