@ai-hero/sandcastle 0.0.1
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 +284 -0
- package/dist/AgentProvider.d.ts +8 -0
- package/dist/AgentProvider.d.ts.map +1 -0
- package/dist/AgentProvider.js +60 -0
- package/dist/AgentProvider.js.map +1 -0
- package/dist/Config.d.ts +35 -0
- package/dist/Config.d.ts.map +1 -0
- package/dist/Config.js +56 -0
- package/dist/Config.js.map +1 -0
- package/dist/CopyToSandbox.d.ts +8 -0
- package/dist/CopyToSandbox.d.ts.map +1 -0
- package/dist/CopyToSandbox.js +32 -0
- package/dist/CopyToSandbox.js.map +1 -0
- package/dist/Display.d.ts +52 -0
- package/dist/Display.d.ts.map +1 -0
- package/dist/Display.js +132 -0
- package/dist/Display.js.map +1 -0
- package/dist/DockerLifecycle.d.ts +37 -0
- package/dist/DockerLifecycle.d.ts.map +1 -0
- package/dist/DockerLifecycle.js +109 -0
- package/dist/DockerLifecycle.js.map +1 -0
- package/dist/DockerSandbox.d.ts +6 -0
- package/dist/DockerSandbox.d.ts.map +1 -0
- package/dist/DockerSandbox.js +122 -0
- package/dist/DockerSandbox.js.map +1 -0
- package/dist/EnvResolver.d.ts +11 -0
- package/dist/EnvResolver.d.ts.map +1 -0
- package/dist/EnvResolver.js +43 -0
- package/dist/EnvResolver.js.map +1 -0
- package/dist/ErrorHandler.d.ts +15 -0
- package/dist/ErrorHandler.d.ts.map +1 -0
- package/dist/ErrorHandler.js +58 -0
- package/dist/ErrorHandler.js.map +1 -0
- package/dist/FilesystemSandbox.d.ts +6 -0
- package/dist/FilesystemSandbox.d.ts.map +1 -0
- package/dist/FilesystemSandbox.js +83 -0
- package/dist/FilesystemSandbox.js.map +1 -0
- package/dist/InitService.d.ts +11 -0
- package/dist/InitService.d.ts.map +1 -0
- package/dist/InitService.js +111 -0
- package/dist/InitService.js.map +1 -0
- package/dist/Orchestrator.d.ts +49 -0
- package/dist/Orchestrator.d.ts.map +1 -0
- package/dist/Orchestrator.js +155 -0
- package/dist/Orchestrator.js.map +1 -0
- package/dist/PromptArgumentSubstitution.d.ts +6 -0
- package/dist/PromptArgumentSubstitution.d.ts.map +1 -0
- package/dist/PromptArgumentSubstitution.js +33 -0
- package/dist/PromptArgumentSubstitution.js.map +1 -0
- package/dist/PromptPreprocessor.d.ts +7 -0
- package/dist/PromptPreprocessor.d.ts.map +1 -0
- package/dist/PromptPreprocessor.js +34 -0
- package/dist/PromptPreprocessor.js.map +1 -0
- package/dist/PromptResolver.d.ts +9 -0
- package/dist/PromptResolver.d.ts.map +1 -0
- package/dist/PromptResolver.js +26 -0
- package/dist/PromptResolver.js.map +1 -0
- package/dist/RecoveryMessage.d.ts +15 -0
- package/dist/RecoveryMessage.d.ts.map +1 -0
- package/dist/RecoveryMessage.js +81 -0
- package/dist/RecoveryMessage.js.map +1 -0
- package/dist/Sandbox.d.ts +23 -0
- package/dist/Sandbox.d.ts.map +1 -0
- package/dist/Sandbox.js +5 -0
- package/dist/Sandbox.js.map +1 -0
- package/dist/SandboxFactory.d.ts +56 -0
- package/dist/SandboxFactory.d.ts.map +1 -0
- package/dist/SandboxFactory.js +219 -0
- package/dist/SandboxFactory.js.map +1 -0
- package/dist/SandboxLifecycle.d.ts +32 -0
- package/dist/SandboxLifecycle.d.ts.map +1 -0
- package/dist/SandboxLifecycle.js +152 -0
- package/dist/SandboxLifecycle.js.map +1 -0
- package/dist/SyncService.d.ts +20 -0
- package/dist/SyncService.d.ts.map +1 -0
- package/dist/SyncService.js +504 -0
- package/dist/SyncService.js.map +1 -0
- package/dist/TokenResolver.d.ts +6 -0
- package/dist/TokenResolver.d.ts.map +1 -0
- package/dist/TokenResolver.js +43 -0
- package/dist/TokenResolver.js.map +1 -0
- package/dist/WorktreeManager.d.ts +42 -0
- package/dist/WorktreeManager.d.ts.map +1 -0
- package/dist/WorktreeManager.js +170 -0
- package/dist/WorktreeManager.js.map +1 -0
- package/dist/cli.d.ts +22 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +217 -0
- package/dist/cli.js.map +1 -0
- package/dist/errors.d.ts +95 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +35 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +3 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +16 -0
- package/dist/main.js.map +1 -0
- package/dist/run.d.ts +91 -0
- package/dist/run.d.ts.map +1 -0
- package/dist/run.js +155 -0
- package/dist/run.js.map +1 -0
- package/dist/templates/blank/main.ts +9 -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.ts +200 -0
- package/dist/templates/parallel-planner/merge-prompt.md +22 -0
- package/dist/templates/parallel-planner/plan-prompt.md +33 -0
- package/dist/templates/parallel-planner/template.json +4 -0
- package/dist/templates/sequential-reviewer/implement-prompt.md +62 -0
- package/dist/templates/sequential-reviewer/main.ts +102 -0
- package/dist/templates/sequential-reviewer/review-prompt.md +43 -0
- package/dist/templates/sequential-reviewer/template.json +4 -0
- package/dist/templates/simple-loop/main.ts +37 -0
- package/dist/templates/simple-loop/prompt.md +51 -0
- package/dist/templates/simple-loop/template.json +4 -0
- package/dist/templates.d.ts +2 -0
- package/dist/templates.d.ts.map +1 -0
- package/dist/templates.js +26 -0
- package/dist/templates.js.map +1 -0
- package/dist/terminalCleanup.d.ts +30 -0
- package/dist/terminalCleanup.d.ts.map +1 -0
- package/dist/terminalCleanup.js +37 -0
- package/dist/terminalCleanup.js.map +1 -0
- package/dist/testSandbox.d.ts +8 -0
- package/dist/testSandbox.d.ts.map +1 -0
- package/dist/testSandbox.js +101 -0
- package/dist/testSandbox.js.map +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { ExecError } from "./errors.js";
|
|
3
|
+
import { type ExecResult, Sandbox, type SandboxError, type SandboxService } from "./Sandbox.js";
|
|
4
|
+
export declare const execOk: (sandbox: SandboxService, command: string, options?: {
|
|
5
|
+
cwd?: string | undefined;
|
|
6
|
+
} | undefined) => Effect.Effect<ExecResult, ExecError, never>;
|
|
7
|
+
export declare const runHooks: (hooks: readonly {
|
|
8
|
+
readonly command: string;
|
|
9
|
+
}[] | undefined, options?: {
|
|
10
|
+
cwd?: string | undefined;
|
|
11
|
+
} | undefined) => Effect.Effect<void, ExecError, Sandbox>;
|
|
12
|
+
export declare const syncIn: (hostRepoDir: string, sandboxRepoDir: string, options?: {
|
|
13
|
+
branch?: string | undefined;
|
|
14
|
+
} | undefined) => Effect.Effect<{
|
|
15
|
+
branch: string;
|
|
16
|
+
}, SandboxError, Sandbox>;
|
|
17
|
+
export declare const syncOut: (hostRepoDir: string, sandboxRepoDir: string, baseHead: string, options?: {
|
|
18
|
+
branch?: string | undefined;
|
|
19
|
+
} | undefined) => Effect.Effect<void, SandboxError, Sandbox>;
|
|
20
|
+
//# sourceMappingURL=SyncService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SyncService.d.ts","sourceRoot":"","sources":["../src/SyncService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAehC,OAAO,EAAE,SAAS,EAA4B,MAAM,aAAa,CAAC;AAClE,OAAO,EACL,KAAK,UAAU,EACf,OAAO,EACP,KAAK,YAAY,EACjB,KAAK,cAAc,EACpB,MAAM,cAAc,CAAC;AA4BtB,eAAO,MAAM,MAAM;;6DAchB,CAAC;AAEJ,eAAO,MAAM,QAAQ;;;;yDAUjB,CAAC;AAEL,eAAO,MAAM,MAAM;;;;yBA0Kf,CAAC;AAEL,eAAO,MAAM,OAAO;;4DA2BhB,CAAC"}
|
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { execFile } from "node:child_process";
|
|
3
|
+
import { copyFile, mkdir, mkdtemp, readdir, readFile, rm, stat, } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join, relative } from "node:path";
|
|
6
|
+
import { buildRecoveryMessage } from "./RecoveryMessage.js";
|
|
7
|
+
import { ExecError, ExecHostError, SyncError } from "./errors.js";
|
|
8
|
+
import { Sandbox, } from "./Sandbox.js";
|
|
9
|
+
const execHost = (command, cwd) => Effect.async((resume) => {
|
|
10
|
+
execFile("sh", ["-c", command], { cwd, maxBuffer: 10 * 1024 * 1024 }, (error, stdout, stderr) => {
|
|
11
|
+
if (error) {
|
|
12
|
+
resume(Effect.fail(new ExecHostError({
|
|
13
|
+
command,
|
|
14
|
+
message: `${command}: ${stderr?.toString() || error.message}`,
|
|
15
|
+
})));
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
resume(Effect.succeed(stdout.toString()));
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
export const execOk = (sandbox, command, options) => Effect.flatMap(sandbox.exec(command, options), (result) => result.exitCode !== 0
|
|
23
|
+
? Effect.fail(new ExecError({
|
|
24
|
+
command,
|
|
25
|
+
message: `Command failed (exit ${result.exitCode}): ${command}\n${result.stderr}`,
|
|
26
|
+
}))
|
|
27
|
+
: Effect.succeed(result));
|
|
28
|
+
export const runHooks = (hooks, options) => Effect.gen(function* () {
|
|
29
|
+
if (!hooks || hooks.length === 0)
|
|
30
|
+
return;
|
|
31
|
+
const sandbox = yield* Sandbox;
|
|
32
|
+
for (const hook of hooks) {
|
|
33
|
+
yield* execOk(sandbox, hook.command, options);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
export const syncIn = (hostRepoDir, sandboxRepoDir, options) => Effect.gen(function* () {
|
|
37
|
+
const sandbox = yield* Sandbox;
|
|
38
|
+
// Get current branch from host
|
|
39
|
+
const hostBranch = (yield* execHost("git rev-parse --abbrev-ref HEAD", hostRepoDir)).trim();
|
|
40
|
+
// The branch to check out in the sandbox
|
|
41
|
+
const branch = options?.branch ?? hostBranch;
|
|
42
|
+
// Create git bundle on host
|
|
43
|
+
const bundleDir = yield* Effect.promise(() => mkdtemp(join(tmpdir(), "sandcastle-bundle-")));
|
|
44
|
+
const bundleHostPath = join(bundleDir, "repo.bundle");
|
|
45
|
+
yield* execHost(`git bundle create "${bundleHostPath}" --all`, hostRepoDir);
|
|
46
|
+
// Detect if --branch target exists on the host
|
|
47
|
+
const branchExistsOnHost = branch !== hostBranch
|
|
48
|
+
? yield* Effect.map(Effect.either(execHost(`git rev-parse --verify "refs/heads/${branch}"`, hostRepoDir)), (either) => either._tag === "Right")
|
|
49
|
+
: true; // hostBranch always exists
|
|
50
|
+
// Create temp dir in sandbox for the bundle
|
|
51
|
+
const sandboxTmpDir = (yield* execOk(sandbox, "mktemp -d -t sandcastle-XXXXXX")).stdout.trim();
|
|
52
|
+
const bundleSandboxPath = `${sandboxTmpDir}/repo.bundle`;
|
|
53
|
+
// Copy bundle into sandbox
|
|
54
|
+
yield* sandbox.copyIn(bundleHostPath, bundleSandboxPath);
|
|
55
|
+
// Check if sandbox repo already initialized
|
|
56
|
+
const gitCheck = yield* sandbox.exec(`test -d "${sandboxRepoDir}/.git" && echo yes || echo no`);
|
|
57
|
+
const repoExists = gitCheck.stdout.trim() === "yes";
|
|
58
|
+
// Determine the ref to fetch and sync to
|
|
59
|
+
const fetchRef = branchExistsOnHost ? branch : hostBranch;
|
|
60
|
+
const isNewBranch = !branchExistsOnHost;
|
|
61
|
+
if (repoExists) {
|
|
62
|
+
// Fetch bundle into temp ref, reset to match host
|
|
63
|
+
yield* execOk(sandbox, `git fetch "${bundleSandboxPath}" "${fetchRef}:refs/sandcastle/sync" --force`, { cwd: sandboxRepoDir });
|
|
64
|
+
if (isNewBranch) {
|
|
65
|
+
// Create new branch from host HEAD
|
|
66
|
+
yield* execOk(sandbox, `git checkout -B "${branch}" refs/sandcastle/sync`, { cwd: sandboxRepoDir });
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
yield* execOk(sandbox, `git checkout -B "${branch}" refs/sandcastle/sync`, { cwd: sandboxRepoDir });
|
|
70
|
+
yield* execOk(sandbox, "git reset --hard refs/sandcastle/sync", {
|
|
71
|
+
cwd: sandboxRepoDir,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
yield* execOk(sandbox, "git clean -fdx -e node_modules", {
|
|
75
|
+
cwd: sandboxRepoDir,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
// Clone from bundle
|
|
80
|
+
yield* execOk(sandbox, `git clone "${bundleSandboxPath}" "${sandboxRepoDir}"`);
|
|
81
|
+
if (branchExistsOnHost) {
|
|
82
|
+
yield* execOk(sandbox, `git checkout "${branch}"`, {
|
|
83
|
+
cwd: sandboxRepoDir,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
yield* execOk(sandbox, `git checkout "${hostBranch}"`, {
|
|
88
|
+
cwd: sandboxRepoDir,
|
|
89
|
+
});
|
|
90
|
+
// Create new branch from host HEAD
|
|
91
|
+
yield* execOk(sandbox, `git checkout -b "${branch}"`, {
|
|
92
|
+
cwd: sandboxRepoDir,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// Configure remotes from host
|
|
97
|
+
const hostRemotes = (yield* execHost("git remote -v", hostRepoDir)).trim();
|
|
98
|
+
if (hostRemotes.length > 0) {
|
|
99
|
+
// Parse unique remote names and their fetch URLs
|
|
100
|
+
const remotes = new Map();
|
|
101
|
+
for (const line of hostRemotes.split("\n")) {
|
|
102
|
+
const match = line.match(/^(\S+)\t(\S+)\s+\(fetch\)$/);
|
|
103
|
+
if (match) {
|
|
104
|
+
remotes.set(match[1], match[2]);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// Get existing sandbox remotes
|
|
108
|
+
const sandboxRemotes = (yield* execOk(sandbox, "git remote", {
|
|
109
|
+
cwd: sandboxRepoDir,
|
|
110
|
+
})).stdout
|
|
111
|
+
.trim()
|
|
112
|
+
.split("\n")
|
|
113
|
+
.filter((r) => r.length > 0);
|
|
114
|
+
for (const [name, url] of remotes) {
|
|
115
|
+
if (sandboxRemotes.includes(name)) {
|
|
116
|
+
yield* execOk(sandbox, `git remote set-url "${name}" "${url}"`, {
|
|
117
|
+
cwd: sandboxRepoDir,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
yield* execOk(sandbox, `git remote add "${name}" "${url}"`, {
|
|
122
|
+
cwd: sandboxRepoDir,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// Remove sandbox remotes that don't exist on host
|
|
127
|
+
for (const name of sandboxRemotes) {
|
|
128
|
+
if (!remotes.has(name)) {
|
|
129
|
+
yield* execOk(sandbox, `git remote remove "${name}"`, {
|
|
130
|
+
cwd: sandboxRepoDir,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// Clean up temp files
|
|
136
|
+
yield* sandbox.exec(`rm -rf "${sandboxTmpDir}"`);
|
|
137
|
+
yield* Effect.promise(() => rm(bundleDir, { recursive: true }));
|
|
138
|
+
// Verify sync succeeded — compare against the ref we synced to
|
|
139
|
+
const expectedHead = (yield* execHost(`git rev-parse "refs/heads/${fetchRef}"`, hostRepoDir)).trim();
|
|
140
|
+
const sandboxHead = (yield* execOk(sandbox, "git rev-parse HEAD", {
|
|
141
|
+
cwd: sandboxRepoDir,
|
|
142
|
+
})).stdout.trim();
|
|
143
|
+
if (expectedHead !== sandboxHead) {
|
|
144
|
+
yield* Effect.fail(new SyncError({
|
|
145
|
+
message: `HEAD mismatch after sync: host=${expectedHead} sandbox=${sandboxHead}`,
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
return { branch };
|
|
149
|
+
});
|
|
150
|
+
export const syncOut = (hostRepoDir, sandboxRepoDir, baseHead, options) => Effect.gen(function* () {
|
|
151
|
+
const sandbox = yield* Sandbox;
|
|
152
|
+
// Determine if we need worktree-based sync
|
|
153
|
+
const targetBranch = options?.branch;
|
|
154
|
+
const hostBranch = targetBranch
|
|
155
|
+
? (yield* execHost("git rev-parse --abbrev-ref HEAD", hostRepoDir)).trim()
|
|
156
|
+
: undefined;
|
|
157
|
+
const useWorktree = targetBranch != null && targetBranch !== hostBranch;
|
|
158
|
+
if (useWorktree) {
|
|
159
|
+
yield* syncOutViaWorktree(sandbox, hostRepoDir, sandboxRepoDir, baseHead, targetBranch);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
yield* syncOutDirect(sandbox, hostRepoDir, sandboxRepoDir, baseHead);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
/** Format a timestamp as YYYYMMDD-HHMMSS */
|
|
166
|
+
const formatTimestamp = (date) => {
|
|
167
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
168
|
+
return (`${date.getFullYear()}${pad(date.getMonth() + 1)}${pad(date.getDate())}-` +
|
|
169
|
+
`${pad(date.getHours())}${pad(date.getMinutes())}${pad(date.getSeconds())}`);
|
|
170
|
+
};
|
|
171
|
+
/** Create a unique timestamped directory under .sandcastle/patches/ */
|
|
172
|
+
const createPatchDir = async (hostRepoDir) => {
|
|
173
|
+
const base = formatTimestamp(new Date());
|
|
174
|
+
const patchesDir = join(hostRepoDir, ".sandcastle", "patches");
|
|
175
|
+
await mkdir(patchesDir, { recursive: true });
|
|
176
|
+
// Ensure uniqueness by appending a counter if the dir already exists
|
|
177
|
+
let dir = join(patchesDir, base);
|
|
178
|
+
let counter = 0;
|
|
179
|
+
while (true) {
|
|
180
|
+
try {
|
|
181
|
+
await mkdir(dir);
|
|
182
|
+
return dir;
|
|
183
|
+
}
|
|
184
|
+
catch (e) {
|
|
185
|
+
if (e.code === "EEXIST") {
|
|
186
|
+
counter++;
|
|
187
|
+
dir = join(patchesDir, `${base}-${counter}`);
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
throw e;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
/** Eagerly save all patch artifacts to .sandcastle/patches/<timestamp>/ */
|
|
196
|
+
const saveArtifacts = (sandbox, hostRepoDir, sandboxRepoDir, baseHead) => Effect.gen(function* () {
|
|
197
|
+
const patchDir = yield* Effect.promise(() => createPatchDir(hostRepoDir));
|
|
198
|
+
let hasCommits = false;
|
|
199
|
+
let hasDiff = false;
|
|
200
|
+
let hasUntracked = false;
|
|
201
|
+
// --- 1. Save committed patches ---
|
|
202
|
+
const sandboxHead = (yield* execOk(sandbox, "git rev-parse HEAD", {
|
|
203
|
+
cwd: sandboxRepoDir,
|
|
204
|
+
})).stdout.trim();
|
|
205
|
+
if (sandboxHead !== baseHead) {
|
|
206
|
+
const countResult = yield* execOk(sandbox, `git rev-list "${baseHead}..HEAD" --count`, { cwd: sandboxRepoDir });
|
|
207
|
+
const commitCount = parseInt(countResult.stdout.trim(), 10);
|
|
208
|
+
if (commitCount > 0) {
|
|
209
|
+
hasCommits = true;
|
|
210
|
+
const hostPatchDir = yield* generateAndCopyPatches(sandbox, sandboxRepoDir, baseHead);
|
|
211
|
+
// Move patch files into the persistent directory
|
|
212
|
+
const patchFiles = (yield* Effect.promise(() => readdir(hostPatchDir))).filter((f) => f.endsWith(".patch"));
|
|
213
|
+
for (const file of patchFiles) {
|
|
214
|
+
yield* Effect.promise(() => copyFile(join(hostPatchDir, file), join(patchDir, file)));
|
|
215
|
+
}
|
|
216
|
+
yield* Effect.promise(() => rm(hostPatchDir, { recursive: true }));
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
// --- 2. Save uncommitted diff ---
|
|
220
|
+
const diffCheck = yield* sandbox.exec("git diff HEAD --quiet", {
|
|
221
|
+
cwd: sandboxRepoDir,
|
|
222
|
+
});
|
|
223
|
+
if (diffCheck.exitCode !== 0) {
|
|
224
|
+
hasDiff = true;
|
|
225
|
+
const sandboxDiffDir = (yield* execOk(sandbox, "mktemp -d -t sandcastle-diff-XXXXXX")).stdout.trim();
|
|
226
|
+
const sandboxDiffFile = `${sandboxDiffDir}/changes.patch`;
|
|
227
|
+
yield* execOk(sandbox, `git diff HEAD > "${sandboxDiffFile}"`, {
|
|
228
|
+
cwd: sandboxRepoDir,
|
|
229
|
+
});
|
|
230
|
+
yield* sandbox.copyOut(sandboxDiffFile, join(patchDir, "changes.patch"));
|
|
231
|
+
yield* sandbox.exec(`rm -rf "${sandboxDiffDir}"`);
|
|
232
|
+
}
|
|
233
|
+
// --- 3. Save untracked files ---
|
|
234
|
+
const untrackedResult = yield* sandbox.exec("git ls-files --others --exclude-standard", { cwd: sandboxRepoDir });
|
|
235
|
+
if (untrackedResult.exitCode === 0 &&
|
|
236
|
+
untrackedResult.stdout.trim().length > 0) {
|
|
237
|
+
const untrackedFiles = untrackedResult.stdout
|
|
238
|
+
.trim()
|
|
239
|
+
.split("\n")
|
|
240
|
+
.filter((f) => f.length > 0);
|
|
241
|
+
if (untrackedFiles.length > 0) {
|
|
242
|
+
hasUntracked = true;
|
|
243
|
+
const untrackedDir = join(patchDir, "untracked");
|
|
244
|
+
yield* Effect.promise(() => mkdir(untrackedDir, { recursive: true }));
|
|
245
|
+
for (const file of untrackedFiles) {
|
|
246
|
+
const destPath = join(untrackedDir, file);
|
|
247
|
+
const destDir = join(untrackedDir, file.split("/").slice(0, -1).join("/"));
|
|
248
|
+
if (destDir !== untrackedDir) {
|
|
249
|
+
yield* Effect.promise(() => mkdir(destDir, { recursive: true }));
|
|
250
|
+
}
|
|
251
|
+
yield* sandbox.copyOut(`${sandboxRepoDir}/${file}`, destPath);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return { patchDir, hasCommits, hasDiff, hasUntracked };
|
|
256
|
+
});
|
|
257
|
+
/** Apply patches directly to the host's current branch (existing behavior) */
|
|
258
|
+
const syncOutDirect = (sandbox, hostRepoDir, sandboxRepoDir, baseHead) => Effect.gen(function* () {
|
|
259
|
+
const sandboxHead = (yield* execOk(sandbox, "git rev-parse HEAD", {
|
|
260
|
+
cwd: sandboxRepoDir,
|
|
261
|
+
})).stdout.trim();
|
|
262
|
+
// Check if there's anything to do
|
|
263
|
+
const diffCheck = yield* sandbox.exec("git diff HEAD --quiet", {
|
|
264
|
+
cwd: sandboxRepoDir,
|
|
265
|
+
});
|
|
266
|
+
const untrackedResult = yield* sandbox.exec("git ls-files --others --exclude-standard", { cwd: sandboxRepoDir });
|
|
267
|
+
const hasAnyChanges = sandboxHead !== baseHead ||
|
|
268
|
+
diffCheck.exitCode !== 0 ||
|
|
269
|
+
(untrackedResult.exitCode === 0 &&
|
|
270
|
+
untrackedResult.stdout.trim().length > 0);
|
|
271
|
+
if (!hasAnyChanges)
|
|
272
|
+
return;
|
|
273
|
+
// Phase 1: Eagerly save all artifacts
|
|
274
|
+
const { patchDir, hasCommits, hasDiff, hasUntracked } = yield* saveArtifacts(sandbox, hostRepoDir, sandboxRepoDir, baseHead);
|
|
275
|
+
// Phase 2: Apply from the saved directory, tracking which step we're on
|
|
276
|
+
let currentStep;
|
|
277
|
+
const applyEffect = Effect.gen(function* () {
|
|
278
|
+
// Apply committed patches
|
|
279
|
+
if (hasCommits) {
|
|
280
|
+
currentStep = "commits";
|
|
281
|
+
const patchFiles = (yield* Effect.promise(() => readdir(patchDir)))
|
|
282
|
+
.filter((f) => f.endsWith(".patch") && f !== "changes.patch")
|
|
283
|
+
.sort();
|
|
284
|
+
// Skip empty patches (e.g. from merge commits — git format-patch
|
|
285
|
+
// produces 0-byte files or header-only patches with no diff)
|
|
286
|
+
const nonEmptyPatchFiles = [];
|
|
287
|
+
for (const file of patchFiles) {
|
|
288
|
+
const filePath = join(patchDir, file);
|
|
289
|
+
const { size } = yield* Effect.promise(() => stat(filePath));
|
|
290
|
+
if (size === 0)
|
|
291
|
+
continue;
|
|
292
|
+
const content = yield* Effect.promise(() => readFile(filePath, "utf-8"));
|
|
293
|
+
if (!content.includes("diff "))
|
|
294
|
+
continue;
|
|
295
|
+
nonEmptyPatchFiles.push(file);
|
|
296
|
+
}
|
|
297
|
+
// Abort any leftover git am session
|
|
298
|
+
yield* Effect.ignore(execHost("git am --abort", hostRepoDir));
|
|
299
|
+
for (const file of nonEmptyPatchFiles) {
|
|
300
|
+
yield* execHost(`git am --3way "${join(patchDir, file)}"`, hostRepoDir);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
// Apply uncommitted diff
|
|
304
|
+
if (hasDiff) {
|
|
305
|
+
currentStep = "diff";
|
|
306
|
+
yield* execHost(`git apply "${join(patchDir, "changes.patch")}"`, hostRepoDir);
|
|
307
|
+
}
|
|
308
|
+
// Copy untracked files
|
|
309
|
+
if (hasUntracked) {
|
|
310
|
+
currentStep = "untracked";
|
|
311
|
+
const untrackedDir = join(patchDir, "untracked");
|
|
312
|
+
const files = yield* Effect.promise(() => readdir(untrackedDir));
|
|
313
|
+
for (const file of files) {
|
|
314
|
+
const src = join(untrackedDir, file);
|
|
315
|
+
const dest = join(hostRepoDir, file);
|
|
316
|
+
yield* Effect.promise(() => copyFile(src, dest));
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
// On success, clean up the patch directory. On failure, generate recovery message.
|
|
321
|
+
yield* Effect.matchEffect(applyEffect, {
|
|
322
|
+
onSuccess: () => Effect.promise(() => rm(patchDir, { recursive: true, force: true })),
|
|
323
|
+
onFailure: (error) => {
|
|
324
|
+
const relativePatchDir = relative(hostRepoDir, patchDir);
|
|
325
|
+
const recovery = currentStep
|
|
326
|
+
? buildRecoveryMessage({
|
|
327
|
+
patchDir: relativePatchDir,
|
|
328
|
+
failedStep: currentStep,
|
|
329
|
+
hasCommits,
|
|
330
|
+
hasDiff,
|
|
331
|
+
hasUntracked,
|
|
332
|
+
})
|
|
333
|
+
: "";
|
|
334
|
+
const errorMsg = error.message + (recovery ? `\n\n${recovery}` : "");
|
|
335
|
+
return Effect.fail(new SyncError({ message: errorMsg }));
|
|
336
|
+
},
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
/** Create a WIP commit in the sandbox for any uncommitted/untracked changes */
|
|
340
|
+
const createWipCommit = (sandbox, sandboxRepoDir) => Effect.gen(function* () {
|
|
341
|
+
// Check for uncommitted changes (staged + unstaged)
|
|
342
|
+
const diffCheck = yield* sandbox.exec("git diff HEAD --quiet", {
|
|
343
|
+
cwd: sandboxRepoDir,
|
|
344
|
+
});
|
|
345
|
+
const stagedCheck = yield* sandbox.exec("git diff --cached --quiet", {
|
|
346
|
+
cwd: sandboxRepoDir,
|
|
347
|
+
});
|
|
348
|
+
// Check for untracked files
|
|
349
|
+
const untrackedResult = yield* sandbox.exec("git ls-files --others --exclude-standard", { cwd: sandboxRepoDir });
|
|
350
|
+
const untrackedFiles = untrackedResult.exitCode === 0 && untrackedResult.stdout.trim().length > 0
|
|
351
|
+
? untrackedResult.stdout
|
|
352
|
+
.trim()
|
|
353
|
+
.split("\n")
|
|
354
|
+
.filter((f) => f.length > 0)
|
|
355
|
+
: [];
|
|
356
|
+
const hasUncommitted = diffCheck.exitCode !== 0 ||
|
|
357
|
+
stagedCheck.exitCode !== 0 ||
|
|
358
|
+
untrackedFiles.length > 0;
|
|
359
|
+
if (!hasUncommitted)
|
|
360
|
+
return false;
|
|
361
|
+
// Stage everything
|
|
362
|
+
yield* execOk(sandbox, "git add -A", { cwd: sandboxRepoDir });
|
|
363
|
+
// Build a detailed WIP commit message listing affected files
|
|
364
|
+
const statusResult = yield* execOk(sandbox, "git diff --cached --name-status", {
|
|
365
|
+
cwd: sandboxRepoDir,
|
|
366
|
+
});
|
|
367
|
+
const fileList = statusResult.stdout.trim();
|
|
368
|
+
const message = [
|
|
369
|
+
"WIP: uncommitted sandbox changes",
|
|
370
|
+
"",
|
|
371
|
+
"These are uncommitted changes from a sandcastle sandbox run.",
|
|
372
|
+
"They were auto-committed to preserve work that would otherwise be lost.",
|
|
373
|
+
"",
|
|
374
|
+
"Affected files:",
|
|
375
|
+
...fileList
|
|
376
|
+
.split("\n")
|
|
377
|
+
.filter((l) => l.length > 0)
|
|
378
|
+
.map((l) => ` ${l}`),
|
|
379
|
+
].join("\n");
|
|
380
|
+
yield* execOk(sandbox, `git commit -m ${JSON.stringify(message)}`, {
|
|
381
|
+
cwd: sandboxRepoDir,
|
|
382
|
+
});
|
|
383
|
+
return true;
|
|
384
|
+
});
|
|
385
|
+
/** Apply committed patches to a target branch via a temporary git worktree */
|
|
386
|
+
const syncOutViaWorktree = (sandbox, hostRepoDir, sandboxRepoDir, baseHead, targetBranch) => Effect.gen(function* () {
|
|
387
|
+
// Create WIP commit for any uncommitted/untracked changes
|
|
388
|
+
yield* createWipCommit(sandbox, sandboxRepoDir);
|
|
389
|
+
// Check if there are new commits to apply (including WIP)
|
|
390
|
+
const sandboxHead = (yield* execOk(sandbox, "git rev-parse HEAD", {
|
|
391
|
+
cwd: sandboxRepoDir,
|
|
392
|
+
})).stdout.trim();
|
|
393
|
+
if (sandboxHead === baseHead) {
|
|
394
|
+
// No commits and no uncommitted changes — nothing to do
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
const countResult = yield* execOk(sandbox, `git rev-list "${baseHead}..HEAD" --count`, { cwd: sandboxRepoDir });
|
|
398
|
+
const commitCount = parseInt(countResult.stdout.trim(), 10);
|
|
399
|
+
if (commitCount === 0)
|
|
400
|
+
return;
|
|
401
|
+
// Phase 1: Eagerly save patches to persistent timestamped directory
|
|
402
|
+
const patchDir = yield* Effect.promise(() => createPatchDir(hostRepoDir));
|
|
403
|
+
const hostPatchDir = yield* generateAndCopyPatches(sandbox, sandboxRepoDir, baseHead);
|
|
404
|
+
// Move patch files into the persistent directory
|
|
405
|
+
const patchFiles = (yield* Effect.promise(() => readdir(hostPatchDir))).filter((f) => f.endsWith(".patch"));
|
|
406
|
+
for (const file of patchFiles) {
|
|
407
|
+
yield* Effect.promise(() => copyFile(join(hostPatchDir, file), join(patchDir, file)));
|
|
408
|
+
}
|
|
409
|
+
yield* Effect.promise(() => rm(hostPatchDir, { recursive: true }));
|
|
410
|
+
// Phase 2: Create worktree, apply patches
|
|
411
|
+
const worktreeDir = yield* Effect.promise(() => mkdtemp(join(tmpdir(), "sandcastle-worktree-")));
|
|
412
|
+
// Check if target branch already exists on host and record its tip
|
|
413
|
+
const branchExistsResult = yield* Effect.either(execHost(`git rev-parse --verify "refs/heads/${targetBranch}"`, hostRepoDir));
|
|
414
|
+
const branchExists = branchExistsResult._tag === "Right";
|
|
415
|
+
const originalBranchTip = branchExists
|
|
416
|
+
? branchExistsResult.right.trim()
|
|
417
|
+
: undefined;
|
|
418
|
+
const applyEffect = Effect.ensuring(
|
|
419
|
+
// Try: create worktree and apply patches
|
|
420
|
+
Effect.gen(function* () {
|
|
421
|
+
if (branchExists) {
|
|
422
|
+
yield* execHost(`git worktree add "${worktreeDir}/wt" "${targetBranch}"`, hostRepoDir);
|
|
423
|
+
}
|
|
424
|
+
else {
|
|
425
|
+
yield* execHost(`git worktree add "${worktreeDir}/wt" -b "${targetBranch}" HEAD`, hostRepoDir);
|
|
426
|
+
}
|
|
427
|
+
// Abort any leftover git am session
|
|
428
|
+
yield* Effect.ignore(execHost("git am --abort", `${worktreeDir}/wt`));
|
|
429
|
+
// Apply patches in the worktree
|
|
430
|
+
const sortedFiles = (yield* Effect.promise(() => readdir(patchDir)))
|
|
431
|
+
.filter((f) => f.endsWith(".patch"))
|
|
432
|
+
.sort();
|
|
433
|
+
for (const file of sortedFiles) {
|
|
434
|
+
yield* execHost(`git am --3way "${join(patchDir, file)}"`, `${worktreeDir}/wt`);
|
|
435
|
+
}
|
|
436
|
+
}),
|
|
437
|
+
// Finally: always clean up worktree (but not patches)
|
|
438
|
+
Effect.gen(function* () {
|
|
439
|
+
yield* Effect.ignore(execHost(`git worktree remove "${worktreeDir}/wt" --force`, hostRepoDir));
|
|
440
|
+
yield* Effect.promise(() => rm(worktreeDir, { recursive: true, force: true }));
|
|
441
|
+
}));
|
|
442
|
+
// On success, clean up patch dir. On failure, generate recovery message.
|
|
443
|
+
yield* Effect.matchEffect(applyEffect, {
|
|
444
|
+
onSuccess: () => Effect.promise(() => rm(patchDir, { recursive: true, force: true })),
|
|
445
|
+
onFailure: (error) => Effect.gen(function* () {
|
|
446
|
+
// Roll back the branch to its original state (all-or-nothing)
|
|
447
|
+
if (originalBranchTip) {
|
|
448
|
+
yield* Effect.ignore(execHost(`git update-ref "refs/heads/${targetBranch}" "${originalBranchTip}"`, hostRepoDir));
|
|
449
|
+
}
|
|
450
|
+
else {
|
|
451
|
+
// Branch was newly created — delete it
|
|
452
|
+
yield* Effect.ignore(execHost(`git branch -D "${targetBranch}"`, hostRepoDir));
|
|
453
|
+
}
|
|
454
|
+
const relativePatchDir = relative(hostRepoDir, patchDir);
|
|
455
|
+
const recovery = buildRecoveryMessage({
|
|
456
|
+
patchDir: relativePatchDir,
|
|
457
|
+
failedStep: "commits",
|
|
458
|
+
hasCommits: true,
|
|
459
|
+
hasDiff: false,
|
|
460
|
+
hasUntracked: false,
|
|
461
|
+
branch: targetBranch,
|
|
462
|
+
});
|
|
463
|
+
const errorMsg = error.message + `\n\n${recovery}`;
|
|
464
|
+
yield* Effect.fail(new SyncError({ message: errorMsg }));
|
|
465
|
+
}),
|
|
466
|
+
});
|
|
467
|
+
});
|
|
468
|
+
/** Generate format-patch files in sandbox and copy them to host temp dir */
|
|
469
|
+
const generateAndCopyPatches = (sandbox, sandboxRepoDir, baseHead) => Effect.gen(function* () {
|
|
470
|
+
const sandboxPatchDir = (yield* execOk(sandbox, "mktemp -d -t sandcastle-patches-XXXXXX")).stdout.trim();
|
|
471
|
+
yield* execOk(sandbox, `git format-patch "${baseHead}..HEAD" -o "${sandboxPatchDir}"`, { cwd: sandboxRepoDir });
|
|
472
|
+
const hostPatchDir = yield* Effect.promise(() => mkdtemp(join(tmpdir(), "sandcastle-patches-")));
|
|
473
|
+
const patchListResult = yield* execOk(sandbox, `ls "${sandboxPatchDir}"/*.patch`);
|
|
474
|
+
const patchFiles = patchListResult.stdout
|
|
475
|
+
.trim()
|
|
476
|
+
.split("\n")
|
|
477
|
+
.filter((f) => f.length > 0);
|
|
478
|
+
for (const sandboxPatchPath of patchFiles) {
|
|
479
|
+
const filename = sandboxPatchPath.split("/").pop();
|
|
480
|
+
const hostPatchPath = join(hostPatchDir, filename);
|
|
481
|
+
yield* sandbox.copyOut(sandboxPatchPath, hostPatchPath);
|
|
482
|
+
}
|
|
483
|
+
yield* sandbox.exec(`rm -rf "${sandboxPatchDir}"`);
|
|
484
|
+
return hostPatchDir;
|
|
485
|
+
});
|
|
486
|
+
/** Apply patches directly to a host repo dir */
|
|
487
|
+
const applyPatches = (sandbox, hostRepoDir, sandboxRepoDir, baseHead) => Effect.gen(function* () {
|
|
488
|
+
const countResult = yield* execOk(sandbox, `git rev-list "${baseHead}..HEAD" --count`, { cwd: sandboxRepoDir });
|
|
489
|
+
const commitCount = parseInt(countResult.stdout.trim(), 10);
|
|
490
|
+
if (commitCount > 0) {
|
|
491
|
+
const hostPatchDir = yield* generateAndCopyPatches(sandbox, sandboxRepoDir, baseHead);
|
|
492
|
+
// Abort any leftover git am session
|
|
493
|
+
yield* Effect.ignore(execHost("git am --abort", hostRepoDir));
|
|
494
|
+
// Apply patches in order
|
|
495
|
+
const sortedFiles = (yield* Effect.promise(() => readdir(hostPatchDir)))
|
|
496
|
+
.filter((f) => f.endsWith(".patch"))
|
|
497
|
+
.sort();
|
|
498
|
+
for (const file of sortedFiles) {
|
|
499
|
+
yield* execHost(`git am --3way "${join(hostPatchDir, file)}"`, hostRepoDir);
|
|
500
|
+
}
|
|
501
|
+
yield* Effect.promise(() => rm(hostPatchDir, { recursive: true }));
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
//# sourceMappingURL=SyncService.js.map
|
|
@@ -0,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AC,CAAC;QAE9D,yBAAyB;QACzB,MAAM,WAAW,GAAG,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;aACrE,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;aACnC,IAAI,EAAE,CAAC;QAEV,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE,CAAC;YAC/B,KAAK,CAAC,CAAC,QAAQ,CACb,kBAAkB,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,GAAG,EAC7C,WAAW,CACZ,CAAC;QACJ,CAAC;QAED,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,YAAY,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IACrE,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TokenResolver.d.ts","sourceRoot":"","sources":["../src/TokenResolver.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAuBD,eAAO,MAAM,aAAa,8CAgCzB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
const parseEnvFile = async (filePath) => {
|
|
4
|
+
try {
|
|
5
|
+
const content = await readFile(filePath, "utf-8");
|
|
6
|
+
const vars = {};
|
|
7
|
+
for (const line of content.split("\n")) {
|
|
8
|
+
const trimmed = line.trim();
|
|
9
|
+
if (!trimmed || trimmed.startsWith("#"))
|
|
10
|
+
continue;
|
|
11
|
+
const eqIndex = trimmed.indexOf("=");
|
|
12
|
+
if (eqIndex === -1)
|
|
13
|
+
continue;
|
|
14
|
+
const key = trimmed.slice(0, eqIndex).trim();
|
|
15
|
+
const value = trimmed.slice(eqIndex + 1).trim();
|
|
16
|
+
if (value)
|
|
17
|
+
vars[key] = value;
|
|
18
|
+
}
|
|
19
|
+
return vars;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
export const resolveTokens = async (repoDir) => {
|
|
26
|
+
// Precedence: repo root .env > .sandcastle/.env > process env
|
|
27
|
+
const rootEnv = await parseEnvFile(join(repoDir, ".env"));
|
|
28
|
+
const sandcastleEnv = await parseEnvFile(join(repoDir, ".sandcastle", ".env"));
|
|
29
|
+
const oauthToken = rootEnv["CLAUDE_CODE_OAUTH_TOKEN"] ??
|
|
30
|
+
sandcastleEnv["CLAUDE_CODE_OAUTH_TOKEN"] ??
|
|
31
|
+
process.env["CLAUDE_CODE_OAUTH_TOKEN"];
|
|
32
|
+
const ghToken = rootEnv["GH_TOKEN"] ??
|
|
33
|
+
sandcastleEnv["GH_TOKEN"] ??
|
|
34
|
+
process.env["GH_TOKEN"];
|
|
35
|
+
if (!oauthToken) {
|
|
36
|
+
throw new Error("CLAUDE_CODE_OAUTH_TOKEN not found. Set it in .env, .sandcastle/.env, or as an environment variable.");
|
|
37
|
+
}
|
|
38
|
+
if (!ghToken) {
|
|
39
|
+
throw new Error("GH_TOKEN not found. Set it in .env, .sandcastle/.env, or as an environment variable.");
|
|
40
|
+
}
|
|
41
|
+
return { oauthToken, ghToken };
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=TokenResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TokenResolver.js","sourceRoot":"","sources":["../src/TokenResolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,C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