Skip to content

Commit b6fe4db

Browse files
committed
feat(skill): add umbrella gecode skill
1 parent a1ee9be commit b6fe4db

15 files changed

Lines changed: 513 additions & 14 deletions

README.md

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,43 @@
11
# Gecode Skills
22

3-
Repository infrastructure for publishing Gecode-focused AI agent skills.
3+
Canonical skill repository for the umbrella Gecode AI agent skill.
44

5-
This branch sets up validation, CI, and release automation. It does not introduce a published skill yet.
5+
Install with:
66

7-
## Infrastructure
7+
```bash
8+
npx skills add Gecode/gecode-skills
9+
```
10+
11+
List available skills:
12+
13+
```bash
14+
npx skills add Gecode/gecode-skills --list
15+
```
816

9-
Included here:
17+
Install a single skill:
1018

11-
- GitHub Actions for validation and release publishing
12-
- semver/version helper scripts
13-
- release policy gating through `.release-policy.yml`
14-
- generic skill validation that works before any skill is added
19+
```bash
20+
npx skills add Gecode/gecode-skills --skill gecode
21+
```
1522

16-
## Future Skill Layout
23+
## Available Skill
1724

18-
Skills will live under:
25+
- `gecode`
1926

20-
- `skills/<skill-name>/SKILL.md`
27+
The skill routes internally to focused reference documents for:
28+
- Gecode architecture and runtime semantics
29+
- modeling and search setup
30+
- custom propagators
31+
- custom branchers
32+
- memory management
33+
- built-in search engines
34+
- custom search engine implementation
2135

2236
## Contributing
2337

2438
### Skill structure
2539

26-
Each skill must be under:
40+
The skill must be under:
2741

2842
- `skills/<skill-name>/SKILL.md`
2943

@@ -33,7 +47,7 @@ Optional metadata for UIs can be added at:
3347

3448
### Required frontmatter
3549

36-
Each `SKILL.md` must include YAML frontmatter with:
50+
`SKILL.md` must include YAML frontmatter with:
3751

3852
- `name`
3953
- `description`
@@ -48,7 +62,7 @@ Auto-release determines semver bump from PR labels:
4862
- `release:minor` -> minor bump
4963
- no label -> patch bump
5064

51-
## Release Policy
65+
## Release policy
5266

5367
Releases are controlled by `.release-policy.yml`.
5468

evals/gecode-trigger-evals.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
[
2+
{
3+
"query": "I'm implementing a cumulative-style constraint in Gecode and the decomposition is too weak. I think I need a custom propagator with better domain filtering. Can you sketch the post/propagate structure and what propagation conditions I should subscribe to?",
4+
"should_trigger": true
5+
},
6+
{
7+
"query": "I need a custom Gecode brancher for a packing model where the second alternative should encode a symmetry-breaking exclusion. How should I structure the choice payload and commit logic so recomputation stays safe?",
8+
"should_trigger": true
9+
},
10+
{
11+
"query": "My Gecode model solves, but BAB is crawling. Help me decide whether to stay on BAB, switch to restart-based search, or diversify with PBS. I also want to understand the completeness tradeoffs.",
12+
"should_trigger": true
13+
},
14+
{
15+
"query": "Can you help debug a Gecode issue where a stored choice seems invalid after recomputation? The model uses custom branchers and I suspect I'm breaking clone or commit invariants.",
16+
"should_trigger": true
17+
},
18+
{
19+
"query": "Please model this scheduling problem in Gecode with strong global constraints, sensible symmetry breaking, and a branching strategy that focuses on the cost-driving variables first.",
20+
"should_trigger": true
21+
},
22+
{
23+
"query": "My Gecode search tree exploded after I added a few side constraints. I need a debugging workflow for deciding whether the problem is weak propagation, bad branching, or missing symmetry breaking.",
24+
"should_trigger": true
25+
},
26+
{
27+
"query": "I want a cookbook-style answer for modeling a Gecode optimization problem with channeling, a couple of implied constraints, and a clean brancher order. Think recipe, not theory.",
28+
"should_trigger": true
29+
},
30+
{
31+
"query": "How should I model this warehouse assignment problem in Gecode if each customer can be assigned to a set of depots and I care about subset and cardinality structure? I think set vars might fit better than raw ints.",
32+
"should_trigger": true
33+
},
34+
{
35+
"query": "I'm using Gecode with a mix of discrete choices and continuous tolerances. What should I watch out for when float vars are part of the model, especially compared with ordinary integer branching intuition?",
36+
"should_trigger": true
37+
},
38+
{
39+
"query": "How would you model a nurse rostering problem in constraint programming? I'm open to any solver or even OR-Tools, I mainly want high-level CP advice.",
40+
"should_trigger": false
41+
},
42+
{
43+
"query": "I'm debugging a C++ memory leak around std::shared_ptr and custom allocators. This is ordinary application code, not a solver, and I'm not using Gecode.",
44+
"should_trigger": false
45+
},
46+
{
47+
"query": "Can you explain branch and bound versus depth-first search in general terms? I don't need implementation details for any particular library.",
48+
"should_trigger": false
49+
},
50+
{
51+
"query": "What are good heuristics for graph coloring in CP, and how do I think about symmetry? Solver-agnostic advice is fine.",
52+
"should_trigger": false
53+
},
54+
{
55+
"query": "My game engine is slow and I want advice on profiling frame spikes with Tracy and Instruments. This has nothing to do with constraint programming.",
56+
"should_trigger": false
57+
},
58+
{
59+
"query": "I need help modeling a production schedule, but I'm doing it in CP-SAT and mostly want generic scheduling ideas, not Gecode-specific guidance.",
60+
"should_trigger": false
61+
}
62+
]

