@descryy/mcp 0.1.2 → 0.2.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.
Files changed (94) hide show
  1. package/dist/bin/descry-mcp.js +24 -1
  2. package/dist/bin/descry-mcp.js.map +1 -1
  3. package/dist/disclosure-ledger.d.ts +38 -0
  4. package/dist/disclosure-ledger.d.ts.map +1 -0
  5. package/dist/disclosure-ledger.js +40 -0
  6. package/dist/disclosure-ledger.js.map +1 -0
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js.map +1 -1
  10. package/dist/protocol.d.ts +12 -3
  11. package/dist/protocol.d.ts.map +1 -1
  12. package/dist/protocol.js +12 -3
  13. package/dist/protocol.js.map +1 -1
  14. package/dist/render.d.ts +9 -0
  15. package/dist/render.d.ts.map +1 -1
  16. package/dist/render.js +17 -2
  17. package/dist/render.js.map +1 -1
  18. package/dist/runtime-registry.d.ts +63 -0
  19. package/dist/runtime-registry.d.ts.map +1 -0
  20. package/dist/runtime-registry.js +131 -0
  21. package/dist/runtime-registry.js.map +1 -0
  22. package/dist/server.d.ts.map +1 -1
  23. package/dist/server.js +5 -0
  24. package/dist/server.js.map +1 -1
  25. package/dist/session.d.ts +74 -2
  26. package/dist/session.d.ts.map +1 -1
  27. package/dist/session.js +177 -4
  28. package/dist/session.js.map +1 -1
  29. package/dist/tools/analyze.d.ts.map +1 -1
  30. package/dist/tools/analyze.js +30 -1
  31. package/dist/tools/analyze.js.map +1 -1
  32. package/dist/tools/cross-pr.d.ts.map +1 -1
  33. package/dist/tools/cross-pr.js +1 -0
  34. package/dist/tools/cross-pr.js.map +1 -1
  35. package/dist/tools/git-diff.d.ts.map +1 -1
  36. package/dist/tools/git-diff.js +24 -3
  37. package/dist/tools/git-diff.js.map +1 -1
  38. package/dist/tools/git-history.d.ts.map +1 -1
  39. package/dist/tools/git-history.js +1 -0
  40. package/dist/tools/git-history.js.map +1 -1
  41. package/dist/tools/history.js +1 -1
  42. package/dist/tools/history.js.map +1 -1
  43. package/dist/tools/impact.js +1 -1
  44. package/dist/tools/impact.js.map +1 -1
  45. package/dist/tools/index.d.ts +3 -1
  46. package/dist/tools/index.d.ts.map +1 -1
  47. package/dist/tools/index.js +4 -0
  48. package/dist/tools/index.js.map +1 -1
  49. package/dist/tools/kit.d.ts +1 -0
  50. package/dist/tools/kit.d.ts.map +1 -1
  51. package/dist/tools/kit.js +1 -0
  52. package/dist/tools/kit.js.map +1 -1
  53. package/dist/tools/link-workspace.d.ts.map +1 -1
  54. package/dist/tools/link-workspace.js +13 -1
  55. package/dist/tools/link-workspace.js.map +1 -1
  56. package/dist/tools/mark-incident.d.ts +69 -0
  57. package/dist/tools/mark-incident.d.ts.map +1 -0
  58. package/dist/tools/mark-incident.js +212 -0
  59. package/dist/tools/mark-incident.js.map +1 -0
  60. package/dist/tools/observe-runtime.d.ts +198 -0
  61. package/dist/tools/observe-runtime.d.ts.map +1 -0
  62. package/dist/tools/observe-runtime.js +951 -0
  63. package/dist/tools/observe-runtime.js.map +1 -0
  64. package/dist/tools/pr-analysis.d.ts +60 -13
  65. package/dist/tools/pr-analysis.d.ts.map +1 -1
  66. package/dist/tools/pr-analysis.js +54 -11
  67. package/dist/tools/pr-analysis.js.map +1 -1
  68. package/dist/tools/propagation.d.ts.map +1 -1
  69. package/dist/tools/propagation.js +1 -0
  70. package/dist/tools/propagation.js.map +1 -1
  71. package/dist/tools/questions.d.ts.map +1 -1
  72. package/dist/tools/questions.js +66 -4
  73. package/dist/tools/questions.js.map +1 -1
  74. package/dist/tools/refusal-fetch.d.ts.map +1 -1
  75. package/dist/tools/refusal-fetch.js +1 -0
  76. package/dist/tools/refusal-fetch.js.map +1 -1
  77. package/dist/tools/runtime-incident.d.ts +92 -0
  78. package/dist/tools/runtime-incident.d.ts.map +1 -0
  79. package/dist/tools/runtime-incident.js +144 -0
  80. package/dist/tools/runtime-incident.js.map +1 -0
  81. package/dist/tools/scope.d.ts.map +1 -1
  82. package/dist/tools/scope.js +1 -0
  83. package/dist/tools/scope.js.map +1 -1
  84. package/dist/tools/similar-incidents.d.ts +13 -0
  85. package/dist/tools/similar-incidents.d.ts.map +1 -1
  86. package/dist/tools/similar-incidents.js +22 -8
  87. package/dist/tools/similar-incidents.js.map +1 -1
  88. package/dist/tools/verification-status.d.ts.map +1 -1
  89. package/dist/tools/verification-status.js +1 -0
  90. package/dist/tools/verification-status.js.map +1 -1
  91. package/dist/tools/verify-claim.d.ts.map +1 -1
  92. package/dist/tools/verify-claim.js +5 -0
  93. package/dist/tools/verify-claim.js.map +1 -1
  94. package/package.json +15 -4
