Add xmd prompt: turn a request into an approved executable Plan #260

Description

@taras

Motivation

xmd prompt turns steps into a program

This document is a workflow that generates an executable Plan from a sequence of steps. It combines the original Prompt, which describes those steps, with the XMD components available to carry them out. A coding agent turns both into one document that explains and executes the sequence.

The result is the XMD version of a coding agent’s plan. A conventional Markdown plan must be interpreted again before its steps can happen. An XMD Plan already contains those executable steps, so running it simply executes them.

A draft remains text while this workflow reviews it. Nothing in it runs before you approve it. After approval, xmd prompt validates the exact source again. By default it prints the approved XMD source. --output writes that source to a file instead, and --run executes the Plan. With both options, the command writes the source before running it.

xmd prompt "ask me for my age and write it to a file"

xmd run -e executes a program someone already wrote. xmd prompt performs the preceding conversion and review. It adds no second execution model.

Terminology

These terms are used precisely:

  • A Prompt is the person’s original natural-language request.
  • A Plan is the executable XMD program produced from that Prompt.
  • A Plan combines reader-facing prose expressing the Prompt’s intent with the XMD components that carry it out.
  • xmd prompt converts a Prompt into an approved Plan.
  • The prompt command document is the packaged Markdown workflow that performs generation, checking, review, revision, approval, stopping, explanation, and exhaustion. It is not itself a Plan.
  • The prompt profile is the constrained trusted-host context under which that document runs.
  • A draft is candidate Plan source that has not been approved. It remains inert text.

“Plan” is not a generic synonym for a workflow, policy document, command implementation, arbitrary XMD document, or the packaged prompt command document.

The reusable or custom <Plan> surface remains separate in #660.

Architecture

The trusted host owns two root executions with complete teardown between them:

fixed command preflight
-> build the run-profile syntax catalog
-> execute the exact packaged prompt command document
-> one enclosing Session
-> draft, check, repair, review, revise, approve, stop, explain, or exhaust
-> Return the exact approved Plan source
-> await prompt-profile execution and complete provider teardown
-> admit the returned source again
-> perform exactly the selected output mode:
-> print the exact source; or
-> exclusively create an output file; or
-> execute through the ordinary supplied-source path; or
-> create the output file and then execute

The packaged Markdown owns:

  • drafting;
  • repair;
  • diagnostic presentation;
  • review;
  • revision;
  • approval;
  • stopping;
  • final-invalid explanation;
  • authored failure; and
  • finite exhaustion.

Trusted TypeScript owns:

  • fixed command parsing and preflight;
  • prompt-profile assembly;
  • syntax-catalog construction;
  • property-source parsing and frozen option signatures;
  • non-executing draft checking;
  • complete prompt-profile teardown;
  • final admission;
  • byte-exact stdout;
  • exclusive output-file creation; and
  • ordinary supplied-source execution.

No drafting, retry, review, revision, explanation, or exhaustion policy belongs in TypeScript, <Prompt>, or the Agent API.

Command surface

xmd prompt <Prompt> [--output <path>] [--run] [--session <name>] \ [shared options] [--props-<name> <value>]…

The Prompt is exactly one positional string containing at least one non-whitespace character. Missing, repeated, empty, and whitespace-only Prompts fail during fixed preflight.

-- ends option parsing, allowing a dash-leading Prompt.

The command adds:

  • --output <path> — exclusively create a file containing the exact approved source;
  • --run — execute the approved Plan after final admission and any requested output-file creation;
  • --session <name> — replace the invocation-unique authorship session name with a non-empty explicit name.

The unreleased --save spelling is removed. It has no compatibility alias.

-e and --eval remain exclusive to xmd run.

Property arguments

The non-empty Prompt must appear before every individual --props-* option. An individual property option before the Prompt is refused during fixed preflight.

Known fixed-arity options, including aggregate --props, may appear before the Prompt.

For every initial or revised draft, the host:

  1. inspects the root declaration without execution;
  2. derives property bindings from the original CLI and invocation-environment sources;
  3. checks the frozen signatures of supplied individual options;
  4. resolves those sources against the draft’s schema; and
  5. checks the draft with the resolved props.

Candidate-versus-caller failure classification and frozen property signatures remain unchanged.

Shared option roles

These options remain meaningful without --run because they participate in authorship, catalog construction, property admission, output selection, or the whole-command deadline:

  • --output;
  • --session;
  • --include;
  • --props and declared individual --props-* options;
  • --agent-provider;
  • --default-agent; and
  • --timeout.

The following options configure only final Plan execution and are refused during fixed preflight unless --run is present:

  • --verbose / -V;
  • --journal / -j;
  • --raw;
  • --timeout-exec;
  • --timeout-fetch;
  • --approve-all;
  • --approve-reads;
  • --deny-all;
  • --secret-detection; and
  • --no-secret-detection.

Final-run permission flags cannot widen the prompt profile.

Help

xmd prompt --help is generic and effect-free. It documents:

  • the Prompt positional;
  • default byte-exact source output;
  • --output;
  • --run;
  • --session;
  • aggregate props;
  • the individual-property ordering rule;
  • shared authorship and admission options; and
  • which final-run options require --run.

Help does not generate individual property options and does not:

  • load the packaged prompt command document;
  • build a syntax catalog;
  • inspect a generated document;
  • start an Agent;
  • construct a prompt profile;
  • elicit an answer;
  • create a file or journal; or
  • execute a Plan.

A complete Plan

A produced Plan begins, after optional frontmatter, with one descriptive level-one Markdown heading as its first body content.

The Plan then preserves:

  • the Prompt’s sequence of readable steps;
  • every requested outcome;
  • meaningful ordering between those outcomes;
  • reader-facing prose; and
  • the XMD components beside the steps they perform.

For example:

# Ask for an age and save it
Ask me for my age.
<Elicit ... as="result" />
Write it to a file.
<Filepath="age.txt">{result.age}</File>

The Prompt need not be quoted literally. It may be divided, clarified, and rewritten as natural prose. The resulting Plan must remain understandable in the same order in which its actions execute.

The descriptive H1 and narrative-plus-components form are enforced through the initial, repair, and revision instructions and through human review. They are not hidden checks in TypeScript or validateDocument().

The packaged prompt command document

The host executes one exact checked-in Markdown value root, packaged as prompt-command.md, under the stable internal source identity <prompt-command>.

Its declared return schema is exactly:

{ "type": "string" }

The host supplies these internal inputs:

  • the original Prompt;
  • the rendered run-profile syntax catalog;
  • the resolved logical session name.

They are not Plan root props and consume none of the Plan’s property sources.

The document begins with the approved introduction in this issue and uses these visible stage headings:

## Create the first draft## Check and repair the draft## Review the draft## Continue from your decision## Return the approved Plan

Stable explanations remain outside repeated loops where possible. The command document does not expose internal <Return> failure precedence to the user.

<Return> is internal control flow. It transfers the exact approved source from the command document to the trusted host and does not print that source.

Authorship Agent and Session

One enclosing <Session> expansion carries every Agent turn:

  • the initial draft;
  • automatic repairs;
  • human-requested revisions; and
  • the optional final explanation.

Sibling Sessions are not used. The same authored name on sibling Sessions would still represent distinct placements.

Without --session, the host generates an invocation-unique logical name. With --session <name>, the exact non-empty name replaces it. The default and named session-directory identities, preparation rules, cleanup rules, and continuation behavior remain unchanged.

The prompt profile gives the authorship Agent:

  • its session-specific host-owned directory;
  • no additional directories;
  • no MCP servers;
  • an empty native-tool allowlist;
  • strict denial of every native permission request; and
  • no document Files, command, service, or XMD-mediated network authority.

The provider’s own model transport does not grant the Agent a native network tool.

The host instruction layer establishes authority and common context. It does not require every Agent answer to be XMD source.

Each authored <Prompt> owns its own response contract:

  • initial, repair, and revision turns request one complete replacement Plan as source only;
  • the final explanation turn requests explanatory prose only.

A failed, cancelled, unavailable, or protocol-invalid Agent turn is terminal. Partial text never becomes a draft or explanation.

Drafts remain inert

Every Agent reply remains an inert string throughout prompt-profile execution.

The command document may:

  • bind the string;
  • pass it to <CheckDraft>;
  • present it through <CodeBlock>;
  • pass diagnostics into another Agent turn;
  • retain it as the approved value; or
  • return it to the host.

It never evaluates, imports, or executes a draft.

Only the exact approved source may proceed, and only after complete prompt-profile teardown and final host admission.

Internal draft checking

The prompt profile declares one protected internal value component:

<CheckDraftsource={draft}as="assessment" />

Repository component lookup cannot replace it.

<CheckDraft> checks an unapproved draft without executing it. Its behavior is the behavior previously assigned to the internal <ValidateCandidate> name.

For each draft it:

  1. checks the supplied root declaration without execution;
  2. derives bindings once a usable root property schema exists;
  3. verifies every frozen supplied individual-option signature before consuming tokens;
  4. resolves the original CLI and invocation-environment property sources; and
  5. calls core’s validateDocument() with those props, the caller’s includes, and the run-profile declarations.

Core’s validateDocument() keeps its existing name. This issue introduces no generic public <Validate> component.

Draft-authored failures return structured problems eligible for repair, including:

  • source and frontmatter failures;
  • invalid root props or return declarations;
  • binding collisions;
  • missing required props; and
  • other definite whole-document diagnostics.

Caller-authored failures raise terminally, including:

  • malformed aggregate CLI or environment JSON;
  • a supplied individual option not declared by the usable draft schema;
  • a malformed individual value;
  • an extra positional exposed by the draft’s arity; and
  • a later schema removing a frozen option or changing its arity or accumulation behavior.

Caller-authored failures cause no repair, presentation, approval, output, journal, or execution.

<CheckDraft> reports structural facts only. It does not decide whether the H1 or prose adequately communicates the Prompt.

Create, check, and repair a draft

The first draft instruction requires:

  • one complete replacement root as source only;
  • optional frontmatter followed immediately by one descriptive H1;
  • the Prompt’s complete sequence as readable prose;
  • every requested outcome;
  • meaningful ordering; and
  • each XMD component beside the prose describing its action.

Each initial draft and each human-requested revision receives its own automatic repair budget:

  • the base draft is attempt one;
  • at most three repair turns may replace it;
  • every repair prompt contains the complete structured draft diagnostics;
  • every repair response is one complete replacement root; and
  • repair instructions repeat the complete Plan requirements, including the descriptive H1.

The fourth invalid draft is repair-exhausted and proceeds to human review with its diagnostics.

No fence is stripped, Markdown substring extracted, or patch applied.

Human review

The command document permits at most ten draft presentations.

The exact Elicitation values are:

  • Approve
  • Request changes
  • Stop
  • Explain what went wrong

The offered decision set depends on validity and round:

Review stateOffered values
Valid, rounds 1–9Approve, Request changes, Stop
Invalid, rounds 1–9Request changes, Stop
Valid, round 10Approve, Stop
Invalid, round 10Explain what went wrong, Stop

Request changes requires non-empty feedback. It sends one complete-replacement revision request through the same enclosing Session and resets the automatic repair budget.

Revision instructions repeat the descriptive-H1 and narrative-plus-components requirements.

The review presents the exact draft through <CodeBlock>. Invalid reviews also present the complete structured diagnostics. Draft text cannot close the presentation fence and is never interpreted.

Approve binds the exact draft for return. It does not execute or print the draft.

Explanation after the final invalid draft

When the tenth presented draft is invalid, the person may select Explain what went wrong.

That choice:

  1. makes one final <Prompt> turn in the same enclosing Session;
  2. is not another draft, repair, revision, or review round;
  3. relies on the Session’s existing conversation history;
  4. supplies the final diagnostics, which the Agent has not previously seen;
  5. asks why the attempts failed and what the person should clarify next time;
  6. requests explanatory prose rather than document source;
  7. treats the answer as inert text;
  8. cannot return to drafting or approval; and
  9. ends without source output, file output, journal, or Plan execution.

The explanation prompt supplies no draft, Prompt, catalog, or prior diagnostics again. Those remain available only through the existing Session history. Its new contextual data is the final diagnostics.

A failed explanation turn is terminal.

A successful explanation is reported through the command’s ordinary terminal failure reporting as the authored failure message. It is not written to source stdout and is not interpreted as XMD. The command exits nonzero because no Plan was approved.

No TypeScript or Agent API behavior implements this branch.

Command-document history and presentation

The prompt command document uses an invocation-owned in-memory durable stream because ordinary document and <Prompt> semantics require one.

That stream is:

  • never written to --journal;
  • never persisted as a workflow;
  • never reused or replayed; and
  • discarded after complete prompt-profile teardown.

The configured Agent provider may retain the named Session under its ordinary provider contract.

Command-document rendering is not successful CLI source output. Successful source output is written by the trusted host only after teardown and final admission.

Final admission

After the command document returns and its entire prompt-profile scope tears down successfully, the host treats the approved source as untrusted again.

The host repeats checking and property resolution using:

  • the exact returned bytes;
  • the original raw CLI and invocation-environment property sources;
  • the frozen individual-option signatures;
  • the caller’s ordered includes; and
  • the ordinary run-profile declarations.

A final caller-source failure or document failure exits nonzero. It does not re-enter drafting or review.

The resolved props belong to the exact approved bytes. No props object from an earlier draft is reused.

No stdout source, output file, journal, or Plan execution begins before this admission succeeds.

The approved source is the CLI result

The exact approved source is the primary result of xmd prompt.

Default: print the source

xmd prompt "<Prompt>"

After teardown and final admission, the host writes the exact approved source to stdout.

It adds no fence, label, delimiter, or newline. It does not execute the Plan or create a generated-source file.

Write the source

xmd prompt "<Prompt>" --output <path>

After teardown and final admission, the host exclusively creates <path> with the exact approved bytes.

An existing target remains unchanged and fails the command. The command writes nothing to stdout and does not execute the Plan.

Run the Plan

xmd prompt "<Prompt>" --run

After teardown and final admission, the host executes:

retainedSource("<prompt>", source)

through the ordinary supplied-source path.

The host does not print the source. Stdout belongs exclusively to the Plan’s ordinary output.

Write, then run

xmd prompt "<Prompt>" --output <path> --run

After teardown and final admission, the host exclusively creates the file first.

Execution begins only if file creation succeeds. An existing target or other write failure leaves the target unchanged where applicable and prevents execution.

The host does not print the source. Stdout belongs exclusively to the Plan.

A runtime failure does not return to authorship. A successfully created output file remains.

Journal behavior

Authorship never writes the final journal.

A diagnostic journal may be created only when:

  • --run is present;
  • --journal <path> is present; and
  • final Plan execution is beginning.

Default source output and output-only mode create no journal.

The final journal contains no prompt command document, authorship Session, Agent turn, draft check, repair, human review, explanation, or approval event.

Authored failures

PathAuthored failure
Ordinary Stopxmd prompt stopped at your request. Nothing was output or run.
Stop on the final invalid draftxmd prompt reviewed ten drafts without an approved Plan. Nothing was output or run.
Unexpected post-Session fallback without approvalxmd prompt ended without an approved Plan. Nothing was output or run.
Successful final explanationThe coding agent’s explanation is the authored terminal failure message; no generic advice replaces it

An ordinary Stop includes stopping a valid tenth draft.

The final-invalid Stop is distinct from the explanation choice. It reports exhaustion without spending another Agent turn.

All authored failures are selected by the Markdown command document. They exit nonzero and produce no approved-source stdout, output file, final journal, or execution.

Cancellation and failure ordering

The whole-command deadline encloses:

  • fixed preparation after argument admission;
  • catalog construction;
  • prompt-profile execution;
  • Elicitation;
  • explanation when selected;
  • profile teardown;
  • final admission;
  • source output or exclusive file creation; and
  • final execution when requested.

Cancellation stops active authorship and awaits structured teardown.

No final admission or output mode begins until prompt-profile execution and teardown both succeed. A teardown failure wins over an approved source.

Once ordinary Plan execution begins, its existing outcome and teardown precedence apply unchanged.

Acceptance matrix

The amended evidence replaces the superseded TypeScript-policy matrix.

IDBoundaryRequired evidence
P1Fixed grammarExactly one non-empty Prompt; individual --props-* options require the Prompt first; aggregate props retain ordinary placement
P2Effect-free helpGeneric help documents default output, --output, --run, --session, property ordering, and run-only flags without loading the packaged document or performing effects
P3Packaged command documentThe package-relative prompt-command.md is the exact root executed under <prompt-command> and cannot be replaced through component lookup
P4Approved document languageThe shipped document contains the approved introduction and the five visible stage headings
P5Complete Plan instructionsInitial, repair, and revision prompts require optional frontmatter followed by a descriptive H1, readable ordered steps, and components beside their prose
P6One SessionInitial drafting, repairs, revisions, and final explanation use one enclosing Session; default names differ and --session supplies the exact override
P7Prompt-profile authorityThe authorship Agent receives only the settled session directory and constrained authority; final-run flags cannot widen it
P8Draft inertnessNo draft is imported, evaluated, journaled as the final Plan, saved, printed as success, or executed before approval
P9Protected checker<CheckDraft> is the protected host-declared capability, repository lookup cannot replace it, and <ValidateCandidate> is absent
P10Failure classificationDraft-authored problems return structured facts; caller-authored failures escape terminally; frozen property signatures are checked before token consumption
P11Repair budgetEach base draft receives at most three repair turns; a human revision resets that budget
P12Friendly review valuesThe exact values and per-round decision sets are Approve, Request changes, Stop, and final-invalid-only Explain what went wrong
P13Revision feedbackRequest changes requires non-empty feedback and requests a complete replacement Plan preserving the H1 and narrative requirements
P14Final explanationFinal-invalid explanation makes exactly one additional <Prompt> turn in the same Session and supplies only the previously unseen final diagnostics as new context
P15Explanation is terminalExplanation cannot trigger checking, repair, presentation, revision, approval, or another Agent turn; its inert answer is reported and the command ends without a Plan
P16Authored stoppingOrdinary Stop, final-invalid Stop, unexpected fallback, and explanation use authored Markdown failure paths with the required messages or explanation
P17Final gateComplete prompt-profile teardown and final admission precede every successful output mode
P18Default stdoutDefault success writes the exact approved bytes to stdout with no fence, label, delimiter, or added newline and performs no execution
P19--outputOutput-only success exclusively creates a byte-identical file, writes no stdout, and performs no execution
P20Explicit --runPlan execution occurs only with --run, through the ordinary supplied-source path
P21Write before runWith --output --run, byte-identical exclusive creation completes before execution; write refusal prevents execution
P22Stdout ownershipSource bytes and runtime output never share stdout: default owns source stdout; run modes leave stdout entirely to the Plan
P23Run-only preflightEvery explicitly supplied run-only flag is refused before catalog or Agent work unless --run is present
P24Journal separationNo journal file is created without final execution; a requested journal begins only when --run starts and contains no authorship activity
P25Session-directory lifetimeInvocation-unique cleanup and named-directory preservation remain exactly as specified, with no recursive deletion
P26Exact bytes and propsApproval, final admission, stdout, --output, and execution use the exact returned bytes; final props are resolved for those bytes
P27Ordinary run behavior--run preserves ordinary cwd, includes, props, Agent configuration, permissions, timeouts, output, value, failures, and exit behavior
P28Teardown and cancellationCancellation and every teardown failure settle before final admission, source output, file output, journal creation, or execution

Use one discriminating regression for each distinct boundary. Do not restore permutations that existed only to prove the superseded TypeScript policy loop.

Dependencies and delivery

Delivered foundations remain:

PR #657 remains the focused implementation vehicle. Its issue #260 delivery includes:

  • rename the packaged asset to prompt-command.md;
  • rename PROMPT_PLAN and related source/test vocabulary to PROMPT_COMMAND;
  • install the approved introduction and visible stage headings;
  • strengthen initial, repair, and revision instructions with the complete Plan requirement;
  • rename the protected internal checker to <CheckDraft>;
  • install the exact friendly review values and round-specific decision sets;
  • add the final same-Session explanation branch;
  • remove any host instruction requiring every Agent response to be source;
  • replace --save with --output, without an alias;
  • make byte-exact stdout the default result;
  • require --run for execution;
  • enforce run-only option preflight;
  • preserve final admission and complete teardown before every output mode;
  • preserve output-file-before-run ordering;
  • keep source stdout separate from Plan stdout;
  • create a journal only when final execution begins;
  • update architecture.md;
  • rewrite specs/prompt-command-spec.md;
  • update the affected prompt-command, Agent-provider, property-binding, CLI, and Tier PR sections of the specifications; and
  • add the revised acceptance evidence.

The architecture review of feedback commit 1e449879c04e7c458ff6738ae13c2da8abb290dd is not reopened by this amendment. The next feedback commit is reviewed against this amended contract.

