@hediet/linkrpc-cli 0.0.3-next.20261023.4 → 0.0.3-next.20261025.1

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 CHANGED
@@ -581,7 +581,7 @@ it**. Pick one of:
581
581
  | `--endpoint <uri>` | A strict endpoint URI (see below). |
582
582
  | `--endpoint-cmd <command>` | Spawn a _server_, hand it a fresh socket + token via `LINKRPC_ENDPOINT`/`LINKRPC_TOKEN`, then connect to it. |
583
583
  | `--endpoint-cmd-stdio <command>` | Spawn a child and talk linkrpc over its stdio. |
584
- | `LINKRPC_ENDPOINT` (env) | A URI, or a legacy bare socket path / `ws://` URL. Token from `LINKRPC_TOKEN`; enabled by default in the Hub profile. |
584
+ | `LINKRPC_ENDPOINT` (env) | A URI, or a legacy bare socket path / `ws://` URL. Token from `LINKRPC_TOKEN`; enabled by default in the Hub profile and with `--use-env` in the RPC profile. |
585
585
 
586
586
  Legacy `HUBRPC_ENDPOINT` and `HUBRPC_TOKEN` remain supported when the
587
587
  corresponding `LINKRPC_*` variable is absent.
@@ -940,7 +940,7 @@ Value-taking options support both `--option=value` and `--option value`.
940
940
  Parameter assignment itself still uses `key=value`, e.g.
941
941
  `--param path=/docs/a` or `--param=path=/docs/a`. Use the equals form for
942
942
  dash-prefixed values. Quote JSON and strings containing spaces.
943
- `--cap:request` and `--cap:allow-any` are switches with no value.
943
+ `--cap:request`, `--cap:allow-any`, and `--cap:delegate` are switches with no value.
944
944
  The older `--request-cap`, `--allow-param`, and `--duration` spellings have
945
945
  been replaced by the `--cap:` options.
946
946
 
@@ -950,6 +950,9 @@ Schema validation is mandatory for explicit requests: `--no-validate` and
950
950
  the permission; signed calls include that hash in their signed metadata.
951
951
  The default requested duration is `persistent`; `--cap:duration shortLived` and
952
952
  `--cap:duration longLived` are also supported. The Hub still decides what to grant.
953
+ `--cap:delegate` also requests `canDelegate`, so the identity can issue narrower
954
+ capabilities for that scope to other identities, e.g. a service it runs; a
955
+ stored grant without delegation does not satisfy such a request.
953
956
  One-shot approval cannot satisfy a reusable scope and is rejected.
954
957
 
955
958
  Fresh durable grants for the selected principal are reused when they cover
