Skip to content

Commit acb8656

Browse files
committed
♻️ Compose the run profile's elicitation provider instead of flagging it (#607)
Review of 8b380b9: a trusted host profile must install Web elicitation directly, through lexical composition, rather than by handing the shared assembly a property to interpret. `DocumentMode.webElicitation` is gone, and `installDocumentComponents()` no longer installs an elicitation provider for any command — it neither receives nor reads a profile. `installWebComponents()` stays unconditional, so `<WebForm>` remains registered everywhere. Instead, each profile composes what it owns. `xmd run` installs `installWebElicitation()` in the scope it assembles around its own document, and the nested `host="run"` profile installs it in the isolated scope the harness gives a child — restated there rather than inherited, because a child of `xmd test` is still the run profile and its command composes none. `xmd test` and `xmd workflow` compose no elicitation provider at all, so the workflow attachment's suspending provider stays the only one a workflow document can reach. The behavior is the one 8b380b9 established and the four-profile table is unchanged; what moves is where the decision lives. Absence is now how a profile says it does not own the question, so there is no flag to read and no default to inherit. The subprocess regression is unchanged, and still fails on the defect: with `installWebElicitation()` moved back into the shared assembly, the case is abandoned at its deadline with the loopback form URL in its captured output.
1 parent 8b380b9 commit acb8656

2 files changed

Lines changed: 57 additions & 68 deletions

File tree

‎packages/cli/src/cli.ts‎

