<SKILL_OS2_CLASSIC_REXX_CORE>
## Critical REXX Variant & Runtime Requirement
- Syntax Rule: Exclusively write CLASSIC REXX syntax. NEVER use ooRexx (Object REXX) syntax, classes, or methods (like `~`).
- Target Runtimes: The code must run seamlessly on BOTH the stock Classic interpreter (`REXX.DLL`) AND the backward-compatible Object REXX interpreter (`OBJREXX`) running in Classic mode.

## Architecture & Flow Control (Recursion vs. Iteration)
- VERIFIED Engine Limitation: Even when executing pure Classic REXX code, systems running the backward-compatible Object REXX (`OBJREXX`) runtime enforce 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.
- Fast File Read: For reading cURL JSON responses into memory, use `size = Stream(file, 'C', 'QUERY SIZE')`, followed by `data = CharIn(file, 1, size)` and `Call Stream file, 'C', 'CLOSE'`.
- 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 via Fast File Read (or line-by-line), close stream, 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:
  rem_len = total_len - start_pos + 1
  take_len = Min(rem_len, chunk_size)
  chunk = SubStr(data, start_pos, take_len)

## VERIFIED OS/2 Classic REXX String Literal Limit (Error 30 Prevention)
- Engine Limitation: In OS/2 Classic REXX, literal strings in source code and single expressions spanning multiple lines via continuation commas (`,`) must NOT exceed 250 bytes in total source length. Exceeding this limit triggers `REX0030: Error 30: Name or string too long` at compile/tokenization time.
- Mitigation Rule: Never use line-continuation commas (`,`) to build long CSV rows, headers, or JSON strings. Always break string literals into chunks well under 100 characters and concatenate them across separate assignment statements (`str = str || ...`).

## FORBIDDEN FUNCTIONS
- NEVER use CHANGESTR() or COUNTSTR() (ooRexx/ANSI only). Always use an iterative PARSE VAR / POS() loop for string replacements.
</SKILL_OS2_CLASSIC_REXX_CORE>

<SKILL_UPDATE>
## VERIFIED Classic REXX DataType('W') 9-Digit Precision Trap
- Bug Description: By default, Classic REXX uses `NUMERIC DIGITS 9`. Calling `DataType(var, 'W')` (Whole Number check) on any integer with more than 9 digits (such as 12-digit eBay Item IDs or 13-digit EAN/GTIN barcodes) returns `0` (False) unless `NUMERIC DIGITS` has been increased beforehand.
- Mitigation Rule: To validate whether a string consists purely of digits without being constrained by `NUMERIC DIGITS`, always use `If var \= '' & Verify(var, '0123456789') = 0 Then` instead of `DataType(var, 'W')`.
</SKILL_UPDATE>
