@junghanacs/entwurf 0.12.9 → 0.13.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 (100) hide show
  1. package/AGENTS.md +135 -248
  2. package/BASELINE.md +46 -7
  3. package/CHANGELOG.md +35 -0
  4. package/CONTRIBUTING.md +4 -2
  5. package/DELIVERY.md +5 -4
  6. package/README.md +46 -18
  7. package/VERIFY.md +10 -6
  8. package/demo/demo.sh +7 -1
  9. package/docs/setup-clean-host.md +10 -4
  10. package/mcp/entwurf-bridge/dist/mcp/entwurf-bridge/src/index.js +159 -66
  11. package/mcp/entwurf-bridge/dist/pi-extensions/lib/acp/backend-adapter.js +148 -5
  12. package/mcp/entwurf-bridge/dist/pi-extensions/lib/acp/config.js +16 -4
  13. package/mcp/entwurf-bridge/dist/pi-extensions/lib/acp/models.js +66 -7
  14. package/mcp/entwurf-bridge/dist/pi-extensions/lib/acp/overlay.js +190 -3
  15. package/mcp/entwurf-bridge/dist/pi-extensions/lib/acp/tool-surface.js +12 -4
  16. package/mcp/entwurf-bridge/dist/pi-extensions/lib/entwurf-core.js +26 -9
  17. package/mcp/entwurf-bridge/dist/pi-extensions/lib/entwurf-deliverability.js +10 -6
  18. package/mcp/entwurf-bridge/dist/pi-extensions/lib/entwurf-fact-provider.js +15 -17
  19. package/mcp/entwurf-bridge/dist/pi-extensions/lib/entwurf-facts.js +13 -13
  20. package/mcp/entwurf-bridge/dist/pi-extensions/lib/entwurf-resume-args.js +31 -41
  21. package/mcp/entwurf-bridge/dist/pi-extensions/lib/entwurf-self-address.js +8 -9
  22. package/mcp/entwurf-bridge/dist/pi-extensions/lib/entwurf-v2-contract.js +32 -25
  23. package/mcp/entwurf-bridge/dist/pi-extensions/lib/entwurf-v2-decider.js +4 -4
  24. package/mcp/entwurf-bridge/dist/pi-extensions/lib/entwurf-v2-lock.js +5 -4
  25. package/mcp/entwurf-bridge/dist/pi-extensions/lib/entwurf-v2-production.js +9 -11
  26. package/mcp/entwurf-bridge/dist/pi-extensions/lib/entwurf-v2-spawn-production.js +3 -1
  27. package/mcp/entwurf-bridge/dist/pi-extensions/lib/meta-session.js +17 -20
  28. package/mcp/entwurf-bridge/src/index.ts +190 -82
  29. package/package.json +7 -3
  30. package/pi/settings.reference.json +1 -1
  31. package/pi-extensions/acp-provider.ts +20 -10
  32. package/pi-extensions/entwurf-control.ts +69 -27
  33. package/pi-extensions/lib/acp/augment.ts +60 -2
  34. package/pi-extensions/lib/acp/backend-adapter.ts +183 -8
  35. package/pi-extensions/lib/acp/backend.ts +5 -1
  36. package/pi-extensions/lib/acp/config.ts +19 -5
  37. package/pi-extensions/lib/acp/engraving.ts +3 -1
  38. package/pi-extensions/lib/acp/event-mapper.ts +10 -3
  39. package/pi-extensions/lib/acp/models.ts +69 -7
  40. package/pi-extensions/lib/acp/overlay.ts +234 -3
  41. package/pi-extensions/lib/acp/tool-surface.ts +12 -4
  42. package/pi-extensions/lib/entwurf-core.ts +26 -9
  43. package/pi-extensions/lib/entwurf-deliverability.ts +10 -6
  44. package/pi-extensions/lib/entwurf-fact-provider.ts +15 -17
  45. package/pi-extensions/lib/entwurf-facts.ts +13 -13
  46. package/pi-extensions/lib/entwurf-resume-args.ts +40 -46
  47. package/pi-extensions/lib/entwurf-self-address.ts +8 -9
  48. package/pi-extensions/lib/entwurf-v2-contract-schema.ts +7 -2
  49. package/pi-extensions/lib/entwurf-v2-contract.ts +32 -25
  50. package/pi-extensions/lib/entwurf-v2-decider.ts +8 -8
  51. package/pi-extensions/lib/entwurf-v2-lock.ts +5 -4
  52. package/pi-extensions/lib/entwurf-v2-production.ts +14 -11
  53. package/pi-extensions/lib/entwurf-v2-spawn-production.ts +3 -1
  54. package/pi-extensions/lib/meta-session.ts +17 -20
  55. package/run.sh +200 -62
  56. package/scripts/agy-bridge-config.py +249 -49
  57. package/scripts/agy-bridge.sh +59 -14
  58. package/scripts/check-acp-carrier-augment.ts +34 -2
  59. package/scripts/check-acp-cortex.ts +668 -0
  60. package/scripts/check-acp-provider-surface.ts +50 -6
  61. package/scripts/check-acp-sdk-surface.ts +22 -11
  62. package/scripts/check-acp-session-reuse.ts +64 -1
  63. package/scripts/check-agy-permission-matrix.py +655 -0
  64. package/scripts/check-entwurf-deliverability.ts +9 -6
  65. package/scripts/check-entwurf-fact-provider.ts +7 -7
  66. package/scripts/check-entwurf-facts.ts +12 -12
  67. package/scripts/check-entwurf-resume-args.ts +22 -60
  68. package/scripts/check-entwurf-self-address.ts +187 -4
  69. package/scripts/check-entwurf-v2-contract.ts +2 -2
  70. package/scripts/check-entwurf-v2-production.ts +5 -5
  71. package/scripts/check-entwurf-v2-spawn-production.ts +6 -2
  72. package/scripts/check-entwurf-v2-surface.ts +327 -14
  73. package/scripts/check-gate-qualification.ts +787 -0
  74. package/scripts/check-meta-identity-consumers.ts +1 -1
  75. package/scripts/check-probe-cli-shim.ts +879 -0
  76. package/scripts/check-probe-ordering.ts +2450 -0
  77. package/scripts/check-shell-quote.ts +5 -4
  78. package/scripts/fixtures/probe-cli-shim +20 -0
  79. package/scripts/fixtures/probe-mcp-server.ts +168 -12
  80. package/scripts/lib/mutation-qualify.ts +794 -0
  81. package/scripts/lib/probe-acp-turn.ts +207 -0
  82. package/scripts/lib/probe-cli-shim.ts +464 -0
  83. package/scripts/lib/probe-cli-target.ts +165 -0
  84. package/scripts/lib/probe-event-log.ts +383 -0
  85. package/scripts/lib/probe-verdict.ts +1213 -0
  86. package/scripts/mutants/acp-augment.json +30 -0
  87. package/scripts/mutants/acp-cortex.json +196 -0
  88. package/scripts/mutants/agy-permission.json +144 -0
  89. package/scripts/mutants/meta-identity.json +17 -0
  90. package/scripts/mutants/probe-ordering.json +1032 -0
  91. package/scripts/mutants/self-address.json +59 -0
  92. package/scripts/mutants/v2-surface.json +87 -0
  93. package/scripts/smoke-acp-cortex-live.ts +392 -0
  94. package/scripts/smoke-acp-ordering-probe-live.ts +848 -0
  95. package/scripts/smoke-acp-raw-turn-live.ts +1 -1
  96. package/scripts/smoke-acp-v2-send-live.ts +33 -18
  97. package/scripts/smoke-agy-install-state.sh +205 -20
  98. package/scripts/smoke-entwurf-v2-matrix-live.ts +3 -2
  99. package/pi-extensions/lib/entwurf-mailbox-guard.ts +0 -100
  100. package/scripts/check-entwurf-mailbox-guard.ts +0 -266
