matlab/matlab-agentic-toolkit / skills-catalog/matlab-software-development/matlab-package-toolbox
matlab-package-toolbox
VerifiedTurn raw MATLAB code into a published .mltbx toolbox — full pipeline from scope definition through packaging and release. Drives 8 phases with human checkpoints, enforcing ordering and dependencies. Use when asked to package, create a toolbox, or run the files-to-package pipeline.
references/phase-2-dependencies.md
View on GitHub# Phase 2: Analyze Dependencies
Produce the Dependency Manifest: a complete picture of what the toolbox needs at runtime, what ships inside the .mltbx, and what doesn't.
## Key Functions
| Function | Purpose |
|----------|---------|
| `matlab.addons.toolbox.ToolboxOptions` | Determine effective file set (what ships) |
| `matlab.codetools.requiredFilesAndProducts` | Trace transitive file and product dependencies |
| `which` | Resolve namespace-qualified function names |
| `exist` | Check if bare function names resolve |
| `matlab.addons.installedAddons` | Correlate add-on file paths with metadata |
## Critical Pitfalls
**Pitfall 1: Path Separator Mismatch (Windows)**
On Windows, `fList` returns backslashes regardless of input. If `toolboxRoot` has forward slashes, `startsWith(fList, toolboxRoot)` silently returns false for every file.
```matlab
toolboxRoot = replace(toolboxRoot, '/', filesep);
fList = replace(fList, '/', filesep);
```
**Pitfall 2: matlabroot File Leak**
Files under `matlabroot` occasionally appear in `fList`. Filter them out:
```matlab
mroot = matlabroot;
fList = fList(~startsWith(fList, mroot));
```
**Pitfall 3: Namespace Resolution Requires which()**
`exist('pkg.subpkg.func', 'file')` returns **0** even when the function is valid and on the path. For any dotted/namespace-qualified name, use `which()` instead:
```matlab
% exist() FAILS for namespace calls:
exist('statskit.internal.computeRange', 'file') % returns 0 (wrong!)
% which() WORKS:
which('statskit.internal.computeRange') % returns full path
```
**Resolution strategy:**
- Bare names (no dots): `exist(name, 'file') > 0 || exist(name, 'builtin') > 0`
- Dotted names: `~isempty(which(name))`
## Core Concepts
**The Packaging Constraint:** An .mltbx can only contain files inside the toolbox root folder. External files cannot be pulled in at install time. Options: copy in, declare add-on dependency, Additional Software (URL zip), or refactor.
**The Effective File Set:** All files in toolbox root minus those excluded by the ignore file and default exclusions. Use `ToolboxOptions` to determine this authoritatively. The ignore file may be named `toolbox.ignore` (R2026a and earlier).
## Step 2.1 — Determine the Effective File Set
```matlab
identifier = matlab.lang.internal.uuid();
opts = matlab.addons.toolbox.ToolboxOptions(toolboxRoot, identifier);
effectiveFiles = opts.ToolboxFiles;
```
Do not reimplement ignore-file logic manually.
## Step 2.2 — Trace Dependencies
```matlab
mFiles = effectiveFiles(endsWith(effectiveFiles, ".m") | endsWith(effectiveFiles, ".mlx"));
[fList, pList] = matlab.codetools.requiredFilesAndProducts(mFiles);
fList = string(fList(:));
```
Apply Pitfall 1 and Pitfall 2 **immediately after** getting fList.
**Classify files in fList:**
- **Included**: starts with `toolboxRoot` and in effective set
- **Add-on**: under `fullfile(getenv('APPDATA'), 'MathWorks', 'MATLAB Add-Ons')`
- **External unresolved**: everything else — requires user decision
**Classify products from pList:**
- `Certain == 1`: confirmed product dependency — declare in metadata
- `Certain == 0`: heuristic guess — flag for user confirmation
**Check ignore conflicts:** Files inside toolbox root that are in `fList` but NOT in `effectiveFiles` — code needs them but they won't ship.
**Check runtime file references:** `fList` never contains data files (.mat, .csv, images, etc.). Scan `.m` files for I/O functions with string-literal path arguments. See `references/runtime-file-references.md`.
## Step 2.3 — Detect Unresolved Symbols
`requiredFilesAndProducts` silently skips unresolvable symbols. For each file, extract candidate function names (via `mtree` or regex `(?<![%.\w])([a-zA-Z]\w*)\s*\(`). Filter out MATLAB keywords, the function's own name, local functions, variables in `arguments` blocks.
For dotted identifiers, apply Pitfall 3 — use `which()`.
See `references/unresolved-symbol-classification.md` for classification and presentation.
## Step 2.4 — Transitive Closure of External Files
For each external file, trace its dependency subtree. At each level classify children. Build the tree showing pull-in cost.
**Early termination:** If subtree exceeds ~15 files across multiple directories, mark as "sprawling."
**Deduplication:** Use `'toponly'` on each toolbox file to find which externals are directly called.
**Detect patterns:** Multiple externals from same directory → group them.
## Step 2.5 — Present Results
Produce a tree view showing directly-called externals with call chains and transitive cost. See `references/tree-view-format.md`.
## Step 2.6 — Recommend Resolution Options
Present options with tradeoffs for each unresolved external or group. See `references/resolution-options.md`.
This phase **does not perform resolutions**. It presents options so the user can decide.
## Step 2.7 — Persist the Manifest
Save as `buildUtilities/tbxManifest.m`. See `scripts/tbxManifest-template.m`.
## Rules
- Show the full transitive cost of pulling in any external
- Surface same-folder groups as one architectural decision, not N individual ones
- Present resolution options with tradeoffs — do not execute them
- Flag ignore conflicts — a needed-but-excluded file is a silent packaging bug
----
Copyright 2026 The MathWorks, Inc.
----
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |