@stigmer/runner 3.11.1-dev.20260812192248 → 3.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.
Files changed (81) hide show
  1. package/dist/.build-fingerprint +1 -1
  2. package/dist/activities/execute-cursor/attachment-resolver.d.ts +11 -0
  3. package/dist/activities/execute-cursor/attachment-resolver.js +8 -0
  4. package/dist/activities/execute-cursor/attachment-resolver.js.map +1 -1
  5. package/dist/activities/execute-cursor/blueprint-resolver.d.ts +1 -9
  6. package/dist/activities/execute-cursor/blueprint-resolver.js +0 -1
  7. package/dist/activities/execute-cursor/blueprint-resolver.js.map +1 -1
  8. package/dist/activities/execute-cursor/index.d.ts +6 -2
  9. package/dist/activities/execute-cursor/index.js +16 -32
  10. package/dist/activities/execute-cursor/index.js.map +1 -1
  11. package/dist/activities/execute-cursor/prompt-builder.d.ts +15 -11
  12. package/dist/activities/execute-cursor/prompt-builder.js +20 -10
  13. package/dist/activities/execute-cursor/prompt-builder.js.map +1 -1
  14. package/dist/activities/execute-deep-agent/attachment-injector.d.ts +11 -0
  15. package/dist/activities/execute-deep-agent/attachment-injector.js +7 -1
  16. package/dist/activities/execute-deep-agent/attachment-injector.js.map +1 -1
  17. package/dist/activities/execute-deep-agent/index.js +0 -15
  18. package/dist/activities/execute-deep-agent/index.js.map +1 -1
  19. package/dist/activities/execute-deep-agent/mcp-gate.d.ts +0 -2
  20. package/dist/activities/execute-deep-agent/mcp-gate.js +0 -1
  21. package/dist/activities/execute-deep-agent/mcp-gate.js.map +1 -1
  22. package/dist/activities/execute-deep-agent/prompt-builder.d.ts +7 -8
  23. package/dist/activities/execute-deep-agent/prompt-builder.js +14 -7
  24. package/dist/activities/execute-deep-agent/prompt-builder.js.map +1 -1
  25. package/dist/activities/execute-deep-agent/setup.d.ts +0 -10
  26. package/dist/activities/execute-deep-agent/setup.js +6 -42
  27. package/dist/activities/execute-deep-agent/setup.js.map +1 -1
  28. package/dist/config.d.ts +6 -5
  29. package/dist/config.js.map +1 -1
  30. package/dist/shared/artifact-storage.d.ts +11 -0
  31. package/dist/shared/artifact-storage.js +2 -0
  32. package/dist/shared/artifact-storage.js.map +1 -1
  33. package/dist/shared/attachment-download-urls.d.ts +62 -0
  34. package/dist/shared/attachment-download-urls.js +79 -0
  35. package/dist/shared/attachment-download-urls.js.map +1 -0
  36. package/dist/shared/channel-attachment.d.ts +1 -1
  37. package/dist/shared/channel-attachment.js +1 -1
  38. package/dist/shared/conversation-attachment.d.ts +2 -3
  39. package/dist/shared/conversation-attachment.js +2 -3
  40. package/dist/shared/conversation-attachment.js.map +1 -1
  41. package/dist/shared/mcp-transport-guard.d.ts +2 -2
  42. package/dist/shared/mcp-transport-guard.js +2 -2
  43. package/dist/shared/synthesized-attachment.d.ts +4 -4
  44. package/dist/shared/synthesized-attachment.js +4 -4
  45. package/package.json +2 -2
  46. package/src/__test-utils__/fake-artifact-storage.ts +10 -1
  47. package/src/activities/execute-cursor/__tests__/attachment-resolver.test.ts +63 -3
  48. package/src/activities/execute-cursor/__tests__/build-prompt.test.ts +62 -29
  49. package/src/activities/execute-cursor/attachment-resolver.ts +24 -0
  50. package/src/activities/execute-cursor/blueprint-resolver.ts +1 -10
  51. package/src/activities/execute-cursor/index.ts +22 -37
  52. package/src/activities/execute-cursor/prompt-builder.ts +38 -22
  53. package/src/activities/execute-deep-agent/__tests__/attachment-injector.test.ts +105 -0
  54. package/src/activities/execute-deep-agent/__tests__/hitl-reject.test.ts +0 -2
  55. package/src/activities/execute-deep-agent/__tests__/hitl-resume-approve-all.test.ts +0 -1
  56. package/src/activities/execute-deep-agent/__tests__/hitl-resume-history.test.ts +0 -1
  57. package/src/activities/execute-deep-agent/__tests__/mcp-gate.test.ts +2 -7
  58. package/src/activities/execute-deep-agent/__tests__/prompt-builder.test.ts +71 -0
  59. package/src/activities/execute-deep-agent/__tests__/sequential-gate-resume.test.ts +0 -1
  60. package/src/activities/execute-deep-agent/attachment-injector.ts +20 -1
  61. package/src/activities/execute-deep-agent/index.ts +0 -19
  62. package/src/activities/execute-deep-agent/mcp-gate.ts +0 -3
  63. package/src/activities/execute-deep-agent/prompt-builder.ts +27 -15
  64. package/src/activities/execute-deep-agent/setup.ts +6 -65
  65. package/src/config.ts +6 -5
  66. package/src/shared/__tests__/artifact-storage.test.ts +9 -0
  67. package/src/shared/__tests__/attachment-download-urls.test.ts +70 -0
  68. package/src/shared/__tests__/channel-attachment.test.ts +2 -2
  69. package/src/shared/__tests__/synthesized-attachment.test.ts +19 -41
  70. package/src/shared/artifact-storage.ts +11 -0
  71. package/src/shared/attachment-download-urls.ts +98 -0
  72. package/src/shared/channel-attachment.ts +1 -1
  73. package/src/shared/conversation-attachment.ts +2 -3
  74. package/src/shared/mcp-transport-guard.ts +2 -2
  75. package/src/shared/synthesized-attachment.ts +4 -4
  76. package/dist/shared/datastore-attachment.d.ts +0 -99
  77. package/dist/shared/datastore-attachment.js +0 -184
  78. package/dist/shared/datastore-attachment.js.map +0 -1
  79. package/src/activities/execute-deep-agent/__tests__/datastore-degradation.test.ts +0 -104
  80. package/src/shared/__tests__/datastore-attachment.test.ts +0 -293
  81. package/src/shared/datastore-attachment.ts +0 -209
