Commit Graph
41 Commits
Author SHA1 Message Date
Charles YaoandClaude Opus 4.8 4e55747aa6 fix(dify-builder): add 3 missing status literals + restore typed annotations in strings.py
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-10 15:18:55 -07:00
Charles YaoandClaude Opus 4.8 c54274e92f feat(dify-builder): static-string catalog for reply localization (M2)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-10 15:10:40 -07:00
Charles YaoandClaude Opus 4.8 97b8354173 fix(dify-builder): capture verify-launch errors instead of swallowing them
The build/edit test handlers wrapped run_draft in a bare, non-logging
`except Exception` that turned any launch-time failure into a blank failed
run (dify_run_id="", per_node=[], no error). Diagnose then had nothing to
act on and the repair loop ran blind — the prod symptom where a stale test
input (ValueError "<var> is required in input form") produced an
undiagnosable await_repair loop.

Now the launch error is logged, captured, and persisted so diagnose/routing
can act on it:
- Run.error field + dify_builder_runs.error column (migration a9cc8d552db4)
- handlers_build/edit: logger.exception + launch_error_text(exc) -> Run.error
- is_input_failure() also inspects Run.error (+ "in input form" signal), so a
  stale-input launch failure routes to the testdata gate, not blind repair
- diagnose/_degraded_diagnosis surface the launch error when no node executed

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-10 14:24:51 -07:00
twwu c51e277389 feat(dify-builder): show affected nodes in change cards
Render change sets directly in plan-style cards with affected node names,
IDs, and change details. Capture node metadata for proposed and applied
changes and persist it with conversation history.

Remove the view_changes action and expand/collapse state. Update generated
contracts, translations, and regression coverage.

Validation: 112 frontend tests and 742 backend unit tests passed.
2026-09-07 13:44:39 +08:00
twwu ac7db51302 fix(dify-builder): align form schema types with values 2026-09-04 16:10:22 +08:00
twwu 4893c5e621 refactor(dify-builder): separate reasoning from execution progress 2026-09-04 13:43:16 +08:00
twwu eb25c2d8ee feat(dify-builder): add live progress and conversation streaming 2026-09-04 10:16:50 +08:00
twwu 3eacff14a6 feat: add typed SSE interactions to Dify Builder 2026-09-03 08:48:23 +08:00
Charles YaoandClaude Opus 4.8 e7e14ab888 fix(dify_builder): stop empty/mode-mismatched builds silently emptying the canvas
A build for a workflow app whose goal reads like a chatbot produced an empty
canvas while the assistant reported "Workflow built on the canvas.": the plan
was chatbot-shaped, build_nodes fed it to the generator (mode="workflow"), the
LLM emitted a chatflow graph (answer node / no end node), the generator
rejected it as MISSING_TERMINAL -- a class it does NOT retry -- and build_nodes
swallowed the error into []. handle_plan_approval then treated [] as a
successful build: it deleted the placeholder start and advanced to
build.execution, leaving nothing on the canvas.

Two parts:

1. build_nodes now prepends an explicit workflow-topology directive (one
   start + >=1 end node, no answer nodes) to the generator instruction, and
   retries ONCE on an error/empty result with the specific error fed back as
   a corrective nudge -- covering the terminal-node failure the shared
   generator skips.

2. handle_plan_approval refuses to fake success: when build_nodes yields zero
   create_node intents it surfaces an honest error and stays in
   build.plan_approval (retryable) without deleting the placeholder, instead
   of emptying the canvas and claiming a build. A loop-back re-approve still
   returns the fixed create intents (only filtered as already-present), so
   zero create intents unambiguously means a genuine generation failure.

Adds regression tests for both. Note: part 1 improves LLM reliability
(verifiable live); part 2 is the deterministic guarantee against the
false-success empty canvas.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-02 14:39:56 -07:00
Charles YaoandClaude Opus 4.8 1ef298e5fd Fix dify-builder contract gen script cwd and stale docstring paths
uv run --project selects the venv but doesn't chdir, so invoking
gen-dify-builder-contract from packages/contracts (as autofix.yml does)
raised ModuleNotFoundError: No module named 'core'. Switch to
--directory so uv chdirs into api/ before running the module. Also
update two contract_gen.py docstrings that still pointed at the old
web/app/components/dify-builder/contract/types.ts output path.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-01 00:06:31 -07:00
Charles YaoandClaude Opus 4.8 cad5919220 refactor(dify-builder): generate contract TS into @dify/contracts/dify-builder
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-31 23:34:45 -07:00
twwu 22be55af5f feat: redesign app builder fix flow 2026-08-31 18:18:30 +08:00
Charles YaoandClaude Opus 4.8 133e8fdc0c refactor(dify-builder): remove unused propose_build_repair from agent Protocol
It was stubbed to [] in LlmBuilderAgent, canned in PlaceholderAgent, and never
called by any handler — the Build failure path reuses Fix cognition (diagnose +
propose_repair). Removed from the DifyBuilderAgent Protocol, both implementations,
and all test doubles.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-30 10:03:48 -07:00
Charles YaoandClaude Opus 4.8 d2cfaf7f72 fix(dify_builder): narrow input-failure signals, fix build delete/create id collision
Final-review fix wave for the testdata-gate + start-selector slice:

- I1 (Important): is_input_failure's signal list included the bare
  "required" (and generic "variable not found"), which also fire on
  config/runtime faults unrelated to test inputs -- misrouting those
  failures to the *_AWAIT_TESTDATA gate, where the diagnosed auto-repair
  is never offered and re-running just loops at the gate. Narrowed
  _INPUT_FAILURE_SIGNALS to ("file variable", "not provided", "missing
  input"), favoring precision per the spec's ambiguous-failure ->
  config-repair safe default. The real file-input E2E error ("File
  variable not found for selector: [...]") still matches via "file
  variable".

- M2 (Minor, latent): handle_plan_approval's from-scratch delete-then-
  create-filter path could drop a generator create_node/connect that
  reuses a just-deleted placeholder start's id, since _already_present
  compared against the PRE-delete existing_node_ids/existing_edges --
  delete with no re-create, silently vanishing the node. Deleted ids are
  now excluded from that comparison set; the loop-back path (no deletes)
  is unaffected.

- Cleanups: state.py's Build/Edit state-count comments (14->15, 9->10,
  verified against the actual enum members), FormCard's docstring now
  lists the "testdata" variant, and handle_plan_approval binds
  current_graph's nodes to one local instead of calling .get() 3x and
  documents the delete-placeholder branch.

Tests: extended test_is_input_failure_matches_input_signals's sibling
with a config "required" case (red before the signal-list fix, green
after), and added a plan_approval test where the generator's create_node
reuses the deleted placeholder start's id (red before the id-exclusion
fix -- a dangling connect ValueError -- green after).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-30 10:03:48 -07:00
Charles YaoandClaude Opus 4.8 db150d1a43 feat(dify-builder): Edit live test reuses prepared input, routes input-failures to testdata gate
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-30 10:03:47 -07:00
Charles YaoandClaude Opus 4.8 ef88f6532c feat(dify-builder): EDIT_AWAIT_TESTDATA gate + run_affected_tests routing
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-30 10:03:47 -07:00
Charles YaoandClaude Opus 4.8 cea65957bb feat(dify-builder): Build live test reuses prepared input, routes input-failures to testdata gate
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-30 10:03:47 -07:00
Charles YaoandClaude Opus 4.8 4f6a5f07b7 feat(dify-builder): BUILD_AWAIT_TESTDATA gate + run_test routing
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-30 10:03:47 -07:00
Charles YaoandClaude Opus 4.8 1dda1d3326 feat(dify-builder): is_input_failure + testdata_form_fields core helpers
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-30 10:03:47 -07:00
Charles YaoandClaude Opus 4.8 20d932177c fix(dify-builder): drop draft placeholder start on from-scratch build
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-30 10:03:47 -07:00
Charles YaoandClaude Opus 4.8 8b640e44de Fix Dify Builder live-test escape paths to reset stale test inputs
Clear fc.test_input_ref and fc.verify_run_id on the four re-plan/revert
escape branches in Build and Edit (handle_review's continue_adjusting
and handle_reverted's retry_after_revert) so a rebuild+retest
regenerates fresh schema-shaped mock inputs instead of reusing the
first build's stale ones -- the approve_repair retest path is left
untouched since it must fairly retest against the same failing case.
Also corrects three doc/comment mismatches (llm_agent's 12->13 method
count, an await_repair docstring describing a branch that doesn't
exist, and state.py's Build state-count banner), and adds tests for
the run_draft-raises degrade path and Build/Edit pass-path canvas
event symmetry.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-29 19:26:48 -07:00
Charles YaoandClaude Opus 4.8 b3e9f1df3d feat(dify-builder): live Edit test via run_draft, fail routes to repair gate
Rewrite handle_test_affected_paths from a canned always-success stub to a
live handler mirroring Build's handle_test_and_repair (A5): derive mock
inputs once via start_schema/generate_mock_inputs and persist a TestInput
(reused on retest), run run_draft (degrading to a synthesized failed Run on
exception), and mint a real immutable Run. Pass -> edit.review with a green
TestResultCard + summary. Fail -> real diagnose/propose_repair, stage
fc.diagnosis/staged_repair/risk, emit a red TestResultCard + ErrorCard (+
ChangeSetCard when intents are proposed) -> edit.await_repair (the B1 gate).
No auto-apply; apply_repair still runs only inside handle_await_repair's
approve_repair branch.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-29 19:04:29 -07:00
Charles YaoandClaude Opus 4.8 ac5f48a765 feat(dify-builder): EDIT_AWAIT_REPAIR gate + handler
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-29 18:53:09 -07:00
Charles YaoandClaude Opus 4.8 badb67c720 feat(dify-builder): live Build test via run_draft, fail routes to repair gate
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-29 18:33:32 -07:00
Charles YaoandClaude Opus 4.8 26fdde78c2 feat(dify-builder): BUILD_AWAIT_REPAIR gate + handler
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-29 18:20:29 -07:00
Charles YaoandClaude Opus 4.8 e2b9e3aba3 feat(dify-builder): start_schema core helper (start node variables)
Implement start_schema(graph: Graph) -> StartSchema that reads the start
node's declared input variables from graph.nodes[].data.variables into
{"variables": [...]}. Pure dict access — stays in core without importing
services. Returns {"variables": []} when there is no start node or it
declares no variables.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-29 17:52:36 -07:00
Charles YaoandClaude Opus 4.8 ac2523beb6 feat(dify-builder): goal-shaped Edit rules form from cognition output
analyze_impact now returns {fields, values, target_node_ids} instead of a
flat edit_rules dict, mirroring Build's goal-shaped form (A2). Rewire
handle_capability_check to read fc.form_fields/edit_rules/edit_target_node_ids
from that shape and render the FormCard via build_form_fields;
handle_impact_analysis merges the submitted payload on the dynamic
fc.form_fields keys instead of a fixed key tuple; handle_review's re_fix
branch re-renders the form the same way. Delete the now-dead
_EDIT_RULE_FIELDS/_EDIT_RULE_KEYS constants. PlaceholderAgent.analyze_impact
returns the new shape (the old fields become canned fields/values), so both
it and the LLM agent (which still delegates to canned) are shape-uniform.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-29 13:28:30 -07:00
Charles YaoandClaude Opus 4.8 cbb1487d6a fix(dify-builder): sync cards manifest to attached cards, cover remaining Build wirings
handle_test_and_repair's AssistantTurnItem.cards was unconditional even
though error/change_set cards are now only appended when
propose_build_repair returns intents -- the manifest claimed cards that
were never attached in the neutral (empty-repair) path. Make cards
conditional to match what's actually appended, and assert it in both
branches.

Remove three noqa comments added in the prior commit that suppressed
ARG001/ARG005 on new test code (the global constraint disallows noqa
for non-enabled rules); switch the genuinely-unused monkeypatch
args/lambda params to underscore-prefixed names instead, and drop a
build_nodes monkeypatch that exercised nothing. Add
test_remaining_build_methods_thread_model_and_tenant_args to cover
propose_plan_v1/discover_resources/bind_resources/build_nodes/
learn_from_build's model/tenant_id/model_config threading, matching
the existing analyze_goal coverage.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-29 13:14:08 -07:00
Charles YaoandClaude Opus 4.8 8683e6517c feat(dify-builder): wire real Build cognition + neutral empty test-repair
LlmBuilderAgent's 6 Build methods (analyze_goal, propose_plan_v1,
discover_resources, bind_resources, build_nodes, learn_from_build) now
delegate to services.dify_builder.agent.build instead of the canned
PlaceholderAgent. propose_build_repair returns [] -- there's no real
failure signal to diagnose until the live test step is de-canned.

handle_test_and_repair now conditions the error card + apply_repair on
a non-empty propose_build_repair result: placeholder mode keeps today's
"found and fixed" arc, while real cognition (which never reports a
failure yet) emits a neutral "no issues found" review summary instead
of a fake error/fix on a hardcoded node id that real build_nodes
wouldn't have generated anyway.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-29 12:25:14 -07:00
Charles YaoandClaude Opus 4.8 14bd9425d6 feat(dify-builder): goal-shaped Build requirements form from cognition output
analyze_goal now returns {fields, values} instead of a flat requirements
dict, so the Build capability-check form renders whatever fields the
agent (placeholder or LLM) proposes rather than a hardcoded 6-field
constant. handlers_fix.build_form_fields whitelists/coerces the agent's
raw field specs into FormField (unknown type -> text). handle_goal_analysis
now merges submitted values against the dynamic fc.form_fields keys
instead of the deleted _REQUIREMENT_KEYS constant.

Also updates test_placeholder_agent.py's analyze_goal shape assertion,
which broke as a direct consequence of the new {fields, values} contract.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-29 11:06:47 -07:00
Charles YaoandClaude Opus 4.8 28a4dad58f feat(dify-builder): persist goal-shaped form_fields on context
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-29 10:54:36 -07:00
Charles YaoandClaude Opus 4.8 d5a8f5021f feat(dify-builder): explain the no-automatic-fix outcome in handle_propose
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-29 02:23:08 -07:00
Charles YaoandClaude Opus 4.8 4c0efd947d feat(dify-builder): echo chosen model in SessionView + regen contract
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-27 22:51:27 -07:00
Charles YaoandClaude Opus 4.8 6bf013da3a feat(dify-builder): model resolver + BadRequestError -> 400
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-27 22:51:27 -07:00
Charles YaoandClaude Opus 4.8 71a1e51917 feat(dify-builder): add model_config to session context + serde
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-27 22:51:26 -07:00
Charles YaoandClaude Opus 4.8 24de2c8417 Dedup Dify Builder handlers/services: extract shared helpers
Behavior-preserving code-quality cleanup across the Dify Builder engine:
extract emit_canvas, build_change_set, mint_checkpoint, action_kind, and
merge_known_keys into handlers_fix.py (shared by handlers_build.py and
handlers_edit.py); extract _add in repository.py for the id-preservation
idiom; extract _make_edge (and unify the node/edge id-collision loops
into _next_unique_id) in graph_ops.py; extract _sync_graph_only in
dify_port.py. No behavior, generated ids, or wire output changed — same
387-test suite passes, ruff clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-23 19:32:57 -07:00
Charles YaoandClaude Opus 4.8 b0586315f3 Fix cosmetic minor docstring and test assertions in handlers_build
FINDING 1: Updated module docstring in handlers_build.py to accurately
reflect that build.complete's completion summary is emitted by the
governance-tail handlers (handle_governance_feedback for automatic/disabled
policies, or handle_await_learning for the ask policy).

FINDING 2: Strengthened two per-policy governance tests to include notice
kind assertions:
- test_governance_automatic_learns_and_reaches_complete: add assert "notice" in kinds
- test_await_learning_accept_learns_and_completes: add assert "notice" in kinds

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-23 13:09:13 -07:00
Charles YaoandClaude Opus 4.8 bad0046ccf feat(dify-builder): real governance tail — policy branch + build.await_learning (C-2)
Rework handle_governance_feedback into the 3-policy branch (automatic/
disabled/ask) reading fc.skill_learning_policy, and add handle_await_learning
to resolve the ask-policy accept_learning/skip_learning turn. Both funnel
into a shared _emit_completion helper for the build-complete summary.
Registered BUILD_AWAIT_LEARNING in build_registry().

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-23 12:46:39 -07:00
Charles YaoandClaude Opus 4.8 6f02649374 feat(dify-builder): add DifyBuilderAgent.learn_from_build seam (canned) (C-2)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-23 12:33:44 -07:00
Charles YaoandClaude Opus 4.8 e4b0195528 feat(dify-builder): add build.await_learning state + skill_learning_policy context field (C-2)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-23 12:24:19 -07:00
Charles YaoandClaude Opus 4.8 7e83264330 refactor: rename Workflow Copilot → Dify Builder
Project rename across api/ + web/: modules, symbols, routes
(/console/api/dify-builder/*), feature flag (DIFY_BUILDER_ENABLED),
Celery queue/tasks, the 7 DB tables (via migration df1b0114de40),
and regenerated contract artifacts. Behavior unchanged; 430 tests green,
ruff clean. Branch renamed feat/copilot-py-backend → dify-builder.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-23 11:18:35 -07:00