Skip to content

Consolidate the public library interface and CLI adapter #19

Description

@adrianbrowning

What to build

Consolidate the public mdcode library interface so programmatic callers receive structured results and errors without inheriting CLI process exits or terminal formatting behavior.

Acceptance criteria

  • The public library interface returns structured results, changes, and errors for supported operations.
  • CLI presentation and process-exit behavior are implemented in a thin adapter rather than in library operations.
  • Documentation and examples use the current package identity and accurate transformer signatures.
  • Library callers can provide or observe output without relying on global console state.
  • The migrated interface is covered by focused library and CLI integration tests.

Blocked by

Activity

  1. adrianbrowning commented on Aug 8, 2026

    @adrianbrowning
    OwnerAuthor

    This was generated by AI during triage.

    Agent Brief

    Category: enhancement
    Summary: Consolidate mdcode library operations around structured outcomes and make the CLI a presentation/exit-code adapter.

    Current behavior:
    Public command functions mix operation logic with console output. The exported Execute function calls process.exit in command error paths. The default library helper returns only transformed Markdown, and its documentation uses an outdated package identity and transformer signature.

    Desired behavior:
    Programmatic callers receive structured success values, changes, diagnostics, and errors without terminal formatting or process termination. The CLI renders the same outcomes for humans or JSON and chooses its exit code at the outermost adapter. Callers may observe progress through an explicit callback instead of global console state.

    Key interfaces:

    • Result — a shared discriminated outcome: successful value plus diagnostics, or structured errors. Reuse the semantics underlying the versioned JSON contract from issue Add a versioned machine-readable CLI contract for agents #5.
    • Library operations — list, extract, update/plan/apply/check, run, dump, and transforms return Result; they never call console or process.exit.
    • Reporter callback — optional caller-provided event/diagnostic callback for observable progress without requiring global console state.
    • CLI adapter — converts Result into human text or versioned JSON and sets the process exit code after all operation work completes. Do not call process.exit from library code.
    • Public migration — replace or deprecate the default transform helper in favor of the structured operation interface; update examples to @gcmdev/mdcode and the object-form transformer signature ({ tag, meta, code }) => ... .

    Acceptance criteria:

    • Public library operations return structured success values, changes, diagnostics, and errors.
    • No library operation writes to global console or terminates the process.
    • Callers can supply a reporter callback to observe operation events or diagnostics.
    • The CLI is a thin adapter that renders human/JSON output and assigns exit codes.
    • CLI behavior preserves the documented command contract from issues Add a versioned machine-readable CLI contract for agents #5 and Add plan, diff, apply, and check workflows for agent-driven sync #6.
    • Public library documentation and examples use @gcmdev/mdcode and accurate transformer signatures.
    • Focused library tests and CLI integration tests cover success, failure, reporter, JSON, and exit-code paths.

    Out of scope:

    Verification status:
    Confirmed: commands call console, CLI paths call process.exit, and the current default library example uses an outdated package identity/signature. This issue is blocked by #5 and #6.

  2. adrianbrowning commented on Oct 6, 2026

    @adrianbrowning
    OwnerAuthor

    Scope check against main (c50021e) before starting. Most of the brief was written before #5/#6 landed and is already done:

    Criterion State on main
    Operations return structured results list, extract, update, validate, watch, run, dump all return typed results; failures throw MetadataError / BlockFailure / CommandError, which errorsFrom() maps onto contract codes.
    No global console / process exit in library code Only commands/transform.ts still does it: transform() reads process.stdin and both it and transformWithFunction() print every block with console.log. main.ts sets process.exitCode; nothing calls process.exit.
    Reporter callback run({ onBlock }) and watch({ onEvent }) already exist and are tested. The other operations are one-shot and return every diagnostic in their result.
    CLI is a thin adapter Execute() renders via format*() and returns the exit code.
    Docs use the package identity and object-form transformer Already mdcode-ts and ({ tag, meta, code }). @gcmdev/mdcode belongs to #3 and stays out of scope.

    Remaining work, which is all this issue now covers:

    1. Remove transform() and transformWithFunction(). No CLI command uses them. transformWithFunction(source, fn, filter) is update({ source, transformer: fn, filter }) without the file= reads, plus console noise. Callers move to update(), or to walk() to skip file= reads. Breaking, but the package is 0.0.x.
    2. extract({ updateSource, ignoreAnonymous }) throws a plain Error, which maps to unexpected_error. Make it a CommandError("invalid_usage") as the CLI already does.
    3. Keep the mdcode() default export: it already wraps update() and is documented as the simple string API.
  3. added a commit that references this issue on Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancementNew feature or requestready-for-agentFully specified and ready for an AFK agent

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions