Skip to content

feat(agentic)!: the agent kit: the shared session, the MCP server and the typed command layer - #2094

Draft
yyyyaaa wants to merge 1 commit into
feat/headless-toolsfrom
feat/headless-agent-kit
Draft

yyyyaaa wants to merge 1 commit into
feat/headless-toolsfrom
feat/headless-agent-kit

Conversation

@yyyyaaa

@yyyyaaa yyyyaaa commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Part of constructive-io/constructive-planning#2588. Stack 2 of 3, on the tools PR.

After dev-utils publishes: inquirerer ^4.10.0 in agentic/command and agentic/cli, appstash ^0.9.0 in agentic/session, and a new lockfile; CI cannot build @agentic-kit/command before that.

The integration-tests PR moves its pin to this merge.

@agentic-kit/session and the agent CLI:

@agentic-kit/session is a new package with the sign-in that every
Constructive binary shares:

  • Backend contexts with all five planes (api, auth, modules, agent and
    compute), from the endpoints or from the CONSTRUCTIVE_* overrides.
  • resolveSession answers who talks to which backend in one of seven
    states, and pairs a credential only with the backend it was issued for.
  • signIn and signOut with email and password. A sign-in mints a 30-day API
    key, revokes the key of the session it replaces, and stores the session
    with the backend it was issued for. verifySession asks the backend
    whether it still accepts the credential, and keyEndsSoon says when to
    sign in again.
  • Agents: createAgent, listAgents, renewAgentKey and removeAgent manage a
    principal of the person with its own key, whose lifetime is capped on
    the principal at 30 days. The package uses the key only to mint short
    access tokens, which it caches in a 0600 file and reuses until they
    end. The backend also accepts the key itself, so whoever holds it can
    act as the agent until it ends, is renewed or the agent is removed; it
    stays in a 0600 file. An agent cannot change the schema unless it is
    allowed to (grantSchemaChanges, revokeSchemaChanges).
  • sessionToolsHost, the db-tools host on top of the resolved session.
  • The store lives under ~/.constructive/, and CONSTRUCTIVE_STASH_DIR
    replaces ~. Context and agent names are checked.

The agent CLI (@agentic-kit/cli) signs in and out through it and loses
its own account, backend, API key and credential code. whoami also asks
the backend whether it accepts the credential. The README names the
access tools it registers.

CI runs the session tests in the agentic batch.

@agentic-kit/mcp:

@agentic-kit/mcp is a new package. serveStdio and createMcpServerFactory
serve HarnessTools on @modelcontextprotocol/server 2.x. A tool's name,
title, description, parameters, effect, failures and follow-up calls come
from the tool object; the plan and the gate's decision come from the
harness.

  • readOnly: true serves the tools whose effect is read; readOnly: false
    adds the tools whose effect is write. A destructive tool is not served
    in either mode.
  • A write tool is annotated readOnlyHint: false, destructiveHint: true and
    idempotentHint: false, with _meta "anthropic/requiresUserInteraction":
    true, so a host that honors it asks the person before each call.
  • A write call gets its plan from the gate. When the gate blocks it, the
    failure comes back and nothing changes. When it runs, the result carries
    the plan. A client with form elicitation is shown the plan once as an
    optional preview: the host's prompt is the approval, so the "Apply this
    change" box starts ticked and accepting the form applies the change. A
    decline, a closed question or an unticked box changes nothing.
  • structuredContent is an envelope: { ok: true, data, plan?, calls? }, or
    { ok: false, error, data?, plan?, calls? } with isError.
  • A tool that throws returns a fixed sentence that names the tool, with
    the logged error's id when there is one, and never the error's text.
  • The server sends instructions on connect: the read tools to call first,
    the tools that change things, and that the host asks before each of
    them. The host's own instructions follow.

CI runs the MCP tests in the agentic batch.

@agentic-kit/command:

