@coryrylan/cradle 0.0.0 → 1.3.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,8 +1,10 @@
1
+ import { type SandboxBackend } from '../agent/folder.js';
1
2
  import { type LaunchSpec } from '../agent/launch.js';
2
3
  import { type NpmPackageSpec } from '../agent/packages.js';
4
+ import { type SbxSpec } from '../sbx/compose.js';
3
5
  import { type TreeFile } from '../setup/install.js';
4
6
  import { type WhichFn } from '../util/which.js';
5
- export interface StartFlags {
7
+ export interface RunFlags {
6
8
  readonly dir: string;
7
9
  /** `--offline` → full network block. Overrides the folder network posture and forces the sandbox on (unless --no-sandbox). */
8
10
  readonly offline?: boolean;
@@ -10,15 +12,19 @@ export interface StartFlags {
10
12
  readonly allowHost?: readonly string[];
11
13
  /** Explicit CLI choice: `--no-sandbox` → true, `--sandbox` → false. Absent = defer to the folder. */
12
14
  readonly noSandbox?: boolean;
15
+ /** `--sandbox-backend` → explicit backend choice; implies the sandbox is on (still beaten by `--no-sandbox`). */
16
+ readonly sandboxBackend?: SandboxBackend;
13
17
  readonly dryRun?: boolean;
14
18
  readonly passthrough?: readonly string[];
15
19
  /** `--verbose` → show nono's full sandbox capabilities banner instead of the one-line status. */
16
20
  readonly verbose?: boolean;
17
21
  }
18
- interface StartDeps {
22
+ interface RunDeps {
19
23
  readonly cwd?: string;
20
24
  readonly home?: string;
21
25
  readonly which?: WhichFn;
26
+ /** Whether stdout is a TTY (`cli.ts` passes `process.stdout.isTTY`) — rides the sbx exec argv as `-t`; default false. */
27
+ readonly tty?: boolean;
22
28
  }
23
29
  /**
24
30
  * The agent's settings.json `packages` resolved into a per-agent npm install
@@ -41,27 +47,46 @@ export interface PackagesPlan {
41
47
  */
42
48
  readonly installCommand: readonly string[];
43
49
  }
44
- export interface StartPlan {
50
+ /**
51
+ * The sbx backend's materialization plan: the setup argvs `materializeRun`
52
+ * runs before the final `sbx exec` (composed there, wrapping the pi argv).
53
+ * `spec.piVersion` is null at plan time — the provision argv is recomposed at
54
+ * materialize with the host pi version (see `MaterializeDeps.readPiVersion`)
55
+ * so the guest install pins to it; the plan-time argv is the unpinned preview
56
+ * dry-run prints, the same precedent as package `-e` entries, which also
57
+ * resolve at materialize.
58
+ */
59
+ export interface SbxRunPlan {
60
+ readonly spec: SbxSpec;
61
+ /** Resolved host pi path — the version-pin source for guest provisioning; never spawned in-guest. */
62
+ readonly hostPiBin: string;
63
+ readonly createArgv: readonly string[];
64
+ readonly policyArgvs: ReadonlyArray<readonly string[]>;
65
+ readonly provisionArgv: readonly string[];
66
+ }
67
+ export interface RunPlan {
45
68
  /** Generated extensions, relative to `extensionsDir`. */
46
69
  readonly files: readonly TreeFile[];
47
70
  /**
48
71
  * Authoritative — the single derivation site for where generated extensions
49
- * and sessions live. `materializeStart` re-asserts these onto `launch`
72
+ * and sessions live. `materializeRun` re-asserts these onto `launch`
50
73
  * before composing the final argv, so overriding either here (as tests do)
51
74
  * changes the composed argv accordingly instead of silently disagreeing
52
- * with whatever `launch` had baked in at `planStart` time.
75
+ * with whatever `launch` had baked in at `planRun` time.
53
76
  */
54
77
  readonly extensionsDir: string;
55
78
  readonly sessionsDir: string;
56
79
  readonly warnings: readonly string[];
57
- /** The generated per-agent nono profile to write before spawning; `null` on unsandboxed runs (no profile needed). */
80
+ /** The generated per-agent nono profile to write before spawning; `null` unless the resolved backend is `'nono'`. */
58
81
  readonly profile: {
59
82
  readonly path: string;
60
83
  readonly content: string;
61
84
  } | null;
85
+ /** The sbx setup plan (see `SbxRunPlan`); `null` unless the resolved backend is `'sbx'`. */
86
+ readonly sbx: SbxRunPlan | null;
62
87
  /** Settings.json `packages` resolved into an install plan; `null` when the folder declares none. */
63
88
  readonly packages: PackagesPlan | null;
64
- /** The single argv source: `composeArgv(plan.launch)` — package-entry-free until `materializeStart` recomposes it with resolved package entries. */
89
+ /** The single argv source: `composeArgv(plan.launch)` — package-entry-free until `materializeRun` recomposes it with resolved package entries. */
65
90
  readonly launch: LaunchSpec;
66
91
  readonly dryRun: boolean;
67
92
  }
@@ -71,23 +96,32 @@ export interface StartPlan {
71
96
  * decides whether to print it (`--dry-run`) or materialize + spawn it.
72
97
  *
73
98
  * `--dry-run` only previews, so it deliberately skips the bin checks — you can
74
- * compose a command before nono/pi are installed.
99
+ * compose a command before nono/sbx/pi are installed.
75
100
  */
76
- export declare function planStart(flags: StartFlags, deps?: StartDeps): Promise<StartPlan>;
101
+ export declare function planRun(flags: RunFlags, deps?: RunDeps): Promise<RunPlan>;
102
+ export interface SbxRunResult {
103
+ readonly exitCode: number;
104
+ readonly stderr: string;
105
+ }
77
106
  export interface MaterializeDeps {
78
107
  /** Runs a package install (e.g. `npm install`) in `cwd`; `cli.ts` always passes `runInstall` from `util/proc.js`. */
79
108
  readonly install?: (command: readonly string[], cwd: string) => Promise<void>;
109
+ /** Runs one sbx setup command (create/policy/provision), capturing stderr; `cli.ts` passes `runCapture` from `util/proc.js`. */
110
+ readonly run?: (argv: readonly string[]) => Promise<SbxRunResult>;
111
+ /** Reads the host pi version (`cli.ts` passes its `--version` reader) to pin the guest install; absent → unpinned provisioning. */
112
+ readonly readPiVersion?: (piBin: string) => Promise<string | null>;
80
113
  }
81
114
  /**
82
115
  * Write the generated extensions (replacing stale ones), ensure the sessions
83
- * dir, and — on sandboxed runs — (re)write the generated per-agent nono profile
84
- * that `nono run --profile` points at. When the folder declares `packages`,
85
- * also (re)install the per-agent npm project and resolve each package's pi
86
- * extension entries, returning the final argv with those entries appended as
87
- * `-e` flags plus any resolution warnings; otherwise the plan's argv is
88
- * already final.
116
+ * dir, and — per backend — (re)write the generated per-agent nono profile
117
+ * that `nono run --profile` points at, or run the sbx setup sequence
118
+ * (create/policy/provision) and wrap the final argv in `sbx exec`. When the
119
+ * folder declares `packages`, also (re)install the per-agent npm project and
120
+ * resolve each package's pi extension entries, returning the final argv with
121
+ * those entries appended as `-e` flags plus any resolution warnings;
122
+ * otherwise the plan's argv is already final.
89
123
  */
90
- export declare function materializeStart(plan: StartPlan, deps?: MaterializeDeps): Promise<{
124
+ export declare function materializeRun(plan: RunPlan, deps?: MaterializeDeps): Promise<{
91
125
  argv: string[];
92
126
  warnings: string[];
93
127
  }>;