@mastra/factory 0.11.1 → 0.12.0-alpha.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/CHANGELOG.md +30 -0
- package/dist/factory.d.ts +2 -22
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +15 -58
- package/dist/factory.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/integrations/base.d.ts +5 -13
- package/dist/integrations/base.d.ts.map +1 -1
- package/dist/integrations/github/config.d.ts +4 -4
- package/dist/integrations/github/config.d.ts.map +1 -1
- package/dist/integrations/github/config.js +3 -3
- package/dist/integrations/github/config.js.map +1 -1
- package/dist/integrations/github/integration.d.ts.map +1 -1
- package/dist/integrations/github/integration.js +2 -4
- package/dist/integrations/github/integration.js.map +1 -1
- package/dist/integrations/github/reconcile-worker.d.ts +0 -5
- package/dist/integrations/github/reconcile-worker.d.ts.map +1 -1
- package/dist/integrations/github/reconcile-worker.js +0 -7
- package/dist/integrations/github/reconcile-worker.js.map +1 -1
- package/dist/integrations/github/routes.d.ts +6 -5
- package/dist/integrations/github/routes.d.ts.map +1 -1
- package/dist/integrations/github/routes.js +36 -263
- package/dist/integrations/github/routes.js.map +1 -1
- package/dist/integrations/github/sandbox-release.d.ts +17 -47
- package/dist/integrations/github/sandbox-release.d.ts.map +1 -1
- package/dist/integrations/github/sandbox-release.js +24 -103
- package/dist/integrations/github/sandbox-release.js.map +1 -1
- package/dist/integrations/github/sandbox.d.ts +25 -139
- package/dist/integrations/github/sandbox.d.ts.map +1 -1
- package/dist/integrations/github/sandbox.js +24 -212
- package/dist/integrations/github/sandbox.js.map +1 -1
- package/dist/integrations/github/webhook.d.ts.map +1 -1
- package/dist/integrations/github/webhook.js +1 -2
- package/dist/integrations/github/webhook.js.map +1 -1
- package/dist/integrations/platform/github/event-worker.d.ts +0 -2
- package/dist/integrations/platform/github/event-worker.d.ts.map +1 -1
- package/dist/integrations/platform/github/event-worker.js +0 -7
- package/dist/integrations/platform/github/event-worker.js.map +1 -1
- package/dist/integrations/platform/github/integration.d.ts.map +1 -1
- package/dist/integrations/platform/github/integration.js +5 -7
- package/dist/integrations/platform/github/integration.js.map +1 -1
- package/dist/routes/config.d.ts.map +1 -1
- package/dist/routes/config.js +3 -1
- package/dist/routes/config.js.map +1 -1
- package/dist/routes/fs.d.ts +4 -6
- package/dist/routes/fs.d.ts.map +1 -1
- package/dist/routes/fs.js +28 -34
- package/dist/routes/fs.js.map +1 -1
- package/dist/routes/skills.d.ts.map +1 -1
- package/dist/routes/skills.js +6 -3
- package/dist/routes/skills.js.map +1 -1
- package/dist/routes/surface.d.ts +4 -9
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +3 -5
- package/dist/routes/surface.js.map +1 -1
- package/dist/sandbox/materialization.d.ts +36 -0
- package/dist/sandbox/materialization.d.ts.map +1 -0
- package/dist/sandbox/materialization.js +18 -0
- package/dist/sandbox/materialization.js.map +1 -0
- package/dist/sandbox/session-retirement.d.ts +8 -6
- package/dist/sandbox/session-retirement.d.ts.map +1 -1
- package/dist/sandbox/session-retirement.js +28 -123
- package/dist/sandbox/session-retirement.js.map +1 -1
- package/dist/sandbox/session-sandbox.d.ts +117 -0
- package/dist/sandbox/session-sandbox.d.ts.map +1 -0
- package/dist/sandbox/session-sandbox.js +132 -0
- package/dist/sandbox/session-sandbox.js.map +1 -0
- package/dist/sandbox/workdir.d.ts +30 -0
- package/dist/sandbox/workdir.d.ts.map +1 -0
- package/dist/sandbox/workdir.js +48 -0
- package/dist/sandbox/workdir.js.map +1 -0
- package/dist/session/filesystem-capture.d.ts +2 -1
- package/dist/session/filesystem-capture.d.ts.map +1 -1
- package/dist/session/filesystem-capture.js +45 -4
- package/dist/session/filesystem-capture.js.map +1 -1
- package/dist/session/first-exec-capture.d.ts +1 -0
- package/dist/session/first-exec-capture.d.ts.map +1 -1
- package/dist/session/first-exec-capture.js +1 -1
- package/dist/session/first-exec-capture.js.map +1 -1
- package/dist/storage/domains/integrations/base.d.ts +1 -1
- package/dist/storage/domains/integrations/base.js +1 -1
- package/dist/storage/domains/integrations/base.js.map +1 -1
- package/dist/storage/domains/source-control/base.d.ts +0 -144
- package/dist/storage/domains/source-control/base.d.ts.map +1 -1
- package/dist/storage/domains/source-control/base.js +3 -290
- package/dist/storage/domains/source-control/base.js.map +1 -1
- package/dist/storage/domains/source-control/inmemory.d.ts +1 -63
- package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/source-control/inmemory.js +0 -89
- package/dist/storage/domains/source-control/inmemory.js.map +1 -1
- package/dist/workspace.d.ts +5 -37
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +107 -245
- package/dist/workspace.js.map +1 -1
- package/package.json +4 -4
- package/dist/sandbox/base-checkpoint-triggers.d.ts +0 -77
- package/dist/sandbox/base-checkpoint-triggers.d.ts.map +0 -1
- package/dist/sandbox/base-checkpoint-triggers.js +0 -137
- package/dist/sandbox/base-checkpoint-triggers.js.map +0 -1
- package/dist/sandbox/base-checkpoint.d.ts +0 -59
- package/dist/sandbox/base-checkpoint.d.ts.map +0 -1
- package/dist/sandbox/base-checkpoint.js +0 -145
- package/dist/sandbox/base-checkpoint.js.map +0 -1
- package/dist/sandbox/fleet.d.ts +0 -258
- package/dist/sandbox/fleet.d.ts.map +0 -1
- package/dist/sandbox/fleet.js +0 -356
- package/dist/sandbox/fleet.js.map +0 -1
- package/dist/sandbox/reattach.d.ts +0 -3
- package/dist/sandbox/reattach.d.ts.map +0 -1
- package/dist/sandbox/reattach.js +0 -16
- package/dist/sandbox/reattach.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sandbox-release.d.ts","sourceRoot":"","sources":["../../../src/integrations/github/sandbox-release.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sandbox-release.d.ts","sourceRoot":"","sources":["../../../src/integrations/github/sandbox-release.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,wBAAsB,qBAAqB,CAAC,OAAO,EAAE;IACnD,2DAA2D;IAC3D,SAAS,EAAE,MAAM,CAAC;IAClB,qEAAqE;IACrE,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GAAG,OAAO,CAAC,IAAI,CAAC,CAehB;AAED;;;;GAIG;AACH,wBAAsB,4BAA4B,CAAC,OAAO,EAAE;IAC1D,OAAO,EAAE,IAAI,CAAC,OAAO,8CAA8C,EAAE,oBAAoB,EAAE,IAAI,CAAC,CAAC;CAClG,GAAG,OAAO,CAAC,IAAI,CAAC,CAEhB"}
|
|
@@ -1,117 +1,38 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { evictSessionSandbox, peekSessionSandbox } from "../../sandbox/session-sandbox.js";
|
|
2
2
|
//#region src/integrations/github/sandbox-release.ts
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* VMs don't sit on stale branches, dirty worktrees, or abandoned work while
|
|
7
|
-
* they wait for the next claim. Best-effort — the VM may already be reaped
|
|
8
|
-
* (the pooled claim then falls back to fresh provisioning) and the claim
|
|
9
|
-
* path recycles the workdir again before reuse, so a failed scrub never
|
|
10
|
-
* blocks the release.
|
|
11
|
-
*/
|
|
12
|
-
async function cleanReleasedSandbox(options) {
|
|
13
|
-
try {
|
|
14
|
-
const projectRepository = await options.sourceControl.projectRepositories.get({
|
|
15
|
-
orgId: options.orgId,
|
|
16
|
-
id: options.projectRepositoryId
|
|
17
|
-
});
|
|
18
|
-
if (!projectRepository) return;
|
|
19
|
-
const repository = await options.sourceControl.repositories.get({
|
|
20
|
-
orgId: options.orgId,
|
|
21
|
-
id: projectRepository.repositoryId
|
|
22
|
-
});
|
|
23
|
-
if (!repository) return;
|
|
24
|
-
await recycleClaimedWorkdir(options.sandbox ?? await options.fleet.reattachSandbox(options.sandboxId, { actingUserId: options.actingUserId }), options.sandboxWorkdir, repository.defaultBranch);
|
|
25
|
-
} catch {}
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Reclaim the sandbox a just-deleted user session was holding: return a remote
|
|
29
|
-
* VM to the reuse pool (scrubbed first), or tear a local/unpooled one down.
|
|
4
|
+
* Stop or destroy the sandbox a session holds in this process, dropping it
|
|
5
|
+
* from the per-process memo first so later opens construct fresh.
|
|
30
6
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
7
|
+
* Sandbox identity is the session id, so there is no reuse pool to publish
|
|
8
|
+
* into — a reopened session resolves the same id through its provider
|
|
9
|
+
* (reconnect/resume, or a fresh VM whose setup hook re-materializes).
|
|
10
|
+
* Sessions never opened in this replica have no memo entry; their VMs are
|
|
11
|
+
* left to the provider's idle lifecycle (pause / idle GC).
|
|
36
12
|
*/
|
|
37
|
-
async function
|
|
38
|
-
const
|
|
39
|
-
if (!
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
orgId: session.orgId,
|
|
45
|
-
projectRepositoryId: session.projectRepositoryId,
|
|
46
|
-
sandboxId: session.sandboxId,
|
|
47
|
-
sandboxWorkdir: session.sandboxWorkdir,
|
|
48
|
-
actingUserId: session.userId
|
|
49
|
-
});
|
|
50
|
-
await sourceControl.sandboxPool.release({
|
|
51
|
-
orgId: session.orgId,
|
|
52
|
-
projectRepositoryId: session.projectRepositoryId,
|
|
53
|
-
userId: session.userId,
|
|
54
|
-
sandboxId: session.sandboxId,
|
|
55
|
-
sandboxWorkdir: session.sandboxWorkdir
|
|
56
|
-
});
|
|
13
|
+
async function releaseSessionSandbox(options) {
|
|
14
|
+
const entry = peekSessionSandbox(options.sessionId);
|
|
15
|
+
if (!entry) return;
|
|
16
|
+
evictSessionSandbox(options.sessionId);
|
|
17
|
+
const sandbox = entry.sandbox;
|
|
18
|
+
if (options.destroy) {
|
|
19
|
+
await (sandbox._destroy ? sandbox._destroy() : sandbox.destroy?.());
|
|
57
20
|
return;
|
|
58
21
|
}
|
|
59
|
-
|
|
60
|
-
try {
|
|
61
|
-
sandbox = await fleet.reattachSandbox(session.sandboxId, { actingUserId: session.userId });
|
|
62
|
-
} catch {}
|
|
63
|
-
await fleet.teardownSandbox({
|
|
64
|
-
sandboxId: session.sandboxId,
|
|
65
|
-
setSandboxId: async () => {},
|
|
66
|
-
clear: async () => {}
|
|
67
|
-
}, sandbox);
|
|
22
|
+
await (sandbox._stop ? sandbox._stop() : sandbox.stop?.());
|
|
68
23
|
}
|
|
69
24
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* its branch sessions stop receiving runs, so their VMs — which would
|
|
74
|
-
* otherwise idle until the provider reaps them — can serve the next session
|
|
75
|
-
* for the same repository instead of a fresh provision. Each session
|
|
76
|
-
* keeps its row (a reopened branch simply claims a pooled VM or provisions
|
|
77
|
-
* fresh on next use); it only loses its sandbox binding.
|
|
25
|
+
* Tear down the sandbox a just-deleted user session was holding. The row is
|
|
26
|
+
* already gone, so the VM is destroyed rather than stopped — nothing will
|
|
27
|
+
* ever resolve this session id again.
|
|
78
28
|
*/
|
|
79
|
-
async function
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
id: options.workItemId
|
|
29
|
+
async function reclaimDeletedSessionSandbox(options) {
|
|
30
|
+
await releaseSessionSandbox({
|
|
31
|
+
sessionId: options.session.id,
|
|
32
|
+
destroy: true
|
|
84
33
|
});
|
|
85
|
-
if (!item) return;
|
|
86
|
-
const sessionIds = [...new Set(Object.values(item.sessions).map((session) => session.sessionId))];
|
|
87
|
-
for (const sessionId of sessionIds) {
|
|
88
|
-
const session = await sourceControl.sessions.getBySessionId(sessionId);
|
|
89
|
-
if (!session || session.orgId !== options.orgId) continue;
|
|
90
|
-
if (!session.sandboxId || !session.sandboxWorkdir) continue;
|
|
91
|
-
await cleanReleasedSandbox({
|
|
92
|
-
fleet: options.fleet,
|
|
93
|
-
sourceControl,
|
|
94
|
-
orgId: session.orgId,
|
|
95
|
-
projectRepositoryId: session.projectRepositoryId,
|
|
96
|
-
sandboxId: session.sandboxId,
|
|
97
|
-
sandboxWorkdir: session.sandboxWorkdir,
|
|
98
|
-
actingUserId: session.userId
|
|
99
|
-
});
|
|
100
|
-
await sourceControl.sandboxPool.release({
|
|
101
|
-
orgId: session.orgId,
|
|
102
|
-
projectRepositoryId: session.projectRepositoryId,
|
|
103
|
-
userId: session.userId,
|
|
104
|
-
sandboxId: session.sandboxId,
|
|
105
|
-
sandboxWorkdir: session.sandboxWorkdir
|
|
106
|
-
});
|
|
107
|
-
await sourceControl.sessions.setSandbox({
|
|
108
|
-
id: session.id,
|
|
109
|
-
sandboxId: null,
|
|
110
|
-
sandboxWorkdir: session.sandboxWorkdir
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
34
|
}
|
|
114
35
|
//#endregion
|
|
115
|
-
export {
|
|
36
|
+
export { reclaimDeletedSessionSandbox, releaseSessionSandbox };
|
|
116
37
|
|
|
117
38
|
//# sourceMappingURL=sandbox-release.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sandbox-release.js","names":[],"sources":["../../../src/integrations/github/sandbox-release.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"sandbox-release.js","names":[],"sources":["../../../src/integrations/github/sandbox-release.ts"],"sourcesContent":["import { evictSessionSandbox, peekSessionSandbox } from '../../sandbox/session-sandbox.js';\n\n/**\n * Stop or destroy the sandbox a session holds in this process, dropping it\n * from the per-process memo first so later opens construct fresh.\n *\n * Sandbox identity is the session id, so there is no reuse pool to publish\n * into — a reopened session resolves the same id through its provider\n * (reconnect/resume, or a fresh VM whose setup hook re-materializes).\n * Sessions never opened in this replica have no memo entry; their VMs are\n * left to the provider's idle lifecycle (pause / idle GC).\n */\nexport async function releaseSessionSandbox(options: {\n /** The session's storage row id (the sandbox identity). */\n sessionId: string;\n /** Destroy instead of stop — for sessions that are gone for good. */\n destroy?: boolean;\n}): Promise<void> {\n const entry = peekSessionSandbox(options.sessionId);\n if (!entry) return;\n evictSessionSandbox(options.sessionId);\n const sandbox = entry.sandbox as unknown as {\n _stop?: () => Promise<void>;\n _destroy?: () => Promise<void>;\n stop?: () => Promise<void>;\n destroy?: () => Promise<void>;\n };\n if (options.destroy) {\n await (sandbox._destroy ? sandbox._destroy() : sandbox.destroy?.());\n return;\n }\n await (sandbox._stop ? sandbox._stop() : sandbox.stop?.());\n}\n\n/**\n * Tear down the sandbox a just-deleted user session was holding. The row is\n * already gone, so the VM is destroyed rather than stopped — nothing will\n * ever resolve this session id again.\n */\nexport async function reclaimDeletedSessionSandbox(options: {\n session: Pick<import('../../storage/domains/source-control/base.js').SourceControlSession, 'id'>;\n}): Promise<void> {\n await releaseSessionSandbox({ sessionId: options.session.id, destroy: true });\n}\n"],"mappings":";;;;;;;;;;;;AAYA,eAAsB,sBAAsB,SAK1B;CAChB,MAAM,QAAQ,mBAAmB,QAAQ,SAAS;CAClD,IAAI,CAAC,OAAO;CACZ,oBAAoB,QAAQ,SAAS;CACrC,MAAM,UAAU,MAAM;CAMtB,IAAI,QAAQ,SAAS;EACnB,OAAO,QAAQ,WAAW,QAAQ,SAAS,IAAI,QAAQ,UAAU;EACjE;CACF;CACA,OAAO,QAAQ,QAAQ,QAAQ,MAAM,IAAI,QAAQ,OAAO;AAC1D;;;;;;AAOA,eAAsB,6BAA6B,SAEjC;CAChB,MAAM,sBAAsB;EAAE,WAAW,QAAQ,QAAQ;EAAI,SAAS;CAAK,CAAC;AAC9E"}
|
|
@@ -1,57 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Repo materialization for GitHub-backed repositories.
|
|
3
3
|
*
|
|
4
|
-
* A GitHub repo is never cloned onto the server host.
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* tools then operate entirely against the remote checkout.
|
|
4
|
+
* A GitHub repo is never cloned onto the server host. The repo is cloned
|
|
5
|
+
* *inside* the session's sandbox, so the agent's file tools and command tools
|
|
6
|
+
* operate entirely against the remote checkout.
|
|
8
7
|
*
|
|
9
|
-
* - `ensureProjectSandbox(row)` / `teardownProjectSandbox(row)` bind the fleet's
|
|
10
|
-
* provision/reattach/teardown lifecycle to the per-(project,user) sandbox row.
|
|
11
8
|
* - `materializeRepo(row, token)` runs `git clone` (first open) or `git pull`
|
|
12
9
|
* (re-open) inside the sandbox, using a short-lived installation token that is
|
|
13
10
|
* scrubbed from the git remote afterwards so it never persists in the VM.
|
|
14
11
|
*
|
|
15
|
-
* This module owns everything git/GitHub: clone/pull, commit/push,
|
|
16
|
-
* and `gh pr create`.
|
|
17
|
-
* the fleet module.
|
|
12
|
+
* This module owns everything git/GitHub: clone/pull, commit/push, setup/teardown commands,
|
|
13
|
+
* and `gh pr create`. Workdir layout lives in `../sandbox/workdir`.
|
|
18
14
|
*/
|
|
19
|
-
import type {
|
|
20
|
-
import type {
|
|
21
|
-
type
|
|
22
|
-
type MaterializationStore = Pick<SourceControlSandboxStorage, 'markMaterialized'>;
|
|
15
|
+
import type { ExecutableSandbox, SandboxCommandResult } from '../../sandbox/materialization.js';
|
|
16
|
+
import type { SourceControlStorageHandle } from '../../storage/domains/source-control/base.js';
|
|
17
|
+
type MaterializationStore = Pick<SourceControlStorageHandle['sessions'], 'markMaterialized'>;
|
|
23
18
|
interface RepoMaterializationBinding {
|
|
24
19
|
id: string;
|
|
25
20
|
sandboxWorkdir: string;
|
|
26
21
|
materializedAt: Date | null;
|
|
27
22
|
}
|
|
28
|
-
/**
|
|
29
|
-
* Provision a new sandbox (persisting its provider id on first open) or
|
|
30
|
-
* reattach to the stored one. Returns a started, live sandbox.
|
|
31
|
-
*/
|
|
32
|
-
export declare function ensureProjectSandbox(options: {
|
|
33
|
-
fleet: SandboxFleet;
|
|
34
|
-
row: ProjectRepositorySandbox;
|
|
35
|
-
storage: SourceControlSandboxStorage;
|
|
36
|
-
token: string;
|
|
37
|
-
onProgress?: ProgressFn;
|
|
38
|
-
/** Repo base checkpoint to seed a fresh provision from (boot-only). */
|
|
39
|
-
seedCheckpointName?: string;
|
|
40
|
-
}): Promise<MaterializationSandbox>;
|
|
41
|
-
/**
|
|
42
|
-
* Tear down a user's sandbox for a project: stop the live VM (best-effort) and
|
|
43
|
-
* clear the persisted `sandboxId`/`materializedAt` on the per-(project,user)
|
|
44
|
-
* binding row so the next open re-provisions cleanly.
|
|
45
|
-
*
|
|
46
|
-
* @param row the per-(project,user) sandbox binding to tear down
|
|
47
|
-
* @param sandbox an already-reattached live sandbox to stop, when available
|
|
48
|
-
*/
|
|
49
|
-
export declare function teardownProjectSandbox(options: {
|
|
50
|
-
fleet: SandboxFleet;
|
|
51
|
-
row: ProjectRepositorySandbox;
|
|
52
|
-
storage: SourceControlSandboxStorage;
|
|
53
|
-
sandbox?: MaterializationSandbox;
|
|
54
|
-
}): Promise<void>;
|
|
55
23
|
/**
|
|
56
24
|
* Single-quote a string for safe POSIX shell interpolation. Wraps the value in
|
|
57
25
|
* single quotes and escapes any embedded single quote using the canonical
|
|
@@ -82,7 +50,7 @@ interface ShOptions {
|
|
|
82
50
|
* to re-run. Hang-guard timeouts are NOT retried — the budget applies to the
|
|
83
51
|
* command as a whole.
|
|
84
52
|
*/
|
|
85
|
-
export declare function sh(sandbox:
|
|
53
|
+
export declare function sh(sandbox: ExecutableSandbox, script: string, options?: ShOptions): Promise<SandboxCommandResult>;
|
|
86
54
|
/** Error raised when the sandbox cannot materialize the repo (actionable). */
|
|
87
55
|
export declare class MaterializeError extends Error {
|
|
88
56
|
readonly code: 'git-missing' | 'egress-blocked' | 'clone-failed' | 'pull-failed' | 'push-failed' | 'commit-failed' | 'gh-missing' | 'pr-failed';
|
|
@@ -95,47 +63,24 @@ export interface RepoMaterializeInfo {
|
|
|
95
63
|
}
|
|
96
64
|
/** Options for {@link materializeRepo}. */
|
|
97
65
|
export interface MaterializeRepoOptions {
|
|
98
|
-
/** The per-(project,user) sandbox binding
|
|
66
|
+
/** The per-(project,user) sandbox binding whose workdir this materializes into. */
|
|
99
67
|
row: RepoMaterializationBinding;
|
|
100
68
|
/** Repo metadata from the org-owned project row. */
|
|
101
69
|
repoInfo: RepoMaterializeInfo;
|
|
102
70
|
/** The live sandbox to run git inside. */
|
|
103
|
-
sandbox:
|
|
71
|
+
sandbox: ExecutableSandbox;
|
|
104
72
|
/** A freshly minted, short-lived installation access token. */
|
|
105
73
|
token: string;
|
|
106
74
|
storage: MaterializationStore;
|
|
107
|
-
onProgress?: ProgressFn;
|
|
108
|
-
/**
|
|
109
|
-
* Skip the default-branch `git pull --ff-only` when the workdir already
|
|
110
|
-
* holds a checkout. Set when the checkout was just seeded from a fresh base
|
|
111
|
-
* checkpoint (rebuilt on every default-branch push), where the pull is
|
|
112
|
-
* redundant network cost: session work happens on a branch that
|
|
113
|
-
* `checkoutSessionBranch` fetches fresh regardless.
|
|
114
|
-
*/
|
|
115
|
-
skipPullOnExistingCheckout?: boolean;
|
|
116
75
|
}
|
|
117
76
|
/**
|
|
118
77
|
* Materialize the repo inside the user's sandbox. Clones on first open, pulls on
|
|
119
78
|
* re-open. Always scrubs the install token from the remote afterwards and sets
|
|
120
79
|
* `materialized_at` on the per-user sandbox binding row.
|
|
121
|
-
*
|
|
122
80
|
*/
|
|
123
81
|
export declare function materializeRepo(options: MaterializeRepoOptions): Promise<void>;
|
|
124
|
-
/**
|
|
125
|
-
* Reset a pooled workdir that a new session just claimed: the previous
|
|
126
|
-
* session's branch and dirty state must not leak into the new session, so
|
|
127
|
-
* force-checkout the default branch, drop all local modifications, and delete
|
|
128
|
-
* every other local branch (a surviving branch would otherwise hand the next
|
|
129
|
-
* session for the same branch the previous session's stale tip instead of a
|
|
130
|
-
* fresh fork from the base branch). When the claimed VM was reaped and
|
|
131
|
-
* re-provisioned there is no checkout yet and this is a no-op (the clone path
|
|
132
|
-
* handles it). A wedged checkout falls back to wiping the workdir so
|
|
133
|
-
* `materializeRepo` re-clones inside the same VM instead of permanently
|
|
134
|
-
* failing the session.
|
|
135
|
-
*/
|
|
136
|
-
export declare function recycleClaimedWorkdir(sandbox: MaterializationSandbox, workdir: string, defaultBranch: string): Promise<void>;
|
|
137
82
|
/** Check out a session's branch inside its isolated repository clone. */
|
|
138
|
-
export declare function checkoutSessionBranch(sandbox:
|
|
83
|
+
export declare function checkoutSessionBranch(sandbox: ExecutableSandbox, workdir: string, options: {
|
|
139
84
|
branch: string;
|
|
140
85
|
baseBranch: string;
|
|
141
86
|
token: string;
|
|
@@ -146,7 +91,7 @@ export declare function checkoutSessionBranch(sandbox: MaterializationSandbox, w
|
|
|
146
91
|
* this exact repo. Matches both the clean and token-auth URL forms; any other
|
|
147
92
|
* remote (or no git dir at all) falls back to the clone path.
|
|
148
93
|
*/
|
|
149
|
-
export declare function hasExistingCheckout(sandbox:
|
|
94
|
+
export declare function hasExistingCheckout(sandbox: ExecutableSandbox, workdir: string, repoFullName: string): Promise<boolean>;
|
|
150
95
|
/**
|
|
151
96
|
* Validate a git ref (branch) name. Server-side defense-in-depth: only allow a
|
|
152
97
|
* conservative character set so a branch can never be built into a shell
|
|
@@ -173,7 +118,7 @@ export declare function resolveGitIdentity(identity: GitIdentity): {
|
|
|
173
118
|
* Configure `user.name` / `user.email` for the given repo working tree inside
|
|
174
119
|
* the sandbox so commits are authored correctly. Values are shell-quoted.
|
|
175
120
|
*/
|
|
176
|
-
export declare function configureGitIdentity(sandbox:
|
|
121
|
+
export declare function configureGitIdentity(sandbox: ExecutableSandbox, workdir: string, identity: GitIdentity): Promise<void>;
|
|
177
122
|
/**
|
|
178
123
|
* Temporarily rewrite `origin` to a tokenized URL, run `fn` (e.g. a push), and
|
|
179
124
|
* **always** scrub the remote back to the tokenless URL afterwards. The token
|
|
@@ -186,14 +131,14 @@ export declare function configureGitIdentity(sandbox: MaterializationSandbox, wo
|
|
|
186
131
|
* Only a failed set-url (the token never reached the remote) downgrades the
|
|
187
132
|
* scrub to best-effort.
|
|
188
133
|
*/
|
|
189
|
-
export declare function withInstallToken<T>(sandbox:
|
|
134
|
+
export declare function withInstallToken<T>(sandbox: ExecutableSandbox, workdir: string, repoFullName: string, token: string, fn: () => Promise<T>): Promise<T>;
|
|
190
135
|
/**
|
|
191
136
|
* Push a branch back to GitHub from inside the sandbox using a short-lived
|
|
192
137
|
* installation token. The branch is ref-validated, the token is injected only
|
|
193
138
|
* into the remote URL via `withInstallToken`, and egress failures are
|
|
194
139
|
* classified into actionable errors.
|
|
195
140
|
*/
|
|
196
|
-
export declare function pushBranch(sandbox:
|
|
141
|
+
export declare function pushBranch(sandbox: ExecutableSandbox, workdir: string, branch: string, token: string, repoFullName: string): Promise<void>;
|
|
197
142
|
export interface CommitResult {
|
|
198
143
|
/** True when a commit was created; false when there was nothing to commit. */
|
|
199
144
|
committed: boolean;
|
|
@@ -205,85 +150,26 @@ export interface CommitResult {
|
|
|
205
150
|
* error, so callers can safely commit-then-push without first diffing.
|
|
206
151
|
*
|
|
207
152
|
* @param sandbox the live sandbox containing the checkout
|
|
208
|
-
* @param workdir the
|
|
153
|
+
* @param workdir the session workdir to commit in
|
|
209
154
|
* @param message the commit message (quoted; arbitrary text is safe)
|
|
210
155
|
* @param identity authorship identity for the commit
|
|
211
156
|
*/
|
|
212
|
-
export declare function commitAll(sandbox:
|
|
213
|
-
/** Error raised when
|
|
214
|
-
export declare class
|
|
215
|
-
readonly code: '
|
|
216
|
-
constructor(message: string, code: '
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Reduce a (already ref-validated) branch name to a filesystem-safe directory
|
|
220
|
-
* segment for the worktree path: slashes/dots/unsafe chars collapsed to `-`.
|
|
221
|
-
* This only affects the *directory name*, never the git branch itself.
|
|
222
|
-
*
|
|
223
|
-
* Sanitization is lossy (e.g. `feat/a` and `feat-a` both reduce to `feat-a`),
|
|
224
|
-
* so an 8-char hash of the original branch is appended whenever the sanitized
|
|
225
|
-
* form differs from the input. That keeps clean names (`main`) readable while
|
|
226
|
-
* guaranteeing distinct branches never share a worktree directory.
|
|
227
|
-
*/
|
|
228
|
-
export declare function safeBranchDir(branch: string): string;
|
|
229
|
-
/**
|
|
230
|
-
* Compute the absolute worktree path for a branch, server-side only. Worktrees
|
|
231
|
-
* live alongside the repo checkout under a sibling `worktrees/` directory so the
|
|
232
|
-
* repo's `.git` is shared. Never derived from client-supplied paths.
|
|
233
|
-
*/
|
|
234
|
-
export declare function computeWorktreePath(repoWorkdir: string, branch: string): string;
|
|
235
|
-
export interface EnsureWorktreeResult {
|
|
236
|
-
worktreePath: string;
|
|
237
|
-
branch: string;
|
|
238
|
-
baseBranch: string;
|
|
239
|
-
/** True when an existing worktree was reused rather than freshly created. */
|
|
240
|
-
reused: boolean;
|
|
157
|
+
export declare function commitAll(sandbox: ExecutableSandbox, workdir: string, message: string, identity: GitIdentity): Promise<CommitResult>;
|
|
158
|
+
/** Error raised when the org's setup or teardown command fails in the sandbox. */
|
|
159
|
+
export declare class SetupCommandError extends Error {
|
|
160
|
+
readonly code: 'setup-failed' | 'teardown-failed';
|
|
161
|
+
constructor(message: string, code: 'setup-failed' | 'teardown-failed');
|
|
241
162
|
}
|
|
242
|
-
|
|
243
|
-
* Create (or reuse) a git worktree + branch inside the sandbox for a unit of
|
|
244
|
-
* work. Idempotent: if a worktree already exists at the computed path it is
|
|
245
|
-
* reused. The branch is created from the freshly fetched `origin/<baseBranch>`
|
|
246
|
-
* — never the sandbox's possibly stale local ref — so new worktrees always
|
|
247
|
-
* start from the latest remote state.
|
|
248
|
-
*
|
|
249
|
-
* @param sandbox live sandbox containing the base checkout
|
|
250
|
-
* @param repoWorkdir the base repo checkout path inside the sandbox
|
|
251
|
-
* @param branch the feature branch (ref-validated server-side)
|
|
252
|
-
* @param baseBranch the branch to fork from (ref-validated; defaults to the repo's default branch)
|
|
253
|
-
* @param token short-lived installation token used only for the base-branch fetch
|
|
254
|
-
* @param repoFullName `owner/repo` used to build the tokenized remote URL
|
|
255
|
-
*/
|
|
256
|
-
export declare function ensureWorktree(sandbox: MaterializationSandbox, repoWorkdir: string, { branch, baseBranch, token, repoFullName, }: {
|
|
257
|
-
branch: string;
|
|
258
|
-
baseBranch: string;
|
|
259
|
-
token: string;
|
|
260
|
-
repoFullName: string;
|
|
261
|
-
}): Promise<EnsureWorktreeResult>;
|
|
262
|
-
export declare function runWorktreeSetup(sandbox: MaterializationSandbox, worktreePath: string, command: string): Promise<void>;
|
|
163
|
+
export declare function runSetupCommand(sandbox: ExecutableSandbox, workdir: string, command: string): Promise<void>;
|
|
263
164
|
/**
|
|
264
165
|
* Run the repository's best-effort teardown command from the materialized
|
|
265
166
|
* session workdir. Callers own lifecycle policy: this helper reports failures
|
|
266
167
|
* so the retirement coordinator can log them while still continuing with
|
|
267
168
|
* scrub, pooling/destruction, cache invalidation, and row deletion.
|
|
268
169
|
*/
|
|
269
|
-
export declare function
|
|
170
|
+
export declare function runTeardownCommand(sandbox: ExecutableSandbox, workdir: string, command: string, options?: {
|
|
270
171
|
timeoutMs?: number;
|
|
271
172
|
}): Promise<void>;
|
|
272
|
-
/**
|
|
273
|
-
* Remove a worktree (and its local feature branch) from the sandbox. The
|
|
274
|
-
* checkout is removed with `--force` — the caller owns confirming that any
|
|
275
|
-
* uncommitted work in it can be discarded. Idempotent: a worktree whose
|
|
276
|
-
* directory is already gone only has its metadata pruned.
|
|
277
|
-
*
|
|
278
|
-
* @param sandbox live sandbox containing the base checkout
|
|
279
|
-
* @param repoWorkdir the base repo checkout path inside the sandbox
|
|
280
|
-
* @param branch the worktree's feature branch (ref-validated)
|
|
281
|
-
* @param worktreePath the persisted, server-computed worktree path
|
|
282
|
-
*/
|
|
283
|
-
export declare function removeWorktree(sandbox: MaterializationSandbox, repoWorkdir: string, { branch, worktreePath }: {
|
|
284
|
-
branch: string;
|
|
285
|
-
worktreePath: string;
|
|
286
|
-
}): Promise<void>;
|
|
287
173
|
export interface CreatePullRequestArgs {
|
|
288
174
|
/** Short-lived installation token, injected only into the `gh` process env. */
|
|
289
175
|
token: string;
|
|
@@ -309,6 +195,6 @@ export interface CreatePullRequestResult {
|
|
|
309
195
|
* @param sandbox live sandbox containing the checkout
|
|
310
196
|
* @param workdir the worktree (or repo) path the PR head branch is checked out in
|
|
311
197
|
*/
|
|
312
|
-
export declare function createPullRequest(sandbox:
|
|
198
|
+
export declare function createPullRequest(sandbox: ExecutableSandbox, workdir: string, { token, base, head, title, body }: CreatePullRequestArgs): Promise<CreatePullRequestResult>;
|
|
313
199
|
export {};
|
|
314
200
|
//# sourceMappingURL=sandbox.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../../../src/integrations/github/sandbox.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../../../src/integrations/github/sandbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAChG,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,8CAA8C,CAAC;AAG/F,KAAK,oBAAoB,GAAG,IAAI,CAAC,0BAA0B,CAAC,UAAU,CAAC,EAAE,kBAAkB,CAAC,CAAC;AAE7F,UAAU,0BAA0B;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,IAAI,GAAG,IAAI,CAAC;CAC7B;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAGhD;AAED;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,QAAc,CAAC;AACtD,4EAA4E;AAC5E,eAAO,MAAM,2BAA2B,QAAa,CAAC;AAEtD,UAAU,SAAS;IACjB,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAkBD;;;;;;GAMG;AACH,wBAAsB,EAAE,CAC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