@primusclaw/personal-agent-runtime 0.11.0 → 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.
package/dist/index.js CHANGED
@@ -555,6 +555,18 @@ var HttpRemoteAgents = class {
555
555
  async setApprovals(key2, enabled) {
556
556
  return enabledOf(await this.#call("PUT", "/approvals", key2, { enabled }));
557
557
  }
558
+ async muteTerminal(key2, item2, muted) {
559
+ const data = anyDataOf(await this.#call("PUT", "/approvals/mutes", key2, { item: item2, muted }), "a terminal mute");
560
+ const d = data !== null && typeof data === "object" ? data : {};
561
+ if (typeof d["muted"] !== "boolean" || typeof d["item"] !== "number")
562
+ throw new ClawAnswerInvalid4("a terminal mute has no item or muted");
563
+ return {
564
+ item: d["item"],
565
+ muted: d["muted"],
566
+ machine: typeof d["machine"] === "string" ? d["machine"] : "",
567
+ title: typeof d["title"] === "string" ? d["title"] : ""
568
+ };
569
+ }
558
570
  async pair(key2) {
559
571
  return read(
560
572
  remotePairingSchema,
@@ -1595,6 +1607,28 @@ var HELP = {
1595
1607
  "Files a user sent that did not reach Claw, by where they were dropped."
1596
1608
  ]
1597
1609
  };
1610
+ var HELP_CURRENT_ONLY = {
1611
+ personal_agent_probe_total: [
1612
+ "counter",
1613
+ "Delivery probes the worker answered, by outcome: answered (the relay's ack came back) or unanswered."
1614
+ ],
1615
+ personal_agent_probe_feedback_ms: [
1616
+ "gauge",
1617
+ "Milliseconds from the last probe's sending (by the ingress) to the worker's answer queued for the relay."
1618
+ ],
1619
+ personal_agent_probe_reply_ms: [
1620
+ "gauge",
1621
+ "Milliseconds from the last answered probe's sending to the relay's ack of the answer reaching the worker."
1622
+ ],
1623
+ personal_agent_probe_last_answered_seconds: [
1624
+ "gauge",
1625
+ "Unix time of the last answered probe (0: none since the worker started)."
1626
+ ],
1627
+ personal_agent_inbound_rearmed_total: [
1628
+ "counter",
1629
+ "Times the inbound receivers' connection was re-opened because a call on the broker hung (once per connection)."
1630
+ ]
1631
+ };
1598
1632
  function compareTuples(a, b) {
1599
1633
  for (let i = 0; i < Math.min(a.length, b.length); i++) {
1600
1634
  const x = a[i] ?? "";
@@ -1624,6 +1658,8 @@ var PrometheusMetrics = class {
1624
1658
  /** (when, lag): decreasing lags, the sliding-window maximum. */
1625
1659
  lags = [];
1626
1660
  /** Event type -> (receipt to sent, occurred to sent), each written from the start. */
1661
+ probes = { answered: 0, unanswered: 0, feedbackMs: 0, replyMs: 0, answeredAt: 0 };
1662
+ rearmed = 0;
1627
1663
  eventTimes = new Map(
1628
1664
  DELIVERED_EVENT_TYPES.map((t) => [t, [new Histogram(EVENT_BUCKETS), new Histogram(EVENT_BUCKETS)]])
1629
1665
  );
@@ -1668,6 +1704,23 @@ var PrometheusMetrics = class {
1668
1704
  if (current === void 0 || count <= 0) return;
1669
1705
  this.dropped.set(path, current + Math.trunc(count));
1670
1706
  }
1707
+ probed(feedbackMs, replyMs) {
1708
+ const feedback = Math.max(Math.trunc(feedbackMs), 0);
1709
+ if (replyMs === null) {
1710
+ this.probes = { ...this.probes, unanswered: this.probes.unanswered + 1, feedbackMs: feedback };
1711
+ return;
1712
+ }
1713
+ this.probes = {
1714
+ answered: this.probes.answered + 1,
1715
+ unanswered: this.probes.unanswered,
1716
+ feedbackMs: feedback,
1717
+ replyMs: Math.max(Math.trunc(replyMs), 0),
1718
+ answeredAt: Math.trunc(this.clock.epochMs() / 1e3)
1719
+ };
1720
+ }
1721
+ inboundRearmed() {
1722
+ this.rearmed += 1;
1723
+ }
1671
1724
  /** The longest wait of the messages handled in the window, in milliseconds (0: none). */
1672
1725
  lagMaxMs() {
1673
1726
  this.expire(this.clock.monotonicMs());
@@ -1682,7 +1735,28 @@ var PrometheusMetrics = class {
1682
1735
  */
1683
1736
  render() {
1684
1737
  const lagMaxMs = this.lagMaxMs();
1685
- return this.renderAs(METRIC_PREFIX, lagMaxMs) + this.renderAs(LEGACY_METRIC_PREFIX, lagMaxMs);
1738
+ return this.renderAs(METRIC_PREFIX, lagMaxMs) + this.renderAs(LEGACY_METRIC_PREFIX, lagMaxMs) + this.renderCurrentOnly();
1739
+ }
1740
+ renderCurrentOnly() {
1741
+ const lines = [];
1742
+ const head2 = (name) => {
1743
+ const [kind, text3] = own2(HELP_CURRENT_ONLY, name) ?? ["untyped", ""];
1744
+ lines.push(`# HELP ${name} ${text3}`, `# TYPE ${name} ${kind}`);
1745
+ };
1746
+ head2("personal_agent_probe_total");
1747
+ lines.push(`personal_agent_probe_total{outcome="answered"} ${String(this.probes.answered)}`);
1748
+ lines.push(`personal_agent_probe_total{outcome="unanswered"} ${String(this.probes.unanswered)}`);
1749
+ const gauges = [
1750
+ ["personal_agent_probe_feedback_ms", this.probes.feedbackMs],
1751
+ ["personal_agent_probe_reply_ms", this.probes.replyMs],
1752
+ ["personal_agent_probe_last_answered_seconds", this.probes.answeredAt],
1753
+ ["personal_agent_inbound_rearmed_total", this.rearmed]
1754
+ ];
1755
+ for (const [name, value] of gauges) {
1756
+ head2(name);
1757
+ lines.push(`${name} ${String(value)}`);
1758
+ }
1759
+ return lines.join("\n") + "\n";
1686
1760
  }
1687
1761
  renderAs(prefix, lagMaxMs) {
1688
1762
  const lines = [];
@@ -6262,6 +6336,7 @@ export {
6262
6336
  GithubDeviceFlow,
6263
6337
  GithubIssueSink,
6264
6338
  HELP,
6339
+ HELP_CURRENT_ONLY,
6265
6340
  HttpIdentityLookup,
6266
6341
  HttpKeyRevoker,
6267
6342
  HttpTokenExchange,
@@ -1,4 +1,4 @@
1
- import { type ClawCredential, type ClawRemoteAgentsPort, type JsonObject, type NewRemoteSession, type RemoteConnector, type RemoteEventRow, type RemoteHidden, type RemotePairing, type RemoteSession, type RemoteSetup, type SseEvent } from "@primusclaw/personal-agent";
1
+ import { type ClawCredential, type ClawRemoteAgentsPort, type JsonObject, type NewRemoteSession, type RemoteConnector, type RemoteEventRow, type RemoteHidden, type RemotePairing, type RemoteSession, type RemoteSetup, type SseEvent, type TerminalMute } from "@primusclaw/personal-agent";
2
2
  import { type ClawHttp } from "./http.js";
3
3
  /** `ClawRemoteAgentsPort` over Claw's HTTP API; every call names this client (`X-Claw-Client`) in Claw's audit trail. */
4
4
  export declare class HttpRemoteAgents implements ClawRemoteAgentsPort {
@@ -12,6 +12,7 @@ export declare class HttpRemoteAgents implements ClawRemoteAgentsPort {
12
12
  }): Promise<RemoteConnector[]>;
13
13
  approvals(key: ClawCredential): Promise<boolean>;
14
14
  setApprovals(key: ClawCredential, enabled: boolean): Promise<boolean>;
15
+ muteTerminal(key: ClawCredential, item: number, muted: boolean): Promise<TerminalMute>;
15
16
  pair(key: ClawCredential): Promise<RemotePairing>;
16
17
  hide(key: ClawCredential, connectorId: string, refs: readonly string[], hidden: boolean): Promise<RemoteHidden>;
17
18
  revoke(key: ClawCredential, connectorId: string): Promise<void>;
@@ -1,2 +1,2 @@
1
1
  export { formatNumber, pyFloatRepr, round3 } from "./exposition.js";
2
- export { ALERTED, CONTENT_TYPE, EVENT_BUCKETS, HELP, LAG_WINDOW_MS, LEGACY_METRIC_PREFIX, METRIC_PREFIX, PrometheusMetrics, } from "./prometheus-metrics.js";
2
+ export { ALERTED, CONTENT_TYPE, EVENT_BUCKETS, HELP, HELP_CURRENT_ONLY, LAG_WINDOW_MS, LEGACY_METRIC_PREFIX, METRIC_PREFIX, PrometheusMetrics, } from "./prometheus-metrics.js";
@@ -22,6 +22,11 @@ type Labels = ReadonlyArray<readonly [string, string]>;
22
22
  export declare const ALERTED: ReadonlyArray<readonly [string, Labels]>;
23
23
  /** Every metric (by its `personal_agent_` name): its type and help text. */
24
24
  export declare const HELP: Readonly<Record<string, readonly [string, string]>>;
25
+ /**
26
+ * The series added after the names changed: written under their `personal_agent_` names only (no earlier release wrote
27
+ * them), after both halves above, so that the text an earlier release wrote stays as it was.
28
+ */
29
+ export declare const HELP_CURRENT_ONLY: Readonly<Record<string, readonly [string, string]>>;
25
30
  /** The MetricsPort of a worker, kept in memory and written in the Prometheus text format. */
26
31
  export declare class PrometheusMetrics implements MetricsPort {
27
32
  private readonly clock;
@@ -35,6 +40,8 @@ export declare class PrometheusMetrics implements MetricsPort {
35
40
  /** (when, lag): decreasing lags, the sliding-window maximum. */
36
41
  private readonly lags;
37
42
  /** Event type -> (receipt to sent, occurred to sent), each written from the start. */
43
+ private probes;
44
+ private rearmed;
38
45
  private readonly eventTimes;
39
46
  constructor(clock: Clock, lagWindowMs?: number);
40
47
  /** Inbound messages handled so far. */
@@ -44,6 +51,8 @@ export declare class PrometheusMetrics implements MetricsPort {
44
51
  processed(lagMs: number | null, handleMs: number, ok: boolean): void;
45
52
  limited(reason: string): void;
46
53
  filesDropped(path: string, count?: number): void;
54
+ probed(feedbackMs: number, replyMs: number | null): void;
55
+ inboundRearmed(): void;
47
56
  /** The longest wait of the messages handled in the window, in milliseconds (0: none). */
48
57
  lagMaxMs(): number;
49
58
  private expire;
@@ -52,6 +61,7 @@ export declare class PrometheusMetrics implements MetricsPort {
52
61
  * help, under the deprecated names of an earlier release (that half is the text it wrote, byte for byte).
53
62
  */
54
63
  render(): string;
64
+ private renderCurrentOnly;
55
65
  private renderAs;
56
66
  }
57
67
  export {};
package/dist/worker.js CHANGED
@@ -99,6 +99,7 @@ import {
99
99
  channelActions,
100
100
  channelContext,
101
101
  connectionsText,
102
+ forwardBlock,
102
103
  limitsText,
103
104
  MessageRateLimiter,
104
105
  noteMessage,
@@ -118,7 +119,11 @@ function isGroup(message) {
118
119
  var mask = (text) => redactText(text).text;
119
120
  function messageTextFor(channelName) {
120
121
  return {
121
- quoteBlock: (message, group) => quoteBlock(message.quotes, { group, redact: mask }),
122
+ // (what the person forwarded, then what they quoted: both stand before their own words)
123
+ quoteBlock: (message, group) => [
124
+ forwardBlock(message.forwards ?? [], { group, redact: mask }),
125
+ quoteBlock(message.quotes, { group, redact: mask })
126
+ ].filter(Boolean).join("\n\n"),
122
127
  withLinks: (text, message) => withLinks(text, message.links, { group: isGroup(message), redact: mask }),
123
128
  withQuote,
124
129
  unreadable(message) {
@@ -1534,6 +1539,12 @@ function withInboundStats(prometheus, stats) {
1534
1539
  },
1535
1540
  filesDropped: (path, count) => {
1536
1541
  prometheus.filesDropped(path, count);
1542
+ },
1543
+ probed: (feedbackMs, replyMs) => {
1544
+ prometheus.probed(feedbackMs, replyMs);
1545
+ },
1546
+ inboundRearmed: () => {
1547
+ prometheus.inboundRearmed();
1537
1548
  }
1538
1549
  };
1539
1550
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primusclaw/personal-agent-runtime",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Node adapters for the personal agent's ports (clock, randomness, logging, storage, Claw, metrics, HTTP), and, at @primusclaw/personal-agent-runtime/worker, the worker process on any chat surface.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -33,7 +33,7 @@
33
33
  "access": "public"
34
34
  },
35
35
  "dependencies": {
36
- "@primusclaw/personal-agent": "0.11.0",
36
+ "@primusclaw/personal-agent": "0.12.0",
37
37
  "fastify": "^5.12.8",
38
38
  "zod": "^4.6.7"
39
39
  }