@snappedly-tools/shipyard 0.7.0-staging.36082887921 → 0.7.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.
- package/README.md +41 -34
- package/dist/MountConfig-bZoCs4Dd.d.ts +26 -0
- package/dist/SandboxProvider-XJQqEdSf.d.ts +261 -0
- package/dist/{chunk-JI3HDDMS.js → chunk-56TDSWFU.js} +3 -3
- package/dist/{chunk-JI3HDDMS.js.map → chunk-56TDSWFU.js.map} +1 -1
- package/dist/chunk-ACD46ZM4.js +136 -0
- package/dist/chunk-ACD46ZM4.js.map +1 -0
- package/dist/{chunk-L6PX5QTU.js → chunk-FDYOTN55.js} +887 -262
- package/dist/chunk-FDYOTN55.js.map +1 -0
- package/dist/chunk-KMGNFXKN.js +38 -0
- package/dist/chunk-KMGNFXKN.js.map +1 -0
- package/dist/chunk-SOJTAJTF.js +78 -0
- package/dist/chunk-SOJTAJTF.js.map +1 -0
- package/dist/{chunk-44I2BL6E.js → chunk-WAXEMZUV.js} +33 -225
- package/dist/chunk-WAXEMZUV.js.map +1 -0
- package/dist/index.d.ts +97 -117
- package/dist/index.js +344 -322
- package/dist/index.js.map +1 -1
- package/dist/main.js +139 -235
- package/dist/main.js.map +1 -1
- package/dist/sandboxes/docker.d.ts +3 -1
- package/dist/sandboxes/docker.js +4 -2
- package/dist/sandboxes/no-sandbox.d.ts +37 -0
- package/dist/sandboxes/no-sandbox.js +4 -0
- package/dist/sandboxes/no-sandbox.js.map +1 -0
- package/dist/sandboxes/vercel.d.ts +104 -0
- package/dist/sandboxes/vercel.js +166 -0
- package/dist/sandboxes/vercel.js.map +1 -0
- package/dist/templates/blank/main.mts +13 -0
- package/dist/templates/blank/prompt.md +12 -0
- package/dist/templates/blank/template.json +4 -0
- package/dist/templates/parallel-planner/main.mts +9 -67
- package/dist/templates/parallel-planner-with-review/main.mts +12 -70
- package/dist/templates/sequential-reviewer/main.mts +3 -52
- package/dist/templates/simple-loop/main.mts +2 -51
- package/package.json +17 -1
- package/dist/MountConfig-BHnKnA4h.d.ts +0 -145
- package/dist/chunk-44I2BL6E.js.map +0 -1
- package/dist/chunk-L6PX5QTU.js.map +0 -1
- package/dist/templates/parallel-planner/planner-branch.mts +0 -151
- package/dist/templates/parallel-planner-with-review/planner-branch.mts +0 -151
package/README.md
CHANGED
|
@@ -23,71 +23,78 @@ a commit or pull request you can inspect.
|
|
|
23
23
|
|
|
24
24
|
## Try it on one task
|
|
25
25
|
|
|
26
|
-
You need **Node.js 20.18.1+**, **Git**, **Docker running**, and **Codex or Claude
|
|
27
|
-
with a
|
|
26
|
+
You need **Node.js 20.18.1+**, **Git**, **Docker running**, and **Codex or Claude
|
|
27
|
+
Code** with a login or API key. Start with a clean Git repository you want
|
|
28
|
+
Shipyard to change. If it is on GitHub, sign in with the
|
|
29
|
+
[GitHub CLI](https://cli.github.com/) (`gh auth login`) before `init`; Shipyard
|
|
30
|
+
creates its issue labels there.
|
|
28
31
|
|
|
29
32
|
Run:
|
|
30
33
|
|
|
31
34
|
```sh
|
|
35
|
+
git switch -c try-shipyard
|
|
32
36
|
npx skills add snappedly/skills
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
Ask your coding agent to run `setup-snappedly-skills` in that repository.
|
|
36
|
-
|
|
37
|
-
```sh
|
|
38
37
|
npm install --save-dev @snappedly-tools/shipyard
|
|
39
38
|
npx shipyard init
|
|
40
39
|
```
|
|
41
40
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
the authentication prompts.
|
|
41
|
+
Ask your coding agent to run `setup-snappedly-skills` in that repository. During
|
|
42
|
+
`shipyard init`, choose your agent, **Docker**, and the **blank** template. Follow
|
|
43
|
+
the authentication prompts. You can skip the optional repository runner for
|
|
44
|
+
this first task.
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
It runs as long as its terminal stays open.
|
|
46
|
+
Open `.shipyard/prompt.md` and describe a small change. For example:
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
```md
|
|
49
|
+
# Task
|
|
51
50
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
Requests read/write access and Metadata read access.
|
|
55
|
-
Set `SHIPYARD_ROUTINE_MODEL` and `SHIPYARD_STRONG_MODEL` in `.shipyard/.env`
|
|
56
|
-
for the roles your template uses. `simple-loop` uses routine for triage and
|
|
57
|
-
implementation. `sequential-reviewer` also uses strong for issue reviews.
|
|
58
|
-
Parallel planner templates use routine for ticket work and strong for planning,
|
|
59
|
-
conflict resolution, and integration. The review-enabled planner also uses
|
|
60
|
-
strong for ticket and final specification reviews. See
|
|
61
|
-
[agent setup](docs/content/docs/agents.mdx).
|
|
62
|
-
|
|
63
|
-
Commit the setup and prompt so the sandbox can read them. Make sure the Git ignore file keeps
|
|
64
|
-
`.shipyard/.env` out of the commit.
|
|
51
|
+
Document how to run this project locally using commands already in the repo.
|
|
52
|
+
Run the relevant checks and commit the change.
|
|
65
53
|
|
|
66
|
-
|
|
67
|
-
|
|
54
|
+
# Done
|
|
55
|
+
|
|
56
|
+
Output <promise>COMPLETE</promise> when finished.
|
|
68
57
|
```
|
|
69
58
|
|
|
70
|
-
|
|
59
|
+
Fill in any credentials requested in `.shipyard/.env`. Commit the setup and
|
|
60
|
+
prompt so the sandbox can read them. The generated Git ignore file keeps
|
|
61
|
+
`.shipyard/.env` out of the commit.
|
|
71
62
|
|
|
72
63
|
```sh
|
|
73
|
-
|
|
64
|
+
git add .
|
|
65
|
+
git commit -m "Set up Shipyard"
|
|
66
|
+
npx shipyard run
|
|
67
|
+
git show --stat HEAD
|
|
74
68
|
```
|
|
75
69
|
|
|
70
|
+
Shipyard builds the Docker image, runs the agent, and returns its commit to your
|
|
71
|
+
current branch. `git show` lets you inspect what changed. See the
|
|
72
|
+
[getting started guide](docs/content/docs/index.mdx) for authentication and
|
|
73
|
+
branch options.
|
|
74
|
+
|
|
76
75
|
## Turn GitHub issues into pull requests
|
|
77
76
|
|
|
78
|
-
|
|
77
|
+
For a repository you want to automate from GitHub Issues, choose
|
|
78
|
+
**sequential-reviewer** instead of **blank** during `shipyard init`. Set
|
|
79
|
+
`GH_TOKEN` in `.shipyard/.env` to a token with Contents, Issues, and Pull
|
|
80
|
+
requests read/write access and Metadata read access. Then:
|
|
79
81
|
|
|
80
82
|
1. Write an issue with a clear goal and add the `shipyard` and
|
|
81
83
|
`ready-for-agent` labels.
|
|
82
|
-
2.
|
|
84
|
+
2. Run `npx shipyard run`. Shipyard checks the issue, implements it in Docker,
|
|
83
85
|
reviews the work, and opens a pull request.
|
|
84
86
|
3. Inspect the pull request and merge it when you are happy with the result.
|
|
85
87
|
|
|
88
|
+
On an Apple Silicon Mac, the optional [repository runner](docs/content/docs/repository-runner.mdx)
|
|
89
|
+
can wake Shipyard when you label an issue. It runs while its terminal stays open.
|
|
90
|
+
The guide covers installation, retries, and issue status labels.
|
|
91
|
+
|
|
86
92
|
## Choose a workflow
|
|
87
93
|
|
|
88
94
|
| Template | What it does |
|
|
89
95
|
| ------------------------------ | -------------------------------------------------- |
|
|
90
|
-
| `
|
|
96
|
+
| `blank` | Runs your own task and prompt. |
|
|
97
|
+
| `simple-loop` | Works through labelled issues one at a time. |
|
|
91
98
|
| `sequential-reviewer` | Implements and reviews issues before PR handoff. |
|
|
92
99
|
| `parallel-planner` | Plans and works on independent issues in parallel. |
|
|
93
100
|
| `parallel-planner-with-review` | Adds review to the parallel workflow. |
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User-facing mount configuration for bind-mount sandbox providers.
|
|
3
|
+
*
|
|
4
|
+
* Each entry describes a host directory to mount into the sandbox container.
|
|
5
|
+
*/
|
|
6
|
+
/** A single bind-mount descriptor for the Docker provider. */
|
|
7
|
+
interface MountConfig {
|
|
8
|
+
/**
|
|
9
|
+
* Path on the host. Supports:
|
|
10
|
+
* - Absolute paths (`/data/cache`)
|
|
11
|
+
* - Tilde-expanded paths (`~/data` → `<home>/data`)
|
|
12
|
+
* - Relative paths (`data` or `./data`) — resolved from `process.cwd()`
|
|
13
|
+
*/
|
|
14
|
+
readonly hostPath: string;
|
|
15
|
+
/**
|
|
16
|
+
* Path inside the sandbox container. Supports:
|
|
17
|
+
* - Absolute paths (`/mnt/data`)
|
|
18
|
+
* - Tilde-expanded paths (`~/.npm` → `/home/agent/.npm`) — expanded using the provider's sandbox home directory
|
|
19
|
+
* - Relative paths (`data` or `./data`) — resolved from the worktree directory (`/home/agent/workspace`)
|
|
20
|
+
*/
|
|
21
|
+
readonly sandboxPath: string;
|
|
22
|
+
/** Mount as read-only. Defaults to `false`. */
|
|
23
|
+
readonly readonly?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type { MountConfig as M };
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sandbox provider types — the pluggable interface for sandbox runtimes.
|
|
3
|
+
*
|
|
4
|
+
* Provider authors implement a small Promise-based interface. Shipyard
|
|
5
|
+
* handles worktree creation, git mount resolution, and commit extraction.
|
|
6
|
+
*/
|
|
7
|
+
/** Result of executing a command inside a sandbox. */
|
|
8
|
+
interface ExecResult {
|
|
9
|
+
readonly stdout: string;
|
|
10
|
+
readonly stderr: string;
|
|
11
|
+
readonly exitCode: number;
|
|
12
|
+
}
|
|
13
|
+
/** Options for interactiveExec — the streams the provider should wire to the spawned process. */
|
|
14
|
+
interface InteractiveExecOptions {
|
|
15
|
+
readonly stdin: NodeJS.ReadableStream;
|
|
16
|
+
readonly stdout: NodeJS.WritableStream;
|
|
17
|
+
readonly stderr: NodeJS.WritableStream;
|
|
18
|
+
readonly cwd?: string;
|
|
19
|
+
/** Terminate the interactive process when the caller cancels the session. */
|
|
20
|
+
readonly signal?: AbortSignal;
|
|
21
|
+
}
|
|
22
|
+
/** Handle to a running bind-mount sandbox. */
|
|
23
|
+
interface BindMountSandboxHandle {
|
|
24
|
+
/** Absolute path to the worktree inside the sandbox. */
|
|
25
|
+
readonly worktreePath: string;
|
|
26
|
+
/**
|
|
27
|
+
* Execute a command in the sandbox.
|
|
28
|
+
*
|
|
29
|
+
* Implementations MUST support line-by-line streaming via `onLine`. This is
|
|
30
|
+
* how Shipyard delivers live feedback to the user and enforces idle timeouts —
|
|
31
|
+
* without a streaming implementation, neither will work. A buffered/batch
|
|
32
|
+
* implementation that only calls `onLine` after the process exits does NOT
|
|
33
|
+
* satisfy this contract.
|
|
34
|
+
*
|
|
35
|
+
* When `stdin` is set, the implementation pipes the string to the child
|
|
36
|
+
* process's stdin and closes it. This avoids the Linux 128 KB per-arg limit.
|
|
37
|
+
*/
|
|
38
|
+
exec(command: string, options?: {
|
|
39
|
+
onLine?: (line: string) => void;
|
|
40
|
+
cwd?: string;
|
|
41
|
+
sudo?: boolean;
|
|
42
|
+
stdin?: string;
|
|
43
|
+
/** Abort the command when the caller's operation is cancelled. */
|
|
44
|
+
signal?: AbortSignal;
|
|
45
|
+
/** Reject/terminate the command after this many combined output bytes. */
|
|
46
|
+
maxOutputBytes?: number;
|
|
47
|
+
}): Promise<ExecResult>;
|
|
48
|
+
/**
|
|
49
|
+
* Launch an interactive process inside the sandbox.
|
|
50
|
+
* Optional — providers that support interactive sessions implement this.
|
|
51
|
+
* The provider detects TTY mode from the streams (e.g. stdin.isTTY) and
|
|
52
|
+
* allocates a pseudo-terminal accordingly.
|
|
53
|
+
* Implementations MUST terminate the underlying process when `signal` aborts.
|
|
54
|
+
*/
|
|
55
|
+
interactiveExec?(args: string[], options: InteractiveExecOptions): Promise<{
|
|
56
|
+
exitCode: number;
|
|
57
|
+
}>;
|
|
58
|
+
/** Copy a single file from the host into the sandbox. */
|
|
59
|
+
copyFileIn(hostPath: string, sandboxPath: string): Promise<void>;
|
|
60
|
+
/** Copy a single file from the sandbox to the host. */
|
|
61
|
+
copyFileOut(sandboxPath: string, hostPath: string): Promise<void>;
|
|
62
|
+
/** Tear down the sandbox. */
|
|
63
|
+
close(): Promise<void>;
|
|
64
|
+
}
|
|
65
|
+
/** Options passed to a bind-mount provider's `create` function. */
|
|
66
|
+
interface BindMountCreateOptions {
|
|
67
|
+
/** Host-side path to the worktree directory. */
|
|
68
|
+
readonly worktreePath: string;
|
|
69
|
+
/** Host-side path to the original repo root. */
|
|
70
|
+
readonly hostRepoPath: string;
|
|
71
|
+
/** Volume mounts to apply (host:sandbox pairs). */
|
|
72
|
+
readonly mounts: Array<{
|
|
73
|
+
hostPath: string;
|
|
74
|
+
sandboxPath: string;
|
|
75
|
+
readonly?: boolean;
|
|
76
|
+
}>;
|
|
77
|
+
/** Environment variables to inject into the sandbox. */
|
|
78
|
+
readonly env: Record<string, string>;
|
|
79
|
+
}
|
|
80
|
+
/** Configuration for createBindMountSandboxProvider. */
|
|
81
|
+
interface BindMountSandboxProviderConfig {
|
|
82
|
+
/** Human-readable name for this provider (e.g. "docker"). */
|
|
83
|
+
readonly name: string;
|
|
84
|
+
/** Environment variables injected by this provider. Merged at launch time. */
|
|
85
|
+
readonly env?: Record<string, string>;
|
|
86
|
+
/**
|
|
87
|
+
* Absolute path to the home directory inside the sandbox (e.g. `"/home/agent"`).
|
|
88
|
+
* Used to expand `~` in user-provided `sandboxPath` mount configs.
|
|
89
|
+
* Set to `undefined` for providers that do not have a fixed home directory.
|
|
90
|
+
*/
|
|
91
|
+
readonly sandboxHomedir?: string;
|
|
92
|
+
/** Create a sandbox handle from the given options. */
|
|
93
|
+
readonly create: (options: BindMountCreateOptions) => Promise<BindMountSandboxHandle>;
|
|
94
|
+
}
|
|
95
|
+
/** Handle to a running isolated sandbox (extends bind-mount with file transfer). */
|
|
96
|
+
interface IsolatedSandboxHandle {
|
|
97
|
+
/** Absolute path to the worktree inside the sandbox. */
|
|
98
|
+
readonly worktreePath: string;
|
|
99
|
+
/**
|
|
100
|
+
* Execute a command in the sandbox.
|
|
101
|
+
*
|
|
102
|
+
* Implementations MUST support line-by-line streaming via `onLine`. This is
|
|
103
|
+
* how Shipyard delivers live feedback to the user and enforces idle timeouts —
|
|
104
|
+
* without a streaming implementation, neither will work. A buffered/batch
|
|
105
|
+
* implementation that only calls `onLine` after the process exits does NOT
|
|
106
|
+
* satisfy this contract.
|
|
107
|
+
*
|
|
108
|
+
* When `stdin` is set, the implementation pipes the string to the child
|
|
109
|
+
* process's stdin and closes it. This avoids the Linux 128 KB per-arg limit.
|
|
110
|
+
*/
|
|
111
|
+
exec(command: string, options?: {
|
|
112
|
+
onLine?: (line: string) => void;
|
|
113
|
+
cwd?: string;
|
|
114
|
+
sudo?: boolean;
|
|
115
|
+
stdin?: string;
|
|
116
|
+
/** Abort the command when the caller's operation is cancelled. */
|
|
117
|
+
signal?: AbortSignal;
|
|
118
|
+
/** Reject/terminate the command after this many combined output bytes. */
|
|
119
|
+
maxOutputBytes?: number;
|
|
120
|
+
}): Promise<ExecResult>;
|
|
121
|
+
/**
|
|
122
|
+
* Launch an interactive process inside the sandbox.
|
|
123
|
+
* Optional — providers that support interactive sessions implement this.
|
|
124
|
+
* The provider detects TTY mode from the streams (e.g. stdin.isTTY) and
|
|
125
|
+
* allocates a pseudo-terminal accordingly.
|
|
126
|
+
* Implementations MUST terminate the underlying process when `signal` aborts.
|
|
127
|
+
*/
|
|
128
|
+
interactiveExec?(args: string[], options: InteractiveExecOptions): Promise<{
|
|
129
|
+
exitCode: number;
|
|
130
|
+
}>;
|
|
131
|
+
/** Copy a file or directory from the host into the sandbox. */
|
|
132
|
+
copyIn(hostPath: string, sandboxPath: string): Promise<void>;
|
|
133
|
+
/** Copy a single file from the sandbox to the host. */
|
|
134
|
+
copyFileOut(sandboxPath: string, hostPath: string): Promise<void>;
|
|
135
|
+
/** Tear down the sandbox. */
|
|
136
|
+
close(): Promise<void>;
|
|
137
|
+
}
|
|
138
|
+
/** Options passed to an isolated provider's `create` function. */
|
|
139
|
+
interface IsolatedCreateOptions {
|
|
140
|
+
/** Original host repository path, used only for image naming; never mounted. */
|
|
141
|
+
readonly hostRepoPath?: string;
|
|
142
|
+
/** Environment variables to inject into the sandbox. */
|
|
143
|
+
readonly env: Record<string, string>;
|
|
144
|
+
}
|
|
145
|
+
/** Configuration for createIsolatedSandboxProvider. */
|
|
146
|
+
interface IsolatedSandboxProviderConfig {
|
|
147
|
+
/** Human-readable name for this provider (e.g. "vercel"). */
|
|
148
|
+
readonly name: string;
|
|
149
|
+
/** Environment variables injected by this provider. Merged at launch time. */
|
|
150
|
+
readonly env?: Record<string, string>;
|
|
151
|
+
/** Create an isolated sandbox handle from the given options. */
|
|
152
|
+
readonly create: (options: IsolatedCreateOptions) => Promise<IsolatedSandboxHandle>;
|
|
153
|
+
}
|
|
154
|
+
/** A bind-mount sandbox provider. */
|
|
155
|
+
interface BindMountSandboxProvider {
|
|
156
|
+
/** Human-readable provider name. */
|
|
157
|
+
readonly name: string;
|
|
158
|
+
/** Environment variables injected by this provider. */
|
|
159
|
+
readonly env: Record<string, string>;
|
|
160
|
+
/**
|
|
161
|
+
* Absolute path to the home directory inside the sandbox (e.g. `"/home/agent"`).
|
|
162
|
+
* `undefined` when the provider does not declare a sandbox home directory.
|
|
163
|
+
*/
|
|
164
|
+
readonly sandboxHomedir: string | undefined;
|
|
165
|
+
}
|
|
166
|
+
/** An isolated sandbox provider. */
|
|
167
|
+
interface IsolatedSandboxProvider {
|
|
168
|
+
/** Human-readable provider name. */
|
|
169
|
+
readonly name: string;
|
|
170
|
+
/** Environment variables injected by this provider. */
|
|
171
|
+
readonly env: Record<string, string>;
|
|
172
|
+
}
|
|
173
|
+
/** Handle to a no-sandbox session — runs commands directly on the host. */
|
|
174
|
+
interface NoSandboxHandle {
|
|
175
|
+
/** Absolute path to the worktree on the host. */
|
|
176
|
+
readonly worktreePath: string;
|
|
177
|
+
/**
|
|
178
|
+
* Execute a command on the host.
|
|
179
|
+
*
|
|
180
|
+
* Implementations MUST support line-by-line streaming via `onLine`. This is
|
|
181
|
+
* how Shipyard delivers live feedback to the user and enforces idle timeouts —
|
|
182
|
+
* without a streaming implementation, neither will work.
|
|
183
|
+
*
|
|
184
|
+
* When `stdin` is set, the implementation pipes the string to the child
|
|
185
|
+
* process's stdin and closes it. This avoids the Linux 128 KB per-arg limit.
|
|
186
|
+
*/
|
|
187
|
+
exec(command: string, options?: {
|
|
188
|
+
onLine?: (line: string) => void;
|
|
189
|
+
cwd?: string;
|
|
190
|
+
sudo?: boolean;
|
|
191
|
+
stdin?: string;
|
|
192
|
+
/** Abort the command when the caller's operation is cancelled. */
|
|
193
|
+
signal?: AbortSignal;
|
|
194
|
+
/** Reject/terminate the command after this many combined output bytes. */
|
|
195
|
+
maxOutputBytes?: number;
|
|
196
|
+
}): Promise<ExecResult>;
|
|
197
|
+
/**
|
|
198
|
+
* Launch an interactive process on the host with inherited stdio.
|
|
199
|
+
*/
|
|
200
|
+
interactiveExec(args: string[], options: InteractiveExecOptions): Promise<{
|
|
201
|
+
exitCode: number;
|
|
202
|
+
}>;
|
|
203
|
+
/** No-op — no container to tear down. */
|
|
204
|
+
close(): Promise<void>;
|
|
205
|
+
}
|
|
206
|
+
/** A no-sandbox provider — runs the agent directly on the host with no container isolation. */
|
|
207
|
+
interface NoSandboxProvider {
|
|
208
|
+
/** Human-readable provider name. */
|
|
209
|
+
readonly name: string;
|
|
210
|
+
/** Environment variables injected by this provider. */
|
|
211
|
+
readonly env: Record<string, string>;
|
|
212
|
+
}
|
|
213
|
+
/** Head strategy: agent writes directly to host working directory. Bind-mount only. */
|
|
214
|
+
interface HeadBranchStrategy {
|
|
215
|
+
readonly type: "head";
|
|
216
|
+
}
|
|
217
|
+
/** Merge-to-head strategy: temp branch, merge back to HEAD, delete temp branch. */
|
|
218
|
+
interface MergeToHeadBranchStrategy {
|
|
219
|
+
readonly type: "merge-to-head";
|
|
220
|
+
}
|
|
221
|
+
/** Branch strategy: commits land on an explicit named branch. */
|
|
222
|
+
interface NamedBranchStrategy {
|
|
223
|
+
readonly type: "branch";
|
|
224
|
+
readonly branch: string;
|
|
225
|
+
/**
|
|
226
|
+
* Git ref to use as the starting point when creating a new branch.
|
|
227
|
+
* Only used when the branch doesn't already exist — ignored otherwise.
|
|
228
|
+
* Callers are responsible for ensuring the ref is current (e.g. `git fetch`).
|
|
229
|
+
* Defaults to `HEAD` when omitted.
|
|
230
|
+
*/
|
|
231
|
+
readonly baseBranch?: string;
|
|
232
|
+
}
|
|
233
|
+
/** Branch strategy for bind-mount providers (all three variants). */
|
|
234
|
+
type BindMountBranchStrategy = HeadBranchStrategy | MergeToHeadBranchStrategy | NamedBranchStrategy;
|
|
235
|
+
/** Branch strategy for isolated providers (no head — can't write to host). */
|
|
236
|
+
type IsolatedBranchStrategy = MergeToHeadBranchStrategy | NamedBranchStrategy;
|
|
237
|
+
/** Branch strategy for no-sandbox providers (all three — same as bind-mount). */
|
|
238
|
+
type NoSandboxBranchStrategy = HeadBranchStrategy | MergeToHeadBranchStrategy | NamedBranchStrategy;
|
|
239
|
+
/** Union of all branch strategy variants. */
|
|
240
|
+
type BranchStrategy = BindMountBranchStrategy | IsolatedBranchStrategy | NoSandboxBranchStrategy;
|
|
241
|
+
/**
|
|
242
|
+
* A sandbox provider — the pluggable unit that `run()`, `interactive()`, and
|
|
243
|
+
* `createSandbox()` accept. Tagged for internal dispatch: "bind-mount",
|
|
244
|
+
* "isolated", or "none". When `NoSandboxProvider` is used, the agent runs
|
|
245
|
+
* directly on the host with no container isolation — opt in at your own risk.
|
|
246
|
+
*/
|
|
247
|
+
type SandboxProvider = BindMountSandboxProvider | IsolatedSandboxProvider | NoSandboxProvider;
|
|
248
|
+
/** @deprecated Use `SandboxProvider` — it now includes `NoSandboxProvider`. */
|
|
249
|
+
type AnySandboxProvider = SandboxProvider;
|
|
250
|
+
/**
|
|
251
|
+
* Create a bind-mount sandbox provider from a config object.
|
|
252
|
+
* The returned provider can be passed to `run()` or `createSandbox()`.
|
|
253
|
+
*/
|
|
254
|
+
declare const createBindMountSandboxProvider: (config: BindMountSandboxProviderConfig) => BindMountSandboxProvider;
|
|
255
|
+
/**
|
|
256
|
+
* Create an isolated sandbox provider from a config object.
|
|
257
|
+
* The returned provider can be passed to `run()` or `createSandbox()`.
|
|
258
|
+
*/
|
|
259
|
+
declare const createIsolatedSandboxProvider: (config: IsolatedSandboxProviderConfig) => IsolatedSandboxProvider;
|
|
260
|
+
|
|
261
|
+
export { type AnySandboxProvider as A, type BindMountSandboxHandle as B, type ExecResult as E, type HeadBranchStrategy as H, type IsolatedSandboxProvider as I, type MergeToHeadBranchStrategy as M, type NoSandboxProvider as N, type SandboxProvider as S, type BranchStrategy as a, type NamedBranchStrategy as b, type BindMountBranchStrategy as c, type BindMountCreateOptions as d, type BindMountSandboxProvider as e, type BindMountSandboxProviderConfig as f, type InteractiveExecOptions as g, type IsolatedBranchStrategy as h, type IsolatedCreateOptions as i, type IsolatedSandboxHandle as j, type IsolatedSandboxProviderConfig as k, type NoSandboxBranchStrategy as l, type NoSandboxHandle as m, createBindMountSandboxProvider as n, createIsolatedSandboxProvider as o };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CONFIG_DIR, ConfigDirError, assertNoSymlinkComponents, LOGS_DIR, Display } from './chunk-
|
|
1
|
+
import { CONFIG_DIR, ConfigDirError, assertNoSymlinkComponents, LOGS_DIR, Display } from './chunk-FDYOTN55.js';
|
|
2
2
|
import { Effect } from 'effect';
|
|
3
3
|
import { FileSystem } from '@effect/platform';
|
|
4
4
|
import { join } from 'path';
|
|
@@ -251,5 +251,5 @@ var purgeRunLogs = async (options) => {
|
|
|
251
251
|
};
|
|
252
252
|
|
|
253
253
|
export { CODEX_MODELS, CODEX_REASONING_EFFORTS, DEFAULT_LOG_RETENTION_DAYS, buildLogDirectoryName, formatErrorMessage, purgeRunLogs, resolveEnv, withFriendlyErrors };
|
|
254
|
-
//# sourceMappingURL=chunk-
|
|
255
|
-
//# sourceMappingURL=chunk-
|
|
254
|
+
//# sourceMappingURL=chunk-56TDSWFU.js.map
|
|
255
|
+
//# sourceMappingURL=chunk-56TDSWFU.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ErrorHandler.ts","../src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AAA,GAAO,MAAM,KAAA,CAAM,SAAS,CAAA;AAClC,MAAA,IAAI,KAAK,MAAA,EAAO,KAAM,WAAW,MAAA,IAAa,IAAA,CAAK,QAAQ,MAAA,CAAA,EAAS;AAClE,QAAA,MAAM,EAAA,CAAG,SAAA,EAAW,EAAE,KAAA,EAAO,MAAM,CAAA;AACnC,QAAA,YAAA,CAAa,IAAA,CAAK,MAAM,IAAI,CAAA;AAAA,MAC9B;AACA,MAAA;AAAA,IACF;AACA,IAAA,IAAI,CAAC,KAAA,CAAM,WAAA,EAAY,EAAG;AAC1B,IAAA,MAAM,aAAA,GAAgB,qBAAA,CAAsB,KAAA,CAAM,IAAI,CAAA;AACtD,IAAA,IAAI,kBAAkB,MAAA,EAAW;AACjC,IAAA,kBAAA,IAAsB,CAAA;AACtB,IAAA,IAAI,MAAA,KAAW,MAAA,IAAa,aAAA,IAAiB,MAAA,EAAQ;AAErD,IAAA,MAAM,GAAG,SAAA,EAAW,EAAE,WAAW,IAAA,EAAM,KAAA,EAAO,MAAM,CAAA;AACpD,IAAA,kBAAA,CAAmB,IAAA,CAAK,MAAM,IAAI,CAAA;AAAA,EACpC;AAEA,EAAA,OAAO;AAAA,IACL,OAAA;AAAA,IACA,GAAI,aAAA,KAAkB,MAAA,GAAY,EAAC,GAAI,EAAE,eAAe,UAAA,EAAW;AAAA,IACnE,kBAAA;AAAA,IACA,YAAA,EAAc,kBAAA,CAAmB,MAAA,GAAS,YAAA,CAAa,MAAA;AAAA,IACvD,kBAAA;AAAA,IACA;AAAA,GACF;AACF","file":"chunk-JI3HDDMS.js","sourcesContent":["import { Effect } from \"effect\";\nimport { Display } from \"./Display.js\";\nimport type { SandboxError } from \"./errors.js\";\n\n/**\n * Formats a tagged SandboxError into a user-friendly message with\n * context-specific hints about what went wrong and how to recover.\n */\nexport const formatErrorMessage = (error: SandboxError): string => {\n switch (error._tag) {\n case \"ExecError\":\n return `Command failed in sandbox (${error.command}): ${error.message}`;\n case \"ExecHostError\":\n return `Command failed on host (${error.command}): ${error.message}`;\n case \"CopyError\":\n return `File copy failed: ${error.message}`;\n case \"DockerError\":\n return `Docker operation failed: ${error.message}. Is Docker running?`;\n case \"SyncError\":\n return `Git sync failed: ${error.message}`;\n case \"WorktreeError\":\n return `Git worktree operation failed: ${error.message}`;\n case \"PromptError\":\n return `Failed to resolve prompt: ${error.message}`;\n case \"AgentError\":\n return `Agent invocation failed: ${error.message}`;\n case \"ConfigDirError\":\n return `${error.message}`;\n case \"InitError\":\n return `${error.message}`;\n case \"AgentIdleTimeoutError\":\n case \"WorktreeTimeoutError\":\n case \"ContainerStartTimeoutError\":\n case \"CopyToWorktreeTimeoutError\":\n case \"CopyToWorktreeError\":\n case \"SyncInTimeoutError\":\n case \"HookTimeoutError\":\n case \"GitSetupTimeoutError\":\n case \"PromptExpansionTimeoutError\":\n case \"CommitCollectionTimeoutError\":\n case \"MergeToHostTimeoutError\":\n case \"SessionCaptureError\":\n case \"CwdError\":\n return error.message;\n }\n};\n\nconst showErrorAndExit = (error: SandboxError) =>\n Effect.gen(function* () {\n const d = yield* Display;\n yield* d.status(formatErrorMessage(error), \"error\");\n return yield* Effect.sync(() => process.exit(1) as never);\n });\n\n/**\n * Wraps an effect so that any SandboxError is caught, displayed via the\n * Display service as an error-severity status message, then exits the process\n * with code 1. Non-SandboxError errors pass through unchanged.\n */\nexport const withFriendlyErrors = <A, E, R>(\n effect: Effect.Effect<A, E, R>,\n): Effect.Effect<A, Exclude<E, SandboxError>, R | Display> =>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n Effect.catchTags(effect as Effect.Effect<A, SandboxError, R>, {\n ExecError: showErrorAndExit,\n ExecHostError: showErrorAndExit,\n CopyError: showErrorAndExit,\n DockerError: showErrorAndExit,\n SyncError: showErrorAndExit,\n WorktreeError: showErrorAndExit,\n PromptError: showErrorAndExit,\n AgentError: showErrorAndExit,\n ConfigDirError: showErrorAndExit,\n InitError: showErrorAndExit,\n AgentIdleTimeoutError: showErrorAndExit,\n WorktreeTimeoutError: showErrorAndExit,\n ContainerStartTimeoutError: showErrorAndExit,\n CopyToWorktreeTimeoutError: showErrorAndExit,\n CopyToWorktreeError: showErrorAndExit,\n SyncInTimeoutError: showErrorAndExit,\n HookTimeoutError: showErrorAndExit,\n GitSetupTimeoutError: showErrorAndExit,\n PromptExpansionTimeoutError: showErrorAndExit,\n CommitCollectionTimeoutError: showErrorAndExit,\n MergeToHostTimeoutError: showErrorAndExit,\n SessionCaptureError: showErrorAndExit,\n CwdError: showErrorAndExit,\n }) as Effect.Effect<A, Exclude<E, SandboxError>, R | Display>;\n","/** Reasoning efforts accepted by the Codex CLI. */\nexport const CODEX_REASONING_EFFORTS = [\n \"low\",\n \"medium\",\n \"high\",\n \"xhigh\",\n \"max\",\n] as const;\n\nexport type CodexReasoningEffort = (typeof CODEX_REASONING_EFFORTS)[number];\n\n/** A model identifier plus the reasoning policy used for that model role. */\nexport interface CodexModelConfig {\n readonly model: string;\n readonly effort: CodexReasoningEffort;\n}\n\n/**\n * Default values for Shipyard's built-in Codex roles.\n *\n * Runtime environment variables override these defaults:\n * SHIPYARD_CODEX_ROUTINE_MODEL\n * SHIPYARD_CODEX_ROUTINE_REASONING_EFFORT\n * SHIPYARD_CODEX_STRONG_MODEL\n * SHIPYARD_CODEX_STRONG_REASONING_EFFORT\n *\n * Keep the defaults here so runtime providers, generated templates, and the\n * repository workflows all use the same role definitions.\n */\nconst DEFAULT_CODEX_MODELS = {\n routine: { model: \"gpt-5.6-luna\", effort: \"max\" },\n strong: { model: \"gpt-5.6-sol\", effort: \"max\" },\n} as const satisfies Record<string, CodexModelConfig>;\n\nconst readModel = (role: keyof typeof DEFAULT_CODEX_MODELS): string =>\n process.env[`SHIPYARD_CODEX_${role.toUpperCase()}_MODEL`]?.trim() ||\n DEFAULT_CODEX_MODELS[role].model;\n\nconst readEffort = (\n role: keyof typeof DEFAULT_CODEX_MODELS,\n): CodexReasoningEffort => {\n const envName = `SHIPYARD_CODEX_${role.toUpperCase()}_REASONING_EFFORT`;\n const value = process.env[envName]?.trim();\n if (!value) return DEFAULT_CODEX_MODELS[role].effort;\n if ((CODEX_REASONING_EFFORTS as readonly string[]).includes(value)) {\n return value as CodexReasoningEffort;\n }\n throw new Error(\n `${envName} must be one of ${CODEX_REASONING_EFFORTS.join(\", \")}; received \"${value}\"`,\n );\n};\n\nexport const CODEX_MODELS = {\n routine: {\n model: readModel(\"routine\"),\n effort: readEffort(\"routine\"),\n },\n strong: {\n model: readModel(\"strong\"),\n effort: readEffort(\"strong\"),\n },\n} as const satisfies Record<string, CodexModelConfig>;\n","import { FileSystem } from \"@effect/platform\";\nimport { Effect } from \"effect\";\nimport { join } from \"node:path\";\n\nimport { ConfigDirError } from \"./errors.js\";\nimport { assertNoSymlinkComponents } from \"./pathSecurity.js\";\nimport { CONFIG_DIR } from \"./runtimeNames.js\";\n\nconst parseEnvFile = (\n filePath: string,\n): Effect.Effect<Record<string, string>, never, FileSystem.FileSystem> =>\n Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const symlink = yield* fs.readLink(filePath).pipe(\n Effect.map(() => true),\n Effect.catchAll(() => Effect.succeed(false)),\n );\n // A repository-controlled symlink could redirect this read to a host\n // secret and then expose matching keys to the agent.\n if (symlink) return {};\n const content = yield* fs\n .readFileString(filePath)\n .pipe(Effect.catchAll(() => Effect.succeed(null)));\n if (content === null) return {};\n const vars: Record<string, string> = {};\n for (const line of content.split(\"\\n\")) {\n const trimmed = line.trim();\n if (!trimmed || trimmed.startsWith(\"#\")) continue;\n const eqIndex = trimmed.indexOf(\"=\");\n if (eqIndex === -1) continue;\n const key = trimmed.slice(0, eqIndex).trim();\n let value = trimmed.slice(eqIndex + 1).trim();\n const isDoubleQuoted =\n value.length >= 2 &&\n value[0] === '\"' &&\n value[value.length - 1] === '\"';\n const isSingleQuoted =\n value.length >= 2 &&\n value[0] === \"'\" &&\n value[value.length - 1] === \"'\";\n if (isDoubleQuoted || isSingleQuoted) {\n value = value.slice(1, -1);\n }\n if (isDoubleQuoted) {\n value = value.replace(/\\\\([nrt\\\\])/g, (_, ch: string) => {\n const escapes: Record<string, string> = {\n n: \"\\n\",\n r: \"\\r\",\n t: \"\\t\",\n \"\\\\\": \"\\\\\",\n };\n return escapes[ch] ?? ch;\n });\n }\n vars[key] = value;\n }\n return vars;\n });\n\n/**\n * Resolve all env vars from .env files with process.env fallback.\n *\n * Precedence: .shipyard/.env > process.env\n * Only keys declared in .shipyard/.env are resolved from process.env.\n * Repo root .env is not part of the resolution chain.\n */\nexport const resolveEnv = (\n repoDir: string,\n): Effect.Effect<\n Record<string, string>,\n ConfigDirError,\n FileSystem.FileSystem\n> =>\n Effect.gen(function* () {\n const configDir = join(repoDir, CONFIG_DIR);\n const envPath = join(configDir, \".env\");\n yield* Effect.tryPromise({\n try: () =>\n assertNoSymlinkComponents(repoDir, envPath, \"environment file\"),\n catch: (e) =>\n new ConfigDirError({\n message: `Refusing symlinked environment path: ${e instanceof Error ? e.message : String(e)}`,\n }),\n });\n const shipyardEnv = yield* parseEnvFile(envPath);\n\n const result: Record<string, string> = {};\n for (const key of Object.keys(shipyardEnv)) {\n // A blank placeholder falls back to process.env, so callers can source\n // credentials from a host login for one invocation, e.g.\n // `GH_TOKEN=\"$(gh auth token)\" npx shipyard run`. Only keys declared in\n // .shipyard/.env are eligible for this fallback.\n const value = shipyardEnv[key] || process.env[key];\n if (value) {\n result[key] = value;\n }\n }\n\n return result;\n });\n","import { lstat, readdir, rm } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { CONFIG_DIR, LOGS_DIR } from \"./runtimeNames.js\";\n\n/** The default age threshold for automatic run-log purges. */\nexport const DEFAULT_LOG_RETENTION_DAYS = 8;\n\nconst LOG_DIRECTORY_PATTERN = /^(\\d{4})-(\\d{2})-(\\d{2})$/;\n\n/** Build the local calendar date directory used for default run logs. */\nexport const buildLogDirectoryName = (date: Date = new Date()): string => {\n if (Number.isNaN(date.getTime())) {\n throw new Error(\"Cannot build a log directory name from an invalid date.\");\n }\n const pad = (value: number): string => String(value).padStart(2, \"0\");\n return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;\n};\n\nconst parseLogDirectoryDate = (name: string): Date | undefined => {\n const match = LOG_DIRECTORY_PATTERN.exec(name);\n if (!match) return undefined;\n\n const year = Number(match[1]);\n const month = Number(match[2]);\n const day = Number(match[3]);\n const date = new Date(year, month - 1, day);\n return date.getFullYear() === year &&\n date.getMonth() === month - 1 &&\n date.getDate() === day\n ? date\n : undefined;\n};\n\nconst validateRetentionDays = (retentionDays: number): void => {\n if (!Number.isSafeInteger(retentionDays) || retentionDays < 0) {\n throw new Error(\"Log retention days must be a non-negative integer.\");\n }\n};\n\nexport interface PurgeRunLogsOptions {\n /** Host repository containing `.shipyard/logs/`. */\n readonly repoDir: string;\n /** Remove run logs strictly older than this many calendar days. Omit to remove every default run log. */\n readonly retentionDays?: number;\n /** Local time used to calculate the cutoff. Primarily useful for tests. */\n readonly now?: Date;\n}\n\nexport interface PurgeRunLogsResult {\n readonly logsDir: string;\n readonly retentionDays?: number;\n /** Dated directories on or after this local date are retained when age-based purging is used. */\n readonly cutoffDate?: string;\n readonly scannedDirectories: number;\n readonly removedCount: number;\n /** Directory names removed from `logsDir`, without the parent path. */\n readonly removedDirectories: readonly string[];\n /** Root-level log filenames removed from `logsDir`. */\n readonly removedFiles: readonly string[];\n}\n\n/**\n * Remove default run logs, either all of them or only those older than an\n * explicit retention threshold.\n *\n * Dated default run-log directories and regular root-level `.log` files inside\n * the managed logs directory are considered. Other files, malformed directory\n * names, and symlink entries are left alone.\n */\nexport const purgeRunLogs = async (\n options: PurgeRunLogsOptions,\n): Promise<PurgeRunLogsResult> => {\n const retentionDays = options.retentionDays;\n if (retentionDays !== undefined) validateRetentionDays(retentionDays);\n\n const now = options.now ?? new Date();\n if (retentionDays !== undefined && Number.isNaN(now.getTime())) {\n throw new Error(\"Cannot purge logs using an invalid date.\");\n }\n const cutoff =\n retentionDays === undefined\n ? undefined\n : new Date(\n now.getFullYear(),\n now.getMonth(),\n now.getDate() - retentionDays,\n );\n const cutoffDate =\n cutoff === undefined ? undefined : buildLogDirectoryName(cutoff);\n const logsDir = join(options.repoDir, CONFIG_DIR, LOGS_DIR);\n\n let entries;\n try {\n entries = await readdir(logsDir, { withFileTypes: true });\n } catch (error) {\n if (error instanceof Error && \"code\" in error && error.code === \"ENOENT\") {\n return {\n logsDir,\n ...(retentionDays === undefined ? {} : { retentionDays, cutoffDate }),\n scannedDirectories: 0,\n removedCount: 0,\n removedDirectories: [],\n removedFiles: [],\n };\n }\n throw error;\n }\n\n const removedDirectories: string[] = [];\n const removedFiles: string[] = [];\n let scannedDirectories = 0;\n for (const entry of entries) {\n const entryPath = join(logsDir, entry.name);\n if (entry.isFile() && entry.name.endsWith(\".log\")) {\n const file = await lstat(entryPath);\n if (file.isFile() && (cutoff === undefined || file.mtime < cutoff)) {\n await rm(entryPath, { force: true });\n removedFiles.push(entry.name);\n }\n continue;\n }\n if (!entry.isDirectory()) continue;\n const directoryDate = parseLogDirectoryDate(entry.name);\n if (directoryDate === undefined) continue;\n scannedDirectories += 1;\n if (cutoff !== undefined && directoryDate >= cutoff) continue;\n\n await rm(entryPath, { recursive: true, force: true });\n removedDirectories.push(entry.name);\n }\n\n return {\n logsDir,\n ...(retentionDays === undefined ? {} : { retentionDays, cutoffDate }),\n scannedDirectories,\n removedCount: removedDirectories.length + removedFiles.length,\n removedDirectories,\n removedFiles,\n };\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/ErrorHandler.ts","../src/modelConfig.ts","../src/EnvResolver.ts","../src/LogRetention.ts"],"names":["Effect","join"],"mappings":";;;;;;AAQO,IAAM,kBAAA,GAAqB,CAAC,KAAA,KAAgC;AACjE,EAAA,QAAQ,MAAM,IAAA;AAAM,IAClB,KAAK,WAAA;AACH,MAAA,OAAO,CAAA,2BAAA,EAA8B,KAAA,CAAM,OAAO,CAAA,GAAA,EAAM,MAAM,OAAO,CAA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AAA;AAAA,MAC9B;AACA,MAAA;AAAA,IACF;AACA,IAAA,IAAI,CAAC,KAAA,CAAM,WAAA,EAAY,EAAG;AAC1B,IAAA,MAAM,aAAA,GAAgB,qBAAA,CAAsB,KAAA,CAAM,IAAI,CAAA;AACtD,IAAA,IAAI,kBAAkB,MAAA,EAAW;AACjC,IAAA,kBAAA,IAAsB,CAAA;AACtB,IAAA,IAAI,MAAA,KAAW,MAAA,IAAa,aAAA,IAAiB,MAAA,EAAQ;AAErD,IAAA,MAAM,GAAG,SAAA,EAAW,EAAE,WAAW,IAAA,EAAM,KAAA,EAAO,MAAM,CAAA;AACpD,IAAA,kBAAA,CAAmB,IAAA,CAAK,MAAM,IAAI,CAAA;AAAA,EACpC;AAEA,EAAA,OAAO;AAAA,IACL,OAAA;AAAA,IACA,GAAI,aAAA,KAAkB,MAAA,GAAY,EAAC,GAAI,EAAE,eAAe,UAAA,EAAW;AAAA,IACnE,kBAAA;AAAA,IACA,YAAA,EAAc,kBAAA,CAAmB,MAAA,GAAS,YAAA,CAAa,MAAA;AAAA,IACvD,kBAAA;AAAA,IACA;AAAA,GACF;AACF","file":"chunk-56TDSWFU.js","sourcesContent":["import { Effect } from \"effect\";\nimport { Display } from \"./Display.js\";\nimport type { SandboxError } from \"./errors.js\";\n\n/**\n * Formats a tagged SandboxError into a user-friendly message with\n * context-specific hints about what went wrong and how to recover.\n */\nexport const formatErrorMessage = (error: SandboxError): string => {\n switch (error._tag) {\n case \"ExecError\":\n return `Command failed in sandbox (${error.command}): ${error.message}`;\n case \"ExecHostError\":\n return `Command failed on host (${error.command}): ${error.message}`;\n case \"CopyError\":\n return `File copy failed: ${error.message}`;\n case \"DockerError\":\n return `Docker operation failed: ${error.message}. Is Docker running?`;\n case \"SyncError\":\n return `Git sync failed: ${error.message}`;\n case \"WorktreeError\":\n return `Git worktree operation failed: ${error.message}`;\n case \"PromptError\":\n return `Failed to resolve prompt: ${error.message}`;\n case \"AgentError\":\n return `Agent invocation failed: ${error.message}`;\n case \"ConfigDirError\":\n return `${error.message}`;\n case \"InitError\":\n return `${error.message}`;\n case \"AgentIdleTimeoutError\":\n case \"WorktreeTimeoutError\":\n case \"ContainerStartTimeoutError\":\n case \"CopyToWorktreeTimeoutError\":\n case \"CopyToWorktreeError\":\n case \"SyncInTimeoutError\":\n case \"HookTimeoutError\":\n case \"GitSetupTimeoutError\":\n case \"PromptExpansionTimeoutError\":\n case \"CommitCollectionTimeoutError\":\n case \"MergeToHostTimeoutError\":\n case \"SessionCaptureError\":\n case \"CwdError\":\n return error.message;\n }\n};\n\nconst showErrorAndExit = (error: SandboxError) =>\n Effect.gen(function* () {\n const d = yield* Display;\n yield* d.status(formatErrorMessage(error), \"error\");\n return yield* Effect.sync(() => process.exit(1) as never);\n });\n\n/**\n * Wraps an effect so that any SandboxError is caught, displayed via the\n * Display service as an error-severity status message, then exits the process\n * with code 1. Non-SandboxError errors pass through unchanged.\n */\nexport const withFriendlyErrors = <A, E, R>(\n effect: Effect.Effect<A, E, R>,\n): Effect.Effect<A, Exclude<E, SandboxError>, R | Display> =>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n Effect.catchTags(effect as Effect.Effect<A, SandboxError, R>, {\n ExecError: showErrorAndExit,\n ExecHostError: showErrorAndExit,\n CopyError: showErrorAndExit,\n DockerError: showErrorAndExit,\n SyncError: showErrorAndExit,\n WorktreeError: showErrorAndExit,\n PromptError: showErrorAndExit,\n AgentError: showErrorAndExit,\n ConfigDirError: showErrorAndExit,\n InitError: showErrorAndExit,\n AgentIdleTimeoutError: showErrorAndExit,\n WorktreeTimeoutError: showErrorAndExit,\n ContainerStartTimeoutError: showErrorAndExit,\n CopyToWorktreeTimeoutError: showErrorAndExit,\n CopyToWorktreeError: showErrorAndExit,\n SyncInTimeoutError: showErrorAndExit,\n HookTimeoutError: showErrorAndExit,\n GitSetupTimeoutError: showErrorAndExit,\n PromptExpansionTimeoutError: showErrorAndExit,\n CommitCollectionTimeoutError: showErrorAndExit,\n MergeToHostTimeoutError: showErrorAndExit,\n SessionCaptureError: showErrorAndExit,\n CwdError: showErrorAndExit,\n }) as Effect.Effect<A, Exclude<E, SandboxError>, R | Display>;\n","/** Reasoning efforts accepted by the Codex CLI. */\nexport const CODEX_REASONING_EFFORTS = [\n \"low\",\n \"medium\",\n \"high\",\n \"xhigh\",\n \"max\",\n] as const;\n\nexport type CodexReasoningEffort = (typeof CODEX_REASONING_EFFORTS)[number];\n\n/** A model identifier plus the reasoning policy used for that model role. */\nexport interface CodexModelConfig {\n readonly model: string;\n readonly effort: CodexReasoningEffort;\n}\n\n/**\n * Default values for Shipyard's built-in Codex roles.\n *\n * Runtime environment variables override these defaults:\n * SHIPYARD_CODEX_ROUTINE_MODEL\n * SHIPYARD_CODEX_ROUTINE_REASONING_EFFORT\n * SHIPYARD_CODEX_STRONG_MODEL\n * SHIPYARD_CODEX_STRONG_REASONING_EFFORT\n *\n * Keep the defaults here so runtime providers, generated templates, and the\n * repository workflows all use the same role definitions.\n */\nconst DEFAULT_CODEX_MODELS = {\n routine: { model: \"gpt-5.6-luna\", effort: \"max\" },\n strong: { model: \"gpt-5.6-sol\", effort: \"max\" },\n} as const satisfies Record<string, CodexModelConfig>;\n\nconst readModel = (role: keyof typeof DEFAULT_CODEX_MODELS): string =>\n process.env[`SHIPYARD_CODEX_${role.toUpperCase()}_MODEL`]?.trim() ||\n DEFAULT_CODEX_MODELS[role].model;\n\nconst readEffort = (\n role: keyof typeof DEFAULT_CODEX_MODELS,\n): CodexReasoningEffort => {\n const envName = `SHIPYARD_CODEX_${role.toUpperCase()}_REASONING_EFFORT`;\n const value = process.env[envName]?.trim();\n if (!value) return DEFAULT_CODEX_MODELS[role].effort;\n if ((CODEX_REASONING_EFFORTS as readonly string[]).includes(value)) {\n return value as CodexReasoningEffort;\n }\n throw new Error(\n `${envName} must be one of ${CODEX_REASONING_EFFORTS.join(\", \")}; received \"${value}\"`,\n );\n};\n\nexport const CODEX_MODELS = {\n routine: {\n model: readModel(\"routine\"),\n effort: readEffort(\"routine\"),\n },\n strong: {\n model: readModel(\"strong\"),\n effort: readEffort(\"strong\"),\n },\n} as const satisfies Record<string, CodexModelConfig>;\n","import { FileSystem } from \"@effect/platform\";\nimport { Effect } from \"effect\";\nimport { join } from \"node:path\";\n\nimport { ConfigDirError } from \"./errors.js\";\nimport { assertNoSymlinkComponents } from \"./pathSecurity.js\";\nimport { CONFIG_DIR } from \"./runtimeNames.js\";\n\nconst parseEnvFile = (\n filePath: string,\n): Effect.Effect<Record<string, string>, never, FileSystem.FileSystem> =>\n Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const symlink = yield* fs.readLink(filePath).pipe(\n Effect.map(() => true),\n Effect.catchAll(() => Effect.succeed(false)),\n );\n // A repository-controlled symlink could redirect this read to a host\n // secret and then expose matching keys to the agent.\n if (symlink) return {};\n const content = yield* fs\n .readFileString(filePath)\n .pipe(Effect.catchAll(() => Effect.succeed(null)));\n if (content === null) return {};\n const vars: Record<string, string> = {};\n for (const line of content.split(\"\\n\")) {\n const trimmed = line.trim();\n if (!trimmed || trimmed.startsWith(\"#\")) continue;\n const eqIndex = trimmed.indexOf(\"=\");\n if (eqIndex === -1) continue;\n const key = trimmed.slice(0, eqIndex).trim();\n let value = trimmed.slice(eqIndex + 1).trim();\n const isDoubleQuoted =\n value.length >= 2 &&\n value[0] === '\"' &&\n value[value.length - 1] === '\"';\n const isSingleQuoted =\n value.length >= 2 &&\n value[0] === \"'\" &&\n value[value.length - 1] === \"'\";\n if (isDoubleQuoted || isSingleQuoted) {\n value = value.slice(1, -1);\n }\n if (isDoubleQuoted) {\n value = value.replace(/\\\\([nrt\\\\])/g, (_, ch: string) => {\n const escapes: Record<string, string> = {\n n: \"\\n\",\n r: \"\\r\",\n t: \"\\t\",\n \"\\\\\": \"\\\\\",\n };\n return escapes[ch] ?? ch;\n });\n }\n vars[key] = value;\n }\n return vars;\n });\n\n/**\n * Resolve all env vars from .env files with process.env fallback.\n *\n * Precedence: .shipyard/.env > process.env\n * Only keys declared in .shipyard/.env are resolved from process.env.\n * Repo root .env is not part of the resolution chain.\n */\nexport const resolveEnv = (\n repoDir: string,\n): Effect.Effect<\n Record<string, string>,\n ConfigDirError,\n FileSystem.FileSystem\n> =>\n Effect.gen(function* () {\n const configDir = join(repoDir, CONFIG_DIR);\n const envPath = join(configDir, \".env\");\n yield* Effect.tryPromise({\n try: () =>\n assertNoSymlinkComponents(repoDir, envPath, \"environment file\"),\n catch: (e) =>\n new ConfigDirError({\n message: `Refusing symlinked environment path: ${e instanceof Error ? e.message : String(e)}`,\n }),\n });\n const shipyardEnv = yield* parseEnvFile(envPath);\n\n const result: Record<string, string> = {};\n for (const key of Object.keys(shipyardEnv)) {\n // A blank placeholder falls back to process.env, so callers can source\n // credentials from a host login for one invocation, e.g.\n // `GH_TOKEN=\"$(gh auth token)\" npx shipyard run`. Only keys declared in\n // .shipyard/.env are eligible for this fallback.\n const value = shipyardEnv[key] || process.env[key];\n if (value) {\n result[key] = value;\n }\n }\n\n return result;\n });\n","import { lstat, readdir, rm } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { CONFIG_DIR, LOGS_DIR } from \"./runtimeNames.js\";\n\n/** The default age threshold for automatic run-log purges. */\nexport const DEFAULT_LOG_RETENTION_DAYS = 8;\n\nconst LOG_DIRECTORY_PATTERN = /^(\\d{4})-(\\d{2})-(\\d{2})$/;\n\n/** Build the local calendar date directory used for default run logs. */\nexport const buildLogDirectoryName = (date: Date = new Date()): string => {\n if (Number.isNaN(date.getTime())) {\n throw new Error(\"Cannot build a log directory name from an invalid date.\");\n }\n const pad = (value: number): string => String(value).padStart(2, \"0\");\n return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;\n};\n\nconst parseLogDirectoryDate = (name: string): Date | undefined => {\n const match = LOG_DIRECTORY_PATTERN.exec(name);\n if (!match) return undefined;\n\n const year = Number(match[1]);\n const month = Number(match[2]);\n const day = Number(match[3]);\n const date = new Date(year, month - 1, day);\n return date.getFullYear() === year &&\n date.getMonth() === month - 1 &&\n date.getDate() === day\n ? date\n : undefined;\n};\n\nconst validateRetentionDays = (retentionDays: number): void => {\n if (!Number.isSafeInteger(retentionDays) || retentionDays < 0) {\n throw new Error(\"Log retention days must be a non-negative integer.\");\n }\n};\n\nexport interface PurgeRunLogsOptions {\n /** Host repository containing `.shipyard/logs/`. */\n readonly repoDir: string;\n /** Remove run logs strictly older than this many calendar days. Omit to remove every default run log. */\n readonly retentionDays?: number;\n /** Local time used to calculate the cutoff. Primarily useful for tests. */\n readonly now?: Date;\n}\n\nexport interface PurgeRunLogsResult {\n readonly logsDir: string;\n readonly retentionDays?: number;\n /** Dated directories on or after this local date are retained when age-based purging is used. */\n readonly cutoffDate?: string;\n readonly scannedDirectories: number;\n readonly removedCount: number;\n /** Directory names removed from `logsDir`, without the parent path. */\n readonly removedDirectories: readonly string[];\n /** Root-level log filenames removed from `logsDir`. */\n readonly removedFiles: readonly string[];\n}\n\n/**\n * Remove default run logs, either all of them or only those older than an\n * explicit retention threshold.\n *\n * Dated default run-log directories and regular root-level `.log` files inside\n * the managed logs directory are considered. Other files, malformed directory\n * names, and symlink entries are left alone.\n */\nexport const purgeRunLogs = async (\n options: PurgeRunLogsOptions,\n): Promise<PurgeRunLogsResult> => {\n const retentionDays = options.retentionDays;\n if (retentionDays !== undefined) validateRetentionDays(retentionDays);\n\n const now = options.now ?? new Date();\n if (retentionDays !== undefined && Number.isNaN(now.getTime())) {\n throw new Error(\"Cannot purge logs using an invalid date.\");\n }\n const cutoff =\n retentionDays === undefined\n ? undefined\n : new Date(\n now.getFullYear(),\n now.getMonth(),\n now.getDate() - retentionDays,\n );\n const cutoffDate =\n cutoff === undefined ? undefined : buildLogDirectoryName(cutoff);\n const logsDir = join(options.repoDir, CONFIG_DIR, LOGS_DIR);\n\n let entries;\n try {\n entries = await readdir(logsDir, { withFileTypes: true });\n } catch (error) {\n if (error instanceof Error && \"code\" in error && error.code === \"ENOENT\") {\n return {\n logsDir,\n ...(retentionDays === undefined ? {} : { retentionDays, cutoffDate }),\n scannedDirectories: 0,\n removedCount: 0,\n removedDirectories: [],\n removedFiles: [],\n };\n }\n throw error;\n }\n\n const removedDirectories: string[] = [];\n const removedFiles: string[] = [];\n let scannedDirectories = 0;\n for (const entry of entries) {\n const entryPath = join(logsDir, entry.name);\n if (entry.isFile() && entry.name.endsWith(\".log\")) {\n const file = await lstat(entryPath);\n if (file.isFile() && (cutoff === undefined || file.mtime < cutoff)) {\n await rm(entryPath, { force: true });\n removedFiles.push(entry.name);\n }\n continue;\n }\n if (!entry.isDirectory()) continue;\n const directoryDate = parseLogDirectoryDate(entry.name);\n if (directoryDate === undefined) continue;\n scannedDirectories += 1;\n if (cutoff !== undefined && directoryDate >= cutoff) continue;\n\n await rm(entryPath, { recursive: true, force: true });\n removedDirectories.push(entry.name);\n }\n\n return {\n logsDir,\n ...(retentionDays === undefined ? {} : { retentionDays, cutoffDate }),\n scannedDirectories,\n removedCount: removedDirectories.length + removedFiles.length,\n removedDirectories,\n removedFiles,\n };\n};\n"]}
|