Skip to content

feat(core): EDITMODE protocol — declarable tweakable params#84

Merged
hqhq1025 merged 2 commits intomainfrom
wt/loop-feat-editmode-protocol
Apr 19, 2026
Merged

feat(core): EDITMODE protocol — declarable tweakable params#84
hqhq1025 merged 2 commits intomainfrom
wt/loop-feat-editmode-protocol

Conversation

@hqhq1025
Copy link
Copy Markdown
Collaborator

让模型在 artifact 顶部声明 TWEAK_DEFAULTS 块(JSON between markers)。Host 实现待 v0.2 — 本 PR 只引入协议。详见 docs/research/30-claude-design-extracted-architecture.md §3。

改动

  • 新建 packages/core/src/prompts/editmode-protocol.v1.txt
  • prompts/index.ts 注册 editmodeProtocolPROMPT_SECTIONS + PROMPT_SECTION_FILES
  • composer 在 pre-flight 之后、craft-directives 之前插入 EDITMODE_PROTOCOL,create / tweak / revise 三个 mode 都包含
  • vitest: 验证 createtweak 两种 mode 都包含 EDITMODE protocol/*EDITMODE-BEGIN*/TWEAK_DEFAULTS 标识

验证

  • pnpm --filter @open-codesign/core exec vitest run — 111 passed (含新增 2 个用例)
  • pnpm typecheck — 通过
  • 现有 prompt section drift 测试覆盖新 .txt ↔ TS 常量字节一致

范围说明

本 PR 只引入 protocol(让模型按规范输出 EDITMODE 块)。Host 端 panel scan / control rendering / string-rewrite 在 v0.2 重写 #74 中实现。

四绿

  • Compatibility: 仅扩展 prompt sections,不破坏现有 API ✅
  • Upgradeability: section 命名带 v1 后缀,未来可平滑迁移 ✅
  • No bloat: 纯文本 prompt 改动,无新依赖、无 install size 影响 ✅
  • Elegance: 与既有 section 注册模式一致 ✅

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Findings

  • [Major] revise mode now receives EDITMODE declaration instructions, which does not match the stated scope (create+tweak) and can steer revision flows toward parameter-block authoring instead of targeted edits. Evidence packages/core/src/prompts/index.ts:660, packages/core/src/prompts/index.ts:663
    Suggested fix:

    const sections: string[] = [
      IDENTITY,
      WORKFLOW,
      OUTPUT_RULES,
      DESIGN_METHODOLOGY,
      ARTIFACT_TYPES,
      PRE_FLIGHT,
    ];
    
    if (opts.mode === 'create' || opts.mode === 'tweak') {
      sections.push(EDITMODE_PROTOCOL);
    }
    
    if (opts.mode === 'tweak') {
      sections.push(TWEAKS_PROTOCOL);
    }
  • [Minor] The protocol table suggests an enum detection via "comment hint (TBD)" while the rules explicitly forbid comments inside the JSON block, which can induce invalid output and parse failures. Evidence packages/core/src/prompts/editmode-protocol.v1.txt:22, packages/core/src/prompts/editmode-protocol.v1.txt:37, packages/core/src/prompts/index.ts:182, packages/core/src/prompts/index.ts:197
    Suggested fix:

    | Enum-like string (closed set defined by key/schema) | Select dropdown |

Summary

  • Review mode: initial
  • 2 issues found in added/modified lines (1 Major, 1 Minor).
  • docs/VISION.md and docs/PRINCIPLES.md: Not found in repo/docs in this checkout, so constraint validation relied on CLAUDE.md plus diff-scoped files.

Testing

  • Not run (automation)
  • Suggested tests: add a composeSystemPrompt({ mode: 'revise' }) assertion that EDITMODE protocol is excluded (if create+tweak scope is intended).

open-codesign Bot

DESIGN_METHODOLOGY,
ARTIFACT_TYPES,
PRE_FLIGHT,
EDITMODE_PROTOCOL,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

EDITMODE_PROTOCOL is pushed in the base section list, so mode: 'revise' gets this section too. If scope is create+tweak (per PR description), gate this push to create || tweak to avoid revise-mode prompt drift.

| `true / false` | Toggle switch |
| Number (e.g. `1.0`, `16`, `0.5`) | Slider |
| Plain string | Text input |
| Enum-like string with comment hint (TBD) | Select dropdown |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This row suggests enum detection via a comment hint, but the rules above forbid comments inside the JSON block. Please remove/comment-proof this guidance to prevent invalid JSON output.

Introduce a new prompt section that teaches the model to declare
TWEAK_DEFAULTS as a JSON block bracketed by /*EDITMODE-BEGIN*/ and
/*EDITMODE-END*/ markers. This enables a host-side Tweaks panel to scan
the artifact, render type-appropriate controls, and rewrite values via
string replacement — zero LLM token cost per tweak.

Included in both create and tweak modes. Host-side panel scan/rewrite
implementation lands in v0.2 (rewrite #74). This PR is protocol only.
@hqhq1025 hqhq1025 force-pushed the wt/loop-feat-editmode-protocol branch from 300b7ee to eb1a10c Compare April 19, 2026 05:42
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Findings

  • [Minor] Type detection 表格与 JSON 规则冲突,可能诱导模型输出不可解析的块并导致 host JSON.parse 失败。规则明确禁止注释,但表格又写了 “comment hint (TBD)”。证据:packages/core/src/prompts/editmode-protocol.v1.txt:22, packages/core/src/prompts/editmode-protocol.v1.txt:37, packages/core/src/prompts/index.ts:182, packages/core/src/prompts/index.ts:197
    Suggested fix:
    | Enum-like string (closed set by key/schema) | Select dropdown |

Summary

  • Review mode: follow-up after new commits
  • 1 issue found in added/modified lines (Minor)。
  • docs/VISION.mddocs/PRINCIPLES.md: Not found in repo/docs。

Testing

  • Not run (automation)

open-codesign Bot

| `true / false` | Toggle switch |
| Number (e.g. `1.0`, `16`, `0.5`) | Slider |
| Plain string | Text input |
| Enum-like string with comment hint (TBD) | Select dropdown |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Enum-like string with comment hint (TBD) conflicts with the rule above (No comments inside). This can push the model to emit invalid JSON in TWEAK_DEFAULTS, breaking host parsing.

Suggested fix:

| Enum-like string (closed set by key/schema) | Select dropdown |

Please apply the same row update in packages/core/src/prompts/index.ts to keep drift tests aligned.

@hqhq1025 hqhq1025 mentioned this pull request Apr 19, 2026
5 tasks
@hqhq1025
Copy link
Copy Markdown
Collaborator Author

Addressed Codex [Minor]: removed the Enum-like string with comment hint (TBD) row from the Type detection table (both editmode-protocol.v1.txt and the inlined EDITMODE_PROTOCOL const in prompts/index.ts). It contradicted the no-comments JSON rule and would have led the model into emitting comment-laden JSON that JSON.parse rejects. Real enum detection can return in v2; for now plain strings render as text input. Pushed as 48ad0f7. Drift test + full @open-codesign/core suite green (121/121).

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Findings

  • None.

Summary

  • Review mode: follow-up after new commits
  • No issues found in added/modified lines.
  • Residual risk/testing gap: targeted Vitest execution could not be run in this environment because pnpm is not available.
  • docs/VISION.md and docs/PRINCIPLES.md: Not found in repo/docs.

Testing

  • Not run (automation)

open-codesign Bot

@hqhq1025 hqhq1025 merged commit ab2493b into main Apr 19, 2026
5 of 6 checks passed
@hqhq1025 hqhq1025 deleted the wt/loop-feat-editmode-protocol branch April 19, 2026 07:27
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