Out of scope

  • arbitrary custom prompt command documents;
  • public or reusable <Plan>;
  • --plan and --plan-eval;
  • File or Glob authorship context;
  • a generic public <Validate>;
  • a general arbitrary-code sandbox;
  • the collaborative playground;
  • stdin or editor Prompt input;
  • automatic revision after runtime failure;
  • a terminal Elicitation provider; and
  • durable journaling or workflow replay of authorship.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      , 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
       blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
      }
      } catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
      })();
      (function(){
      try {
      var __m = "github.com";
      var __re = new RegExp('^' + "github\\.com" + '
      
      Skip to content

      Add xmd prompt: turn a request into an approved executable Plan #260

      Description

      @taras

      Motivation

      xmd prompt turns steps into a program

      This document is a workflow that generates an executable Plan from a sequence of steps. It combines the original Prompt, which describes those steps, with the XMD components available to carry them out. A coding agent turns both into one document that explains and executes the sequence.

      The result is the XMD version of a coding agent’s plan. A conventional Markdown plan must be interpreted again before its steps can happen. An XMD Plan already contains those executable steps, so running it simply executes them.

      A draft remains text while this workflow reviews it. Nothing in it runs before you approve it. After approval, xmd prompt validates the exact source again. By default it prints the approved XMD source. --output writes that source to a file instead, and --run executes the Plan. With both options, the command writes the source before running it.

      xmd prompt "ask me for my age and write it to a file"

      xmd run -e executes a program someone already wrote. xmd prompt performs the preceding conversion and review. It adds no second execution model.

      Terminology

      These terms are used precisely:

      • A Prompt is the person’s original natural-language request.
      • A Plan is the executable XMD program produced from that Prompt.
      • A Plan combines reader-facing prose expressing the Prompt’s intent with the XMD components that carry it out.
      • xmd prompt converts a Prompt into an approved Plan.
      • The prompt command document is the packaged Markdown workflow that performs generation, checking, review, revision, approval, stopping, explanation, and exhaustion. It is not itself a Plan.
      • The prompt profile is the constrained trusted-host context under which that document runs.
      • A draft is candidate Plan source that has not been approved. It remains inert text.

      “Plan” is not a generic synonym for a workflow, policy document, command implementation, arbitrary XMD document, or the packaged prompt command document.

      The reusable or custom <Plan> surface remains separate in #660.

      Architecture

      The trusted host owns two root executions with complete teardown between them:

      fixed command preflight
      -> build the run-profile syntax catalog
      -> execute the exact packaged prompt command document
      -> one enclosing Session
      -> draft, check, repair, review, revise, approve, stop, explain, or exhaust
      -> Return the exact approved Plan source
      -> await prompt-profile execution and complete provider teardown
      -> admit the returned source again
      -> perform exactly the selected output mode:
      -> print the exact source; or
      -> exclusively create an output file; or
      -> execute through the ordinary supplied-source path; or
      -> create the output file and then execute
      

      The packaged Markdown owns:

      • drafting;
      • repair;
      • diagnostic presentation;
      • review;
      • revision;
      • approval;
      • stopping;
      • final-invalid explanation;
      • authored failure; and
      • finite exhaustion.

      Trusted TypeScript owns:

      • fixed command parsing and preflight;
      • prompt-profile assembly;
      • syntax-catalog construction;
      • property-source parsing and frozen option signatures;
      • non-executing draft checking;
      • complete prompt-profile teardown;
      • final admission;
      • byte-exact stdout;
      • exclusive output-file creation; and
      • ordinary supplied-source execution.

      No drafting, retry, review, revision, explanation, or exhaustion policy belongs in TypeScript, <Prompt>, or the Agent API.

      Command surface

      xmd prompt <Prompt> [--output <path>] [--run] [--session <name>] \ [shared options] [--props-<name> <value>]…

      The Prompt is exactly one positional string containing at least one non-whitespace character. Missing, repeated, empty, and whitespace-only Prompts fail during fixed preflight.

      -- ends option parsing, allowing a dash-leading Prompt.

      The command adds:

      • --output <path> — exclusively create a file containing the exact approved source;
      • --run — execute the approved Plan after final admission and any requested output-file creation;
      • --session <name> — replace the invocation-unique authorship session name with a non-empty explicit name.

      The unreleased --save spelling is removed. It has no compatibility alias.

      -e and --eval remain exclusive to xmd run.

      Property arguments

      The non-empty Prompt must appear before every individual --props-* option. An individual property option before the Prompt is refused during fixed preflight.

      Known fixed-arity options, including aggregate --props, may appear before the Prompt.

      For every initial or revised draft, the host:

      1. inspects the root declaration without execution;
      2. derives property bindings from the original CLI and invocation-environment sources;
      3. checks the frozen signatures of supplied individual options;
      4. resolves those sources against the draft’s schema; and
      5. checks the draft with the resolved props.

      Candidate-versus-caller failure classification and frozen property signatures remain unchanged.

      Shared option roles

      These options remain meaningful without --run because they participate in authorship, catalog construction, property admission, output selection, or the whole-command deadline:

      • --output;
      • --session;
      • --include;
      • --props and declared individual --props-* options;
      • --agent-provider;
      • --default-agent; and
      • --timeout.

      The following options configure only final Plan execution and are refused during fixed preflight unless --run is present:

      • --verbose / -V;
      • --journal / -j;
      • --raw;
      • --timeout-exec;
      • --timeout-fetch;
      • --approve-all;
      • --approve-reads;
      • --deny-all;
      • --secret-detection; and
      • --no-secret-detection.

      Final-run permission flags cannot widen the prompt profile.

      Help

      xmd prompt --help is generic and effect-free. It documents:

      • the Prompt positional;
      • default byte-exact source output;
      • --output;
      • --run;
      • --session;
      • aggregate props;
      • the individual-property ordering rule;
      • shared authorship and admission options; and
      • which final-run options require --run.

      Help does not generate individual property options and does not:

      • load the packaged prompt command document;
      • build a syntax catalog;
      • inspect a generated document;
      • start an Agent;
      • construct a prompt profile;
      • elicit an answer;
      • create a file or journal; or
      • execute a Plan.

      A complete Plan

      A produced Plan begins, after optional frontmatter, with one descriptive level-one Markdown heading as its first body content.

      The Plan then preserves:

      • the Prompt’s sequence of readable steps;
      • every requested outcome;
      • meaningful ordering between those outcomes;
      • reader-facing prose; and
      • the XMD components beside the steps they perform.

      For example:

      # Ask for an age and save it
      Ask me for my age.
      <Elicit ... as="result" />
      Write it to a file.
      <Filepath="age.txt">{result.age}</File>

      The Prompt need not be quoted literally. It may be divided, clarified, and rewritten as natural prose. The resulting Plan must remain understandable in the same order in which its actions execute.

      The descriptive H1 and narrative-plus-components form are enforced through the initial, repair, and revision instructions and through human review. They are not hidden checks in TypeScript or validateDocument().

      The packaged prompt command document

      The host executes one exact checked-in Markdown value root, packaged as prompt-command.md, under the stable internal source identity <prompt-command>.

      Its declared return schema is exactly:

      { "type": "string" }

      The host supplies these internal inputs:

      • the original Prompt;
      • the rendered run-profile syntax catalog;
      • the resolved logical session name.

      They are not Plan root props and consume none of the Plan’s property sources.

      The document begins with the approved introduction in this issue and uses these visible stage headings:

      ## Create the first draft## Check and repair the draft## Review the draft## Continue from your decision## Return the approved Plan

      Stable explanations remain outside repeated loops where possible. The command document does not expose internal <Return> failure precedence to the user.

      <Return> is internal control flow. It transfers the exact approved source from the command document to the trusted host and does not print that source.

      Authorship Agent and Session

      One enclosing <Session> expansion carries every Agent turn:

      • the initial draft;
      • automatic repairs;
      • human-requested revisions; and
      • the optional final explanation.

      Sibling Sessions are not used. The same authored name on sibling Sessions would still represent distinct placements.

      Without --session, the host generates an invocation-unique logical name. With --session <name>, the exact non-empty name replaces it. The default and named session-directory identities, preparation rules, cleanup rules, and continuation behavior remain unchanged.

      The prompt profile gives the authorship Agent:

      • its session-specific host-owned directory;
      • no additional directories;
      • no MCP servers;
      • an empty native-tool allowlist;
      • strict denial of every native permission request; and
      • no document Files, command, service, or XMD-mediated network authority.

      The provider’s own model transport does not grant the Agent a native network tool.

      The host instruction layer establishes authority and common context. It does not require every Agent answer to be XMD source.

      Each authored <Prompt> owns its own response contract:

      • initial, repair, and revision turns request one complete replacement Plan as source only;
      • the final explanation turn requests explanatory prose only.

      A failed, cancelled, unavailable, or protocol-invalid Agent turn is terminal. Partial text never becomes a draft or explanation.

      Drafts remain inert

      Every Agent reply remains an inert string throughout prompt-profile execution.

      The command document may:

      • bind the string;
      • pass it to <CheckDraft>;
      • present it through <CodeBlock>;
      • pass diagnostics into another Agent turn;
      • retain it as the approved value; or
      • return it to the host.

      It never evaluates, imports, or executes a draft.

      Only the exact approved source may proceed, and only after complete prompt-profile teardown and final host admission.

      Internal draft checking

      The prompt profile declares one protected internal value component:

      <CheckDraftsource={draft}as="assessment" />

      Repository component lookup cannot replace it.

      <CheckDraft> checks an unapproved draft without executing it. Its behavior is the behavior previously assigned to the internal <ValidateCandidate> name.

      For each draft it:

      1. checks the supplied root declaration without execution;
      2. derives bindings once a usable root property schema exists;
      3. verifies every frozen supplied individual-option signature before consuming tokens;
      4. resolves the original CLI and invocation-environment property sources; and
      5. calls core’s validateDocument() with those props, the caller’s includes, and the run-profile declarations.

      Core’s validateDocument() keeps its existing name. This issue introduces no generic public <Validate> component.

      Draft-authored failures return structured problems eligible for repair, including:

      • source and frontmatter failures;
      • invalid root props or return declarations;
      • binding collisions;
      • missing required props; and
      • other definite whole-document diagnostics.

      Caller-authored failures raise terminally, including:

      • malformed aggregate CLI or environment JSON;
      • a supplied individual option not declared by the usable draft schema;
      • a malformed individual value;
      • an extra positional exposed by the draft’s arity; and
      • a later schema removing a frozen option or changing its arity or accumulation behavior.

      Caller-authored failures cause no repair, presentation, approval, output, journal, or execution.

      <CheckDraft> reports structural facts only. It does not decide whether the H1 or prose adequately communicates the Prompt.

      Create, check, and repair a draft

      The first draft instruction requires:

      • one complete replacement root as source only;
      • optional frontmatter followed immediately by one descriptive H1;
      • the Prompt’s complete sequence as readable prose;
      • every requested outcome;
      • meaningful ordering; and
      • each XMD component beside the prose describing its action.

      Each initial draft and each human-requested revision receives its own automatic repair budget:

      • the base draft is attempt one;
      • at most three repair turns may replace it;
      • every repair prompt contains the complete structured draft diagnostics;
      • every repair response is one complete replacement root; and
      • repair instructions repeat the complete Plan requirements, including the descriptive H1.

      The fourth invalid draft is repair-exhausted and proceeds to human review with its diagnostics.

      No fence is stripped, Markdown substring extracted, or patch applied.

      Human review

      The command document permits at most ten draft presentations.

      The exact Elicitation values are:

      • Approve
      • Request changes
      • Stop
      • Explain what went wrong

      The offered decision set depends on validity and round:

      Review stateOffered values
      Valid, rounds 1–9Approve, Request changes, Stop
      Invalid, rounds 1–9Request changes, Stop
      Valid, round 10Approve, Stop
      Invalid, round 10Explain what went wrong, Stop

      Request changes requires non-empty feedback. It sends one complete-replacement revision request through the same enclosing Session and resets the automatic repair budget.

      Revision instructions repeat the descriptive-H1 and narrative-plus-components requirements.

      The review presents the exact draft through <CodeBlock>. Invalid reviews also present the complete structured diagnostics. Draft text cannot close the presentation fence and is never interpreted.

      Approve binds the exact draft for return. It does not execute or print the draft.

      Explanation after the final invalid draft

      When the tenth presented draft is invalid, the person may select Explain what went wrong.

      That choice:

      1. makes one final <Prompt> turn in the same enclosing Session;
      2. is not another draft, repair, revision, or review round;
      3. relies on the Session’s existing conversation history;
      4. supplies the final diagnostics, which the Agent has not previously seen;
      5. asks why the attempts failed and what the person should clarify next time;
      6. requests explanatory prose rather than document source;
      7. treats the answer as inert text;
      8. cannot return to drafting or approval; and
      9. ends without source output, file output, journal, or Plan execution.

      The explanation prompt supplies no draft, Prompt, catalog, or prior diagnostics again. Those remain available only through the existing Session history. Its new contextual data is the final diagnostics.

      A failed explanation turn is terminal.

      A successful explanation is reported through the command’s ordinary terminal failure reporting as the authored failure message. It is not written to source stdout and is not interpreted as XMD. The command exits nonzero because no Plan was approved.

      No TypeScript or Agent API behavior implements this branch.

      Command-document history and presentation

      The prompt command document uses an invocation-owned in-memory durable stream because ordinary document and <Prompt> semantics require one.

      That stream is:

      • never written to --journal;
      • never persisted as a workflow;
      • never reused or replayed; and
      • discarded after complete prompt-profile teardown.

      The configured Agent provider may retain the named Session under its ordinary provider contract.

      Command-document rendering is not successful CLI source output. Successful source output is written by the trusted host only after teardown and final admission.

      Final admission

      After the command document returns and its entire prompt-profile scope tears down successfully, the host treats the approved source as untrusted again.

      The host repeats checking and property resolution using:

      • the exact returned bytes;
      • the original raw CLI and invocation-environment property sources;
      • the frozen individual-option signatures;
      • the caller’s ordered includes; and
      • the ordinary run-profile declarations.

      A final caller-source failure or document failure exits nonzero. It does not re-enter drafting or review.

      The resolved props belong to the exact approved bytes. No props object from an earlier draft is reused.

      No stdout source, output file, journal, or Plan execution begins before this admission succeeds.

      The approved source is the CLI result

      The exact approved source is the primary result of xmd prompt.

      Default: print the source

      xmd prompt "<Prompt>"

      After teardown and final admission, the host writes the exact approved source to stdout.

      It adds no fence, label, delimiter, or newline. It does not execute the Plan or create a generated-source file.

      Write the source

      xmd prompt "<Prompt>" --output <path>

      After teardown and final admission, the host exclusively creates <path> with the exact approved bytes.

      An existing target remains unchanged and fails the command. The command writes nothing to stdout and does not execute the Plan.

      Run the Plan

      xmd prompt "<Prompt>" --run

      After teardown and final admission, the host executes:

      retainedSource("<prompt>", source)
      

      through the ordinary supplied-source path.

      The host does not print the source. Stdout belongs exclusively to the Plan’s ordinary output.

      Write, then run

      xmd prompt "<Prompt>" --output <path> --run

      After teardown and final admission, the host exclusively creates the file first.

      Execution begins only if file creation succeeds. An existing target or other write failure leaves the target unchanged where applicable and prevents execution.

      The host does not print the source. Stdout belongs exclusively to the Plan.

      A runtime failure does not return to authorship. A successfully created output file remains.

      Journal behavior

      Authorship never writes the final journal.

      A diagnostic journal may be created only when:

      • --run is present;
      • --journal <path> is present; and
      • final Plan execution is beginning.

      Default source output and output-only mode create no journal.

      The final journal contains no prompt command document, authorship Session, Agent turn, draft check, repair, human review, explanation, or approval event.

      Authored failures

      PathAuthored failure
      Ordinary Stopxmd prompt stopped at your request. Nothing was output or run.
      Stop on the final invalid draftxmd prompt reviewed ten drafts without an approved Plan. Nothing was output or run.
      Unexpected post-Session fallback without approvalxmd prompt ended without an approved Plan. Nothing was output or run.
      Successful final explanationThe coding agent’s explanation is the authored terminal failure message; no generic advice replaces it

      An ordinary Stop includes stopping a valid tenth draft.

      The final-invalid Stop is distinct from the explanation choice. It reports exhaustion without spending another Agent turn.

      All authored failures are selected by the Markdown command document. They exit nonzero and produce no approved-source stdout, output file, final journal, or execution.

      Cancellation and failure ordering

      The whole-command deadline encloses:

      • fixed preparation after argument admission;
      • catalog construction;
      • prompt-profile execution;
      • Elicitation;
      • explanation when selected;
      • profile teardown;
      • final admission;
      • source output or exclusive file creation; and
      • final execution when requested.

      Cancellation stops active authorship and awaits structured teardown.

      No final admission or output mode begins until prompt-profile execution and teardown both succeed. A teardown failure wins over an approved source.

      Once ordinary Plan execution begins, its existing outcome and teardown precedence apply unchanged.

      Acceptance matrix

      The amended evidence replaces the superseded TypeScript-policy matrix.

      IDBoundaryRequired evidence
      P1Fixed grammarExactly one non-empty Prompt; individual --props-* options require the Prompt first; aggregate props retain ordinary placement
      P2Effect-free helpGeneric help documents default output, --output, --run, --session, property ordering, and run-only flags without loading the packaged document or performing effects
      P3Packaged command documentThe package-relative prompt-command.md is the exact root executed under <prompt-command> and cannot be replaced through component lookup
      P4Approved document languageThe shipped document contains the approved introduction and the five visible stage headings
      P5Complete Plan instructionsInitial, repair, and revision prompts require optional frontmatter followed by a descriptive H1, readable ordered steps, and components beside their prose
      P6One SessionInitial drafting, repairs, revisions, and final explanation use one enclosing Session; default names differ and --session supplies the exact override
      P7Prompt-profile authorityThe authorship Agent receives only the settled session directory and constrained authority; final-run flags cannot widen it
      P8Draft inertnessNo draft is imported, evaluated, journaled as the final Plan, saved, printed as success, or executed before approval
      P9Protected checker<CheckDraft> is the protected host-declared capability, repository lookup cannot replace it, and <ValidateCandidate> is absent
      P10Failure classificationDraft-authored problems return structured facts; caller-authored failures escape terminally; frozen property signatures are checked before token consumption
      P11Repair budgetEach base draft receives at most three repair turns; a human revision resets that budget
      P12Friendly review valuesThe exact values and per-round decision sets are Approve, Request changes, Stop, and final-invalid-only Explain what went wrong
      P13Revision feedbackRequest changes requires non-empty feedback and requests a complete replacement Plan preserving the H1 and narrative requirements
      P14Final explanationFinal-invalid explanation makes exactly one additional <Prompt> turn in the same Session and supplies only the previously unseen final diagnostics as new context
      P15Explanation is terminalExplanation cannot trigger checking, repair, presentation, revision, approval, or another Agent turn; its inert answer is reported and the command ends without a Plan
      P16Authored stoppingOrdinary Stop, final-invalid Stop, unexpected fallback, and explanation use authored Markdown failure paths with the required messages or explanation
      P17Final gateComplete prompt-profile teardown and final admission precede every successful output mode
      P18Default stdoutDefault success writes the exact approved bytes to stdout with no fence, label, delimiter, or added newline and performs no execution
      P19--outputOutput-only success exclusively creates a byte-identical file, writes no stdout, and performs no execution
      P20Explicit --runPlan execution occurs only with --run, through the ordinary supplied-source path
      P21Write before runWith --output --run, byte-identical exclusive creation completes before execution; write refusal prevents execution
      P22Stdout ownershipSource bytes and runtime output never share stdout: default owns source stdout; run modes leave stdout entirely to the Plan
      P23Run-only preflightEvery explicitly supplied run-only flag is refused before catalog or Agent work unless --run is present
      P24Journal separationNo journal file is created without final execution; a requested journal begins only when --run starts and contains no authorship activity
      P25Session-directory lifetimeInvocation-unique cleanup and named-directory preservation remain exactly as specified, with no recursive deletion
      P26Exact bytes and propsApproval, final admission, stdout, --output, and execution use the exact returned bytes; final props are resolved for those bytes
      P27Ordinary run behavior--run preserves ordinary cwd, includes, props, Agent configuration, permissions, timeouts, output, value, failures, and exit behavior
      P28Teardown and cancellationCancellation and every teardown failure settle before final admission, source output, file output, journal creation, or execution

      Use one discriminating regression for each distinct boundary. Do not restore permutations that existed only to prove the superseded TypeScript policy loop.

      Dependencies and delivery

      Delivered foundations remain:

      PR #657 remains the focused implementation vehicle. Its issue #260 delivery includes:

      • rename the packaged asset to prompt-command.md;
      • rename PROMPT_PLAN and related source/test vocabulary to PROMPT_COMMAND;
      • install the approved introduction and visible stage headings;
      • strengthen initial, repair, and revision instructions with the complete Plan requirement;
      • rename the protected internal checker to <CheckDraft>;
      • install the exact friendly review values and round-specific decision sets;
      • add the final same-Session explanation branch;
      • remove any host instruction requiring every Agent response to be source;
      • replace --save with --output, without an alias;
      • make byte-exact stdout the default result;
      • require --run for execution;
      • enforce run-only option preflight;
      • preserve final admission and complete teardown before every output mode;
      • preserve output-file-before-run ordering;
      • keep source stdout separate from Plan stdout;
      • create a journal only when final execution begins;
      • update architecture.md;
      • rewrite specs/prompt-command-spec.md;
      • update the affected prompt-command, Agent-provider, property-binding, CLI, and Tier PR sections of the specifications; and
      • add the revised acceptance evidence.

      The architecture review of feedback commit 1e449879c04e7c458ff6738ae13c2da8abb290dd is not reopened by this amendment. The next feedback commit is reviewed against this amended contract.

      Out of scope

      • arbitrary custom prompt command documents;
      • public or reusable <Plan>;
      • --plan and --plan-eval;
      • File or Glob authorship context;
      • a generic public <Validate>;
      • a general arbitrary-code sandbox;
      • the collaborative playground;
      • stdin or editor Prompt input;
      • automatic revision after runtime failure;
      • a terminal Elicitation provider; and
      • durable journaling or workflow replay of authorship.

      Activity

      Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

      Metadata

      Metadata

      Assignees

      No one assigned

        Labels

        No labels
        No labels

        Projects

        No projects

          Milestone

          No milestone

          Relationships

          None yet

          Development

          No branches or pull requests

          Issue actions

          , 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
          Skip to content

          Add xmd prompt: turn a request into an approved executable Plan #260

          Description

          @taras

          Motivation

          xmd prompt turns steps into a program

          This document is a workflow that generates an executable Plan from a sequence of steps. It combines the original Prompt, which describes those steps, with the XMD components available to carry them out. A coding agent turns both into one document that explains and executes the sequence.

          The result is the XMD version of a coding agent’s plan. A conventional Markdown plan must be interpreted again before its steps can happen. An XMD Plan already contains those executable steps, so running it simply executes them.

          A draft remains text while this workflow reviews it. Nothing in it runs before you approve it. After approval, xmd prompt validates the exact source again. By default it prints the approved XMD source. --output writes that source to a file instead, and --run executes the Plan. With both options, the command writes the source before running it.

          xmd prompt "ask me for my age and write it to a file"

          xmd run -e executes a program someone already wrote. xmd prompt performs the preceding conversion and review. It adds no second execution model.

          Terminology

          These terms are used precisely:

          • A Prompt is the person’s original natural-language request.
          • A Plan is the executable XMD program produced from that Prompt.
          • A Plan combines reader-facing prose expressing the Prompt’s intent with the XMD components that carry it out.
          • xmd prompt converts a Prompt into an approved Plan.
          • The prompt command document is the packaged Markdown workflow that performs generation, checking, review, revision, approval, stopping, explanation, and exhaustion. It is not itself a Plan.
          • The prompt profile is the constrained trusted-host context under which that document runs.
          • A draft is candidate Plan source that has not been approved. It remains inert text.

          “Plan” is not a generic synonym for a workflow, policy document, command implementation, arbitrary XMD document, or the packaged prompt command document.

          The reusable or custom <Plan> surface remains separate in #660.

          Architecture

          The trusted host owns two root executions with complete teardown between them:

          fixed command preflight
          -> build the run-profile syntax catalog
          -> execute the exact packaged prompt command document
          -> one enclosing Session
          -> draft, check, repair, review, revise, approve, stop, explain, or exhaust
          -> Return the exact approved Plan source
          -> await prompt-profile execution and complete provider teardown
          -> admit the returned source again
          -> perform exactly the selected output mode:
          -> print the exact source; or
          -> exclusively create an output file; or
          -> execute through the ordinary supplied-source path; or
          -> create the output file and then execute
          

          The packaged Markdown owns:

          • drafting;
          • repair;
          • diagnostic presentation;
          • review;
          • revision;
          • approval;
          • stopping;
          • final-invalid explanation;
          • authored failure; and
          • finite exhaustion.

          Trusted TypeScript owns:

          • fixed command parsing and preflight;
          • prompt-profile assembly;
          • syntax-catalog construction;
          • property-source parsing and frozen option signatures;
          • non-executing draft checking;
          • complete prompt-profile teardown;
          • final admission;
          • byte-exact stdout;
          • exclusive output-file creation; and
          • ordinary supplied-source execution.

          No drafting, retry, review, revision, explanation, or exhaustion policy belongs in TypeScript, <Prompt>, or the Agent API.

          Command surface

          xmd prompt <Prompt> [--output <path>] [--run] [--session <name>] \ [shared options] [--props-<name> <value>]…

          The Prompt is exactly one positional string containing at least one non-whitespace character. Missing, repeated, empty, and whitespace-only Prompts fail during fixed preflight.

          -- ends option parsing, allowing a dash-leading Prompt.

          The command adds:

          • --output <path> — exclusively create a file containing the exact approved source;
          • --run — execute the approved Plan after final admission and any requested output-file creation;
          • --session <name> — replace the invocation-unique authorship session name with a non-empty explicit name.

          The unreleased --save spelling is removed. It has no compatibility alias.

          -e and --eval remain exclusive to xmd run.

          Property arguments

          The non-empty Prompt must appear before every individual --props-* option. An individual property option before the Prompt is refused during fixed preflight.

          Known fixed-arity options, including aggregate --props, may appear before the Prompt.

          For every initial or revised draft, the host:

          1. inspects the root declaration without execution;
          2. derives property bindings from the original CLI and invocation-environment sources;
          3. checks the frozen signatures of supplied individual options;
          4. resolves those sources against the draft’s schema; and
          5. checks the draft with the resolved props.

          Candidate-versus-caller failure classification and frozen property signatures remain unchanged.

          Shared option roles

          These options remain meaningful without --run because they participate in authorship, catalog construction, property admission, output selection, or the whole-command deadline:

          • --output;
          • --session;
          • --include;
          • --props and declared individual --props-* options;
          • --agent-provider;
          • --default-agent; and
          • --timeout.

          The following options configure only final Plan execution and are refused during fixed preflight unless --run is present:

          • --verbose / -V;
          • --journal / -j;
          • --raw;
          • --timeout-exec;
          • --timeout-fetch;
          • --approve-all;
          • --approve-reads;
          • --deny-all;
          • --secret-detection; and
          • --no-secret-detection.

          Final-run permission flags cannot widen the prompt profile.

          Help

          xmd prompt --help is generic and effect-free. It documents:

          • the Prompt positional;
          • default byte-exact source output;
          • --output;
          • --run;
          • --session;
          • aggregate props;
          • the individual-property ordering rule;
          • shared authorship and admission options; and
          • which final-run options require --run.

          Help does not generate individual property options and does not:

          • load the packaged prompt command document;
          • build a syntax catalog;
          • inspect a generated document;
          • start an Agent;
          • construct a prompt profile;
          • elicit an answer;
          • create a file or journal; or
          • execute a Plan.

          A complete Plan

          A produced Plan begins, after optional frontmatter, with one descriptive level-one Markdown heading as its first body content.

          The Plan then preserves:

          • the Prompt’s sequence of readable steps;
          • every requested outcome;
          • meaningful ordering between those outcomes;
          • reader-facing prose; and
          • the XMD components beside the steps they perform.

          For example:

          # Ask for an age and save it
          Ask me for my age.
          <Elicit ... as="result" />
          Write it to a file.
          <Filepath="age.txt">{result.age}</File>

          The Prompt need not be quoted literally. It may be divided, clarified, and rewritten as natural prose. The resulting Plan must remain understandable in the same order in which its actions execute.

          The descriptive H1 and narrative-plus-components form are enforced through the initial, repair, and revision instructions and through human review. They are not hidden checks in TypeScript or validateDocument().

          The packaged prompt command document

          The host executes one exact checked-in Markdown value root, packaged as prompt-command.md, under the stable internal source identity <prompt-command>.

          Its declared return schema is exactly:

          { "type": "string" }

          The host supplies these internal inputs:

          • the original Prompt;
          • the rendered run-profile syntax catalog;
          • the resolved logical session name.

          They are not Plan root props and consume none of the Plan’s property sources.

          The document begins with the approved introduction in this issue and uses these visible stage headings:

          ## Create the first draft## Check and repair the draft## Review the draft## Continue from your decision## Return the approved Plan

          Stable explanations remain outside repeated loops where possible. The command document does not expose internal <Return> failure precedence to the user.

          <Return> is internal control flow. It transfers the exact approved source from the command document to the trusted host and does not print that source.

          Authorship Agent and Session

          One enclosing <Session> expansion carries every Agent turn:

          • the initial draft;
          • automatic repairs;
          • human-requested revisions; and
          • the optional final explanation.

          Sibling Sessions are not used. The same authored name on sibling Sessions would still represent distinct placements.

          Without --session, the host generates an invocation-unique logical name. With --session <name>, the exact non-empty name replaces it. The default and named session-directory identities, preparation rules, cleanup rules, and continuation behavior remain unchanged.

          The prompt profile gives the authorship Agent:

          • its session-specific host-owned directory;
          • no additional directories;
          • no MCP servers;
          • an empty native-tool allowlist;
          • strict denial of every native permission request; and
          • no document Files, command, service, or XMD-mediated network authority.

          The provider’s own model transport does not grant the Agent a native network tool.

          The host instruction layer establishes authority and common context. It does not require every Agent answer to be XMD source.

          Each authored <Prompt> owns its own response contract:

          • initial, repair, and revision turns request one complete replacement Plan as source only;
          • the final explanation turn requests explanatory prose only.

          A failed, cancelled, unavailable, or protocol-invalid Agent turn is terminal. Partial text never becomes a draft or explanation.

          Drafts remain inert

          Every Agent reply remains an inert string throughout prompt-profile execution.

          The command document may:

          • bind the string;
          • pass it to <CheckDraft>;
          • present it through <CodeBlock>;
          • pass diagnostics into another Agent turn;
          • retain it as the approved value; or
          • return it to the host.

          It never evaluates, imports, or executes a draft.

          Only the exact approved source may proceed, and only after complete prompt-profile teardown and final host admission.

          Internal draft checking

          The prompt profile declares one protected internal value component:

          <CheckDraftsource={draft}as="assessment" />

          Repository component lookup cannot replace it.

          <CheckDraft> checks an unapproved draft without executing it. Its behavior is the behavior previously assigned to the internal <ValidateCandidate> name.

          For each draft it:

          1. checks the supplied root declaration without execution;
          2. derives bindings once a usable root property schema exists;
          3. verifies every frozen supplied individual-option signature before consuming tokens;
          4. resolves the original CLI and invocation-environment property sources; and
          5. calls core’s validateDocument() with those props, the caller’s includes, and the run-profile declarations.

          Core’s validateDocument() keeps its existing name. This issue introduces no generic public <Validate> component.

          Draft-authored failures return structured problems eligible for repair, including:

          • source and frontmatter failures;
          • invalid root props or return declarations;
          • binding collisions;
          • missing required props; and
          • other definite whole-document diagnostics.

          Caller-authored failures raise terminally, including:

          • malformed aggregate CLI or environment JSON;
          • a supplied individual option not declared by the usable draft schema;
          • a malformed individual value;
          • an extra positional exposed by the draft’s arity; and
          • a later schema removing a frozen option or changing its arity or accumulation behavior.

          Caller-authored failures cause no repair, presentation, approval, output, journal, or execution.

          <CheckDraft> reports structural facts only. It does not decide whether the H1 or prose adequately communicates the Prompt.

          Create, check, and repair a draft

          The first draft instruction requires:

          • one complete replacement root as source only;
          • optional frontmatter followed immediately by one descriptive H1;
          • the Prompt’s complete sequence as readable prose;
          • every requested outcome;
          • meaningful ordering; and
          • each XMD component beside the prose describing its action.

          Each initial draft and each human-requested revision receives its own automatic repair budget:

          • the base draft is attempt one;
          • at most three repair turns may replace it;
          • every repair prompt contains the complete structured draft diagnostics;
          • every repair response is one complete replacement root; and
          • repair instructions repeat the complete Plan requirements, including the descriptive H1.

          The fourth invalid draft is repair-exhausted and proceeds to human review with its diagnostics.

          No fence is stripped, Markdown substring extracted, or patch applied.

          Human review

          The command document permits at most ten draft presentations.

          The exact Elicitation values are:

          • Approve
          • Request changes
          • Stop
          • Explain what went wrong

          The offered decision set depends on validity and round:

          Review stateOffered values
          Valid, rounds 1–9Approve, Request changes, Stop
          Invalid, rounds 1–9Request changes, Stop
          Valid, round 10Approve, Stop
          Invalid, round 10Explain what went wrong, Stop

          Request changes requires non-empty feedback. It sends one complete-replacement revision request through the same enclosing Session and resets the automatic repair budget.

          Revision instructions repeat the descriptive-H1 and narrative-plus-components requirements.

          The review presents the exact draft through <CodeBlock>. Invalid reviews also present the complete structured diagnostics. Draft text cannot close the presentation fence and is never interpreted.

          Approve binds the exact draft for return. It does not execute or print the draft.

          Explanation after the final invalid draft

          When the tenth presented draft is invalid, the person may select Explain what went wrong.

          That choice:

          1. makes one final <Prompt> turn in the same enclosing Session;
          2. is not another draft, repair, revision, or review round;
          3. relies on the Session’s existing conversation history;
          4. supplies the final diagnostics, which the Agent has not previously seen;
          5. asks why the attempts failed and what the person should clarify next time;
          6. requests explanatory prose rather than document source;
          7. treats the answer as inert text;
          8. cannot return to drafting or approval; and
          9. ends without source output, file output, journal, or Plan execution.

          The explanation prompt supplies no draft, Prompt, catalog, or prior diagnostics again. Those remain available only through the existing Session history. Its new contextual data is the final diagnostics.

          A failed explanation turn is terminal.

          A successful explanation is reported through the command’s ordinary terminal failure reporting as the authored failure message. It is not written to source stdout and is not interpreted as XMD. The command exits nonzero because no Plan was approved.

          No TypeScript or Agent API behavior implements this branch.

          Command-document history and presentation

          The prompt command document uses an invocation-owned in-memory durable stream because ordinary document and <Prompt> semantics require one.

          That stream is:

          • never written to --journal;
          • never persisted as a workflow;
          • never reused or replayed; and
          • discarded after complete prompt-profile teardown.

          The configured Agent provider may retain the named Session under its ordinary provider contract.

          Command-document rendering is not successful CLI source output. Successful source output is written by the trusted host only after teardown and final admission.

          Final admission

          After the command document returns and its entire prompt-profile scope tears down successfully, the host treats the approved source as untrusted again.

          The host repeats checking and property resolution using:

          • the exact returned bytes;
          • the original raw CLI and invocation-environment property sources;
          • the frozen individual-option signatures;
          • the caller’s ordered includes; and
          • the ordinary run-profile declarations.

          A final caller-source failure or document failure exits nonzero. It does not re-enter drafting or review.

          The resolved props belong to the exact approved bytes. No props object from an earlier draft is reused.

          No stdout source, output file, journal, or Plan execution begins before this admission succeeds.

          The approved source is the CLI result

          The exact approved source is the primary result of xmd prompt.

          Default: print the source

          xmd prompt "<Prompt>"

          After teardown and final admission, the host writes the exact approved source to stdout.

          It adds no fence, label, delimiter, or newline. It does not execute the Plan or create a generated-source file.

          Write the source

          xmd prompt "<Prompt>" --output <path>

          After teardown and final admission, the host exclusively creates <path> with the exact approved bytes.

          An existing target remains unchanged and fails the command. The command writes nothing to stdout and does not execute the Plan.

          Run the Plan

          xmd prompt "<Prompt>" --run

          After teardown and final admission, the host executes:

          retainedSource("<prompt>", source)
          

          through the ordinary supplied-source path.

          The host does not print the source. Stdout belongs exclusively to the Plan’s ordinary output.

          Write, then run

          xmd prompt "<Prompt>" --output <path> --run

          After teardown and final admission, the host exclusively creates the file first.

          Execution begins only if file creation succeeds. An existing target or other write failure leaves the target unchanged where applicable and prevents execution.

          The host does not print the source. Stdout belongs exclusively to the Plan.

          A runtime failure does not return to authorship. A successfully created output file remains.

          Journal behavior

          Authorship never writes the final journal.

          A diagnostic journal may be created only when:

          • --run is present;
          • --journal <path> is present; and
          • final Plan execution is beginning.

          Default source output and output-only mode create no journal.

          The final journal contains no prompt command document, authorship Session, Agent turn, draft check, repair, human review, explanation, or approval event.

          Authored failures

          PathAuthored failure
          Ordinary Stopxmd prompt stopped at your request. Nothing was output or run.
          Stop on the final invalid draftxmd prompt reviewed ten drafts without an approved Plan. Nothing was output or run.
          Unexpected post-Session fallback without approvalxmd prompt ended without an approved Plan. Nothing was output or run.
          Successful final explanationThe coding agent’s explanation is the authored terminal failure message; no generic advice replaces it

          An ordinary Stop includes stopping a valid tenth draft.

          The final-invalid Stop is distinct from the explanation choice. It reports exhaustion without spending another Agent turn.

          All authored failures are selected by the Markdown command document. They exit nonzero and produce no approved-source stdout, output file, final journal, or execution.

          Cancellation and failure ordering

          The whole-command deadline encloses:

          • fixed preparation after argument admission;
          • catalog construction;
          • prompt-profile execution;
          • Elicitation;
          • explanation when selected;
          • profile teardown;
          • final admission;
          • source output or exclusive file creation; and
          • final execution when requested.

          Cancellation stops active authorship and awaits structured teardown.

          No final admission or output mode begins until prompt-profile execution and teardown both succeed. A teardown failure wins over an approved source.

          Once ordinary Plan execution begins, its existing outcome and teardown precedence apply unchanged.

          Acceptance matrix

          The amended evidence replaces the superseded TypeScript-policy matrix.

          IDBoundaryRequired evidence
          P1Fixed grammarExactly one non-empty Prompt; individual --props-* options require the Prompt first; aggregate props retain ordinary placement
          P2Effect-free helpGeneric help documents default output, --output, --run, --session, property ordering, and run-only flags without loading the packaged document or performing effects
          P3Packaged command documentThe package-relative prompt-command.md is the exact root executed under <prompt-command> and cannot be replaced through component lookup
          P4Approved document languageThe shipped document contains the approved introduction and the five visible stage headings
          P5Complete Plan instructionsInitial, repair, and revision prompts require optional frontmatter followed by a descriptive H1, readable ordered steps, and components beside their prose
          P6One SessionInitial drafting, repairs, revisions, and final explanation use one enclosing Session; default names differ and --session supplies the exact override
          P7Prompt-profile authorityThe authorship Agent receives only the settled session directory and constrained authority; final-run flags cannot widen it
          P8Draft inertnessNo draft is imported, evaluated, journaled as the final Plan, saved, printed as success, or executed before approval
          P9Protected checker<CheckDraft> is the protected host-declared capability, repository lookup cannot replace it, and <ValidateCandidate> is absent
          P10Failure classificationDraft-authored problems return structured facts; caller-authored failures escape terminally; frozen property signatures are checked before token consumption
          P11Repair budgetEach base draft receives at most three repair turns; a human revision resets that budget
          P12Friendly review valuesThe exact values and per-round decision sets are Approve, Request changes, Stop, and final-invalid-only Explain what went wrong
          P13Revision feedbackRequest changes requires non-empty feedback and requests a complete replacement Plan preserving the H1 and narrative requirements
          P14Final explanationFinal-invalid explanation makes exactly one additional <Prompt> turn in the same Session and supplies only the previously unseen final diagnostics as new context
          P15Explanation is terminalExplanation cannot trigger checking, repair, presentation, revision, approval, or another Agent turn; its inert answer is reported and the command ends without a Plan
          P16Authored stoppingOrdinary Stop, final-invalid Stop, unexpected fallback, and explanation use authored Markdown failure paths with the required messages or explanation
          P17Final gateComplete prompt-profile teardown and final admission precede every successful output mode
          P18Default stdoutDefault success writes the exact approved bytes to stdout with no fence, label, delimiter, or added newline and performs no execution
          P19--outputOutput-only success exclusively creates a byte-identical file, writes no stdout, and performs no execution
          P20Explicit --runPlan execution occurs only with --run, through the ordinary supplied-source path
          P21Write before runWith --output --run, byte-identical exclusive creation completes before execution; write refusal prevents execution
          P22Stdout ownershipSource bytes and runtime output never share stdout: default owns source stdout; run modes leave stdout entirely to the Plan
          P23Run-only preflightEvery explicitly supplied run-only flag is refused before catalog or Agent work unless --run is present
          P24Journal separationNo journal file is created without final execution; a requested journal begins only when --run starts and contains no authorship activity
          P25Session-directory lifetimeInvocation-unique cleanup and named-directory preservation remain exactly as specified, with no recursive deletion
          P26Exact bytes and propsApproval, final admission, stdout, --output, and execution use the exact returned bytes; final props are resolved for those bytes
          P27Ordinary run behavior--run preserves ordinary cwd, includes, props, Agent configuration, permissions, timeouts, output, value, failures, and exit behavior
          P28Teardown and cancellationCancellation and every teardown failure settle before final admission, source output, file output, journal creation, or execution

          Use one discriminating regression for each distinct boundary. Do not restore permutations that existed only to prove the superseded TypeScript policy loop.

          Dependencies and delivery

          Delivered foundations remain:

          PR #657 remains the focused implementation vehicle. Its issue #260 delivery includes:

          • rename the packaged asset to prompt-command.md;
          • rename PROMPT_PLAN and related source/test vocabulary to PROMPT_COMMAND;
          • install the approved introduction and visible stage headings;
          • strengthen initial, repair, and revision instructions with the complete Plan requirement;
          • rename the protected internal checker to <CheckDraft>;
          • install the exact friendly review values and round-specific decision sets;
          • add the final same-Session explanation branch;
          • remove any host instruction requiring every Agent response to be source;
          • replace --save with --output, without an alias;
          • make byte-exact stdout the default result;
          • require --run for execution;
          • enforce run-only option preflight;
          • preserve final admission and complete teardown before every output mode;
          • preserve output-file-before-run ordering;
          • keep source stdout separate from Plan stdout;
          • create a journal only when final execution begins;
          • update architecture.md;
          • rewrite specs/prompt-command-spec.md;
          • update the affected prompt-command, Agent-provider, property-binding, CLI, and Tier PR sections of the specifications; and
          • add the revised acceptance evidence.

          The architecture review of feedback commit 1e449879c04e7c458ff6738ae13c2da8abb290dd is not reopened by this amendment. The next feedback commit is reviewed against this amended contract.

          Out of scope

          • arbitrary custom prompt command documents;
          • public or reusable <Plan>;
          • --plan and --plan-eval;
          • File or Glob authorship context;
          • a generic public <Validate>;
          • a general arbitrary-code sandbox;
          • the collaborative playground;
          • stdin or editor Prompt input;
          • automatic revision after runtime failure;
          • a terminal Elicitation provider; and
          • durable journaling or workflow replay of authorship.

          Activity

          Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

          Metadata

          Metadata

          Assignees

          No one assigned

            Labels

            No labels
            No labels

            Projects

            No projects

              Milestone

              No milestone

              Relationships

              None yet

              Development

              No branches or pull requests

              Issue actions

              , 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
              Skip to content

              Add xmd prompt: turn a request into an approved executable Plan #260

              Description

              @taras

              Motivation

              xmd prompt turns steps into a program

              This document is a workflow that generates an executable Plan from a sequence of steps. It combines the original Prompt, which describes those steps, with the XMD components available to carry them out. A coding agent turns both into one document that explains and executes the sequence.

              The result is the XMD version of a coding agent’s plan. A conventional Markdown plan must be interpreted again before its steps can happen. An XMD Plan already contains those executable steps, so running it simply executes them.

              A draft remains text while this workflow reviews it. Nothing in it runs before you approve it. After approval, xmd prompt validates the exact source again. By default it prints the approved XMD source. --output writes that source to a file instead, and --run executes the Plan. With both options, the command writes the source before running it.

              xmd prompt "ask me for my age and write it to a file"

              xmd run -e executes a program someone already wrote. xmd prompt performs the preceding conversion and review. It adds no second execution model.

              Terminology

              These terms are used precisely:

              • A Prompt is the person’s original natural-language request.
              • A Plan is the executable XMD program produced from that Prompt.
              • A Plan combines reader-facing prose expressing the Prompt’s intent with the XMD components that carry it out.
              • xmd prompt converts a Prompt into an approved Plan.
              • The prompt command document is the packaged Markdown workflow that performs generation, checking, review, revision, approval, stopping, explanation, and exhaustion. It is not itself a Plan.
              • The prompt profile is the constrained trusted-host context under which that document runs.
              • A draft is candidate Plan source that has not been approved. It remains inert text.

              “Plan” is not a generic synonym for a workflow, policy document, command implementation, arbitrary XMD document, or the packaged prompt command document.

              The reusable or custom <Plan> surface remains separate in #660.

              Architecture

              The trusted host owns two root executions with complete teardown between them:

              fixed command preflight
              -> build the run-profile syntax catalog
              -> execute the exact packaged prompt command document
              -> one enclosing Session
              -> draft, check, repair, review, revise, approve, stop, explain, or exhaust
              -> Return the exact approved Plan source
              -> await prompt-profile execution and complete provider teardown
              -> admit the returned source again
              -> perform exactly the selected output mode:
              -> print the exact source; or
              -> exclusively create an output file; or
              -> execute through the ordinary supplied-source path; or
              -> create the output file and then execute
              

              The packaged Markdown owns:

              • drafting;
              • repair;
              • diagnostic presentation;
              • review;
              • revision;
              • approval;
              • stopping;
              • final-invalid explanation;
              • authored failure; and
              • finite exhaustion.

              Trusted TypeScript owns:

              • fixed command parsing and preflight;
              • prompt-profile assembly;
              • syntax-catalog construction;
              • property-source parsing and frozen option signatures;
              • non-executing draft checking;
              • complete prompt-profile teardown;
              • final admission;
              • byte-exact stdout;
              • exclusive output-file creation; and
              • ordinary supplied-source execution.

              No drafting, retry, review, revision, explanation, or exhaustion policy belongs in TypeScript, <Prompt>, or the Agent API.

              Command surface

              xmd prompt <Prompt> [--output <path>] [--run] [--session <name>] \ [shared options] [--props-<name> <value>]…

              The Prompt is exactly one positional string containing at least one non-whitespace character. Missing, repeated, empty, and whitespace-only Prompts fail during fixed preflight.

              -- ends option parsing, allowing a dash-leading Prompt.

              The command adds:

              • --output <path> — exclusively create a file containing the exact approved source;
              • --run — execute the approved Plan after final admission and any requested output-file creation;
              • --session <name> — replace the invocation-unique authorship session name with a non-empty explicit name.

              The unreleased --save spelling is removed. It has no compatibility alias.

              -e and --eval remain exclusive to xmd run.

              Property arguments

              The non-empty Prompt must appear before every individual --props-* option. An individual property option before the Prompt is refused during fixed preflight.

              Known fixed-arity options, including aggregate --props, may appear before the Prompt.

              For every initial or revised draft, the host:

              1. inspects the root declaration without execution;
              2. derives property bindings from the original CLI and invocation-environment sources;
              3. checks the frozen signatures of supplied individual options;
              4. resolves those sources against the draft’s schema; and
              5. checks the draft with the resolved props.

              Candidate-versus-caller failure classification and frozen property signatures remain unchanged.

              Shared option roles

              These options remain meaningful without --run because they participate in authorship, catalog construction, property admission, output selection, or the whole-command deadline:

              • --output;
              • --session;
              • --include;
              • --props and declared individual --props-* options;
              • --agent-provider;
              • --default-agent; and
              • --timeout.

              The following options configure only final Plan execution and are refused during fixed preflight unless --run is present:

              • --verbose / -V;
              • --journal / -j;
              • --raw;
              • --timeout-exec;
              • --timeout-fetch;
              • --approve-all;
              • --approve-reads;
              • --deny-all;
              • --secret-detection; and
              • --no-secret-detection.

              Final-run permission flags cannot widen the prompt profile.

              Help

              xmd prompt --help is generic and effect-free. It documents:

              • the Prompt positional;
              • default byte-exact source output;
              • --output;
              • --run;
              • --session;
              • aggregate props;
              • the individual-property ordering rule;
              • shared authorship and admission options; and
              • which final-run options require --run.

              Help does not generate individual property options and does not:

              • load the packaged prompt command document;
              • build a syntax catalog;
              • inspect a generated document;
              • start an Agent;
              • construct a prompt profile;
              • elicit an answer;
              • create a file or journal; or
              • execute a Plan.

              A complete Plan

              A produced Plan begins, after optional frontmatter, with one descriptive level-one Markdown heading as its first body content.

              The Plan then preserves:

              • the Prompt’s sequence of readable steps;
              • every requested outcome;
              • meaningful ordering between those outcomes;
              • reader-facing prose; and
              • the XMD components beside the steps they perform.

              For example:

              # Ask for an age and save it
              Ask me for my age.
              <Elicit ... as="result" />
              Write it to a file.
              <Filepath="age.txt">{result.age}</File>

              The Prompt need not be quoted literally. It may be divided, clarified, and rewritten as natural prose. The resulting Plan must remain understandable in the same order in which its actions execute.

              The descriptive H1 and narrative-plus-components form are enforced through the initial, repair, and revision instructions and through human review. They are not hidden checks in TypeScript or validateDocument().

              The packaged prompt command document

              The host executes one exact checked-in Markdown value root, packaged as prompt-command.md, under the stable internal source identity <prompt-command>.

              Its declared return schema is exactly:

              { "type": "string" }

              The host supplies these internal inputs:

              • the original Prompt;
              • the rendered run-profile syntax catalog;
              • the resolved logical session name.

              They are not Plan root props and consume none of the Plan’s property sources.

              The document begins with the approved introduction in this issue and uses these visible stage headings:

              ## Create the first draft## Check and repair the draft## Review the draft## Continue from your decision## Return the approved Plan

              Stable explanations remain outside repeated loops where possible. The command document does not expose internal <Return> failure precedence to the user.

              <Return> is internal control flow. It transfers the exact approved source from the command document to the trusted host and does not print that source.

              Authorship Agent and Session

              One enclosing <Session> expansion carries every Agent turn:

              • the initial draft;
              • automatic repairs;
              • human-requested revisions; and
              • the optional final explanation.

              Sibling Sessions are not used. The same authored name on sibling Sessions would still represent distinct placements.

              Without --session, the host generates an invocation-unique logical name. With --session <name>, the exact non-empty name replaces it. The default and named session-directory identities, preparation rules, cleanup rules, and continuation behavior remain unchanged.

              The prompt profile gives the authorship Agent:

              • its session-specific host-owned directory;
              • no additional directories;
              • no MCP servers;
              • an empty native-tool allowlist;
              • strict denial of every native permission request; and
              • no document Files, command, service, or XMD-mediated network authority.

              The provider’s own model transport does not grant the Agent a native network tool.

              The host instruction layer establishes authority and common context. It does not require every Agent answer to be XMD source.

              Each authored <Prompt> owns its own response contract:

              • initial, repair, and revision turns request one complete replacement Plan as source only;
              • the final explanation turn requests explanatory prose only.

              A failed, cancelled, unavailable, or protocol-invalid Agent turn is terminal. Partial text never becomes a draft or explanation.

              Drafts remain inert

              Every Agent reply remains an inert string throughout prompt-profile execution.

              The command document may:

              • bind the string;
              • pass it to <CheckDraft>;
              • present it through <CodeBlock>;
              • pass diagnostics into another Agent turn;
              • retain it as the approved value; or
              • return it to the host.

              It never evaluates, imports, or executes a draft.

              Only the exact approved source may proceed, and only after complete prompt-profile teardown and final host admission.

              Internal draft checking

              The prompt profile declares one protected internal value component:

              <CheckDraftsource={draft}as="assessment" />

              Repository component lookup cannot replace it.

              <CheckDraft> checks an unapproved draft without executing it. Its behavior is the behavior previously assigned to the internal <ValidateCandidate> name.

              For each draft it:

              1. checks the supplied root declaration without execution;
              2. derives bindings once a usable root property schema exists;
              3. verifies every frozen supplied individual-option signature before consuming tokens;
              4. resolves the original CLI and invocation-environment property sources; and
              5. calls core’s validateDocument() with those props, the caller’s includes, and the run-profile declarations.

              Core’s validateDocument() keeps its existing name. This issue introduces no generic public <Validate> component.

              Draft-authored failures return structured problems eligible for repair, including:

              • source and frontmatter failures;
              • invalid root props or return declarations;
              • binding collisions;
              • missing required props; and
              • other definite whole-document diagnostics.

              Caller-authored failures raise terminally, including:

              • malformed aggregate CLI or environment JSON;
              • a supplied individual option not declared by the usable draft schema;
              • a malformed individual value;
              • an extra positional exposed by the draft’s arity; and
              • a later schema removing a frozen option or changing its arity or accumulation behavior.

              Caller-authored failures cause no repair, presentation, approval, output, journal, or execution.

              <CheckDraft> reports structural facts only. It does not decide whether the H1 or prose adequately communicates the Prompt.

              Create, check, and repair a draft

              The first draft instruction requires:

              • one complete replacement root as source only;
              • optional frontmatter followed immediately by one descriptive H1;
              • the Prompt’s complete sequence as readable prose;
              • every requested outcome;
              • meaningful ordering; and
              • each XMD component beside the prose describing its action.

              Each initial draft and each human-requested revision receives its own automatic repair budget:

              • the base draft is attempt one;
              • at most three repair turns may replace it;
              • every repair prompt contains the complete structured draft diagnostics;
              • every repair response is one complete replacement root; and
              • repair instructions repeat the complete Plan requirements, including the descriptive H1.

              The fourth invalid draft is repair-exhausted and proceeds to human review with its diagnostics.

              No fence is stripped, Markdown substring extracted, or patch applied.

              Human review

              The command document permits at most ten draft presentations.

              The exact Elicitation values are:

              • Approve
              • Request changes
              • Stop
              • Explain what went wrong

              The offered decision set depends on validity and round:

              Review stateOffered values
              Valid, rounds 1–9Approve, Request changes, Stop
              Invalid, rounds 1–9Request changes, Stop
              Valid, round 10Approve, Stop
              Invalid, round 10Explain what went wrong, Stop

              Request changes requires non-empty feedback. It sends one complete-replacement revision request through the same enclosing Session and resets the automatic repair budget.

              Revision instructions repeat the descriptive-H1 and narrative-plus-components requirements.

              The review presents the exact draft through <CodeBlock>. Invalid reviews also present the complete structured diagnostics. Draft text cannot close the presentation fence and is never interpreted.

              Approve binds the exact draft for return. It does not execute or print the draft.

              Explanation after the final invalid draft

              When the tenth presented draft is invalid, the person may select Explain what went wrong.

              That choice:

              1. makes one final <Prompt> turn in the same enclosing Session;
              2. is not another draft, repair, revision, or review round;
              3. relies on the Session’s existing conversation history;
              4. supplies the final diagnostics, which the Agent has not previously seen;
              5. asks why the attempts failed and what the person should clarify next time;
              6. requests explanatory prose rather than document source;
              7. treats the answer as inert text;
              8. cannot return to drafting or approval; and
              9. ends without source output, file output, journal, or Plan execution.

              The explanation prompt supplies no draft, Prompt, catalog, or prior diagnostics again. Those remain available only through the existing Session history. Its new contextual data is the final diagnostics.

              A failed explanation turn is terminal.

              A successful explanation is reported through the command’s ordinary terminal failure reporting as the authored failure message. It is not written to source stdout and is not interpreted as XMD. The command exits nonzero because no Plan was approved.

              No TypeScript or Agent API behavior implements this branch.

              Command-document history and presentation

              The prompt command document uses an invocation-owned in-memory durable stream because ordinary document and <Prompt> semantics require one.

              That stream is:

              • never written to --journal;
              • never persisted as a workflow;
              • never reused or replayed; and
              • discarded after complete prompt-profile teardown.

              The configured Agent provider may retain the named Session under its ordinary provider contract.

              Command-document rendering is not successful CLI source output. Successful source output is written by the trusted host only after teardown and final admission.

              Final admission

              After the command document returns and its entire prompt-profile scope tears down successfully, the host treats the approved source as untrusted again.

              The host repeats checking and property resolution using:

              • the exact returned bytes;
              • the original raw CLI and invocation-environment property sources;
              • the frozen individual-option signatures;
              • the caller’s ordered includes; and
              • the ordinary run-profile declarations.

              A final caller-source failure or document failure exits nonzero. It does not re-enter drafting or review.

              The resolved props belong to the exact approved bytes. No props object from an earlier draft is reused.

              No stdout source, output file, journal, or Plan execution begins before this admission succeeds.

              The approved source is the CLI result

              The exact approved source is the primary result of xmd prompt.

              Default: print the source

              xmd prompt "<Prompt>"

              After teardown and final admission, the host writes the exact approved source to stdout.

              It adds no fence, label, delimiter, or newline. It does not execute the Plan or create a generated-source file.

              Write the source

              xmd prompt "<Prompt>" --output <path>

              After teardown and final admission, the host exclusively creates <path> with the exact approved bytes.

              An existing target remains unchanged and fails the command. The command writes nothing to stdout and does not execute the Plan.

              Run the Plan

              xmd prompt "<Prompt>" --run

              After teardown and final admission, the host executes:

              retainedSource("<prompt>", source)
              

              through the ordinary supplied-source path.

              The host does not print the source. Stdout belongs exclusively to the Plan’s ordinary output.

              Write, then run

              xmd prompt "<Prompt>" --output <path> --run

              After teardown and final admission, the host exclusively creates the file first.

              Execution begins only if file creation succeeds. An existing target or other write failure leaves the target unchanged where applicable and prevents execution.

              The host does not print the source. Stdout belongs exclusively to the Plan.

              A runtime failure does not return to authorship. A successfully created output file remains.

              Journal behavior

              Authorship never writes the final journal.

              A diagnostic journal may be created only when:

              • --run is present;
              • --journal <path> is present; and
              • final Plan execution is beginning.

              Default source output and output-only mode create no journal.

              The final journal contains no prompt command document, authorship Session, Agent turn, draft check, repair, human review, explanation, or approval event.

              Authored failures

              PathAuthored failure
              Ordinary Stopxmd prompt stopped at your request. Nothing was output or run.
              Stop on the final invalid draftxmd prompt reviewed ten drafts without an approved Plan. Nothing was output or run.
              Unexpected post-Session fallback without approvalxmd prompt ended without an approved Plan. Nothing was output or run.
              Successful final explanationThe coding agent’s explanation is the authored terminal failure message; no generic advice replaces it

              An ordinary Stop includes stopping a valid tenth draft.

              The final-invalid Stop is distinct from the explanation choice. It reports exhaustion without spending another Agent turn.

              All authored failures are selected by the Markdown command document. They exit nonzero and produce no approved-source stdout, output file, final journal, or execution.

              Cancellation and failure ordering

              The whole-command deadline encloses:

              • fixed preparation after argument admission;
              • catalog construction;
              • prompt-profile execution;
              • Elicitation;
              • explanation when selected;
              • profile teardown;
              • final admission;
              • source output or exclusive file creation; and
              • final execution when requested.

              Cancellation stops active authorship and awaits structured teardown.

              No final admission or output mode begins until prompt-profile execution and teardown both succeed. A teardown failure wins over an approved source.

              Once ordinary Plan execution begins, its existing outcome and teardown precedence apply unchanged.

              Acceptance matrix

              The amended evidence replaces the superseded TypeScript-policy matrix.

              IDBoundaryRequired evidence
              P1Fixed grammarExactly one non-empty Prompt; individual --props-* options require the Prompt first; aggregate props retain ordinary placement
              P2Effect-free helpGeneric help documents default output, --output, --run, --session, property ordering, and run-only flags without loading the packaged document or performing effects
              P3Packaged command documentThe package-relative prompt-command.md is the exact root executed under <prompt-command> and cannot be replaced through component lookup
              P4Approved document languageThe shipped document contains the approved introduction and the five visible stage headings
              P5Complete Plan instructionsInitial, repair, and revision prompts require optional frontmatter followed by a descriptive H1, readable ordered steps, and components beside their prose
              P6One SessionInitial drafting, repairs, revisions, and final explanation use one enclosing Session; default names differ and --session supplies the exact override
              P7Prompt-profile authorityThe authorship Agent receives only the settled session directory and constrained authority; final-run flags cannot widen it
              P8Draft inertnessNo draft is imported, evaluated, journaled as the final Plan, saved, printed as success, or executed before approval
              P9Protected checker<CheckDraft> is the protected host-declared capability, repository lookup cannot replace it, and <ValidateCandidate> is absent
              P10Failure classificationDraft-authored problems return structured facts; caller-authored failures escape terminally; frozen property signatures are checked before token consumption
              P11Repair budgetEach base draft receives at most three repair turns; a human revision resets that budget
              P12Friendly review valuesThe exact values and per-round decision sets are Approve, Request changes, Stop, and final-invalid-only Explain what went wrong
              P13Revision feedbackRequest changes requires non-empty feedback and requests a complete replacement Plan preserving the H1 and narrative requirements
              P14Final explanationFinal-invalid explanation makes exactly one additional <Prompt> turn in the same Session and supplies only the previously unseen final diagnostics as new context
              P15Explanation is terminalExplanation cannot trigger checking, repair, presentation, revision, approval, or another Agent turn; its inert answer is reported and the command ends without a Plan
              P16Authored stoppingOrdinary Stop, final-invalid Stop, unexpected fallback, and explanation use authored Markdown failure paths with the required messages or explanation
              P17Final gateComplete prompt-profile teardown and final admission precede every successful output mode
              P18Default stdoutDefault success writes the exact approved bytes to stdout with no fence, label, delimiter, or added newline and performs no execution
              P19--outputOutput-only success exclusively creates a byte-identical file, writes no stdout, and performs no execution
              P20Explicit --runPlan execution occurs only with --run, through the ordinary supplied-source path
              P21Write before runWith --output --run, byte-identical exclusive creation completes before execution; write refusal prevents execution
              P22Stdout ownershipSource bytes and runtime output never share stdout: default owns source stdout; run modes leave stdout entirely to the Plan
              P23Run-only preflightEvery explicitly supplied run-only flag is refused before catalog or Agent work unless --run is present
              P24Journal separationNo journal file is created without final execution; a requested journal begins only when --run starts and contains no authorship activity
              P25Session-directory lifetimeInvocation-unique cleanup and named-directory preservation remain exactly as specified, with no recursive deletion
              P26Exact bytes and propsApproval, final admission, stdout, --output, and execution use the exact returned bytes; final props are resolved for those bytes
              P27Ordinary run behavior--run preserves ordinary cwd, includes, props, Agent configuration, permissions, timeouts, output, value, failures, and exit behavior
              P28Teardown and cancellationCancellation and every teardown failure settle before final admission, source output, file output, journal creation, or execution

              Use one discriminating regression for each distinct boundary. Do not restore permutations that existed only to prove the superseded TypeScript policy loop.

              Dependencies and delivery

              Delivered foundations remain:

              PR #657 remains the focused implementation vehicle. Its issue #260 delivery includes:

              • rename the packaged asset to prompt-command.md;
              • rename PROMPT_PLAN and related source/test vocabulary to PROMPT_COMMAND;
              • install the approved introduction and visible stage headings;
              • strengthen initial, repair, and revision instructions with the complete Plan requirement;
              • rename the protected internal checker to <CheckDraft>;
              • install the exact friendly review values and round-specific decision sets;
              • add the final same-Session explanation branch;
              • remove any host instruction requiring every Agent response to be source;
              • replace --save with --output, without an alias;
              • make byte-exact stdout the default result;
              • require --run for execution;
              • enforce run-only option preflight;
              • preserve final admission and complete teardown before every output mode;
              • preserve output-file-before-run ordering;
              • keep source stdout separate from Plan stdout;
              • create a journal only when final execution begins;
              • update architecture.md;
              • rewrite specs/prompt-command-spec.md;
              • update the affected prompt-command, Agent-provider, property-binding, CLI, and Tier PR sections of the specifications; and
              • add the revised acceptance evidence.

              The architecture review of feedback commit 1e449879c04e7c458ff6738ae13c2da8abb290dd is not reopened by this amendment. The next feedback commit is reviewed against this amended contract.

              Out of scope

              • arbitrary custom prompt command documents;
              • public or reusable <Plan>;
              • --plan and --plan-eval;
              • File or Glob authorship context;
              • a generic public <Validate>;
              • a general arbitrary-code sandbox;
              • the collaborative playground;
              • stdin or editor Prompt input;
              • automatic revision after runtime failure;
              • a terminal Elicitation provider; and
              • durable journaling or workflow replay of authorship.

              Activity

              Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

              Metadata

              Metadata

              Assignees

              No one assigned

                Labels

                No labels
                No labels

                Projects

                No projects

                  Milestone

                  No milestone

                  Relationships

                  None yet

                  Development

                  No branches or pull requests

                  Issue actions

                  , 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
                  Skip to content

                  Add xmd prompt: turn a request into an approved executable Plan #260

                  Description

                  @taras

                  Motivation

                  xmd prompt turns steps into a program

                  This document is a workflow that generates an executable Plan from a sequence of steps. It combines the original Prompt, which describes those steps, with the XMD components available to carry them out. A coding agent turns both into one document that explains and executes the sequence.

                  The result is the XMD version of a coding agent’s plan. A conventional Markdown plan must be interpreted again before its steps can happen. An XMD Plan already contains those executable steps, so running it simply executes them.

                  A draft remains text while this workflow reviews it. Nothing in it runs before you approve it. After approval, xmd prompt validates the exact source again. By default it prints the approved XMD source. --output writes that source to a file instead, and --run executes the Plan. With both options, the command writes the source before running it.

                  xmd prompt "ask me for my age and write it to a file"

                  xmd run -e executes a program someone already wrote. xmd prompt performs the preceding conversion and review. It adds no second execution model.

                  Terminology

                  These terms are used precisely:

                  • A Prompt is the person’s original natural-language request.
                  • A Plan is the executable XMD program produced from that Prompt.
                  • A Plan combines reader-facing prose expressing the Prompt’s intent with the XMD components that carry it out.
                  • xmd prompt converts a Prompt into an approved Plan.
                  • The prompt command document is the packaged Markdown workflow that performs generation, checking, review, revision, approval, stopping, explanation, and exhaustion. It is not itself a Plan.
                  • The prompt profile is the constrained trusted-host context under which that document runs.
                  • A draft is candidate Plan source that has not been approved. It remains inert text.

                  “Plan” is not a generic synonym for a workflow, policy document, command implementation, arbitrary XMD document, or the packaged prompt command document.

                  The reusable or custom <Plan> surface remains separate in #660.

                  Architecture

                  The trusted host owns two root executions with complete teardown between them:

                  fixed command preflight
                  -> build the run-profile syntax catalog
                  -> execute the exact packaged prompt command document
                  -> one enclosing Session
                  -> draft, check, repair, review, revise, approve, stop, explain, or exhaust
                  -> Return the exact approved Plan source
                  -> await prompt-profile execution and complete provider teardown
                  -> admit the returned source again
                  -> perform exactly the selected output mode:
                  -> print the exact source; or
                  -> exclusively create an output file; or
                  -> execute through the ordinary supplied-source path; or
                  -> create the output file and then execute
                  

                  The packaged Markdown owns:

                  • drafting;
                  • repair;
                  • diagnostic presentation;
                  • review;
                  • revision;
                  • approval;
                  • stopping;
                  • final-invalid explanation;
                  • authored failure; and
                  • finite exhaustion.

                  Trusted TypeScript owns:

                  • fixed command parsing and preflight;
                  • prompt-profile assembly;
                  • syntax-catalog construction;
                  • property-source parsing and frozen option signatures;
                  • non-executing draft checking;
                  • complete prompt-profile teardown;
                  • final admission;
                  • byte-exact stdout;
                  • exclusive output-file creation; and
                  • ordinary supplied-source execution.

                  No drafting, retry, review, revision, explanation, or exhaustion policy belongs in TypeScript, <Prompt>, or the Agent API.

                  Command surface

                  xmd prompt <Prompt> [--output <path>] [--run] [--session <name>] \ [shared options] [--props-<name> <value>]…

                  The Prompt is exactly one positional string containing at least one non-whitespace character. Missing, repeated, empty, and whitespace-only Prompts fail during fixed preflight.

                  -- ends option parsing, allowing a dash-leading Prompt.

                  The command adds:

                  • --output <path> — exclusively create a file containing the exact approved source;
                  • --run — execute the approved Plan after final admission and any requested output-file creation;
                  • --session <name> — replace the invocation-unique authorship session name with a non-empty explicit name.

                  The unreleased --save spelling is removed. It has no compatibility alias.

                  -e and --eval remain exclusive to xmd run.

                  Property arguments

                  The non-empty Prompt must appear before every individual --props-* option. An individual property option before the Prompt is refused during fixed preflight.

                  Known fixed-arity options, including aggregate --props, may appear before the Prompt.

                  For every initial or revised draft, the host:

                  1. inspects the root declaration without execution;
                  2. derives property bindings from the original CLI and invocation-environment sources;
                  3. checks the frozen signatures of supplied individual options;
                  4. resolves those sources against the draft’s schema; and
                  5. checks the draft with the resolved props.

                  Candidate-versus-caller failure classification and frozen property signatures remain unchanged.

                  Shared option roles

                  These options remain meaningful without --run because they participate in authorship, catalog construction, property admission, output selection, or the whole-command deadline:

                  • --output;
                  • --session;
                  • --include;
                  • --props and declared individual --props-* options;
                  • --agent-provider;
                  • --default-agent; and
                  • --timeout.

                  The following options configure only final Plan execution and are refused during fixed preflight unless --run is present:

                  • --verbose / -V;
                  • --journal / -j;
                  • --raw;
                  • --timeout-exec;
                  • --timeout-fetch;
                  • --approve-all;
                  • --approve-reads;
                  • --deny-all;
                  • --secret-detection; and
                  • --no-secret-detection.

                  Final-run permission flags cannot widen the prompt profile.

                  Help

                  xmd prompt --help is generic and effect-free. It documents:

                  • the Prompt positional;
                  • default byte-exact source output;
                  • --output;
                  • --run;
                  • --session;
                  • aggregate props;
                  • the individual-property ordering rule;
                  • shared authorship and admission options; and
                  • which final-run options require --run.

                  Help does not generate individual property options and does not:

                  • load the packaged prompt command document;
                  • build a syntax catalog;
                  • inspect a generated document;
                  • start an Agent;
                  • construct a prompt profile;
                  • elicit an answer;
                  • create a file or journal; or
                  • execute a Plan.

                  A complete Plan

                  A produced Plan begins, after optional frontmatter, with one descriptive level-one Markdown heading as its first body content.

                  The Plan then preserves:

                  • the Prompt’s sequence of readable steps;
                  • every requested outcome;
                  • meaningful ordering between those outcomes;
                  • reader-facing prose; and
                  • the XMD components beside the steps they perform.

                  For example:

                  # Ask for an age and save it
                  Ask me for my age.
                  <Elicit ... as="result" />
                  Write it to a file.
                  <Filepath="age.txt">{result.age}</File>

                  The Prompt need not be quoted literally. It may be divided, clarified, and rewritten as natural prose. The resulting Plan must remain understandable in the same order in which its actions execute.

                  The descriptive H1 and narrative-plus-components form are enforced through the initial, repair, and revision instructions and through human review. They are not hidden checks in TypeScript or validateDocument().

                  The packaged prompt command document

                  The host executes one exact checked-in Markdown value root, packaged as prompt-command.md, under the stable internal source identity <prompt-command>.

                  Its declared return schema is exactly:

                  { "type": "string" }

                  The host supplies these internal inputs:

                  • the original Prompt;
                  • the rendered run-profile syntax catalog;
                  • the resolved logical session name.

                  They are not Plan root props and consume none of the Plan’s property sources.

                  The document begins with the approved introduction in this issue and uses these visible stage headings:

                  ## Create the first draft## Check and repair the draft## Review the draft## Continue from your decision## Return the approved Plan

                  Stable explanations remain outside repeated loops where possible. The command document does not expose internal <Return> failure precedence to the user.

                  <Return> is internal control flow. It transfers the exact approved source from the command document to the trusted host and does not print that source.

                  Authorship Agent and Session

                  One enclosing <Session> expansion carries every Agent turn:

                  • the initial draft;
                  • automatic repairs;
                  • human-requested revisions; and
                  • the optional final explanation.

                  Sibling Sessions are not used. The same authored name on sibling Sessions would still represent distinct placements.

                  Without --session, the host generates an invocation-unique logical name. With --session <name>, the exact non-empty name replaces it. The default and named session-directory identities, preparation rules, cleanup rules, and continuation behavior remain unchanged.

                  The prompt profile gives the authorship Agent:

                  • its session-specific host-owned directory;
                  • no additional directories;
                  • no MCP servers;
                  • an empty native-tool allowlist;
                  • strict denial of every native permission request; and
                  • no document Files, command, service, or XMD-mediated network authority.

                  The provider’s own model transport does not grant the Agent a native network tool.

                  The host instruction layer establishes authority and common context. It does not require every Agent answer to be XMD source.

                  Each authored <Prompt> owns its own response contract:

                  • initial, repair, and revision turns request one complete replacement Plan as source only;
                  • the final explanation turn requests explanatory prose only.

                  A failed, cancelled, unavailable, or protocol-invalid Agent turn is terminal. Partial text never becomes a draft or explanation.

                  Drafts remain inert

                  Every Agent reply remains an inert string throughout prompt-profile execution.

                  The command document may:

                  • bind the string;
                  • pass it to <CheckDraft>;
                  • present it through <CodeBlock>;
                  • pass diagnostics into another Agent turn;
                  • retain it as the approved value; or
                  • return it to the host.

                  It never evaluates, imports, or executes a draft.

                  Only the exact approved source may proceed, and only after complete prompt-profile teardown and final host admission.

                  Internal draft checking

                  The prompt profile declares one protected internal value component:

                  <CheckDraftsource={draft}as="assessment" />

                  Repository component lookup cannot replace it.

                  <CheckDraft> checks an unapproved draft without executing it. Its behavior is the behavior previously assigned to the internal <ValidateCandidate> name.

                  For each draft it:

                  1. checks the supplied root declaration without execution;
                  2. derives bindings once a usable root property schema exists;
                  3. verifies every frozen supplied individual-option signature before consuming tokens;
                  4. resolves the original CLI and invocation-environment property sources; and
                  5. calls core’s validateDocument() with those props, the caller’s includes, and the run-profile declarations.

                  Core’s validateDocument() keeps its existing name. This issue introduces no generic public <Validate> component.

                  Draft-authored failures return structured problems eligible for repair, including:

                  • source and frontmatter failures;
                  • invalid root props or return declarations;
                  • binding collisions;
                  • missing required props; and
                  • other definite whole-document diagnostics.

                  Caller-authored failures raise terminally, including:

                  • malformed aggregate CLI or environment JSON;
                  • a supplied individual option not declared by the usable draft schema;
                  • a malformed individual value;
                  • an extra positional exposed by the draft’s arity; and
                  • a later schema removing a frozen option or changing its arity or accumulation behavior.

                  Caller-authored failures cause no repair, presentation, approval, output, journal, or execution.

                  <CheckDraft> reports structural facts only. It does not decide whether the H1 or prose adequately communicates the Prompt.

                  Create, check, and repair a draft

                  The first draft instruction requires:

                  • one complete replacement root as source only;
                  • optional frontmatter followed immediately by one descriptive H1;
                  • the Prompt’s complete sequence as readable prose;
                  • every requested outcome;
                  • meaningful ordering; and
                  • each XMD component beside the prose describing its action.

                  Each initial draft and each human-requested revision receives its own automatic repair budget:

                  • the base draft is attempt one;
                  • at most three repair turns may replace it;
                  • every repair prompt contains the complete structured draft diagnostics;
                  • every repair response is one complete replacement root; and
                  • repair instructions repeat the complete Plan requirements, including the descriptive H1.

                  The fourth invalid draft is repair-exhausted and proceeds to human review with its diagnostics.

                  No fence is stripped, Markdown substring extracted, or patch applied.

                  Human review

                  The command document permits at most ten draft presentations.

                  The exact Elicitation values are:

                  • Approve
                  • Request changes
                  • Stop
                  • Explain what went wrong

                  The offered decision set depends on validity and round:

                  Review stateOffered values
                  Valid, rounds 1–9Approve, Request changes, Stop
                  Invalid, rounds 1–9Request changes, Stop
                  Valid, round 10Approve, Stop
                  Invalid, round 10Explain what went wrong, Stop

                  Request changes requires non-empty feedback. It sends one complete-replacement revision request through the same enclosing Session and resets the automatic repair budget.

                  Revision instructions repeat the descriptive-H1 and narrative-plus-components requirements.

                  The review presents the exact draft through <CodeBlock>. Invalid reviews also present the complete structured diagnostics. Draft text cannot close the presentation fence and is never interpreted.

                  Approve binds the exact draft for return. It does not execute or print the draft.

                  Explanation after the final invalid draft

                  When the tenth presented draft is invalid, the person may select Explain what went wrong.

                  That choice:

                  1. makes one final <Prompt> turn in the same enclosing Session;
                  2. is not another draft, repair, revision, or review round;
                  3. relies on the Session’s existing conversation history;
                  4. supplies the final diagnostics, which the Agent has not previously seen;
                  5. asks why the attempts failed and what the person should clarify next time;
                  6. requests explanatory prose rather than document source;
                  7. treats the answer as inert text;
                  8. cannot return to drafting or approval; and
                  9. ends without source output, file output, journal, or Plan execution.

                  The explanation prompt supplies no draft, Prompt, catalog, or prior diagnostics again. Those remain available only through the existing Session history. Its new contextual data is the final diagnostics.

                  A failed explanation turn is terminal.

                  A successful explanation is reported through the command’s ordinary terminal failure reporting as the authored failure message. It is not written to source stdout and is not interpreted as XMD. The command exits nonzero because no Plan was approved.

                  No TypeScript or Agent API behavior implements this branch.

                  Command-document history and presentation

                  The prompt command document uses an invocation-owned in-memory durable stream because ordinary document and <Prompt> semantics require one.

                  That stream is:

                  • never written to --journal;
                  • never persisted as a workflow;
                  • never reused or replayed; and
                  • discarded after complete prompt-profile teardown.

                  The configured Agent provider may retain the named Session under its ordinary provider contract.

                  Command-document rendering is not successful CLI source output. Successful source output is written by the trusted host only after teardown and final admission.

                  Final admission

                  After the command document returns and its entire prompt-profile scope tears down successfully, the host treats the approved source as untrusted again.

                  The host repeats checking and property resolution using:

                  • the exact returned bytes;
                  • the original raw CLI and invocation-environment property sources;
                  • the frozen individual-option signatures;
                  • the caller’s ordered includes; and
                  • the ordinary run-profile declarations.

                  A final caller-source failure or document failure exits nonzero. It does not re-enter drafting or review.

                  The resolved props belong to the exact approved bytes. No props object from an earlier draft is reused.

                  No stdout source, output file, journal, or Plan execution begins before this admission succeeds.

                  The approved source is the CLI result

                  The exact approved source is the primary result of xmd prompt.

                  Default: print the source

                  xmd prompt "<Prompt>"

                  After teardown and final admission, the host writes the exact approved source to stdout.

                  It adds no fence, label, delimiter, or newline. It does not execute the Plan or create a generated-source file.

                  Write the source

                  xmd prompt "<Prompt>" --output <path>

                  After teardown and final admission, the host exclusively creates <path> with the exact approved bytes.

                  An existing target remains unchanged and fails the command. The command writes nothing to stdout and does not execute the Plan.

                  Run the Plan

                  xmd prompt "<Prompt>" --run

                  After teardown and final admission, the host executes:

                  retainedSource("<prompt>", source)
                  

                  through the ordinary supplied-source path.

                  The host does not print the source. Stdout belongs exclusively to the Plan’s ordinary output.

                  Write, then run

                  xmd prompt "<Prompt>" --output <path> --run

                  After teardown and final admission, the host exclusively creates the file first.

                  Execution begins only if file creation succeeds. An existing target or other write failure leaves the target unchanged where applicable and prevents execution.

                  The host does not print the source. Stdout belongs exclusively to the Plan.

                  A runtime failure does not return to authorship. A successfully created output file remains.

                  Journal behavior

                  Authorship never writes the final journal.

                  A diagnostic journal may be created only when:

                  • --run is present;
                  • --journal <path> is present; and
                  • final Plan execution is beginning.

                  Default source output and output-only mode create no journal.

                  The final journal contains no prompt command document, authorship Session, Agent turn, draft check, repair, human review, explanation, or approval event.

                  Authored failures

                  PathAuthored failure
                  Ordinary Stopxmd prompt stopped at your request. Nothing was output or run.
                  Stop on the final invalid draftxmd prompt reviewed ten drafts without an approved Plan. Nothing was output or run.
                  Unexpected post-Session fallback without approvalxmd prompt ended without an approved Plan. Nothing was output or run.
                  Successful final explanationThe coding agent’s explanation is the authored terminal failure message; no generic advice replaces it

                  An ordinary Stop includes stopping a valid tenth draft.

                  The final-invalid Stop is distinct from the explanation choice. It reports exhaustion without spending another Agent turn.

                  All authored failures are selected by the Markdown command document. They exit nonzero and produce no approved-source stdout, output file, final journal, or execution.

                  Cancellation and failure ordering

                  The whole-command deadline encloses:

                  • fixed preparation after argument admission;
                  • catalog construction;
                  • prompt-profile execution;
                  • Elicitation;
                  • explanation when selected;
                  • profile teardown;
                  • final admission;
                  • source output or exclusive file creation; and
                  • final execution when requested.

                  Cancellation stops active authorship and awaits structured teardown.

                  No final admission or output mode begins until prompt-profile execution and teardown both succeed. A teardown failure wins over an approved source.

                  Once ordinary Plan execution begins, its existing outcome and teardown precedence apply unchanged.

                  Acceptance matrix

                  The amended evidence replaces the superseded TypeScript-policy matrix.

                  IDBoundaryRequired evidence
                  P1Fixed grammarExactly one non-empty Prompt; individual --props-* options require the Prompt first; aggregate props retain ordinary placement
                  P2Effect-free helpGeneric help documents default output, --output, --run, --session, property ordering, and run-only flags without loading the packaged document or performing effects
                  P3Packaged command documentThe package-relative prompt-command.md is the exact root executed under <prompt-command> and cannot be replaced through component lookup
                  P4Approved document languageThe shipped document contains the approved introduction and the five visible stage headings
                  P5Complete Plan instructionsInitial, repair, and revision prompts require optional frontmatter followed by a descriptive H1, readable ordered steps, and components beside their prose
                  P6One SessionInitial drafting, repairs, revisions, and final explanation use one enclosing Session; default names differ and --session supplies the exact override
                  P7Prompt-profile authorityThe authorship Agent receives only the settled session directory and constrained authority; final-run flags cannot widen it
                  P8Draft inertnessNo draft is imported, evaluated, journaled as the final Plan, saved, printed as success, or executed before approval
                  P9Protected checker<CheckDraft> is the protected host-declared capability, repository lookup cannot replace it, and <ValidateCandidate> is absent
                  P10Failure classificationDraft-authored problems return structured facts; caller-authored failures escape terminally; frozen property signatures are checked before token consumption
                  P11Repair budgetEach base draft receives at most three repair turns; a human revision resets that budget
                  P12Friendly review valuesThe exact values and per-round decision sets are Approve, Request changes, Stop, and final-invalid-only Explain what went wrong
                  P13Revision feedbackRequest changes requires non-empty feedback and requests a complete replacement Plan preserving the H1 and narrative requirements
                  P14Final explanationFinal-invalid explanation makes exactly one additional <Prompt> turn in the same Session and supplies only the previously unseen final diagnostics as new context
                  P15Explanation is terminalExplanation cannot trigger checking, repair, presentation, revision, approval, or another Agent turn; its inert answer is reported and the command ends without a Plan
                  P16Authored stoppingOrdinary Stop, final-invalid Stop, unexpected fallback, and explanation use authored Markdown failure paths with the required messages or explanation
                  P17Final gateComplete prompt-profile teardown and final admission precede every successful output mode
                  P18Default stdoutDefault success writes the exact approved bytes to stdout with no fence, label, delimiter, or added newline and performs no execution
                  P19--outputOutput-only success exclusively creates a byte-identical file, writes no stdout, and performs no execution
                  P20Explicit --runPlan execution occurs only with --run, through the ordinary supplied-source path
                  P21Write before runWith --output --run, byte-identical exclusive creation completes before execution; write refusal prevents execution
                  P22Stdout ownershipSource bytes and runtime output never share stdout: default owns source stdout; run modes leave stdout entirely to the Plan
                  P23Run-only preflightEvery explicitly supplied run-only flag is refused before catalog or Agent work unless --run is present
                  P24Journal separationNo journal file is created without final execution; a requested journal begins only when --run starts and contains no authorship activity
                  P25Session-directory lifetimeInvocation-unique cleanup and named-directory preservation remain exactly as specified, with no recursive deletion
                  P26Exact bytes and propsApproval, final admission, stdout, --output, and execution use the exact returned bytes; final props are resolved for those bytes
                  P27Ordinary run behavior--run preserves ordinary cwd, includes, props, Agent configuration, permissions, timeouts, output, value, failures, and exit behavior
                  P28Teardown and cancellationCancellation and every teardown failure settle before final admission, source output, file output, journal creation, or execution

                  Use one discriminating regression for each distinct boundary. Do not restore permutations that existed only to prove the superseded TypeScript policy loop.

                  Dependencies and delivery

                  Delivered foundations remain:

                  PR #657 remains the focused implementation vehicle. Its issue #260 delivery includes:

                  • rename the packaged asset to prompt-command.md;
                  • rename PROMPT_PLAN and related source/test vocabulary to PROMPT_COMMAND;
                  • install the approved introduction and visible stage headings;
                  • strengthen initial, repair, and revision instructions with the complete Plan requirement;
                  • rename the protected internal checker to <CheckDraft>;
                  • install the exact friendly review values and round-specific decision sets;
                  • add the final same-Session explanation branch;
                  • remove any host instruction requiring every Agent response to be source;
                  • replace --save with --output, without an alias;
                  • make byte-exact stdout the default result;
                  • require --run for execution;
                  • enforce run-only option preflight;
                  • preserve final admission and complete teardown before every output mode;
                  • preserve output-file-before-run ordering;
                  • keep source stdout separate from Plan stdout;
                  • create a journal only when final execution begins;
                  • update architecture.md;
                  • rewrite specs/prompt-command-spec.md;
                  • update the affected prompt-command, Agent-provider, property-binding, CLI, and Tier PR sections of the specifications; and
                  • add the revised acceptance evidence.

                  The architecture review of feedback commit 1e449879c04e7c458ff6738ae13c2da8abb290dd is not reopened by this amendment. The next feedback commit is reviewed against this amended contract.

                  Out of scope

                  • arbitrary custom prompt command documents;
                  • public or reusable <Plan>;
                  • --plan and --plan-eval;
                  • File or Glob authorship context;
                  • a generic public <Validate>;
                  • a general arbitrary-code sandbox;
                  • the collaborative playground;
                  • stdin or editor Prompt input;
                  • automatic revision after runtime failure;
                  • a terminal Elicitation provider; and
                  • durable journaling or workflow replay of authorship.

                  Activity

                  Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

                  Metadata

                  Metadata

                  Assignees

                  No one assigned

                    Labels

                    No labels
                    No labels

                    Projects

                    No projects

                      Milestone

                      No milestone

                      Relationships

                      None yet

                      Development

                      No branches or pull requests

                      Issue actions

                      , 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
                      Skip to content

                      Add xmd prompt: turn a request into an approved executable Plan #260

                      Description

                      @taras

                      Motivation

                      xmd prompt turns steps into a program

                      This document is a workflow that generates an executable Plan from a sequence of steps. It combines the original Prompt, which describes those steps, with the XMD components available to carry them out. A coding agent turns both into one document that explains and executes the sequence.

                      The result is the XMD version of a coding agent’s plan. A conventional Markdown plan must be interpreted again before its steps can happen. An XMD Plan already contains those executable steps, so running it simply executes them.

                      A draft remains text while this workflow reviews it. Nothing in it runs before you approve it. After approval, xmd prompt validates the exact source again. By default it prints the approved XMD source. --output writes that source to a file instead, and --run executes the Plan. With both options, the command writes the source before running it.

                      xmd prompt "ask me for my age and write it to a file"

                      xmd run -e executes a program someone already wrote. xmd prompt performs the preceding conversion and review. It adds no second execution model.

                      Terminology

                      These terms are used precisely:

                      • A Prompt is the person’s original natural-language request.
                      • A Plan is the executable XMD program produced from that Prompt.
                      • A Plan combines reader-facing prose expressing the Prompt’s intent with the XMD components that carry it out.
                      • xmd prompt converts a Prompt into an approved Plan.
                      • The prompt command document is the packaged Markdown workflow that performs generation, checking, review, revision, approval, stopping, explanation, and exhaustion. It is not itself a Plan.
                      • The prompt profile is the constrained trusted-host context under which that document runs.
                      • A draft is candidate Plan source that has not been approved. It remains inert text.

                      “Plan” is not a generic synonym for a workflow, policy document, command implementation, arbitrary XMD document, or the packaged prompt command document.

                      The reusable or custom <Plan> surface remains separate in #660.

                      Architecture

                      The trusted host owns two root executions with complete teardown between them:

                      fixed command preflight
                      -> build the run-profile syntax catalog
                      -> execute the exact packaged prompt command document
                      -> one enclosing Session
                      -> draft, check, repair, review, revise, approve, stop, explain, or exhaust
                      -> Return the exact approved Plan source
                      -> await prompt-profile execution and complete provider teardown
                      -> admit the returned source again
                      -> perform exactly the selected output mode:
                      -> print the exact source; or
                      -> exclusively create an output file; or
                      -> execute through the ordinary supplied-source path; or
                      -> create the output file and then execute
                      

                      The packaged Markdown owns:

                      • drafting;
                      • repair;
                      • diagnostic presentation;
                      • review;
                      • revision;
                      • approval;
                      • stopping;
                      • final-invalid explanation;
                      • authored failure; and
                      • finite exhaustion.

                      Trusted TypeScript owns:

                      • fixed command parsing and preflight;
                      • prompt-profile assembly;
                      • syntax-catalog construction;
                      • property-source parsing and frozen option signatures;
                      • non-executing draft checking;
                      • complete prompt-profile teardown;
                      • final admission;
                      • byte-exact stdout;
                      • exclusive output-file creation; and
                      • ordinary supplied-source execution.

                      No drafting, retry, review, revision, explanation, or exhaustion policy belongs in TypeScript, <Prompt>, or the Agent API.

                      Command surface

                      xmd prompt <Prompt> [--output <path>] [--run] [--session <name>] \ [shared options] [--props-<name> <value>]…

                      The Prompt is exactly one positional string containing at least one non-whitespace character. Missing, repeated, empty, and whitespace-only Prompts fail during fixed preflight.

                      -- ends option parsing, allowing a dash-leading Prompt.

                      The command adds:

                      • --output <path> — exclusively create a file containing the exact approved source;
                      • --run — execute the approved Plan after final admission and any requested output-file creation;
                      • --session <name> — replace the invocation-unique authorship session name with a non-empty explicit name.

                      The unreleased --save spelling is removed. It has no compatibility alias.

                      -e and --eval remain exclusive to xmd run.

                      Property arguments

                      The non-empty Prompt must appear before every individual --props-* option. An individual property option before the Prompt is refused during fixed preflight.

                      Known fixed-arity options, including aggregate --props, may appear before the Prompt.

                      For every initial or revised draft, the host:

                      1. inspects the root declaration without execution;
                      2. derives property bindings from the original CLI and invocation-environment sources;
                      3. checks the frozen signatures of supplied individual options;
                      4. resolves those sources against the draft’s schema; and
                      5. checks the draft with the resolved props.

                      Candidate-versus-caller failure classification and frozen property signatures remain unchanged.

                      Shared option roles

                      These options remain meaningful without --run because they participate in authorship, catalog construction, property admission, output selection, or the whole-command deadline:

                      • --output;
                      • --session;
                      • --include;
                      • --props and declared individual --props-* options;
                      • --agent-provider;
                      • --default-agent; and
                      • --timeout.

                      The following options configure only final Plan execution and are refused during fixed preflight unless --run is present:

                      • --verbose / -V;
                      • --journal / -j;
                      • --raw;
                      • --timeout-exec;
                      • --timeout-fetch;
                      • --approve-all;
                      • --approve-reads;
                      • --deny-all;
                      • --secret-detection; and
                      • --no-secret-detection.

                      Final-run permission flags cannot widen the prompt profile.

                      Help

                      xmd prompt --help is generic and effect-free. It documents:

                      • the Prompt positional;
                      • default byte-exact source output;
                      • --output;
                      • --run;
                      • --session;
                      • aggregate props;
                      • the individual-property ordering rule;
                      • shared authorship and admission options; and
                      • which final-run options require --run.

                      Help does not generate individual property options and does not:

                      • load the packaged prompt command document;
                      • build a syntax catalog;
                      • inspect a generated document;
                      • start an Agent;
                      • construct a prompt profile;
                      • elicit an answer;
                      • create a file or journal; or
                      • execute a Plan.

                      A complete Plan

                      A produced Plan begins, after optional frontmatter, with one descriptive level-one Markdown heading as its first body content.

                      The Plan then preserves:

                      • the Prompt’s sequence of readable steps;
                      • every requested outcome;
                      • meaningful ordering between those outcomes;
                      • reader-facing prose; and
                      • the XMD components beside the steps they perform.

                      For example:

                      # Ask for an age and save it
                      Ask me for my age.
                      <Elicit ... as="result" />
                      Write it to a file.
                      <Filepath="age.txt">{result.age}</File>

                      The Prompt need not be quoted literally. It may be divided, clarified, and rewritten as natural prose. The resulting Plan must remain understandable in the same order in which its actions execute.

                      The descriptive H1 and narrative-plus-components form are enforced through the initial, repair, and revision instructions and through human review. They are not hidden checks in TypeScript or validateDocument().

                      The packaged prompt command document

                      The host executes one exact checked-in Markdown value root, packaged as prompt-command.md, under the stable internal source identity <prompt-command>.

                      Its declared return schema is exactly:

                      { "type": "string" }

                      The host supplies these internal inputs:

                      • the original Prompt;
                      • the rendered run-profile syntax catalog;
                      • the resolved logical session name.

                      They are not Plan root props and consume none of the Plan’s property sources.

                      The document begins with the approved introduction in this issue and uses these visible stage headings:

                      ## Create the first draft## Check and repair the draft## Review the draft## Continue from your decision## Return the approved Plan

                      Stable explanations remain outside repeated loops where possible. The command document does not expose internal <Return> failure precedence to the user.

                      <Return> is internal control flow. It transfers the exact approved source from the command document to the trusted host and does not print that source.

                      Authorship Agent and Session

                      One enclosing <Session> expansion carries every Agent turn:

                      • the initial draft;
                      • automatic repairs;
                      • human-requested revisions; and
                      • the optional final explanation.

                      Sibling Sessions are not used. The same authored name on sibling Sessions would still represent distinct placements.

                      Without --session, the host generates an invocation-unique logical name. With --session <name>, the exact non-empty name replaces it. The default and named session-directory identities, preparation rules, cleanup rules, and continuation behavior remain unchanged.

                      The prompt profile gives the authorship Agent:

                      • its session-specific host-owned directory;
                      • no additional directories;
                      • no MCP servers;
                      • an empty native-tool allowlist;
                      • strict denial of every native permission request; and
                      • no document Files, command, service, or XMD-mediated network authority.

                      The provider’s own model transport does not grant the Agent a native network tool.

                      The host instruction layer establishes authority and common context. It does not require every Agent answer to be XMD source.

                      Each authored <Prompt> owns its own response contract:

                      • initial, repair, and revision turns request one complete replacement Plan as source only;
                      • the final explanation turn requests explanatory prose only.

                      A failed, cancelled, unavailable, or protocol-invalid Agent turn is terminal. Partial text never becomes a draft or explanation.

                      Drafts remain inert

                      Every Agent reply remains an inert string throughout prompt-profile execution.

                      The command document may:

                      • bind the string;
                      • pass it to <CheckDraft>;
                      • present it through <CodeBlock>;
                      • pass diagnostics into another Agent turn;
                      • retain it as the approved value; or
                      • return it to the host.

                      It never evaluates, imports, or executes a draft.

                      Only the exact approved source may proceed, and only after complete prompt-profile teardown and final host admission.

                      Internal draft checking

                      The prompt profile declares one protected internal value component:

                      <CheckDraftsource={draft}as="assessment" />

                      Repository component lookup cannot replace it.

                      <CheckDraft> checks an unapproved draft without executing it. Its behavior is the behavior previously assigned to the internal <ValidateCandidate> name.

                      For each draft it:

                      1. checks the supplied root declaration without execution;
                      2. derives bindings once a usable root property schema exists;
                      3. verifies every frozen supplied individual-option signature before consuming tokens;
                      4. resolves the original CLI and invocation-environment property sources; and
                      5. calls core’s validateDocument() with those props, the caller’s includes, and the run-profile declarations.

                      Core’s validateDocument() keeps its existing name. This issue introduces no generic public <Validate> component.

                      Draft-authored failures return structured problems eligible for repair, including:

                      • source and frontmatter failures;
                      • invalid root props or return declarations;
                      • binding collisions;
                      • missing required props; and
                      • other definite whole-document diagnostics.

                      Caller-authored failures raise terminally, including:

                      • malformed aggregate CLI or environment JSON;
                      • a supplied individual option not declared by the usable draft schema;
                      • a malformed individual value;
                      • an extra positional exposed by the draft’s arity; and
                      • a later schema removing a frozen option or changing its arity or accumulation behavior.

                      Caller-authored failures cause no repair, presentation, approval, output, journal, or execution.

                      <CheckDraft> reports structural facts only. It does not decide whether the H1 or prose adequately communicates the Prompt.

                      Create, check, and repair a draft

                      The first draft instruction requires:

                      • one complete replacement root as source only;
                      • optional frontmatter followed immediately by one descriptive H1;
                      • the Prompt’s complete sequence as readable prose;
                      • every requested outcome;
                      • meaningful ordering; and
                      • each XMD component beside the prose describing its action.

                      Each initial draft and each human-requested revision receives its own automatic repair budget:

                      • the base draft is attempt one;
                      • at most three repair turns may replace it;
                      • every repair prompt contains the complete structured draft diagnostics;
                      • every repair response is one complete replacement root; and
                      • repair instructions repeat the complete Plan requirements, including the descriptive H1.

                      The fourth invalid draft is repair-exhausted and proceeds to human review with its diagnostics.

                      No fence is stripped, Markdown substring extracted, or patch applied.

                      Human review

                      The command document permits at most ten draft presentations.

                      The exact Elicitation values are:

                      • Approve
                      • Request changes
                      • Stop
                      • Explain what went wrong

                      The offered decision set depends on validity and round:

                      Review stateOffered values
                      Valid, rounds 1–9Approve, Request changes, Stop
                      Invalid, rounds 1–9Request changes, Stop
                      Valid, round 10Approve, Stop
                      Invalid, round 10Explain what went wrong, Stop

                      Request changes requires non-empty feedback. It sends one complete-replacement revision request through the same enclosing Session and resets the automatic repair budget.

                      Revision instructions repeat the descriptive-H1 and narrative-plus-components requirements.

                      The review presents the exact draft through <CodeBlock>. Invalid reviews also present the complete structured diagnostics. Draft text cannot close the presentation fence and is never interpreted.

                      Approve binds the exact draft for return. It does not execute or print the draft.

                      Explanation after the final invalid draft

                      When the tenth presented draft is invalid, the person may select Explain what went wrong.

                      That choice:

                      1. makes one final <Prompt> turn in the same enclosing Session;
                      2. is not another draft, repair, revision, or review round;
                      3. relies on the Session’s existing conversation history;
                      4. supplies the final diagnostics, which the Agent has not previously seen;
                      5. asks why the attempts failed and what the person should clarify next time;
                      6. requests explanatory prose rather than document source;
                      7. treats the answer as inert text;
                      8. cannot return to drafting or approval; and
                      9. ends without source output, file output, journal, or Plan execution.

                      The explanation prompt supplies no draft, Prompt, catalog, or prior diagnostics again. Those remain available only through the existing Session history. Its new contextual data is the final diagnostics.

                      A failed explanation turn is terminal.

                      A successful explanation is reported through the command’s ordinary terminal failure reporting as the authored failure message. It is not written to source stdout and is not interpreted as XMD. The command exits nonzero because no Plan was approved.

                      No TypeScript or Agent API behavior implements this branch.

                      Command-document history and presentation

                      The prompt command document uses an invocation-owned in-memory durable stream because ordinary document and <Prompt> semantics require one.

                      That stream is:

                      • never written to --journal;
                      • never persisted as a workflow;
                      • never reused or replayed; and
                      • discarded after complete prompt-profile teardown.

                      The configured Agent provider may retain the named Session under its ordinary provider contract.

                      Command-document rendering is not successful CLI source output. Successful source output is written by the trusted host only after teardown and final admission.

                      Final admission

                      After the command document returns and its entire prompt-profile scope tears down successfully, the host treats the approved source as untrusted again.

                      The host repeats checking and property resolution using:

                      • the exact returned bytes;
                      • the original raw CLI and invocation-environment property sources;
                      • the frozen individual-option signatures;
                      • the caller’s ordered includes; and
                      • the ordinary run-profile declarations.

                      A final caller-source failure or document failure exits nonzero. It does not re-enter drafting or review.

                      The resolved props belong to the exact approved bytes. No props object from an earlier draft is reused.

                      No stdout source, output file, journal, or Plan execution begins before this admission succeeds.

                      The approved source is the CLI result

                      The exact approved source is the primary result of xmd prompt.

                      Default: print the source

                      xmd prompt "<Prompt>"

                      After teardown and final admission, the host writes the exact approved source to stdout.

                      It adds no fence, label, delimiter, or newline. It does not execute the Plan or create a generated-source file.

                      Write the source

                      xmd prompt "<Prompt>" --output <path>

                      After teardown and final admission, the host exclusively creates <path> with the exact approved bytes.

                      An existing target remains unchanged and fails the command. The command writes nothing to stdout and does not execute the Plan.

                      Run the Plan

                      xmd prompt "<Prompt>" --run

                      After teardown and final admission, the host executes:

                      retainedSource("<prompt>", source)
                      

                      through the ordinary supplied-source path.

                      The host does not print the source. Stdout belongs exclusively to the Plan’s ordinary output.

                      Write, then run

                      xmd prompt "<Prompt>" --output <path> --run

                      After teardown and final admission, the host exclusively creates the file first.

                      Execution begins only if file creation succeeds. An existing target or other write failure leaves the target unchanged where applicable and prevents execution.

                      The host does not print the source. Stdout belongs exclusively to the Plan.

                      A runtime failure does not return to authorship. A successfully created output file remains.

                      Journal behavior

                      Authorship never writes the final journal.

                      A diagnostic journal may be created only when:

                      • --run is present;
                      • --journal <path> is present; and
                      • final Plan execution is beginning.

                      Default source output and output-only mode create no journal.

                      The final journal contains no prompt command document, authorship Session, Agent turn, draft check, repair, human review, explanation, or approval event.

                      Authored failures

                      PathAuthored failure
                      Ordinary Stopxmd prompt stopped at your request. Nothing was output or run.
                      Stop on the final invalid draftxmd prompt reviewed ten drafts without an approved Plan. Nothing was output or run.
                      Unexpected post-Session fallback without approvalxmd prompt ended without an approved Plan. Nothing was output or run.
                      Successful final explanationThe coding agent’s explanation is the authored terminal failure message; no generic advice replaces it

                      An ordinary Stop includes stopping a valid tenth draft.

                      The final-invalid Stop is distinct from the explanation choice. It reports exhaustion without spending another Agent turn.

                      All authored failures are selected by the Markdown command document. They exit nonzero and produce no approved-source stdout, output file, final journal, or execution.

                      Cancellation and failure ordering

                      The whole-command deadline encloses:

                      • fixed preparation after argument admission;
                      • catalog construction;
                      • prompt-profile execution;
                      • Elicitation;
                      • explanation when selected;
                      • profile teardown;
                      • final admission;
                      • source output or exclusive file creation; and
                      • final execution when requested.

                      Cancellation stops active authorship and awaits structured teardown.

                      No final admission or output mode begins until prompt-profile execution and teardown both succeed. A teardown failure wins over an approved source.

                      Once ordinary Plan execution begins, its existing outcome and teardown precedence apply unchanged.

                      Acceptance matrix

                      The amended evidence replaces the superseded TypeScript-policy matrix.

                      IDBoundaryRequired evidence
                      P1Fixed grammarExactly one non-empty Prompt; individual --props-* options require the Prompt first; aggregate props retain ordinary placement
                      P2Effect-free helpGeneric help documents default output, --output, --run, --session, property ordering, and run-only flags without loading the packaged document or performing effects
                      P3Packaged command documentThe package-relative prompt-command.md is the exact root executed under <prompt-command> and cannot be replaced through component lookup
                      P4Approved document languageThe shipped document contains the approved introduction and the five visible stage headings
                      P5Complete Plan instructionsInitial, repair, and revision prompts require optional frontmatter followed by a descriptive H1, readable ordered steps, and components beside their prose
                      P6One SessionInitial drafting, repairs, revisions, and final explanation use one enclosing Session; default names differ and --session supplies the exact override
                      P7Prompt-profile authorityThe authorship Agent receives only the settled session directory and constrained authority; final-run flags cannot widen it
                      P8Draft inertnessNo draft is imported, evaluated, journaled as the final Plan, saved, printed as success, or executed before approval
                      P9Protected checker<CheckDraft> is the protected host-declared capability, repository lookup cannot replace it, and <ValidateCandidate> is absent
                      P10Failure classificationDraft-authored problems return structured facts; caller-authored failures escape terminally; frozen property signatures are checked before token consumption
                      P11Repair budgetEach base draft receives at most three repair turns; a human revision resets that budget
                      P12Friendly review valuesThe exact values and per-round decision sets are Approve, Request changes, Stop, and final-invalid-only Explain what went wrong
                      P13Revision feedbackRequest changes requires non-empty feedback and requests a complete replacement Plan preserving the H1 and narrative requirements
                      P14Final explanationFinal-invalid explanation makes exactly one additional <Prompt> turn in the same Session and supplies only the previously unseen final diagnostics as new context
                      P15Explanation is terminalExplanation cannot trigger checking, repair, presentation, revision, approval, or another Agent turn; its inert answer is reported and the command ends without a Plan
                      P16Authored stoppingOrdinary Stop, final-invalid Stop, unexpected fallback, and explanation use authored Markdown failure paths with the required messages or explanation
                      P17Final gateComplete prompt-profile teardown and final admission precede every successful output mode
                      P18Default stdoutDefault success writes the exact approved bytes to stdout with no fence, label, delimiter, or added newline and performs no execution
                      P19--outputOutput-only success exclusively creates a byte-identical file, writes no stdout, and performs no execution
                      P20Explicit --runPlan execution occurs only with --run, through the ordinary supplied-source path
                      P21Write before runWith --output --run, byte-identical exclusive creation completes before execution; write refusal prevents execution
                      P22Stdout ownershipSource bytes and runtime output never share stdout: default owns source stdout; run modes leave stdout entirely to the Plan
                      P23Run-only preflightEvery explicitly supplied run-only flag is refused before catalog or Agent work unless --run is present
                      P24Journal separationNo journal file is created without final execution; a requested journal begins only when --run starts and contains no authorship activity
                      P25Session-directory lifetimeInvocation-unique cleanup and named-directory preservation remain exactly as specified, with no recursive deletion
                      P26Exact bytes and propsApproval, final admission, stdout, --output, and execution use the exact returned bytes; final props are resolved for those bytes
                      P27Ordinary run behavior--run preserves ordinary cwd, includes, props, Agent configuration, permissions, timeouts, output, value, failures, and exit behavior
                      P28Teardown and cancellationCancellation and every teardown failure settle before final admission, source output, file output, journal creation, or execution

                      Use one discriminating regression for each distinct boundary. Do not restore permutations that existed only to prove the superseded TypeScript policy loop.

                      Dependencies and delivery

                      Delivered foundations remain:

                      PR #657 remains the focused implementation vehicle. Its issue #260 delivery includes:

                      • rename the packaged asset to prompt-command.md;
                      • rename PROMPT_PLAN and related source/test vocabulary to PROMPT_COMMAND;
                      • install the approved introduction and visible stage headings;
                      • strengthen initial, repair, and revision instructions with the complete Plan requirement;
                      • rename the protected internal checker to <CheckDraft>;
                      • install the exact friendly review values and round-specific decision sets;
                      • add the final same-Session explanation branch;
                      • remove any host instruction requiring every Agent response to be source;
                      • replace --save with --output, without an alias;
                      • make byte-exact stdout the default result;
                      • require --run for execution;
                      • enforce run-only option preflight;
                      • preserve final admission and complete teardown before every output mode;
                      • preserve output-file-before-run ordering;
                      • keep source stdout separate from Plan stdout;
                      • create a journal only when final execution begins;
                      • update architecture.md;
                      • rewrite specs/prompt-command-spec.md;
                      • update the affected prompt-command, Agent-provider, property-binding, CLI, and Tier PR sections of the specifications; and
                      • add the revised acceptance evidence.

                      The architecture review of feedback commit 1e449879c04e7c458ff6738ae13c2da8abb290dd is not reopened by this amendment. The next feedback commit is reviewed against this amended contract.

                      Out of scope

                      • arbitrary custom prompt command documents;
                      • public or reusable <Plan>;
                      • --plan and --plan-eval;
                      • File or Glob authorship context;
                      • a generic public <Validate>;
                      • a general arbitrary-code sandbox;
                      • the collaborative playground;
                      • stdin or editor Prompt input;
                      • automatic revision after runtime failure;
                      • a terminal Elicitation provider; and
                      • durable journaling or workflow replay of authorship.

                      Activity

                      Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

                      Metadata

                      Metadata

                      Assignees

                      No one assigned

                        Labels

                        No labels
                        No labels

                        Projects

                        No projects

                          Milestone

                          No milestone

                          Relationships

                          None yet

                          Development

                          No branches or pull requests

                          Issue actions

                          , 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
                          Skip to content

                          Add xmd prompt: turn a request into an approved executable Plan #260

                          Description

                          @taras

                          Motivation

                          xmd prompt turns steps into a program

                          This document is a workflow that generates an executable Plan from a sequence of steps. It combines the original Prompt, which describes those steps, with the XMD components available to carry them out. A coding agent turns both into one document that explains and executes the sequence.

                          The result is the XMD version of a coding agent’s plan. A conventional Markdown plan must be interpreted again before its steps can happen. An XMD Plan already contains those executable steps, so running it simply executes them.

                          A draft remains text while this workflow reviews it. Nothing in it runs before you approve it. After approval, xmd prompt validates the exact source again. By default it prints the approved XMD source. --output writes that source to a file instead, and --run executes the Plan. With both options, the command writes the source before running it.

                          xmd prompt "ask me for my age and write it to a file"

                          xmd run -e executes a program someone already wrote. xmd prompt performs the preceding conversion and review. It adds no second execution model.

                          Terminology

                          These terms are used precisely:

                          • A Prompt is the person’s original natural-language request.
                          • A Plan is the executable XMD program produced from that Prompt.
                          • A Plan combines reader-facing prose expressing the Prompt’s intent with the XMD components that carry it out.
                          • xmd prompt converts a Prompt into an approved Plan.
                          • The prompt command document is the packaged Markdown workflow that performs generation, checking, review, revision, approval, stopping, explanation, and exhaustion. It is not itself a Plan.
                          • The prompt profile is the constrained trusted-host context under which that document runs.
                          • A draft is candidate Plan source that has not been approved. It remains inert text.

                          “Plan” is not a generic synonym for a workflow, policy document, command implementation, arbitrary XMD document, or the packaged prompt command document.

                          The reusable or custom <Plan> surface remains separate in #660.

                          Architecture

                          The trusted host owns two root executions with complete teardown between them:

                          fixed command preflight
                          -> build the run-profile syntax catalog
                          -> execute the exact packaged prompt command document
                          -> one enclosing Session
                          -> draft, check, repair, review, revise, approve, stop, explain, or exhaust
                          -> Return the exact approved Plan source
                          -> await prompt-profile execution and complete provider teardown
                          -> admit the returned source again
                          -> perform exactly the selected output mode:
                          -> print the exact source; or
                          -> exclusively create an output file; or
                          -> execute through the ordinary supplied-source path; or
                          -> create the output file and then execute
                          

                          The packaged Markdown owns:

                          • drafting;
                          • repair;
                          • diagnostic presentation;
                          • review;
                          • revision;
                          • approval;
                          • stopping;
                          • final-invalid explanation;
                          • authored failure; and
                          • finite exhaustion.

                          Trusted TypeScript owns:

                          • fixed command parsing and preflight;
                          • prompt-profile assembly;
                          • syntax-catalog construction;
                          • property-source parsing and frozen option signatures;
                          • non-executing draft checking;
                          • complete prompt-profile teardown;
                          • final admission;
                          • byte-exact stdout;
                          • exclusive output-file creation; and
                          • ordinary supplied-source execution.

                          No drafting, retry, review, revision, explanation, or exhaustion policy belongs in TypeScript, <Prompt>, or the Agent API.

                          Command surface

                          xmd prompt <Prompt> [--output <path>] [--run] [--session <name>] \ [shared options] [--props-<name> <value>]…

                          The Prompt is exactly one positional string containing at least one non-whitespace character. Missing, repeated, empty, and whitespace-only Prompts fail during fixed preflight.

                          -- ends option parsing, allowing a dash-leading Prompt.

                          The command adds:

                          • --output <path> — exclusively create a file containing the exact approved source;
                          • --run — execute the approved Plan after final admission and any requested output-file creation;
                          • --session <name> — replace the invocation-unique authorship session name with a non-empty explicit name.

                          The unreleased --save spelling is removed. It has no compatibility alias.

                          -e and --eval remain exclusive to xmd run.

                          Property arguments

                          The non-empty Prompt must appear before every individual --props-* option. An individual property option before the Prompt is refused during fixed preflight.

                          Known fixed-arity options, including aggregate --props, may appear before the Prompt.

                          For every initial or revised draft, the host:

                          1. inspects the root declaration without execution;
                          2. derives property bindings from the original CLI and invocation-environment sources;
                          3. checks the frozen signatures of supplied individual options;
                          4. resolves those sources against the draft’s schema; and
                          5. checks the draft with the resolved props.

                          Candidate-versus-caller failure classification and frozen property signatures remain unchanged.

                          Shared option roles

                          These options remain meaningful without --run because they participate in authorship, catalog construction, property admission, output selection, or the whole-command deadline:

                          • --output;
                          • --session;
                          • --include;
                          • --props and declared individual --props-* options;
                          • --agent-provider;
                          • --default-agent; and
                          • --timeout.

                          The following options configure only final Plan execution and are refused during fixed preflight unless --run is present:

                          • --verbose / -V;
                          • --journal / -j;
                          • --raw;
                          • --timeout-exec;
                          • --timeout-fetch;
                          • --approve-all;
                          • --approve-reads;
                          • --deny-all;
                          • --secret-detection; and
                          • --no-secret-detection.

                          Final-run permission flags cannot widen the prompt profile.

                          Help

                          xmd prompt --help is generic and effect-free. It documents:

                          • the Prompt positional;
                          • default byte-exact source output;
                          • --output;
                          • --run;
                          • --session;
                          • aggregate props;
                          • the individual-property ordering rule;
                          • shared authorship and admission options; and
                          • which final-run options require --run.

                          Help does not generate individual property options and does not:

                          • load the packaged prompt command document;
                          • build a syntax catalog;
                          • inspect a generated document;
                          • start an Agent;
                          • construct a prompt profile;
                          • elicit an answer;
                          • create a file or journal; or
                          • execute a Plan.

                          A complete Plan

                          A produced Plan begins, after optional frontmatter, with one descriptive level-one Markdown heading as its first body content.

                          The Plan then preserves:

                          • the Prompt’s sequence of readable steps;
                          • every requested outcome;
                          • meaningful ordering between those outcomes;
                          • reader-facing prose; and
                          • the XMD components beside the steps they perform.

                          For example:

                          # Ask for an age and save it
                          Ask me for my age.
                          <Elicit ... as="result" />
                          Write it to a file.
                          <Filepath="age.txt">{result.age}</File>

                          The Prompt need not be quoted literally. It may be divided, clarified, and rewritten as natural prose. The resulting Plan must remain understandable in the same order in which its actions execute.

                          The descriptive H1 and narrative-plus-components form are enforced through the initial, repair, and revision instructions and through human review. They are not hidden checks in TypeScript or validateDocument().

                          The packaged prompt command document

                          The host executes one exact checked-in Markdown value root, packaged as prompt-command.md, under the stable internal source identity <prompt-command>.

                          Its declared return schema is exactly:

                          { "type": "string" }

                          The host supplies these internal inputs:

                          • the original Prompt;
                          • the rendered run-profile syntax catalog;
                          • the resolved logical session name.

                          They are not Plan root props and consume none of the Plan’s property sources.

                          The document begins with the approved introduction in this issue and uses these visible stage headings:

                          ## Create the first draft## Check and repair the draft## Review the draft## Continue from your decision## Return the approved Plan

                          Stable explanations remain outside repeated loops where possible. The command document does not expose internal <Return> failure precedence to the user.

                          <Return> is internal control flow. It transfers the exact approved source from the command document to the trusted host and does not print that source.

                          Authorship Agent and Session

                          One enclosing <Session> expansion carries every Agent turn:

                          • the initial draft;
                          • automatic repairs;
                          • human-requested revisions; and
                          • the optional final explanation.

                          Sibling Sessions are not used. The same authored name on sibling Sessions would still represent distinct placements.

                          Without --session, the host generates an invocation-unique logical name. With --session <name>, the exact non-empty name replaces it. The default and named session-directory identities, preparation rules, cleanup rules, and continuation behavior remain unchanged.

                          The prompt profile gives the authorship Agent:

                          • its session-specific host-owned directory;
                          • no additional directories;
                          • no MCP servers;
                          • an empty native-tool allowlist;
                          • strict denial of every native permission request; and
                          • no document Files, command, service, or XMD-mediated network authority.

                          The provider’s own model transport does not grant the Agent a native network tool.

                          The host instruction layer establishes authority and common context. It does not require every Agent answer to be XMD source.

                          Each authored <Prompt> owns its own response contract:

                          • initial, repair, and revision turns request one complete replacement Plan as source only;
                          • the final explanation turn requests explanatory prose only.

                          A failed, cancelled, unavailable, or protocol-invalid Agent turn is terminal. Partial text never becomes a draft or explanation.

                          Drafts remain inert

                          Every Agent reply remains an inert string throughout prompt-profile execution.

                          The command document may:

                          • bind the string;
                          • pass it to <CheckDraft>;
                          • present it through <CodeBlock>;
                          • pass diagnostics into another Agent turn;
                          • retain it as the approved value; or
                          • return it to the host.

                          It never evaluates, imports, or executes a draft.

                          Only the exact approved source may proceed, and only after complete prompt-profile teardown and final host admission.

                          Internal draft checking

                          The prompt profile declares one protected internal value component:

                          <CheckDraftsource={draft}as="assessment" />

                          Repository component lookup cannot replace it.

                          <CheckDraft> checks an unapproved draft without executing it. Its behavior is the behavior previously assigned to the internal <ValidateCandidate> name.

                          For each draft it:

                          1. checks the supplied root declaration without execution;
                          2. derives bindings once a usable root property schema exists;
                          3. verifies every frozen supplied individual-option signature before consuming tokens;
                          4. resolves the original CLI and invocation-environment property sources; and
                          5. calls core’s validateDocument() with those props, the caller’s includes, and the run-profile declarations.

                          Core’s validateDocument() keeps its existing name. This issue introduces no generic public <Validate> component.

                          Draft-authored failures return structured problems eligible for repair, including:

                          • source and frontmatter failures;
                          • invalid root props or return declarations;
                          • binding collisions;
                          • missing required props; and
                          • other definite whole-document diagnostics.

                          Caller-authored failures raise terminally, including:

                          • malformed aggregate CLI or environment JSON;
                          • a supplied individual option not declared by the usable draft schema;
                          • a malformed individual value;
                          • an extra positional exposed by the draft’s arity; and
                          • a later schema removing a frozen option or changing its arity or accumulation behavior.

                          Caller-authored failures cause no repair, presentation, approval, output, journal, or execution.

                          <CheckDraft> reports structural facts only. It does not decide whether the H1 or prose adequately communicates the Prompt.

                          Create, check, and repair a draft

                          The first draft instruction requires:

                          • one complete replacement root as source only;
                          • optional frontmatter followed immediately by one descriptive H1;
                          • the Prompt’s complete sequence as readable prose;
                          • every requested outcome;
                          • meaningful ordering; and
                          • each XMD component beside the prose describing its action.

                          Each initial draft and each human-requested revision receives its own automatic repair budget:

                          • the base draft is attempt one;
                          • at most three repair turns may replace it;
                          • every repair prompt contains the complete structured draft diagnostics;
                          • every repair response is one complete replacement root; and
                          • repair instructions repeat the complete Plan requirements, including the descriptive H1.

                          The fourth invalid draft is repair-exhausted and proceeds to human review with its diagnostics.

                          No fence is stripped, Markdown substring extracted, or patch applied.

                          Human review

                          The command document permits at most ten draft presentations.

                          The exact Elicitation values are:

                          • Approve
                          • Request changes
                          • Stop
                          • Explain what went wrong

                          The offered decision set depends on validity and round:

                          Review stateOffered values
                          Valid, rounds 1–9Approve, Request changes, Stop
                          Invalid, rounds 1–9Request changes, Stop
                          Valid, round 10Approve, Stop
                          Invalid, round 10Explain what went wrong, Stop

                          Request changes requires non-empty feedback. It sends one complete-replacement revision request through the same enclosing Session and resets the automatic repair budget.

                          Revision instructions repeat the descriptive-H1 and narrative-plus-components requirements.

                          The review presents the exact draft through <CodeBlock>. Invalid reviews also present the complete structured diagnostics. Draft text cannot close the presentation fence and is never interpreted.

                          Approve binds the exact draft for return. It does not execute or print the draft.

                          Explanation after the final invalid draft

                          When the tenth presented draft is invalid, the person may select Explain what went wrong.

                          That choice:

                          1. makes one final <Prompt> turn in the same enclosing Session;
                          2. is not another draft, repair, revision, or review round;
                          3. relies on the Session’s existing conversation history;
                          4. supplies the final diagnostics, which the Agent has not previously seen;
                          5. asks why the attempts failed and what the person should clarify next time;
                          6. requests explanatory prose rather than document source;
                          7. treats the answer as inert text;
                          8. cannot return to drafting or approval; and
                          9. ends without source output, file output, journal, or Plan execution.

                          The explanation prompt supplies no draft, Prompt, catalog, or prior diagnostics again. Those remain available only through the existing Session history. Its new contextual data is the final diagnostics.

                          A failed explanation turn is terminal.

                          A successful explanation is reported through the command’s ordinary terminal failure reporting as the authored failure message. It is not written to source stdout and is not interpreted as XMD. The command exits nonzero because no Plan was approved.

                          No TypeScript or Agent API behavior implements this branch.

                          Command-document history and presentation

                          The prompt command document uses an invocation-owned in-memory durable stream because ordinary document and <Prompt> semantics require one.

                          That stream is:

                          • never written to --journal;
                          • never persisted as a workflow;
                          • never reused or replayed; and
                          • discarded after complete prompt-profile teardown.

                          The configured Agent provider may retain the named Session under its ordinary provider contract.

                          Command-document rendering is not successful CLI source output. Successful source output is written by the trusted host only after teardown and final admission.

                          Final admission

                          After the command document returns and its entire prompt-profile scope tears down successfully, the host treats the approved source as untrusted again.

                          The host repeats checking and property resolution using:

                          • the exact returned bytes;
                          • the original raw CLI and invocation-environment property sources;
                          • the frozen individual-option signatures;
                          • the caller’s ordered includes; and
                          • the ordinary run-profile declarations.

                          A final caller-source failure or document failure exits nonzero. It does not re-enter drafting or review.

                          The resolved props belong to the exact approved bytes. No props object from an earlier draft is reused.

                          No stdout source, output file, journal, or Plan execution begins before this admission succeeds.

                          The approved source is the CLI result

                          The exact approved source is the primary result of xmd prompt.

                          Default: print the source

                          xmd prompt "<Prompt>"

                          After teardown and final admission, the host writes the exact approved source to stdout.

                          It adds no fence, label, delimiter, or newline. It does not execute the Plan or create a generated-source file.

                          Write the source

                          xmd prompt "<Prompt>" --output <path>

                          After teardown and final admission, the host exclusively creates <path> with the exact approved bytes.

                          An existing target remains unchanged and fails the command. The command writes nothing to stdout and does not execute the Plan.

                          Run the Plan

                          xmd prompt "<Prompt>" --run

                          After teardown and final admission, the host executes:

                          retainedSource("<prompt>", source)
                          

                          through the ordinary supplied-source path.

                          The host does not print the source. Stdout belongs exclusively to the Plan’s ordinary output.

                          Write, then run

                          xmd prompt "<Prompt>" --output <path> --run

                          After teardown and final admission, the host exclusively creates the file first.

                          Execution begins only if file creation succeeds. An existing target or other write failure leaves the target unchanged where applicable and prevents execution.

                          The host does not print the source. Stdout belongs exclusively to the Plan.

                          A runtime failure does not return to authorship. A successfully created output file remains.

                          Journal behavior

                          Authorship never writes the final journal.

                          A diagnostic journal may be created only when:

                          • --run is present;
                          • --journal <path> is present; and
                          • final Plan execution is beginning.

                          Default source output and output-only mode create no journal.

                          The final journal contains no prompt command document, authorship Session, Agent turn, draft check, repair, human review, explanation, or approval event.

                          Authored failures

                          PathAuthored failure
                          Ordinary Stopxmd prompt stopped at your request. Nothing was output or run.
                          Stop on the final invalid draftxmd prompt reviewed ten drafts without an approved Plan. Nothing was output or run.
                          Unexpected post-Session fallback without approvalxmd prompt ended without an approved Plan. Nothing was output or run.
                          Successful final explanationThe coding agent’s explanation is the authored terminal failure message; no generic advice replaces it

                          An ordinary Stop includes stopping a valid tenth draft.

                          The final-invalid Stop is distinct from the explanation choice. It reports exhaustion without spending another Agent turn.

                          All authored failures are selected by the Markdown command document. They exit nonzero and produce no approved-source stdout, output file, final journal, or execution.

                          Cancellation and failure ordering

                          The whole-command deadline encloses:

                          • fixed preparation after argument admission;
                          • catalog construction;
                          • prompt-profile execution;
                          • Elicitation;
                          • explanation when selected;
                          • profile teardown;
                          • final admission;
                          • source output or exclusive file creation; and
                          • final execution when requested.

                          Cancellation stops active authorship and awaits structured teardown.

                          No final admission or output mode begins until prompt-profile execution and teardown both succeed. A teardown failure wins over an approved source.

                          Once ordinary Plan execution begins, its existing outcome and teardown precedence apply unchanged.

                          Acceptance matrix

                          The amended evidence replaces the superseded TypeScript-policy matrix.

                          IDBoundaryRequired evidence
                          P1Fixed grammarExactly one non-empty Prompt; individual --props-* options require the Prompt first; aggregate props retain ordinary placement
                          P2Effect-free helpGeneric help documents default output, --output, --run, --session, property ordering, and run-only flags without loading the packaged document or performing effects
                          P3Packaged command documentThe package-relative prompt-command.md is the exact root executed under <prompt-command> and cannot be replaced through component lookup
                          P4Approved document languageThe shipped document contains the approved introduction and the five visible stage headings
                          P5Complete Plan instructionsInitial, repair, and revision prompts require optional frontmatter followed by a descriptive H1, readable ordered steps, and components beside their prose
                          P6One SessionInitial drafting, repairs, revisions, and final explanation use one enclosing Session; default names differ and --session supplies the exact override
                          P7Prompt-profile authorityThe authorship Agent receives only the settled session directory and constrained authority; final-run flags cannot widen it
                          P8Draft inertnessNo draft is imported, evaluated, journaled as the final Plan, saved, printed as success, or executed before approval
                          P9Protected checker<CheckDraft> is the protected host-declared capability, repository lookup cannot replace it, and <ValidateCandidate> is absent
                          P10Failure classificationDraft-authored problems return structured facts; caller-authored failures escape terminally; frozen property signatures are checked before token consumption
                          P11Repair budgetEach base draft receives at most three repair turns; a human revision resets that budget
                          P12Friendly review valuesThe exact values and per-round decision sets are Approve, Request changes, Stop, and final-invalid-only Explain what went wrong
                          P13Revision feedbackRequest changes requires non-empty feedback and requests a complete replacement Plan preserving the H1 and narrative requirements
                          P14Final explanationFinal-invalid explanation makes exactly one additional <Prompt> turn in the same Session and supplies only the previously unseen final diagnostics as new context
                          P15Explanation is terminalExplanation cannot trigger checking, repair, presentation, revision, approval, or another Agent turn; its inert answer is reported and the command ends without a Plan
                          P16Authored stoppingOrdinary Stop, final-invalid Stop, unexpected fallback, and explanation use authored Markdown failure paths with the required messages or explanation
                          P17Final gateComplete prompt-profile teardown and final admission precede every successful output mode
                          P18Default stdoutDefault success writes the exact approved bytes to stdout with no fence, label, delimiter, or added newline and performs no execution
                          P19--outputOutput-only success exclusively creates a byte-identical file, writes no stdout, and performs no execution
                          P20Explicit --runPlan execution occurs only with --run, through the ordinary supplied-source path
                          P21Write before runWith --output --run, byte-identical exclusive creation completes before execution; write refusal prevents execution
                          P22Stdout ownershipSource bytes and runtime output never share stdout: default owns source stdout; run modes leave stdout entirely to the Plan
                          P23Run-only preflightEvery explicitly supplied run-only flag is refused before catalog or Agent work unless --run is present
                          P24Journal separationNo journal file is created without final execution; a requested journal begins only when --run starts and contains no authorship activity
                          P25Session-directory lifetimeInvocation-unique cleanup and named-directory preservation remain exactly as specified, with no recursive deletion
                          P26Exact bytes and propsApproval, final admission, stdout, --output, and execution use the exact returned bytes; final props are resolved for those bytes
                          P27Ordinary run behavior--run preserves ordinary cwd, includes, props, Agent configuration, permissions, timeouts, output, value, failures, and exit behavior
                          P28Teardown and cancellationCancellation and every teardown failure settle before final admission, source output, file output, journal creation, or execution

                          Use one discriminating regression for each distinct boundary. Do not restore permutations that existed only to prove the superseded TypeScript policy loop.

                          Dependencies and delivery

                          Delivered foundations remain:

                          PR #657 remains the focused implementation vehicle. Its issue #260 delivery includes:

                          • rename the packaged asset to prompt-command.md;
                          • rename PROMPT_PLAN and related source/test vocabulary to PROMPT_COMMAND;
                          • install the approved introduction and visible stage headings;
                          • strengthen initial, repair, and revision instructions with the complete Plan requirement;
                          • rename the protected internal checker to <CheckDraft>;
                          • install the exact friendly review values and round-specific decision sets;
                          • add the final same-Session explanation branch;
                          • remove any host instruction requiring every Agent response to be source;
                          • replace --save with --output, without an alias;
                          • make byte-exact stdout the default result;
                          • require --run for execution;
                          • enforce run-only option preflight;
                          • preserve final admission and complete teardown before every output mode;
                          • preserve output-file-before-run ordering;
                          • keep source stdout separate from Plan stdout;
                          • create a journal only when final execution begins;
                          • update architecture.md;
                          • rewrite specs/prompt-command-spec.md;
                          • update the affected prompt-command, Agent-provider, property-binding, CLI, and Tier PR sections of the specifications; and
                          • add the revised acceptance evidence.

                          The architecture review of feedback commit 1e449879c04e7c458ff6738ae13c2da8abb290dd is not reopened by this amendment. The next feedback commit is reviewed against this amended contract.

                          Out of scope

                          • arbitrary custom prompt command documents;
                          • public or reusable <Plan>;
                          • --plan and --plan-eval;
                          • File or Glob authorship context;
                          • a generic public <Validate>;
                          • a general arbitrary-code sandbox;
                          • the collaborative playground;
                          • stdin or editor Prompt input;
                          • automatic revision after runtime failure;
                          • a terminal Elicitation provider; and
                          • durable journaling or workflow replay of authorship.

                          Activity

                          Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

                          Metadata

                          Metadata

                          Assignees

                          No one assigned

                            Labels

                            No labels
                            No labels

                            Projects

                            No projects

                              Milestone

                              No milestone

                              Relationships

                              None yet

                              Development

                              No branches or pull requests

                              Issue actions

                              , 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
                              Skip to content

                              Add xmd prompt: turn a request into an approved executable Plan #260

                              Description

                              @taras

                              Motivation

                              xmd prompt turns steps into a program

                              This document is a workflow that generates an executable Plan from a sequence of steps. It combines the original Prompt, which describes those steps, with the XMD components available to carry them out. A coding agent turns both into one document that explains and executes the sequence.

                              The result is the XMD version of a coding agent’s plan. A conventional Markdown plan must be interpreted again before its steps can happen. An XMD Plan already contains those executable steps, so running it simply executes them.

                              A draft remains text while this workflow reviews it. Nothing in it runs before you approve it. After approval, xmd prompt validates the exact source again. By default it prints the approved XMD source. --output writes that source to a file instead, and --run executes the Plan. With both options, the command writes the source before running it.

                              xmd prompt "ask me for my age and write it to a file"

                              xmd run -e executes a program someone already wrote. xmd prompt performs the preceding conversion and review. It adds no second execution model.

                              Terminology

                              These terms are used precisely:

                              • A Prompt is the person’s original natural-language request.
                              • A Plan is the executable XMD program produced from that Prompt.
                              • A Plan combines reader-facing prose expressing the Prompt’s intent with the XMD components that carry it out.
                              • xmd prompt converts a Prompt into an approved Plan.
                              • The prompt command document is the packaged Markdown workflow that performs generation, checking, review, revision, approval, stopping, explanation, and exhaustion. It is not itself a Plan.
                              • The prompt profile is the constrained trusted-host context under which that document runs.
                              • A draft is candidate Plan source that has not been approved. It remains inert text.

                              “Plan” is not a generic synonym for a workflow, policy document, command implementation, arbitrary XMD document, or the packaged prompt command document.

                              The reusable or custom <Plan> surface remains separate in #660.

                              Architecture

                              The trusted host owns two root executions with complete teardown between them:

                              fixed command preflight
                              -> build the run-profile syntax catalog
                              -> execute the exact packaged prompt command document
                              -> one enclosing Session
                              -> draft, check, repair, review, revise, approve, stop, explain, or exhaust
                              -> Return the exact approved Plan source
                              -> await prompt-profile execution and complete provider teardown
                              -> admit the returned source again
                              -> perform exactly the selected output mode:
                              -> print the exact source; or
                              -> exclusively create an output file; or
                              -> execute through the ordinary supplied-source path; or
                              -> create the output file and then execute
                              

                              The packaged Markdown owns:

                              • drafting;
                              • repair;
                              • diagnostic presentation;
                              • review;
                              • revision;
                              • approval;
                              • stopping;
                              • final-invalid explanation;
                              • authored failure; and
                              • finite exhaustion.

                              Trusted TypeScript owns:

                              • fixed command parsing and preflight;
                              • prompt-profile assembly;
                              • syntax-catalog construction;
                              • property-source parsing and frozen option signatures;
                              • non-executing draft checking;
                              • complete prompt-profile teardown;
                              • final admission;
                              • byte-exact stdout;
                              • exclusive output-file creation; and
                              • ordinary supplied-source execution.

                              No drafting, retry, review, revision, explanation, or exhaustion policy belongs in TypeScript, <Prompt>, or the Agent API.

                              Command surface

                              xmd prompt <Prompt> [--output <path>] [--run] [--session <name>] \ [shared options] [--props-<name> <value>]…

                              The Prompt is exactly one positional string containing at least one non-whitespace character. Missing, repeated, empty, and whitespace-only Prompts fail during fixed preflight.

                              -- ends option parsing, allowing a dash-leading Prompt.

                              The command adds:

                              • --output <path> — exclusively create a file containing the exact approved source;
                              • --run — execute the approved Plan after final admission and any requested output-file creation;
                              • --session <name> — replace the invocation-unique authorship session name with a non-empty explicit name.

                              The unreleased --save spelling is removed. It has no compatibility alias.

                              -e and --eval remain exclusive to xmd run.

                              Property arguments

                              The non-empty Prompt must appear before every individual --props-* option. An individual property option before the Prompt is refused during fixed preflight.

                              Known fixed-arity options, including aggregate --props, may appear before the Prompt.

                              For every initial or revised draft, the host:

                              1. inspects the root declaration without execution;
                              2. derives property bindings from the original CLI and invocation-environment sources;
                              3. checks the frozen signatures of supplied individual options;
                              4. resolves those sources against the draft’s schema; and
                              5. checks the draft with the resolved props.

                              Candidate-versus-caller failure classification and frozen property signatures remain unchanged.

                              Shared option roles

                              These options remain meaningful without --run because they participate in authorship, catalog construction, property admission, output selection, or the whole-command deadline:

                              • --output;
                              • --session;
                              • --include;
                              • --props and declared individual --props-* options;
                              • --agent-provider;
                              • --default-agent; and
                              • --timeout.

                              The following options configure only final Plan execution and are refused during fixed preflight unless --run is present:

                              • --verbose / -V;
                              • --journal / -j;
                              • --raw;
                              • --timeout-exec;
                              • --timeout-fetch;
                              • --approve-all;
                              • --approve-reads;
                              • --deny-all;
                              • --secret-detection; and
                              • --no-secret-detection.

                              Final-run permission flags cannot widen the prompt profile.

                              Help

                              xmd prompt --help is generic and effect-free. It documents:

                              • the Prompt positional;
                              • default byte-exact source output;
                              • --output;
                              • --run;
                              • --session;
                              • aggregate props;
                              • the individual-property ordering rule;
                              • shared authorship and admission options; and
                              • which final-run options require --run.

                              Help does not generate individual property options and does not:

                              • load the packaged prompt command document;
                              • build a syntax catalog;
                              • inspect a generated document;
                              • start an Agent;
                              • construct a prompt profile;
                              • elicit an answer;
                              • create a file or journal; or
                              • execute a Plan.

                              A complete Plan

                              A produced Plan begins, after optional frontmatter, with one descriptive level-one Markdown heading as its first body content.

                              The Plan then preserves:

                              • the Prompt’s sequence of readable steps;
                              • every requested outcome;
                              • meaningful ordering between those outcomes;
                              • reader-facing prose; and
                              • the XMD components beside the steps they perform.

                              For example:

                              # Ask for an age and save it
                              Ask me for my age.
                              <Elicit ... as="result" />
                              Write it to a file.
                              <Filepath="age.txt">{result.age}</File>

                              The Prompt need not be quoted literally. It may be divided, clarified, and rewritten as natural prose. The resulting Plan must remain understandable in the same order in which its actions execute.

                              The descriptive H1 and narrative-plus-components form are enforced through the initial, repair, and revision instructions and through human review. They are not hidden checks in TypeScript or validateDocument().

                              The packaged prompt command document

                              The host executes one exact checked-in Markdown value root, packaged as prompt-command.md, under the stable internal source identity <prompt-command>.

                              Its declared return schema is exactly:

                              { "type": "string" }

                              The host supplies these internal inputs:

                              • the original Prompt;
                              • the rendered run-profile syntax catalog;
                              • the resolved logical session name.

                              They are not Plan root props and consume none of the Plan’s property sources.

                              The document begins with the approved introduction in this issue and uses these visible stage headings:

                              ## Create the first draft## Check and repair the draft## Review the draft## Continue from your decision## Return the approved Plan

                              Stable explanations remain outside repeated loops where possible. The command document does not expose internal <Return> failure precedence to the user.

                              <Return> is internal control flow. It transfers the exact approved source from the command document to the trusted host and does not print that source.

                              Authorship Agent and Session

                              One enclosing <Session> expansion carries every Agent turn:

                              • the initial draft;
                              • automatic repairs;
                              • human-requested revisions; and
                              • the optional final explanation.

                              Sibling Sessions are not used. The same authored name on sibling Sessions would still represent distinct placements.

                              Without --session, the host generates an invocation-unique logical name. With --session <name>, the exact non-empty name replaces it. The default and named session-directory identities, preparation rules, cleanup rules, and continuation behavior remain unchanged.

                              The prompt profile gives the authorship Agent:

                              • its session-specific host-owned directory;
                              • no additional directories;
                              • no MCP servers;
                              • an empty native-tool allowlist;
                              • strict denial of every native permission request; and
                              • no document Files, command, service, or XMD-mediated network authority.

                              The provider’s own model transport does not grant the Agent a native network tool.

                              The host instruction layer establishes authority and common context. It does not require every Agent answer to be XMD source.

                              Each authored <Prompt> owns its own response contract:

                              • initial, repair, and revision turns request one complete replacement Plan as source only;
                              • the final explanation turn requests explanatory prose only.

                              A failed, cancelled, unavailable, or protocol-invalid Agent turn is terminal. Partial text never becomes a draft or explanation.

                              Drafts remain inert

                              Every Agent reply remains an inert string throughout prompt-profile execution.

                              The command document may:

                              • bind the string;
                              • pass it to <CheckDraft>;
                              • present it through <CodeBlock>;
                              • pass diagnostics into another Agent turn;
                              • retain it as the approved value; or
                              • return it to the host.

                              It never evaluates, imports, or executes a draft.

                              Only the exact approved source may proceed, and only after complete prompt-profile teardown and final host admission.

                              Internal draft checking

                              The prompt profile declares one protected internal value component:

                              <CheckDraftsource={draft}as="assessment" />

                              Repository component lookup cannot replace it.

                              <CheckDraft> checks an unapproved draft without executing it. Its behavior is the behavior previously assigned to the internal <ValidateCandidate> name.

                              For each draft it:

                              1. checks the supplied root declaration without execution;
                              2. derives bindings once a usable root property schema exists;
                              3. verifies every frozen supplied individual-option signature before consuming tokens;
                              4. resolves the original CLI and invocation-environment property sources; and
                              5. calls core’s validateDocument() with those props, the caller’s includes, and the run-profile declarations.

                              Core’s validateDocument() keeps its existing name. This issue introduces no generic public <Validate> component.

                              Draft-authored failures return structured problems eligible for repair, including:

                              • source and frontmatter failures;
                              • invalid root props or return declarations;
                              • binding collisions;
                              • missing required props; and
                              • other definite whole-document diagnostics.

                              Caller-authored failures raise terminally, including:

                              • malformed aggregate CLI or environment JSON;
                              • a supplied individual option not declared by the usable draft schema;
                              • a malformed individual value;
                              • an extra positional exposed by the draft’s arity; and
                              • a later schema removing a frozen option or changing its arity or accumulation behavior.

                              Caller-authored failures cause no repair, presentation, approval, output, journal, or execution.

                              <CheckDraft> reports structural facts only. It does not decide whether the H1 or prose adequately communicates the Prompt.

                              Create, check, and repair a draft

                              The first draft instruction requires:

                              • one complete replacement root as source only;
                              • optional frontmatter followed immediately by one descriptive H1;
                              • the Prompt’s complete sequence as readable prose;
                              • every requested outcome;
                              • meaningful ordering; and
                              • each XMD component beside the prose describing its action.

                              Each initial draft and each human-requested revision receives its own automatic repair budget:

                              • the base draft is attempt one;
                              • at most three repair turns may replace it;
                              • every repair prompt contains the complete structured draft diagnostics;
                              • every repair response is one complete replacement root; and
                              • repair instructions repeat the complete Plan requirements, including the descriptive H1.

                              The fourth invalid draft is repair-exhausted and proceeds to human review with its diagnostics.

                              No fence is stripped, Markdown substring extracted, or patch applied.

                              Human review

                              The command document permits at most ten draft presentations.

                              The exact Elicitation values are:

                              • Approve
                              • Request changes
                              • Stop
                              • Explain what went wrong

                              The offered decision set depends on validity and round:

                              Review stateOffered values
                              Valid, rounds 1–9Approve, Request changes, Stop
                              Invalid, rounds 1–9Request changes, Stop
                              Valid, round 10Approve, Stop
                              Invalid, round 10Explain what went wrong, Stop

                              Request changes requires non-empty feedback. It sends one complete-replacement revision request through the same enclosing Session and resets the automatic repair budget.

                              Revision instructions repeat the descriptive-H1 and narrative-plus-components requirements.

                              The review presents the exact draft through <CodeBlock>. Invalid reviews also present the complete structured diagnostics. Draft text cannot close the presentation fence and is never interpreted.

                              Approve binds the exact draft for return. It does not execute or print the draft.

                              Explanation after the final invalid draft

                              When the tenth presented draft is invalid, the person may select Explain what went wrong.

                              That choice:

                              1. makes one final <Prompt> turn in the same enclosing Session;
                              2. is not another draft, repair, revision, or review round;
                              3. relies on the Session’s existing conversation history;
                              4. supplies the final diagnostics, which the Agent has not previously seen;
                              5. asks why the attempts failed and what the person should clarify next time;
                              6. requests explanatory prose rather than document source;
                              7. treats the answer as inert text;
                              8. cannot return to drafting or approval; and
                              9. ends without source output, file output, journal, or Plan execution.

                              The explanation prompt supplies no draft, Prompt, catalog, or prior diagnostics again. Those remain available only through the existing Session history. Its new contextual data is the final diagnostics.

                              A failed explanation turn is terminal.

                              A successful explanation is reported through the command’s ordinary terminal failure reporting as the authored failure message. It is not written to source stdout and is not interpreted as XMD. The command exits nonzero because no Plan was approved.

                              No TypeScript or Agent API behavior implements this branch.

                              Command-document history and presentation

                              The prompt command document uses an invocation-owned in-memory durable stream because ordinary document and <Prompt> semantics require one.

                              That stream is:

                              • never written to --journal;
                              • never persisted as a workflow;
                              • never reused or replayed; and
                              • discarded after complete prompt-profile teardown.

                              The configured Agent provider may retain the named Session under its ordinary provider contract.

                              Command-document rendering is not successful CLI source output. Successful source output is written by the trusted host only after teardown and final admission.

                              Final admission

                              After the command document returns and its entire prompt-profile scope tears down successfully, the host treats the approved source as untrusted again.

                              The host repeats checking and property resolution using:

                              • the exact returned bytes;
                              • the original raw CLI and invocation-environment property sources;
                              • the frozen individual-option signatures;
                              • the caller’s ordered includes; and
                              • the ordinary run-profile declarations.

                              A final caller-source failure or document failure exits nonzero. It does not re-enter drafting or review.

                              The resolved props belong to the exact approved bytes. No props object from an earlier draft is reused.

                              No stdout source, output file, journal, or Plan execution begins before this admission succeeds.

                              The approved source is the CLI result

                              The exact approved source is the primary result of xmd prompt.

                              Default: print the source

                              xmd prompt "<Prompt>"

                              After teardown and final admission, the host writes the exact approved source to stdout.

                              It adds no fence, label, delimiter, or newline. It does not execute the Plan or create a generated-source file.

                              Write the source

                              xmd prompt "<Prompt>" --output <path>

                              After teardown and final admission, the host exclusively creates <path> with the exact approved bytes.

                              An existing target remains unchanged and fails the command. The command writes nothing to stdout and does not execute the Plan.

                              Run the Plan

                              xmd prompt "<Prompt>" --run

                              After teardown and final admission, the host executes:

                              retainedSource("<prompt>", source)
                              

                              through the ordinary supplied-source path.

                              The host does not print the source. Stdout belongs exclusively to the Plan’s ordinary output.

                              Write, then run

                              xmd prompt "<Prompt>" --output <path> --run

                              After teardown and final admission, the host exclusively creates the file first.

                              Execution begins only if file creation succeeds. An existing target or other write failure leaves the target unchanged where applicable and prevents execution.

                              The host does not print the source. Stdout belongs exclusively to the Plan.

                              A runtime failure does not return to authorship. A successfully created output file remains.

                              Journal behavior

                              Authorship never writes the final journal.

                              A diagnostic journal may be created only when:

                              • --run is present;
                              • --journal <path> is present; and
                              • final Plan execution is beginning.

                              Default source output and output-only mode create no journal.

                              The final journal contains no prompt command document, authorship Session, Agent turn, draft check, repair, human review, explanation, or approval event.

                              Authored failures

                              PathAuthored failure
                              Ordinary Stopxmd prompt stopped at your request. Nothing was output or run.
                              Stop on the final invalid draftxmd prompt reviewed ten drafts without an approved Plan. Nothing was output or run.
                              Unexpected post-Session fallback without approvalxmd prompt ended without an approved Plan. Nothing was output or run.
                              Successful final explanationThe coding agent’s explanation is the authored terminal failure message; no generic advice replaces it

                              An ordinary Stop includes stopping a valid tenth draft.

                              The final-invalid Stop is distinct from the explanation choice. It reports exhaustion without spending another Agent turn.

                              All authored failures are selected by the Markdown command document. They exit nonzero and produce no approved-source stdout, output file, final journal, or execution.

                              Cancellation and failure ordering

                              The whole-command deadline encloses:

                              • fixed preparation after argument admission;
                              • catalog construction;
                              • prompt-profile execution;
                              • Elicitation;
                              • explanation when selected;
                              • profile teardown;
                              • final admission;
                              • source output or exclusive file creation; and
                              • final execution when requested.

                              Cancellation stops active authorship and awaits structured teardown.

                              No final admission or output mode begins until prompt-profile execution and teardown both succeed. A teardown failure wins over an approved source.

                              Once ordinary Plan execution begins, its existing outcome and teardown precedence apply unchanged.

                              Acceptance matrix

                              The amended evidence replaces the superseded TypeScript-policy matrix.

                              IDBoundaryRequired evidence
                              P1Fixed grammarExactly one non-empty Prompt; individual --props-* options require the Prompt first; aggregate props retain ordinary placement
                              P2Effect-free helpGeneric help documents default output, --output, --run, --session, property ordering, and run-only flags without loading the packaged document or performing effects
                              P3Packaged command documentThe package-relative prompt-command.md is the exact root executed under <prompt-command> and cannot be replaced through component lookup
                              P4Approved document languageThe shipped document contains the approved introduction and the five visible stage headings
                              P5Complete Plan instructionsInitial, repair, and revision prompts require optional frontmatter followed by a descriptive H1, readable ordered steps, and components beside their prose
                              P6One SessionInitial drafting, repairs, revisions, and final explanation use one enclosing Session; default names differ and --session supplies the exact override
                              P7Prompt-profile authorityThe authorship Agent receives only the settled session directory and constrained authority; final-run flags cannot widen it
                              P8Draft inertnessNo draft is imported, evaluated, journaled as the final Plan, saved, printed as success, or executed before approval
                              P9Protected checker<CheckDraft> is the protected host-declared capability, repository lookup cannot replace it, and <ValidateCandidate> is absent
                              P10Failure classificationDraft-authored problems return structured facts; caller-authored failures escape terminally; frozen property signatures are checked before token consumption
                              P11Repair budgetEach base draft receives at most three repair turns; a human revision resets that budget
                              P12Friendly review valuesThe exact values and per-round decision sets are Approve, Request changes, Stop, and final-invalid-only Explain what went wrong
                              P13Revision feedbackRequest changes requires non-empty feedback and requests a complete replacement Plan preserving the H1 and narrative requirements
                              P14Final explanationFinal-invalid explanation makes exactly one additional <Prompt> turn in the same Session and supplies only the previously unseen final diagnostics as new context
                              P15Explanation is terminalExplanation cannot trigger checking, repair, presentation, revision, approval, or another Agent turn; its inert answer is reported and the command ends without a Plan
                              P16Authored stoppingOrdinary Stop, final-invalid Stop, unexpected fallback, and explanation use authored Markdown failure paths with the required messages or explanation
                              P17Final gateComplete prompt-profile teardown and final admission precede every successful output mode
                              P18Default stdoutDefault success writes the exact approved bytes to stdout with no fence, label, delimiter, or added newline and performs no execution
                              P19--outputOutput-only success exclusively creates a byte-identical file, writes no stdout, and performs no execution
                              P20Explicit --runPlan execution occurs only with --run, through the ordinary supplied-source path
                              P21Write before runWith --output --run, byte-identical exclusive creation completes before execution; write refusal prevents execution
                              P22Stdout ownershipSource bytes and runtime output never share stdout: default owns source stdout; run modes leave stdout entirely to the Plan
                              P23Run-only preflightEvery explicitly supplied run-only flag is refused before catalog or Agent work unless --run is present
                              P24Journal separationNo journal file is created without final execution; a requested journal begins only when --run starts and contains no authorship activity
                              P25Session-directory lifetimeInvocation-unique cleanup and named-directory preservation remain exactly as specified, with no recursive deletion
                              P26Exact bytes and propsApproval, final admission, stdout, --output, and execution use the exact returned bytes; final props are resolved for those bytes
                              P27Ordinary run behavior--run preserves ordinary cwd, includes, props, Agent configuration, permissions, timeouts, output, value, failures, and exit behavior
                              P28Teardown and cancellationCancellation and every teardown failure settle before final admission, source output, file output, journal creation, or execution

                              Use one discriminating regression for each distinct boundary. Do not restore permutations that existed only to prove the superseded TypeScript policy loop.

                              Dependencies and delivery

                              Delivered foundations remain:

                              PR #657 remains the focused implementation vehicle. Its issue #260 delivery includes:

                              • rename the packaged asset to prompt-command.md;
                              • rename PROMPT_PLAN and related source/test vocabulary to PROMPT_COMMAND;
                              • install the approved introduction and visible stage headings;
                              • strengthen initial, repair, and revision instructions with the complete Plan requirement;
                              • rename the protected internal checker to <CheckDraft>;
                              • install the exact friendly review values and round-specific decision sets;
                              • add the final same-Session explanation branch;
                              • remove any host instruction requiring every Agent response to be source;
                              • replace --save with --output, without an alias;
                              • make byte-exact stdout the default result;
                              • require --run for execution;
                              • enforce run-only option preflight;
                              • preserve final admission and complete teardown before every output mode;
                              • preserve output-file-before-run ordering;
                              • keep source stdout separate from Plan stdout;
                              • create a journal only when final execution begins;
                              • update architecture.md;
                              • rewrite specs/prompt-command-spec.md;
                              • update the affected prompt-command, Agent-provider, property-binding, CLI, and Tier PR sections of the specifications; and
                              • add the revised acceptance evidence.

                              The architecture review of feedback commit 1e449879c04e7c458ff6738ae13c2da8abb290dd is not reopened by this amendment. The next feedback commit is reviewed against this amended contract.

                              Out of scope

                              • arbitrary custom prompt command documents;
                              • public or reusable <Plan>;
                              • --plan and --plan-eval;
                              • File or Glob authorship context;
                              • a generic public <Validate>;
                              • a general arbitrary-code sandbox;
                              • the collaborative playground;
                              • stdin or editor Prompt input;
                              • automatic revision after runtime failure;
                              • a terminal Elicitation provider; and
                              • durable journaling or workflow replay of authorship.

                              Activity

                              Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

                              Metadata

                              Metadata

                              Assignees

                              No one assigned

                                Labels

                                No labels
                                No labels

                                Projects

                                No projects

                                  Milestone

                                  No milestone

                                  Relationships

                                  None yet

                                  Development

                                  No branches or pull requests

                                  Issue actions