@junghanacs/entwurf 0.15.1 → 0.16.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 (91) hide show
  1. package/AGENTS.md +1 -1
  2. package/CHANGELOG.md +354 -0
  3. package/DELIVERY.md +3 -2
  4. package/README.md +68 -88
  5. package/VERIFY.md +4 -1
  6. package/demo/README.md +1 -1
  7. package/docs/acp-backend-rail.md +1 -1
  8. package/docs/external-mcp-host.md +147 -9
  9. package/docs/setup-clean-host.md +125 -6
  10. package/mcp/entwurf-bridge/dist/mcp/entwurf-bridge/src/index.js +65 -20
  11. package/mcp/entwurf-bridge/dist/pi-extensions/entwurf-capabilities.json +1 -0
  12. package/mcp/entwurf-bridge/dist/pi-extensions/lib/acp/backend-adapter.js +19 -10
  13. package/mcp/entwurf-bridge/dist/pi-extensions/lib/entwurf-self-address.js +17 -6
  14. package/mcp/entwurf-bridge/dist/pi-extensions/lib/meta-sender-identity.js +1 -1
  15. package/mcp/entwurf-bridge/dist/pi-extensions/lib/meta-session.js +172 -5
  16. package/mcp/entwurf-bridge/dist/pi-extensions/lib/mux-fresh-call.js +152 -17
  17. package/mcp/entwurf-bridge/dist/pi-extensions/lib/omp-fresh-preflight.js +271 -0
  18. package/mcp/entwurf-bridge/dist/pi-extensions/meta-bridge-omp.js +988 -0
  19. package/mcp/entwurf-bridge/dist/pi-extensions/meta-bridge-receive-omp.js +574 -0
  20. package/mcp/entwurf-bridge/dist/scripts/omp-receive-facts.js +84 -0
  21. package/mcp/entwurf-bridge/src/index.ts +65 -19
  22. package/mcp/entwurf-bridge/tsconfig.build.json +19 -3
  23. package/mcp/tsconfig.json +10 -0
  24. package/package.json +19 -9
  25. package/pi/entwurf-capabilities.json +1 -0
  26. package/pi/meta-bridge-omp/entwurf-meta-omp/package.json +7 -0
  27. package/pi/omp-receive/entwurf-receive-omp/package.json +7 -0
  28. package/pi-extensions/entwurf-control.ts +12 -9
  29. package/pi-extensions/lib/acp/backend-adapter.ts +19 -9
  30. package/pi-extensions/lib/acp/backend.ts +125 -7
  31. package/pi-extensions/lib/acp/claude-acp-launch.js +100 -0
  32. package/pi-extensions/lib/entwurf-self-address.ts +18 -7
  33. package/pi-extensions/lib/meta-sender-identity.ts +1 -1
  34. package/pi-extensions/lib/meta-session.ts +219 -5
  35. package/pi-extensions/lib/mux-fresh-call.ts +171 -17
  36. package/pi-extensions/lib/omp-fresh-preflight.ts +275 -0
  37. package/pi-extensions/meta-bridge-omp.ts +1244 -0
  38. package/pi-extensions/meta-bridge-receive-omp.ts +666 -0
  39. package/run.sh +399 -31
  40. package/scripts/check-acp-launch-namespace.ts +127 -0
  41. package/scripts/check-acp-prompt-lifecycle.ts +145 -2
  42. package/scripts/check-copilot-birth-hook.ts +28 -1
  43. package/scripts/check-entwurf-self-address.ts +31 -0
  44. package/scripts/check-gate-qualification.ts +7 -3
  45. package/scripts/check-harness-admission-parity.ts +143 -0
  46. package/scripts/check-meta-doctor-oracle.sh +20 -0
  47. package/scripts/check-omp-birth-hook.ts +1049 -0
  48. package/scripts/check-omp-fresh-preflight.ts +208 -0
  49. package/scripts/check-omp-receive-arm.ts +516 -0
  50. package/scripts/check-setup-qualification.sh +40 -2
  51. package/scripts/copilot-bridge-oracle.sh +14 -6
  52. package/scripts/fake-copilot-vendor.sh +4 -2
  53. package/scripts/inventory-verification-surface.ts +1 -1
  54. package/scripts/meta-bridge-hook-log.sh +9 -1
  55. package/scripts/mutants/acp-launch-namespace.json +34 -0
  56. package/scripts/mutants/acp-prompt-lifecycle.json +67 -2
  57. package/scripts/mutants/copilot-birth.json +10 -10
  58. package/scripts/mutants/mux-fresh-call.json +22 -22
  59. package/scripts/mutants/omp-birth.json +173 -0
  60. package/scripts/mutants/omp-fresh.json +300 -0
  61. package/scripts/mutants/omp-receive.json +135 -0
  62. package/scripts/mutants/pack-install.json +2 -2
  63. package/scripts/mutants/self-address.json +34 -0
  64. package/scripts/mutants/setup-verdict.json +35 -0
  65. package/scripts/omp-bridge-doctor.sh +315 -0
  66. package/scripts/omp-bridge-install.sh +221 -0
  67. package/scripts/omp-bridge-oracle.sh +154 -0
  68. package/scripts/omp-bridge-uninstall.sh +57 -0
  69. package/scripts/omp-config-xdev.py +310 -0
  70. package/scripts/omp-config-xdev.sh +76 -0
  71. package/scripts/omp-mcp-bridge.sh +320 -0
  72. package/scripts/omp-mcp-config.py +392 -0
  73. package/scripts/omp-receive-doctor.sh +246 -0
  74. package/scripts/omp-receive-facts.ts +106 -0
  75. package/scripts/omp-receive-install.sh +228 -0
  76. package/scripts/omp-receive-uninstall.sh +60 -0
  77. package/scripts/omp-tool-surface.py +400 -0
  78. package/scripts/raw-acp-child-exit-measure/README.md +285 -0
  79. package/scripts/raw-acp-child-exit-measure/acp-turn-population.py +89 -0
  80. package/scripts/raw-acp-child-exit-measure/reaper-correlation.py +47 -0
  81. package/scripts/raw-omp-measure/README.md +420 -0
  82. package/scripts/raw-omp-measure/probe-extension.ts +76 -0
  83. package/scripts/raw-omp-measure/probe-receive-surface.ts +250 -0
  84. package/scripts/raw-omp-measure/source-audit.md +414 -0
  85. package/scripts/smoke-omp-bridge-state.sh +221 -0
  86. package/scripts/smoke-omp-fresh-live.ts +497 -0
  87. package/scripts/smoke-omp-mcp-state.sh +327 -0
  88. package/scripts/smoke-omp-receive-live.ts +340 -0
  89. package/scripts/smoke-omp-receive-state.sh +196 -0
  90. package/scripts/smoke-setup-verdict.sh +48 -3
  91. package/scripts/tsconfig.json +2 -0
@@ -70,10 +70,14 @@ import {
70
70
  runTmux,
71
71
  type WindowHandle,
72
72
  } from "./mux-placement.ts";
73
+ import { OMP_PREFLIGHT_HINT, type OmpPreflightRejectReason, ompFreshPreflight } from "./omp-fresh-preflight.ts";
73
74
 
74
75
  /** The backends this rail can open. Fixed set, not a profile — a further one is a decision,
75
- * not a config entry. `copilot` was added by #82 RAIL 9 under the step 9 admission contract. */
76
- export const FRESH_CALL_BACKENDS = ["pi", "claude-code", "copilot"] as const;
76
+ * not a config entry. `copilot` was added by #82 RAIL 9 under the step 9 admission contract, and
77
+ * `omp` by #87 Bundle C under the same one. The set is joined to the citizen backends by
78
+ * `check-harness-admission-parity`: a harness that mints records but is missing HERE is not an
79
+ * unwired convenience, it is a release blocker. */
80
+ export const FRESH_CALL_BACKENDS = ["pi", "claude-code", "copilot", "omp"] as const;
77
81
  export type FreshCallBackend = (typeof FRESH_CALL_BACKENDS)[number];
78
82
 
79
83
  /**
@@ -89,11 +93,20 @@ export type FreshCallBackend = (typeof FRESH_CALL_BACKENDS)[number];
89
93
  * flag, its recursion fence and its receiver precondition; fresh call reaches Copilot only
90
94
  * through it. The cost is named: a Copilot fresh call needs a current `entwurf` on PATH, the
91
95
  * way a pi fresh call needs `pi`.
96
+ *
97
+ * `omp` resolves the BARE vendor, and that difference is a measured one rather than an
98
+ * inconsistency. Copilot needs a managed wrapper because the bare CLI starts without
99
+ * `COPILOT_CLI_ENABLED_FEATURE_FLAGS=EXTENSIONS` and skips its extension scan silently — there
100
+ * is a flag only a launcher can carry. omp has no such flag: it always scans its extensions
101
+ * directory, and the one thing it needs beyond that (`tools.xdev: false`) lives in the operator
102
+ * config, which is a PREFLIGHT fact and not something a launcher could supply. Inventing an
103
+ * `entwurf omp` verb here would add a managed surface with nothing to manage.
92
104
  */
93
105
  export const FRESH_CALL_RUNTIME: Record<FreshCallBackend, string> = {
94
106
  pi: "pi",
95
107
  "claude-code": "claude",
96
108
  copilot: "entwurf",
109
+ omp: "omp",
97
110
  };
98
111
 
99
112
  /**
@@ -107,11 +120,21 @@ export const FRESH_CALL_RUNTIME: Record<FreshCallBackend, string> = {
107
120
  * `tool.execution_start.toolName` both carry `entwurf-bridge-entwurf_v2`, with
108
121
  * `mcpServerName`/`mcpToolName` beside them as the parts. Derive-and-measure, never copy a
109
122
  * sibling's spelling (`docs/adding-a-harness.md` step 5).
123
+ *
124
+ * `[측정]` omp 18.0.0 is the sharpest case for that rule: it mints
125
+ * `mcp__${sanitizedServerName}_${normalizedToolName}` with a sanitizer whose charset is
126
+ * `[a-z_]` (`mcp/tool-bridge.ts:351-357`, `:396`), so the DIGIT IN `entwurf_v2` IS EATEN and the
127
+ * hyphen in the server key becomes an underscore — the model-facing name is
128
+ * `mcp__entwurf_bridge_entwurf_v`, not `..._entwurf_v2` and not Claude's double-underscore form.
129
+ * Confirmed against a live tool dump of all seven bridge tools and a real session transcript
130
+ * (`scripts/raw-omp-measure/README.md` "Tool-name dialect"). Unlike Copilot there is no second
131
+ * permission dialect: omp's approval layer consults the same minted string (`source-audit.md`).
110
132
  */
