<SKILL_OS2_CLASSIC_REXX_CORE>
## Critical REXX Variant Requirement
- Exclusively use CLASSIC REXX syntax. NO ooREXX (Object REXX).
- Remain 100% compatible with stock REXX.DLL / REXXHIDE / CMD.EXE.

## Architecture & Flow Control (Recursion vs. Iteration)
- VERIFIED Limitation: Object REXX (ooRexx) under OS/2 has a strict machine stack limit for procedure calls. The interpreter crashes at exactly 100 consecutive recursive calls with "Error 5 / Error 43" or silent termination. Stack frames cannot be freed manually via `DROP`.
- Rule: NEVER use recursive procedures when the recursion depth is unknown or depends on variable data sizes (e.g., JSON parsing, global string replacements, deep directory tree traversals).
- Exception: Recursion is only permitted for strictly bounded operations where the maximum depth is mathematically guaranteed to remain well below 50.
- Workaround: ALWAYS use iterative loops (`Do While`, `Do Forever`) with state variables instead of recursion for data processing.

## Mandatory OS/2 System & IO Rules
- Host Command Environment: ALWAYS use `address cmd`.
- VERIFIED CMD.EXE Limit: `ADDRESS CMD` commands are hard-truncated at exactly 1024 bytes. NEVER pass large JSON payloads directly via cURL arguments. ALWAYS write payloads to a temporary text file first and pass the file (`curl -d @temp.json`).
- VERIFIED File-Locking: `LINEIN()` and `LINEOUT()` open files with an implicit exclusive lock. ALWAYS explicitly release the file after reading/writing using `Call Stream file, 'C', 'CLOSE'` to prevent OS/2 system blocking and `NOTREADY` errors.
- Directory Changing (DIRECTORY): When using `CALL DIRECTORY(path)`, OS/2 requires the trailing backslash for root drives (e.g. `C:\`) but it MUST be stripped for subdirectories (e.g. `C:\DIR`).
- cURL / Web: Redirect to temp file (`-o temp.txt`). NO `WITH OUTPUT STEM`. Read line-by-line, then `del`.
- RexxUtil: Load via `SysLoadFuncs` at script start.
- SysFileTree: Returns `0` on SUCCESS. ALWAYS check `If SysFileTree(...) = 0 Then Do` and subsequently `If stem.0 > 0`.
- Paths: Use native OS/2 separators (`\`).

## Critical Stem, Variable & Symbol Rules
- DOCUMENTED Symbol Limit: Variable names, stem names, and labels must NOT exceed 250 characters. Syntax errors will occur if dynamic JSON keys exceed this limit when used as variables.
- Stem Tail Shadowing: NEVER use local variables matching a stem's tail name. Use prefixes (`curr`, `tmp`, `val`, `local`).
- Expose: ALWAYS explicitly list the exact stem name.
- Lowercase Compounds: Prefer strict LOWERCASE names for variables.
- Arg vs. Parse Arg (Critical): NEVER use the shorthand `Arg` in a subroutine when handling case-sensitive data (like JSON payloads, API responses, or exact strings). `Arg` translates to `Parse Upper Arg`. ALWAYS use `Parse Arg var1, var2` to strictly preserve capitalization.

## Math, Date, Logic & Formatting
- VERIFIED FORMAT() Crash: Passing an empty string `""`, strings with invisible control characters, or non-numeric strings to `FORMAT()` causes a hard `Error 40: Incorrect call to routine` crash. ALWAYS validate with `DATATYPE(var, 'N')` before formatting.
- VERIFIED SysSleep() Crash: Passing a floating-point number (e.g., `0.5`) to `SysSleep()` causes an `Error 40` crash. ALWAYS pass integers.
- Boolean: REXX does NOT short-circuit `|` and `&`. Nest `IF` statements.
- Dates: DO NOT use `ooREXX` options (`J`, `I`) or the 3-parameter `Date('B', dateVal, 'S')` (RC 40 crash). Use manual mathematical calendar procedures.


## VERIFIED BUG: REXX SubStr Padding
  - Bug Description: In OS/2 Classic REXX, `SubStr(string, start, length)` does NOT silently stop at the end of the string. If the requested `length` is greater than the remaining characters, REXX automatically pads the result with ASCII spaces (`'20'x`) up to the requested length.
  - Impact: Exponential whitespace bloat and memory corruption when chunking data (e.g., writing files in 8 KB blocks), leading to API 400 errors or extreme payload sizes.
  - Mitigation Rule: ALWAYS calculate and cap the exact length for the final chunk.
  - Safe Code Pattern:
  ```rexx
  rem_len = total_len - start_pos + 1
  take_len = Min(rem_len, chunk_size)
  chunk = SubStr(data, start_pos, take_len)
</SKILL_OS2_CLASSIC_REXX_CORE>