SC4SAP Program → Specification
Reads an existing ABAP program (Report / Module Pool / FM Group / Class / CDS / RAP) via MCP, runs structural + semantic + where-used analysis, then produces a Specification artifact in any combination of Markdown (.md), HTML (.html, one self-contained file) and Excel (.xlsx). Scope is negotiated Socratically — start wide, narrow on each turn, stop when the user's target granularity is confirmed.
Every response triggered by this skill MUST begin with [Model: <main-model> · Dispatched: <sub-summary>] per ../../common/model-routing-rule.md § Response Prefix Convention.
Multi-phase skill. Before each Agent(...) dispatch, emit ▶ phase=<id> (<label>) · agent=<name> · model=<Opus 4.7|Sonnet 4.6|Haiku 4.5> per ../../common/model-routing-rule.md § Phase Banner Convention.
No teamMode integration. program-to-spec targets a single object (one program / class / FM group / CDS / RAP BO) and performs read-only structural extraction — no cross-module synthesis, no authoring conflict, no incident triage. See ../../docs/team-consultation-architecture.md § 6 gating logic. Future extension: if a target's GetWhereUsed graph spans ≥ 2 modules AND user picks L4 depth, Type A (module consultants annotating cross-module concerns in Step 3) could be added — not in current scope.
Invoke /sc4sap:trust-session with parent_skill=sc4sap:program-to-spec to pre-grant MCP tool + file-op permissions (eliminates per-tool prompts during structural reads + screen rendering pipeline).
- If
.sc4sap/session-trust.logalready has a line within the last 24h, skip silently. - Otherwise run it and surface the one-line confirmation.
Full spec: see ../trust-session/SKILL.md.
Default opener — bundled 4-question AskUserQuestion (MANDATORY when the target object is already supplied in ARGUMENTS):
Issue ONE AskUserQuestion call with these four questions in this exact order — Audience / Format / Depth / Language — each with "(Recommended)" as the first option. Format is multi-select (multiSelect: true); the other three are single-select. This replaces Rounds 2+3+5 in one UI turn. Only fall back to per-round questioning when the object itself is missing or ambiguous (Round 1) or when the user picks L3/L4 (Round 4 scope trimming).
| # | Header | Question | Options (Recommended first) |
|---|---|---|---|
| 1 | Audience | Who is the primary audience for the spec? | Both (Recommended) · Functional · Technical |
| 2 | Format | Which output formats? (select one or more) | Markdown (Recommended) · HTML · Excel |
| 3 | Depth | What depth of detail? | L2 Standard (Recommended) · L1 Quick Spec · L3 Deep Technical · L4 Audit-grade |
| 4 | Language | Output language? | Korean · English · Japanese (order follows user's current language — promote the matching one to first with "(Recommended)") |
Round 1 — Target object (only if ARGUMENTS did not supply it)
- "Which object? (program / FM group / class / CDS / RAP BO name)"
- Verify via
SearchObject. If ambiguous, list candidates.
Round 2 — Audience + format (covered by the default opener — do not ask separately)
- Audience: Functional (business readers — SD/FI/MM users) vs Technical (developers) vs Both
- Format (any combination): Markdown (review-friendly, git-friendly) · HTML (one self-contained file with images inlined — share, mail, print) · Excel (project-PMO-friendly, reviewable cell-by-cell)
- Default if user says "up to you" / "you choose" → Audience Both + Format Markdown.
Round 3 — Depth (pick one) (covered by the default opener)
| Depth | Contains |
|---|---|
| L1 — Quick Spec | Purpose, inputs, outputs, main logic steps (numbered; for Module Pool includes PBO/PAI module flow) |
| L2 — Standard Spec (default) | L1 + inputs & screens, data model, authorizations, outputs, exceptions, every subroutine / method signature |
| L3 — Deep Technical | L2 + SQL inventory, BAdI / exit list, performance notes |
| L4 — Audit-grade | L3 + line-level cross-references, where-used (scope: main object + screens × Z* / Y* callers), risk register, transport history |
Round 4 — Scope trimming (only if L3/L4) Ask ONE narrowing question per turn until ambiguity ≤3:
- "Include unit tests inventory?"
- "Include generated artifacts (Screens / GUI Status / Text Elements)?"
- "Cover all includes or just main?"
Where-Used scope (L4 only — fixed default, no interactive prompt)
- Target = main program / class / FM-group / CDS / RAP-BO object + each of its screens (T1+Screen).
- Caller filter = customer namespace
Z*/Y*only (S2). Standard SAP and add-on namespaces are excluded. - The rendered
Where-Usedsection MUST repeat this scope in its header so reviewers know what was (and wasn't) searched.
Round 5 — Output location
- Default:
.sc4sap/specs/{object_name}-{YYYYMMDD}-{lang}.{md|html|xlsx}— one file per selected format - Language: ko / en / ja (infer from user's current language; confirm once).
Stop condition: every dimension above has a concrete answer OR user explicitly says "skip remaining, use defaults".
MUST read workflow-steps.md (in this skill folder) and execute the steps defined there in order whenever this skill runs.
MUST read spec-templates.md (in this skill folder) when rendering the artifact in Step 4.
- Main orchestrator (Sonnet 4.6) — Steps 0, 1, 1.5, 2, 5: Socratic interview orchestration, object classification routing, CBO context preload, Step 5 review loop. State tracking across depth / format / language dimensions needs Sonnet headroom.
- Analysis (
sap-analyst× 1, Opus 4.7, frontmatter) — Step 3 primary dispatch: extracts business purpose, inputs, outputs, data sources (including CBO-annotated Z-references whencbo-context.mdexists), main-logic narrative, authorization checks, error cases. One dispatch covers all narrative dimensions to keep context continuous. - Rendering (
sap-writer× 1) — Step 3 second dispatch (or Step 4 render invocation):- L1 / L2 depth → Haiku 4.5 base (frontmatter). Pure templating from structured analyst output.
- L3 / L4 depth → Sonnet 4.6 override (
model: "sonnet") — longer narrative + deeper cross-reference + stronger consistency requirement. - Markdown / HTML output — writer renders the
.md; HTML is produced from that same.mdbyscripts/spec/md-to-html.mjs(no second writer pass). - Excel output — writer's deliverable is TWO JSON files consumed by
scripts/spec/build-spec.mjs:- TR (translation) map —
English source string → target-language replacementmapping; schema + slot semantics inspec-templates.md§ Excel — Template-clone. - image-spec.json —
{selection, alv, processFlow, lang}per-program image data; exact key names + sample values inspec-templates.md§ Image Replacement. Drives the Sheet 3 Selection/ALV mockups + Sheet 4 horizontal Process Flow PNG. Writer does NOT generate workbook styles, drivers, geometry, or PNGs directly —asset/template_base.xlsxsupplies geometry,build-spec.mjsdoes clone + render + swap in one shot. Depth-driven model override still applies (Sonnet for L3/L4 because the warning-row and processing-step narrative is longer). Two hard requirements on both JSON files (full rules inspec-templates.md): (1) business-first content — Sheet 4 Step text +processFlow[]describe the business process for a functional reader, with the ABAP event/FORM kept as a secondary annotation (never an event-only list); (2) single-language output — every prose string is in the targetlang; only SAP identifiers / ABAP literals stay as-is.build-spec.mjsprints a⚠ LANGUAGE MIXgate for ko/ja — finalize only when it reportslanguage check OK.
- TR (translation) map —
- Audit verification (
sap-critic× 1, Opus 4.7, frontmatter, conditional L4 only) — Step 3 gate: verifies every claim in the rendered spec cross-references a concrete line range in source. Skip for L1 / L2 / L3.
Top-level summary: Report that lists open sales orders by Sales Organization and date range and displays them via ALV. Main tables: VBAK, VBAP, VBUK, KNA1 (+ CDS I_SalesOrder). Authorizations: S_TCODE=ZSDR01, S_TABU_DIS=VBAK.
Next options: • "Regenerate as Excel" / "Also give me HTML" • "Extend to L4 with Where-used" • "Add an English version"
</Output_Format>
<MCP_Tools_Used>
- `SearchObject`, `GetObjectInfo`
- `GetProgFullCode`, `GetIncludesList`, `GetInclude`
- `ReadClass`, `ReadFunctionModule`, `ReadInterface`, `ReadView`
- `Read BehaviorDefinition`, `Read BehaviorImplementation`, `Read ServiceDefinition`, `Read ServiceBinding`
- `GetLocalDefinitions`, `GetLocalMacros`, `GetLocalTestClass`, `GetLocalTypes`
- `GetScreensList`, `GetGuiStatusList`, `GetTextElement`
- `GetMetadataExtension`
- `GetAbapAST`, `GetAbapSemanticAnalysis`
- `GetWhereUsed`, `GetEnhancements`, `GetEnhancementSpot`
</MCP_Tools_Used>
<Related_Skills>
- `/sc4sap:analyze-code` — code quality review (what's wrong)
- `/sc4sap:create-program` — spec → new program (forward direction)
- `/sc4sap:deep-interview` — requirement clarification for new builds
</Related_Skills>
<Data_Extraction_Safety>
Spec generation only reads **source code + DDIC metadata + where-used** — never `GetTableContents` / `GetSqlQuery`. No row data is extracted. The blocklist hook is respected if the user asks for sample data (refuse and document the request in the `Risk` sheet instead).
</Data_Extraction_Safety>
<Inputs_And_Screens_Rendering>
**xlsx output — always-on pipeline (clone + program-specific imagery):** every xlsx spec runs `scripts/spec/build-spec.mjs <tr.json> <image-spec.json> <out.xlsx>`. The helper clones `asset/template_base.xlsx` (geometry / styles / fonts / column widths / row heights / image anchors — all preserved), renders three program-specific PNGs from `image-spec.json`, then swaps them into the cloned xlsx with dynamic `<xdr:ext>` extents (no stretching). Three image slots are populated on every spec:
- **Sheet 3 Selection** (`xl/media/image2.png` at C4) — driven by `image-spec.json.selection`
- **Sheet 3 ALV** (`xl/media/image1.png` at C19) — driven by `image-spec.json.alv`
- **Sheet 4 Process Flow** (`xl/media/image3.png` at B19, horizontal layout) — driven by `image-spec.json.processFlow` (each program has a different flow, so `drawing4.xml` is injected on demand from a blank template container)
**Graceful degrade**: if no headless browser is on PATH, `renderScreenImages` returns `null` per slot and `build-spec.mjs` keeps the template mockups for that slot — never crashes.
**No trigger keywords required.** Image rendering is part of the default Excel pipeline because each program has unique selection screens, ALV layouts, and flow charts. Drift risk applies only to geometry regression (the old throwaway-driver problem) and image swap only touches drawing extents + PNG bytes, not geometry.
**Markdown output — unchanged:** continue emitting ASCII wireframes inside fenced code blocks (Step 3.5 in `workflow-steps.md`). ASCII wireframes never go in xlsx cells.
**HTML output:** converted from the finished `.md` by `node scripts/spec/md-to-html.mjs <spec.md> <spec.html>` — PNGs inlined as data URIs, Mermaid fallbacks drawn by the Mermaid CDN script when opened online (plain source text offline). Same content as the `.md`, by construction.
</Inputs_And_Screens_Rendering>
Task: {{ARGUMENTS}}