111
133
  export const FRESH_CALL_CALLBACK_TOOL: Record<FreshCallBackend, string> = {
112
134
  pi: "entwurf_v2",
113
135
  "claude-code": "mcp__entwurf-bridge__entwurf_v2",
114
136
  copilot: "entwurf-bridge-entwurf_v2",
137
+ omp: "mcp__entwurf_bridge_entwurf_v",
115
138
  };
116
139
 
117
140
  /** Mirrors the `entwurf_v2` message bound. This is an INTERFACE cap for symmetry with the
@@ -119,7 +142,7 @@ export const FRESH_CALL_CALLBACK_TOOL: Record<FreshCallBackend, string> = {
119
142
  * that the OS refuses is a launch failure and fails loud — it never reads as a delivered task. */
120
143
  export const TASK_MAX_CHARS = 16000;
121
144
  export const MODEL_MAX_CHARS = 200;
122
- const MODEL_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._/:\[\]-]*$/;
145
+ const MODEL_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._/:[\]-]*$/;
123
146
 
124
147
  /** A model is an explicit launch input, not ambient process state. The grammar admits canonical
125
148
  * pi provider/model ids, Claude model ids/aliases, and bracketed context variants, while refusing
@@ -140,6 +163,11 @@ export function isSafeFreshCallModel(model: string): boolean {
140
163
  * copilot — the managed VERB first, then the prompt as the value of `-i/--interactive`,
141
164
  * `--model`, value as two tokens, and the policy as the explicit `--yolo`
142
165
  * token. Measured from `copilot --help` (1.0.80).
166
+ * omp — NO positional prompt at all. The task rides `--entwurf-bootstrap`, a fixed
167
+ * flag the installed birth extension registers, then `--model`, value as two
168
+ * tokens, then the policy as `--approval-mode`, `yolo`. `-p/--print` remains
169
+ * the flag this argv must never carry — it processes a prompt and EXITS,
170
+ * closing the window on a sibling that has to stay open to be delivered to.
143
171
  *
144
172
  * Both pi/claude failures looked identical from outside: window open, record and socket minted,
145
173
  * no turn.
@@ -172,18 +200,108 @@ export function isSafeFreshCallModel(model: string): boolean {
172
200
  * `--allow-tool` takes `<mcp-server-name>(tool-name?)`, a different dialect from the
173
201
  * model-facing tool name — stays recorded in `docs/adding-a-harness.md` step 9's worked
174
202
  * example; it is a measured vendor fact even though this argv no longer uses it.
203
+ *
204
+ * OMP'S POLICY TOKEN IS THE ONE MOST EASILY ARGUED AWAY, SO READ THIS BEFORE DELETING IT.
205
+ * `[측정]` omp 18.0.0's schema default for `tools.approvalMode` IS ALREADY `yolo`
206
+ * (vendor doc `omp://approval-mode.md`; `omp config get tools.approvalMode` → `yolo` on the
207
+ * acceptance host). So dropping `--approval-mode yolo` changes NOTHING observable: the callback
208
+ * still fires, the LIVE smoke still passes, and the argv silently starts depending on a vendor
209
+ * default and on whatever the operator's config happens to say. That is exactly the drift step 9
210
+ * clause 2 forbids — "carry the chosen width as an explicit argv token rather than relying on a
211
+ * launcher's injected default" — and the reason the width is stated here even though the host
212
+ * would have granted it anyway. The width itself (task-wide, not callback-only) is a GLG
213
+ * operator decision of 2026-08-30, taken with the Copilot measurement in hand: a callback-only
214
+ * sibling names itself and then stops at the first tool its TASK needs. omp offers no argv
215
+ * grammar for a narrower grant at all — `tools.approval.<tool>` is a config axis, not a flag —
216
+ * so the honest choice was between `write` and `yolo`, and `yolo` matches what a human-typed
217
+ * `omp` gets on this host. `--approval-mode` takes both the space and equals form (measured);
218
+ * the space form is used for symmetry with `--model`.
219
+ *
220
+ * WHY OMP ALONE CARRIES NO PROMPT, AND WHY THAT IS A MEASUREMENT RATHER THAN A PREFERENCE.
221
+ * `[LIVE 2026-08-30]` the first public fresh call at omp DID pass the full framing as a bare
222
+ * positional. The window opened, the record minted (garden `20260830T181342-452167`), the
223
+ * prompt arrived byte-identical as a user message at `09:13:42.413Z` — and the model answered
224
+ * the literal text `ACK` with ZERO tool calls, because the callback tool did not exist yet.
225
+ * `[source]` the interactive UI defers MCP discovery and only refreshes the tool list once
226
+ * `discoverAndConnect()` settles (`sdk.ts:1847-1855`, `:1881-1905`), while the positional
227
+ * `initialMessage` prompts immediately after `await mode.init()` (`main.ts:540-565`,
228
+ * `595-610`). `[측정]` a `/tmp` observer on the same runtime: `turn_start` at +654ms with the
229
+ * entwurf tools ABSENT, callback tool present only at +1484ms — the turn began ~830ms before
230
+ * the tool it was told to call existed. No argv can close that gap, because the gap is a race
231
+ * inside the host. So the composition hands omp a PAYLOAD instead of a turn, and the
232
+ * in-process birth extension — which can see when the tool becomes callable — owns the first
233
+ * two messages (`pi-extensions/meta-bridge-omp.ts`, "THE TWO-STAGE FRESH BOOTSTRAP").
234
+ *
235
+ * The flag is fixed and one-purpose ON PURPOSE. `[측정 2026-08-30]` a normal discovered
236
+ * extension that registers a flag receives the operator's argv value byte-identical — quotes,
237
+ * `$VAR`, backticks and a semicolon all survived a 137-byte JSON payload — because extensions
238
+ * load before argv classification and the reparse writes the registered map
239
+ * (`main.ts:1799-1810`, `cli/extension-flags.ts:36-43`). An env carrier or a temp file would
240
+ * have needed its own quoting, its own lifetime and its own refusal rules; argv already owns
241
+ * all three. This is deliberately NOT a general `--flag value` passthrough — an arbitrary
242
+ * carrier would hand callers the launch-shaping power this rail exists to refuse.
175
243
  */