Lines changed: 45 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -572,18 +572,6 @@ interface DocumentConfig {
572572

573573
export interface DocumentMode {
574574
testing: boolean;
575-
/**
576-
* Whether this host profile answers `<Elicit>` with the browser form.
577-
*
578-
* Required, and stated by each trusted profile rather than derived from
579-
* `testing`: whether an execution activates the testing stack and whether
580-
* this host owns elicitation are two independent decisions, and a host that
581-
* already installed a provider of its own — a workflow attachment installs
582-
* the suspending one — must not have a second, nearer provider assembled
583-
* underneath it. Making it required is what keeps a profile added later from
584-
* inheriting the browser form by omission.
585-
*/
586-
webElicitation: boolean;
587575
agent?: AgentFlags;
588576
/**
589577
* What this host states about machine-wide agent sessions: who owns one,
@@ -640,21 +628,18 @@ export function* installDocumentComponents(mode: DocumentMode, verbose: boolean)
640628
// repository's own WebForm.md or WebForm.ts still wins.
641629
yield* installWebComponents();
642630

643-
// `<Elicit>` reaches a person through the same form — but only where the
644-
// profile said this host owns the question.
631+
// No elicitation provider is assembled here, for any command. Who answers
632+
// `<Elicit>` is not a property of the components a document runs with: it is
633+
// whichever host attached this run, and a host says so by installing its own
634+
// provider in the scope it composes around this one. `xmd run` and the nested
635+
// run profile install the browser form there; `xmd test` and `xmd workflow`
636+
// install nothing there, and the workflow attachment's suspending provider is
637+
// the only one a workflow document can reach.
645638
//
646-
// Under `xmd test` a document that elicits without supplying an answer would
647-
// open a browser and wait for somebody who is not coming, which is a hang
648-
// rather than a test result. Under `xmd workflow` the workflow attachment
649-
// already installed the suspending provider around this scope, and both are
650-
// installed `{ at: "min" }`, so a provider assembled here would be the nearer
651-
// one and would answer with a form the run has no reader for. Leaving it out
652-
// makes an unowned elicitation fail immediately with "no elicitation provider
653-
// configured", and an `<Answers>` region stays the way a document says what
654-
// the answer is.
655-
if (mode.webElicitation) {
656-
yield* installWebElicitation();
657-
}
639+
// Deciding it here instead would put the answer in the one assembly every
640+
// profile shares, where a provider is only ever a scope away from the wrong
641+
// run — and where the workflow's provider, installed further out, would lose
642+
// to it at the same `{ at: "min" }`.
658643

659644
// Agent flags are exclusive to `xmd run` — `xmd test` drives agents
660645
// through the deterministic TestAgent stack instead.
@@ -948,9 +933,7 @@ function* test(
948933
announceSecretDetection(config.secretDetection);
949934
const result = yield* runScopedDocument(
950935
{ ...config, root: { path } },
951-
// `xmd test` owns no elicitation: a document that asks without an
952-
// `<Answers>` region fails rather than opening a form nobody is at.
953-
{ testing: true, webElicitation: false },
936+
{ testing: true },
954937
installService,
955938
);
956939
if (!result.ok) {
@@ -990,7 +973,7 @@ function* test(
990973
root: { path: document.path },
991974
componentDir: componentSearchPath(document, target.root, config.componentDir),
992975
},
993-
{ testing: true, webElicitation: false },
976+
{ testing: true },
994977
installService,
995978
);
996979
if (!result.ok) {
@@ -1712,28 +1695,34 @@ function* dispatch(
17121695
}
17131696
const root = propsPhase.root;
17141697
announceSecretDetection(config.secretDetection);
1715-
const result = yield* runScopedDocument(
1716-
{ ...config, root, retainProcessOutput: keepsProcessOutput(config.journal) },
1717-
{
1718-
testing: false,
1719-
// `xmd run` is the command a person is sitting in front of, so it is
1720-
// the one that may ask them through the browser form.
1721-
webElicitation: true,
1722-
props: props.value,
1723-
// Only `xmd run` receives it. Every other command assembles none of
1724-
// it, which is what keeps a machine session from being acted on by a
1725-
// command that never said it could own one.
1726-
...(sessions === undefined ? {} : { machineSessions: sessions }),
1727-
agent: {
1728-
agentProvider: config.agentProvider,
1729-
defaultAgent: config.defaultAgent,
1730-
approveAll: config.approveAll,
1731-
approveReads: config.approveReads,
1732-
denyAll: config.denyAll,
1698+
const result = yield* scoped(function* (): Operation<Result<void>> {
1699+
// `<Elicit>` reaches a person through the browser form, and `xmd run`
1700+
// is the command a person is sitting in front of. Composed here, in the
1701+
// scope this profile assembles around its own document, because that is
1702+
// what owning the question *is*: a host that answers installs a
1703+
// provider, and one that does not installs none. Nothing downstream
1704+
// reads a profile, so nothing downstream can read one wrong.
1705+
yield* installWebElicitation();
1706+
return yield* runScopedDocument(
1707+
{ ...config, root, retainProcessOutput: keepsProcessOutput(config.journal) },
1708+
{
1709+
testing: false,
1710+
props: props.value,
1711+
// Only `xmd run` receives it. Every other command assembles none of
1712+
// it, which is what keeps a machine session from being acted on by
1713+
// a command that never said it could own one.
1714+
...(sessions === undefined ? {} : { machineSessions: sessions }),
1715+
agent: {
1716+
agentProvider: config.agentProvider,
1717+
defaultAgent: config.defaultAgent,
1718+
approveAll: config.approveAll,
1719+
approveReads: config.approveReads,
1720+
denyAll: config.denyAll,
1721+
},
17331722
},
1734-
},
1735-
installService,
1736-
);
1723+
installService,
1724+
);
1725+
});
17371726
if (!result.ok) {
17381727
// The document is reread between preparation and execution, so the
17391728
// exact target this run decided on can be gone by the time it runs.
@@ -1855,17 +1844,11 @@ function* dispatch(
18551844
// already produced; the fork's own execution renders it again.
18561845
...(execution.discardOutput === true ? { discardOutput: true } : {}),
18571846
},
1858-
{
1859-
testing: false,
1860-
// The workflow host attached this execution and installed the
1861-
// suspending provider around it. A browser form assembled here
1862-
// would sit nearer and answer first, and a workflow's question is
1863-
// answered by `xmd workflow answer`, not by a reader who would
1864-
// have to still be at the terminal when the run reaches it.
1865-
webElicitation: false,
1866-
props: execution.props,
1867-
installations: execution.installations,
1868-
},
1847+
// No elicitation provider is composed around this document. The
1848+
// workflow host attached the execution and installed the suspending
1849+
// one already; a browser form here would sit nearer, answer first,
1850+
// and wait for a reader the run has no way to reach.
1851+
{ testing: false, props: execution.props, installations: execution.installations },
18691852
// The workflow authority boundary sits exactly where a host
18701853
// service adapter would: installed inside the execution scope,
18711854
// before the root document is imported.

‎packages/cli/src/testing-host.ts‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
* of `xmd run` that nothing ships.
1010
*
1111
* So a child gets what `xmd run` gets, after the command line has been read:
12-
* the same components (`installDocumentComponents`), the same native service
13-
* adapter this entrypoint installs, the same root loader and target resolver,
14-
* and the same `executeInstalled()` call. What it does not get is process
12+
* the same components (`installDocumentComponents`), the same browser-form
13+
* elicitation provider, the same native service adapter this entrypoint
14+
* installs, the same root loader and target resolver, and the same
15+
* `executeInstalled()` call. What it does not get is process
1516
* presentation — no journal file, no `--verbose` echo, no terminal formatting,
1617
* no stdout of its own. Its rendered output goes back to the document that ran
1718
* it, which is the only reader it has.
@@ -25,6 +26,7 @@ import { InMemoryStream } from "@executablemd/durable-streams";
2526
import type { DurableEvent } from "@executablemd/durable-streams";
2627
import { forEach } from "@effectionx/stream-helpers";
2728
import { useHostFiles } from "@executablemd/runtime";
29+
import { installWebElicitation } from "@executablemd/web";
2830
import type { Operation } from "effection";
2931
import { fileSource, inlineSource } from "@executablemd/core";
3032
import type { RootDocumentSource } from "@executablemd/core";
@@ -93,9 +95,13 @@ function* runProfileChild(
9395
const diagnostic = request.journal === "diagnostic";
9496
const stream = new InMemoryStream();
9597

96-
// A child gets what `xmd run` gets, and the browser form is part of that:
97-
// this profile *is* the run profile, so it states the run profile's answer.
98-
yield* installDocumentComponents({ testing: false, webElicitation: true }, false);
98+
yield* installDocumentComponents({ testing: false }, false);
99+
// A child gets what `xmd run` gets, and the browser form is part of that.
100+
// Installed here rather than inherited: this scope is isolated from the
101+
// command that started it, so the run profile's provider reaches a child only
102+
// if the run profile composes it — and a child of `xmd test`, whose command
103+
// composes none, still gets one because *this* is the run profile.
104+
yield* installWebElicitation();
99105
// Document filesystem access resolves in the caller's own filesystem, as it
100106
// does for `xmd run`. The entrypoint installs its provider process-wide, but
101107
// the child runs in an isolated scope, so the child's assembly must restate

0 commit comments

Comments
 (0)