skills/gecode/SKILL.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
name: gecode
3+
description: "Gecode architecture, modeling, cookbook-style modeling patterns, set/float/scheduling guidance, propagators, branchers, memory management, search engine usage and implementation, recomputation/cloning behavior, and debugging/performance diagnosis. Use for any materially Gecode-specific task: building or refining Gecode models, implementing custom constraints or branchers, tuning DFS/BAB/RBS/PBS/LDS search, diagnosing weak propagation or search pathologies, or reasoning about set/float/resource-style models."
4+
---
5+
6+
# Gecode
7+
8+
Use this skill as the entry point for any Gecode-specific task. Carry the universal Gecode runtime model in mind for every response, then load only the additional reference files needed for the task.
9+
10+
## Always-On Mental Model
11+
- Space is the home for variables, propagators, branchers, and optimization order.
12+
- Propagation is explicit: call `status()`.
13+
- Search primitives are `status()`, `choice()`, `clone()`, `commit()`, and `constrain()`.
14+
- Space status values are `SS_FAILED`, `SS_SOLVED`, and `SS_BRANCH`.
15+
- Choice is a space-independent descriptor; alternatives are indexed `0..n-1`.
16+
- Choice compatibility is clone-based: a choice is valid for its source space and clones.
17+
- `choice()` invalidates previous choices for later `commit()` on that space.
18+
- Clone only stable, non-failed spaces.
19+
- Branchers run in posting order.
20+
- Recomputation can be nondeterministic with weakly monotonic propagation while remaining sound and complete.
21+
- Model as `class M : public Space`, implement copy constructor and virtual `copy()`, and update variable arrays with `x.update(home, s.x)` during cloning.
22+
- After `status()==SS_BRANCH`, compute `choice()` immediately.
23+
- Treat returned solutions as owned `Space` objects and delete seed models, choices, and solution spaces explicitly.
24+
- Do not assume posting performs full propagation.
25+
- Do not call the `Space` copy constructor directly instead of `clone()`.
26+
- Do not reuse stale choices after another `choice()` call.
27+
28+
## Default Gecode Heuristics
29+
- Tighten variable domains as early as possible.
30+
- Prefer global constraints over weak manual decompositions.
31+
- Keep branching explicit and problem-specific rather than relying on generic defaults.
32+
- Treat symmetry handling as first-class design work.
33+
- Use `DFS` as the baseline complete search engine.
34+
- Use `BAB` for optimization unless there is a concrete reason to move to restart or portfolio search.
35+
- Treat restart, portfolio, and parallel search behavior as intentionally nondeterministic.
36+
- Remember that clone footprint matters when designing actor state and cached data.
37+
- Use explicit disposal discipline for external or heap-backed resources.
38+
39+
## Routing
40+
- Read `references/modeling.md` for model structure, variables, constraints, branching setup, and built-in search configuration.
41+
- Read `references/modeling-cookbook.md` when the user needs concrete recipe-style guidance for channeling, symmetry, branching, optimization setup, or choosing globals versus decompositions.
42+
- Read `references/debugging-workflow.md` for weak propagation, exploding search trees, stale choices, recomputation bugs, memory growth, or tracing/profiling workflow.
43+
- Read `references/set-and-float-modeling.md` for set-variable modeling, float-specific caveats, or mixed-domain modeling.
44+
- Read `references/scheduling-patterns.md` for cumulative/resource-style models, sequencing/order constraints, and scheduling-oriented branching or symmetry choices.
45+
- Read `references/propagator-implementation.md` for custom propagator design, posting, propagation lifecycle, advisors, and rewriting.
46+
- Read `references/brancher-implementation.md` for custom branchers, choices, commits, archiving, and NGL support.
47+
- Read `references/memory-handling.md` for space/region/heap allocation, handles, clone footprint, and disposal obligations.
48+
- Read `references/search-engines.md` for using and tuning built-in engines such as `DFS`, `BAB`, `LDS`, restart, and portfolio search.
49+
- Read `references/search-engine-implementation.md` for custom engine orchestration, recomputation strategy, LAO, and completeness invariants.
50+
- Read `references/general-knowledge.md` only for broad conceptual explanations, tracing/observability guidance, or staged model-improvement workflow discussion that goes beyond the always-on mental model.
51+
52+
## Operating Rules
53+
- Read only the reference file or files needed for the current task.
54+
- Combine references only when the task genuinely crosses boundaries, such as a custom propagator with nontrivial memory strategy or a search-engine bug tied to choice compatibility.
55+
- Prefer the narrowest useful reference set first, then expand if the user asks for adjacent concerns.
56+
- Keep answers Gecode-specific. If the request is generic CMake, generic C++ memory, or generic CP theory without a real Gecode angle, do not over-apply this skill.
57+
- Use this `SKILL.md` alone for broad explanations, initial modeling guidance, and many runtime/debugging answers before reaching for extra references.
58+
59+
## Reference Index
60+
- `references/general-knowledge.md`: advanced observability, staged improvement workflow, and broad conceptual framing beyond the always-on core.
61+
- `references/modeling.md`: variable selection, globals, reification, symmetry, branching, and search setup in ordinary models.
62+
- `references/modeling-cookbook.md`: concrete modeling recipes for globals, channeling, symmetry, branching, optimization, and “propagation versus search” decisions.
63+
- `references/debugging-workflow.md`: symptom-driven diagnosis for weak models, stale choices, recomputation issues, performance pathologies, and observability tooling.
64+
- `references/set-and-float-modeling.md`: set-variable patterns, float-specific caveats, and mixed-domain modeling reminders.
65+
- `references/scheduling-patterns.md`: scheduling/resource modeling patterns, sequencing constraints, and search guidance for schedule-like problems.
66+
- `references/propagator-implementation.md`: actor lifecycle, `ExecStatus`, propagation conditions, iterators, advisors, and rewrite patterns.
67+
- `references/brancher-implementation.md`: `status`, `choice`, `commit`, archive compatibility, NGLs, and heuristic encoding.
68+
- `references/memory-handling.md`: memory areas, lazy vs eager allocation, shared/local handles, and `AP_DISPOSE` discipline.
69+
- `references/search-engines.md`: engine selection, restart/portfolio tradeoffs, no-goods, parallel semantics, and completeness caveats.
70+
- `references/search-engine-implementation.md`: custom engine state, replay/recomputation, ownership, branch-and-bound integration, and invariants.

skills/gecode/agents/openai.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
interface:
2+
display_name: "Gecode"
3+
short_description: "Route any Gecode task to the right internal reference"
4+
default_prompt: "Handle this Gecode-specific task by reading only the relevant internal reference files, then provide concise, technically accurate guidance."
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Gecode Brancher Implementation
2+
3+
## Core
4+
- Brancher is the actor that implements branching behavior.
5+
- Implement `status`, `choice(Space&)`, `choice(const Space&, Archive&)`, `commit`, `print`, `copy`, and `dispose`.
6+
- Choice stores only space-independent commit data.
7+
- `commit` must work with recomputed or cloned spaces using only the choice payload.
8+
- Choices must be archive-compatible and deterministic.
9+
- Branchers execute in queue order of posting.
10+
- Optional `ngl()` adds no-good support.
11+
- `status()==false` does not imply immediate disposal; commits for earlier choices must remain valid.
12+
13+
## Key Patterns
14+
- Track the first candidate index such as `start` to avoid rescanning.
15+
- Keep the choice payload minimal, for example `pos`, `val`, and alternative count, and archive it deterministically.
16+
- Use binary alternatives such as `eq` versus `nq` unless an assignment brancher genuinely needs a single alternative.
17+
- Implement an NGL class with `status`, `prune`, `subscribe`, `cancel`, and `reschedule`.
18+
- For complementary last alternatives, `ngl()` can return `NULL` when that is semantically valid.
19+
- Reuse branchers through views, notably minus views for max-style variants.
20+
- Encode the problem heuristic explicitly, such as Warnsdorff or best-fit slack.
21+
- Mix assignment-style one-alternative choices with pruning alternatives only when the heuristic justifies it.
22+
- Design second alternatives to embed symmetry breaking when safe.
23+
- Pair the brancher with branch print callbacks for explainability and debugging.
24+
25+
## Pitfalls
26+
- Storing views or pointers to space state inside choice objects.
27+
- Disposing the brancher too early when `status()` becomes false.
28+
- Depending on mutable brancher state not encoded in the choice for `commit()`.
29+
- Using choices after invalidation by a later `choice()` call on the same space.
30+
- Not skipping assigned views, causing repeated same choice or an infinite tree.
31+
- Violating recomputation invariants and commit-order assumptions.
32+
- Using generic variable-value branching when a structure-aware heuristic is required.
33+
- Forgetting that brancher disposal is not automatic when external resources exist.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Gecode Debugging Workflow
2+
3+
## Symptom: Search Tree Explodes
4+
- First ask whether the model is weak or the branching is weak; the fix is often different.
5+
- Check initial domains, missing implied constraints, and whether a stronger global can replace a weak decomposition.
6+
- Compare nodes and failures before and after modeling changes; do not trust runtime alone.
7+
- If propagation looks adequate but the tree is still huge, inspect branching order, value choice, and symmetry breaking.
8+
- Use `DFS` as a baseline before judging restart or portfolio search.
9+
10+
## Symptom: Branching or Recomputation Looks Wrong
11+
- Suspect stale choices if behavior changes after another `choice()` call on the same space.
12+
- Recheck choice compatibility: choices must be valid only for the originating space and its clones.
13+
- Confirm `commit()` uses only archived, space-independent choice payload.
14+
- If a bug appears only after deeper search, compare direct-clone behavior versus replayed recomputation behavior.
15+
- When a custom brancher is involved, inspect queue order, assigned-view skipping, and brancher disposal timing.
16+
17+
## Symptom: Propagation Is Wrong or Too Weak
18+
- Separate correctness bugs from strength issues. Wrong answers or unexplained failure usually mean correctness; huge trees with valid answers usually mean weak propagation.
19+
- Re-check subscriptions, propagation conditions, and whether the propagator actually reaches fixpoint when it should.
20+
- Replace weak decompositions with stronger globals or a dedicated propagator when two ordinary constraints do not reason jointly enough.
21+
- Use advisor-based localization only when the extra complexity is justified by change locality.
22+
- If reification is involved, verify the exact semantics of the chosen decomposition rather than assuming the control literal forces a benign fallback.
23+
24+
## Symptom: Memory or Clone Footprint Is Too Large
25+
- Inspect what state is copied into every clone and move resize-heavy data away from space memory when appropriate.
26+
- Prefer lazy construction for heavy internal state when many branches will never need it.
27+
- Check external-resource ownership and `AP_DISPOSE` discipline before assuming the issue is search alone.
28+
- Watch for per-choice heap allocations in hot paths, especially inside custom branchers.
29+
- If recomputation is cheaper than cloning the current state, revisit search options and state layout together.
30+
31+
## Observability Tools
32+
- Use groups and tracing to narrow which parts of the model or search are active at the wrong time.
33+
- Use Gist or CPProfiler when you need to see search-tree shape, branching behavior, and failure concentration rather than just counters.
34+
- Measure nodes, failures, restarts, and memory-related symptoms alongside runtime.
35+
- Improve in loops: baseline, strengthen propagation, improve branching, then tune search and memory strategy.
36+
37+
## Escalation Paths
38+
- For custom propagation mechanics, continue into `propagator-implementation.md`.
39+
- For stale-choice, commit, or NGL issues, continue into `brancher-implementation.md`.
40+
- For memory ownership and clone-footprint problems, continue into `memory-handling.md`.
41+
- For restart, no-good, and completeness behavior, continue into `search-engines.md` or `search-engine-implementation.md` depending on whether you are using or implementing engines.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Gecode General Knowledge
2+
3+
## Advanced Framing
4+
- Use groups and tracing for observability and selective control.
5+
- Improve models in loops: baseline, stronger propagation, better branching, then tuned search.
6+
- Measure with nodes, time, and restarts, not runtime alone.
7+
- Treat symmetry handling as a first-class design concern, not post-processing.
8+
9+
## Conceptual Pitfalls
10+
- Assuming parallel search preserves sequential solution order or runtime profile.
11+
- Assuming one modeling pass is enough; most nontrivial case studies need staged refinement.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Gecode Memory Handling
2+
3+
## Core
4+
- Memory areas are space, region, heap, and space freelists.
5+
- `alloc`, `realloc`, and `free` follow C++ object lifecycle semantics.
6+
- Space memory is reclaimed automatically on space deletion and fits stable-size actor data.
7+
- Region is a temporary arena with implicit free on region destruction.
8+
- Heap is for frequently resized or dynamic structures.
9+
- Search memory profile favors pristine clones, so allocation timing matters.
10+
- Shared handles point to cross-space or cross-thread shared heap objects with reference counting.
11+
- Local handles point to per-space shared objects copied on cloning.
12+
13+
## Key Patterns
14+
- Allocate fixed actor members in home space.
15+
- Allocate resize-heavy buffers on the heap and free them in `dispose()`.
16+
- Build heavy internal state lazily on first propagation when possible.
17+
- Choose eager, lazy, or hybrid allocation based on clone footprint and expected hit rate.
18+
- Use regions for short-lived iterators and temporary buffers.
19+
- Call `Region::free()` at clear control-flow boundaries to maximize reuse.
20+
- Use `SharedHandle` for immutable or global lookup data.
21+
- Use `LocalHandle` for shared per-space mutable state.
22+
- Use `IntSharedArray` or related shared arrays for read-only large data reused across clones.
23+
- For brancher choices using heap buffers, pair allocation and free, and register `AP_DISPOSE`.
24+
- Use `Region` for per-choice scratch arrays to avoid heap churn.
25+
26+
## Pitfalls
27+
- Frequent resize in space memory causing fragmentation.
28+
- Forgetting `home.notice(..., AP_DISPOSE)` for external or heap resources.
29+
- Forgetting the matching `home.ignore(..., AP_DISPOSE)` in the dispose path.
30+
- Assuming identical alignment guarantees across space, heap, and region memory.
31+
- Leaking ownership assumptions across cloning boundaries.
32+
- Allocating per-choice temporary arrays on the heap in hot paths.

0 commit comments

Comments
 (0)