Skip to content

[codex] shell: publish syntax, expand, and analysis packages - #756

Merged
ewhauser merged 1 commit into
mainfrom
ewhauser/publish-shell-semantics-analysis
Mar 28, 2026
Merged

ewhauser merged 1 commit into
mainfrom
ewhauser/publish-shell-semantics-analysis

Conversation

@ewhauser

Copy link
Copy Markdown
Owner

Summary

  • publish shell parser and expansion packages as shell/syntax, shell/syntax/typedjson, and shell/expand
  • add a new public shell/analysis observer API and wire the internal interpreter to emit read-only semantic events
  • keep interpreter internals internal, update imports/tooling/spec docs, and add public-package plus observer coverage

What changed

  • moved internal/shell/syntax to shell/syntax and internal/shell/syntax/typedjson to shell/syntax/typedjson
  • moved internal/shell/expand to shell/expand
  • moved shell pattern helpers behind shell/internal/pattern and added an internal-only internal/shellpattern copy for non-shell/* internal consumers
  • added shell/analysis with Observer, ObserverFunc, Context, immutable context snapshots, and concrete events for run/file, statement, command, scope, variable, and option changes
  • threaded AnalysisObserver through gbash.Config, gbash.WithAnalysisObserver, runtime config, shell execution, and interp.RunnerConfig
  • wired hooks at real execution points for file/run boundaries, statement and command lifecycle, function/source/eval/subshell/pipeline scopes, variable reads/writes/unsets, and selected shell option changes
  • updated SPEC.md to document the new public package paths and the intentionally read-only analysis surface

Validation

  • make test
  • make lint

@ewhauser
ewhauser marked this pull request as ready for review March 28, 2026 04:42

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 75c38660fa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +310 to +314
r.analysisEmit(analysis.VariableWrite{
Name: name,
Ref: ref,
Variable: vr,
Previous: prev,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Deep-copy variable values before emitting analysis events

analysisVariableWrite forwards vr/prev directly into analysis.VariableWrite, and those expand.Variable values can still alias live map/slice storage from the shell environment. If an observer mutates event.Variable.Map or event.Previous.List, it can change runtime shell state, which breaks the documented read-only/immutable analysis contract and can alter subsequent command behavior. Emit cloned expand.Variable payloads (deep-copy maps/slices) before calling the observer.

Useful? React with 👍 / 👎.

var transformErr error
synthetic, transformErr = transform(file)
if transformErr != nil {
r.analysisFileFinish(r.AnalysisStatus())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Emit failing FileFinish status when chunk transform errors

When transform(file) fails (for example via compileChunk returning a compilation/policy error), analysisFileFinish is emitted with r.AnalysisStatus() before any non-zero status is derived from that error. In this path the status is typically still zero, so observers see a successful FileFinish even though the run exits with a compilation failure. Derive the file status from transformErr (or set r.exit accordingly) before emitting FileFinish.

Useful? React with 👍 / 👎.

@ewhauser
ewhauser merged commit 86bbea8 into main Mar 28, 2026
15 checks passed
@ewhauser
ewhauser deleted the ewhauser/publish-shell-semantics-analysis branch March 28, 2026 04:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant