@snappedly-tools/shipyard 0.2.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/LICENSE +59 -0
- package/NOTICE +4 -0
- package/README.md +197 -0
- package/dist/MountConfig-bZoCs4Dd.d.ts +26 -0
- package/dist/SandboxProvider-KeFp_nju.d.ts +257 -0
- package/dist/chunk-4VDXZY7T.js +27624 -0
- package/dist/chunk-4VDXZY7T.js.map +1 -0
- package/dist/chunk-BU6XJFJ2.js +90 -0
- package/dist/chunk-BU6XJFJ2.js.map +1 -0
- package/dist/chunk-CP6YEQKU.js +42 -0
- package/dist/chunk-CP6YEQKU.js.map +1 -0
- package/dist/chunk-OAHPDSOJ.js +407 -0
- package/dist/chunk-OAHPDSOJ.js.map +1 -0
- package/dist/chunk-SRUH232X.js +26712 -0
- package/dist/chunk-SRUH232X.js.map +1 -0
- package/dist/chunk-YVJHSJUW.js +127 -0
- package/dist/chunk-YVJHSJUW.js.map +1 -0
- package/dist/index.d.ts +2780 -0
- package/dist/index.js +9843 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +20475 -0
- package/dist/main.js.map +1 -0
- package/dist/sandboxes/docker.d.ts +125 -0
- package/dist/sandboxes/docker.js +9 -0
- package/dist/sandboxes/docker.js.map +1 -0
- package/dist/sandboxes/no-sandbox.d.ts +37 -0
- package/dist/sandboxes/no-sandbox.js +7 -0
- package/dist/sandboxes/no-sandbox.js.map +1 -0
- package/dist/sandboxes/vercel.d.ts +104 -0
- package/dist/sandboxes/vercel.js +188 -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/implement-prompt.md +62 -0
- package/dist/templates/parallel-planner/main.mts +205 -0
- package/dist/templates/parallel-planner/merge-prompt.md +26 -0
- package/dist/templates/parallel-planner/plan-prompt.md +37 -0
- package/dist/templates/parallel-planner/template.json +4 -0
- package/dist/templates/parallel-planner-with-review/CODING_STANDARDS.md +27 -0
- package/dist/templates/parallel-planner-with-review/implement-prompt.md +62 -0
- package/dist/templates/parallel-planner-with-review/main.mts +227 -0
- package/dist/templates/parallel-planner-with-review/merge-prompt.md +26 -0
- package/dist/templates/parallel-planner-with-review/plan-prompt.md +37 -0
- package/dist/templates/parallel-planner-with-review/review-prompt.md +55 -0
- package/dist/templates/parallel-planner-with-review/template.json +4 -0
- package/dist/templates/sequential-reviewer/CODING_STANDARDS.md +27 -0
- package/dist/templates/sequential-reviewer/implement-prompt.md +53 -0
- package/dist/templates/sequential-reviewer/main.mts +120 -0
- package/dist/templates/sequential-reviewer/review-prompt.md +55 -0
- package/dist/templates/sequential-reviewer/template.json +4 -0
- package/dist/templates/simple-loop/main.mts +51 -0
- package/dist/templates/simple-loop/prompt.md +53 -0
- package/dist/templates/simple-loop/template.json +4 -0
- package/dist/workflow/coordinator/migrations/001_initial.sql +131 -0
- package/package.json +103 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { I as IsolatedSandboxProvider } from '../SandboxProvider-KeFp_nju.js';
|
|
2
|
+
import { M as MountConfig } from '../MountConfig-bZoCs4Dd.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Shared mount utilities for the Docker sandbox provider.
|
|
6
|
+
*
|
|
7
|
+
* Handles host/sandbox path resolution, tilde expansion, user mount
|
|
8
|
+
* validation, image naming, and Windows path normalization.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* SELinux volume label suffix applied to bind mounts.
|
|
13
|
+
*
|
|
14
|
+
* - `"z"` — shared label. No-op on non-SELinux systems.
|
|
15
|
+
* - `"Z"` — private label; only this container can access the mount.
|
|
16
|
+
* - `false` — disable labeling entirely.
|
|
17
|
+
*/
|
|
18
|
+
type SelinuxLabel = "z" | "Z" | false;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Derive the default image name from the repo directory.
|
|
22
|
+
* Returns `shipyard:<dir-name>` where dir-name is the last path segment,
|
|
23
|
+
* lowercased and sanitized for image tag rules.
|
|
24
|
+
*
|
|
25
|
+
* Handles both POSIX (`/`) and Windows (`\`) path separators.
|
|
26
|
+
*/
|
|
27
|
+
declare const defaultImageName: (repoDir: string) => string;
|
|
28
|
+
|
|
29
|
+
interface DockerOptions {
|
|
30
|
+
/** Docker image name (default: derived from repo directory name). */
|
|
31
|
+
readonly imageName?: string;
|
|
32
|
+
/**
|
|
33
|
+
* The UID of the `agent` user inside the container image (default: host UID via `process.getuid()`, or 1000).
|
|
34
|
+
*
|
|
35
|
+
* Must match the UID baked into the image at build time. Used as the `--user` flag value
|
|
36
|
+
* and checked against the image's configured UID in the pre-flight diagnostic.
|
|
37
|
+
*/
|
|
38
|
+
readonly containerUid?: number;
|
|
39
|
+
/**
|
|
40
|
+
* The GID of the `agent` user inside the container image (default: host GID via `process.getgid()`, or 1000).
|
|
41
|
+
*
|
|
42
|
+
* Must match the GID baked into the image at build time. Used as the `--user` flag value.
|
|
43
|
+
*/
|
|
44
|
+
readonly containerGid?: number;
|
|
45
|
+
/**
|
|
46
|
+
* SELinux volume label suffix applied to bind mounts.
|
|
47
|
+
*
|
|
48
|
+
* - `"z"` — shared label (default). No-op on non-SELinux systems.
|
|
49
|
+
* - `"Z"` — private label; only this container can access the mount.
|
|
50
|
+
* - `false` — disable labeling entirely.
|
|
51
|
+
*/
|
|
52
|
+
readonly selinuxLabel?: SelinuxLabel;
|
|
53
|
+
/**
|
|
54
|
+
* Additional host directories to bind-mount into the sandbox.
|
|
55
|
+
*
|
|
56
|
+
* Each entry specifies a `hostPath` (tilde-expanded) and `sandboxPath`.
|
|
57
|
+
* If `hostPath` does not exist, sandbox creation fails with a clear error.
|
|
58
|
+
*/
|
|
59
|
+
readonly mounts?: readonly MountConfig[];
|
|
60
|
+
/** Environment variables injected by this provider. Merged at launch time with env resolver and agent provider env. */
|
|
61
|
+
readonly env?: Record<string, string>;
|
|
62
|
+
/**
|
|
63
|
+
* Docker network(s) to attach the container to.
|
|
64
|
+
*
|
|
65
|
+
* - `"my-network"` → `--network my-network`
|
|
66
|
+
* - `["net1", "net2"]` → `--network net1 --network net2`
|
|
67
|
+
*
|
|
68
|
+
* When omitted, Docker's default bridge network is used.
|
|
69
|
+
*/
|
|
70
|
+
readonly network?: string | readonly string[];
|
|
71
|
+
/**
|
|
72
|
+
* Supplementary groups to add the container user to, via `--group-add`.
|
|
73
|
+
*
|
|
74
|
+
* Accepts group names or numeric GIDs:
|
|
75
|
+
*
|
|
76
|
+
* - `["docker"]` → `--group-add docker`
|
|
77
|
+
* - `[999]` → `--group-add 999`
|
|
78
|
+
* - `["docker", 999]` → `--group-add docker --group-add 999`
|
|
79
|
+
*
|
|
80
|
+
* Useful for granting access to a bind-mounted Docker socket (Docker-outside-of-Docker).
|
|
81
|
+
* When omitted, no `--group-add` flags are added.
|
|
82
|
+
*/
|
|
83
|
+
readonly groups?: readonly (string | number)[];
|
|
84
|
+
/**
|
|
85
|
+
* Host devices to expose to the container, via `--device`.
|
|
86
|
+
*
|
|
87
|
+
* Each entry is a full device spec in `host[:container[:permissions]]` form:
|
|
88
|
+
*
|
|
89
|
+
* - `["/dev/kvm"]` → `--device /dev/kvm`
|
|
90
|
+
* - `["/dev/sda:/dev/xvda:rwm"]` → `--device /dev/sda:/dev/xvda:rwm`
|
|
91
|
+
* - `["/dev/kvm", "/dev/fuse"]` → `--device /dev/kvm --device /dev/fuse`
|
|
92
|
+
*
|
|
93
|
+
* When omitted, no `--device` flags are added.
|
|
94
|
+
*/
|
|
95
|
+
readonly devices?: readonly string[];
|
|
96
|
+
/**
|
|
97
|
+
* Maximum number of characters of streamed `exec` output retained per stream
|
|
98
|
+
* (stdout and stderr) when an `onLine` callback is supplied (default: 64KiB).
|
|
99
|
+
*
|
|
100
|
+
* Output is delivered live to `onLine` regardless; this only bounds the tail
|
|
101
|
+
* returned in `ExecResult`, preventing a long-running agent's output from
|
|
102
|
+
* overflowing V8's max string length and crashing the run.
|
|
103
|
+
*/
|
|
104
|
+
readonly maxOutputTailChars?: number;
|
|
105
|
+
/**
|
|
106
|
+
* Limit the CPU resources available to the container, via `--cpus`.
|
|
107
|
+
*
|
|
108
|
+
* Maps directly to `docker run --cpus`. Accepts fractional values:
|
|
109
|
+
*
|
|
110
|
+
* - `2` → `--cpus 2` (at most 2 CPUs)
|
|
111
|
+
* - `1.5` → `--cpus 1.5` (at most 1.5 CPUs)
|
|
112
|
+
*
|
|
113
|
+
* When omitted, no `--cpus` flag is added and the container is unconstrained.
|
|
114
|
+
*/
|
|
115
|
+
readonly cpus?: number;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Create a Docker sandbox provider.
|
|
119
|
+
*
|
|
120
|
+
* The returned provider creates Docker containers with isolated repository and Git storage.
|
|
121
|
+
* Changes are transferred through git bundle and validated sync-out.
|
|
122
|
+
*/
|
|
123
|
+
declare const docker: (options?: DockerOptions) => IsolatedSandboxProvider;
|
|
124
|
+
|
|
125
|
+
export { type DockerOptions, defaultImageName, docker };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
export { docker } from '../chunk-OAHPDSOJ.js';
|
|
3
|
+
export { defaultImageName } from '../chunk-4VDXZY7T.js';
|
|
4
|
+
import '../chunk-CP6YEQKU.js';
|
|
5
|
+
import '../chunk-BU6XJFJ2.js';
|
|
6
|
+
|
|
7
|
+
createRequire(import.meta.url);
|
|
8
|
+
//# sourceMappingURL=docker.js.map
|
|
9
|
+
//# sourceMappingURL=docker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"docker.js"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { N as NoSandboxProvider } from '../SandboxProvider-KeFp_nju.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* No-sandbox provider — runs the agent directly on the host with no container isolation.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* import { noSandbox } from "@snappedly-tools/shipyard/sandboxes/no-sandbox";
|
|
8
|
+
* await run({ agent: codex(CODEX_MODELS.routine), sandbox: noSandbox(), prompt: "..." });
|
|
9
|
+
*
|
|
10
|
+
* Accepted by `run()`, `interactive()`, and `createSandbox()`. It skips
|
|
11
|
+
* container isolation entirely and does not pass
|
|
12
|
+
* `--dangerously-skip-permissions` to the agent.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
interface NoSandboxOptions {
|
|
16
|
+
/** Environment variables injected by this provider. Merged at launch time. */
|
|
17
|
+
readonly env?: Record<string, string>;
|
|
18
|
+
/**
|
|
19
|
+
* Maximum number of characters of streamed `exec` output retained per stream
|
|
20
|
+
* (stdout and stderr) when an `onLine` callback is supplied (default: 64KiB).
|
|
21
|
+
*
|
|
22
|
+
* Output is delivered live to `onLine` regardless; this only bounds the tail
|
|
23
|
+
* returned in `ExecResult`, preventing a long-running agent's output from
|
|
24
|
+
* overflowing V8's max string length and crashing the run.
|
|
25
|
+
*/
|
|
26
|
+
readonly maxOutputTailChars?: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create a no-sandbox provider.
|
|
30
|
+
*
|
|
31
|
+
* The returned provider runs the agent directly on the host. All three
|
|
32
|
+
* branch strategies are supported (head, merge-to-head, branch),
|
|
33
|
+
* defaulting to head.
|
|
34
|
+
*/
|
|
35
|
+
declare const noSandbox: (options?: NoSandboxOptions) => NoSandboxProvider;
|
|
36
|
+
|
|
37
|
+
export { type NoSandboxOptions, noSandbox };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"no-sandbox.js"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { I as IsolatedSandboxProvider } from '../SandboxProvider-KeFp_nju.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Vercel isolated sandbox provider — wraps `@vercel/sandbox` into a SandboxProvider.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* import { vercel } from "@snappedly-tools/shipyard/sandboxes/vercel";
|
|
8
|
+
* await run({ agent: codex(CODEX_MODELS.routine), sandbox: vercel() });
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Options for creating a Vercel sandbox provider.
|
|
13
|
+
*
|
|
14
|
+
* All `@vercel/sandbox` `Sandbox.create()` options are accepted as pass-through,
|
|
15
|
+
* plus Shipyard-specific options for auth and branch strategy.
|
|
16
|
+
*/
|
|
17
|
+
interface VercelOptions {
|
|
18
|
+
/**
|
|
19
|
+
* Vercel access token.
|
|
20
|
+
*
|
|
21
|
+
* Falls back to the SDK's default auth behavior, which reads
|
|
22
|
+
* `VERCEL_OIDC_TOKEN` (recommended for Vercel-hosted environments) or
|
|
23
|
+
* `VERCEL_TOKEN` from the environment.
|
|
24
|
+
*/
|
|
25
|
+
readonly token?: string;
|
|
26
|
+
/**
|
|
27
|
+
* The source of the sandbox (git repo, tarball, or snapshot).
|
|
28
|
+
* Omit to start an empty sandbox.
|
|
29
|
+
*/
|
|
30
|
+
readonly source?: {
|
|
31
|
+
type: "git";
|
|
32
|
+
url: string;
|
|
33
|
+
depth?: number;
|
|
34
|
+
revision?: string;
|
|
35
|
+
username?: string;
|
|
36
|
+
password?: string;
|
|
37
|
+
} | {
|
|
38
|
+
type: "tarball";
|
|
39
|
+
url: string;
|
|
40
|
+
} | {
|
|
41
|
+
type: "snapshot";
|
|
42
|
+
snapshotId: string;
|
|
43
|
+
};
|
|
44
|
+
/** Array of port numbers to expose from the sandbox (up to 4). */
|
|
45
|
+
readonly ports?: number[];
|
|
46
|
+
/** Timeout in milliseconds before the sandbox auto-terminates. */
|
|
47
|
+
readonly timeout?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Resources to allocate to the sandbox.
|
|
50
|
+
* Each vCPU gets 2048 MB of memory.
|
|
51
|
+
*/
|
|
52
|
+
readonly resources?: {
|
|
53
|
+
vcpus: number;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* The runtime of the sandbox (e.g. `"node24"`, `"node22"`, `"python3.13"`).
|
|
57
|
+
* Defaults to `"node24"`.
|
|
58
|
+
*/
|
|
59
|
+
readonly runtime?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Network policy for the sandbox.
|
|
62
|
+
* Defaults to full internet access if not specified.
|
|
63
|
+
*/
|
|
64
|
+
readonly networkPolicy?: Record<string, unknown>;
|
|
65
|
+
/**
|
|
66
|
+
* Vercel project ID to associate sandbox operations with.
|
|
67
|
+
*/
|
|
68
|
+
readonly projectId?: string;
|
|
69
|
+
/**
|
|
70
|
+
* Vercel team ID to associate sandbox operations with.
|
|
71
|
+
*/
|
|
72
|
+
readonly teamId?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Timeout in milliseconds (alias for `timeout`, kept for discoverability).
|
|
75
|
+
*/
|
|
76
|
+
readonly timeoutMs?: number;
|
|
77
|
+
/**
|
|
78
|
+
* Sandbox template shorthand (e.g. `"node-22"`).
|
|
79
|
+
* Maps to the `runtime` option.
|
|
80
|
+
*/
|
|
81
|
+
readonly template?: string;
|
|
82
|
+
/** Environment variables injected by this provider. Merged at launch time with env resolver and agent provider env. */
|
|
83
|
+
readonly env?: Record<string, string>;
|
|
84
|
+
/**
|
|
85
|
+
* Maximum number of characters of streamed `exec` output retained per stream
|
|
86
|
+
* (stdout and stderr) when an `onLine` callback is supplied (default: 64KiB).
|
|
87
|
+
*
|
|
88
|
+
* Output is delivered live to `onLine` regardless; this only bounds the tail
|
|
89
|
+
* returned in `ExecResult`, preventing a long-running agent's output from
|
|
90
|
+
* overflowing V8's max string length and crashing the run.
|
|
91
|
+
*/
|
|
92
|
+
readonly maxOutputTailChars?: number;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Create a Vercel isolated sandbox provider.
|
|
96
|
+
*
|
|
97
|
+
* The returned provider creates Vercel Firecracker microVM sandboxes via
|
|
98
|
+
* the `@vercel/sandbox` SDK. Each sandbox is ephemeral — one sandbox per run.
|
|
99
|
+
*
|
|
100
|
+
* Requires `@vercel/sandbox` to be installed as a peer dependency.
|
|
101
|
+
*/
|
|
102
|
+
declare const vercel: (options?: VercelOptions) => IsolatedSandboxProvider;
|
|
103
|
+
|
|
104
|
+
export { type VercelOptions, vercel };
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { createIsolatedSandboxProvider, shellQuote } from '../chunk-CP6YEQKU.js';
|
|
3
|
+
import { MAX_TAIL_CHARS, OutputByteCounter, BoundedTail } from '../chunk-BU6XJFJ2.js';
|
|
4
|
+
import { execFileSync } from 'child_process';
|
|
5
|
+
import { mkdir, lstat, writeFile, chmod, mkdtemp, readFile, rm } from 'fs/promises';
|
|
6
|
+
import { randomUUID } from 'crypto';
|
|
7
|
+
import { tmpdir } from 'os';
|
|
8
|
+
import { dirname, join } from 'path';
|
|
9
|
+
import { Writable } from 'stream';
|
|
10
|
+
|
|
11
|
+
createRequire(import.meta.url);
|
|
12
|
+
var VERCEL_REPO_PATH = "/vercel/sandbox/workspace";
|
|
13
|
+
var vercel = (options) => createIsolatedSandboxProvider({
|
|
14
|
+
name: "vercel",
|
|
15
|
+
env: options?.env,
|
|
16
|
+
create: async (createOptions) => {
|
|
17
|
+
const maxOutputTailChars = options?.maxOutputTailChars ?? MAX_TAIL_CHARS;
|
|
18
|
+
const { Sandbox } = await import('@vercel/sandbox');
|
|
19
|
+
const createParams = {};
|
|
20
|
+
if (options?.source) createParams.source = options.source;
|
|
21
|
+
if (options?.ports) createParams.ports = options.ports;
|
|
22
|
+
if (options?.resources) createParams.resources = options.resources;
|
|
23
|
+
if (options?.networkPolicy)
|
|
24
|
+
createParams.networkPolicy = options.networkPolicy;
|
|
25
|
+
const resolvedRuntime = options?.runtime ?? options?.template;
|
|
26
|
+
if (resolvedRuntime) createParams.runtime = resolvedRuntime;
|
|
27
|
+
const timeoutValue = options?.timeout ?? options?.timeoutMs;
|
|
28
|
+
if (timeoutValue !== void 0) createParams.timeout = timeoutValue;
|
|
29
|
+
createParams.env = createOptions.env;
|
|
30
|
+
if (options?.token) createParams.token = options.token;
|
|
31
|
+
if (options?.projectId) createParams.projectId = options.projectId;
|
|
32
|
+
if (options?.teamId) createParams.teamId = options.teamId;
|
|
33
|
+
const sandbox = await Sandbox.create(
|
|
34
|
+
createParams
|
|
35
|
+
);
|
|
36
|
+
await sandbox.mkDir(VERCEL_REPO_PATH);
|
|
37
|
+
const handle = {
|
|
38
|
+
worktreePath: VERCEL_REPO_PATH,
|
|
39
|
+
exec: async (command, opts) => {
|
|
40
|
+
if (opts?.onLine || opts?.maxOutputBytes !== void 0) {
|
|
41
|
+
const onLine = opts?.onLine ?? (() => {
|
|
42
|
+
});
|
|
43
|
+
const outputLimit = opts?.maxOutputBytes === void 0 ? void 0 : new OutputByteCounter(opts.maxOutputBytes);
|
|
44
|
+
const tailChars = opts?.maxOutputBytes ?? maxOutputTailChars;
|
|
45
|
+
const stdoutTail = new BoundedTail(tailChars, "\n");
|
|
46
|
+
const stderrTail = new BoundedTail(tailChars, "");
|
|
47
|
+
let outputLimitError;
|
|
48
|
+
const checkOutputLimit = (chunk) => {
|
|
49
|
+
if (outputLimit === void 0 || outputLimitError !== void 0) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
outputLimit.add(chunk);
|
|
53
|
+
if (outputLimit.exceeded) {
|
|
54
|
+
outputLimitError = new Error(
|
|
55
|
+
`Sandbox command output exceeded ${opts.maxOutputBytes} bytes`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
let partial = "";
|
|
60
|
+
const stdoutWritable = new Writable({
|
|
61
|
+
write(chunk, _encoding, callback) {
|
|
62
|
+
checkOutputLimit(chunk.toString());
|
|
63
|
+
if (outputLimitError !== void 0) {
|
|
64
|
+
callback(outputLimitError);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const text = partial + chunk.toString();
|
|
68
|
+
const lines = text.split("\n");
|
|
69
|
+
partial = lines.pop() ?? "";
|
|
70
|
+
for (const line of lines) {
|
|
71
|
+
stdoutTail.push(line);
|
|
72
|
+
onLine(line);
|
|
73
|
+
}
|
|
74
|
+
callback();
|
|
75
|
+
},
|
|
76
|
+
final(callback) {
|
|
77
|
+
if (partial) {
|
|
78
|
+
stdoutTail.push(partial);
|
|
79
|
+
onLine(partial);
|
|
80
|
+
partial = "";
|
|
81
|
+
}
|
|
82
|
+
callback();
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
const stderrWritable = new Writable({
|
|
86
|
+
write(chunk, _encoding, callback) {
|
|
87
|
+
checkOutputLimit(chunk.toString());
|
|
88
|
+
if (outputLimitError !== void 0) {
|
|
89
|
+
callback(outputLimitError);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
stderrTail.push(chunk.toString());
|
|
93
|
+
callback();
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
const result2 = await sandbox.runCommand({
|
|
97
|
+
cmd: "sh",
|
|
98
|
+
args: ["-c", command],
|
|
99
|
+
cwd: opts?.cwd ?? VERCEL_REPO_PATH,
|
|
100
|
+
stdout: stdoutWritable,
|
|
101
|
+
stderr: stderrWritable,
|
|
102
|
+
...opts?.sudo ? { sudo: true } : {}
|
|
103
|
+
});
|
|
104
|
+
if (outputLimitError !== void 0) throw outputLimitError;
|
|
105
|
+
return {
|
|
106
|
+
stdout: stdoutTail.toString(),
|
|
107
|
+
stderr: stderrTail.toString(),
|
|
108
|
+
exitCode: result2.exitCode
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const result = await sandbox.runCommand({
|
|
112
|
+
cmd: "sh",
|
|
113
|
+
args: ["-c", command],
|
|
114
|
+
cwd: opts?.cwd ?? VERCEL_REPO_PATH,
|
|
115
|
+
...opts?.sudo ? { sudo: true } : {}
|
|
116
|
+
});
|
|
117
|
+
const stdout = await result.stdout();
|
|
118
|
+
const stderr = await result.stderr();
|
|
119
|
+
return {
|
|
120
|
+
stdout,
|
|
121
|
+
stderr,
|
|
122
|
+
exitCode: result.exitCode
|
|
123
|
+
};
|
|
124
|
+
},
|
|
125
|
+
copyIn: async (hostPath, sandboxPath) => {
|
|
126
|
+
const info = await lstat(hostPath);
|
|
127
|
+
if (info.isSymbolicLink()) {
|
|
128
|
+
throw new Error(`Refusing to copy a symbolic link: ${hostPath}`);
|
|
129
|
+
}
|
|
130
|
+
if (info.isDirectory()) {
|
|
131
|
+
const tempDir = await mkdtemp(join(tmpdir(), "shipyard-copyin-"));
|
|
132
|
+
const tarPath = join(tempDir, "archive.tar.gz");
|
|
133
|
+
try {
|
|
134
|
+
execFileSync("tar", ["-czf", tarPath, "-C", hostPath, "."]);
|
|
135
|
+
const tarContent = await readFile(tarPath);
|
|
136
|
+
const sandboxTarPath = `/tmp/shipyard-copyin-${randomUUID()}.tar.gz`;
|
|
137
|
+
await sandbox.writeFiles([
|
|
138
|
+
{ path: sandboxTarPath, content: tarContent }
|
|
139
|
+
]);
|
|
140
|
+
await sandbox.runCommand({
|
|
141
|
+
cmd: "sh",
|
|
142
|
+
args: [
|
|
143
|
+
"-c",
|
|
144
|
+
`mkdir -p ${shellQuote(sandboxPath)} && tar -xzf ${shellQuote(sandboxTarPath)} -C ${shellQuote(sandboxPath)} && rm -f ${shellQuote(sandboxTarPath)}`
|
|
145
|
+
]
|
|
146
|
+
});
|
|
147
|
+
} finally {
|
|
148
|
+
await rm(tempDir, { recursive: true, force: true }).catch(
|
|
149
|
+
() => {
|
|
150
|
+
}
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
} else {
|
|
154
|
+
const content = await readFile(hostPath);
|
|
155
|
+
await sandbox.writeFiles([{ path: sandboxPath, content }]);
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
copyFileOut: async (sandboxPath, hostPath) => {
|
|
159
|
+
const buffer = await sandbox.readFileToBuffer({
|
|
160
|
+
path: sandboxPath
|
|
161
|
+
});
|
|
162
|
+
if (!buffer) {
|
|
163
|
+
throw new Error(`File not found in Vercel sandbox: ${sandboxPath}`);
|
|
164
|
+
}
|
|
165
|
+
await mkdir(dirname(hostPath), { recursive: true, mode: 448 });
|
|
166
|
+
try {
|
|
167
|
+
if ((await lstat(hostPath)).isSymbolicLink()) {
|
|
168
|
+
throw new Error(
|
|
169
|
+
`Refusing to overwrite symbolic link: ${hostPath}`
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
} catch (error) {
|
|
173
|
+
if (error.code !== "ENOENT") throw error;
|
|
174
|
+
}
|
|
175
|
+
await writeFile(hostPath, buffer, { mode: 384 });
|
|
176
|
+
await chmod(hostPath, 384);
|
|
177
|
+
},
|
|
178
|
+
close: async () => {
|
|
179
|
+
await sandbox.stop();
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
return handle;
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
export { vercel };
|
|
187
|
+
//# sourceMappingURL=vercel.js.map
|
|
188
|
+
//# sourceMappingURL=vercel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/sandboxes/vercel.ts"],"names":["result"],"mappings":";;;;;;;;;;;AAoCA,IAAM,gBAAA,GAAmB,2BAAA;AA+GlB,IAAM,MAAA,GAAS,CAAC,OAAA,KACrB,6BAAA,CAA8B;AAAA,EAC5B,IAAA,EAAM,QAAA;AAAA,EACN,KAAK,OAAA,EAAS,GAAA;AAAA,EACd,MAAA,EAAQ,OAAO,aAAA,KAAkD;AAC/D,IAAA,MAAM,kBAAA,GAAqB,SAAS,kBAAA,IAAsB,cAAA;AAE1D,IAAA,MAAM,EAAE,OAAA,EAAQ,GAAI,MAAM,OAAO,iBAAiB,CAAA;AAElD,IAAA,MAAM,eAAwC,EAAC;AAG/C,IAAA,IAAI,OAAA,EAAS,MAAA,EA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,QAAQ,CAAA,EAAG,EAAE,SAAA,EAAW,IAAA,EAAM,IAAA,EAAM,GAAA,EAAO,CAAA;AAC/D,QAAA,IAAI;AACF,UAAA,IAAA,CAAK,MAAM,KAAA,CAAM,QAAQ,CAAA,EAAG,gBAAe,EAAG;AAC5C,YAAA,MAAM,IAAI,KAAA;AAAA,cACR,wCAAwC,QAAQ,CAAA;AAAA,aAClD;AAAA,UACF;AAAA,QACF,SAAS,KAAA,EAAO;AACd,UAAA,IAAK,KAAA,CAAgC,IAAA,KAAS,QAAA,EAAU,MAAM,KAAA;AAAA,QAChE;AACA,QAAA,MAAM,UAAU,QAAA,EAAU,MAAA,EAAQ,EAAE,IAAA,EAAM,KAAO,CAAA;AACjD,QAAA,MAAM,KAAA,CAAM,UAAU,GAAK,CAAA;AAAA,MAC7B,CAAA;AAAA,MAEA,OAAO,YAA2B;AAChC,QAAA,MAAM,QAAQ,IAAA,EAAK;AAAA,MACrB;AAAA,KACF;AAEA,IAAA,OAAO,MAAA;AAAA,EACT;AACF,CAAC","file":"vercel.js","sourcesContent":["/**\n * Vercel isolated sandbox provider — wraps `@vercel/sandbox` into a SandboxProvider.\n *\n * Usage:\n * import { vercel } from \"@snappedly-tools/shipyard/sandboxes/vercel\";\n * await run({ agent: codex(CODEX_MODELS.routine), sandbox: vercel() });\n */\n\nimport { execFileSync } from \"node:child_process\";\nimport {\n lstat,\n chmod,\n mkdir,\n mkdtemp,\n readFile,\n rm,\n writeFile,\n} from \"node:fs/promises\";\nimport { randomUUID } from \"node:crypto\";\nimport { tmpdir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\nimport { Writable } from \"node:stream\";\nimport {\n createIsolatedSandboxProvider,\n type ExecResult,\n type IsolatedSandboxHandle,\n type IsolatedSandboxProvider,\n} from \"../SandboxProvider.js\";\nimport {\n BoundedTail,\n MAX_TAIL_CHARS,\n OutputByteCounter,\n} from \"../boundedTail.js\";\nimport { shellQuote } from \"../shellQuote.js\";\n\n/** Worktree path inside the Vercel sandbox. */\nconst VERCEL_REPO_PATH = \"/vercel/sandbox/workspace\";\n\n/**\n * Options for creating a Vercel sandbox provider.\n *\n * All `@vercel/sandbox` `Sandbox.create()` options are accepted as pass-through,\n * plus Shipyard-specific options for auth and branch strategy.\n */\nexport interface VercelOptions {\n /**\n * Vercel access token.\n *\n * Falls back to the SDK's default auth behavior, which reads\n * `VERCEL_OIDC_TOKEN` (recommended for Vercel-hosted environments) or\n * `VERCEL_TOKEN` from the environment.\n */\n readonly token?: string;\n\n // ---- Pass-through @vercel/sandbox Sandbox.create() options ----\n\n /**\n * The source of the sandbox (git repo, tarball, or snapshot).\n * Omit to start an empty sandbox.\n */\n readonly source?:\n | {\n type: \"git\";\n url: string;\n depth?: number;\n revision?: string;\n username?: string;\n password?: string;\n }\n | {\n type: \"tarball\";\n url: string;\n }\n | {\n type: \"snapshot\";\n snapshotId: string;\n };\n\n /** Array of port numbers to expose from the sandbox (up to 4). */\n readonly ports?: number[];\n\n /** Timeout in milliseconds before the sandbox auto-terminates. */\n readonly timeout?: number;\n\n /**\n * Resources to allocate to the sandbox.\n * Each vCPU gets 2048 MB of memory.\n */\n readonly resources?: {\n vcpus: number;\n };\n\n /**\n * The runtime of the sandbox (e.g. `\"node24\"`, `\"node22\"`, `\"python3.13\"`).\n * Defaults to `\"node24\"`.\n */\n readonly runtime?: string;\n\n /**\n * Network policy for the sandbox.\n * Defaults to full internet access if not specified.\n */\n readonly networkPolicy?: Record<string, unknown>;\n\n /**\n * Vercel project ID to associate sandbox operations with.\n */\n readonly projectId?: string;\n\n /**\n * Vercel team ID to associate sandbox operations with.\n */\n readonly teamId?: string;\n\n /**\n * Timeout in milliseconds (alias for `timeout`, kept for discoverability).\n */\n readonly timeoutMs?: number;\n\n /**\n * Sandbox template shorthand (e.g. `\"node-22\"`).\n * Maps to the `runtime` option.\n */\n readonly template?: string;\n\n /** Environment variables injected by this provider. Merged at launch time with env resolver and agent provider env. */\n readonly env?: Record<string, string>;\n\n /**\n * Maximum number of characters of streamed `exec` output retained per stream\n * (stdout and stderr) when an `onLine` callback is supplied (default: 64KiB).\n *\n * Output is delivered live to `onLine` regardless; this only bounds the tail\n * returned in `ExecResult`, preventing a long-running agent's output from\n * overflowing V8's max string length and crashing the run.\n */\n readonly maxOutputTailChars?: number;\n}\n\n/**\n * Create a Vercel isolated sandbox provider.\n *\n * The returned provider creates Vercel Firecracker microVM sandboxes via\n * the `@vercel/sandbox` SDK. Each sandbox is ephemeral — one sandbox per run.\n *\n * Requires `@vercel/sandbox` to be installed as a peer dependency.\n */\nexport const vercel = (options?: VercelOptions): IsolatedSandboxProvider =>\n createIsolatedSandboxProvider({\n name: \"vercel\",\n env: options?.env,\n create: async (createOptions): Promise<IsolatedSandboxHandle> => {\n const maxOutputTailChars = options?.maxOutputTailChars ?? MAX_TAIL_CHARS;\n // Dynamic import so the peer dependency is only loaded at runtime\n const { Sandbox } = await import(\"@vercel/sandbox\");\n\n const createParams: Record<string, unknown> = {};\n\n // Pass through SDK options\n if (options?.source) createParams.source = options.source;\n if (options?.ports) createParams.ports = options.ports;\n if (options?.resources) createParams.resources = options.resources;\n if (options?.networkPolicy)\n createParams.networkPolicy = options.networkPolicy;\n // runtime takes precedence over the template convenience alias\n const resolvedRuntime = options?.runtime ?? options?.template;\n if (resolvedRuntime) createParams.runtime = resolvedRuntime;\n\n // Timeout: prefer explicit timeout, fall back to timeoutMs alias\n const timeoutValue = options?.timeout ?? options?.timeoutMs;\n if (timeoutValue !== undefined) createParams.timeout = timeoutValue;\n\n // Merge provider env with Shipyard env\n createParams.env = createOptions.env;\n\n // Auth: pass token and team/project IDs if provided\n if (options?.token) createParams.token = options.token;\n if (options?.projectId) createParams.projectId = options.projectId;\n if (options?.teamId) createParams.teamId = options.teamId;\n\n const sandbox = await Sandbox.create(\n createParams as Parameters<typeof Sandbox.create>[0],\n );\n\n // Ensure worktree directory exists\n await sandbox.mkDir(VERCEL_REPO_PATH);\n\n const handle: IsolatedSandboxHandle = {\n worktreePath: VERCEL_REPO_PATH,\n\n exec: async (\n command: string,\n opts?: {\n onLine?: (line: string) => void;\n cwd?: string;\n sudo?: boolean;\n maxOutputBytes?: number;\n },\n ): Promise<ExecResult> => {\n if (opts?.onLine || opts?.maxOutputBytes !== undefined) {\n const onLine = opts?.onLine ?? (() => {});\n const outputLimit =\n opts?.maxOutputBytes === undefined\n ? undefined\n : new OutputByteCounter(opts.maxOutputBytes);\n const tailChars = opts?.maxOutputBytes ?? maxOutputTailChars;\n const stdoutTail = new BoundedTail(tailChars, \"\\n\");\n const stderrTail = new BoundedTail(tailChars, \"\");\n let outputLimitError: Error | undefined;\n const checkOutputLimit = (chunk: string): void => {\n if (outputLimit === undefined || outputLimitError !== undefined) {\n return;\n }\n outputLimit.add(chunk);\n if (outputLimit.exceeded) {\n outputLimitError = new Error(\n `Sandbox command output exceeded ${opts.maxOutputBytes} bytes`,\n );\n }\n };\n let partial = \"\";\n\n const stdoutWritable = new Writable({\n write(chunk, _encoding, callback) {\n checkOutputLimit(chunk.toString());\n if (outputLimitError !== undefined) {\n callback(outputLimitError);\n return;\n }\n const text = partial + chunk.toString();\n const lines = text.split(\"\\n\");\n partial = lines.pop() ?? \"\";\n for (const line of lines) {\n stdoutTail.push(line);\n onLine(line);\n }\n callback();\n },\n final(callback) {\n if (partial) {\n stdoutTail.push(partial);\n onLine(partial);\n partial = \"\";\n }\n callback();\n },\n });\n\n const stderrWritable = new Writable({\n write(chunk, _encoding, callback) {\n checkOutputLimit(chunk.toString());\n if (outputLimitError !== undefined) {\n callback(outputLimitError);\n return;\n }\n stderrTail.push(chunk.toString());\n callback();\n },\n });\n\n const result = await sandbox.runCommand({\n cmd: \"sh\",\n args: [\"-c\", command],\n cwd: opts?.cwd ?? VERCEL_REPO_PATH,\n stdout: stdoutWritable,\n stderr: stderrWritable,\n ...(opts?.sudo ? { sudo: true } : {}),\n });\n\n if (outputLimitError !== undefined) throw outputLimitError;\n\n return {\n stdout: stdoutTail.toString(),\n stderr: stderrTail.toString(),\n exitCode: result.exitCode,\n };\n }\n\n const result = await sandbox.runCommand({\n cmd: \"sh\",\n args: [\"-c\", command],\n cwd: opts?.cwd ?? VERCEL_REPO_PATH,\n ...(opts?.sudo ? { sudo: true } : {}),\n });\n\n const stdout = await result.stdout();\n const stderr = await result.stderr();\n\n return {\n stdout,\n stderr,\n exitCode: result.exitCode,\n };\n },\n\n copyIn: async (\n hostPath: string,\n sandboxPath: string,\n ): Promise<void> => {\n const info = await lstat(hostPath);\n if (info.isSymbolicLink()) {\n throw new Error(`Refusing to copy a symbolic link: ${hostPath}`);\n }\n if (info.isDirectory()) {\n const tempDir = await mkdtemp(join(tmpdir(), \"shipyard-copyin-\"));\n const tarPath = join(tempDir, \"archive.tar.gz\");\n try {\n execFileSync(\"tar\", [\"-czf\", tarPath, \"-C\", hostPath, \".\"]);\n const tarContent = await readFile(tarPath);\n const sandboxTarPath = `/tmp/shipyard-copyin-${randomUUID()}.tar.gz`;\n await sandbox.writeFiles([\n { path: sandboxTarPath, content: tarContent },\n ]);\n await sandbox.runCommand({\n cmd: \"sh\",\n args: [\n \"-c\",\n `mkdir -p ${shellQuote(sandboxPath)} && tar -xzf ${shellQuote(sandboxTarPath)} -C ${shellQuote(sandboxPath)} && rm -f ${shellQuote(sandboxTarPath)}`,\n ],\n });\n } finally {\n await rm(tempDir, { recursive: true, force: true }).catch(\n () => {},\n );\n }\n } else {\n const content = await readFile(hostPath);\n await sandbox.writeFiles([{ path: sandboxPath, content }]);\n }\n },\n\n copyFileOut: async (\n sandboxPath: string,\n hostPath: string,\n ): Promise<void> => {\n const buffer = await sandbox.readFileToBuffer({\n path: sandboxPath,\n });\n if (!buffer) {\n throw new Error(`File not found in Vercel sandbox: ${sandboxPath}`);\n }\n await mkdir(dirname(hostPath), { recursive: true, mode: 0o700 });\n try {\n if ((await lstat(hostPath)).isSymbolicLink()) {\n throw new Error(\n `Refusing to overwrite symbolic link: ${hostPath}`,\n );\n }\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n }\n await writeFile(hostPath, buffer, { mode: 0o600 });\n await chmod(hostPath, 0o600);\n },\n\n close: async (): Promise<void> => {\n await sandbox.stop();\n },\n };\n\n return handle;\n },\n });\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CODEX_MODELS, run, codex } from "@snappedly-tools/shipyard";
|
|
2
|
+
import { docker } from "@snappedly-tools/shipyard/sandboxes/docker";
|
|
3
|
+
|
|
4
|
+
// Blank template: customize this to build your own orchestration.
|
|
5
|
+
// Generated entrypoint: .shipyard/main.mts
|
|
6
|
+
// Run this with: npx shipyard run
|
|
7
|
+
// Or add to package.json scripts: "shipyard": "shipyard run"
|
|
8
|
+
|
|
9
|
+
await run({
|
|
10
|
+
agent: codex(CODEX_MODELS.routine),
|
|
11
|
+
sandbox: docker(),
|
|
12
|
+
promptFile: "./.shipyard/prompt.md",
|
|
13
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Context
|
|
2
|
+
|
|
3
|
+
<!-- Use !`command` to pull in dynamic context. Commands run inside the sandbox. -->
|
|
4
|
+
<!-- Example: !`git log --oneline -10` or !`{{LIST_TASKS_COMMAND}}` -->
|
|
5
|
+
|
|
6
|
+
# Task
|
|
7
|
+
|
|
8
|
+
<!-- Describe what the agent should do. -->
|
|
9
|
+
|
|
10
|
+
# Done
|
|
11
|
+
|
|
12
|
+
<!-- When the task is complete, output <promise>COMPLETE</promise> to signal early termination. -->
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# TASK
|
|
2
|
+
|
|
3
|
+
Fix issue {{TASK_ID}}: {{ISSUE_TITLE}}
|
|
4
|
+
|
|
5
|
+
Pull in the issue using `{{VIEW_TASK_COMMAND}}`. If it has a parent PRD, pull that in too.
|
|
6
|
+
|
|
7
|
+
Only work on the issue specified.
|
|
8
|
+
|
|
9
|
+
Work on branch {{BRANCH}}. Make commits and run tests.
|
|
10
|
+
|
|
11
|
+
# CONTEXT
|
|
12
|
+
|
|
13
|
+
Here are the last 10 commits:
|
|
14
|
+
|
|
15
|
+
<recent-commits>
|
|
16
|
+
|
|
17
|
+
!`git log -n 10 --format="%H%n%ad%n%B---" --date=short`
|
|
18
|
+
|
|
19
|
+
</recent-commits>
|
|
20
|
+
|
|
21
|
+
# EXPLORATION
|
|
22
|
+
|
|
23
|
+
Explore the repo and fill your context window with relevant information that will allow you to complete the task.
|
|
24
|
+
|
|
25
|
+
Pay extra attention to test files that touch the relevant parts of the code.
|
|
26
|
+
|
|
27
|
+
# EXECUTION
|
|
28
|
+
|
|
29
|
+
If applicable, use RGR to complete the task.
|
|
30
|
+
|
|
31
|
+
1. RED: write one test
|
|
32
|
+
2. GREEN: write the implementation to pass that test
|
|
33
|
+
3. REPEAT until done
|
|
34
|
+
4. REFACTOR the code
|
|
35
|
+
|
|
36
|
+
# FEEDBACK LOOPS
|
|
37
|
+
|
|
38
|
+
Before committing, read the repository's configured feedback-loop contract and run every applicable check for this change. Use the configured static check and focused behavior tests when they exist; include formatting, build, or broader checks when the contract or change requires them. Fix failures before committing.
|
|
39
|
+
|
|
40
|
+
# COMMIT
|
|
41
|
+
|
|
42
|
+
Make a git commit. The commit message must:
|
|
43
|
+
|
|
44
|
+
1. Start with `RALPH:` prefix
|
|
45
|
+
2. Include task completed + PRD reference
|
|
46
|
+
3. Key decisions made
|
|
47
|
+
4. Files changed
|
|
48
|
+
5. Blockers or notes for next iteration
|
|
49
|
+
|
|
50
|
+
Keep it concise.
|
|
51
|
+
|
|
52
|
+
# THE ISSUE
|
|
53
|
+
|
|
54
|
+
If the task is not complete, leave a comment on the issue with what was done.
|
|
55
|
+
|
|
56
|
+
Do not close the issue - this will be done later.
|
|
57
|
+
|
|
58
|
+
Once complete, output <promise>COMPLETE</promise>.
|
|
59
|
+
|
|
60
|
+
# FINAL RULES
|
|
61
|
+
|
|
62
|
+
ONLY WORK ON A SINGLE TASK.
|