@@ -5,8 +5,10 @@
5
5
  * SSH command strings with `JSON.stringify`, which is NOT a shell-safe escape.
6
6
  * Backticks and `$(...)` inside a user prompt got executed by the remote shell
7
7
  * before pi ever saw them. The fix introduced `shellQuote()` (POSIX `'...'`
8
- * with `'\''` escape) in two places:
9
- * - pi-extensions/lib/entwurf-core.ts (legacy sync spawn/resume helper while v2 extraction is in progress)
8
+ * with `'\''` escape) in:
9
+ * - pi-extensions/lib/entwurf-core.ts (the one remaining core site; the entwurf.ts /
10
+ * entwurf-async.ts siblings this once cross-checked were removed in 0.12)
11
+ * - pi-extensions/lib/acp/backend-adapter.ts (cortex CORTEX_ACP_COMMAND override arg quoting)
10
12
  *
11
13
  * This script enforces two invariants:
12
14
  * 1. `shellQuote()` source matches the reference implementation byte-for-byte.
@@ -14,7 +16,6 @@
14
16
  * payload classes that caused the original incident — backtick command
15
17
  * substitution, `$(...)` command substitution, `$VAR` expansion, embedded
16
18
  * single quotes, whitespace, empty string, non-ASCII text.
17
- *
18
19
  * No process spawn, no SSH, no API. Pure-string verification — safe in `pnpm
19
20
  * check` chain.
