Skip to content

feat: experimental dynamic workflows — runtime, TUI, SDK, mode, autocomplete, docs - #2280

Open
lucasfelipe24 wants to merge 24 commits into
MoonshotAI:mainfrom
lucasfelipe24:feat/dynamic-workflows
Open

feat: experimental dynamic workflows — runtime, TUI, SDK, mode, autocomplete, docs#2280
lucasfelipe24 wants to merge 24 commits into
MoonshotAI:mainfrom
lucasfelipe24:feat/dynamic-workflows

Conversation

@lucasfelipe24

Copy link
Copy Markdown

Problem

Kimi Code lacks a way to orchestrate multiple subagents with structured phases, parallel fan-out, pipelines, and validated outputs. Users who need multi-step research or complex automation must manually manage each subagent turn.

What changed

This PR adds Dynamic Workflows: an experimental feature that runs user-approved JavaScript scripts orchestrating subagents inside a restricted sandbox.

Engine v1 (packages/agent-core)

  • Workflow runtime: sandboxed node:vm with agent/parallel/pipeline API, JSON Schema validation, limits, cancellation, explicit failure/refusal propagation
  • Discovery in project/user/extra/builtin scopes with first-match precedence
  • WorkflowRunManager + WorkflowBackgroundTask with live events
  • Tool Workflow (proposal via model, approval via workflow_run display, background execution)
  • Permission policy workflow-run-review-ask (manual/yolo/auto)
  • WorkflowMode (orthogonal mode via /workflow on|off)

Engine v2 (packages/agent-core-v2)

  • IWorkflowCatalogService (App), IWorkflowRunService (Session), WorkflowModeService (Agent)
  • Tool/approval/config/flag ported

Protocol

  • WorkflowTaskInfo, WorkflowPhaseInfo, workflow.run.* events, display kind workflow_run

SDK (packages/node-sdk)

  • 8 workflow methods + setWorkflowMode + events

TUI (apps/kimi-code)

  • /workflow command with 10 subcommands
  • Dynamic autocomplete (workflow names after /workflow run)
  • Full-screen runs browser with phase progress, logs, cancel/save/view
  • Footer badge for active workflows
  • Subagent suppression in transcript
  • Workflow mode badge

Builtin

  • deep-research.js (5 phases, adversarial verification, <=50 agent calls)

Docs

  • New pages EN+ZH + config/env/slash-commands updates

Checklist

  • Tests added (engine v1: 4113, v2: 4229, TUI: 2434, SDK: 238, protocol: 523)
  • Changeset generated
  • Docs updated

Register AI/ML, architecture, backend, database, debugging, design,
DevOps, embedded, frontend, game dev, languages, project management,
research writing, security, and testing skills as built-in bundles in
both agent-core and agent-core-v2.
…ve bundle check

Code examples in domain skill .md files contained require('uuid'),
require('commander'), import('vue'), import ... from 'vue', and
import('./types/user.mjs') patterns that the native bundle checker
treated as real runtime dependencies.
# Conflicts:
#	apps/kimi-code/src/cli/commands.ts
#	docs/en/reference/kimi-command.md
#	docs/zh/reference/kimi-command.md
Restore the references/, rules/, and AGENTS.md files of the original
domain skills into the built-in skill trees of both engines, and make
them loadable at runtime:

- SkillDefinition gains a resources map (skill-relative path to
  content), populated from ?raw imports in each bundle registration.
- The Skill tool gains a resource parameter that returns a bundled
  resource file without invoking the skill (no activation, no depth).
- The loaded skill block lists available resources under
  <bundled-resources>, and the system prompt documents the mechanism.
- Escape require()/import() patterns in resource content so the
  native bundle check passes.
- Compare entry guards against pathToFileURL(argv[1]) so native build
  steps are not silently skipped when the checkout path contains
  spaces or non-ASCII characters (01-bundle.mjs, minidb server).
- Use fileURLToPath instead of URL.pathname for MCP stdio fixtures
  and vis session fixtures, which broke under percent-encoded paths.
# Conflicts:
#	packages/agent-core-v2/src/app/agentProfileCatalog/system.md
#	packages/agent-core-v2/src/app/auth/webSearch/webSearchService.ts
#	packages/agent-core-v2/test/agent/loop/loop.test.ts
#	packages/agent-core-v2/test/tool/tool.test.ts
# Conflicts:
#	apps/kimi-code/src/tui/components/dialogs/api-key-input-dialog.ts
Drop the 16 domain expertise skill bundles (ai-ml, architecture,
backend-frameworks, database, debugging, design, devops-infra,
embedded-systems, find-skills, frontend-frameworks, game-developer,
languages, project-management, research-writing, security, testing)
from both engines, along with their SKILL.md files, sub-skills and
bundled reference material.

Revert the shared skill infrastructure to its prior state: the builtin
registries, the SkillDefinition resources map, the Skill tool resource
parameter, the loaded-block bundled-resources rendering, and the skill
sections of both system prompts.
# Conflicts:
#	docs/en/configuration/config-files.md
#	docs/zh/configuration/config-files.md
#	packages/agent-core-v2/scripts/check-domain-layers.mjs
#	packages/agent-core-v2/src/app/auth/configSection.ts
#	packages/agent-core-v2/test/agent/mcp/stubs.ts
#	packages/agent-core/src/rpc/core-api.ts
#	packages/agent-core/src/rpc/core-impl.ts
#	packages/agent-core/test/harness/runtime.test.ts
# Conflicts:
#	packages/agent-core-v2/src/agent/tools/web-search/webSearchTool.ts
#	packages/agent-core-v2/src/app/auth/webSearch/webSearchService.ts
#	packages/agent-core-v2/src/index.ts
…omplete, docs

Dynamic Workflows permitem orquestrar múltiplos subagentes a partir de
scripts JS controlados (node:vm sandbox), com fases, fan-out paralelo,
pipeline, saída estruturada validada por JSON Schema, logs/progresso e
resultado final.

Engine v1 (agent-core):
  - Workflow runtime sandbox (types, validate, script, runtime, discovery)
  - WorkflowRunManager + WorkflowBackgroundTask (kind workflow)
  - Descoberta em scopes: projeto (.kimi-code/workflows) → usuário → extra → builtin
  - Config section [workflows] (limites: concorrência, calls, duração, bytes)
  - Flag experimental 'dynamic-workflows'
  - Tool Workflow (proposal via model → approval → background run)
  - Permission policy workflow-run-review-ask (manual/yolo/auto)
  - WorkflowMode (modo ortogonal via system reminder)
  - argumentHint field na metadata

Engine v2 (agent-core-v2):
  - IWorkflowCatalogService (App scope), IWorkflowRunService (Session scope)
  - Agent tool Workflow + approval + WorkflowModeService

Protocol:
  - WorkflowTaskInfo, WorkflowPhaseInfo (+ zod schemas)
  - Eventos workflow.run.started/phase/log/agent_call/completed
  - Display kind workflow_run no ToolInputDisplay

SDK (node-sdk):
  - listWorkflows, getWorkflow, reloadWorkflows, runWorkflow
  - listWorkflowRuns, getWorkflowRun, cancelWorkflowRun, saveWorkflow
  - setWorkflowMode

TUI (kimi-code):
  - /workflow (alias /workflows) com subcomandos list/run/runs/show/cancel/save/reload/on/off
  - Autocomplete dinâmico: /workflow run <Tab> lista workflows disponíveis
  - Runs browser full-screen (status, fases, agend calls, logs, cancel, save, view script)
  - Workflow badge no footer ([N workflow(s) running])
  - Painel de approval renderiza workflow_run display com script expansível
  - ProgressController + subagent suppression for cleaner transcript

Builtin:
  - deep-research.js (5 fases: Scope/Search/Fetch/Verify/Synthesize, adversarial verification)

Docs EN+ZH:
  - Páginas customization/workflows.md + seções em config-files, env-vars, slash-commands
@changeset-bot

changeset-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c64223e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: adc6853f73

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/agent-core/src/workflow/runtime.ts Outdated
Comment thread packages/agent-core/src/workflow/discovery.ts
Comment thread apps/kimi-code/src/tui/commands/workflow.ts Outdated
Comment thread packages/agent-core/src/session/rpc.ts
@lucasfelipe24

Copy link
Copy Markdown
Author

Thanks for the thorough review! Here are my responses:

P1 — Sync loop blocking: Fixed in 3d57663. Added syncTimeoutMs: 100 to the compiled.run() call in both v1 (packages/agent-core/src/workflow/runtime.ts) and v2 (packages/agent-core-v2/src/app/workflow/runtime/runtime.ts). The script.ts already exposed the syncTimeoutMs option but the runtime was not passing it.

P1 — Builtin not bundled: Valid observation. The builtin deep-research.js is loaded via fs.readFile at runtime by the discovery module, so it needs to be present in the installed package. Currently both v1 and v2 only work in source-tree development. A follow-up fix should add the builtin directory to the package.json files field and ensure the build step copies *.js files from src/workflow/builtin/ to the output. This applies equally to v1 and v2.

P1 — Confirmation removed: This was an intentional design decision per user request. The /workflow run command is an explicit user action that doesn't need a second confirmation dialog. The model-invoked path (via the Workflow tool) still goes through the workflow-run-review-ask permission policy and shows the workflow_run approval panel. This matches how other explicit commands like /goal behave — they execute immediately without an extra confirmation popup.

P2 — WorkflowMode gate: Fixed in 3d57663. Added this.requireWorkflowsEnabled() guard to both enterWorkflowMode and exitWorkflowMode RPC handlers in packages/agent-core/src/session/rpc.ts, consistent with all other workflow RPC methods.

@lucasfelipe24

Copy link
Copy Markdown
Author

Engine v2 migration progress

As part of the ongoing migration to the v2 engine architecture (agent-core-v2), this PR now includes:

kap-server REST routes (8 new endpoints)

GET    /api/v1/sessions/{sid}/workflows              — list catalog
GET    /api/v1/sessions/{sid}/workflows/{name}        — get detail
POST   /api/v1/sessions/{sid}/workflows/run           — start run
GET    /api/v1/sessions/{sid}/workflows/runs          — list runs
GET    /api/v1/sessions/{sid}/workflows/runs/{runId}  — get run detail
POST   /api/v1/sessions/{sid}/workflows/runs/{runId}/cancel — cancel
POST   /api/v1/sessions/{sid}/workflows/save          — save to disk
POST   /api/v1/sessions/{sid}/workflows/reload        — reload catalog

Built on top of IWorkflowCatalogService (App scope) and IWorkflowRunService (Session scope), following the same patterns as tasks.ts.

klient contracts

  • workflowCatalogContract and workflowRunContract with Zod schemas
  • Registered in globalContract with facade methods on SessionFacade

TUI WorkflowV2Client

  • WorkflowV2Client adapter class that delegates to v2 (kap-server) when available, falling back to v1 Session
  • All workflow TUI commands now go through this adapter, enabling gradual engine migration without breaking existing functionality

Tests

  • kap-server: 6 route tests (kap-server/test/workflows.test.ts)
  • klient: 14 contract schema tests (klient/test/contract/session/workflow.test.ts)
  • TUI: 11 command tests passing

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