Commit Graph

2 Commits

Author SHA1 Message Date
Eve
03ee42982b MUL-3560: gate runtime brief sections per task kind (PR 0.6)
Builds on PR 0.5's helper extraction. The dispatcher now skips
sections each task kind doesn't need, per Eve's Section × Kind
matrix on MUL-3560.

Measured impact (claude provider, full fixture with 2 repos + 10
skills, comparing PR 0.5 ↔ PR 0.6):

  kind                      PR 0.5    PR 0.6      Δ      Δ%
  ------------------------------------------------------------
  comment-triggered          19462    19462       0       0%
  assignment-triggered       18034    18034       0       0%
  autopilot-run-only         11174     8442  -2732     -24%
  quick-create               12497     4799  -7698     -62%
  chat                       11155     8423  -2732     -24%

  ✓ comment / assignment unchanged this PR (their diet comes from
    the per-section compression PRs #1..#9 on the roadmap)
  ✓ quick-create from 12.5k → 4.8k chars (-62%)
  ✓ autopilot and chat from 11k → 8k chars (-24% each)

The matrix encoded in `buildMetaSkillContent`:

  Section               | comment | assign | autopilot | quick_create | chat
  ----------------------+---------+--------+-----------+--------------+------
  Available Commands    |   full  |  full  |   full    |   minimal    | full
  Comment Formatting    |    ✓    |   ✓    |     —     |      —       |  —
  Repositories          |    △    |   △    |     △     |      —       |  △
  Project Context       |    △    |   △    |     —     |      —       |  —
  Issue Metadata        |    ✓    |   ✓    |     —     |      —       |  —
  Instruction Precedence|    —    |   ✓    |     —     |      —       |  —
  Sub-issue Creation    |    ✓    |   ✓    |     —     |      —       |  —
  Skills                |    ✓    |   ✓    |     ✓     |      —       |  ✓
  Mentions              |    ✓    |   ✓    |     —     |      —       |  —
  Attachments           |    ✓    |   ✓    |     —     |      —       |  —

What changed:

- runtime_config.go: the dispatcher now decides per kind which
  helpers to call. Always-on prelude unchanged. The matrix above
  is documented inline on `buildMetaSkillContent` and is the
  single source of truth.
- runtime_config_sections.go: new `writeAvailableCommandsQuickCreate`
  helper — emits only the `issue create` line plus the
  `multica --help` escape hatch (~500 chars vs ~4400 for the full
  variant). Used only when classifyTask returns kindQuickCreate.
- runtime_config_kind.go: `hasIssueContext` doc comment narrowed
  to the three real call sites (Project Context, Issue Metadata,
  Sub-issue Creation) per GPT-Boy's PR 0.5 review nit.
- runtime_config_kind_test.go:
  * TestBuildMetaSkillContentKindMatrix updated to encode the new
    expected section set per kind. Heading match tightened so it
    only fires on the heading line, not inline references like
    "See ## Comment Formatting below" inside Available Commands.
  * TestBuildMetaSkillContentQuickCreateAvailableCommands (new)
    locks the minimal-variant content: `issue create` is present,
    every other Core command — get / status / metadata / comment
    add / children / repo checkout / squad — is asserted absent.
- execenv_test.go: TestInjectRuntimeConfigIssueMetadataSectionScope
  now expects the metadata Core discovery lines to be ABSENT for
  quick-create (it uses the minimal Available Commands) and
  PRESENT for every other kind. Comment narrowed to match.

Verification:

- go vet ./internal/daemon/...                                       ok
- go test ./internal/daemon/... ./internal/handler/...               ok

Backwards compatibility:

- InjectRuntimeConfig signature unchanged (still 2-tuple).
- No new daemon flags, no new ctx fields, no per-provider changes.
- Reverting this commit restores PR 0.5 byte-for-byte; the change
  is contained inside buildMetaSkillContent's section selection.

Risk and follow-up:

- comment-triggered and assignment-triggered still ~19k each;
  their reduction lands in PRs #1 (Available Commands compression),
  #4 (Mentions compression), #5 (Issue Metadata compression).
- The full Available Commands variant retains "See ## Comment
  Formatting below" as an inline reference, which is now a
  dangling pointer for autopilot/chat where Comment Formatting is
  gated out. Cleanup deferred to PR #1 of the roadmap (Available
  Commands compression) — addressing it requires kind-specific
  Available Commands variants, which is exactly that PR's
  surface.

Co-authored-by: multica-agent <github@multica.ai>
2026-06-23 14:48:24 +08:00
Eve
38aa864e70 MUL-3560: refactor buildMetaSkillContent into kind-driven dispatcher
This is the structural prep PR for the runtime-brief diet roadmap on
MUL-3560 — split out from the per-section compression work so the
refactor risk and the content-gating risk land separately.

Output is byte-for-byte identical to the pre-refactor monolithic
builder for every existing test fixture. All existing tests pass
unchanged. The follow-up PR (0.6) will start gating sections per the
Section × Kind matrix from Eve's design comment on MUL-3560 (drop
Mentions / Comment Formatting / Issue Metadata / Sub-issue out of
quick-create, drop Comment Formatting / Mentions / Attachments out of
autopilot and chat, etc.), with negative assertions added alongside
each removal so each kind's brief contract becomes machine-checked.

What changed:

- runtime_config_kind.go (new): taskKind enum + classifyTask helper.
  Five kinds, mutually exclusive in practice; the documented
  precedence rule keeps the tiebreak deterministic even if a future
  caller breaks the mutex by accident. hasIssueContext is the
  predicate Issue Metadata and Sub-issue Creation gate on.
- runtime_config_sections.go (new): every section of the brief is
  extracted into its own writeXxx helper, preserving byte sequences
  exactly. Helpers with internal conditions keep those conditions;
  helpers the dispatcher always wants to call are unconditional.
- runtime_config.go: buildMetaSkillContent collapses from a
  ~450-line monolith to a ~70-line dispatcher — prelude, conditional
  context sections, a 5-way kind switch over Workflow bodies, and
  trailing sections. The matrix of "which kind gets which section"
  is now readable in one screen.
- runtime_config_kind_test.go (new): TestClassifyTask covers all 5
  kinds plus tiebreak cases; TestTaskKindHasIssueContext pins the
  predicate semantics; TestBuildMetaSkillContentKindMatrix is the
  structural canary that locks today's per-kind section set so any
  later PR that drops a section from a kind must update its
  expectations in lockstep.

Verification:

- go build ./...                                                      ok
- go vet ./internal/daemon/...                                        ok
- go test ./internal/daemon/... ./internal/handler/...                ok
- go test ./internal/daemon/execenv -run TestClassifyTask -v         pass
- go test ./internal/daemon/execenv -run TestTaskKindHasIssueContext pass
- go test ./internal/daemon/execenv -run TestBuildMetaSkillContent   pass

No production behaviour change in this PR. No new logging, no new
char-bucket fields — those are in PR #4439 and compose cleanly with
this refactor.

Co-authored-by: multica-agent <github@multica.ai>
2026-06-23 14:33:42 +08:00