opencode-swarm 7.44.1 → 7.46.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1,2 @@
1
- export { WindowsSandboxExecutor } from '../win32/restricted-token-executor';
1
+ export { NativeWindowsSandboxExecutor as WindowsSandboxExecutor } from '../win32/native-sandbox-executor';
2
+ export { WindowsSandboxExecutor as LegacyWindowsSandboxExecutor } from '../win32/restricted-environment-executor';
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Windows native sandbox executor.
3
+ *
4
+ * Prefers the native swarm-sandbox-runner binary for true OS-level isolation
5
+ * (AppContainer or restricted token). Falls back to the PowerShell-based
6
+ * environment executor when the runner binary is unavailable.
7
+ *
8
+ * The public API matches SandboxExecutor, but wrapCommand is not the primary
9
+ * execution path when the native runner is available — execute() provides
10
+ * the full sandbox lifecycle with NDJSON events.
11
+ */
12
+ import type { SandboxExecutor } from '../executor';
13
+ import { type RunnerExecuteResult, type RunnerProbeResult } from './runner-client';
14
+ export type SandboxStrength = 'strong' | 'weak' | 'none';
15
+ /**
16
+ * Native Windows sandbox executor with runner-first, PowerShell-fallback strategy.
17
+ */
18
+ export declare class NativeWindowsSandboxExecutor implements SandboxExecutor {
19
+ readonly mechanism: string;
20
+ private readonly _probeResult;
21
+ private readonly _fallbackExecutor;
22
+ private readonly _strength;
23
+ private _disabled;
24
+ private _disabledReason;
25
+ constructor(scopePaths?: string[], tempDir?: string);
26
+ /** Sandbox strength: 'strong' (native runner), 'weak' (PowerShell), 'none'. */
27
+ get strength(): SandboxStrength;
28
+ isAvailable(): boolean;
29
+ disable(reason: string): void;
30
+ /**
31
+ * Wrap a command for execution.
32
+ *
33
+ * When the native runner is available, generates a command that pipes
34
+ * the policy JSON to the runner binary via a temp file. This keeps the
35
+ * existing guardrails flow (modify args.command → shell executes) while
36
+ * providing real OS-level sandboxing.
37
+ *
38
+ * When the runner is unavailable, falls back to the PowerShell wrapper.
39
+ */
40
+ wrapCommand(command: string, scopePaths: string[], tempDir?: string): string;
41
+ private _wrapWithRunner;
42
+ getEnvOverrides(): Record<string, string | null>;
43
+ /**
44
+ * Execute a command in the native sandbox.
45
+ *
46
+ * Only available when strength is 'strong'. Falls back to wrapCommand
47
+ * for weak sandbox mode.
48
+ */
49
+ executeNative(command: string[], workspaceRoot: string, runId?: string): Promise<RunnerExecuteResult>;
50
+ /** Whether the native runner is available for direct execution. */
51
+ get hasNativeRunner(): boolean;
52
+ /** The reason the sandbox was disabled, or null if not disabled. */
53
+ get disabledReason(): string | null;
54
+ /** Probe result from the native runner. */
55
+ get probeResult(): RunnerProbeResult;
56
+ }
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Windows Restricted Environment sandbox executor (legacy fallback).
3
+ *
4
+ * Wraps shell commands with a PowerShell-based sandbox approach to restrict
5
+ * process capabilities on Windows. This is the "weak" sandbox used when the
6
+ * native swarm-sandbox-runner binary is not available.
7
+ *
8
+ * Windows does not have a native sandbox mechanism equivalent to Linux bwrap
9
+ * or macOS sandbox-exec that is accessible from Node.js without native bindings.
10
+ * This executor provides best-effort sandboxing via:
11
+ * - Environment variable scrubbing (removing dangerous vars)
12
+ * - PATH restriction to safe system paths only
13
+ * - Scoped temp directory
14
+ * - PowerShell wrapper for command execution
15
+ *
16
+ * For true OS-level sandboxing (AppContainer, Restricted Token, Low Integrity),
17
+ * native Windows APIs (CreateAppContainerToken, CreateRestrictedToken) are required.
18
+ */
19
+ import type { SandboxExecutor } from '../executor';
20
+ /**
21
+ * Check whether the Windows sandbox mechanism is present and functional.
22
+ * Uses spawnSync to probe synchronously without throwing.
23
+ *
24
+ * On Windows, this verifies that basic command execution works.
25
+ * A failure here indicates the sandbox cannot be initialized and should
26
+ * degrade gracefully to passthrough mode.
27
+ */
28
+ declare function probeWindowsSandbox(): boolean;
29
+ /**
30
+ * DI seam for testability. Exposes the probe function so tests can simulate
31
+ * unavailable sandbox conditions without requiring a real Windows environment.
32
+ */
33
+ export declare const _internals: {
34
+ probeWindowsSandbox: typeof probeWindowsSandbox;
35
+ };
36
+ /**
37
+ * Windows Restricted Token sandbox executor.
38
+ *
39
+ * Provides best-effort process sandboxing via PowerShell environment restrictions.
40
+ * True OS-level sandboxing requires native Windows API bindings.
41
+ */
42
+ export declare class WindowsSandboxExecutor implements SandboxExecutor {
43
+ /** Human-readable mechanism identifier */
44
+ readonly mechanism = "powershell-wrapper";
45
+ private readonly _scopePaths;
46
+ private readonly _tempDir;
47
+ private _available;
48
+ private _disabled;
49
+ private _disabledReason;
50
+ /**
51
+ * @param scopePaths - Absolute paths the sandboxed process may write to
52
+ * @param tempDir - Optional temp directory path (defaults to system temp)
53
+ */
54
+ constructor(scopePaths?: string[], tempDir?: string);
55
+ /**
56
+ * Returns true when the Windows sandbox is available and has not been disabled.
57
+ */
58
+ isAvailable(): boolean;
59
+ /**
60
+ * Disable the sandbox with a reason. Allows external code to force
61
+ * fallback to unwrapped execution (e.g., for testing, explicit opt-out,
62
+ * or when initialization fails).
63
+ *
64
+ * After calling disable():
65
+ * - isAvailable() returns false
66
+ * - wrapCommand() returns the raw command unchanged (passthrough)
67
+ */
68
+ disable(reason: string): void;
69
+ /**
70
+ * Wrap a shell command string with PowerShell-based sandbox restrictions.
71
+ *
72
+ * The wrapper:
73
+ * - Sets scoped temp directory (%TEMP%, %TMP%)
74
+ * - Restricts PATH to safe system paths only
75
+ * - Removes dangerous environment variables that could be used to bypass restrictions
76
+ * - Executes the command via cmd /c inside a PowerShell script
77
+ *
78
+ * @param command - Raw shell command to execute inside the sandbox
79
+ * @param scopePaths - Additional scope paths to allow (merged with constructor scope)
80
+ * @param tempDir - Optional temp directory override
81
+ * @returns A PowerShell-wrapped command string ready for shell execution,
82
+ * or the raw command string when the sandbox is unavailable (passthrough mode)
83
+ */
84
+ wrapCommand(command: string, scopePaths: string[], tempDir?: string): string;
85
+ /**
86
+ * Return environment variable overrides required for the Windows sandbox.
87
+ *
88
+ * Security measures:
89
+ * - PATH is restricted to essential Windows system directories only
90
+ * - TEMP/TMP are set to null (will be set to scoped temp at runtime via wrapCommand)
91
+ * - Dangerous variables that don't apply to Windows are cleared for completeness
92
+ */
93
+ getEnvOverrides(): Record<string, string | null>;
94
+ }
95
+ export {};
@@ -1,94 +1,9 @@
1
1
  /**
2
- * Windows Restricted Token sandbox executor.
2
+ * Backwards-compatibility re-export.
3
3
  *
4
- * Wraps shell commands with a PowerShell-based sandbox approach to restrict
5
- * process capabilities on Windows.
6
- *
7
- * Windows does not have a native sandbox mechanism equivalent to Linux bwrap
8
- * or macOS sandbox-exec that is accessible from Node.js without native bindings.
9
- * This executor provides best-effort sandboxing via:
10
- * - Environment variable scrubbing (removing dangerous vars)
11
- * - PATH restriction to safe system paths only
12
- * - Scoped temp directory
13
- * - PowerShell wrapper for command execution
14
- *
15
- * For true OS-level sandboxing (AppContainer, Restricted Token, Low Integrity),
16
- * native Windows APIs (CreateAppContainerToken, CreateRestrictedToken) are required.
17
- */
18
- import type { SandboxExecutor } from '../executor';
19
- /**
20
- * Check whether the Windows sandbox mechanism is present and functional.
21
- * Uses spawnSync to probe synchronously without throwing.
22
- *
23
- * On Windows, this verifies that basic command execution works.
24
- * A failure here indicates the sandbox cannot be initialized and should
25
- * degrade gracefully to passthrough mode.
26
- */
27
- declare function probeWindowsSandbox(): boolean;
28
- /**
29
- * DI seam for testability. Exposes the probe function so tests can simulate
30
- * unavailable sandbox conditions without requiring a real Windows environment.
31
- */
32
- export declare const _internals: {
33
- probeWindowsSandbox: typeof probeWindowsSandbox;
34
- };
35
- /**
36
- * Windows Restricted Token sandbox executor.
37
- *
38
- * Provides best-effort process sandboxing via PowerShell environment restrictions.
39
- * True OS-level sandboxing requires native Windows API bindings.
4
+ * The implementation has moved to restricted-environment-executor.ts to
5
+ * clarify that this is environment scrubbing, not real token restriction.
6
+ * The native sandbox runner (swarm-sandbox-runner.exe) provides true
7
+ * OS-level isolation via runner-client.ts.
40
8
  */