176
- export function buildBackendArgs(backend: FreshCallBackend, prompt: string, model: string): string[] {
244
+ export function buildBackendArgs(
245
+ backend: FreshCallBackend,
246
+ composition: FreshCallComposition,
247
+ model: string,
248
+ ): string[] {
177
249
  switch (backend) {
178
250
  case "pi":
179
- return [prompt, "--entwurf-control", "--model", model];
251
+ return [composition.prompt, "--entwurf-control", "--model", model];
180
252
  case "claude-code":
181
- return [prompt, `--allowedTools=${FRESH_CALL_CALLBACK_TOOL["claude-code"]}`, `--model=${model}`];
253
+ return [composition.prompt, `--allowedTools=${FRESH_CALL_CALLBACK_TOOL["claude-code"]}`, `--model=${model}`];
182
254
  case "copilot":
183
- return ["copilot", "--interactive", prompt, "--model", model, "--yolo"];
255
+ return ["copilot", "--interactive", composition.prompt, "--model", model, "--yolo"];
256
+ case "omp":
257
+ return [`--${OMP_BOOTSTRAP_FLAG}`, composition.bootstrapPayload, "--model", model, "--approval-mode", "yolo"];
184
258
  }
185
259
  }
186
260
 
261
+ /**
262
+ * What a launch has to say, in the two shapes the four backends need. Three of them are
263
+ * handed a first-turn PROMPT; omp is handed a bootstrap PAYLOAD its own installed extension
264
+ * unpacks. Both are always built, because building one is cheap and a backend switch must
265
+ * never be able to reach a field that was not composed.
266
+ */
267
+ export interface FreshCallComposition {
268
+ prompt: string;
269
+ bootstrapPayload: string;
270
+ }
271
+
272
+ /**
273
+ * The omp bootstrap flag, spelled WITHOUT dashes — the vendor's flag map is keyed by bare
274
+ * name (`extensions/loader.ts:221-228`) and this composition adds the `--` itself.
275
+ *
276
+ * Held equal to the installed extension's own constant by
277
+ * `test/omp-fresh-bootstrap.contract.test.ts`. The two copies exist because the extension
278
+ * ships INSIDE the omp agent dir carrying only its own small closure and cannot import this
279
+ * module; the gate is what keeps the duplication from becoming drift.
280
+ */
281
+ export const OMP_BOOTSTRAP_FLAG = "entwurf-bootstrap";
282
+
283
+ /** Payload grammar version, matched exactly by the decoder. A bump means a stale installed
284
+ * unit, which is the one thing `doctor-omp-bridge` exists to say out loud. */
285
+ export const OMP_BOOTSTRAP_VERSION = 1;
286
+
287
+ /**
288
+ * The whole of what a fresh omp sibling is launched with.
289
+ *
290
+ * THREE FIELDS, CLOSED. The decoder refuses an unknown key, so this object is the entire
291
+ * contract: who to call back, the nonce that proves it is this call, and the task that is
292
+ * released only after that callback succeeds. There is no command here, no path, no env name
293
+ * and no model — the model is already an explicit argv token, and a second copy of it inside
294
+ * a payload would be a second place for it to disagree with the launch.
295
+ */
296
+ export function buildOmpBootstrapPayload(params: { callerGardenId: string; nonce: string; task: string }): string {
297
+ return JSON.stringify({
298
+ v: OMP_BOOTSTRAP_VERSION,
299
+ target: params.callerGardenId,
300
+ nonce: params.nonce,
301
+ task: params.task,
302
+ });
303
+ }
304
+
187
305
  /**
188
306
  * The first-turn framing. Order is the contract: the callback is the FIRST action and the task
189
307
  * follows it, so a sibling that gets stuck in the task has already told the caller who it is.
@@ -224,6 +342,7 @@ export type FreshCallRejectReason =
224
342
  | LaunchRejectReason
225
343
  | TmuxCwdRejectReason
226
344
  | CopilotPreflightRejectReason
345
+ | OmpPreflightRejectReason
227
346
  | "caller-identity-unavailable"
228
347
  | "model-empty"
229
348
  | "model-invalid"
@@ -256,9 +375,35 @@ function defaultRandomHex(): string {
256
375
  return randomBytes(12).toString("hex");
257
376
  }
258
377
 
259
- /** Launch argv: the leaf's detached-append shape, optionally `-c` at the resume-symmetric token
260
- * position (after `-t`, before `-P -F`), the runtime, then the backend's dialect. An omitted cwd
261
- * yields the exact pre-#73 argv — no carrier at all. */
378
+ /**
379
+ * The pi identity carrier, scrubbed at the launch seam for EVERY backend (#87 Bundle C).
380
+ *
381
+ * `[측정]` 2026-08-30, private tmux server: a `new-window` pane inherits the tmux SERVER's
382
+ * environment, not the caller's. A server started from a shell that exported `PI_SESSION_ID`
383
+ * hands that value to every window it will ever open — the control run printed
384
+ * `SID=[leaked-uuid]` in a pane the caller never touched. Nothing about the fresh call creates
385
+ * that leak and nothing about it notices: the sibling's own MCP child would read the STALE pair
386
+ * as its authoritative identity and call home as a citizen it is not (`mcp/entwurf-bridge/
387
+ * src/index.ts:692-698` keeps the measured incident — a fresh cell answering with the uuidv7 it
388
+ * found in the environment, confidently and wrong).
389
+ *
390
+ * `-e VAR=` sets the variable EMPTY rather than unsetting it, which tmux has no per-window form
391
+ * for. That is sufficient and not a compromise: every reader of the carrier trims and tests
392
+ * truthiness (`index.ts:212-217`), so empty and absent are the same answer by construction.
393
+ *
394
+ * It is applied to all four backends because the leak is a property of tmux, not of a vendor. A
395
+ * scrub only on the backend whose measurement surfaced it would encode the claim that the other
396
+ * three are immune, which is false. It costs the legitimate case nothing: a carrier is only ever
397
+ * authoritative when the process that owns it exported it ITSELF, and a fresh `pi` sibling does
398
+ * exactly that after this argv has run. This is a fixed two-variable seam and deliberately NOT a
399
+ * general env carrier — an arbitrary `-e` passthrough would hand callers the environment-shaping
400
+ * power this rail exists to refuse.
401
+ */
402
+ const SCRUBBED_INHERITED_ENV = ["PI_SESSION_ID=", "PI_AGENT_ID="] as const;
403
+
404
+ /** Launch argv: the leaf's detached-append shape, the identity scrub, optionally `-c` at the
405
+ * resume-symmetric token position (after `-t`, before `-P -F`), the runtime, then the backend's
406
+ * dialect. An omitted cwd adds no `-c` carrier at all. */
262
407
  export function buildFreshCallArgs(
263
408
  placement: Placement,
264
409
  runtimePath: string,
@@ -275,6 +420,7 @@ export function buildFreshCallArgs(
275
420
  "new-window",
276
421
  "-d",
277
422
  "-a",
423
+ ...SCRUBBED_INHERITED_ENV.flatMap((assignment) => ["-e", assignment]),
278
424
  "-t",
279
425
  `${placement.sessionId}:{end}`,
280
426
  ...(cwd === undefined ? [] : ["-c", cwd]),
@@ -337,20 +483,27 @@ export function freshCall(
337
483
  const missing = copilotFreshPreflight(env);
338
484
  if (missing) return { ok: false, reason: missing };
339
485
  }
486
+ if (params.backend === "omp") {
487
+ const missing = ompFreshPreflight(env);
488
+ if (missing) return { ok: false, reason: missing };
489
+ }
340
490
 
341
491
  const inspected = inspectPlacement(env);
342
492
  if (!inspected.ok) return { ok: false, reason: inspected.reason };
343
493
  const placement = inspected.placement;
344
494
  requireSameContext("freshCall", placement, env);
345
495
 
346
- const prompt = buildFreshCallPrompt({
347
- backend: params.backend,
348
- task,
349
- callerGardenId: params.callerGardenId,
350
- nonce,
351
- });
496
+ const composition: FreshCallComposition = {
497
+ prompt: buildFreshCallPrompt({
498
+ backend: params.backend,
499
+ task,
500
+ callerGardenId: params.callerGardenId,
501
+ nonce,
502
+ }),
503
+ bootstrapPayload: buildOmpBootstrapPayload({ callerGardenId: params.callerGardenId, nonce, task }),
504
+ };
352
505
  const run = runTmux(
353
- buildFreshCallArgs(placement, runtimePath, buildBackendArgs(params.backend, prompt, model), cwd),
506
+ buildFreshCallArgs(placement, runtimePath, buildBackendArgs(params.backend, composition, model), cwd),
354
507
  env,
355
508
  );
356
509
  assertTmuxOk("new-window", run);
@@ -390,6 +543,7 @@ const REJECT_HINT: Record<FreshCallRejectReason, string> = {
390
543
  // The Copilot capability reasons keep their repair text on the leaf that decides them, so
391
544
  // the sentence an operator reads cannot drift away from the predicate that produced it.
392
545
  ...COPILOT_PREFLIGHT_HINT,
546
+ ...OMP_PREFLIGHT_HINT,
393
547
  "no-tmux-context": "this agent is not running inside tmux, so there is no session to open a sibling beside",
394
548
  "anchor-malformed": "TMUX_PANE is not a native pane id",
395
549
  "anchor-unresolved": "tmux resolved no pane for this agent's anchor",
@@ -0,0 +1,275 @@
1
+ /**
2
+ * omp-fresh-preflight — the pre-mutation capability check an OMP fresh call needs
3
+ * (#87 Bundle C, `docs/adding-a-harness.md` step 9 clauses 3, 4 and 5).
4
+ *
5
+ * Same shape and the same reasons as `copilot-fresh-preflight.ts`: a doctor answers "is this
6
+ * host correctly wired?" and may be slow, spawn the vendor and read live processes. This is not
7
+ * that. It answers ONE narrower question at ONE moment — before `mux-fresh-call` mutates the
8
+ * operator's tmux session, are the things the fresh contract requires actually in place on this
9
+ * filesystem?
10
+ *
11
+ * ── Why OMP has FIVE axes where Copilot has four ──
12
+ *
13
+ * birth — without the birth extension the session mints no record, so the callback
14
+ * carries no garden id and the sibling never becomes addressable.
15
+ * MCP hand — without the native `entwurf-bridge` server the callback tool does not
16
+ * exist in that session and the first turn has nothing to call.
17
+ * receive — without the receiver extension the sibling can be launched and can call
18
+ * home, and then nothing can ever be delivered TO it.
19
+ * visible identity — the garden id must be on the harness's own persistent surface.
20
+ * callback callable — THE OMP-SPECIFIC ONE. `tools.xdev` defaults to TRUE, which mounts MCP
21
+ * tools as `xd://` devices whose schemas never reach the prompt. The tool
22
+ * would be configured, the bridge would be running, and the model still
23
+ * could not call `mcp__entwurf_bridge_entwurf_v`. Step 9 clause 5 makes the
24
+ * callback the FIRST action, so a fresh call onto a default-config host
25
+ * opens a window that can never name itself. `[측정]` #87 A-lane: the
26
+ * vendor default wrapped the send tool and produced a false delivery report.
27
+ *
28
+ * Copilot's fourth axis is a statusline COMMAND that must resolve on PATH. OMP has no such
29
+ * surface: `ctx.ui.setStatus` inside the birth extension is the only thing that renders
30
+ * extension-owned text on a v18 TUI (`pi-extensions/meta-bridge-omp.ts:163-169`), and the
31
+ * vendor gates it on `statusLine.showHookStatus` (default true). So visible identity here is
32
+ * "the birth extension is installed AND the operator has not turned hook status off" — a
33
+ * different predicate for the same clause, derived rather than copied.
34
+ *
35
+ * ── What this deliberately does NOT claim ──
36
+ *
37
+ * Ownership/configuration truth only. It does NOT prove omp loaded the extensions, connected
38
+ * the MCP server, or rendered a garden id — that is runtime truth and belongs to
39
+ * `doctor-omp-bridge` / `doctor-omp-receive` / `doctor-omp-mcp` and to the clause 7 LIVE
40
+ * receipt. A green preflight is a statement about this filesystem, not a prediction about the
41
+ * next process.
42
+ *
43
+ * No vendor spawn, no network, no await, no mutation.
44
+ */
45
+
46
+ import { existsSync, readFileSync, statSync } from "node:fs";
47
+ import * as path from "node:path";
48
+
49
+ /** One reason per axis, plus the environment refusal. These strings are stable contract — they
50
+ * cross the public surfaces as `entwurf_fresh_call` refusals, so a caller can act on them. */
51
+ export type OmpPreflightRejectReason =
52
+ | "omp-agent-dir-ambiguous"
53
+ | "omp-birth-unit-missing"
54
+ | "omp-mcp-hand-missing"
55
+ | "omp-receive-unit-missing"
56
+ | "omp-visible-identity-missing"
57
+ | "omp-callback-tool-uncallable";
58
+
59
+ const BIRTH_UNIT = "entwurf-meta-omp";
60
+ const RECEIVE_UNIT = "entwurf-receive-omp";
61
+ const MCP_SERVER_KEY = "entwurf-bridge";
62
+ /** Vendor load order, `utils/src/dirs.ts` MAIN_CONFIG_FILENAMES. */
63
+ const MAIN_CONFIG_FILENAMES = ["config.yml", "config.yaml"] as const;
64
+ /** `utils/src/dirs.ts` PROFILE_NAME_RE, reproduced from `scripts/omp-bridge-oracle.sh`. */
65
+ const PROFILE_NAME_RE = /^[a-z0-9][a-z0-9._-]*$/;
66
+
67
+ /**
68
+ * The agent directory omp itself would read, or `null` for REFUSE.
69
+ *
70
+ * This is `omp_agent_dir` from `scripts/omp-bridge-oracle.sh`, expressed in the language this
71
+ * half is written in. It is a reproduction on purpose and not a spawn of that script: the fresh
72
+ * lane runs inside the pi extension and inside the bundled MCP child, and resolving a sibling
73
+ * shell script by relative path from two different emit depths is the exact arithmetic
74
+ * `check-capability-bundle-reach` exists to catch. The AGREEMENT of the two implementations is
75
+ * pinned by `check-omp-fresh-preflight`, which drives both over the same environments.
76
+ *
77
+ * A `PI_*` knob is a refusal and never a lookup (#87 ledger M6): omp is a pi fork that kept pi's
78
+ * env vocabulary, so `PI_CODING_AGENT_DIR` steers TWO harnesses and a value in the environment
79
+ * does not say which one it is addressing. Guessing here would aim the preflight at a directory
80
+ * no live omp reads, and it would report green off an empty one.
81
+ */
82
+ export function ompAgentDir(env: NodeJS.ProcessEnv): string | null {
83
+ const explicit = env.ENTWURF_OMP_AGENT_DIR;
84
+ if (typeof explicit === "string" && explicit.length > 0) {
85
+ const home = env.HOME;
86
+ const expanded =
87
+ explicit === "~" || explicit.startsWith("~/")
88
+ ? typeof home === "string" && home.length > 0
89
+ ? path.join(home, explicit.slice(1))
90
+ : null
91
+ : explicit;
92
+ return expanded === null ? null : path.resolve(expanded);
93
+ }
94
+ if (typeof env.PI_CODING_AGENT_DIR === "string" && env.PI_CODING_AGENT_DIR.length > 0) return null;
95
+ if (typeof env.PI_CONFIG_DIR === "string" && env.PI_CONFIG_DIR.length > 0) return null;
96
+ const ompProfile = env.OMP_PROFILE;
97
+ const hasOmpProfile = typeof ompProfile === "string" && ompProfile.length > 0;
98
+ if (typeof env.PI_PROFILE === "string" && env.PI_PROFILE.length > 0 && !hasOmpProfile) return null;
99
+ const home = env.HOME;
100
+ if (typeof home !== "string" || home.length === 0) return null;
101
+ if (hasOmpProfile) {
102
+ if (!PROFILE_NAME_RE.test(ompProfile)) return null;
103
+ return path.join(home, ".omp", "profiles", ompProfile, "agent");
104
+ }
105
+ return path.join(home, ".omp", "agent");
106
+ }
107
+
108
+ function isDir(p: string): boolean {
109
+ try {
110
+ return statSync(p).isDirectory();
111
+ } catch {
112
+ // Bounded environment probing, Hard Rule 15's stated exception.
113
+ return false;
114
+ }
115
+ }
116
+
117
+ /** A JSON object or nothing. Unreadable, unparseable and not-an-object are the SAME answer,
118
+ * because the caller's next move is identical in all three: run the installer. */
119
+ function readJsonObject(file: string): Record<string, unknown> | null {
120
+ try {
121
+ const parsed: unknown = JSON.parse(readFileSync(file, "utf8"));
122
+ return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)
123
+ ? (parsed as Record<string, unknown>)
124
+ : null;
125
+ } catch {
126
+ return null;
127
+ }
128
+ }
129
+
130
+ /**
131
+ * The effective value of one TOP-LEVEL-then-one-key path in omp's config, as a tri-state:
132
+ * `true` / `false` / `null` for "not stated, or not readable with confidence".
133
+ *
134
+ * A deliberately NARROW block-YAML reader — it understands exactly the shape these two settings
135
+ * are written in (`tools:` newline, two-space `xdev: false`) and answers `null` for everything
136
+ * else. It mirrors `scripts/omp-tool-surface.py`'s scalar vocabulary for booleans, including its
137
+ * `true/yes/on/y` word set and its comment stripping, but it does NOT try to be that parser: the
138
+ * Python leaf reports a full verdict for a doctor, this one answers one question for a refusal.
139
+ *
140
+ * The tri-state is what makes both callers able to fail in the direction their axis needs, so
141
+ * neither has to invent a default here.
142
+ */
143
+ export function readOmpConfigFlag(agentDir: string, section: string, key: string): boolean | null {
144
+ let text: string | null = null;
145
+ for (const name of MAIN_CONFIG_FILENAMES) {
146
+ const candidate = path.join(agentDir, name);
147
+ if (!existsSync(candidate)) continue;
148
+ try {
149
+ if (statSync(candidate).isDirectory()) return null;
150
+ text = readFileSync(candidate, "utf8");
151
+ } catch {
152
+ return null;
153
+ }
154
+ break;
155
+ }
156
+ if (text === null) return null;
157
+ // A tab anywhere in the body makes this not-YAML for the vendor's own reader; refuse rather
158
+ // than guess which indentation the vendor would have seen.
159
+ let inSection = false;
160
+ // The indent of the section's IMMEDIATE children, learned from the first one. Matching a key
161
+ // at any deeper indent would read `tools.nested.xdev` as `tools.xdev` — a fail-OPEN misread
162
+ // that would preflight green off a config which never set the flag. Caught by
163
+ // `check-omp-fresh-preflight` when this reader was first compared against the python leaf.
164
+ let childIndent = -1;
165
+ for (const raw of text.split("\n")) {
166
+ const body = stripComment(raw);
167
+ if (body.trim() === "") continue;
168
+ if (body.includes("\t")) return null;
169
+ const indent = body.length - body.trimStart().length;
170
+ const trimmed = body.trim();
171
+ if (!inSection) {
172
+ if (indent === 0 && trimmed === `${section}:`) inSection = true;
173
+ continue;
174
+ }
175
+ if (indent === 0) break; // the section ended at the next top-level key
176
+ if (childIndent === -1) childIndent = indent;
177
+ if (indent !== childIndent) continue; // a grandchild, or a mis-indented line: not our key
178
+ const colon = trimmed.indexOf(":");
179
+ if (colon <= 0) continue;
180
+ if (trimmed.slice(0, colon).trim() !== key) continue;
181
+ return parseBool(trimmed.slice(colon + 1).trim());
182
+ }
183
+ return null;
184
+ }
185
+
186
+ /** Comment stripping with the same quote awareness as `omp-tool-surface.py:strip_comment`. */
187
+ function stripComment(raw: string): string {
188
+ let inSingle = false;
189
+ let inDouble = false;
190
+ let escaped = false;
191
+ for (let i = 0; i < raw.length; i++) {
192
+ const ch = raw[i];
193
+ if (escaped) {
194
+ escaped = false;
195
+ continue;
196
+ }
197
+ if (ch === "\\" && inDouble) {
198
+ escaped = true;
199
+ continue;
200
+ }
201
+ if (ch === "'" && !inDouble) inSingle = !inSingle;
202
+ else if (ch === '"' && !inSingle) inDouble = !inDouble;
203
+ else if (ch === "#" && !inSingle && !inDouble) return raw.slice(0, i).trimEnd();
204
+ }
205
+ return raw.trimEnd();
206
+ }
207
+
208
+ /** `omp-tool-surface.py:parse_scalar`'s boolean vocabulary; anything else is "not a boolean". */
209
+ function parseBool(text: string): boolean | null {
210
+ const folded = text.toLowerCase();
211
+ if (["true", "yes", "on", "y"].includes(folded)) return true;
212
+ if (["false", "no", "off", "n"].includes(folded)) return false;
213
+ return null;
214
+ }
215
+
216
+ /**
217
+ * The five axes, decided in the order an operator should repair them. Returns the FIRST missing
218
+ * capability, or `null` when every one is in place.
219
+ *
220
+ * Order is not cosmetic. The agent dir comes first because every other predicate is a path under
221
+ * it — reporting "birth unit missing" while the directory itself is ambiguous would send the
222
+ * operator to reinstall into a directory omp may never read. Birth precedes the rest because a
223
+ * host with no birth unit has nothing else worth checking, and visible identity depends on the
224
+ * same unit.
225
+ */
226
+ export function ompFreshPreflight(env: NodeJS.ProcessEnv): OmpPreflightRejectReason | null {
227
+ const agentDir = ompAgentDir(env);
228
+ if (agentDir === null) return "omp-agent-dir-ambiguous";
229
+
230
+ const extensions = path.join(agentDir, "extensions");
231
+ if (!isDir(path.join(extensions, BIRTH_UNIT))) return "omp-birth-unit-missing";
232
+
233
+ // The native MCP entry omp reads, at the ONE non-configurable path the installer owns
234
+ // (`scripts/omp-mcp-bridge.sh`: `<resolved omp agent dir>/mcp.json`).
235
+ const mcp = readJsonObject(path.join(agentDir, "mcp.json"));
236
+ const servers = mcp?.mcpServers;
237
+ const hand =
238
+ typeof servers === "object" && servers !== null && !Array.isArray(servers)
239
+ ? (servers as Record<string, unknown>)[MCP_SERVER_KEY]
240
+ : undefined;
241
+ if (typeof hand !== "object" || hand === null || Array.isArray(hand)) return "omp-mcp-hand-missing";
242
+
243
+ if (!isDir(path.join(extensions, RECEIVE_UNIT))) return "omp-receive-unit-missing";
244
+
245
+ // Visible identity: the vendor default is TRUE, so only an explicit false refuses. An
246
+ // unreadable config is not a refusal HERE — it is one on the axis below, which needs proof
247
+ // rather than absence, and reporting the same file twice under two names would send an
248
+ // operator looking for two problems.
249
+ if (readOmpConfigFlag(agentDir, "statusLine", "showHookStatus") === false) return "omp-visible-identity-missing";
250
+
251
+ // Callback callable: the vendor default is TRUE and true is the BROKEN state, so this axis
252
+ // requires positive proof of `false`. Absent file, absent key and unparseable config all
253
+ // refuse — that is the fail-closed direction, and it is the opposite of the axis above for
254
+ // the same reason: each fails toward the value the vendor would actually apply.
255
+ if (readOmpConfigFlag(agentDir, "tools", "xdev") !== false) return "omp-callback-tool-uncallable";
256
+
257
+ return null;
258
+ }
259
+
260
+ /** Repair text lives on the leaf that decides the predicate, so the sentence an operator reads
261
+ * cannot drift away from the check that produced it. */
262
+ export const OMP_PREFLIGHT_HINT: Record<OmpPreflightRejectReason, string> = {
263
+ "omp-agent-dir-ambiguous":
264
+ "an inherited PI_CODING_AGENT_DIR / PI_CONFIG_DIR / PI_PROFILE makes it ambiguous which agent directory omp would read (omp is a pi fork and shares those names) — unset it, or set ENTWURF_OMP_AGENT_DIR explicitly; guessing would preflight a directory no live omp reads",
265
+ "omp-birth-unit-missing":
266
+ "this host has no OMP birth extension, so the sibling would mint no record and its callback would carry no garden id — run `entwurf install-omp-bridge`",
267
+ "omp-mcp-hand-missing":
268
+ "this host has no entwurf-bridge server in omp's own mcp.json, so the callback tool would not exist in that session — run `entwurf install-omp-mcp`",
269
+ "omp-receive-unit-missing":
270
+ "this host has no OMP receiver extension, so the sibling could call home and nothing could ever be delivered to it — run `entwurf install-omp-receive`",
271
+ "omp-visible-identity-missing":
272
+ "omp's statusLine.showHookStatus is set to false, so the citizen's garden id would render nowhere on its own TUI — remove that setting from the omp config",
273
+ "omp-callback-tool-uncallable":
274
+ "omp's tools.xdev is not set to false, so MCP tools mount as xd:// devices whose schemas never reach the prompt and the model cannot call the callback tool — set `tools: xdev: false` in the omp agent config",
275
+ };