@lensmcp/protocol-types 1.25.79 → 1.26.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.
Files changed (55) hide show
  1. package/index.d.ts +9 -1
  2. package/index.js +1 -1
  3. package/lib/ai-call-groups.js +2 -2
  4. package/lib/ai-call-row.js +3 -3
  5. package/lib/ai-call.js +9 -9
  6. package/lib/ai-context.js +6 -6
  7. package/lib/ai-origins.js +9 -9
  8. package/lib/attributes.d.ts +15 -0
  9. package/lib/attributes.js +1 -1
  10. package/lib/bounded-clone.js +1 -1
  11. package/lib/bounded-map.js +1 -1
  12. package/lib/bounded-writer.js +1 -1
  13. package/lib/capture-demand.js +1 -1
  14. package/lib/changes.d.ts +48 -0
  15. package/lib/dashboard-lint.d.ts +207 -0
  16. package/lib/dashboard-lint.js +1 -0
  17. package/lib/dashboard-path.d.ts +15 -0
  18. package/lib/dashboard-path.js +1 -0
  19. package/lib/dashboard.d.ts +198 -3
  20. package/lib/error-cause.d.ts +69 -0
  21. package/lib/error-cause.js +5 -0
  22. package/lib/error-dismissal.js +1 -1
  23. package/lib/event-loop.d.ts +57 -1
  24. package/lib/event-loop.js +1 -1
  25. package/lib/flood-guard.js +1 -1
  26. package/lib/follow-ups.d.ts +238 -0
  27. package/lib/follow-ups.js +1 -0
  28. package/lib/goal-design.d.ts +51 -0
  29. package/lib/goal-design.js +1 -1
  30. package/lib/goal-outcome.d.ts +12 -1
  31. package/lib/goal-retro.d.ts +21 -0
  32. package/lib/lint-coverage.d.ts +113 -0
  33. package/lib/lint-coverage.js +1 -0
  34. package/lib/log-query.js +1 -1
  35. package/lib/metrics-reset.js +1 -1
  36. package/lib/overseer-findings.js +1 -1
  37. package/lib/perf-rules.js +1 -1
  38. package/lib/pod-memory.d.ts +2 -0
  39. package/lib/pod-memory.js +1 -1
  40. package/lib/producer-health.js +1 -1
  41. package/lib/role-fidelity.d.ts +210 -0
  42. package/lib/role-fidelity.js +1 -0
  43. package/lib/sources.js +1 -1
  44. package/lib/system-report.js +1 -1
  45. package/lib/team-delivery.d.ts +38 -4
  46. package/lib/team-delivery.js +1 -1
  47. package/lib/team-design.d.ts +224 -0
  48. package/lib/team-design.js +1 -1
  49. package/lib/team-prompts.d.ts +16 -7
  50. package/lib/team-prompts.js +4 -47
  51. package/lib/team-skills.d.ts +355 -0
  52. package/lib/team-skills.js +1 -0
  53. package/lib/team.d.ts +95 -1
  54. package/lib/team.js +1 -1
  55. package/package.json +1 -1
@@ -14,6 +14,7 @@ import type { HttpExchange } from './http-exchange.js';
14
14
  import type { DashTeamDesignRun, TeamDesign } from './team-design.js';
15
15
  import type { PageVisitNavType, PageVisitRaw, PageVisitReadyBy, PageVisitRequest, PageVisitVitals } from './page-visit.js';
16
16
  import type { WorktreeRunOutcome } from './workspace-actions.js';
17
+ import type { DesignStage } from './goal-design.js';
17
18
  import type { DashExternalBefore, DashSqlBefore } from './metrics-reset.js';
18
19
  /** Bumped only on a breaking change to the stream framing itself. */
19
20
  export declare const DASHBOARD_PROTOCOL = 1;
