@unieai/rabi-experimental-worktree 0.0.0-stage → 0.2.1-rc.3
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 +21 -0
- package/README.md +7 -2
- package/lib/index.js +368 -0
- package/lib/types/directory.d.ts +7 -0
- package/lib/types/index.d.ts +54 -0
- package/lib/types/process.d.ts +29 -0
- package/lib/types/types.d.ts +20 -0
- package/package.json +36 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DeepSeek
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @unieai/rabi-experimental-worktree
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Creates a named Git worktree and changes the calling Session working directory
|
|
4
|
+
|
|
5
|
+
Part of Rabi, the agent harness UnieAI Code runs on. Installed as a dependency of `@unieai/rabi`;
|
|
6
|
+
not meant to be used on its own.
|
|
7
|
+
|
|
8
|
+
See LICENSE for the license and copyright of this package.
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { Service } from "@unieai/cordis";
|
|
3
|
+
import z from "@unieai/schemastery";
|
|
4
|
+
import { MAX_TIMER_DELAY_MS, deadline } from "@unieai/rabi-timeout";
|
|
5
|
+
//#region lib/types/directory.js
|
|
6
|
+
/** Static child program for exclusive checkout-directory allocation inside the process sandbox. */
|
|
7
|
+
/**
|
|
8
|
+
* The child receives the configured root and destination as literal argv. Existing roots retain
|
|
9
|
+
* their files; only the process that creates a root writes its self-ignoring .gitignore.
|
|
10
|
+
*/
|
|
11
|
+
const PREPARE_DIRECTORY = `
|
|
12
|
+
import fs from 'node:fs/promises';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
async function main() {
|
|
15
|
+
const [root, destination] = process.argv.slice(1);
|
|
16
|
+
await fs.mkdir(path.dirname(root), { recursive: true });
|
|
17
|
+
let created = false;
|
|
18
|
+
try {
|
|
19
|
+
await fs.mkdir(root);
|
|
20
|
+
created = true;
|
|
21
|
+
} catch (error) {
|
|
22
|
+
if (error.code !== 'EEXIST' || !(await fs.stat(root)).isDirectory()) throw error;
|
|
23
|
+
}
|
|
24
|
+
if (created) await fs.writeFile(path.join(root, '.gitignore'), '*\\n', { flag: 'wx' });
|
|
25
|
+
await fs.mkdir(path.dirname(destination), { recursive: true });
|
|
26
|
+
await fs.mkdir(destination);
|
|
27
|
+
}
|
|
28
|
+
main().catch(error => { console.error(error.message); process.exitCode = 1; });
|
|
29
|
+
`;
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region lib/types/process.js
|
|
32
|
+
/** Bounded, cancellable commands under the calling Session's existing file policy. */
|
|
33
|
+
var __addDisposableResource = function(env, value, async) {
|
|
34
|
+
if (value !== null && value !== void 0) {
|
|
35
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
36
|
+
var dispose, inner;
|
|
37
|
+
if (async) {
|
|
38
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
39
|
+
dispose = value[Symbol.asyncDispose];
|
|
40
|
+
}
|
|
41
|
+
if (dispose === void 0) {
|
|
42
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
43
|
+
dispose = value[Symbol.dispose];
|
|
44
|
+
if (async) inner = dispose;
|
|
45
|
+
}
|
|
46
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
47
|
+
if (inner) dispose = function() {
|
|
48
|
+
try {
|
|
49
|
+
inner.call(this);
|
|
50
|
+
} catch (e) {
|
|
51
|
+
return Promise.reject(e);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
env.stack.push({
|
|
55
|
+
value,
|
|
56
|
+
dispose,
|
|
57
|
+
async
|
|
58
|
+
});
|
|
59
|
+
} else if (async) env.stack.push({ async: true });
|
|
60
|
+
return value;
|
|
61
|
+
};
|
|
62
|
+
var __disposeResources = (function(SuppressedError) {
|
|
63
|
+
return function(env) {
|
|
64
|
+
function fail(e) {
|
|
65
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
66
|
+
env.hasError = true;
|
|
67
|
+
}
|
|
68
|
+
var r, s = 0;
|
|
69
|
+
function next() {
|
|
70
|
+
while (r = env.stack.pop()) try {
|
|
71
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
72
|
+
if (r.dispose) {
|
|
73
|
+
var result = r.dispose.call(r.value);
|
|
74
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
|
|
75
|
+
fail(e);
|
|
76
|
+
return next();
|
|
77
|
+
});
|
|
78
|
+
} else s |= 1;
|
|
79
|
+
} catch (e) {
|
|
80
|
+
fail(e);
|
|
81
|
+
}
|
|
82
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
83
|
+
if (env.hasError) throw env.error;
|
|
84
|
+
}
|
|
85
|
+
return next();
|
|
86
|
+
};
|
|
87
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
88
|
+
var e = new Error(message);
|
|
89
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
90
|
+
});
|
|
91
|
+
/** Clear inherited repository, attribute-tree, command-line configuration, and replacement-ref selectors. */
|
|
92
|
+
const GIT_ENV = Object.fromEntries([
|
|
93
|
+
"GIT_DIR",
|
|
94
|
+
"GIT_WORK_TREE",
|
|
95
|
+
"GIT_COMMON_DIR",
|
|
96
|
+
"GIT_INDEX_FILE",
|
|
97
|
+
"GIT_OBJECT_DIRECTORY",
|
|
98
|
+
"GIT_ALTERNATE_OBJECT_DIRECTORIES",
|
|
99
|
+
"GIT_CONFIG",
|
|
100
|
+
"GIT_CONFIG_PARAMETERS",
|
|
101
|
+
"GIT_CONFIG_COUNT",
|
|
102
|
+
"GIT_CEILING_DIRECTORIES",
|
|
103
|
+
"GIT_PREFIX",
|
|
104
|
+
"GIT_SHALLOW_FILE",
|
|
105
|
+
"GIT_GRAFT_FILE",
|
|
106
|
+
"GIT_REPLACE_REF_BASE",
|
|
107
|
+
"GIT_ATTR_SOURCE"
|
|
108
|
+
].map((key) => [key, void 0]));
|
|
109
|
+
/**
|
|
110
|
+
* Run an argv without a shell and await termination of its managed process range.
|
|
111
|
+
* @param ctx - subprocess and sandbox providers in the same execution world.
|
|
112
|
+
* @param config - complete process resource limits.
|
|
113
|
+
* @param policy - unchanged calling Session policy.
|
|
114
|
+
* @param cwd - canonical process working directory.
|
|
115
|
+
* @param argv - executable followed by literal arguments.
|
|
116
|
+
* @param signal - operation cancellation.
|
|
117
|
+
* @param allowedExitCodes - command-specific successful statuses.
|
|
118
|
+
* @param env - command-local environment overrides, applied after Git selector removal.
|
|
119
|
+
* @returns complete bounded stdout and the exit code.
|
|
120
|
+
*/
|
|
121
|
+
async function runCommand(ctx, config, policy, cwd, argv, signal, allowedExitCodes = [0], env = {}) {
|
|
122
|
+
const env_1 = {
|
|
123
|
+
stack: [],
|
|
124
|
+
error: void 0,
|
|
125
|
+
hasError: false
|
|
126
|
+
};
|
|
127
|
+
try {
|
|
128
|
+
const timeout = __addDisposableResource(env_1, deadline(signal, config.timeoutMs, "WORKTREE_TIMEOUT"), false);
|
|
129
|
+
timeout.signal.throwIfAborted();
|
|
130
|
+
const command = [await ctx.subprocess.resolveExecutable(argv[0], void 0, timeout.signal), ...argv.slice(1)];
|
|
131
|
+
const wrapped = policy.mode === "danger-full-access" ? command : (await ctx.sandbox.confine(command, {
|
|
132
|
+
...policy,
|
|
133
|
+
mode: policy.mode
|
|
134
|
+
}, timeout.signal)).argv;
|
|
135
|
+
timeout.signal.throwIfAborted();
|
|
136
|
+
const child = ctx.subprocess.spawn({
|
|
137
|
+
argv: wrapped,
|
|
138
|
+
cwd,
|
|
139
|
+
env: {
|
|
140
|
+
...GIT_ENV,
|
|
141
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
142
|
+
GIT_LFS_SKIP_SMUDGE: "1",
|
|
143
|
+
GIT_NO_LAZY_FETCH: "1",
|
|
144
|
+
...env
|
|
145
|
+
},
|
|
146
|
+
signal: timeout.signal,
|
|
147
|
+
graceMs: config.graceMs,
|
|
148
|
+
stdio: {
|
|
149
|
+
stdin: "ignore",
|
|
150
|
+
stdout: { maxBytes: config.maxOutputBytes },
|
|
151
|
+
stderr: { maxBytes: config.maxOutputBytes }
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
try {
|
|
155
|
+
const outcome = await child.done;
|
|
156
|
+
timeout.signal.throwIfAborted();
|
|
157
|
+
const captured = child.collected;
|
|
158
|
+
const stdout = captured.stdout.readFrom(0);
|
|
159
|
+
const stderr = captured.stderr.readFrom(0);
|
|
160
|
+
if (outcome.exitCode === null || !allowedExitCodes.includes(outcome.exitCode)) throw new Error(`worktree command failed (${outcome.signal ?? outcome.exitCode}): ${stderr.text.trim()}`);
|
|
161
|
+
if (stdout.lossy) throw new Error("worktree command output exceeds maxOutputBytes");
|
|
162
|
+
return {
|
|
163
|
+
stdout: stdout.text,
|
|
164
|
+
exitCode: outcome.exitCode
|
|
165
|
+
};
|
|
166
|
+
} finally {
|
|
167
|
+
child.terminate();
|
|
168
|
+
await child.waitForExit();
|
|
169
|
+
}
|
|
170
|
+
} catch (e_1) {
|
|
171
|
+
env_1.error = e_1;
|
|
172
|
+
env_1.hasError = true;
|
|
173
|
+
} finally {
|
|
174
|
+
__disposeResources(env_1);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region lib/types/index.js
|
|
179
|
+
/** Creates a new Git branch and checkout, then changes the calling Session's working directory. */
|
|
180
|
+
/** Reject path traversal independently of Git's branch-name grammar. */
|
|
181
|
+
function relativePath(value) {
|
|
182
|
+
return value.length > 0 && !value.includes("\\") && !value.includes(":") && value.split("/").every((part) => part.length > 0 && part !== "." && part !== "..");
|
|
183
|
+
}
|
|
184
|
+
/** Creates retained Git worktrees under the mounted filesystem and sandbox providers. */
|
|
185
|
+
var WorktreeService = class extends Service {
|
|
186
|
+
static inject = [
|
|
187
|
+
"workingDirectory",
|
|
188
|
+
"fs",
|
|
189
|
+
"subprocess",
|
|
190
|
+
"sandbox",
|
|
191
|
+
"sandboxPolicy"
|
|
192
|
+
];
|
|
193
|
+
static Config = z.object({
|
|
194
|
+
directory: z.string().default(".agents/worktrees"),
|
|
195
|
+
namePrefix: z.string().default("worktree-"),
|
|
196
|
+
gitCommand: z.string().default("git"),
|
|
197
|
+
nodeCommand: z.string().default("node"),
|
|
198
|
+
timeoutMs: z.number().default(6e4),
|
|
199
|
+
graceMs: z.number().default(3e3),
|
|
200
|
+
maxOutputBytes: z.number().default(65536)
|
|
201
|
+
});
|
|
202
|
+
config;
|
|
203
|
+
lifetime = new AbortController();
|
|
204
|
+
pending = /* @__PURE__ */ new Set();
|
|
205
|
+
constructor(ctx, config) {
|
|
206
|
+
super(ctx, "worktrees");
|
|
207
|
+
this.config = config;
|
|
208
|
+
if (!relativePath(this.config.directory)) throw new Error("worktree: directory must be a relative directory without dot segments");
|
|
209
|
+
if (!relativePath(`${this.config.namePrefix}name`) || this.config.namePrefix.startsWith("-")) throw new Error("worktree: namePrefix must produce a relative branch name");
|
|
210
|
+
for (const key of ["gitCommand", "nodeCommand"]) if (this.config[key].trim().length === 0) throw new Error(`worktree: ${key} must not be empty`);
|
|
211
|
+
for (const key of [
|
|
212
|
+
"timeoutMs",
|
|
213
|
+
"graceMs",
|
|
214
|
+
"maxOutputBytes"
|
|
215
|
+
]) {
|
|
216
|
+
const value = this.config[key];
|
|
217
|
+
if (!Number.isSafeInteger(value) || value <= 0 || value > MAX_TIMER_DELAY_MS) throw new Error(`worktree: ${key} must be a positive integer no greater than ${MAX_TIMER_DELAY_MS}`);
|
|
218
|
+
}
|
|
219
|
+
ctx.effect(() => async () => {
|
|
220
|
+
this.lifetime.abort(/* @__PURE__ */ new Error("worktree service disposed"));
|
|
221
|
+
await Promise.allSettled(this.pending);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Create a fresh branch and checkout at a pinned local revision, then enter it.
|
|
226
|
+
* Existing branches or checkout paths fail. Uncommitted files stay in the source checkout.
|
|
227
|
+
* Checkout disables configured clean, smudge, and process filters without changing Git config.
|
|
228
|
+
* Repository-local replacement refs still apply; baseCommit reports the resolved object name.
|
|
229
|
+
* The new checkout becomes current only after Git setup succeeds. Failures may retain newly
|
|
230
|
+
* allocated Git/filesystem artifacts; no branch or checkout is removed automatically.
|
|
231
|
+
* @param agent - caller whose current directory selects the source repository and file policy.
|
|
232
|
+
* @param request - optional new name and local revision; defaults are generated name and HEAD.
|
|
233
|
+
* @param signal - cancellation of lookup, creation, and working-directory publication.
|
|
234
|
+
* @returns canonical checkout path, branch name, pinned commit, and source repository root.
|
|
235
|
+
*/
|
|
236
|
+
async create(agent, request = {}, signal) {
|
|
237
|
+
const operationSignal = signal === void 0 ? this.lifetime.signal : AbortSignal.any([this.lifetime.signal, signal]);
|
|
238
|
+
operationSignal.throwIfAborted();
|
|
239
|
+
const operation = this.createCheckout(agent, this.resolve(request), operationSignal);
|
|
240
|
+
this.pending.add(operation);
|
|
241
|
+
try {
|
|
242
|
+
return await operation;
|
|
243
|
+
} finally {
|
|
244
|
+
this.pending.delete(operation);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
resolve(request) {
|
|
248
|
+
const branch = request.name ?? `${this.config.namePrefix}${randomUUID()}`;
|
|
249
|
+
if (!relativePath(branch) || branch.startsWith("-")) throw new Error("worktree name must be a relative Git branch name");
|
|
250
|
+
const revision = request.from ?? "HEAD";
|
|
251
|
+
if (revision.length === 0) throw new Error("worktree from must name a local commit, branch, or tag");
|
|
252
|
+
return {
|
|
253
|
+
branch,
|
|
254
|
+
revision
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
async createCheckout(agent, { branch, revision }, signal) {
|
|
258
|
+
const cwd = await this.ctx.workingDirectory.ensure(agent, signal);
|
|
259
|
+
const policy = this.ctx.sandboxPolicy.resolve({ session: agent.session });
|
|
260
|
+
const run = (directory, args, allowedExitCodes, env) => runCommand(this.ctx, this.config, policy, directory, [
|
|
261
|
+
this.config.gitCommand,
|
|
262
|
+
"-c",
|
|
263
|
+
"core.hooksPath=/dev/null",
|
|
264
|
+
"-c",
|
|
265
|
+
"core.fsmonitor=false",
|
|
266
|
+
...args
|
|
267
|
+
], signal, allowedExitCodes, env);
|
|
268
|
+
await run(cwd, ["check-ref-format", `refs/heads/${branch}`]);
|
|
269
|
+
const rootOutput = await run(cwd, ["rev-parse", "--show-toplevel"]);
|
|
270
|
+
const rootTarget = await this.ctx.fs.resolve(rootOutput.stdout.replace(/\r?\n$/, ""), {
|
|
271
|
+
cwd,
|
|
272
|
+
signal
|
|
273
|
+
});
|
|
274
|
+
const repositoryRoot = this.ctx.fs.processPath(rootTarget);
|
|
275
|
+
const baseCommit = (await run(repositoryRoot, [
|
|
276
|
+
"rev-parse",
|
|
277
|
+
"--verify",
|
|
278
|
+
"--end-of-options",
|
|
279
|
+
`${revision}^{commit}`
|
|
280
|
+
])).stdout.trim();
|
|
281
|
+
if ((await run(repositoryRoot, [
|
|
282
|
+
"show-ref",
|
|
283
|
+
"--verify",
|
|
284
|
+
"--quiet",
|
|
285
|
+
`refs/heads/${branch}`
|
|
286
|
+
], [0, 1])).exitCode === 0) throw new Error(`worktree branch already exists: ${branch}`);
|
|
287
|
+
const pool = await this.ctx.fs.resolve(this.config.directory, {
|
|
288
|
+
cwd: repositoryRoot,
|
|
289
|
+
signal
|
|
290
|
+
});
|
|
291
|
+
const poolPath = this.ctx.fs.processPath(pool);
|
|
292
|
+
const destination = await this.ctx.fs.resolve(branch, {
|
|
293
|
+
cwd: poolPath,
|
|
294
|
+
signal
|
|
295
|
+
});
|
|
296
|
+
const path = this.ctx.fs.processPath(destination);
|
|
297
|
+
if (await this.ctx.fs.lstat(path, void 0, signal) !== void 0) throw new Error(`worktree path already exists: ${path}`);
|
|
298
|
+
try {
|
|
299
|
+
await runCommand(this.ctx, this.config, policy, repositoryRoot, [
|
|
300
|
+
this.config.nodeCommand,
|
|
301
|
+
"--input-type=module",
|
|
302
|
+
"-e",
|
|
303
|
+
PREPARE_DIRECTORY,
|
|
304
|
+
poolPath,
|
|
305
|
+
path
|
|
306
|
+
], signal);
|
|
307
|
+
await run(repositoryRoot, [
|
|
308
|
+
"--work-tree",
|
|
309
|
+
repositoryRoot,
|
|
310
|
+
"worktree",
|
|
311
|
+
"add",
|
|
312
|
+
"--no-checkout",
|
|
313
|
+
"-b",
|
|
314
|
+
branch,
|
|
315
|
+
"--",
|
|
316
|
+
path,
|
|
317
|
+
baseCommit
|
|
318
|
+
]);
|
|
319
|
+
const configured = await run(path, [
|
|
320
|
+
"config",
|
|
321
|
+
"--null",
|
|
322
|
+
"--name-only",
|
|
323
|
+
"--get-regexp",
|
|
324
|
+
"^filter\\."
|
|
325
|
+
], [0, 1]);
|
|
326
|
+
const drivers = /* @__PURE__ */ new Set();
|
|
327
|
+
for (const key of configured.stdout.split("\0")) {
|
|
328
|
+
const separator = key.lastIndexOf(".");
|
|
329
|
+
if (separator > 7 && [
|
|
330
|
+
"clean",
|
|
331
|
+
"smudge",
|
|
332
|
+
"process",
|
|
333
|
+
"required"
|
|
334
|
+
].includes(key.slice(separator + 1))) drivers.add(key.slice(7, separator));
|
|
335
|
+
}
|
|
336
|
+
const overrides = { GIT_CONFIG_COUNT: String(drivers.size * 4) };
|
|
337
|
+
let index = 0;
|
|
338
|
+
for (const driver of drivers) for (const attribute of [
|
|
339
|
+
"clean",
|
|
340
|
+
"smudge",
|
|
341
|
+
"process",
|
|
342
|
+
"required"
|
|
343
|
+
]) {
|
|
344
|
+
overrides[`GIT_CONFIG_KEY_${index}`] = `filter.${driver}.${attribute}`;
|
|
345
|
+
overrides[`GIT_CONFIG_VALUE_${index}`] = attribute === "required" ? "false" : "";
|
|
346
|
+
index++;
|
|
347
|
+
}
|
|
348
|
+
await run(path, [
|
|
349
|
+
"--work-tree",
|
|
350
|
+
path,
|
|
351
|
+
"reset",
|
|
352
|
+
"--hard",
|
|
353
|
+
"--no-recurse-submodules",
|
|
354
|
+
baseCommit
|
|
355
|
+
], void 0, overrides);
|
|
356
|
+
return {
|
|
357
|
+
path: await this.ctx.workingDirectory.set(agent, path, signal),
|
|
358
|
+
branch,
|
|
359
|
+
baseCommit,
|
|
360
|
+
repositoryRoot
|
|
361
|
+
};
|
|
362
|
+
} catch (error) {
|
|
363
|
+
throw new Error(`Could not finish worktree ${branch} at ${path}. Any created checkout and branch are retained. ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
//#endregion
|
|
368
|
+
export { WorktreeService, WorktreeService as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Static child program for exclusive checkout-directory allocation inside the process sandbox. */
|
|
2
|
+
/**
|
|
3
|
+
* The child receives the configured root and destination as literal argv. Existing roots retain
|
|
4
|
+
* their files; only the process that creates a root writes its self-ignoring .gitignore.
|
|
5
|
+
*/
|
|
6
|
+
export declare const PREPARE_DIRECTORY = "\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\nasync function main() {\n const [root, destination] = process.argv.slice(1);\n await fs.mkdir(path.dirname(root), { recursive: true });\n let created = false;\n try {\n await fs.mkdir(root);\n created = true;\n } catch (error) {\n if (error.code !== 'EEXIST' || !(await fs.stat(root)).isDirectory()) throw error;\n }\n if (created) await fs.writeFile(path.join(root, '.gitignore'), '*\\n', { flag: 'wx' });\n await fs.mkdir(path.dirname(destination), { recursive: true });\n await fs.mkdir(destination);\n}\nmain().catch(error => { console.error(error.message); process.exitCode = 1; });\n";
|
|
7
|
+
//# sourceMappingURL=directory.d.ts.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** Creates a new Git branch and checkout, then changes the calling Session's working directory. */
|
|
2
|
+
import { Context, Service } from '@unieai/cordis';
|
|
3
|
+
import z from '@unieai/schemastery';
|
|
4
|
+
import type { Agent } from '@unieai/rabi-agent';
|
|
5
|
+
import type { CreatedWorktree, CreateWorktreeRequest } from './types.ts';
|
|
6
|
+
export type { CreatedWorktree, CreateWorktreeRequest } from './types.ts';
|
|
7
|
+
/** Worktree location, generated names, executables, and subprocess resource limits. */
|
|
8
|
+
export interface Config {
|
|
9
|
+
/** Relative checkout pool inside the source repository. */
|
|
10
|
+
directory?: string;
|
|
11
|
+
/** Prefix for automatically generated branch and checkout names. */
|
|
12
|
+
namePrefix?: string;
|
|
13
|
+
/** Executable name or absolute execution-world path of a Git release that honors `GIT_NO_LAZY_FETCH`. */
|
|
14
|
+
gitCommand?: string;
|
|
15
|
+
/** Node executable used for sandboxed directory allocation. */
|
|
16
|
+
nodeCommand?: string;
|
|
17
|
+
/** Deadline in milliseconds for one command. */
|
|
18
|
+
timeoutMs?: number;
|
|
19
|
+
/** Subprocess termination grace in milliseconds. */
|
|
20
|
+
graceMs?: number;
|
|
21
|
+
/** Maximum captured bytes per subprocess output stream. */
|
|
22
|
+
maxOutputBytes?: number;
|
|
23
|
+
}
|
|
24
|
+
declare module '@unieai/cordis' {
|
|
25
|
+
interface Context {
|
|
26
|
+
worktrees: WorktreeService;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** Creates retained Git worktrees under the mounted filesystem and sandbox providers. */
|
|
30
|
+
export declare class WorktreeService extends Service {
|
|
31
|
+
static inject: string[];
|
|
32
|
+
static Config: z<Config>;
|
|
33
|
+
private readonly config;
|
|
34
|
+
private readonly lifetime;
|
|
35
|
+
private readonly pending;
|
|
36
|
+
constructor(ctx: Context, config: Config);
|
|
37
|
+
/**
|
|
38
|
+
* Create a fresh branch and checkout at a pinned local revision, then enter it.
|
|
39
|
+
* Existing branches or checkout paths fail. Uncommitted files stay in the source checkout.
|
|
40
|
+
* Checkout disables configured clean, smudge, and process filters without changing Git config.
|
|
41
|
+
* Repository-local replacement refs still apply; baseCommit reports the resolved object name.
|
|
42
|
+
* The new checkout becomes current only after Git setup succeeds. Failures may retain newly
|
|
43
|
+
* allocated Git/filesystem artifacts; no branch or checkout is removed automatically.
|
|
44
|
+
* @param agent - caller whose current directory selects the source repository and file policy.
|
|
45
|
+
* @param request - optional new name and local revision; defaults are generated name and HEAD.
|
|
46
|
+
* @param signal - cancellation of lookup, creation, and working-directory publication.
|
|
47
|
+
* @returns canonical checkout path, branch name, pinned commit, and source repository root.
|
|
48
|
+
*/
|
|
49
|
+
create(agent: Agent, request?: CreateWorktreeRequest, signal?: AbortSignal): Promise<CreatedWorktree>;
|
|
50
|
+
private resolve;
|
|
51
|
+
private createCheckout;
|
|
52
|
+
}
|
|
53
|
+
export default WorktreeService;
|
|
54
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Bounded, cancellable commands under the calling Session's existing file policy. */
|
|
2
|
+
import type { Context } from '@unieai/cordis';
|
|
3
|
+
import type { SandboxExecutionPolicy } from '@unieai/rabi-sandbox';
|
|
4
|
+
/** Resolved process resource limits owned by the worktree service. */
|
|
5
|
+
export interface ProcessConfig {
|
|
6
|
+
/** Deadline for one command, including executable lookup and confinement. */
|
|
7
|
+
timeoutMs: number;
|
|
8
|
+
/** Termination grace period for each managed subprocess. */
|
|
9
|
+
graceMs: number;
|
|
10
|
+
/** Maximum captured bytes per output stream. */
|
|
11
|
+
maxOutputBytes: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Run an argv without a shell and await termination of its managed process range.
|
|
15
|
+
* @param ctx - subprocess and sandbox providers in the same execution world.
|
|
16
|
+
* @param config - complete process resource limits.
|
|
17
|
+
* @param policy - unchanged calling Session policy.
|
|
18
|
+
* @param cwd - canonical process working directory.
|
|
19
|
+
* @param argv - executable followed by literal arguments.
|
|
20
|
+
* @param signal - operation cancellation.
|
|
21
|
+
* @param allowedExitCodes - command-specific successful statuses.
|
|
22
|
+
* @param env - command-local environment overrides, applied after Git selector removal.
|
|
23
|
+
* @returns complete bounded stdout and the exit code.
|
|
24
|
+
*/
|
|
25
|
+
export declare function runCommand(ctx: Context, config: ProcessConfig, policy: SandboxExecutionPolicy, cwd: string, argv: readonly [string, ...string[]], signal: AbortSignal, allowedExitCodes?: readonly number[], env?: NodeJS.ProcessEnv): Promise<{
|
|
26
|
+
stdout: string;
|
|
27
|
+
exitCode: number;
|
|
28
|
+
}>;
|
|
29
|
+
//# sourceMappingURL=process.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Public requests and results for creating a Git worktree and entering it. */
|
|
2
|
+
/** A new checkout from a locally available Git commit, branch, or tag. */
|
|
3
|
+
export interface CreateWorktreeRequest {
|
|
4
|
+
/** New branch name, also used as the relative checkout directory; omission generates a name. */
|
|
5
|
+
name?: string;
|
|
6
|
+
/** Local revision to resolve before creation; omission selects HEAD. */
|
|
7
|
+
from?: string;
|
|
8
|
+
}
|
|
9
|
+
/** Committed Git baseline and the calling Session's resulting working directory. */
|
|
10
|
+
export interface CreatedWorktree {
|
|
11
|
+
/** Canonical absolute checkout directory in the filesystem provider's execution world. */
|
|
12
|
+
path: string;
|
|
13
|
+
/** Newly created branch name. */
|
|
14
|
+
branch: string;
|
|
15
|
+
/** Resolved commit object name; repository-local replacement refs can change its checked-out content. */
|
|
16
|
+
baseCommit: string;
|
|
17
|
+
/** Canonical root of the source checkout. */
|
|
18
|
+
repositoryRoot: string;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=types.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unieai/rabi-experimental-worktree",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"description": "Creates a named Git worktree and changes the calling Session working directory",
|
|
4
|
+
"version": "0.2.1-rc.3",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "lib/index.js",
|
|
10
|
+
"types": "lib/types/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./lib/types/index.d.ts",
|
|
14
|
+
"default": "./lib/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./src/*": "./src/*",
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"lib/index.js",
|
|
21
|
+
"lib/types/**/*.d.ts",
|
|
22
|
+
"README.md"
|
|
23
|
+
],
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@unieai/schemastery": "3.18.5",
|
|
27
|
+
"@unieai/rabi-timeout": "0.2.1-rc.3"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"@unieai/cordis": "4.0.5",
|
|
31
|
+
"@unieai/rabi-agent": "0.2.1-rc.3",
|
|
32
|
+
"@unieai/rabi-fs": "0.2.1-rc.3",
|
|
33
|
+
"@unieai/rabi-sandbox": "0.2.1-rc.3",
|
|
34
|
+
"@unieai/rabi-sandbox-policy": "0.2.1-rc.3",
|
|
35
|
+
"@unieai/rabi-subprocess": "0.2.1-rc.3",
|
|
36
|
+
"@unieai/rabi-working-directory": "0.2.1-rc.3"
|
|
37
|
+
}
|
|
38
|
+
}
|