20
21
  */
@@ -37,7 +38,7 @@ const REFERENCE_BODY = `function shellQuote(value: string): string {
37
38
  \treturn \`'\${value.replace(/'/g, \`'\\\\''\`)}\`;
38
39
  }`;
39
40
 
40
- const SOURCE_SITES = ["pi-extensions/lib/entwurf-core.ts"] as const;
41
+ const SOURCE_SITES = ["pi-extensions/lib/entwurf-core.ts", "pi-extensions/lib/acp/backend-adapter.ts"] as const;
41
42
 
42
43
  // Match the function block from `function shellQuote` up to the closing brace.
43
44
  // Tab indentation is required (matches the rest of the repo).
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+ // §11-7-c B-name-snapshot producer — the launcher the SDK actually execs.
3
+ //
4
+ // EXTENSIONLESS ON PURPOSE, and that is a contract, not a style choice. The SDK
5
+ // picks its launch branch off a pure suffix test: a path ending in one of
6
+ // SDK_SCRIPT_SUFFIXES (.js/.mjs/.tsx/.ts/.jsx) is run as `node|bun <path>`, and
7
+ // anything else is spawned DIRECTLY. The probe asserts the native branch instead
8
+ // of reproducing the interpreter choice (probe-cli-target.ts), so the instrument
9
+ // itself has to sit on that branch too — hence no extension, a shebang, and the
10
+ // executable bit tracked in git. Renaming this file to *.js would silently move
11
+ // the shim onto the other launch branch.
12
+ //
13
+ // It stays two lines because an extensionless file is outside `tsc --noEmit` and
14
+ // outside biome: every behaviour worth typechecking, linting and mutating lives
15
+ // in ../lib/probe-cli-shim.ts, which check-probe-cli-shim drives as a real
16
+ // process. Node >=24 (package.json engines) with "type": "module" resolves this
17
+ // file as ESM and strips types from the imported .ts SSOT.
18
+ import { runProbeCliShim } from "../lib/probe-cli-shim.ts";
19
+
20
+ runProbeCliShim();
@@ -1,4 +1,5 @@
1
- // Tiny stdio MCP server used ONLY by smoke-acp-mcp-live (S2g LIVE 1).
1
+ // Tiny stdio MCP server used by smoke-acp-mcp-live (S2g LIVE 1) and by the
2
+ // §11-7 ordering probe (smoke-acp-ordering-probe-live).
2
3
  //
3
4
  // It exposes ONE tool — `probe_nonce` — that returns a per-run secret nonce
4
5
  // supplied via the PROBE_NONCE env var. The smoke registers this server in a
@@ -9,25 +10,180 @@
9
10
  // is broken (the pre-S2g hardcoded `mcpServers:[]`), the tool never exists and
10
11
  // the nonce cannot appear.
11
12
  //
13
+ // §11-7 ordering-probe mode — active ONLY when PROBE_MCP_EVENT_LOG is set
14
+ // (smoke-acp-mcp-live never sets it, so its behavior is unchanged):
15
+ // - PROBE_MCP_STARTUP_DELAY_MS delays the transport connect — the controlled
16
+ // input the probe injects instead of trying to observe a window that has no
17
+ // observable signal on this server's ACP surface;
18
+ // - the tool takes a REQUIRED `probeRunId` argument, the cross-layer join key
19
+ // (§11-7: the ACP toolCallId and the MCP JSON-RPC id share no namespace, so
20
+ // correlation must ride an argument we control);
21
+ // - every wire step appends to the shared NDJSON event log, including THE
22
+ // wire-availability marker `tools_list_response_forwarded`, emitted only
23
+ // after the ENTIRE tools/list response frame was write()-n to downstream
24
+ // stdio AND the write callback fired. The SDK's own send() resolves on
25
+ // buffered-write/drain — NOT the write callback — which is exactly the
26
+ // false-green §11-7 forbids, so probe mode swaps in a callback-forwarding
27
+ // transport instead of trusting send().
28
+ //
12
29
  // Lives under the repo's scripts/fixtures/ so its `@modelcontextprotocol/sdk`