@@ -517,6 +518,10 @@ export interface DashFlowNode {
517
518
  role?: string;
518
519
  queue?: string;
519
520
  jobId?: string;
521
+ /** The database a SQL step ran on when it is not Postgres (`mysql`). */
522
+ db?: string;
523
+ /** The broker a queue step went through when it is not BullMQ (`kafka`). */
524
+ broker?: string;
520
525
  sig?: string;
521
526
  urlKey?: string;
522
527
  method?: string;
@@ -646,7 +651,15 @@ export interface DashSegmentStats {
646
651
  }
647
652
  export interface DashFlowDetail {
648
653
  flowId: string;
654
+ /** The stalls that ran this flow's code: the only ones that count against it. */
649
655
  eventLoopIncidents?: import('./event-loop.js').EventLoopIncident[];
656
+ /** Stalls that only overlapped it in time, as one context line: never a problem. */
657
+ eventLoopOverlaps?: {
658
+ count: number;
659
+ services: string[];
660
+ longestMs: number;
661
+ text: string;
662
+ };
650
663
  /** The reducer's own summary (kept as-is for older consumers). */
651
664
  summary: unknown;
652
665
  events: DashFlowNode[];
@@ -909,11 +922,66 @@ export interface DashErrors {
909
922
  * flow when none of those has one) — what Errors shows of a group. The error log keeps more; `count` is all of them.
910
923
  */
911
924
  occurrencesShown?: number;
925
+ /**
926
+ * One row per CAUSE (issues/closed/overseer-71): the groups above that are one error — the 500s of each route it
927
+ * broke and the log line an exception filter printed for it — folded together by `errorCause` (error-cause.ts).
928
+ * Built from the shown groups only, so a dismissed group is in none. Absent from a server that predates it.
929
+ */
930
+ causes?: DashErrorCause[];
931
+ /**
932
+ * Occurrences the producers' flood guards held back that no single cause can claim (one bucket held several),
933
+ * plus any the error log itself let go of. Per-cause drops are on each cause (`DashErrorCause.dropped`).
934
+ */
935
+ dropped?: number;
936
+ }
937
+ /** Where a cause surfaced: one of its groups, as a row of the cause («GET /documents → 500 ×30»). */
938
+ export interface DashErrorSurface {
939
+ groupId: string;
940
+ kind: DashErrorKind;
941
+ label: string;
942
+ project?: string;
943
+ count: number;
944
+ }
945
+ /** One error, however many places it surfaced. Its `id` is `errorCause`'s, or `cause:<group id>` for a group that has no class to tell it by. */
946
+ export interface DashErrorCause {
947
+ id: string;
948
+ /** `QueryFailedError: column "x" does not exist`, or the group's title. */
949
+ title: string;
950
+ /** What it means, for a well-known error (`errorHeadline`); otherwise the message says it. */
951
+ headline?: string;
952
+ /** What usually fixes it. */
953
+ hint?: string;
954
+ errorName?: string;
955
+ message?: string;
956
+ /** One sample stack, app frames first. */
957
+ stack?: string;
958
+ /** The kind of its first surface. */
959
+ kind: DashErrorKind;
960
+ /** Occurrences: a request and the log line it printed are one, so a cause that has requests counts those. */
961
+ count: number;
962
+ /** Since it was dismissed, when it came back after one; otherwise its first occurrence ever. */
963
+ firstSeenAt: number;
964
+ lastSeenAt: number;
965
+ /** Occurrences in the minute before the frame's `at`, the flood-guard drops it can claim included. */
966
+ ratePerMin: number;
967
+ /** Occurrences the producers' flood guards held back that are known to be this cause's. */
968
+ dropped?: number;
969
+ surfaces: DashErrorSurface[];
970
+ services: string[];
971
+ /** Every group it folds — what dismissing it dismisses. */
972
+ groupIds: string[];
973
+ spark: number[];
974
+ flowCount: number;
975
+ ongoing?: boolean;
976
+ /** It was dismissed and happened again: counted from its return. */
977
+ back?: boolean;
912
978
  }
913
979
  /** `POST /api/errors/dismiss` and `/api/errors/restore` — the body, and the answer. */
914
980
  export interface DashErrorIds {
915
981
  /** `DashErrorGroup.id`s. Ones the dashboard does not hold are ignored. */
916
982
  ids: string[];
983
+ /** `DashErrorCause.id`s: every group of each (dismiss only). Ones the dashboard does not hold are ignored. */
984
+ causes?: string[];
917
985
  }
918
986
  export interface DashErrorIdsResult {
919
987
  /** How many of them were written to the bus. */
@@ -1021,6 +1089,10 @@ export interface DashSummary {
1021
1089
  };
1022
1090
  /** `DashSession.setupIssues.length`. */
1023
1091
  setupIssues?: number;
1092
+ /** The lint errors the last lint runs left, each once (Investigate › Lint's badge). Absent while `lint://` is not served. */
1093
+ lint?: {
1094
+ errors: number;
1095
+ };
1024
1096
  /**
1025
1097
  * The pages of the features `lensmcp.json` turns off, by screen id (planning/modules/01-split.md S4): they leave the
1026
1098
  * sidebar, and opening one says it is off and how it comes back. Absent when every page is on, and from a lens
@@ -1279,6 +1351,15 @@ export interface DashRouteDetail extends DashRouteSummary {
1279
1351
  /** The latest run against the oldest one kept. */
1280
1352
  changesSinceOldest: DashRouteChange[];
1281
1353
  }
1354
+ /**
1355
+ * A route's SQL statements by time spent — the ones its route review is shown (`/api/catalog/route/statements`), the
1356
+ * first `limit`; `total` counts them all.
1357
+ */
1358
+ export interface DashRouteStatements {
1359
+ id: string;
1360
+ total: number;
1361
+ statements: DashSqlTemplateSummary[];
1362
+ }
1282
1363
  export interface DashRoutesCatalog {
1283
1364
  at: number;
1284
1365
  routes: DashRouteSummary[];
@@ -1719,9 +1800,13 @@ export interface DashCodeSite {
1719
1800
  services: string[];
1720
1801
  lastSeenAt: number;
1721
1802
  }
1803
+ /** The engine a SQL statement ran on: the tap's `name` (`mysql` from the mysql2 tap); a tap before it names `postgres` or nothing. */
1804
+ export type DashSqlEngine = 'postgres' | 'mysql';
1722
1805
  export interface DashSqlTemplateSummary {
1723
1806
  /** 12 hex characters — the statement's shape (`@lensmcp/core/sql-shape`). */
1724
1807
  id: string;
1808
+ /** The engine it ran on — absent from an older lens: `postgres`. The lens's Postgres reads (plans, pg_stat_statements, tables) take only `postgres`. */
1809
+ engine?: DashSqlEngine;
1725
1810
  /** The statement with literals as `?` and value lists folded to `(…)`. */
1726
1811
  template: string;
1727
1812
  /** A leading comment naming it (`registry.product-composition`). */
@@ -1788,6 +1873,8 @@ export interface DashSqlTemplateDetail extends DashSqlTemplateSummary {
1788
1873
  }
1789
1874
  export interface DashSqlTable {
1790
1875
  name: string;
1876
+ /** The engines of the statements that touch it — absent from an older lens: `postgres`. */
1877
+ engines?: DashSqlEngine[];
1791
1878
  /** The databases the statements that touch it ran on (the pg tap names each); absent from an older tap. */
1792
1879
  databases?: string[];
1793
1880
  /** Runs of reading statements that touched it, and of writing ones. */
@@ -1804,6 +1891,7 @@ export interface DashSqlTable {
1804
1891
  export interface DashSqlRun extends DashSqlExecution {
1805
1892
  /** Its statement's shape id, verb, template and tables. */
1806
1893
  id: string;
1894
+ engine?: DashSqlEngine;
1807
1895
  verb: string;
1808
1896
  template: string;
1809
1897
  tables: string[];
@@ -2727,10 +2815,12 @@ export interface DashAiRun {
2727
2815
  * `kvstore` / `queuestore`: one Redis store's keys / BullMQ queues (`<store>`); `files`: the services' file access
2728
2816
  * (`files`); `external`: the external APIs the services call (`external`); `log`: one log line (its `seq`);
2729
2817
  * `aiagent`: one AI agent of the app, by its key on the AI calls page (`agent:onboarding-chat-conductor`);
2730
- * `team`: the project's agent team, designed (`team.design`) — by its repository (`project` when it has no id).
2818
+ * `team`: the project's agent team, designed (`team.design`) — by its repository (`project` when it has no id);
2819
+ * `goal`: one goal's design written from suggestions (`suggestions.combine`) — by the suggestions it combines — or the
2820
+ * proposed goals written from finished goals' follow-ups (`follow-ups.organize`, `follow-ups.reorganize`).
2731
2821
  */
2732
2822
  target: {
2733
- kind: 'sql' | 'route' | 'error' | 'flow' | 'ui' | 'kv' | 'queue' | 'db' | 'dbtable' | 'kvstore' | 'queuestore' | 'files' | 'external' | 'log' | 'page' | 'aiagent' | 'team';
2823
+ kind: 'sql' | 'route' | 'error' | 'flow' | 'ui' | 'kv' | 'queue' | 'db' | 'dbtable' | 'kvstore' | 'queuestore' | 'files' | 'external' | 'log' | 'page' | 'aiagent' | 'team' | 'goal';
2734
2824
  id: string;
2735
2825
  label: string;
2736
2826
  name?: string;
@@ -2820,6 +2910,17 @@ export interface DashAiRun {
2820
2910
  design?: TeamDesign;
2821
2911
  /** The design was accepted on the Team page: when, the files it wrote, the goals it created. */
2822
2912
  accepted?: DashTeamDesignRun['accepted'];
2913
+ /** The goal a combine run filed (`suggestions.combine`): its design waits for the person. */
2914
+ goal?: {
2915
+ id: string;
2916
+ title: string;
2917
+ };
2918
+ /** An Organize or Reorganize all run (Suggestions › Follow-ups): the finished goals it read and the proposals it made. */
2919
+ followUps?: {
2920
+ kind: 'organize' | 'reorganize';
2921
+ goals: string[];
2922
+ proposals: string[];
2923
+ };
2823
2924
  impact?: DashAiImpact;
2824
2925
  /** The instructions it sent: which guide, the workspace's rules and memories, the indicator set. */
2825
2926
  prompt?: DashAiPrompt;
@@ -3111,6 +3212,65 @@ export interface DashSuggestions {
3111
3212
  /** What coding agents are shown (`nx.json` → `lensmcp.ai.agentFeed`): accepted suggestions only, or new ones too. */
3112
3213
  feed: 'accepted' | 'all';
3113
3214
  }
3215
+ /**
3216
+ * A goal filed from suggestions (`/api/team/suggestion-goals`): «Accept + task» (the suggestion is its approved design)
3217
+ * or «Combine into a goal» (Claude wrote one design from several; it waits for the person). Its title, where it is, and
3218
+ * the suggestions it was filed from. When it completes, they move to applied and their checks are scheduled.
3219
+ */
3220
+ export interface DashSuggestionGoal {
3221
+ goalId: string;
3222
+ title: string;
3223
+ state: string;
3224
+ outcome?: string;
3225
+ /** Marked done by the person (`--done`), not by its agents. */
3226
+ personDone?: boolean;
3227
+ stage?: DesignStage;
3228
+ /** The suggestions' ids (`sg-…`). */
3229
+ suggestions: string[];
3230
+ /** When its completion moved them to applied and scheduled their checks. */
3231
+ settledAt?: number;
3232
+ updatedAt: number;
3233
+ }
3234
+ export interface DashSuggestionGoals {
3235
+ goals: DashSuggestionGoal[];
3236
+ }
3237
+ /** «Combine into a goal» before it spends: what it sends, what it may cost, and today's dashboard allowance. */
3238
+ export interface DashCombineEstimate {
3239
+ ids: string[];
3240
+ model: string;
3241
+ /** The first message's size, estimated, and what the run may read on top (code, LensMCP's check of the draft). */
3242
+ inputTokens: number;
3243
+ /** A run's likely cost — its message, its research and the design it writes; undefined when the model has no price. */
3244
+ estimateUsd?: number;
3245
+ /** The most it may spend: its own ceiling, or less when today's allowance has less left. */
3246
+ maxUsd: number;
3247
+ allowance: {
3248
+ capUsd: number;
3249
+ spentUsd: number;
3250
+ leftUsd: number;
3251
+ };
3252
+ refs: number;
3253
+ excerpts: number;
3254
+ /** What was left out to keep the message bounded. */
3255
+ dropped?: string[];
3256
+ /** Whether it can start now — a key, the allowance, the team on; `why` says what stops it. */
3257
+ ready: boolean;
3258
+ why?: string;
3259
+ }
3260
+ /** A combine run as the Suggestions page follows it — and the goal it filed once it is done. */
3261
+ export interface DashCombineRun {
3262
+ runId: string;
3263
+ status: DashAiRun['status'];
3264
+ step: string;
3265
+ startedAt: number;
3266
+ finishedAt?: number;
3267
+ costUsd: number;
3268
+ error?: string;
3269
+ goal?: {
3270
+ id: string;
3271
+ title: string;
3272
+ };
3273
+ }
3114
3274
  /** One issue of `kv://lint`: a Redis / Valkey key family against what a coding agent fixes. */
3115
3275
  export interface DashKvLintIssue {
3116
3276
  severity: 'error' | 'warning';
@@ -3775,12 +3935,47 @@ export interface DashRunningVersion {
3775
3935
  }
3776
3936
  export interface DashVersions {
3777
3937
  at: number;
3778
- /** The lensmcp in this workspace's node_modules now, and when it was put there. */
3938
+ /** The lensmcp in this workspace's node_modules now, and when it was put there — the store's current one, when the machine has a store. */
3779
3939
  installed?: {
3780
3940
  version: string;
3781
3941
  at?: number;
3782
3942
  };
3783
3943
  processes: DashRunningVersion[];
3944
+ /** The machine's store of LensMCP versions (planning/global), when it has one. */
3945
+ store?: DashStore;
3946
+ }
3947
+ /** One version folder of the machine's store. */
3948
+ export interface DashStoreVersion {
3949
+ version: string;
3950
+ current: boolean;
3951
+ /** The pids that run from it now. */
3952
+ running: number[];
3953
+ /** The optional packages installed beside lensmcp in it (`@lensmcp/terminals`, …). */
3954
+ optional: string[];
3955
+ }
3956
+ /** A workspace the gateway registered: the version it was last set up with, and its migrations still to do. */
3957
+ export interface DashStoreWorkspace {
3958
+ key: string;
3959
+ root: string;
3960
+ setupVersion?: string;
3961
+ /** Its setup is older than the current version: the lens runs the auto migrations at its next gate, setup the rest. */
3962
+ behind: boolean;
3963
+ /** The journal's entries that wait (pending) or failed. */
3964
+ pending: {
3965
+ id: string;
3966
+ state: 'pending' | 'failed';
3967
+ why?: string;
3968
+ }[];
3969
+ }
3970
+ export interface DashStore {
3971
+ home: string;
3972
+ current?: string;
3973
+ /** The version the running lens runs — the gateway's, else this dashboard's. */
3974
+ lens?: string;
3975
+ /** The running lens runs another version than current: it keeps it until it restarts (`lensmcp restart`). */
3976
+ restartRequired: boolean;
3977
+ versions: DashStoreVersion[];
3978
+ workspaces: DashStoreWorkspace[];
3784
3979
  }
3785
3980
  /** Where a setting's value comes from: its default, this machine, this repository's `lensmcp.json`, or the environment. */
3786
3981
  export type DashSettingSource = 'default' | 'machine' | 'repository' | 'env';
@@ -0,0 +1,69 @@
1
+ /**
2
+ * What an error IS, apart from where it surfaced (issues/closed/overseer-71).
3
+ *
4
+ * One exception reaches the lens several ways: the 500 of each route it broke, and the log line an exception filter
5
+ * printed for it. A CAUSE is what they share — the error's class, its message with ids and numbers folded, and the
6
+ * first frame in the app's own code. The dashboard's Errors page and `observe_errors` both group by it, so a row
7
+ * there and an entry here name the same thing, and `observe_dismiss_errors` can hide one by its id.
8
+ *
9
+ * And what a well-known error means, in a sentence a person reads before the stack: `errorHeadline`.
10
+ */
11
+ /** Joins parts into an id no two different part lists share: a `:` inside a part is escaped, never a separator. */
12
+ export declare function joinId(prefix: string, parts: readonly (string | number | undefined)[]): string;
13
+ /** A message with what differs between occurrences folded: uuids, ULIDs, hex, numbers. Its first line, bounded. */
14
+ export declare function foldMessage(s: string | undefined): string;
15
+ export interface ErrorCauseInput {
16
+ /** The error's class, when the producer named it (`QueryFailedError`). */
17
+ name?: string;
18
+ message?: string;
19
+ stack?: string;
20
+ /** What the line or request said, when nothing else did: `Uncaught TypeError: x is undefined`. */
21
+ title?: string;
22
+ }
23
+ export interface ErrorCause {
24
+ /** `cause:<name>:<message>:<frame>` — the same for every surface of one error. */
25
+ id: string;
26
+ errorName: string;
27
+ /** The message as written (its first line), not folded. */
28
+ message: string;
29
+ /** The first frame in the app's code, `file:line`, when the stack has one. */
30
+ frame?: string;
31
+ }
32
+ /** The first frame outside dependencies and the runtime, as `file:line` (the column dropped: a rebuild moves it). */
33
+ export declare function appFrameOf(stack: string | undefined): string | undefined;
34
+ /**
35
+ * The cause of an error, or nothing when it has no class to tell it by — a gateway 503, a refused connection with
36
+ * no error object: those stay grouped by where they surfaced, since nothing says two of them are one thing.
37
+ */
38
+ export declare function errorCause(input: ErrorCauseInput): ErrorCause | undefined;
39
+ /** The cause's id without its frame — what a surface that carried no stack is matched on. */
40
+ export declare function causeIdWithoutFrame(c: Pick<ErrorCause, 'errorName' | 'message'>): string;
41
+ export interface HeadlineInput {
42
+ name?: string;
43
+ message?: string;
44
+ /** A driver's code (`ER_BAD_FIELD_ERROR`, `23505`, `ECONNREFUSED`), when the message does not carry it. */
45
+ code?: string;
46
+ /** The HTTP status the request answered. */
47
+ status?: number;
48
+ }
49
+ export interface ErrorHeadline {
50
+ /** Which entry of the table said it. */
51
+ id: string;
52
+ /** What happened, in plain words. */
53
+ headline: string;
54
+ /** What usually fixes it. */
55
+ hint?: string;
56
+ }
57
+ interface HeadlineRule {
58
+ id: string;
59
+ match: (text: string, input: HeadlineInput) => RegExpExecArray | true | null | false;
60
+ say: (m: RegExpExecArray | true) => Omit<ErrorHeadline, 'id'>;
61
+ }
62
+ /**
63
+ * Well-known errors, said plainly. First match wins, so the specific (a missing column) sits above the general (a
64
+ * query that failed). An error not in the table has no headline: the page shows its message.
65
+ */
66
+ export declare const ERROR_HEADLINES: readonly HeadlineRule[];
67
+ /** What a well-known error means, or nothing — then its message says it. */
68
+ export declare function errorHeadline(input: HeadlineInput): ErrorHeadline | undefined;
69
+ export {};
@@ -0,0 +1,5 @@
1
+ "use strict";var p=Object.defineProperty;var n=(e,t)=>p(e,"name",{value:t,configurable:!0});var f=Object.defineProperty,s=n((e,t)=>f(e,"name",{value:t,configurable:!0}),"n"),g=Object.defineProperty,a=s((e,t)=>g(e,"name",{value:t,configurable:!0}),"n");export function joinId(e,t){const o=a(i=>i.replace(/%/g,"%25").replace(/:/g,"%3A"),"esc");return[e,...t.map(i=>o(i===void 0?"":String(i)))].join(":")}n(joinId,"joinId"),s(joinId,"joinId"),a(joinId,"joinId");export function foldMessage(e){return e?e.split(`
2
+ `)[0].replace(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi,"<id>").replace(/\b[0-9A-HJKMNP-TV-Z]{26}\b/g,"<id>").replace(/0x[0-9a-f]+/gi,"<hex>").replace(/\b[0-9a-f]{12,}\b/gi,"<id>").replace(/\d+/g,"#").trim().slice(0,140):""}n(foldMessage,"foldMessage"),s(foldMessage,"foldMessage"),a(foldMessage,"foldMessage");const E=/^(?:Uncaught\s+(?:\(in promise\)\s+)?)?((?:[A-Za-z_$][\w$]*)?(?:Error|Exception|Failure|Fault|Rejection))(?:\s*\[[^\]]*\])?:\s*(.+)$/;function d(e){const t=E.exec((e??"").split(`
3
+ `)[0].trim());return t?{name:t[1],message:t[2].trim()}:void 0}n(d,"c"),s(d,"r"),a(d,"named");export function appFrameOf(e){for(const t of(e??"").split(`
4
+ `)){const o=/^\s*at\s+(.+)$/.exec(t);if(!o||/node_modules|node:internal|node:async_hooks|\(native\)|<anonymous>|\(internal\//.test(o[1]))continue;const i=/\(?([^()\s]+?):(\d+)(?::\d+)?\)?$/.exec(o[1].trim());return i?`${i[1].replace(/^.*?\/(?=(?:src|apps|libs)\/)/,"")}:${i[2]}`:o[1].trim()}}n(appFrameOf,"appFrameOf"),s(appFrameOf,"appFrameOf"),a(appFrameOf,"appFrameOf");export function errorCause(e){const t=d(e.stack),o=d(e.message),i=d(e.title),c=e.name?.trim()||t?.name||o?.name||i?.name;if(!c)return;let r=(t&&t.name===c?t.message:void 0)??e.message??i?.message??e.title??"";const h=d(r);h&&h.name===c&&(r=h.message),r=r.split(`
5
+ `)[0].trim();const u=appFrameOf(e.stack),l=y.has(errorHeadline({name:c,message:r})?.id??"");return{id:joinId("cause",[c,foldMessage(r),l?void 0:u]),errorName:c,message:r,...u?{frame:u}:{}}}n(errorCause,"errorCause"),s(errorCause,"errorCause"),a(errorCause,"errorCause");const y=new Set(["missing-column","missing-table","connection-refused","out-of-memory"]);export function causeIdWithoutFrame(e){return joinId("cause",[e.errorName,foldMessage(e.message),void 0])}n(causeIdWithoutFrame,"causeIdWithoutFrame"),s(causeIdWithoutFrame,"causeIdWithoutFrame"),a(causeIdWithoutFrame,"causeIdWithoutFrame");const m=a(e=>e?` (\xAB${e}\xBB)`:"","q");export const ERROR_HEADLINES=[{id:"missing-column",match:a(e=>/column "?([\w.]+)"?(?: of relation "?[\w.]+"?)? does not exist|Unknown column '([^']+)'|ER_BAD_FIELD_ERROR/i.exec(e),"match"),say:a(e=>({headline:`The code expects a database column${m(e===!0?void 0:e[1]??e[2])} the database doesn't have`,hint:"Run the migrations, or add the migration the entity change needs."}),"say")},{id:"missing-table",match:a(e=>/relation "?([\w.]+)"? does not exist|Table '([^']+)' doesn't exist|ER_NO_SUCH_TABLE/i.exec(e),"match"),say:a(e=>({headline:`The code expects a database table${m(e===!0?void 0:e[1]??e[2])} the database doesn't have`,hint:"Run the migrations against this database."}),"say")},{id:"unique-violation",match:a((e,t)=>/duplicate key value violates unique constraint "?([\w.]+)"?|Duplicate entry '[^']*' for key '([^']+)'|ER_DUP_ENTRY/i.exec(e)||t.code==="23505","match"),say:a(e=>({headline:`A row with the same unique value already exists${m(e===!0?void 0:e[1]??e[2])}`,hint:"The code inserts a duplicate: look up the existing row first, or upsert."}),"say")},{id:"foreign-key-violation",match:a((e,t)=>/violates foreign key constraint "?([\w.]+)"?|a foreign key constraint fails|ER_NO_REFERENCED_ROW|ER_ROW_IS_REFERENCED/i.exec(e)||t.code==="23503","match"),say:a(e=>({headline:`A row points at a row that doesn't exist, or a row still in use was deleted${m(e===!0?void 0:e[1])}`,hint:"Create the referenced row first, or delete the rows that point at it."}),"say")},{id:"connection-refused",match:a((e,t)=>/ECONNREFUSED|connection refused|connect ECONNREFUSED/i.exec(e)||t.code==="ECONNREFUSED","match"),say:a(()=>({headline:"A service the code connects to is not running, or not listening where the code looks",hint:"Start it (database, cache, broker or API), or fix its host and port."}),"say")},{id:"out-of-memory",match:a((e,t)=>/heap out of memory|JavaScript heap|out of memory|ENOMEM|Allocation failed/i.exec(e)||t.code==="ENOMEM","match"),say:a(()=>({headline:"The process ran out of memory",hint:"Something holds or loads too much at once \u2014 look for an unbounded list, cache or query."}),"say")},{id:"jwt-expired",match:a((e,t)=>/jwt expired|token expired/i.exec(e)||t.name==="TokenExpiredError","match"),say:a(()=>({headline:"A sign-in token expired",hint:"Sign in again; if it keeps happening, the client is not refreshing its token."}),"say")},{id:"jwt-invalid",match:a((e,t)=>/jwt malformed|invalid signature|invalid token|jwt must be provided|jwt audience invalid|jwt issuer invalid/i.exec(e)||t.name==="JsonWebTokenError","match"),say:a(()=>({headline:"A sign-in token is not valid here",hint:"Its signature, audience or issuer does not match what this service expects."}),"say")},{id:"timeout",match:a((e,t)=>/ETIMEDOUT|ESOCKETTIMEDOUT|timed? ?out|timeout exceeded|statement timeout|canceling statement due to|Query read timeout/i.exec(e)||t.name==="TimeoutError"||t.code==="ETIMEDOUT","match"),say:a(()=>({headline:"Something took too long and was cut off",hint:"A slow query, a busy dependency or a lock \u2014 open the failing step to see which."}),"say")},{id:"unauthorized",match:a((e,t)=>t.status===401||t.name==="UnauthorizedException"||/^Unauthorized$/i.test(e.trim()),"match"),say:a(()=>({headline:"The request was not signed in (401)",hint:"It came without a valid session or token."}),"say")},{id:"forbidden",match:a((e,t)=>t.status===403||t.name==="ForbiddenException"||/^Forbidden(?: resource)?$/i.test(e.trim()),"match"),say:a(()=>({headline:"The signed-in user is not allowed to do this (403)",hint:"A role or permission check refused it."}),"say")}];export function errorHeadline(e){const t=[e.code,e.message].filter(Boolean).join(" ");for(const o of ERROR_HEADLINES){const i=o.match(t,e);if(i)return{id:o.id,...o.say(i)}}}n(errorHeadline,"errorHeadline"),s(errorHeadline,"errorHeadline"),a(errorHeadline,"errorHeadline");
@@ -1 +1 @@
1
- "use strict";var f=Object.defineProperty;var s=(t,r)=>f(t,"name",{value:r,configurable:!0});var E=Object.defineProperty,S=s((t,r)=>E(t,"name",{value:r,configurable:!0}),"s");export const ERROR_DISMISSED="error-dismissed",ERROR_RESTORED="error-restored",LENS_EVENT_SOURCE="lens",MAX_DISMISSAL_EVENT_IDS=200;const g=2048;export const MAX_DISMISSAL_REASON_CHARS=500;const m=300,I=new Set(["dashboard","cli","agent"]);export function readErrorDismissal(t){if(t.source!==LENS_EVENT_SOURCE||!t.raw||typeof t.raw!="object")return;const r=t.raw,i=r.groupId;if(typeof i!="string"||i.length===0||i.length>2048)return;if(r.kind===ERROR_RESTORED)return{kind:ERROR_RESTORED,groupId:i};if(r.kind!==ERROR_DISMISSED)return;const n=r.until;if(typeof n!="number"||!Number.isFinite(n))return;const c=Array.isArray(r.eventIds)?r.eventIds.filter(e=>typeof e=="string"&&e.length>0).slice(0,200):[],o=I.has(r.by)?r.by:void 0,a=S((e,l)=>typeof e=="string"&&e.trim()?e.trim().slice(0,l):void 0,"text"),d=a(r.reason,500),u=a(r.title,300);return{kind:ERROR_DISMISSED,groupId:i,until:Math.min(n,t.timestamp),eventIds:c,...o?{by:o}:{},...d?{reason:d}:{},...u?{title:u}:{}}}s(readErrorDismissal,"readErrorDismissal"),S(readErrorDismissal,"readErrorDismissal");
1
+ "use strict";var E=Object.defineProperty;var s=(e,r)=>E(e,"name",{value:r,configurable:!0});var m=Object.defineProperty,c=s((e,r)=>m(e,"name",{value:r,configurable:!0}),"s"),p=Object.defineProperty,l=c((e,r)=>p(e,"name",{value:r,configurable:!0}),"s");export const ERROR_DISMISSED="error-dismissed",ERROR_RESTORED="error-restored",LENS_EVENT_SOURCE="lens",MAX_DISMISSAL_EVENT_IDS=200;const y=2048;export const MAX_DISMISSAL_REASON_CHARS=500;const b=300,I=new Set(["dashboard","cli","agent"]);export function readErrorDismissal(e){if(e.source!==LENS_EVENT_SOURCE||!e.raw||typeof e.raw!="object")return;const r=e.raw,i=r.groupId;if(typeof i!="string"||i.length===0||i.length>2048)return;if(r.kind===ERROR_RESTORED)return{kind:ERROR_RESTORED,groupId:i};if(r.kind!==ERROR_DISMISSED)return;const n=r.until;if(typeof n!="number"||!Number.isFinite(n))return;const f=Array.isArray(r.eventIds)?r.eventIds.filter(t=>typeof t=="string"&&t.length>0).slice(0,200):[],o=I.has(r.by)?r.by:void 0,a=l((t,S)=>typeof t=="string"&&t.trim()?t.trim().slice(0,S):void 0,"text"),d=a(r.reason,500),u=a(r.title,300);return{kind:ERROR_DISMISSED,groupId:i,until:Math.min(n,e.timestamp),eventIds:f,...o?{by:o}:{},...d?{reason:d}:{},...u?{title:u}:{}}}s(readErrorDismissal,"readErrorDismissal"),c(readErrorDismissal,"readErrorDismissal"),l(readErrorDismissal,"readErrorDismissal");
@@ -35,16 +35,68 @@ export interface EventLoopIncident {
35
35
  durationMs: number;
36
36
  state: 'recovered' | 'unresponsive' | 'unknown';
37
37
  mechanism: 'callback' | 'heartbeat' | 'long-animation-frame' | 'longtask';
38
- severity: 'warning' | 'error';
38
+ /** `info`: LensMCP's own work ({@link lensOwnWork}), never a flow's. */
39
+ severity: 'info' | 'warning' | 'error';
39
40
  /** Exact async execution context, when measured inside a Node callback. Not a CPU profile. */
40
41
  flowId?: string;
41
42
  requestId?: string;
42
43
  callbackType?: string;
44
+ /** What held the loop when the sampler knows ({@link LENS_CAUSES}); absent from an older sampler: unknown. */
45
+ cause?: string;
46
+ /** How much of it LensMCP itself spent, ms. */
47
+ lensMs?: number;
48
+ /** A forced GC: how long LensMCP held it back for requests in flight, when it did. */
49
+ deferredMs?: number;
50
+ /** The watchdog's measure of the same stall, when it saw it too. */
51
+ heartbeatMs?: number;
43
52
  scripts: EventLoopScript[];
44
53
  evidence: EventLoopEvidence[];
45
54
  evidenceTruncated: boolean;
46
55
  explanation: string;
47
56
  }
57
+ export declare const LENS_CAUSES: Readonly<Record<string, string>>;
58
+ /** The label of a stall that was LensMCP's own work — its cause is the lens's, or the lens spent half of it or more. */
59
+ export declare function lensOwnWork(i: Pick<EventLoopIncident, 'durationMs'> & Partial<Pick<EventLoopIncident, 'cause' | 'lensMs'>>): string | undefined;
60
+ export interface StallWaiters {
61
+ requests: number;
62
+ flows: number;
63
+ /** The evidence was capped: more may have waited. */
64
+ atLeast: boolean;
65
+ }
66
+ /** The requests in flight on the loop while it was held, from the overlap evidence — never the stall's own. */
67
+ export declare function waitedBehind(i: Pick<EventLoopIncident, 'evidence' | 'evidenceTruncated' | 'flowId' | 'requestId'>): StallWaiters;
68
+ export declare function waitedLine(i: Parameters<typeof waitedBehind>[0]): string | undefined;
69
+ /** A stall that only overlapped a flow in time: `overlapMs` is how long the two were open together. */
70
+ export interface FlowStallOverlap {
71
+ incident: EventLoopIncident;
72
+ overlapMs: number;
73
+ }
74
+ export interface FlowStalls {
75
+ /** Stalls whose callback ran this flow's code: the only ones that count against it. */
76
+ ran: EventLoopIncident[];
77
+ overlapped: FlowStallOverlap[];
78
+ }
79
+ /** A flow's stalls apart: those that ran its code, and those that only overlapped it; LensMCP's own work is neither. */
80
+ export declare function flowStalls(incidents: readonly EventLoopIncident[], flowId: string): FlowStalls;
81
+ /** The one context line of a flow's overlapping stalls: how many, in which services, the longest overlap. */
82
+ export declare function overlapLine(overlapped: readonly FlowStallOverlap[]): {
83
+ count: number;
84
+ services: string[];
85
+ longestMs: number;
86
+ text: string;
87
+ } | undefined;
88
+ /** What LensMCP's own work cost the loops over a window. */
89
+ export interface EventLoopOwnWork {
90
+ windowMs: number;
91
+ count: number;
92
+ totalMs: number;
93
+ longestMs: number;
94
+ causes: Array<{
95
+ cause: string;
96
+ count: number;
97
+ totalMs: number;
98
+ }>;
99
+ }
48
100
  export interface EventLoopStatus {
49
101
  loop: EventLoopIdentity;
50
102
  lastSeen: number;
@@ -62,6 +114,8 @@ export interface EventLoopsView {
62
114
  nextBefore?: number;
63
115
  persistence: 'disk' | 'memory';
64
116
  retentionDays: number;
117
+ /** LensMCP's own pauses over the last hour: absent on a flow's or one incident's read, and from an older lens. */
118
+ lensOwn?: EventLoopOwnWork;
65
119
  }
66
120
  /**
67
121
  * A loop's delay over one short window — `[end of the window (epoch ms), mean, p99, max (ms), utilization (0–1)]`.
@@ -116,6 +170,8 @@ export interface EventLoopPhaseWindow {
116
170
  from: number;
117
171
  to: number;
118
172
  running: EventLoopPhaseTotals;
173
+ /** Of the window's stalls, those that were LensMCP's own work: counted in `running` and `startup` too. */
174
+ lensOwn?: EventLoopOwnWork;
119
175
  startup: EventLoopPhaseTotals & {
120
176
  /** Node processes that started in the window, and those of them with a stall in their first minute. */
121
177
  starts: number;
package/lib/event-loop.js CHANGED
@@ -1 +1 @@
1
- "use strict";var a=Object.defineProperty;var r=(t,e)=>a(t,"name",{value:e,configurable:!0});var i=Object.defineProperty,s=r((t,e)=>i(t,"name",{value:e,configurable:!0}),"e");export const LOOP_STARTUP_MS=6e4;export function loopStartedAt(t){if(!t.startsWith("node:"))return;const e=Number(t.slice(t.lastIndexOf(":")+1));return Number.isFinite(e)&&e>0?e:void 0}r(loopStartedAt,"loopStartedAt"),s(loopStartedAt,"loopStartedAt");export function loopPhaseAt(t,e){const n=loopStartedAt(t);if(n===void 0)return;const o=Math.max(0,Math.round(e-n));return{phase:o<6e4?"startup":"running",sinceStartMs:o}}r(loopPhaseAt,"loopPhaseAt"),s(loopPhaseAt,"loopPhaseAt");
1
+ "use strict";var f=Object.defineProperty;var s=(e,t)=>f(e,"name",{value:t,configurable:!0});var w=Object.defineProperty,a=s((e,t)=>w(e,"name",{value:t,configurable:!0}),"r"),h=Object.defineProperty,l=a((e,t)=>h(e,"name",{value:t,configurable:!0}),"r");export const LENS_CAUSES={"lensmcp-gc":"forced GC","lensmcp-cleanup":"cleanup","lensmcp-write":"writing events","lensmcp-capture":"capturing values"};export function lensOwnWork(e){const t=typeof e.cause=="string"&&e.cause.startsWith("lensmcp-");if(!t&&!(typeof e.lensMs=="number"&&e.durationMs>0&&e.lensMs>=e.durationMs/2))return;const o=t?LENS_CAUSES[e.cause]:void 0;return o?`LensMCP's own work \u2014 ${o}`:"LensMCP's own work"}s(lensOwnWork,"lensOwnWork"),a(lensOwnWork,"lensOwnWork"),l(lensOwnWork,"lensOwnWork");export function waitedBehind(e){const t=new Set,o=new Set;for(const n of e.evidence)n.relation==="executing"||(n.requestId?n.requestId===e.requestId:!n.flowId||n.flowId===e.flowId)||(t.add(n.requestId??n.flowId),n.flowId&&n.flowId!==e.flowId&&o.add(n.flowId));return{requests:t.size,flows:o.size,atLeast:e.evidenceTruncated}}s(waitedBehind,"waitedBehind"),a(waitedBehind,"waitedBehind"),l(waitedBehind,"waitedBehind");export function waitedLine(e){const t=waitedBehind(e);return t.requests?`${t.atLeast?"at least ":""}${t.requests} request${t.requests===1?"":"s"} waited behind it`:void 0}s(waitedLine,"waitedLine"),a(waitedLine,"waitedLine"),l(waitedLine,"waitedLine");export function flowStalls(e,t){const o={ran:[],overlapped:[]};for(const n of e){if(lensOwnWork(n))continue;if(n.flowId===t){o.ran.push(n);continue}const u=n.endAt??n.observedAt,d=n.evidence.filter(r=>r.flowId===t).map(r=>[Math.max(r.startAt,n.startAt),Math.min(r.endAt,u)]).filter(([r,i])=>i>=r).sort((r,i)=>r[0]-i[0]);if(!d.length)continue;let p=0,c=-1/0;for(const[r,i]of d)i>c&&(p+=i-Math.max(r,c)),c=Math.max(c,i);o.overlapped.push({incident:n,overlapMs:Math.round(p*100)/100})}return o}s(flowStalls,"flowStalls"),a(flowStalls,"flowStalls"),l(flowStalls,"flowStalls");export function overlapLine(e){if(!e.length)return;const t=[...new Set(e.map(u=>u.incident.loop.project))],o=t.length<=2?t.join(" and "):`${t.length} services`,n=e.length;return{count:n,services:t,longestMs:Math.max(...e.map(u=>u.overlapMs)),text:`${n} pause${n===1?"":"s"} in ${o} while this flow was open \u2014 not this flow\u2019s code`}}s(overlapLine,"overlapLine"),a(overlapLine,"overlapLine"),l(overlapLine,"overlapLine");export const LOOP_STARTUP_MS=6e4;export function loopStartedAt(e){if(!e.startsWith("node:"))return;const t=Number(e.slice(e.lastIndexOf(":")+1));return Number.isFinite(t)&&t>0?t:void 0}s(loopStartedAt,"loopStartedAt"),a(loopStartedAt,"loopStartedAt"),l(loopStartedAt,"loopStartedAt");export function loopPhaseAt(e,t){const o=loopStartedAt(e);if(o===void 0)return;const n=Math.max(0,Math.round(t-o));return{phase:n<LOOP_STARTUP_MS?"startup":"running",sinceStartMs:n}}s(loopPhaseAt,"loopPhaseAt"),a(loopPhaseAt,"loopPhaseAt"),l(loopPhaseAt,"loopPhaseAt");
@@ -1 +1 @@
1
- "use strict";var S=Object.defineProperty;var i=(t,n)=>S(t,"name",{value:n,configurable:!0});var m=Object.defineProperty,u=i((t,n)=>m(t,"name",{value:n,configurable:!0}),"o");function d(){const t=typeof process<"u"?process.env?.LENSMCP_EVENT_MAX_EPS:void 0;if(t===void 0||t==="")return;if(t==="off")return"off";const n=Number(t);if(Number.isFinite(n))return n<=0?"off":n}i(d,"S"),u(d,"envPerSec");export function createEventFloodGuard(t){const n=t?.envOverride===!1?void 0:d();if(n==="off")return{admit:u(()=>({ok:!0,suppressed:0}),"admit")};const l=n??t?.perSec??5,f=Math.max(1,t?.burst??Math.max(30,l*4)),c=t?.maxKeys??2048,r=new Map,p=u(o=>{for(const[s,e]of r)o-e.lastSeenAt>6e4&&r.delete(s);if(r.size>c){const s=[...r.entries()].sort((e,a)=>e[1].lastSeenAt-a[1].lastSeenAt);for(let e=0;e<s.length>>1;e++)r.delete(s[e][0])}},"evictStale");return{admit(o){const s=Date.now();let e=r.get(o);e||(r.size>=c&&p(s),e={tokens:f,lastRefillAt:s,suppressed:0,lastSeenAt:s},r.set(o,e)),e.lastSeenAt=s;const a=s-e.lastRefillAt;if(a>0&&(e.tokens=Math.min(f,e.tokens+a/1e3*l),e.lastRefillAt=s),e.tokens>=1){e.tokens-=1;const v=e.suppressed;return e.suppressed=0,{ok:!0,suppressed:v}}return e.suppressed+=1,{ok:!1,suppressed:0}}}}i(createEventFloodGuard,"createEventFloodGuard"),u(createEventFloodGuard,"createEventFloodGuard");
1
+ "use strict";var S=Object.defineProperty;var i=(t,s)=>S(t,"name",{value:s,configurable:!0});var A=Object.defineProperty,f=i((t,s)=>A(t,"name",{value:s,configurable:!0}),"i"),k=Object.defineProperty,u=f((t,s)=>k(t,"name",{value:s,configurable:!0}),"o");function l(){const t=typeof process<"u"?process.env?.LENSMCP_EVENT_MAX_EPS:void 0;if(t===void 0||t==="")return;if(t==="off")return"off";const s=Number(t);if(Number.isFinite(s))return s<=0?"off":s}i(l,"d"),f(l,"S"),u(l,"envPerSec");export function createEventFloodGuard(t){const s=t?.envOverride===!1?void 0:l();if(s==="off")return{admit:u(()=>({ok:!0,suppressed:0}),"admit")};const c=s??t?.perSec??5,d=Math.max(1,t?.burst??Math.max(30,c*4)),p=t?.maxKeys??2048,n=new Map,v=u(o=>{for(const[r,e]of n)o-e.lastSeenAt>6e4&&n.delete(r);if(n.size>p){const r=[...n.entries()].sort((e,a)=>e[1].lastSeenAt-a[1].lastSeenAt);for(let e=0;e<r.length>>1;e++)n.delete(r[e][0])}},"evictStale");return{admit(o){const r=Date.now();let e=n.get(o);e||(n.size>=p&&v(r),e={tokens:d,lastRefillAt:r,suppressed:0,lastSeenAt:r},n.set(o,e)),e.lastSeenAt=r;const a=r-e.lastRefillAt;if(a>0&&(e.tokens=Math.min(d,e.tokens+a/1e3*c),e.lastRefillAt=r),e.tokens>=1){e.tokens-=1;const m=e.suppressed;return e.suppressed=0,{ok:!0,suppressed:m}}return e.suppressed+=1,{ok:!1,suppressed:0}}}}i(createEventFloodGuard,"createEventFloodGuard"),f(createEventFloodGuard,"createEventFloodGuard"),u(createEventFloodGuard,"createEventFloodGuard");