@agentic-kit/command is a new package: the command layer of the
Constructive CLI, and the binding of a HarnessTool to a command.

  • A command's input is a zod object. The layer parses it once; help,
    --schema, --llms and --llms --json print JSON Schema made from
    it. Each property is a flag; values are coerced by their JSON Schema
    type; --input takes the whole input as JSON, @path or stdin. One null
    rule: null for an optional key that does not take null reads as not
    given.
  • Five kinds of command: a read, a change ({ plan, apply }), a change
    that runs at once (a write marked immediate), a server, and a
    passthrough. A change is planned, and the layer itself decides its
    approval: --dry-run returns the plan, --yes approves, a terminal asks,
    and any other run exits 3. createCli refuses a change that defines run
    without immediate, so no change skips its approval. A plan can name
    the flags its apply needs without a terminal (Planned.needs, such as
    --password-stdin), and the --yes step after --dry-run or exit 3 carries
    them when the run has no terminal.
  • One output contract: text with a Next: block on a terminal, otherwise
    one JSON envelope. Exit codes: 0 done, 1 failed, 2 usage, 3 approval
    required, 4 sign in first, 130 interrupted. A secret marked x-secret is
    never echoed.
  • Help topics are data: createCli takes topics, a built-in help command
    prints the CLI's help, a command's or group's help, or a topic, and a
    word it does not know is a usage error that names the nearest one.
    The --llms index and manifest carry the topics, and renderReference
    turns the manifest into one Markdown reference (the source of the
    CLI's man page).
  • toolCommand and toCliCommands bind tools: the tool's params are the
    input, its effect is the command's effect, a change plans through the
    gate policy (callChange), a tool failure becomes a CliError with the same
    code, and the tool's suggested calls become the first next steps.
    toolCallStep writes a call the same way for another host.

inquirerer stays the prompt library and parseArgv.

CI runs the command tests in the agentic batch.

BREAKING CHANGE: agent login stores a 30-day API key, in place of a
5-year key that the CLI renewed by itself; when it ends, run agent login
again. A session stored by an earlier version records no backend, so it
is not used; run agent login again. CONSTRUCTIVE_STASH_DIR replaces
AGENT_HOME. @agentic-kit/cli no longer exports HOST_ENV_VARS.

… the typed command layer

@agentic-kit/session and the agent CLI:

@agentic-kit/session is a new package with the sign-in that every
Constructive binary shares:
- Backend contexts with all five planes (api, auth, modules, agent and
  compute), from the endpoints or from the CONSTRUCTIVE_* overrides.
- resolveSession answers who talks to which backend in one of seven
  states, and pairs a credential only with the backend it was issued for.
- signIn and signOut with email and password. A sign-in mints a 30-day API
  key, revokes the key of the session it replaces, and stores the session
  with the backend it was issued for. verifySession asks the backend
  whether it still accepts the credential, and keyEndsSoon says when to
  sign in again.
- Agents: createAgent, listAgents, renewAgentKey and removeAgent manage a
  principal of the person with its own key, whose lifetime is capped on
  the principal at 30 days. The package uses the key only to mint short
  access tokens, which it caches in a 0600 file and reuses until they
  end. The backend also accepts the key itself, so whoever holds it can
  act as the agent until it ends, is renewed or the agent is removed; it
  stays in a 0600 file. An agent cannot change the schema unless it is
  allowed to (grantSchemaChanges, revokeSchemaChanges).
- sessionToolsHost, the db-tools host on top of the resolved session.
- The store lives under ~/.constructive/, and CONSTRUCTIVE_STASH_DIR
  replaces ~. Context and agent names are checked.

The agent CLI (@agentic-kit/cli) signs in and out through it and loses
its own account, backend, API key and credential code. whoami also asks
the backend whether it accepts the credential. The README names the
access tools it registers.

CI runs the session tests in the agentic batch.

@agentic-kit/mcp:

@agentic-kit/mcp is a new package. serveStdio and createMcpServerFactory
serve HarnessTools on @modelcontextprotocol/server 2.x. A tool's name,
title, description, parameters, effect, failures and follow-up calls come
from the tool object; the plan and the gate's decision come from the
harness.

- readOnly: true serves the tools whose effect is read; readOnly: false
  adds the tools whose effect is write. A destructive tool is not served
  in either mode.
- A write tool is annotated readOnlyHint: false, destructiveHint: true and
  idempotentHint: false, with _meta "anthropic/requiresUserInteraction":
  true, so a host that honors it asks the person before each call.
- A write call gets its plan from the gate. When the gate blocks it, the
  failure comes back and nothing changes. When it runs, the result carries
  the plan. A client with form elicitation is shown the plan once as an
  optional preview: the host's prompt is the approval, so the "Apply this
  change" box starts ticked and accepting the form applies the change. A
  decline, a closed question or an unticked box changes nothing.
- structuredContent is an envelope: { ok: true, data, plan?, calls? }, or
  { ok: false, error, data?, plan?, calls? } with isError.
- A tool that throws returns a fixed sentence that names the tool, with
  the logged error's id when there is one, and never the error's text.
- The server sends instructions on connect: the read tools to call first,
  the tools that change things, and that the host asks before each of
  them. The host's own instructions follow.

CI runs the MCP tests in the agentic batch.

@agentic-kit/command:

@agentic-kit/command is a new package: the command layer of the
Constructive CLI, and the binding of a HarnessTool to a command.

- A command's input is a zod object. The layer parses it once; help,
  <command> --schema, --llms and --llms --json print JSON Schema made from
  it. Each property is a flag; values are coerced by their JSON Schema
  type; --input takes the whole input as JSON, @path or stdin. One null
  rule: null for an optional key that does not take null reads as not
  given.
- Five kinds of command: a read, a change ({ plan, apply }), a change
  that runs at once (a write marked immediate), a server, and a
  passthrough. A change is planned, and the layer itself decides its
  approval: --dry-run returns the plan, --yes approves, a terminal asks,
  and any other run exits 3. createCli refuses a change that defines run
  without immediate, so no change skips its approval. A plan can name
  the flags its apply needs without a terminal (Planned.needs, such as
  --password-stdin), and the --yes step after --dry-run or exit 3 carries
  them when the run has no terminal.
- One output contract: text with a Next: block on a terminal, otherwise
  one JSON envelope. Exit codes: 0 done, 1 failed, 2 usage, 3 approval
  required, 4 sign in first, 130 interrupted. A secret marked x-secret is
  never echoed.
- Help topics are data: createCli takes topics, a built-in help command
  prints the CLI's help, a command's or group's help, or a topic, and a
  word it does not know is a usage error that names the nearest one.
  The --llms index and manifest carry the topics, and renderReference
  turns the manifest into one Markdown reference (the source of the
  CLI's man page).
- toolCommand and toCliCommands bind tools: the tool's params are the
  input, its effect is the command's effect, a change plans through the
  gate policy (callChange), a tool failure becomes a CliError with the same
  code, and the tool's suggested calls become the first next steps.
  toolCallStep writes a call the same way for another host.

inquirerer stays the prompt library and parseArgv.

CI runs the command tests in the agentic batch.

BREAKING CHANGE: agent login stores a 30-day API key, in place of a
5-year key that the CLI renewed by itself; when it ends, run agent login
again. A session stored by an earlier version records no backend, so it
is not used; run agent login again. CONSTRUCTIVE_STASH_DIR replaces
AGENT_HOME. @agentic-kit/cli no longer exports HOST_ENV_VARS.
@coderabbitai

coderabbitai Bot commented Nov 26, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@yyyyaaa
yyyyaaa added this pull request to stack #2096 November 26, 2026 17:20
@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​modelcontextprotocol/​client@​2.4.0921008295100
Added@​modelcontextprotocol/​server@​2.4.01001008394100

View full report

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant