Replies: 1 comment
|
@mlhher I'll wait till you are done with your AST work before looking more in depth with this. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
AST Parser Adoption Plan (Unix + Windows)
Goal
Adopt AST-backed command analysis to improve safety classification and reduce brittle string parsing across platforms.
Scope
mvdan/shSystem.Management.Automation(Parser::ParseInput)Non-Goals (for initial rollout)
Architecture Overview
1) Parser Interface
Introduce a platform-neutral parser interface:
Parse(command string, platform Platform) (ParsedIR, error)2) Shared Parsed IR
Define a compact JSON-safe IR shape with:
platform(unix|windows)commands[](base commands/cmdlets found)operators[](|,&&,;, etc.)redirects[](>,>>,<, etc.)expansions[](var,glob,subshell, etc.)risk_flags[](normalized policy signals)parse_errors[](syntax/parse diagnostics)3) Platform Adapters
mvdan/shpwsh+System.Management.Automation.Language.Parser::ParseInput4) Policy Engine
Policy consumes only
ParsedIR:Implementation Phases
Phase 0: Baseline & Safety Net
Exit Criteria
Phase 1: Shared IR + Parser Abstraction
ParsedIRtypes and parser interface.Exit Criteria
Phase 2: Unix AST Adapter (
mvdan/sh)mvdan/shparser.ParsedIRrisk signals.Exit Criteria
Phase 3: Windows AST Adapter (
System.Management.Automation)Parser::ParseInputpwsh -NoProfile -NonInteractive).Exit Criteria
Phase 4: Dual-Path (Shadow Mode)
Exit Criteria
Phase 5: Gradual Enforcement
Exit Criteria
Phase 6: Decommission Legacy Parsing
Exit Criteria
Windows Adapter Invocation Strategy
Recommended (initial)
Out-of-process call:
pwshprocess ->System.Management.Automationparser -> JSON IR -> GoWhy
Optimization path (later)
Security & Reliability Requirements
operator,redirect,expansion,invoke_expression).Testing Plan
Unit
Integration
Regression Corpus
CI
go test ./...(existing matrix)Rollout Controls
ast_policy_enabledast_shadow_modeast_windows_enabledRisks & Mitigations
Deliverables Checklist
ParsedIRschema + versioningmvdan/sh)System.Management.Automation)Success Criteria
All reactions