6 Commits

Author SHA256 Message Date
Alphaeus Mote b35c956865 fix(agent): report a script's real exit code and first error
Behaviour change: the in-process PowerShell engine now reports what the
script asked for, the way pwsh -File does.

- `exit 5` reports exit 5 and Failed. It used to report Succeeded, 0: an
  AddScript exit reaches only the host's SetShouldExit, which nothing read,
  so a small host now captures it. `exit 0` succeeds, even after errors.
- A native command's non-zero $LASTEXITCODE no longer fails a script unless
  the script exits with it, and neither do errors it silenced (HadErrors is
  set by both, so the error stream decides now).
- Write-Error still fails a script that never calls exit, with exit 1.

JobStatePayload gains optional ErrorType, ErrorId and ErrorMessage: the first
error's exception type, FullyQualifiedErrorId and message; for external
engines the first stderr line. Older agents omit them. It also gains RunId,
for the backend to set when relaying to browsers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 20:18:50 -04:00
Alphaeus Mote 3c6897d0be feat(agent): pipeline objects arrive as PowerShell displays them
Output objects were sent as PSObject.ToString(), so anything that was not
already a string came back as a type name or a terse dump:
"System.Collections.Hashtable", "System.Diagnostics.Process (svchost)",
"@{Name=widget; Size=42}".

Both PowerShell engines now pipe the script's output through
`Out-String -Stream -Width 4096`, PowerShell's own formatter: objects
arrive as their table or list view (a hashtable's Name/Value rows,
properties as columns), still streamed line by line as they are produced,
wide enough that tables are not cut short with "…" at 80/120 columns.
Strings pass through unchanged; trailing padding is trimmed; the exit
code is unaffected. Bash output was already text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 22:26:49 -04:00
gsadmin a5ad4c3f35 Hashtable entries typed per entry; expansion runs in the background
Hashtable parameters no longer fix one key/value type for the whole
table: every entry picks its own primitives as it is added, carried as
native JSON and rebuilt by the agent from each element's own kind. That
change surfaced a latent binder bug — the int-downcast ternary widened
numbers back to long before boxing, so hashtable keys never matched
integer lookups — now fixed with explicit branches.

On-device expansion becomes the background default (ExpandEnvironment-
Variables then ExpandString, one pass), replacing the confusing per-mode
"On device" selector with a single Literal opt-out checkbox for values
where the raw text is the point. Stored definitions with removed enum
values degrade to no parameters instead of failing every script read.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-07 13:39:17 -04:00
gsadmin b3bee84b9e Pluggable secrets providers with server-side resolution into $Secrets
Scripts can bind entries of a secrets dictionary to values held in an
external vault. The backend resolves every binding at dispatch time —
manual runs and triggered runs alike — and ships only the values, so
agents and browsers never hold vault credentials. The agent injects them
as a case-insensitive OrderedDictionary session variable (name
configurable per script, default Secrets), giving $Secrets.ApiKey in the
script body with declaration order preserved.

Infisical is the first driver (universal-auth machine identity, v3 raw
API); the ISecretsProviderDriver interface keeps the rest pluggable and
self-describing so the settings form renders from driver metadata.
Provider connection settings are a Data Protection-encrypted blob, secret
config fields never return to the browser, and the script editor's picker
lists secret names only. Resolution failures fail the job with a
value-free message naming the binding and provider.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-07 11:12:59 -04:00
gsadmin b55608bb52 Expand parameter values with the target device's environment
Each parameter can opt into on-device expansion of its string values:
Environment (%VAR% via ExpandEnvironmentVariables) or PowerShell
($env:VAR and $() via $ExecutionContext.InvokeCommand.ExpandString in
the job's runspace, before the prelude runs). Applies to string scalars,
string array elements and hashtable values — keys stay literal. The
builder gains an "On device" selector and run inputs show a tag so the
operator knows the value resolves remotely.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-07 10:59:08 -04:00
gsadmin a9e5c6ea44 Queue B: Trim the agent single-file payload
- SatelliteResourceLanguages=en drops PowerShell localization satellites
- Pre-bundle target removes interactive/gallery modules (PSReadLine,
  PackageManagement, PowerShellGet) and non-Windows native runtimes
  (unix/linux/osx/browser/alpine) from the self-contained publish
- Core automation modules (Management, Utility, Security, Host, Diagnostics,
  CimCmdlets, Archive) are retained so admin scripts keep their normal cmdlet
  surface; modules ship inside Agent.exe (no loose Modules folder)
- Remaining ~53 MB is the self-contained .NET + PowerShell engine, which is
  not IL-trim-safe (reflection-heavy)
- Added headless PowerShell execution tests: output/error/warning/verbose
  streams, progress normalization, cancellation, and typed hashtable parameter
  binding (34 agent tests)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-06 19:51:45 -04:00