Skip to content

Inline W₁₀ skill-refine into export_all_skills() with LLM refinement loop#1025

Open
akashgit wants to merge 4 commits into
mainfrom
feat/inline-w10-refine-1024
Open

Inline W₁₀ skill-refine into export_all_skills() with LLM refinement loop#1025
akashgit wants to merge 4 commits into
mainfrom
feat/inline-w10-refine-1024

Conversation

@akashgit

Copy link
Copy Markdown
Owner

Closes #1024

Changes

  • FnNode notes slots: _fn_to_instruction() now emits {{notes_{id}::...}} template slots for FnNode notes, making them refinable by the Opus reviewer. Added "notes_" to _SLOT_PREFIXES in splitter.
  • SKILL_SYNTHESIZER role: Added to AgentRole enum in primitives and runner's AgentRole Literal type.
  • Synthesizer prompt: Created factory/agents/prompts/skill_synthesizer.md — a convergent agent that cherry-picks best slot values across independently-refined candidates.
  • Parallel refine pipeline: export_all_skills() is now async with a refine: bool = True parameter. When enabled, runs 3x parallel skill_reviewer agents, guard-checks each, synthesizes survivors, with a full fallback chain (all fail → mechanical, synthesizer fails → best individual, best fails → mechanical).
  • Async call sites: ensure_skills() is now async. CLI call sites in ceo.py use _run(), workflow/cli.py uses asyncio.run().
  • --no-refine flag: Added to factory workflow export-skills subparser for fast mechanical-only output.
  • Tests: 19 new tests in test_skill_refine.py covering refine pipeline, fallback chain, notes slots, synthesizer prompt loading. Updated existing tests in test_skill_export.py and test_skill_cache.py for async compatibility.

…LLM refinement loop (#1024)

- Add notes_ template slots for FnNode in _fn_to_instruction() and splitter
- Add SKILL_SYNTHESIZER to AgentRole enum and runner Literal
- Create skill_synthesizer.md convergent agent prompt
- Make export_all_skills() async with refine parameter and 3x parallel
  reviewer → guard → synthesizer → fallback chain pipeline
- Make ensure_skills() async, update CLI call sites with _run()/asyncio.run()
- Add --no-refine flag to workflow export-skills subparser
- Add 19 tests covering refine pipeline, fallback chain, notes slots

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jul 18, 2026

Copy link
Copy Markdown

Sentrux Quality Report

Absolute

Scanning ....
[scan] git ls-files: 409 total, 397 kept, 12 dropped (ext:12, meta:0, big:0)
[build_project_map] 397 files, 70 unique dirs, 64 cache misses, 3.2ms
[resolve] 628 resolved, 949 unresolved (of 1577 total specs)
[resolve_imports] project_map 3.3ms, suffix_idx 0.7ms, suffix_resolve 11.6ms, total 15.5ms
[build_graphs] 397 files | maps 1.4ms, imports 15.6ms, calls+inherit 3.3ms, total 20.3ms | 627 import, 4693 call, 0 inherit edges
sentrux check — 3 rules checked

Quality: 4552

✗ [Error] max_cc: 5 function(s) exceed max cyclomatic complexity of 30
    factory/cli/ceo.py:cmd_ceo (cc=99)
    factory/study.py:study_project_local (cc=42)
    factory/cli/_wizard.py:_welcome_wizard (cc=39)
    factory/cli/ceo.py:cmd_run (cc=37)
    factory/workflow/validation.py:validate_workflow (cc=31)

✗ 1 violation(s) found

Diff (vs base branch)

Scanning ....
[scan] git ls-files: 409 total, 397 kept, 12 dropped (ext:12, meta:0, big:0)
[build_project_map] 397 files, 70 unique dirs, 64 cache misses, 3.2ms
[resolve] 628 resolved, 949 unresolved (of 1577 total specs)
[resolve_imports] project_map 3.3ms, suffix_idx 0.7ms, suffix_resolve 11.6ms, total 15.5ms
[build_graphs] 397 files | maps 1.4ms, imports 15.6ms, calls+inherit 3.2ms, total 20.2ms | 627 import, 4693 call, 0 inherit edges
sentrux gate — structural regression check

Quality:      4551 -> 4552
Coupling:     0.80 → 0.80
Cycles:       5 → 5
God files:    2 → 2

Distance from Main Sequence: 0.34

✓ No degradation detected

@codecov

codecov Bot commented Jul 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.91525% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.14%. Comparing base (d965dd5) to head (a683d7c).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
factory/workflow/cli.py 33.33% 2 Missing ⚠️
factory/workflow/skill_export.py 98.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1025      +/-   ##
==========================================
+ Coverage   89.10%   89.14%   +0.04%     
==========================================
  Files         124      124              
  Lines       14626    14689      +63     
==========================================
+ Hits        13032    13095      +63     
  Misses       1594     1594              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@akashgit

Copy link
Copy Markdown
Owner Author

✅ Factory Review: KEEP

Verdict: KEEP
Reason:


Posted by Factory CEO

@akashgit

Copy link
Copy Markdown
Owner Author

Factory KEEP Approval — Experiment #13

Verdict: KEEP

Quality Evidence

  • Tests: 1505 pass, 1 pre-existing failure (unrelated test_legacybench_gatetimeout command not found on macOS)
  • Lint: ruff clean
  • Types: mypy clean (135 source files)
  • QA Issues: 2 found, 2 fixed (DEFAULT_AGENT_POOL entry + redundant guard check)
  • Acceptance Criteria: 7/7 verified
  • Plan Deliverables: 14/14 satisfied
  • Growth dimension: capability_surface

Changes Summary

  1. FnNode notes wrapped in {{notes_{id}::...}} slots — reviewer can now refine them
  2. 3 parallel skill_reviewer agents via invoke_agents_parallel()
  3. Guard check on each candidate
  4. Synthesizer receives original + survivors, guard-checked
  5. 4-tier fallback chain (synthesized → best individual → mechanical)
  6. --no-refine flag for mechanical-only output
  7. All existing tests updated for async compatibility
  8. 19 new tests in test_skill_refine.py

Note

Precheck gate N/A — factory worktree has no project eval dimensions. Quality verified via deep-QA pipeline.

PR is ready for human merge. (Sacred Rule 6: factory does not merge PRs)

akashgit and others added 2 commits July 18, 2026 20:43
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@osilkin98

Copy link
Copy Markdown
Collaborator

@ceo-review

@github-actions github-actions 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.

✅ Factory Review: KEEP

Verdict: KEEP
Reason: QA: CLEAN — 3441 tests pass, 0 issues. Lint clean, types clean. 15 adversarial tests verified: refine pipeline, fallback chain, guard defense, async conversion, CLI flag, prompt loading all correct.

QA Analysis

Adversarial QA Report — PR #1025

Feature Under Test

Inline W₁₀ skill-refine pipeline into export_all_skills() with LLM refinement loop.

Test Results

Direct Feature Tests

# Test Command/Method Result
1 FnNode notes emit template slot workflow_to_skill_md() with notes VERIFIED
2 Empty notes produce no slot workflow_to_skill_md() without notes VERIFIED
3 _count_changed_slots() accuracy Direct call with 0/1/2 changes VERIFIED
4 export_all_skills(refine=False) produces output + annotations Direct call, check files VERIFIED
5 _slot_belongs_to_node() handles notes_ prefix Direct call VERIFIED
6 skill_synthesizer prompt loads correctly resolve_prompt('skill_synthesizer') VERIFIED
7 AgentRole.SKILL_SYNTHESIZER exists Enum attribute check VERIFIED

Fallback Chain Tests (Mock-Based)

# Test Scenario Result
8 All reviewers fail (rc!=0) 3x return code 1 VERIFIED — returns original templatized
9 Guard rejects all candidates 3x injected annotation violation VERIFIED — returns original, synthesizer NOT called
10 Happy path synthesizer 3x pass guard, synth passes guard VERIFIED — synthesizer called with correct ## Original + ## Candidate N
11 Exception in _refine_skill() RuntimeError raised VERIFIED — caught, mechanical fallback, SKILL.md still produced
12 --no-refine CLI flag argparse parsing VERIFIED — args.no_refine == True
13 Synth fails guard, best individual selected Synth output has injected annotation VERIFIED — picks survivor with most changed slots

Integration Tests

# Test Method Result
14 QA prompt has new sections (Step 3.0, 3.0b) resolve_prompt('qa') content check VERIFIED
15 Runner AgentRole includes new roles Literal type inspection VERIFIED

Test Suite Regression Check

  • 3441 tests pass, 0 failures, 13 skipped
  • Ruff lint: All checks passed
  • Mypy: Success: no issues found in 135 source files

Adversarial Observations

  1. Guard defense is effective: The guard correctly catches injected annotation comments and text-outside-slot modifications, preventing corrupted output from propagating.

  2. Fallback chain is robust: Three levels of fallback (synthesizer → best individual → mechanical) ensure the pipeline never produces no output.

  3. Exception safety: The broad except Exception in export_all_skills() around _refine_skill() ensures that even unexpected errors don't break skill generation — it logs the exception and falls back to mechanical output.

  4. No regression risk: refine=True is the default, but all existing tests pass refine=False, and the mechanical path is identical to the previous behavior.

  5. Async conversion is clean: The ensure_skills()_ensure_skills_inner()export_all_skills() chain uses proper async/await. CLI call sites correctly bridge with _run() (asyncio.run()) or asyncio.run() directly.

Issues Found

None.

Verdict

PASS — All 15 adversarial tests pass. No issues found. The refine pipeline is well-guarded with proper fallbacks.


Posted by Factory CEO

@osilkin98

Copy link
Copy Markdown
Collaborator

@akashgit It seems like there's a conflict with the factory/workflow/cli.py

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.

Inline W₁₀ skill-refine into export_all_skills() with LLM refinement loop

2 participants