@@ -0,0 +1,212 @@
1
+ /**
2
+ * `mark_incident` — "that was a bug, and I just fixed it."
3
+ *
4
+ * The mechanism that lets an incident corpus grow during ordinary work, and the
5
+ * only one with precision 1.0 by construction: a person is asserting it.
6
+ *
7
+ * ## Why this exists
8
+ *
9
+ * `similar_incidents` is built, tested and correct, and starved. Until now one
10
+ * thing in the whole system minted an `INCIDENT` — a commit body carrying
11
+ * `This reverts commit <sha>` — which produced **zero** incidents across three
12
+ * measured repositories and two in a real product repository. Widening the
13
+ * automatic detection helps (`incidents.ts` now reads manual reverts and
14
+ * `Fixes #123` too), but every automatic mechanism can only read what somebody
15
+ * already wrote down. Most bugs are fixed forward with a commit message that
16
+ * says what the code now does, not what it used to do wrong.
17
+ *
18
+ * The heuristic that would close that gap was built and measured and refused:
19
+ * `bench/incident-fix-forward.mjs` scored **25%** against a 90% threshold
20
+ * declared before it ran. So the remaining route is to ask, once, cheaply, at
21
+ * the moment the developer already knows the answer.
22
+ *
23
+ * ## Where the record lives, and why not in the graph
24
+ *
25
+ * `.descry/config.json`, beside `confirmedFacts` — DEC-223's storage decision
26
+ * for exactly this class of data. A store is derived data (DEC-017) and every
27
+ * derived table is dropped on a schema bump; a fact a person asserted, which
28
+ * exists nowhere else, must not be. The graph holds a *projection*
29
+ * (`createConfirmedIncidentSource`), re-derived by every `analyze`, and this
30
+ * tool writes both so the incident is visible in the same conversation that
31
+ * recorded it rather than after the next rebuild.
32
+ *
33
+ * ## Reliability
34
+ *
35
+ * DEC-223's rule, unchanged: an edge resting on testimony is capped at class B
36
+ * however much structure surrounds it. One unaudited assertion is one unaudited
37
+ * assertion. This tool asserts a defect existed; it asserts nothing about why,
38
+ * and nothing here may promote it.
39
+ *
40
+ * ## Class
41
+ *
42
+ * `action` — DEC-278's test is *"can this call's effect change a later finding
43
+ * without the developer having said so"*, and an `INCIDENT_CORRELATED` edge
44
+ * biases diff-scoping traversal toward the files it names on every later run.
45
+ * Gated by the same two-call `confirmToken` handshake `questions` uses.
46
+ *
47
+ * See `DEC-NEXT-incident-minting-beyond-explicit-reverts`.
48
+ */
49
+ import { buildGraph, confirmedIncidentId, createConfirmedIncidentSource, nodesInFiles, persistGraph, } from "@descryy/core";
50
+ import { writeConfirmedIncident } from "../session.js";
51
+ import { answer, optionalString, optionalStringArray, requiredString, ToolInputError, } from "./kit.js";
52
+ const SCHEMA = {
53
+ type: "object",
54
+ properties: {
55
+ summary: {
56
+ type: "string",
57
+ description: "What broke, in your own words — one sentence. This becomes the incident's name and is " +
58
+ "matched against future failures, so describe the symptom rather than the fix " +
59
+ "(\"invoice totals doubled for multi-currency orders\", not \"corrected the rate lookup\").",
60
+ },
61
+ files: {
62
+ type: "array",
63
+ items: { type: "string" },
64
+ minItems: 1,
65
+ description: "Repo-relative paths the defect lived in. At least one. These are what make the incident " +
66
+ "findable later and what biases future blast radii toward this area, so name where the " +
67
+ "bug was, not every file the fix happened to touch.",
68
+ },
69
+ errorText: {
70
+ type: "string",
71
+ description: "The error or exception text as you saw it, if there was one. Optional, and worth giving: " +
72
+ "matching a future failure against real error text is what this corpus is for, and a " +
73
+ "commit subject line is a thin substitute.",
74
+ },
75
+ fixedAtCommit: {
76
+ type: "string",
77
+ description: "The commit that fixed it, if it is already committed. Optional — omit it rather than " +
78
+ "guessing, since recording a commit that did not fix this claims something you did not.",
79
+ },
80
+ confirmedBy: {
81
+ type: "string",
82
+ description: "Free text — who is asserting this. Defaults to \"user\".",
83
+ },
84
+ confirmToken: {
85
+ type: "string",
86
+ description: "The token returned by a previous call. Recording an incident takes two calls: the first " +
87
+ "returns a token and writes nothing, the second redeems it. A token is single-use, " +
88
+ "expires, and is only valid for this tool.",
89
+ },
90
+ },
91
+ required: ["summary", "files"],
92
+ additionalProperties: false,
93
+ };
94
+ async function run(args, ctx) {
95
+ const { session } = ctx;
96
+ const summary = requiredString(args, "summary");
97
+ const files = optionalStringArray(args, "files");
98
+ if (files === undefined || files.length === 0) {
99
+ throw new ToolInputError('"files" must name at least one repo-relative path — an incident naming no file has nothing ' +
100
+ "to attach it to, and would be invisible to every query that looks for one");
101
+ }
102
+ const errorText = optionalString(args, "errorText");
103
+ const fixedAtCommit = optionalString(args, "fixedAtCommit");
104
+ const confirmedBy = optionalString(args, "confirmedBy") ?? "user";
105
+ const root = await session.root();
106
+ const recorded = {
107
+ repo: session.config.repo,
108
+ summary,
109
+ files: [...new Set(files)].sort(),
110
+ ...(errorText === undefined ? {} : { errorText }),
111
+ ...(fixedAtCommit === undefined ? {} : { fixedAtCommit }),
112
+ confirmedBy,
113
+ confirmedAt: new Date().toISOString(),
114
+ };
115
+ const driver = session.store().driver;
116
+ // Measured **before** the projection runs. The projection mints a `FILE` node
117
+ // for every path the record names — the same thing the git source does for a
118
+ // reverted commit's files — so asking afterwards would always answer "all of
119
+ // them are in the graph" and the disclosure would be a tautology.
120
+ const { missing: filesNotInGraph } = nodesInFiles(driver, recorded.files);
121
+ ctx.progress(`Recording an incident in ${session.config.repo}`);
122
+ const written = await writeConfirmedIncident(session.repoPath, recorded);
123
+ // Projected into the store now, not at the next `analyze`, so the incident is
124
+ // visible in the conversation that recorded it — the same reason `questions`
125
+ // merges its just-written fact into the response it is about to return.
126
+ ctx.progress("Projecting it into the graph");
127
+ const batch = await createConfirmedIncidentSource({
128
+ repo: session.config.repo,
129
+ // Every record, not just this one: the projection is of the whole file, and
130
+ // a batch carrying only the newest would invalidate the rest of them.
131
+ incidents: [...(session.config.confirmedIncidents ?? []), recorded],
132
+ }).emit({ root });
133
+ const built = buildGraph([batch], { nodeExists: (id) => session.provider().node(id) !== undefined });
134
+ persistGraph(driver, [batch], built);
135
+ const stamp = session.provider().baseStamp();
136
+ const notes = [
137
+ "Recorded as testimony, not as a reading of the repository. An edge resting on it is capped at " +
138
+ "reliability class B (DEC-223) however much structure surrounds it — one unaudited assertion " +
139
+ "is one unaudited assertion.",
140
+ `The durable record is ${written.path}, which is a file you can read and correct. The graph ` +
141
+ "holds a projection of it, re-derived by every analyze, so a rebuild never loses it.",
142
+ ];
143
+ if (fixedAtCommit === undefined) {
144
+ notes.push("No fixing commit was named, so no FIX_PATTERN was minted and no FIXED_BY edge exists. " +
145
+ '"A defect existed" and "this commit fixed it" are separate claims and only the second ' +
146
+ "licenses that edge.");
147
+ }
148
+ if (filesNotInGraph.length > 0) {
149
+ notes.push(`${filesNotInGraph.length} of the named path(s) have no node in the graph ` +
150
+ `(${filesNotInGraph.slice(0, 5).join(", ")}). The incident is recorded and correlated to ` +
151
+ "them anyway — a developer naming a file Descry cannot read is a gap in Descry, not a " +
152
+ "mistake to discard. Run analyze if the graph predates them.");
153
+ }
154
+ return answer({
155
+ headline: `Recorded an incident in ${session.config.repo}, correlated to ${recorded.files.length} file(s). ` +
156
+ `${written.total} confirmed incident(s) now on record.`,
157
+ // A name-level fact: this defect existed and touched these paths. It makes
158
+ // no claim about program shape.
159
+ nameLevel: true,
160
+ // R0, and honestly so. Testimony is not a point on the R0-R4 ladder at all —
161
+ // that ladder measures how much tooling ran — so the honest floor is the
162
+ // bottom of it, with the real ceiling expressed by `humanAsserted` where a
163
+ // finding is actually classified.
164
+ resolutionFloor: 0,
165
+ commitSha: stamp.commitSha,
166
+ graphBuiltAt: stamp.graphBuiltAt,
167
+ irSchemaVersion: stamp.irSchemaVersion,
168
+ commitSpread: stamp.commitSpread,
169
+ notes,
170
+ data: {
171
+ recorded,
172
+ incidentNodeId: confirmedIncidentId({ repo: session.config.repo, ...(root.workspace === undefined ? {} : { workspace: root.workspace }) }, recorded),
173
+ configPath: written.path,
174
+ totalConfirmed: written.total,
175
+ filesNotInGraph,
176
+ },
177
+ });
178
+ }
179
+ /**
180
+ * Always returns a sentence: unlike `questions`, whose unconfirmed shape is a
181
+ * genuine read of the open-question queue, there is no argument to this tool
182
+ * that makes it not write.
183
+ */
184
+ function describeAction(args) {
185
+ const summary = args["summary"];
186
+ const files = args["files"];
187
+ if (typeof summary !== "string" || !Array.isArray(files) || files.length === 0)
188
+ return undefined;
189
+ return (`record a confirmed incident — "${summary}" — correlated to ${files.length} file(s) ` +
190
+ `(${files.slice(0, 3).join(", ")}${files.length > 3 ? ", …" : ""}). It is written to ` +
191
+ ".descry/config.json and projected into the graph, where it will bias future blast radii " +
192
+ "toward those files and can be matched against future failures. Capped at reliability class B.");
193
+ }
194
+ export const markIncidentTool = {
195
+ name: "mark_incident",
196
+ class: "action",
197
+ tier: "evidence",
198
+ version: "1.0.0",
199
+ title: "Record a bug you just fixed, so a future failure can match against it",
200
+ description: "Record that a defect existed in this repository and which files it lived in, so " +
201
+ "\"similar_incidents\" can match a future failure against it. This is the mechanism that lets " +
202
+ "an incident corpus grow during ordinary work: git history only yields an incident when " +
203
+ "somebody wrote a revert or a \"Fixes #123\", and most bugs are fixed forward with a message " +
204
+ "that says what the code now does rather than what it did wrong. Recorded as testimony — an " +
205
+ "edge resting on it is capped at reliability class B regardless of anything else about it " +
206
+ "(DEC-223). Takes a two-call confirmation: the first call performs nothing and returns a " +
207
+ "token; call again with \"confirmToken\" to actually record it.",
208
+ inputSchema: SCHEMA,
209
+ run,
210
+ describeAction,
211
+ };
212
+ //# sourceMappingURL=mark-incident.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mark-incident.js","sourceRoot":"","sources":["../../src/tools/mark-incident.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACjG,OAAO,CACL,kCAAkC,OAAO,qBAAqB,KAAK,CAAC,MAAM,WAAW;QACrF,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,sBAAsB;QACtF,0FAA0F;QAC1F,+FAA+F,CAChG,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAmB;IAC9C,IAAI,EAAE,eAAe;IACrB,KAAK,EAAE,QAAQ;IACf,IAAI,EAAE,UAAU;IAChB,OAAO,EAAE,OAAO;IAChB,KAAK,EAAE,uEAAuE;IAC9E,WAAW,EACT,kFAAkF;QAClF,+FAA+F;QAC/F,yFAAyF;QACzF,8FAA8F;QAC9F,6FAA6F;QAC7F,2FAA2F;QAC3F,0FAA0F;QAC1F,gEAAgE;IAClE,WAAW,EAAE,MAA4C;IACzD,GAAG;IACH,cAAc;CACf,CAAC"}
@@ -0,0 +1,198 @@
1
+ /**
2
+ * `observe_runtime` — boot or attach to a real application, watch it, and write
3
+ * what was witnessed into the graph as R4 facts.
4
+ *
5
+ * **The second tool that writes, and the first that writes something no
6
+ * re-index can reproduce.** `analyze` re-derives the graph from source already
7
+ * on disk, so nothing it writes is a new claim about the world. This one runs
8
+ * a real process and records what it saw happen, which is the one accuracy
9
+ * source architecture §11B.3 calls *"the core technical moat"* and the one a
10
+ * purely static tool is structurally unable to reach: *"a purely static
11
+ * code-graph tool is capped at R3 permanently. It has no runtime."*
12
+ *
13
+ * ## What this composes, and what it invents
14
+ *
15
+ * It invents no mechanism. Every stage already existed, gate-verified, in
16
+ * `descry-runtime`, and every one of them was dormant — the whole point of
17
+ * `DEC-NEXT-mcp-runtime-dependency-boundary-for-r4-evidence`, which measured
18
+ * that `applyRuntimeObservations` had **zero production callers anywhere**,
19
+ * not in `descry-desktop` and not in `descry-runtime`'s own pipeline. Four
20
+ * shipped components in a row, and this tool is the wire between them:
21
+ *
22
+ * 1. `runInstrumentedExecution` (`@descryy/runtime-orchestrator`) spawns or
23
+ * attaches the declared services, starts the adapter's collectors, drains
24
+ * them for a stated window, and writes every item through `EvidenceStore`.
25
+ * 2. `correlateExecution` (`@descryy/runtime-evidence-correlation`) resolves
26
+ * each evidence item to the graph node it is *about* — the resolve-then-
27
+ * attribute pass. This answers identity, not edges.
28
+ * 3. `confirmObservedFrontendCaller` (`@descryy/runtime-graph-correlator`)
29
+ * turns a captured call-site stack plus a resolved endpoint into a
30
+ * `RuntimeEdgeObservation`, and
31
+ * 4. calls `applyRuntimeObservations` (`@descryy/core`) with it, which
32
+ * promotes, mints or contradicts the edge and writes the EARNED ledger.
33
+ *
34
+ * ## Why stage 3 exists rather than deriving edges from stage 2 directly
35
+ *
36
+ * `uat-phase-1-bug-fixes.md` Phase 2 describes step 2 as producing
37
+ * `RuntimeEdgeObservation[]`. It does not, and the difference is load-bearing
38
+ * rather than pedantic: `correlateExecution` returns
39
+ * `CorrelationAttribution`s — *(evidenceId, graphNodeId)* pairs saying which
40
+ * single node an observation is about. An edge needs **two** endpoints and a
41
+ * witnessed relationship between them, and manufacturing one by pairing up
42
+ * attributions that happen to co-occur in the same run would mint edges from
43
+ * temporal coincidence. That is precisely the wrong-direction failure rule 2
44
+ * exists to prevent, arriving through the one mechanism built to make the
45
+ * graph *more* trustworthy.
46
+ *
47
+ * So the observation comes from the one shipped producer that can honestly
48
+ * make one: a captured stack naming the caller, against an endpoint the same
49
+ * observation named. Both endpoints come from the observation itself. Every
50
+ * other correlated item is reported in the counts and produces no edge, which
51
+ * is a disclosed gap rather than a silent one.
52
+ *
53
+ * ## What this closure can actually witness today — measured, not assumed
54
+ *
55
+ * The wire is complete and the arrow it carries is narrow, and the second half
56
+ * of that sentence is worth stating plainly because a reader would otherwise
57
+ * infer it from a zero. HTTP evidence carrying a call-site stack is emitted by
58
+ * exactly one collector in `descry-runtime`: the browser network collector,
59
+ * via its `fetch()` initiator capture. Checked across every collector in this
60
+ * server's dependency closure — `InboundProxy` emits `{method, path, status}`
61
+ * and no stack; `ExternalRequestCollector` sets `stackTrace: null` outright,
62
+ * because it parses a log line the application printed and a printed line
63
+ * carries no stack; `LogCollector` (the only thing the TypeScript runtime
64
+ * adapter builds) attaches a stack to log and error lines, which resolve a
65
+ * FUNCTION and name no endpoint.
66
+ *
67
+ * So a backend-only run resolves both kinds of node and writes no edge. The
68
+ * composition is right, the gate is real, and the arrow is currently reachable
69
+ * only from a browser-driven run — which `runInstrumentedExecution`'s own
70
+ * contract explicitly does not do ("does not drive a browser"), and which is
71
+ * therefore a different orchestration rather than a missing argument here.
72
+ * `STANDING_NOTES` says this on every call, whatever the counts come back as,
73
+ * because "no edge was written" and "nothing here could have written one" are
74
+ * different statements and only the second one is a fact about Descry.
75
+ *
76
+ * ## Why no denial is ever emitted
77
+ *
78
+ * `applyRuntimeObservations` accepts `held: false`. Nothing here ever sends
79
+ * one, and `confirmObservedFrontendCaller`'s own header explains why: a run
80
+ * establishes that a call *happened*; it cannot establish that one did not,
81
+ * because a run exercises the paths it happens to take. Demoting a correct
82
+ * edge on the strength of a route this run did not visit would be worse than
83
+ * never running.
84
+ *
85
+ * ## Class and tier
86
+ *
87
+ * `action` — DEC-278's own test is *"can this call's effect change a later
88
+ * finding without the developer having said so"*, and this one spawns
89
+ * processes and writes R4 edges that cap every later reliability class
90
+ * differently. It is gated by the same two-call `confirmToken` handshake
91
+ * `questions` uses, and additionally by the environment profile's declared
92
+ * `safetyLevel` (DEC-270): booting a service is a **write** against the
93
+ * target, so a `readOnly` profile refuses. An all-attach run is genuinely
94
+ * read-only — `ServiceConfiguration.attach`'s own contract is that Descry
95
+ * never executes code in, or applies limits to, a process it did not spawn —
96
+ * so it is allowed under `readOnly`, and that distinction is stated in the
97
+ * disclosures rather than inferred silently.
98
+ *
99
+ * `evidence` — it reports what was witnessed and what was written. It draws no
100
+ * conclusion about the user's code; nothing here reads or writes a finding, a
101
+ * hypothesis or a category (RT-027).
102
+ *
103
+ * ## No new query tools
104
+ *
105
+ * None are needed and none are added. `impact`, `propagation` and the rest
106
+ * already read the `resolution` field, so an edge this tool promotes to R4
107
+ * becomes visible through every one of them on the next call, with no change
108
+ * to any of them.
109
+ */
110
+ import { type ToolDefinition } from "./kit.ts";
111
+ /** Where evidence lands when the call does not say. Beside the graph, not inside it. */
112
+ export declare const DEFAULT_EVIDENCE_RELATIVE_PATH: string;
113
+ /**
114
+ * What one declared service did, reported from the one source that survives the
115
+ * call: `Execution.processes`.
116
+ *
117
+ * **Deliberately not the controller's `ServiceStartResult`**, which carries a
118
+ * per-service `stage`/`readiness.reason` and would be the better answer.
119
+ * `runInstrumentedExecution` does not return it — `serviceStartResults` is a
120
+ * property of `ExecutionController`, which that function creates, uses and
121
+ * drops, so it is genuinely unavailable to a caller rather than merely
122
+ * unplumbed here. What is knowable is reported and nothing is invented to fill
123
+ * the gap: a service with no `ProcessHandle` did not start, and the
124
+ * execution-level `executionState` (`FAILED_START` in particular) is what says
125
+ * a readiness check is why.
126
+ *
127
+ * A `null` `exitCode` with a `null` `signal` on a process that has not exited
128
+ * is the healthy case, not a missing value — POSIX only sets an exit code on a
129
+ * normal `exit()`, so `signal` is what distinguishes a crash from a clean exit.
130
+ */
131
+ export interface ObservedService {
132
+ readonly service: string;
133
+ /** False when no process handle exists for it at all — it never started. */
134
+ readonly started: boolean;
135
+ /** True when this service was attached to rather than spawned. Governs the safety gate — see the header. */
136
+ readonly attached: boolean;
137
+ /** The port it actually bound, when it listens on one. Null for a non-network process or before the port is known. */
138
+ readonly port: number | null;
139
+ /** Null while still running. Set once it exited and was reaped. */
140
+ readonly exitedAt: string | null;
141
+ readonly exitCode: number | null;
142
+ /** Non-null means killed by this signal, whatever `exitCode` says. */
143
+ readonly signal: string | null;
144
+ }
145
+ /**
146
+ * What the correlation pass resolved, by family. Counts rather than rows: a
147
+ * long run produces thousands of evidence items and this reply is read by an
148
+ * agent, not archived. The rows themselves are in the evidence store, keyed by
149
+ * `executionId`, which is returned so they can be found.
150
+ */
151
+ export interface CorrelationSummary {
152
+ readonly considered: number;
153
+ readonly skipped: number;
154
+ readonly attributed: number;
155
+ readonly refused: number;
156
+ /** Service names carrying symbol evidence no scope named a repository for. Named, never guessed at. */
157
+ readonly unscopedServices: readonly string[];
158
+ /** Non-empty means the correlation machinery itself broke, not that it looked and found nothing. */
159
+ readonly harnessErrors: readonly string[];
160
+ }
161
+ /**
162
+ * The R4 write, reported in `applyRuntimeObservations`'s own six-way
163
+ * vocabulary so a reader can account for every observation without inspecting
164
+ * the store.
165
+ */
166
+ export interface RuntimeWriteSummary {
167
+ /** Edges the graph already held below R4, now witnessed and raised to R4. */
168
+ readonly promoted: readonly string[];
169
+ /** Edges no static producer found, minted at R4 — §11B.3's "recall gap closed". */
170
+ readonly created: readonly string[];
171
+ /** Already at R4 and observed again. Reported, never silently dropped. */
172
+ readonly confirmed: readonly string[];
173
+ /** Observations the graph declined to act on, with the resolver's own reason. */
174
+ readonly refused: readonly string[];
175
+ /**
176
+ * Always empty today, and present so that stays visible rather than
177
+ * unstated. This tool emits no denial — see the header.
178
+ */
179
+ readonly contradictions: readonly string[];
180
+ /** A denial aimed at an edge already at R4. Out of scope by construction; reported, not laundered. */
181
+ readonly staleR4: readonly string[];
182
+ }
183
+ export interface ObserveRuntimeData {
184
+ /** Null when the run never started — see `services` and the disclosures for why. */
185
+ readonly executionId: string | null;
186
+ /** The controller's own terminal state for this execution. */
187
+ readonly executionState: string | null;
188
+ /** `RuntimeAdapter.language`, passed through verbatim. Nothing here branches on it (rule 1). */
189
+ readonly adapterLanguage: string | null;
190
+ readonly evidencePath: string;
191
+ readonly services: readonly ObservedService[];
192
+ /** Every evidence item this run wrote, by `eventType`. */
193
+ readonly evidenceByType: Readonly<Record<string, number>>;
194
+ readonly correlation: CorrelationSummary | null;
195
+ readonly wrote: RuntimeWriteSummary;
196
+ }
197
+ export declare const observeRuntimeTool: ToolDefinition;
198
+ //# sourceMappingURL=observe-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observe-runtime.d.ts","sourceRoot":"","sources":["../../src/tools/observe-runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4GG;AA4BH,OAAO,EAML,KAAK,cAAc,EACpB,MAAM,UAAU,CAAC;AAmBlB,wFAAwF;AACxF,eAAO,MAAM,8BAA8B,QAAiC,CAAC;AAO7E;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,4EAA4E;IAC5E,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,4GAA4G;IAC5G,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,sHAAsH;IACtH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,mEAAmE;IACnE,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,sEAAsE;IACtE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,uGAAuG;IACvG,QAAQ,CA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