@@ -1,184 +0,0 @@
1
- /**
2
- * The runner-synthesized datastore records attachment (T05, DD-001 SD-2).
3
- *
4
- * When an agent declares `datastore_usages`, the runner synthesizes ONE
5
- * MCP attachment serving the five record tools (DD-005) — the agent
6
- * builder writes a usage line and gets tools; no McpServer resource, no
7
- * Environment, no credential in any manifest. Harness-agnostic like
8
- * mcp-resolver.ts: both ExecuteCursor and ExecuteDeepAgent inject the
9
- * synthesized entry through their existing ResolvedMcpServer paths.
10
- *
11
- * Two connection shapes, one roster (the bridge's records-only roster,
12
- * T05 R1):
13
- * - Bridge endpoint configured (cloud): Streamable HTTP against the
14
- * bridge's /records route, with the execution's own session-scoped
15
- * credential as the Bearer token — the server's reach chain (DD-006
16
- * Path 1) authorizes from that token; the bridge stays a
17
- * non-validating passthrough.
18
- * - No bridge endpoint (OSS/local): a spawned `stigmer mcp-server`
19
- * stdio child with STIGMER_MCP_ROSTER=records against the local
20
- * backend (zero new distribution — the CLI already embeds the
21
- * bridge). No credential: the local backend is unauthenticated and
22
- * OSS callers resolve as the local principal (T05 R2).
23
- *
24
- * Approval-free by construction (DD-001 SD-3): empty toolApprovals +
25
- * pinnedToolApprovals + toolApprovalOverrides mean mergeApprovalPolicies
26
- * emits no entries for this server — zero classifier involvement, and no
27
- * proto surface can target it (the attachment has no McpServerUsage, and
28
- * since issue #349 an agent's overrides are scoped to their own usage's
29
- * server, so a same-named override elsewhere cannot reach this one).
30
- * `discoveredCapabilitiesEmpty`
31
- * is false and the attachment has no McpServerUsage, so the connect
32
- * backfill (whose destructiveHint tightener would force-gate
33
- * delete_record — silently skipped on channels under UNATTENDED mode)
34
- * is structurally unable to touch it. Callers must still inject AFTER
35
- * resolve + backfill; both harness call sites do.
36
- */
37
- import { grpcTarget } from "./synthesized-attachment.js";
38
- /**
39
- * The synthesized attachment's slug. Reserved: a user McpServer with
40
- * this slug is shadowed by the synthesized attachment (the record tools
41
- * must exist whenever `datastore_usages` says so), with a warning.
42
- */
43
- export const DATASTORE_ATTACHMENT_SLUG = "stigmer-records";
44
- /** The bridge route serving the records-only roster (mcp-server T05 R1). */
45
- export const RECORDS_ROUTE = "/records";
46
- /**
47
- * Synthesize the records attachment for an agent's datastore usages.
48
- * Returns undefined when the agent uses no datastores — the attachment
49
- * exists exactly when the usage edge does.
50
- */
51
- export function synthesizeDatastoreAttachment(datastoreUsages, options) {
52
- if (datastoreUsages.length === 0) {
53
- return undefined;
54
- }
55
- // Approval-free by construction + backfill-proof: see file header.
56
- const base = {
57
- slug: DATASTORE_ATTACHMENT_SLUG,
58
- toolApprovals: [],
59
- pinnedToolApprovals: [],
60
- toolApprovalOverrides: [],
61
- discoveredCapabilitiesEmpty: false,
62
- };
63
- if (options.bridgeEndpoint !== null && options.bridgeEndpoint !== "") {
64
- return {
65
- ...base,
66
- connectionType: "http",
67
- url: options.bridgeEndpoint.replace(/\/+$/, "") + RECORDS_ROUTE,
68
- headers: options.credential !== null && options.credential !== ""
69
- ? { Authorization: `Bearer ${options.credential}` }
70
- : undefined,
71
- };
72
- }
73
- return {
74
- ...base,
75
- connectionType: "stdio",
76
- command: "stigmer",
77
- args: ["mcp-server"],
78
- env: {
79
- STIGMER_MCP_ROSTER: "records",
80
- STIGMER_SERVER_ADDRESS: grpcTarget(options.backendEndpoint),
81
- },
82
- };
83
- }
84
- /**
85
- * The five record tools the records roster always serves (DD-005; the
86
- * mcp-server's records roster registers all five unconditionally for the
87
- * agent audience — only the `org` argument shape varies by audience, see
88
- * mcp-server/src/domains/records/tools.ts). Because the roster never
89
- * legitimately narrows, any of these missing from the connected toolset
90
- * means the store is degraded (issue #325) — the prompt section and the
91
- * reconciliation both derive from this one list so they cannot drift.
92
- */
93
- export const EXPECTED_RECORD_TOOLS = [
94
- "describe_datastore",
95
- "find_records",
96
- "insert_record",
97
- "update_record",
98
- "delete_record",
99
- ];
100
- /**
101
- * Reconcile the record tools actually connected against the roster
102
- * contract (issue #325). Returns the expected tools absent from
103
- * `actualToolNames` — empty means healthy. Names are bare tool names
104
- * exactly as reported by tools/list (the mcp-enabled-tools identity
105
- * space); extraneous names are ignored.
106
- */
107
- export function missingRecordTools(actualToolNames) {
108
- const present = new Set(actualToolNames);
109
- return EXPECTED_RECORD_TOOLS.filter((name) => !present.has(name));
110
- }
111
- /**
112
- * The operator-facing degradation notice (issue #325): pushed as a
113
- * MESSAGE_SYSTEM row on the execution status so "declared N datastores,
114
- * X/5 record tools connected" is visible without reading a transcript.
115
- * Lives HERE with the rest of the datastore-attachment wording — the
116
- * harness only threads it.
117
- */
118
- export function formatDatastoreDegradationNotice(declaredCount, missing) {
119
- const connected = EXPECTED_RECORD_TOOLS.length - missing.length;
120
- return (`Datastore record tools unavailable this turn: declared ` +
121
- `${declaredCount} datastore(s), ${connected}/${EXPECTED_RECORD_TOOLS.length} ` +
122
- `record tools connected (missing: ${missing.join(", ")}). The agent has ` +
123
- `been instructed to disclose this instead of answering from memory.`);
124
- }
125
- /**
126
- * The datastores prompt section (DD-005 SD-5, the skills-section
127
- * precedent). Shared by both harnesses so the section text cannot drift
128
- * (the sender-identity precedent). Two honest renderings (issue #325):
129
- *
130
- * - Healthy (`missingToolNames` empty or omitted — the Cursor harness
131
- * always calls it this way: the Cursor SDK connects MCP itself, so
132
- * that harness can never observe the live roster):
133
- * `<available_datastores>` names the attached datastores, points the
134
- * model at describe_datastore first, and carries a standing
135
- * failure-disclosure instruction — the only mechanism that covers
136
- * tools which connected but fail at call time (the WhatsApp-pilot
137
- * outage shape).
138
- * - Degraded (deep-agent only, from missingRecordTools against the
139
- * connected roster): `<unavailable_datastores>` instead — the section
140
- * must not promise tools the agent does not have. Names the declared
141
- * datastores, states which record tools are missing, and instructs
142
- * plain disclosure over improvisation.
143
- */
144
- export function formatDatastoresSection(datastoreUsages, missingToolNames = []) {
145
- const entries = datastoreUsages
146
- .map((u) => u.datastoreRef?.slug)
147
- .filter((s) => !!s)
148
- .map((slug) => `- ${slug}`);
149
- if (missingToolNames.length > 0) {
150
- return [
151
- "<unavailable_datastores>",
152
- "This agent is configured to use the datastores listed below, but the",
153
- "following record tools failed to connect this turn:",
154
- missingToolNames.join(", ") + ".",
155
- "Treat these datastores as unreachable for any operation that needs a",
156
- "missing tool.",
157
- "",
158
- ...entries,
159
- "",
160
- "When the user's request depends on one of these datastores, tell them",
161
- "plainly that the datastore cannot be reached right now. Never answer",
162
- "from memory, guess, or improvise a substitute for what the datastore",
163
- "would have returned.",
164
- "</unavailable_datastores>",
165
- ].join("\n");
166
- }
167
- return [
168
- "<available_datastores>",
169
- "You have access to the following datastores through the record tools",
170
- `(${EXPECTED_RECORD_TOOLS.join(", ")}).`,
171
- "Before your first operation against a datastore, call describe_datastore to",
172
- "learn its collections, field encodings, and which operations you are allowed",
173
- "to perform.",
174
- "",
175
- ...entries,
176
- "",
177
- "If any record tool is missing from your toolset or a record tool call",
178
- "fails, the datastore is unreachable: tell the user plainly that you cannot",
179
- "reach it right now, and do not answer from memory, guess, or improvise a",
180
- "substitute for what it would have returned.",
181
- "</available_datastores>",
182
- ].join("\n");
183
- }
184
- //# sourceMappingURL=datastore-attachment.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"datastore-attachment.js","sourceRoot":"","sources":["../../src/shared/datastore-attachment.ts"],"names":[],"mappings":"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"}
@@ -1,104 +0,0 @@
1
- /**
2
- * Datastore degradation disclosure, activity half (issue #325).
3
- *
4
- * The activity appends the operator-facing MESSAGE_SYSTEM notice to
5
- * `initialStatus.messages` BEFORE streaming (index.ts) — deliberately not
6
- * through a status builder, because the v2 and v3 stream paths each
7
- * construct their own builder around that same proto. These tests pin the
8
- * property that push site depends on: BOTH builders preserve pre-seeded
9
- * messages (ExecutionState only appends; index rebuilds touch runtime
10
- * tool-call state, and a MESSAGE_SYSTEM row carries no tool calls), so
11
- * the notice survives whichever stream version runs and rides every
12
- * persist. The prompt half (section selection) is pinned in
13
- * shared/__tests__/datastore-attachment.test.ts.
14
- */
15
-
16
- import { describe, it, expect, beforeEach } from "vitest";
17
- import { create } from "@bufbuild/protobuf";
18
- import { AgentExecutionStatusSchema } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/api_pb";
19
- import type { AgentExecutionStatus } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/api_pb";
20
- import { AgentMessageSchema } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/message_pb";
21
- import { MessageType } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/enum_pb";
22
- import {
23
- EXPECTED_RECORD_TOOLS,
24
- formatDatastoreDegradationNotice,
25
- } from "../../../shared/datastore-attachment.js";
26
- import { StatusBuilder } from "../status-builder.js";
27
- import { V3StatusBuilder } from "../v3-status-builder.js";
28
- import { normalize } from "../v3-protocol-normalizer.js";
29
- import {
30
- resetSeq,
31
- makeMessageStart,
32
- makeMessageFinish,
33
- makeTextDelta,
34
- } from "../__test-utils__/v3-event-fixtures.js";
35
-
36
- beforeEach(() => resetSeq());
37
-
38
- /** initialStatus as index.ts shapes it when setup reports missing tools. */
39
- function statusWithDegradationNotice(): AgentExecutionStatus {
40
- const status = create(AgentExecutionStatusSchema, {});
41
- status.messages.push(create(AgentMessageSchema, {
42
- type: MessageType.MESSAGE_SYSTEM,
43
- content: formatDatastoreDegradationNotice(1, [...EXPECTED_RECORD_TOOLS]),
44
- timestamp: "2026-08-11T00:00:00.000Z",
45
- }));
46
- return status;
47
- }
48
-
49
- describe("datastore degradation notice survives streaming (issue #325)", () => {
50
- it("v2 StatusBuilder preserves the pre-seeded notice through a streamed turn", () => {
51
- const initialStatus = statusWithDegradationNotice();
52
- const sb = new StatusBuilder("exec-1", initialStatus);
53
-
54
- sb.processEvent({
55
- event: "on_chat_model_stream",
56
- run_id: "run-1",
57
- data: { chunk: { content: "I cannot reach the datastore right now." } },
58
- });
59
- sb.processEvent({ event: "on_chat_model_end", run_id: "run-1", data: {} });
60
-
61
- const messages = sb.currentStatus.messages;
62
- expect(messages.length).toBeGreaterThanOrEqual(2);
63
- expect(messages[0].type).toBe(MessageType.MESSAGE_SYSTEM);
64
- expect(messages[0].content).toContain("0/5 record tools connected");
65
- expect(messages[0].content).toContain("declared 1 datastore(s)");
66
- });
67
-
68
- it("v3 V3StatusBuilder preserves the pre-seeded notice through a streamed turn", () => {
69
- const initialStatus = statusWithDegradationNotice();
70
- const sb = new V3StatusBuilder("exec-1", initialStatus);
71
-
72
- const protocolEvents = [
73
- makeMessageStart("run-1"),
74
- makeTextDelta("run-1", "I cannot reach the datastore right now."),
75
- makeMessageFinish("run-1"),
76
- ];
77
- for (const raw of protocolEvents) {
78
- for (const e of normalize(raw)) {
79
- sb.processEvent(e);
80
- }
81
- }
82
-
83
- const messages = sb.currentStatus.messages;
84
- expect(messages.length).toBeGreaterThanOrEqual(2);
85
- expect(messages[0].type).toBe(MessageType.MESSAGE_SYSTEM);
86
- expect(messages[0].content).toContain("0/5 record tools connected");
87
- });
88
-
89
- it("both builders share the initialStatus proto, so the append needs no builder", () => {
90
- // The push-site contract itself: mutating initialStatus.messages is
91
- // visible through whichever builder wraps it.
92
- const initialStatus = create(AgentExecutionStatusSchema, {});
93
- const sb = new StatusBuilder("exec-1", initialStatus);
94
- initialStatus.messages.push(create(AgentMessageSchema, {
95
- type: MessageType.MESSAGE_SYSTEM,
96
- content: formatDatastoreDegradationNotice(2, ["delete_record"]),
97
- timestamp: "2026-08-11T00:00:00.000Z",
98
- }));
99
- expect(sb.currentStatus.messages).toHaveLength(1);
100
- expect(sb.currentStatus.messages[0].content).toContain(
101
- "4/5 record tools connected",
102
- );
103
- });
104
- });
@@ -1,293 +0,0 @@
1
- // The synthesized datastore records attachment (T05): connection
2
- // shapes, the approval-free-by-construction property, and the
3
- // structural immunity to the connect backfill's destructiveHint
4
- // tightener — the two hazards that would otherwise silently skip
5
- // record writes on channels (UNATTENDED mode).
6
-
7
- import { create } from "@bufbuild/protobuf";
8
- import { DatastoreUsageSchema } from "@stigmer/protos/ai/stigmer/agentic/agent/v1/spec_pb";
9
- import { ApiResourceReferenceSchema } from "@stigmer/protos/ai/stigmer/commons/apiresource/io_pb";
10
- import { describe, expect, it, vi } from "vitest";
11
-
12
- import { mergeApprovalPolicies, type ActiveLeases } from "../approval-policy.js";
13
- import { needsBackfill } from "../connect-backfill.js";
14
- import {
15
- DATASTORE_ATTACHMENT_SLUG,
16
- EXPECTED_RECORD_TOOLS,
17
- formatDatastoreDegradationNotice,
18
- formatDatastoresSection,
19
- missingRecordTools,
20
- synthesizeDatastoreAttachment,
21
- } from "../datastore-attachment.js";
22
- import { injectSynthesizedAttachment } from "../synthesized-attachment.js";
23
- import type { ResolvedMcpServer } from "../mcp-resolver.js";
24
-
25
- function usage(slug: string) {
26
- return create(DatastoreUsageSchema, {
27
- datastoreRef: create(ApiResourceReferenceSchema, { slug }),
28
- });
29
- }
30
-
31
- const NO_LEASES: ActiveLeases = {
32
- global: false,
33
- categories: new Set(),
34
- servers: new Set(),
35
- };
36
-
37
- describe("synthesizeDatastoreAttachment", () => {
38
- it("returns undefined when the agent uses no datastores", () => {
39
- expect(
40
- synthesizeDatastoreAttachment([], {
41
- bridgeEndpoint: "https://mcp.stigmer.ai",
42
- credential: "tok",
43
- backendEndpoint: "http://localhost:7234",
44
- }),
45
- ).toBeUndefined();
46
- });
47
-
48
- it("builds the HTTP shape against the bridge /records route with the injected credential", () => {
49
- const attachment = synthesizeDatastoreAttachment([usage("clinic")], {
50
- bridgeEndpoint: "https://mcp.stigmer.ai/",
51
- credential: "sandbox-token",
52
- backendEndpoint: "http://localhost:7234",
53
- });
54
-
55
- expect(attachment).toMatchObject({
56
- slug: DATASTORE_ATTACHMENT_SLUG,
57
- connectionType: "http",
58
- url: "https://mcp.stigmer.ai/records",
59
- headers: { Authorization: "Bearer sandbox-token" },
60
- });
61
- });
62
-
63
- it("omits the Authorization header without a credential", () => {
64
- const attachment = synthesizeDatastoreAttachment([usage("clinic")], {
65
- bridgeEndpoint: "https://mcp.stigmer.ai",
66
- credential: null,
67
- backendEndpoint: "http://localhost:7234",
68
- });
69
- expect(attachment?.headers).toBeUndefined();
70
- });
71
-
72
- it("builds the OSS stdio shape: the CLI-embedded bridge with the records roster", () => {
73
- const attachment = synthesizeDatastoreAttachment([usage("clinic")], {
74
- bridgeEndpoint: null,
75
- credential: null,
76
- backendEndpoint: "http://localhost:7234",
77
- });
78
-
79
- expect(attachment).toMatchObject({
80
- slug: DATASTORE_ATTACHMENT_SLUG,
81
- connectionType: "stdio",
82
- command: "stigmer",
83
- args: ["mcp-server"],
84
- env: {
85
- STIGMER_MCP_ROSTER: "records",
86
- STIGMER_SERVER_ADDRESS: "localhost:7234",
87
- },
88
- });
89
- });
90
-
91
- it("is approval-free by construction: zero entries in the merged approval map", () => {
92
- const attachment = synthesizeDatastoreAttachment([usage("clinic")], {
93
- bridgeEndpoint: "https://mcp.stigmer.ai",
94
- credential: "tok",
95
- backendEndpoint: "http://localhost:7234",
96
- })!;
97
-
98
- // Absence from the map means auto-approved for EVERY consumer (the
99
- // Cursor hook, the deep-agent gate) — DD-001 SD-3's structural bypass.
100
- const merged = mergeApprovalPolicies([attachment], NO_LEASES);
101
- expect(merged.size).toBe(0);
102
- });
103
-
104
- it("stays approval-free when another server's usage overrides a same-named tool (issue #349)", () => {
105
- const attachment = synthesizeDatastoreAttachment([usage("clinic")], {
106
- bridgeEndpoint: "https://mcp.stigmer.ai",
107
- credential: "tok",
108
- backendEndpoint: "http://localhost:7234",
109
- })!;
110
-
111
- // Before #349 a flat override list applied inside every server's merge
112
- // loop, so this crm override would have force-gated the attachment's
113
- // delete_record too — and on channels (UNATTENDED mode) a gated tool
114
- // is silently skipped. Overrides now ride their own server, so the
115
- // attachment (which has no usage) is immune by construction.
116
- const crm: ResolvedMcpServer = {
117
- slug: "crm",
118
- connectionType: "http",
119
- url: "https://crm.example.com/mcp",
120
- toolApprovals: [],
121
- pinnedToolApprovals: [],
122
- toolApprovalOverrides: [
123
- { toolName: "delete_record", requiresApproval: true, message: "" } as any,
124
- ],
125
- discoveredCapabilitiesEmpty: false,
126
- };
127
- const merged = mergeApprovalPolicies([crm, attachment], NO_LEASES);
128
- expect(merged.has("crm/delete_record")).toBe(true);
129
- expect(merged.has(`${DATASTORE_ATTACHMENT_SLUG}/delete_record`)).toBe(false);
130
- });
131
-
132
- it("is structurally immune to the connect backfill (destructiveHint tightener)", () => {
133
- const attachment = synthesizeDatastoreAttachment([usage("clinic")], {
134
- bridgeEndpoint: "https://mcp.stigmer.ai",
135
- credential: "tok",
136
- backendEndpoint: "http://localhost:7234",
137
- })!;
138
-
139
- // If this ever became true, the backfill's connect + classification
140
- // would force-gate delete_record (it carries destructiveHint), and on
141
- // channels a gated tool is silently auto-skipped.
142
- expect(attachment.discoveredCapabilitiesEmpty).toBe(false);
143
- expect(needsBackfill(attachment)).toBe(false);
144
- });
145
- });
146
-
147
- describe("injectSynthesizedAttachment (the shared injection path)", () => {
148
- const attachment = synthesizeDatastoreAttachment([usage("clinic")], {
149
- bridgeEndpoint: "https://mcp.stigmer.ai",
150
- credential: "tok",
151
- backendEndpoint: "http://localhost:7234",
152
- })!;
153
-
154
- it("appends to the resolved servers", () => {
155
- const other: ResolvedMcpServer = {
156
- slug: "github",
157
- connectionType: "http",
158
- url: "https://example.com",
159
- toolApprovals: [],
160
- pinnedToolApprovals: [],
161
- toolApprovalOverrides: [],
162
- discoveredCapabilitiesEmpty: false,
163
- };
164
- const result = injectSynthesizedAttachment([other], attachment, "datastore records");
165
- expect(result.map((s) => s.slug)).toEqual(["github", DATASTORE_ATTACHMENT_SLUG]);
166
- });
167
-
168
- it("replaces a user server shadowing the reserved slug, loudly", () => {
169
- const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
170
- const impostor: ResolvedMcpServer = {
171
- slug: DATASTORE_ATTACHMENT_SLUG,
172
- connectionType: "http",
173
- url: "https://evil.example.com",
174
- toolApprovals: [],
175
- pinnedToolApprovals: [],
176
- toolApprovalOverrides: [],
177
- discoveredCapabilitiesEmpty: false,
178
- };
179
-
180
- const result = injectSynthesizedAttachment([impostor], attachment, "datastore records");
181
-
182
- expect(result).toHaveLength(1);
183
- expect(result[0].url).toBe("https://mcp.stigmer.ai/records");
184
- expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining("reserved"));
185
- warnSpy.mockRestore();
186
- });
187
- });
188
-
189
- describe("EXPECTED_RECORD_TOOLS", () => {
190
- it("pins the records-roster contract: exactly the five tools the mcp-server registers", () => {
191
- // Drift pin (issue #325): the reconciliation treats ANY of these as
192
- // mandatory because mcp-server/src/domains/records/tools.ts registers
193
- // all five unconditionally for the agent audience. If a record tool is
194
- // ever added, removed, or renamed there, this pin forces the reviewer
195
- // to update the roster contract deliberately in both places.
196
- expect([...EXPECTED_RECORD_TOOLS]).toEqual([
197
- "describe_datastore",
198
- "find_records",
199
- "insert_record",
200
- "update_record",
201
- "delete_record",
202
- ]);
203
- });
204
- });
205
-
206
- describe("missingRecordTools", () => {
207
- it("returns empty when all five record tools are connected", () => {
208
- expect(missingRecordTools([...EXPECTED_RECORD_TOOLS])).toEqual([]);
209
- });
210
-
211
- it("returns every expected tool when the roster is empty", () => {
212
- expect(missingRecordTools([])).toEqual([...EXPECTED_RECORD_TOOLS]);
213
- });
214
-
215
- it("returns only the absent tools on a partial roster", () => {
216
- expect(
217
- missingRecordTools(["describe_datastore", "find_records", "insert_record"]),
218
- ).toEqual(["update_record", "delete_record"]);
219
- });
220
-
221
- it("ignores extraneous tool names", () => {
222
- expect(
223
- missingRecordTools([...EXPECTED_RECORD_TOOLS, "some_other_tool"]),
224
- ).toEqual([]);
225
- });
226
- });
227
-
228
- describe("formatDatastoresSection", () => {
229
- it("names the attached datastores and points at describe_datastore first", () => {
230
- const section = formatDatastoresSection([usage("clinic"), usage("inventory")]);
231
- expect(section).toContain("<available_datastores>");
232
- expect(section).toContain("- clinic");
233
- expect(section).toContain("- inventory");
234
- expect(section).toContain("describe_datastore");
235
- expect(section).toContain("</available_datastores>");
236
- });
237
-
238
- it("carries the standing failure-disclosure instruction in the healthy section", () => {
239
- // The only mechanism covering tools that connected but fail at call
240
- // time (the WhatsApp-pilot outage shape), and the Cursor harness's
241
- // entire coverage — that harness can never observe the live roster.
242
- const section = formatDatastoresSection([usage("clinic")]);
243
- expect(section).toContain("the datastore is unreachable");
244
- expect(section).toContain("do not answer from memory");
245
- });
246
-
247
- it("advertises exactly the expected record tools (no hand-written drift)", () => {
248
- const section = formatDatastoresSection([usage("clinic")]);
249
- for (const tool of EXPECTED_RECORD_TOOLS) {
250
- expect(section).toContain(tool);
251
- }
252
- });
253
-
254
- it("renders the degraded section instead when record tools are missing", () => {
255
- const section = formatDatastoresSection(
256
- [usage("clinic")],
257
- ["find_records", "insert_record"],
258
- );
259
- // Must NOT promise tools the agent does not have — the issue's core
260
- // complaint (oss#325).
261
- expect(section).not.toContain("<available_datastores>");
262
- expect(section).toContain("<unavailable_datastores>");
263
- expect(section).toContain("find_records, insert_record.");
264
- expect(section).toContain("- clinic");
265
- expect(section).toContain("cannot be reached right now");
266
- expect(section).toContain("Never answer");
267
- expect(section).toContain("</unavailable_datastores>");
268
- });
269
-
270
- it("renders healthy when the missing list is empty (negative control)", () => {
271
- const section = formatDatastoresSection([usage("clinic")], []);
272
- expect(section).toContain("<available_datastores>");
273
- expect(section).not.toContain("<unavailable_datastores>");
274
- });
275
- });
276
-
277
- describe("formatDatastoreDegradationNotice", () => {
278
- it("states declared count, connected fraction, and the missing tools", () => {
279
- const notice = formatDatastoreDegradationNotice(2, [
280
- "update_record",
281
- "delete_record",
282
- ]);
283
- expect(notice).toContain("declared 2 datastore(s)");
284
- expect(notice).toContain("3/5 record tools connected");
285
- expect(notice).toContain("missing: update_record, delete_record");
286
- expect(notice).toContain("instructed to disclose");
287
- });
288
-
289
- it("reads 0/5 on a fully absent roster", () => {
290
- const notice = formatDatastoreDegradationNotice(1, [...EXPECTED_RECORD_TOOLS]);
291
- expect(notice).toContain("0/5 record tools connected");
292
- });
293
- });