diff --git a/.claude/skills/subsystem-edit/scripts/subsystem-edit.ps1 b/.claude/skills/subsystem-edit/scripts/subsystem-edit.ps1 index bfcaa1fc..344cc551 100644 --- a/.claude/skills/subsystem-edit/scripts/subsystem-edit.ps1 +++ b/.claude/skills/subsystem-edit/scripts/subsystem-edit.ps1 @@ -1,4 +1,4 @@ -# subsystem-edit v1.1 — Edit existing 1C subsystem XML +# subsystem-edit v1.2 — Edit existing 1C subsystem XML # Source: https://github.com/Nikolay-Shirokov/cc-1c-skills param( [Parameter(Mandatory)][string]$SubsystemPath, @@ -119,12 +119,17 @@ if (-not (Test-Path $SubsystemPath)) { } if (-not (Test-Path $SubsystemPath)) { Write-Error "File not found: $SubsystemPath"; exit 1 } $resolvedPath = (Resolve-Path $SubsystemPath).Path +$script:resolvedPath = $resolvedPath # --- Load XML with PreserveWhitespace --- $script:xmlDoc = New-Object System.Xml.XmlDocument $script:xmlDoc.PreserveWhitespace = $true $script:xmlDoc.Load($resolvedPath) +$script:formatVersion = $script:xmlDoc.DocumentElement.GetAttribute("version") +if (-not $script:formatVersion) { $script:formatVersion = "2.17" } +$script:utf8Bom = New-Object System.Text.UTF8Encoding($true) + $script:addCount = 0 $script:removeCount = 0 $script:modifyCount = 0 @@ -164,6 +169,37 @@ foreach ($child in $script:propsEl.ChildNodes) { Info "Subsystem: $($script:objName)" # --- XML manipulation helpers (from meta-edit pattern) --- +function Esc-Xml([string]$s) { + return $s.Replace('&','&').Replace('<','<').Replace('>','>').Replace('"','"') +} + +function New-Guid-String { + return [System.Guid]::NewGuid().ToString() +} + +function Write-ChildSubsystemStub([string]$childPath, [string]$childName, [string]$formatVersion, [System.Text.Encoding]$utf8Bom) { + $childUuid = New-Guid-String + $sb = New-Object System.Text.StringBuilder 2048 + [void]$sb.AppendLine('') + [void]$sb.AppendLine("") + [void]$sb.AppendLine("`t") + [void]$sb.AppendLine("`t`t") + [void]$sb.AppendLine("`t`t`t$(Esc-Xml $childName)") + [void]$sb.AppendLine("`t`t`t") + [void]$sb.AppendLine("`t`t`t") + [void]$sb.AppendLine("`t`t`ttrue") + [void]$sb.AppendLine("`t`t`ttrue") + [void]$sb.AppendLine("`t`t`tfalse") + [void]$sb.AppendLine("`t`t`t") + [void]$sb.AppendLine("`t`t`t") + [void]$sb.AppendLine("`t`t`t") + [void]$sb.AppendLine("`t`t") + [void]$sb.AppendLine("`t`t") + [void]$sb.AppendLine("`t") + [void]$sb.AppendLine('') + [System.IO.File]::WriteAllText($childPath, $sb.ToString(), $utf8Bom) +} + function Import-Fragment([string]$xmlString) { $wrapper = "<_W xmlns=`"$($script:mdNs)`" xmlns:xsi=`"$($script:xsiNs)`" xmlns:v8=`"$($script:v8Ns)`" xmlns:xr=`"$($script:xrNs)`" xmlns:xs=`"http://www.w3.org/2001/XMLSchema`">$xmlString" $frag = New-Object System.Xml.XmlDocument @@ -337,6 +373,20 @@ function Do-AddChild([string]$childName) { Insert-BeforeElement $script:childObjsEl $newEl $null $childIndent $script:addCount++ Info "Added child subsystem: $childName" + + # Write stub XML for the new child if it doesn't exist yet + $parentDir = [System.IO.Path]::GetDirectoryName($script:resolvedPath) + $parentBaseName = [System.IO.Path]::GetFileNameWithoutExtension($script:resolvedPath) + $childSubsDir = Join-Path (Join-Path $parentDir $parentBaseName) "Subsystems" + if (-not (Test-Path $childSubsDir)) { + New-Item -ItemType Directory -Path $childSubsDir -Force | Out-Null + Info "Created directory: $childSubsDir" + } + $childXml = Join-Path $childSubsDir "$childName.xml" + if (-not (Test-Path $childXml)) { + Write-ChildSubsystemStub $childXml $childName $script:formatVersion $script:utf8Bom + Info "Created stub: $childXml" + } } function Do-RemoveChild([string]$childName) { diff --git a/.claude/skills/subsystem-edit/scripts/subsystem-edit.py b/.claude/skills/subsystem-edit/scripts/subsystem-edit.py index ed2ddbfc..b778a4cd 100644 --- a/.claude/skills/subsystem-edit/scripts/subsystem-edit.py +++ b/.claude/skills/subsystem-edit/scripts/subsystem-edit.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# subsystem-edit v1.1 — Edit existing 1C subsystem XML +# subsystem-edit v1.2 — Edit existing 1C subsystem XML # Source: https://github.com/Nikolay-Shirokov/cc-1c-skills import argparse @@ -7,8 +7,64 @@ import json import os import subprocess import sys +import uuid from lxml import etree + +def new_uuid(): + return str(uuid.uuid4()) + + +def esc_xml(s): + return s.replace('&', '&').replace('<', '<').replace('>', '>').replace('"', '"') + + +def write_utf8_bom(path, content): + with open(path, 'w', encoding='utf-8-sig', newline='') as f: + f.write(content) + + +def write_child_subsystem_stub(child_path, child_name, format_version): + child_uuid = new_uuid() + lines = [] + lines.append('') + lines.append( + '' + ) + lines.append(f'\t') + lines.append('\t\t') + lines.append(f'\t\t\t{esc_xml(child_name)}') + lines.append('\t\t\t') + lines.append('\t\t\t') + lines.append('\t\t\ttrue') + lines.append('\t\t\ttrue') + lines.append('\t\t\tfalse') + lines.append('\t\t\t') + lines.append('\t\t\t') + lines.append('\t\t\t') + lines.append('\t\t') + lines.append('\t\t') + lines.append('\t') + lines.append('') + write_utf8_bom(child_path, '\n'.join(lines) + '\n') + MD_NS = "http://v8.1c.ru/8.3/MDClasses" XR_NS = "http://v8.1c.ru/8.3/xcf/readable" XSI_NS = "http://www.w3.org/2001/XMLSchema-instance" @@ -264,6 +320,7 @@ def main(): xml_parser = etree.XMLParser(remove_blank_text=False) tree = etree.parse(resolved_path, xml_parser) xml_root = tree.getroot() + format_version = xml_root.get("version") or "2.17" add_count = 0 remove_count = 0 @@ -381,6 +438,18 @@ def main(): add_count += 1 info(f"Added child subsystem: {child_name}") + # Write stub XML for the new child if it doesn't exist yet + parent_dir = os.path.dirname(resolved_path) + parent_base_name = os.path.splitext(os.path.basename(resolved_path))[0] + child_subs_dir = os.path.join(parent_dir, parent_base_name, 'Subsystems') + if not os.path.exists(child_subs_dir): + os.makedirs(child_subs_dir, exist_ok=True) + info(f"Created directory: {child_subs_dir}") + child_xml = os.path.join(child_subs_dir, f'{child_name}.xml') + if not os.path.exists(child_xml): + write_child_subsystem_stub(child_xml, child_name, format_version) + info(f"Created stub: {child_xml}") + def do_remove_child(child_name): nonlocal remove_count if child_objs_el is None: diff --git a/tests/skills/cases/subsystem-edit/snapshots/add-child/Subsystems/Продажи/Subsystems/Настройки.xml b/tests/skills/cases/subsystem-edit/snapshots/add-child/Subsystems/Продажи/Subsystems/Настройки.xml new file mode 100644 index 00000000..7f218906 --- /dev/null +++ b/tests/skills/cases/subsystem-edit/snapshots/add-child/Subsystems/Продажи/Subsystems/Настройки.xml @@ -0,0 +1,17 @@ + + + + + Настройки + + + true + true + false + + + + + + +