Skip to main content
ClaudeWave
Skill60 repo starsupdated today

corezoid-process-optimizer

>

Install in Claude Code
Copy
git clone --depth 1 https://github.com/corezoid/corezoid-ai-plugin /tmp/corezoid-process-optimizer && cp -r /tmp/corezoid-process-optimizer/plugins/corezoid/skills/corezoid-process-optimizer ~/.claude/skills/corezoid-process-optimizer
Then start a new Claude Code session; the skill loads automatically.

SKILL.md

# Corezoid Process Optimizer

## Mode and scope detection

Determine **mode** and **scope** from the user's phrasing before doing anything else.

### Mode

| User intent | Mode |
|-------------|------|
| "optimize", "apply", "fix", "improve" — action verb | **AUTO** — analyze, plan, execute |
| "show", "what can", "suggest", "check" — analysis verb | **PLAN** — analyze, report, wait |

In PLAN mode, after presenting the report ask:
> "Apply all? Apply by group? (1 — tacts, 2 — data, 3 — naming, 4 — resilience)"

### Scope

The user may request a specific optimization group. Detect from keywords:

| Keyword(s) in request | Scope — run only |
|-----------------------|------------------|
| "tacts", "tact", "state changes", "nodes", "merge" | Group 1 |
| "data", "payload", "cleanup", "garbage", "fields" | Group 2 |
| "names", "naming", "titles", "readability", "descriptions" | Group 3 |
| "resilience", "semaphors", "timeouts", "stability" | Group 4 |
| No group keyword — general request | All groups |

If scope is a single group — run Phase 1 analysis only for that group. Skip all others entirely.
Still run `lint-process` first (its findings feed Group 1 regardless).

Examples:
- "optimize by tacts" → AUTO + Group 1 only
- "show tact optimizations" → PLAN + Group 1 only
- "add missing semaphors" → AUTO + Group 4 only
- "optimize" → AUTO + all groups

---

## Step 0 — Resolve process

Resolve `PROCESS_PATH` before calling any tools:
1. Check if the user provided a path, name, or ID.
2. If not — ask: "Which process? Provide a file path, name, or ID."
3. If name or ID — search locally: `find . -name "*.conv.json"`.
4. Read and parse the file.
5. Call **`lint-process`** — record findings. They become Group 1 quick-wins.

---

## Step 1 — Analyze

Build a node map: `id → { title, obj_type, logics[], sems[], outgoing edges }`.

Trace the execution graph from the Start node following `go.to_node_id` and `err_node_id` edges.

Collect candidates for all four groups below.

---

## Group 1 — Tact Reduction

> Formula: SC = (N – 1) × T. Every node transition costs one state change. Fewer nodes = fewer tacts.

### 1.1 Merge consecutive set_param nodes

Detect chains A → B → C where all nodes have `type: "set_param"`, connected sequentially with no branching.

Merge condition: all nodes share the same `err_node_id` (or all have none).
If `err_node_id` values differ — flag as candidate, do not merge automatically.

Merge action: combine all `extra` and `extra_type` objects into the first node. Remove subsequent nodes. Reconnect routing to where the chain ended.

Tacts saved: (chain length − 1) per task.

---

### 1.2 Merge consecutive code nodes

Detect chains of `type: "api_code"` nodes connected sequentially with no branching.

Merge condition: all share the same `err_node_id`.
If different — flag only; note that error handling must be unified first.

Merge action: concatenate `src` fields in order, separated by `\n// ---\n`. Keep one `err_node_id`. Remove subsequent nodes. Reconnect routing.

Tacts saved: (chain length − 1) per task.

---

### 1.3 Merge consecutive condition nodes checking the same field

Detect chains of `type: "go_if_const"` nodes where all check the **same `arg` field**.

Merge action: combine all `conditions[]` arrays into the first node. Each original branch keeps its own `to_node_id`. Remove subsequent condition nodes.

Do NOT merge if conditions check different fields — different semantics, merging hurts readability.

After merging, add a note to the plan:
> "Merged conditions on field '{{field}}'. Review combined node for readability."

Tacts saved: (chain length − 1) per task.

---

### 1.4 Replace api_rpc with api_copy when reply is unused

Detect `api_rpc` nodes where no downstream node references any field that could only originate from the called process's reply.

Check: scan all downstream `extra`, condition `arg`/`val`, and `src` fields for parameter names not present in the task before the call. If none found — candidate for api_copy.

This change requires confirmation even in AUTO mode. Present:
> "Node '[title]' calls process but does not use the reply. Replace with api_copy (fire-and-forget)? [yes/no]"

If confirmed: change `type: "api_rpc"` → `type: "api_copy"`. Switch `extra`/`extra_type` to `data`/`data_type` per the api_copy schema (see `${CLAUDE_PLUGIN_ROOT}/docs/node-structures.md`).

---

### 1.5 Remove dead nodes

Apply lint findings:
- **Orphaned nodes** — remove from `scheme.nodes`.
- **No-op conditions** — re-route the incoming edge to the single destination; remove the condition node.
- **Unused set_params** — if the node sets only unused variables, remove the node. If mixed, remove only the unused keys from `extra`/`extra_type`.

---

## Group 2 — Data Cleanup

### 2.1 Inline payload cleanup after API calls

After each `type: "api"` node, identify response fields not referenced by any downstream node.

Do NOT add a new cleanup node — inline the cleanup into the nearest existing downstream node:
- **code node**: prepend `delete data.<field>;` at the top of `src`.
- **set_param node**: set_param cannot delete keys. Find the next code node and add the delete there. If no downstream code node exists — flag for the user, do not create a new node.

---

### 2.2 Remove dead code inside code nodes

Inside each `api_code` node's `src`, detect:
- `data.x = data.x` — self-assignment, remove.
- Variables declared but never read after declaration — flag for user review.
- Large commented-out blocks — flag for user review.

---

## Group 3 — Readability

Run this group when:
- User explicitly requested it, OR
- AUTO mode is active.

**Critical nodes always get titles filled** regardless of mode:

| Node type | Always fill `title` if empty |
|-----------|------------------------------|
| `api_code` | Yes |
| `api` | Yes |
| `api_rpc` | Yes |
| `api_copy` | Yes |
| `obj_type: 2` (End/Error) | Yes |

### Title inference rules

| Node type | Inference |
|-----------|----