41
- export declare class WindowsSandboxExecutor implements SandboxExecutor {
42
- /** Human-readable mechanism identifier */
43
- readonly mechanism = "powershell-wrapper";
44
- private readonly _scopePaths;
45
- private readonly _tempDir;
46
- private _available;
47
- private _disabled;
48
- private _disabledReason;
49
- /**
50
- * @param scopePaths - Absolute paths the sandboxed process may write to
51
- * @param tempDir - Optional temp directory path (defaults to system temp)
52
- */
53
- constructor(scopePaths?: string[], tempDir?: string);
54
- /**
55
- * Returns true when the Windows sandbox is available and has not been disabled.
56
- */
57
- isAvailable(): boolean;
58
- /**
59
- * Disable the sandbox with a reason. Allows external code to force
60
- * fallback to unwrapped execution (e.g., for testing, explicit opt-out,
61
- * or when initialization fails).
62
- *
63
- * After calling disable():
64
- * - isAvailable() returns false
65
- * - wrapCommand() returns the raw command unchanged (passthrough)
66
- */
67
- disable(reason: string): void;
68
- /**
69
- * Wrap a shell command string with PowerShell-based sandbox restrictions.
70
- *
71
- * The wrapper:
72
- * - Sets scoped temp directory (%TEMP%, %TMP%)
73
- * - Restricts PATH to safe system paths only
74
- * - Removes dangerous environment variables that could be used to bypass restrictions
75
- * - Executes the command via cmd /c inside a PowerShell script
76
- *
77
- * @param command - Raw shell command to execute inside the sandbox
78
- * @param scopePaths - Additional scope paths to allow (merged with constructor scope)
79
- * @param tempDir - Optional temp directory override
80
- * @returns A PowerShell-wrapped command string ready for shell execution,
81
- * or the raw command string when the sandbox is unavailable (passthrough mode)
82
- */
83
- wrapCommand(command: string, scopePaths: string[], tempDir?: string): string;
84
- /**
85
- * Return environment variable overrides required for the Windows sandbox.
86
- *
87
- * Security measures:
88
- * - PATH is restricted to essential Windows system directories only
89
- * - TEMP/TMP are set to null (will be set to scoped temp at runtime via wrapCommand)
90
- * - Dangerous variables that don't apply to Windows are cleared for completeness
91
- */
92
- getEnvOverrides(): Record<string, string | null>;
93
- }
94
- export {};
9
+ export { _internals, WindowsSandboxExecutor, } from './restricted-environment-executor';
@@ -0,0 +1,120 @@
1
+ /**
2
+ * TypeScript client for the swarm-sandbox-runner native Windows sandbox.
3
+ *
4
+ * Spawns the Rust binary as a bounded subprocess to execute commands under
5
+ * real OS-level isolation (AppContainer or restricted token). Communicates
6
+ * via JSON policy on stdin and NDJSON events on stderr.
7
+ *
8
+ * Invariant 1 compliance: probe() is bounded to 2s timeout and fails open.
9
+ * Invariant 3 compliance: all spawns use explicit cwd, stdin, timeout, and
10
+ * kill() in finally blocks.
11
+ */
12
+ import { spawn, spawnSync } from 'node:child_process';
13
+ /** Result of probing the runner binary for capabilities. */
14
+ export interface RunnerProbeResult {
15
+ available: boolean;
16
+ mode: 'app-container' | 'restricted-token' | 'none';
17
+ capabilities: {
18
+ app_container_available: boolean;
19
+ lpac_available: boolean;
20
+ restricted_token_available: boolean;
21
+ private_desktop_creatable: boolean;
22
+ integrity_level: string;
23
+ is_admin: boolean;
24
+ os_version: string;
25
+ arch: string;
26
+ } | null;
27
+ error?: string;
28
+ }
29
+ /** NDJSON event emitted by the runner on stderr. */
30
+ export interface RunnerEvent {
31
+ type: 'start' | 'denial' | 'quota_exceeded' | 'exit';
32
+ run_id?: string;
33
+ mode?: string;
34
+ pid?: number;
35
+ reason?: string;
36
+ path?: string;
37
+ kind?: string;
38
+ used_bytes?: number;
39
+ cap_bytes?: number;
40
+ elapsed_ms?: number;
41
+ cap_ms?: number;
42
+ exit_code?: number;
43
+ signal?: string | null;
44
+ ts?: string;
45
+ }
46
+ /** Result of executing a command in the sandbox. */
47
+ export interface RunnerExecuteResult {
48
+ exitCode: number;
49
+ stdout: string;
50
+ stderr: string;
51
+ events: RunnerEvent[];
52
+ mode: string;
53
+ }
54
+ /** Exit codes from the runner binary (stable, do not renumber). */
55
+ export declare const RUNNER_EXIT_CODES: {
56
+ readonly SUCCESS: 0;
57
+ readonly CHILD_NON_ZERO: 1;
58
+ readonly POLICY_VIOLATION: 64;
59
+ readonly QUOTA_EXCEEDED: 65;
60
+ readonly WALL_CLOCK_TIMEOUT: 66;
61
+ readonly LAUNCHER_MISCONFIG: 67;
62
+ readonly OS_API_FAILURE: 68;
63
+ readonly PROBE_FAILED: 69;
64
+ };
65
+ /** Sandbox policy passed to the runner via stdin. */
66
+ export interface SandboxPolicy {
67
+ schema_version: 1;
68
+ run_id: string;
69
+ workspace_roots: string[];
70
+ writable_roots: string[];
71
+ read_only_subpaths: string[];
72
+ temp_root: string;
73
+ temp_cap_bytes: number;
74
+ memory_cap_bytes: number;
75
+ child_process_cap: number;
76
+ wall_clock_timeout_ms: number;
77
+ network_mode: 'off' | 'on';
78
+ env_allowlist: string[];
79
+ env_overrides: Record<string, string>;
80
+ path_stubs: string[];
81
+ private_desktop: boolean;
82
+ deny_alternate_data_streams: boolean;
83
+ deny_unc_paths: boolean;
84
+ deny_device_paths: boolean;
85
+ deny_symlink_egress: boolean;
86
+ }
87
+ /**
88
+ * DI seam for testability. Exposes internal functions so tests can simulate
89
+ * runner binary behavior without requiring the actual binary.
90
+ */
91
+ export declare const _internals: {
92
+ findRunnerBinary: () => string | null;
93
+ spawnRunner: typeof spawnSync;
94
+ spawnAsync: typeof spawn;
95
+ };
96
+ /**
97
+ * Probe the runner binary for capabilities.
98
+ *
99
+ * Bounded to 2s timeout per Invariant 1 (fast, bounded, fail-open).
100
+ * Results are cached for the session lifetime.
101
+ */
102
+ export declare function probe(): RunnerProbeResult;
103
+ /**
104
+ * Execute a command inside the native sandbox.
105
+ *
106
+ * @param command - The command and arguments to run
107
+ * @param policy - Sandbox policy configuration
108
+ * @param mode - Sandbox mode (auto, app-container, restricted-token)
109
+ * @returns Execution result with exit code, output, and events
110
+ */
111
+ export declare function execute(command: string[], policy: SandboxPolicy, mode?: 'auto' | 'app-container' | 'restricted-token'): Promise<RunnerExecuteResult>;
112
+ /**
113
+ * Reset the cached probe result — useful for testing.
114
+ * @internal
115
+ */
116
+ export declare function _resetProbeCache(): void;
117
+ /**
118
+ * Build a default sandbox policy for a given workspace.
119
+ */
120
+ export declare function buildDefaultPolicy(workspaceRoot: string, runId?: string): SandboxPolicy;
@@ -13,6 +13,10 @@ export interface DiffResult {
13
13
  astDiffs?: ASTDiffResult[];
14
14
  semanticSummary?: SemanticDiffSummary;
15
15
  markdownSummary?: string;
16
+ /**
17
+ * @deprecated This field is no longer computed and will be removed in a future version.
18
+ * It is retained for backward compatibility with existing consumers.
19
+ */
16
20
  astSkippedCount?: number;
17
21
  }
