Skip to content

Planner Contract

This page records the internal planner boundary for the dreamcli-re-foundation workstream. It is a stability target for tests and refactors, not a public API guarantee.

Responsibilities

  • intercept root --help and --version
  • dispatch nested commands
  • apply default-command fallback
  • merge propagated flags while honoring child shadowing
  • build the execution handoff for the matched command
  • normalize invocation argv for planner-owned global concerns like root --json

Non-Responsibilities

  • parse flag or arg values
  • read env, config, stdin, or prompt sources
  • run middleware or action handlers
  • decide concrete output writers or rendering mechanics

Dispatch Outcome

The planner contract is modeled in src/core/cli/planner.ts as:

ts
import type {
  ,
  HelpOptions,
} from '@kjanat/dreamcli';

type  = <string, unknown>;

type  =
  | {
      readonly : 'root-help';
      readonly : HelpOptions;
    }
  | {
      readonly : 'root-version';
      readonly : string;
    }
  | {
      readonly : 'dispatch-error';
      readonly : ;
    }
  | {
      readonly : 'match';
      readonly : ;
    };

The intent is simple:

  • root-help and root-version short-circuit before command execution
  • dispatch-error captures CLI-level failures before parse and resolve
  • match hands one explicit execution plan to the executor seam

Command Execution Plan

ts
import type {
  CLIPlugin,
  CommandMeta,
  CommandSchema,
  HelpOptions,
} from '@kjanat/dreamcli';

type  = <string, unknown>;
type  = <string, unknown>;

interface CommandExecutionPlan {
  readonly : ;
  readonly : CommandSchema;
  readonly : readonly string[];
  readonly : CommandMeta;
  readonly : readonly CLIPlugin[];
  readonly : ;
  readonly : HelpOptions | undefined;
}

Field meaning:

FieldMeaning
commandmatched leaf command to execute
mergedSchemaleaf schema after propagated ancestor flags are merged and shadowed
argvremaining argv after command-name dispatch
metaCLI metadata passed into middleware and actions
pluginsCLI plugin list observed by the execution path
outputsemantic output facts: jsonMode, isTTY, verbosity
helphelp formatting context carried through command execution

Evidence

  • Contract module: src/core/cli/planner.ts
  • Current dispatcher: src/core/cli/dispatch.ts
  • Current CLI orchestration: src/core/cli/index.ts
  • RFC / PRD source: specs/dreamcli-re-foundation.md, specs/dreamcli-re-foundation-prd.md

Current Status

  • planner outcomes are named explicitly in code
  • raw invocation shaping, root interception, dispatch, and default-command fallback live in src/core/cli/planner.ts
  • CLIBuilder.execute() now consumes planner outcomes as a render-and-execute shell rather than owning command-routing policy

Released under the MIT License.