13
30
  // import resolves against the repo node_modules even though the server is spawned
14
31
  // (by the claude ACP child) with an arbitrary scratch cwd. Deliberately minimal:
15
- // no identity / env coupling beyond PROBE_NONCE, so a failure isolates to "did
16
- // the operator mcpServers reach newSession" — not to entwurf-bridge wiring.
32
+ // no identity / env coupling beyond the PROBE_* vars, so a failure isolates to
33
+ // "did the operator mcpServers reach newSession" — not to entwurf-bridge wiring.
17
34
 
18
35
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
19
36
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
37
+ import { serializeMessage } from "@modelcontextprotocol/sdk/shared/stdio.js";
38
+ import { z } from "zod";
39
+ import {
40
+ appendProbeEvent,
41
+ PROBE_EXPECTED_TOOL as EXPECTED_TOOL,
42
+ PROBE_ENV,
43
+ PROBE_EVENTS,
44
+ type ProbeEventName,
45
+ } from "../lib/probe-event-log.ts";
46
+
47
+ const eventLog = process.env[PROBE_ENV.eventLog];
48
+ const probeMode = typeof eventLog === "string" && eventLog.length > 0;
49
+ const runId = process.env[PROBE_ENV.runId] ?? "unknown-run";
50
+ const startupDelayMs = Math.max(0, Number(process.env[PROBE_ENV.startupDelayMs] ?? "0") || 0);
51
+
52
+ function emit(event: ProbeEventName, payload: Record<string, unknown> = {}): void {
53
+ if (probeMode && eventLog) appendProbeEvent(eventLog, runId, event, payload);
54
+ }
55
+
56
+ // ---------------------------------------------------------------------------
57
+ // §11-7 instrumented transport — write-callback semantics + wire markers.
58
+ // ---------------------------------------------------------------------------
59
+
60
+ type JsonRpcMessage = {
61
+ id?: string | number;
62
+ method?: string;
63
+ params?: { name?: string; arguments?: Record<string, unknown> };
64
+ result?: { tools?: Array<{ name?: string }> };
65
+ };
66
+
67
+ class InstrumentedStdioServerTransport extends StdioServerTransport {
68
+ // JSON-RPC request id → method, so a response frame can be attributed to the
69
+ // request that caused it (the response itself carries no method).
70
+ private readonly pendingMethods = new Map<string | number, string>();
71
+
72
+ constructor() {
73
+ super();
74
+ // The SDK protocol layer assigns `transport.onmessage = handler` after
75
+ // connect; the base class reads `this.onmessage`. Intercept the assignment
76
+ // so every inbound frame is stamped BEFORE the handler runs — receipt
77
+ // markers, not handler-return markers. Installed via defineProperty because
78
+ // the base declares `onmessage` as a plain property (TS2611 forbids a
79
+ // static accessor override) yet never assigns it in its constructor, so an
80
+ // instance accessor here wins cleanly.
81
+ let raw: ((message: unknown, extra?: unknown) => void) | undefined;
82
+ const stampInbound = (msg: JsonRpcMessage) => this.stampInbound(msg);
83
+ Object.defineProperty(this, "onmessage", {
84
+ get(): ((message: unknown, extra?: unknown) => void) | undefined {
85
+ if (!raw) return undefined;
86
+ return (message: unknown, extra?: unknown) => {
87
+ stampInbound(message as JsonRpcMessage);
88
+ raw?.(message, extra);
89
+ };
90
+ },
91
+ set(handler: ((message: unknown, extra?: unknown) => void) | undefined) {
92
+ raw = handler;
93
+ },
94
+ });
95
+ }
96
+
97
+ private stampInbound(msg: JsonRpcMessage): void {
98
+ if (typeof msg?.method !== "string") return;
99
+ if (msg.id !== undefined) this.pendingMethods.set(msg.id, msg.method);
100
+ if (msg.method === "initialize") {
101
+ emit(PROBE_EVENTS.fixtureInitializeReceived, { jsonrpcId: msg.id });
102
+ } else if (msg.method === "tools/list") {
103
+ emit(PROBE_EVENTS.fixtureToolsListReceived, { jsonrpcId: msg.id });
104
+ } else if (msg.method === "tools/call") {
105
+ emit(PROBE_EVENTS.fixtureToolsCallReceived, {
106
+ jsonrpcId: msg.id,
107
+ tool: msg.params?.name,
108
+ probeRunId: msg.params?.arguments?.probeRunId,
109
+ });
110
+ }
111
+ }
112
+
113
+ // Write with the CALLBACK, not the buffered-return the SDK send() settles
114
+ // for: the callback fires when the frame reached the OS pipe, which is the
115
+ // §11-7 definition of "forwarded". Markers are emitted inside the callback
116
+ // so they can never precede the hand-off they claim — and ONLY on a
117
+ // SUCCESSFUL callback: an errored write (EPIPE, closed stream) must reject,
118
+ // never stamp, or the marker would claim a hand-off that did not happen.
119
+ override send(message: unknown): Promise<void> {
120
+ const json = serializeMessage(message as never);
121
+ return new Promise((resolve, reject) => {
122
+ (this as unknown as { _stdout: NodeJS.WriteStream })._stdout.write(json, (err?: Error | null) => {
123
+ if (err) {
124
+ reject(err);
125
+ return;
126
+ }
127
+ this.stampOutbound(message as JsonRpcMessage);
128
+ resolve();
129
+ });
130
+ });
131
+ }
132
+
133
+ private stampOutbound(msg: JsonRpcMessage): void {
134
+ if (msg?.id === undefined || typeof msg.method === "string") return;
135
+ const requestMethod = this.pendingMethods.get(msg.id);
136
+ if (requestMethod === undefined) return;
137
+ this.pendingMethods.delete(msg.id);
138
+ if (requestMethod === "tools/list") {
139
+ const toolNames = (msg.result?.tools ?? []).map((t) => t?.name).filter((n): n is string => !!n);
140
+ if (toolNames.includes(EXPECTED_TOOL)) {
141
+ emit(PROBE_EVENTS.toolsListResponseForwarded, { jsonrpcId: msg.id, tools: toolNames });
142
+ }
143
+ } else if (requestMethod === "tools/call") {
144
+ emit(PROBE_EVENTS.fixtureToolsCallReplied, { jsonrpcId: msg.id });
145
+ }
146
+ }
147
+ }
148
+
149
+ // ---------------------------------------------------------------------------
150
+ // Server — one tool in both modes; probe mode adds the REQUIRED join key.
151
+ // ---------------------------------------------------------------------------
152
+
153
+ emit(PROBE_EVENTS.fixtureProcessStart, { startupDelayMs });
20
154
 
21
155
  const server = new McpServer({ name: "probe", version: "0.0.1" });
22
156
 
23
- server.tool(
24
- "probe_nonce",
25
- "Return this session's secret probe nonce. Call this when asked for the probe nonce.",
26
- {},
27
- async () => ({
28
- content: [{ type: "text", text: `PROBE_NONCE=${process.env.PROBE_NONCE ?? "MISSING"}` }],
29
- }),
30
- );
157
+ if (probeMode) {
158
+ server.tool(
159
+ EXPECTED_TOOL,
160
+ "Return this session's secret probe nonce. Call this when asked for the probe nonce, " +
161
+ "passing the exact probeRunId given in the prompt.",
162
+ { probeRunId: z.string().describe("The exact probeRunId string given in the prompt.") },
163
+ async () => ({
164
+ content: [{ type: "text", text: `PROBE_NONCE=${process.env[PROBE_ENV.nonce] ?? "MISSING"}` }],
165
+ }),
166
+ );
167
+ } else {
168
+ server.tool(
169
+ EXPECTED_TOOL,
170
+ "Return this session's secret probe nonce. Call this when asked for the probe nonce.",
171
+ {},
172
+ async () => ({
173
+ content: [{ type: "text", text: `PROBE_NONCE=${process.env[PROBE_ENV.nonce] ?? "MISSING"}` }],
174
+ }),
175
+ );
176
+ }
177
+
178
+ // The injected startup delay sits BEFORE the transport exists at all — the
179
+ // probe's controlled input models a slow-to-serve MCP server, so nothing may be
180
+ // readable on the wire until the delay elapses.
181
+ if (startupDelayMs > 0) {
182
+ emit(PROBE_EVENTS.fixtureDelayStart, { delayMs: startupDelayMs });
183
+ await new Promise((resolve) => setTimeout(resolve, startupDelayMs));
184
+ emit(PROBE_EVENTS.fixtureDelayEnd, { delayMs: startupDelayMs });
185
+ }
31
186
 
32
- const transport = new StdioServerTransport();
187
+ const transport = probeMode ? new InstrumentedStdioServerTransport() : new StdioServerTransport();
33
188
  await server.connect(transport);
189
+ emit(PROBE_EVENTS.fixtureTransportConnected, {});