18
22
  export interface DiffErrorResult {
@@ -1,4 +1,5 @@
1
1
  import type { tool } from '@opencode-ai/plugin';
2
+ import { getAllHistory, type TestRunRecord } from '../test-impact/history-store.js';
2
3
  export declare const MAX_OUTPUT_BYTES = 512000;
3
4
  export declare const MAX_COMMAND_LENGTH = 500;
4
5
  export declare const DEFAULT_TIMEOUT_MS = 60000;
@@ -127,4 +128,10 @@ export declare function isLanguageSpecificTestFile(basename: string): boolean;
127
128
  */
128
129
  export declare function getTestFilesFromConvention(sourceFiles: string[], workingDir?: string): string[];
129
130
  export declare function runTests(framework: TestFramework, scope: 'all' | 'convention' | 'graph' | 'impact', files: string[], coverage: boolean, timeout_ms: number, cwd: string): Promise<TestResult>;
131
+ declare function selectHistoryForAnalysis(history: ReturnType<typeof getAllHistory>): TestRunRecord[];
130
132
  export declare const test_runner: ReturnType<typeof tool>;
133
+ export declare const _internals: {
134
+ readonly selectHistoryForAnalysis: typeof selectHistoryForAnalysis;
135
+ readonly AGGREGATE_TEST_NAME: "(aggregate)";
136
+ };
137
+ export {};
@@ -0,0 +1,9 @@
1
+ export declare class GitBinaryMissingError extends Error {
2
+ readonly name = "GitBinaryMissingError";
3
+ constructor(message?: string, options?: {
4
+ cause?: unknown;
5
+ });
6
+ }
7
+ export declare function isGitBinaryMissing(err: unknown): err is {
8
+ code?: string;
9
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-swarm",
3
- "version": "7.44.1",
3
+ "version": "7.46.0",
4
4
  "description": "Architect-centric agentic swarm plugin for OpenCode - hub-and-spoke orchestration with SME consultation, code generation, and QA review",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",