feat(cli): introduce CNC Agent Protocol v1 - #1483
Draft
yyyyaaa wants to merge 18 commits into
Draft
Conversation
Introduce registry-backed command contracts, schema validation, bindings, redaction, structured rendering, discovery, documentation projections, cancellation, and stable execution outcomes for reusable CLI operations.
Give embedded cache, schema, bucket, and presigned-upload services explicit instance ownership so concurrent CLI operations do not share or evict one another's state. Add ownership and configuration coverage for the new factories.
Thread explicit environment, cache, diagnostic, and lifecycle ownership through embedded GraphQL and Graphile services. Scope logger suppression to the current async operation and keep public-key signature authentication fail-closed.
Give workers, schedulers, services, and function runtimes explicit environment and ownership boundaries. Return lifecycle handles, await startup and shutdown, and cover concurrent instances and request cleanup.
Make source resolution cancellable and explicit, enforce declarative config safety, plan generated ownership before writes, preserve sensitive-value boundaries, and return structured artifacts suitable for registry-backed CLI execution.
Route context, authentication, GraphQL execution, codegen, server, explorer, and jobs through typed operations. Add deterministic discovery, strict agent-mode bindings, atomic state handling, service adapters, structured output, and compatibility-preserving human rendering.
Describe the command registry as the implementation authority, publish the structured invocation contract, and update human and agent guidance for discovery, state, GraphQL, codegen, and service operations.
Pack the complete CNC release set once and exercise engine-strict installations, CJS and ESM exports, both binaries, structured output, exit semantics, cancellation, lifecycle events, and signal cleanup across supported Node versions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Important
This draft is a WIP snapshot, not currently merge-ready. The implementation was built from
b0843e230;mainis now 210 commits newer, and a synthetic merge reports 30 conflicted paths, including jobs/functions code thatmainhas since removed. The protocol work needs an explicit port-forward/reconciliation pass before normal review and merge.Summary
This PR introduces CNC Agent Protocol v1 and migrates all seven existing CNC command families onto a Constructive-owned, registry-backed runtime:
Agents and other non-terminal consumers now get a typed, discoverable, noninteractive execution boundary with validated JSON/JSONL output, stable errors and exit codes, cancellation, recursive redaction, and deterministic documentation projections.
This is the execution foundation for later semantic app graphs, declarative change sets, MCP, preview deployment, and durable operations. Those features are intentionally outside this PR.
Why
Previously, command definitions, help, prompts, implementation, and generated agent instructions were separate sources of truth. Structured invocation could still prompt, mix prose into stdout, depend on mutable process state, expose secrets through diagnostics, or claim that a dry run was safe while changing files.
Long-running commands behaved as terminal processes instead of observable services, context and credential state was not safely coordinated across processes, and codegen could leave partially applied output or delete files without a reliable ownership boundary.
This PR fixes that command boundary before higher-level agent workflows are added.
CNC Agent Protocol v1
The new
@constructive-io/cli-runtimepackage provides:execute(input, context)operationsAbortSignalThe machine protocol is versioned independently as
constructive.dev/cli/v1.JSON emits exactly one terminal envelope. JSONL emits
operation.started, validated domain events, and exactly one completed, failed, or cancelled terminal event. Structured stdout contains protocol records only, and structured stderr remains empty.01270130CLI behavior
--agentenables strict noninteractive execution, suppresses terminal effects and update checks, and defaults to JSONL. Explicit JSON or JSONL output also forbids prompts.Safety flags are command capabilities rather than misleading universal switches. Mutation approval, destructive codegen overwrite, and dry-run behavior appear only on commands that can enforce them.
Registry-backed discovery includes:
Both
cncandconstructiveremain supported.State and authentication safety
Context and authentication operations now use versioned, schema-validated state with:
Agent remote operations require
--contextorCNC_CONTEXT; they never fall back to mutable global context selection. Human mode retains current-context fallback for compatibility.Agent tokens come from
CNC_TOKENor--token-stdin, ambiguous sources are rejected, and token values never enter protocol output.Raw GraphQL execution
cnc executenow:--allow-mutationand--yesfor agent or CI mutationsTransactional code generation
Codegen now computes a complete plan before applying filesystem changes. It:
--cwdas the root of all discovery and outputMulti-target generation has one planning and application authority, so a child target cannot report success before the coordinated transaction commits.
Observable services
Server, explorer, and jobs commands emit:
They use injected event reporting and
AbortSignal, return lifecycle handles, avoidprocess.chdir, suppress browser opening in agent mode, await signal cleanup, and terminate cancellation with exit130.Supporting GraphQL, Graphile, cache, and jobs packages now use instance-owned pools, caches, diagnostics, runtime environment, and lifecycle handles, so closing one operation cannot invalidate another concurrent operation.
Public-key signature authentication remains fail-closed because no cryptographic verifier exists yet.
Post-implementation audit
An adversarial review independently reproduced or qualified each issue before it was fixed:
Normal CNC routing already used the registry before the legacy-authority fix, but wildcard package exports still made the old handlers directly callable. Explicit exports preserve supported entry points, including the config-manager compatibility path, without publishing bypass routes.
Commit structure
The foundational change is split into signed, conventional subsystem commits for:
Ten subsequent
fix(...)/refactorcommits each contain one independently reproduced audit correction.Compatibility and release boundary
This branch contains:
@constructive-io/cli@7.30.5@constructive-io/cli-runtime@0.1.0@constructive-io/graphql-codegen@4.55.2Compatibility behavior:
CLI_DEPRECATEDwarningsCAPABILITY_UNAVAILABLEVerification
git diff --checkThe existing Knative jobs database E2E fixture still cannot provision locally because
pgpm-verifyandmetaschema_publicare absent. It fails during fixture migration before the changed lifecycle code runs; focused lifecycle and concurrency coverage is green.Recommended review order
packages/cli-runtime/src/contracts.ts,registry.ts,bindings.ts, andexecution.tspackages/cli/src/commands.tsandpackages/cli/src/runtime/registry.tspackages/cli/src/config,runtime/state-commands.ts,runtime/execute-command.ts, andsrc/sdkgraphql/codegen/src/core/output,target-generation.ts, andmulti-generation.tspackages/cli/src/runtime/service-*, GraphQL server/explorer, Graphile cache/settings, and jobs.github/workflows/run-tests.yamlandpackages/cli/scripts/verify-packed-artifacts.mjsExplicit non-goals
csdkcommand migrationplanandapply