@@ -1,4 +1,4 @@
1
- import { $ as requestTopologyAccess, B as proxyCommand, F as disconnectBroker, G as parseDuration, H as withStaticHubReflection, I as getBrokerStatus, L as readBrokerNotifications, M as readEndpointDiscovery, N as ContextStore, P as formatContextReference, Q as requestReflectionAccess, R as stopConnectionBroker, St as mcpForwardInterface, U as parseConnectionLimit, V as tunnelCommand, W as parseConnectionLimitMilliseconds, _t as validateValueAgainstSchema, a as resolveInvocationEndpoint, bt as parseParamOverride, c as resolveLocalEndpoint, ct as parsePrincipalSpec, dt as connectViaTransport, et as setupSigning, ft as resolveTargetEndpoint, gt as explainValidation, ht as describeSchema, i as resolveInvocationContext, it as walkHub, lt as connect, m as managedEndpointsInterface, mt as describeObjectParams, n as loadStaticHubSchema, nt as fetchSchema$1, o as resolveSigning, ot as logoutCliIdentity, pt as resolvedEndpointToConfig, q as resolveCliInvocation, r as resolveStaticHubSchemaSource, rt as findMethodInSchema, s as validationDefault, st as formatPrincipalSource, t as completeForLine, tt as fetchDefaults, ut as connectViaRootOverlay, xt as MethodRefWithOptHash, y as HubHome, yt as mergeParams, z as ConnectionBroker } from "./runComplete-C9LMCMk7.js";
1
+ import { $ as requestTopologyAccess, B as proxyCommand, Ct as MethodRefWithOptHash, F as disconnectBroker, G as parseDuration, H as withStaticHubReflection, I as getBrokerStatus, L as readBrokerNotifications, M as readEndpointDiscovery, N as ContextStore, P as formatContextReference, Q as requestReflectionAccess, R as stopConnectionBroker, St as parseParamOverride, U as parseConnectionLimit, V as tunnelCommand, W as parseConnectionLimitMilliseconds, _t as describeSchema, a as resolveInvocationEndpoint, c as resolveLocalEndpoint, ct as readCliIdentity, dt as connect, et as setupSigning, ft as connectViaRootOverlay, gt as describeObjectParams, ht as resolvedEndpointToConfig, i as resolveInvocationContext, it as walkHub, lt as formatPrincipalSource, m as managedEndpointsInterface, mt as resolveTargetEndpoint, n as loadStaticHubSchema, nt as fetchSchema$1, o as resolveSigning, ot as cliIdentityTarget, pt as connectViaTransport, q as resolveCliInvocation, r as resolveStaticHubSchemaSource, rt as findMethodInSchema, s as validationDefault, st as deleteCliIdentity, t as completeForLine, tt as fetchDefaults, ut as parsePrincipalSpec, vt as explainValidation, wt as mcpForwardInterface, xt as mergeParams, y as HubHome, yt as validateValueAgainstSchema, z as ConnectionBroker } from "./runComplete-bFjlzR3Y.js";
2
2
  import { ErrorCode, INTERFACE_TEMPLATES_EXTENSION, LinkRpcConnection, RpcError, computeInterfaceHash, connectTransports, createSchemaToZod, directoryInterface, exportStaticHubSchema, generateTsContract, generateTsInterface, interfaceTemplateArgumentsEquivalent, interfaceTemplateMemberName, interfaceTemplatesEqual, isAssignable, jcsCanonicalize, matchParams, schemaToZod, validateInterfaceTemplates } from "@hediet/linkrpc";
3
3
  import { z } from "zod";
4
4
  import { WebSocketTransport, connectNdjson, connectToHub, formatEndpointUri, isHubEndpoint, openWebSocket, parseEndpointUri, runInitializeHandshake, traceMessageTransport as traceMessageTransport$1 } from "@hediet/linkrpc/node";
@@ -13,15 +13,15 @@ import * as net from "node:net";
13
13
  import { mkdir, open, readFile, writeFile } from "node:fs/promises";
14
14
  import { DEFAULT_WALK_DEPTH, HubDirectoryExplorer, fetchSchema, findCoveringCapabilities, hubGrantedServiceIdInterface } from "@hediet/linkrpc/hub/common";
15
15
  import { CONSOLE_INTERFACE_TAG, ConsoleTemplate, consoleAttachResultSchema, consoleServerMessageSchema, decodeConsoleData, encodeConsoleData } from "@hediet/linkrpc-infra/console";
16
+ import { createInterface } from "node:readline/promises";
16
17
  import { Command, InvalidArgumentError, Option } from "commander";
17
18
  import * as readline from "node:readline";
18
- import { createInterface, emitKeypressEvents } from "node:readline";
19
+ import { createInterface as createInterface$1, emitKeypressEvents } from "node:readline";
19
20
  import { parse, unknown } from "zod/mini";
20
21
  import { bootstrapApprovalCapability, createHubApprovalClient } from "@hediet/linkrpc-infra/approval";
21
22
  import { connectionTokenBinderInterface } from "@hediet/linkrpc-hub/hub/server/connection-token-binder";
22
23
  import { spawn } from "node:child_process";
23
24
  import { TopologyClient, TopologyNetworkClient, TrafficClient } from "@hediet/linkrpc-infra/inspection";
24
- import { createInterface as createInterface$1 } from "node:readline/promises";
25
25
  import { stdin, stdout } from "node:process";
26
26
  import { TrafficFlowAggregator, createTerminalConsentPrompt, formatFlowSummary } from "@hediet/linkrpc-hub";
27
27
  import { loadHubConfig, printHubConfigSchema } from "@hediet/linkrpc-hub/config-file";
@@ -49,7 +49,7 @@ var ServiceConsoleInput = class {
49
49
  this._close = _close;
50
50
  this._wasRaw = _input.isRaw ?? false;
51
51
  if (_input.isTTY) {
52
- this._readline = createInterface({
52
+ this._readline = createInterface$1({
53
53
  input: _input,
54
54
  output,
55
55
  terminal: true,
@@ -407,7 +407,7 @@ function contextNamespace(reference) {
407
407
  async function useLocalManagement(start, action) {
408
408
  const home = HubHome.resolve();
409
409
  if (start) {
410
- const { startDaemon, nodeDaemonLaunch } = await import("./src-CCyOTeN5.js");
410
+ const { startDaemon, nodeDaemonLaunch } = await import("./src-B71xYgEO.js");
411
411
  if (await startDaemon({
412
412
  home,
413
413
  launch: nodeDaemonLaunch(home)
@@ -427,7 +427,7 @@ async function useLocalManagement(start, action) {
427
427
  }
428
428
  }
429
429
  async function restartLocalDaemon() {
430
- const { startDaemon, stopDaemon, nodeDaemonLaunch } = await import("./src-CCyOTeN5.js");
430
+ const { startDaemon, stopDaemon, nodeDaemonLaunch } = await import("./src-B71xYgEO.js");
431
431
  const home = HubHome.resolve();
432
432
  process.stderr.write("Restarting the local Hub daemon: clients will disconnect and managed workloads will stop. OS autostart settings are unchanged.\n");
433
433
  await stopDaemon(home);
@@ -947,6 +947,7 @@ async function requestCallCapability(channel, session, ref, params, schema, opts
947
947
  ...ref.hash !== void 0 ? { interfaceHash: ref.hash } : {}
948
948
  },
949
949
  canInvoke: true,
950
+ ...opts.delegate === true ? { canDelegate: true } : {},
950
951
  params: matchers
951
952
  };
952
953
  const coverageOptions = {
@@ -3040,7 +3041,7 @@ function selectParticipant(participants, nodeId) {
3040
3041
  return participants.length === 1 ? participants[0] : void 0;
3041
3042
  }
3042
3043
  async function promptForParticipant(participants, search) {
3043
- const readline = createInterface$1({
3044
+ const readline = createInterface({
3044
3045
  input: stdin,
3045
3046
  output: stdout
3046
3047
  });
@@ -8734,7 +8735,8 @@ async function main(rawArgv, executableName = "linkrpc") {
8734
8735
  return;
8735
8736
  }
8736
8737
  if (endpoint === void 0) {
8737
- process.stdout.write("\n(No endpoint configured: pass --endpoint / --endpoint-cmd or set LINKRPC_ENDPOINT\nto see method-specific --p:<name> flags here.)\n");
8738
+ const ignoredEnvironmentHint = ignoredEndpointEnvironmentHint();
8739
+ process.stdout.write(`\n(No endpoint configured: pass ${endpointOptionsDescription()}.\n` + (ignoredEnvironmentHint === void 0 ? "" : `${ignoredEnvironmentHint}.\n`) + "To see method-specific --p:<name> flags here.)\n");
8738
8740
  return;
8739
8741
  }
8740
8742
  let ref;
@@ -8778,7 +8780,7 @@ async function main(rawArgv, executableName = "linkrpc") {
8778
8780
  "shortLived",
8779
8781
  "longLived",
8780
8782
  "persistent"
8781
- ]).default("persistent"));
8783
+ ]).default("persistent")).option("--cap:delegate", "also request the right to delegate this authority (canDelegate) to other identities");
8782
8784
  const configureCall = (cmd, capabilityOnly) => {
8783
8785
  cmd.description((capabilityOnly ? "Request a capability without executing a call. " : "Invoke a request. ") + "`<methodRef>` is `[svc::][iface::]method[@hash]`. Use `--p:<name> <value>` (or `--p:<name>=<value>`) as a shortcut for `--param <name>=<value>`. Run `hub call <methodRef> --help` to see the method-specific `--p:` flags derived from the live schema.").option("--params <json>", "inline params JSON, or \"-\" to read stdin").option("--param <kv...>", "param override, key=value (JSON or string)").option("--no-validate", "skip schema-based param validation").helpOption(false).option("-h, --help", "show help (includes method params when reachable)").action(async (methodRef, opts, cmd) => {
8784
8786
  if (opts.help) {
@@ -8794,6 +8796,7 @@ async function main(rawArgv, executableName = "linkrpc") {
8794
8796
  const allowParams = opts["cap:allowParam"];
8795
8797
  if (!capabilityOnly && allowParams !== void 0 && !requestCap) throw new Error("--cap:allow-param requires --cap:request.");
8796
8798
  if (!capabilityOnly && cmd.getOptionValueSource("cap:duration") === "cli" && !requestCap) throw new Error("--cap:duration requires --cap:request.");
8799
+ if (!capabilityOnly && opts["cap:delegate"] === true && !requestCap) throw new Error("--cap:delegate requires --cap:request.");
8797
8800
  resolveSigning(profile, g_invocation?.values ?? {}, capabilityOnly || requestCap);
8798
8801
  const validation = opts.validate === false ? "off" : effectiveValidation(profile);
8799
8802
  if ((capabilityOnly || requestCap) && validation === "off") throw new Error("Capability requests require schema validation; remove --no-validate/--validation off.");
@@ -8807,7 +8810,8 @@ async function main(rawArgv, executableName = "linkrpc") {
8807
8810
  requestCap,
8808
8811
  capabilityOnly,
8809
8812
  signingSession: session,
8810
- duration: opts["cap:duration"]
8813
+ duration: opts["cap:duration"],
8814
+ delegate: opts["cap:delegate"] === true
8811
8815
  });
8812
8816
  process.stdout.write(out + "\n");
8813
8817
  }, {
@@ -9082,11 +9086,16 @@ Batch options:
9082
9086
  const remote = await connectTargetEndpoint(targetEp, serviceId);
9083
9087
  try {
9084
9088
  reportIdentity(await setupSigning(local.channel, local.signing, getPrincipalSpec(), { negotiateHubCaps: isHubEndpoint(localEp) }));
9089
+ const lost = Promise.race([local.closed.then(() => "source"), remote.closed.then(() => "target")]).then((side) => {
9090
+ process.stderr.write(`linkrpc: tunnel: the ${side} connection closed\n`);
9091
+ process.exitCode = 1;
9092
+ });
9085
9093
  await tunnelCommand({
9086
9094
  serviceId,
9087
9095
  local,
9088
9096
  remote,
9089
- bidi: cmdOpts.bidi
9097
+ bidi: cmdOpts.bidi,
9098
+ stop: Promise.race([lost, _untilSignalled()])
9090
9099
  });
9091
9100
  } finally {
9092
9101
  remote.close();
@@ -9113,10 +9122,10 @@ Batch options:
9113
9122
  const principal = typeof cmdOpts.signAs === "string" ? parsePrincipalSpec(cmdOpts.signAs) : getPrincipalSpec();
9114
9123
  reportIdentity(await setupSigning(hub.channel, hub.signing, principal, { negotiateHubCaps: isHubEndpoint(localEp) }));
9115
9124
  }
9116
- const participant = targetEp === void 0 ? await connectStdioParticipant() : {
9117
- connection: await connectTargetEndpoint(targetEp, cmdOpts.claim ?? ""),
9118
- closed: void 0
9119
- };
9125
+ const participant = targetEp === void 0 ? await connectStdioParticipant() : await connectTargetEndpoint(targetEp, cmdOpts.claim ?? "").then((connection) => ({
9126
+ connection,
9127
+ closed: connection.closed
9128
+ }));
9120
9129
  try {
9121
9130
  await proxyCommand({
9122
9131
  hub,
@@ -9251,7 +9260,7 @@ Batch options:
9251
9260
  process.once("SIGINT", onSignal);
9252
9261
  process.once("SIGTERM", onSignal);
9253
9262
  try {
9254
- const { runApprovalUi } = await import("./runApprovalUi-CVymyDHh.js");
9263
+ const { runApprovalUi } = await import("./runApprovalUi--TML-1-H.js");
9255
9264
  await runApprovalUi({
9256
9265
  client,
9257
9266
  signal: stop.signal
@@ -9266,7 +9275,7 @@ Batch options:
9266
9275
  registerViewCommands(program, (action) => withChannel(endpoint, getPrincipalSpec(), action));
9267
9276
  program.command("ui").description("Launch the terminal UI (form-based browser of services + methods).").action(async () => {
9268
9277
  const acquired = await acquireConnection(endpoint);
9269
- const { runUi } = await import("./runUi-ByL1VdAP.js");
9278
+ const { runUi } = await import("./runUi-CziO0efi.js");
9270
9279
  try {
9271
9280
  await runUi({
9272
9281
  endpoint: acquired.ep,
@@ -9278,13 +9287,27 @@ Batch options:
9278
9287
  acquired.running?.dispose();
9279
9288
  }
9280
9289
  });
9281
- if (profile === "hub") program.command("logout").description("Delete the stored CLI identity and cached capabilities. Next call will mint a fresh keypair and prompt for consent again.").action(async () => {
9282
- const removed = await logoutCliIdentity();
9283
- if (removed.length === 0) {
9284
- process.stdout.write("linkrpc: no stored identity found.\n");
9290
+ if (profile === "hub") program.command("logout").description("Delete the stored keypair and cached capabilities of the identity selected by --principal (default: the user:hubrpc-cli fallback). Asks for confirmation unless --yes is given. The next call mints a fresh keypair, which hubs that trusted the old key do not accept.").option("-y, --yes", "delete without asking for confirmation").action(async (opts) => {
9291
+ const target = cliIdentityTarget(getPrincipalSpec());
9292
+ const principal = await readCliIdentity(target);
9293
+ if (principal === void 0) {
9294
+ process.stdout.write(`linkrpc: no stored identity for ${target.label} (${target.file}).\n`);
9285
9295
  return;
9286
9296
  }
9287
- for (const f of removed) process.stdout.write(`removed ${f}\n`);
9297
+ const description = `identity ${target.label} (${principal}) at ${target.file}`;
9298
+ if (opts.yes !== true) {
9299
+ if (process.stdin.isTTY !== true || process.stderr.isTTY !== true) throw new Error(`Refusing to delete ${description} without confirmation; pass --yes.`);
9300
+ const readline = createInterface({
9301
+ input: process.stdin,
9302
+ output: process.stderr
9303
+ });
9304
+ const answer = await readline.question(`Delete ${description} and its cached capabilities? This cannot be undone. [y/N] `).finally(() => readline.close());
9305
+ if (!/^y(es)?$/i.test(answer.trim())) {
9306
+ process.stderr.write("linkrpc: logout cancelled.\n");
9307
+ return;
9308
+ }
9309
+ }
9310
+ for (const f of await deleteCliIdentity(target)) process.stdout.write(`removed ${f}\n`);
9288
9311
  });
9289
9312
  program.command("completions <shell>").description("Print a shell completion script. Supported: powershell. Install with `hub completions powershell | Out-String | Invoke-Expression` (one-shot) or append to $PROFILE.").action((shell) => {
9290
9313
  try {
@@ -9634,7 +9657,8 @@ async function acquireConnection(endpoint) {
9634
9657
  if (endpoint === void 0 && g_invocation?.profile === "hub") try {
9635
9658
  return { ep: resolveLocalEndpoint() };
9636
9659
  } catch {
9637
- throw new Error("No endpoint configured through flags, environment, or context, and the local Hub daemon is not running. Pass --endpoint, or start the daemon (any `hub services run` starts it).");
9660
+ const ignoredEnvironmentHint = ignoredEndpointEnvironmentHint();
9661
+ throw new Error(`No endpoint configured through flags, environment, or context, and the local Hub daemon is not running. Pass ${endpointOptionsDescription()}, or start the daemon (any \`hub services run\` starts it).` + (ignoredEnvironmentHint === void 0 ? "" : ` ${ignoredEnvironmentHint}.`));
9638
9662
  }
9639
9663
  return { ep: needEndpoint(endpoint) };
9640
9664
  }
@@ -9644,11 +9668,23 @@ function reportIdentity(session) {
9644
9668
  }
9645
9669
  function needEndpoint(endpoint) {
9646
9670
  if (!endpoint) {
9647
- process.stderr.write("linkrpc: this command requires --endpoint / --endpoint-cmd / --endpoint-cmd-stdio or the LINKRPC_ENDPOINT env var to be set.\n");
9671
+ const ignoredEnvironmentHint = ignoredEndpointEnvironmentHint();
9672
+ process.stderr.write(`linkrpc: this command requires ${endpointOptionsDescription()}.\n` + (ignoredEnvironmentHint === void 0 ? "" : `linkrpc: ${ignoredEnvironmentHint}.\n`));
9648
9673
  process.exit(2);
9649
9674
  }
9650
9675
  return endpoint;
9651
9676
  }
9677
+ function endpointOptionsDescription() {
9678
+ const options = "--endpoint / --endpoint-cmd / --endpoint-cmd-stdio or a configured context";
9679
+ return g_invocation?.profile === "hub" && g_invocation.environmentApplied ? `${options} or LINKRPC_ENDPOINT` : options;
9680
+ }
9681
+ function ignoredEndpointEnvironmentHint() {
9682
+ const invocation = g_invocation;
9683
+ if (invocation === void 0 || invocation.environmentApplied) return void 0;
9684
+ const variable = process.env.LINKRPC_ENDPOINT !== void 0 ? "LINKRPC_ENDPOINT" : process.env.HUBRPC_ENDPOINT !== void 0 ? "HUBRPC_ENDPOINT" : void 0;
9685
+ if (variable === void 0) return void 0;
9686
+ return invocation.profile === "rpc" ? `${variable} is set but only used by hub commands: run \`linkrpc hub <command>\` (or pass --use-env)` : `${variable} is set but ignored because environment overrides are disabled; pass --use-env to apply it`;
9687
+ }
9652
9688
  /** The `--target-endpoint*` options shared by `tunnel` and `proxy`. */
9653
9689
  function addTargetEndpointOptions(command) {
9654
9690
  return command.option("--target-endpoint <uri>", "target endpoint URI (unix:/path?token=…, npipe://./pipe/…, ws[s]://host?token=…, cmd:?command=… or cmd-stdio:?command=…)").option("--target-endpoint-cmd <command>", "spawn the target as a server, connect via an injected env socket; the child sees the claimed service id as grantedServiceIdNamespace via hubGrantedServiceId::get").option("--target-endpoint-cmd-stdio <command>", "spawn the target and talk linkrpc over its stdio").option("--target-endpoint-cmd-env <key=value>", "env var for the --target-endpoint-cmd / --target-endpoint-cmd-stdio child (repeatable)", (val, acc) => {
@@ -9802,4 +9838,4 @@ function safeJson(value) {
9802
9838
  //#endregion
9803
9839
  export { formatCondition as _, formatCommandLegend as a, targetId as b, safeTerminalText as c, ObservablePromise as d, observableValue as f, resolveViewTarget as g, Disposable as h, dispatchHostKey as i, approvalDetailLines as l, derived as m, views as n, hostCommands as o, autorun as p, ViewFrame as r, matchesKey as s, runCli as t, ObservableLazyPromise as u, interfaceTarget as v, matchesTarget as y };
9804
9840
 
9805
- //# sourceMappingURL=cli-CYL6JUxF.js.map
9841
+ //# sourceMappingURL=cli-DHK9RSd9.js.map