@prestyj/cli 5.38.0 → 5.39.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 +92 -42
- package/dist/app-sidecar/fleet-adapter.d.ts +138 -0
- package/dist/app-sidecar/fleet-adapter.js +356 -0
- package/dist/app-sidecar/fleet-adapter.js.map +1 -0
- package/dist/app-sidecar/fleet-routes.d.ts +4 -0
- package/dist/app-sidecar/fleet-routes.js +109 -0
- package/dist/app-sidecar/fleet-routes.js.map +1 -0
- package/dist/app-sidecar/goal-routes.d.ts +20 -0
- package/dist/app-sidecar/goal-routes.js +42 -1
- package/dist/app-sidecar/goal-routes.js.map +1 -1
- package/dist/app-sidecar.js +5 -0
- package/dist/app-sidecar.js.map +1 -1
- package/dist/cli/cloud.d.ts +45 -0
- package/dist/cli/cloud.js +241 -0
- package/dist/cli/cloud.js.map +1 -0
- package/dist/cli/command-routing.d.ts +3 -2
- package/dist/cli/command-routing.js +24 -3
- package/dist/cli/command-routing.js.map +1 -1
- package/dist/cli/fleet.d.ts +19 -3
- package/dist/cli/fleet.js +107 -33
- package/dist/cli/fleet.js.map +1 -1
- package/dist/cli/goals.d.ts +11 -0
- package/dist/cli/goals.js +115 -0
- package/dist/cli/goals.js.map +1 -0
- package/dist/cli/node.d.ts +18 -1
- package/dist/cli/node.js +303 -33
- package/dist/cli/node.js.map +1 -1
- package/dist/cli.js +6 -0
- package/dist/cli.js.map +1 -1
- package/dist/core/agent-session.d.ts +8 -0
- package/dist/core/agent-session.js +18 -1
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/cloud/claude.d.ts +128 -0
- package/dist/core/cloud/claude.js +836 -0
- package/dist/core/cloud/claude.js.map +1 -0
- package/dist/core/cloud/cloud-agent.d.ts +136 -0
- package/dist/core/cloud/cloud-agent.js +783 -0
- package/dist/core/cloud/cloud-agent.js.map +1 -0
- package/dist/core/cloud/codex.d.ts +154 -0
- package/dist/core/cloud/codex.js +622 -0
- package/dist/core/cloud/codex.js.map +1 -0
- package/dist/core/cloud/config.d.ts +69 -0
- package/dist/core/cloud/config.js +86 -0
- package/dist/core/cloud/config.js.map +1 -0
- package/dist/core/cloud/git.d.ts +15 -0
- package/dist/core/cloud/git.js +33 -0
- package/dist/core/cloud/git.js.map +1 -0
- package/dist/core/cloud/registry.d.ts +13 -0
- package/dist/core/cloud/registry.js +64 -0
- package/dist/core/cloud/registry.js.map +1 -0
- package/dist/core/cloud/runner.d.ts +46 -0
- package/dist/core/cloud/runner.js +99 -0
- package/dist/core/cloud/runner.js.map +1 -0
- package/dist/core/cloud/snapshot.d.ts +23 -0
- package/dist/core/cloud/snapshot.js +98 -0
- package/dist/core/cloud/snapshot.js.map +1 -0
- package/dist/core/cloud/types.d.ts +139 -0
- package/dist/core/cloud/types.js +28 -0
- package/dist/core/cloud/types.js.map +1 -0
- package/dist/core/fleet/client.d.ts +106 -6
- package/dist/core/fleet/client.js +352 -20
- package/dist/core/fleet/client.js.map +1 -1
- package/dist/core/fleet/cloud-jobs.d.ts +59 -0
- package/dist/core/fleet/cloud-jobs.js +131 -0
- package/dist/core/fleet/cloud-jobs.js.map +1 -0
- package/dist/core/fleet/discovery.d.ts +2 -0
- package/dist/core/fleet/discovery.js +3 -1
- package/dist/core/fleet/discovery.js.map +1 -1
- package/dist/core/fleet/fleet-scheduler.d.ts +4 -0
- package/dist/core/fleet/fleet-scheduler.js +11 -1
- package/dist/core/fleet/fleet-scheduler.js.map +1 -1
- package/dist/core/fleet/git.d.ts +7 -0
- package/dist/core/fleet/git.js +22 -1
- package/dist/core/fleet/git.js.map +1 -1
- package/dist/core/fleet/machines.d.ts +112 -0
- package/dist/core/fleet/machines.js +219 -0
- package/dist/core/fleet/machines.js.map +1 -0
- package/dist/core/fleet/node/agents.d.ts +2 -0
- package/dist/core/fleet/node/agents.js +195 -9
- package/dist/core/fleet/node/agents.js.map +1 -1
- package/dist/core/fleet/node/config.d.ts +37 -3
- package/dist/core/fleet/node/config.js +201 -40
- package/dist/core/fleet/node/config.js.map +1 -1
- package/dist/core/fleet/node/context.d.ts +19 -1
- package/dist/core/fleet/node/docker.d.ts +13 -5
- package/dist/core/fleet/node/docker.js +132 -66
- package/dist/core/fleet/node/docker.js.map +1 -1
- package/dist/core/fleet/node/doctor.d.ts +29 -0
- package/dist/core/fleet/node/doctor.js +202 -0
- package/dist/core/fleet/node/doctor.js.map +1 -0
- package/dist/core/fleet/node/env.d.ts +7 -0
- package/dist/core/fleet/node/env.js +51 -0
- package/dist/core/fleet/node/env.js.map +1 -0
- package/dist/core/fleet/node/gc.d.ts +46 -0
- package/dist/core/fleet/node/gc.js +140 -0
- package/dist/core/fleet/node/gc.js.map +1 -0
- package/dist/core/fleet/node/goals.d.ts +43 -0
- package/dist/core/fleet/node/goals.js +418 -0
- package/dist/core/fleet/node/goals.js.map +1 -0
- package/dist/core/fleet/node/jobs.d.ts +37 -2
- package/dist/core/fleet/node/jobs.js +236 -15
- package/dist/core/fleet/node/jobs.js.map +1 -1
- package/dist/core/fleet/node/local-client.d.ts +9 -0
- package/dist/core/fleet/node/local-client.js +29 -0
- package/dist/core/fleet/node/local-client.js.map +1 -0
- package/dist/core/fleet/node/ops-routes.d.ts +15 -0
- package/dist/core/fleet/node/ops-routes.js +84 -0
- package/dist/core/fleet/node/ops-routes.js.map +1 -0
- package/dist/core/fleet/node/pair-code-route.d.ts +14 -0
- package/dist/core/fleet/node/pair-code-route.js +76 -0
- package/dist/core/fleet/node/pair-code-route.js.map +1 -0
- package/dist/core/fleet/node/secrets.d.ts +43 -0
- package/dist/core/fleet/node/secrets.js +184 -0
- package/dist/core/fleet/node/secrets.js.map +1 -0
- package/dist/core/fleet/node/server.d.ts +22 -1
- package/dist/core/fleet/node/server.js +210 -21
- package/dist/core/fleet/node/server.js.map +1 -1
- package/dist/core/fleet/node/state.d.ts +24 -1
- package/dist/core/fleet/node/state.js +12 -3
- package/dist/core/fleet/node/state.js.map +1 -1
- package/dist/core/fleet/node/tls.d.ts +17 -0
- package/dist/core/fleet/node/tls.js +49 -0
- package/dist/core/fleet/node/tls.js.map +1 -0
- package/dist/core/fleet/node/uninstall.d.ts +27 -0
- package/dist/core/fleet/node/uninstall.js +100 -0
- package/dist/core/fleet/node/uninstall.js.map +1 -0
- package/dist/core/fleet/node/update.d.ts +28 -0
- package/dist/core/fleet/node/update.js +62 -0
- package/dist/core/fleet/node/update.js.map +1 -0
- package/dist/core/fleet/node/workspace.d.ts +4 -0
- package/dist/core/fleet/node/workspace.js +38 -9
- package/dist/core/fleet/node/workspace.js.map +1 -1
- package/dist/core/fleet/node-load.d.ts +4 -0
- package/dist/core/fleet/node-load.js +62 -0
- package/dist/core/fleet/node-load.js.map +1 -0
- package/dist/core/fleet/project-config.d.ts +10 -0
- package/dist/core/fleet/project-config.js +39 -1
- package/dist/core/fleet/project-config.js.map +1 -1
- package/dist/core/fleet/prompt-hint.d.ts +11 -0
- package/dist/core/fleet/prompt-hint.js +47 -0
- package/dist/core/fleet/prompt-hint.js.map +1 -0
- package/dist/core/fleet/propose-config.d.ts +26 -0
- package/dist/core/fleet/propose-config.js +95 -0
- package/dist/core/fleet/propose-config.js.map +1 -0
- package/dist/core/fleet/protocol.d.ts +97 -1
- package/dist/core/fleet/protocol.js +10 -1
- package/dist/core/fleet/protocol.js.map +1 -1
- package/dist/core/fleet/registry.d.ts +12 -1
- package/dist/core/fleet/registry.js +39 -7
- package/dist/core/fleet/registry.js.map +1 -1
- package/dist/core/fleet/remote-agent-nodes.d.ts +56 -8
- package/dist/core/fleet/remote-agent-nodes.js +162 -22
- package/dist/core/fleet/remote-agent-nodes.js.map +1 -1
- package/dist/core/fleet/remote-agent.d.ts +52 -1
- package/dist/core/fleet/remote-agent.js +220 -40
- package/dist/core/fleet/remote-agent.js.map +1 -1
- package/dist/core/fleet/service.d.ts +95 -3
- package/dist/core/fleet/service.js +762 -35
- package/dist/core/fleet/service.js.map +1 -1
- package/dist/core/fleet/store.js +22 -5
- package/dist/core/fleet/store.js.map +1 -1
- package/dist/core/fleet/types.d.ts +36 -1
- package/dist/core/fleet/types.js +12 -2
- package/dist/core/fleet/types.js.map +1 -1
- package/dist/core/goal-controller.d.ts +1 -0
- package/dist/core/goal-controller.js +1 -1
- package/dist/core/goal-controller.js.map +1 -1
- package/dist/core/goal-fleet.d.ts +117 -0
- package/dist/core/goal-fleet.js +441 -0
- package/dist/core/goal-fleet.js.map +1 -0
- package/dist/core/goal-headless.d.ts +45 -0
- package/dist/core/goal-headless.js +177 -0
- package/dist/core/goal-headless.js.map +1 -0
- package/dist/core/goal-remote-worker.d.ts +45 -0
- package/dist/core/goal-remote-worker.js +157 -0
- package/dist/core/goal-remote-worker.js.map +1 -0
- package/dist/core/goal-store.d.ts +36 -0
- package/dist/core/goal-store.js +69 -1
- package/dist/core/goal-store.js.map +1 -1
- package/dist/core/goal-verifier.d.ts +5 -0
- package/dist/core/goal-verifier.js +10 -0
- package/dist/core/goal-verifier.js.map +1 -1
- package/dist/core/goal-worker.d.ts +12 -0
- package/dist/core/goal-worker.js +162 -8
- package/dist/core/goal-worker.js.map +1 -1
- package/dist/core/subagent-manager.d.ts +12 -5
- package/dist/core/subagent-manager.js +15 -10
- package/dist/core/subagent-manager.js.map +1 -1
- package/dist/core/validation/backends.d.ts +34 -5
- package/dist/core/validation/backends.js +45 -5
- package/dist/core/validation/backends.js.map +1 -1
- package/dist/core/validation/cloud-backend.d.ts +77 -0
- package/dist/core/validation/cloud-backend.js +343 -0
- package/dist/core/validation/cloud-backend.js.map +1 -0
- package/dist/core/validation/config.js +9 -2
- package/dist/core/validation/config.js.map +1 -1
- package/dist/core/validation/node-backend.d.ts +2 -0
- package/dist/core/validation/node-backend.js +5 -0
- package/dist/core/validation/node-backend.js.map +1 -1
- package/dist/core/validation/scheduler.d.ts +11 -0
- package/dist/core/validation/scheduler.js +34 -7
- package/dist/core/validation/scheduler.js.map +1 -1
- package/dist/core/validation/service.d.ts +6 -0
- package/dist/core/validation/service.js +51 -13
- package/dist/core/validation/service.js.map +1 -1
- package/dist/core/validation/types.d.ts +14 -0
- package/dist/modes/acp-mode.d.ts +3 -1
- package/dist/modes/acp-mode.js +2 -1
- package/dist/modes/acp-mode.js.map +1 -1
- package/dist/system-prompt.d.ts +5 -0
- package/dist/system-prompt.js +3 -0
- package/dist/system-prompt.js.map +1 -1
- package/dist/tools/fleet.d.ts +40 -4
- package/dist/tools/fleet.js +228 -17
- package/dist/tools/fleet.js.map +1 -1
- package/dist/tools/goals.d.ts +4 -1
- package/dist/tools/goals.js +45 -5
- package/dist/tools/goals.js.map +1 -1
- package/dist/tools/index.d.ts +7 -0
- package/dist/tools/index.js +6 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/steroids.d.ts +1 -1
- package/dist/tools/subagent-control.js +1 -1
- package/dist/tools/subagent-control.js.map +1 -1
- package/dist/tools/validate.js +1 -1
- package/dist/tools/validate.js.map +1 -1
- package/dist/ui/App.js +2 -0
- package/dist/ui/App.js.map +1 -1
- package/package.json +6 -4
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { CloudProviderId } from "./types.js";
|
|
2
|
+
export type CloudUse = "validation" | "jobs" | "agents";
|
|
3
|
+
export interface CloudProviderSettings {
|
|
4
|
+
/** false turns this provider off (default: on when signed in). */
|
|
5
|
+
enabled?: boolean;
|
|
6
|
+
/** Max tasks at once on this provider (default 3). */
|
|
7
|
+
maxConcurrent?: number;
|
|
8
|
+
/** Model for runner/validation tasks (cheapest capable by default). */
|
|
9
|
+
runnerModel?: string;
|
|
10
|
+
/** Environment to use (Claude env_…, Codex environment id); auto when absent. */
|
|
11
|
+
environment?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface CloudSettings {
|
|
14
|
+
/** false turns cloud off entirely. */
|
|
15
|
+
enabled?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* When cloud gets work:
|
|
18
|
+
* - "overflow" (default): only when no self-hosted machine has room (busy, full or offline)
|
|
19
|
+
* - "always": as one more machine, by load
|
|
20
|
+
* - "manual": only when a stage/job/agent names it
|
|
21
|
+
*/
|
|
22
|
+
when?: "overflow" | "always" | "manual";
|
|
23
|
+
/** What cloud may run (default: all three). */
|
|
24
|
+
use?: CloudUse[];
|
|
25
|
+
/** Stop sending work when weekly plan utilization passes this (0-1, default 0.8). */
|
|
26
|
+
maxPlanUtilization?: number;
|
|
27
|
+
providers?: Partial<Record<CloudProviderId, CloudProviderSettings>>;
|
|
28
|
+
/**
|
|
29
|
+
* Which provider gets work first when several can take it (default: Codex,
|
|
30
|
+
* then Claude, to save the Claude plan for interactive coding). Validation
|
|
31
|
+
* and jobs still only go to providers whose results can be verified.
|
|
32
|
+
*/
|
|
33
|
+
order?: CloudProviderId[];
|
|
34
|
+
}
|
|
35
|
+
/** Default preference: Codex first, saving the Claude plan for coding. */
|
|
36
|
+
export declare const DEFAULT_CLOUD_ORDER: readonly CloudProviderId[];
|
|
37
|
+
/** Provider ids in preference order: the user's order, then any left out. */
|
|
38
|
+
export declare function providerOrder(settings: CloudSettings): CloudProviderId[];
|
|
39
|
+
export declare const DEFAULT_CLOUD_MAX_CONCURRENT = 3;
|
|
40
|
+
export declare const DEFAULT_MAX_PLAN_UTILIZATION = 0.8;
|
|
41
|
+
export declare function cloudDir(): string;
|
|
42
|
+
export declare function cloudSettingsFile(): string;
|
|
43
|
+
export declare function readCloudSettings(file?: string): CloudSettings;
|
|
44
|
+
/** Save the settings atomically (temp file + rename). */
|
|
45
|
+
export declare function writeCloudSettings(settings: CloudSettings, file?: string): void;
|
|
46
|
+
export declare function cloudAllowedFor(settings: CloudSettings, use: CloudUse): boolean;
|
|
47
|
+
export declare function providerSettings(settings: CloudSettings, id: CloudProviderId): CloudProviderSettings & {
|
|
48
|
+
maxConcurrent: number;
|
|
49
|
+
};
|
|
50
|
+
/** Runtime state that must survive restarts (benches after usage limits). */
|
|
51
|
+
export interface CloudState {
|
|
52
|
+
/** Provider benched until (ISO), with the reason. */
|
|
53
|
+
benched?: Partial<Record<CloudProviderId, {
|
|
54
|
+
until: string;
|
|
55
|
+
reason: string;
|
|
56
|
+
}>>;
|
|
57
|
+
/** Last plan utilization seen per provider (0-1) and when. */
|
|
58
|
+
utilization?: Partial<Record<CloudProviderId, {
|
|
59
|
+
value: number;
|
|
60
|
+
at: string;
|
|
61
|
+
resetsAt?: string;
|
|
62
|
+
}>>;
|
|
63
|
+
}
|
|
64
|
+
export declare function readCloudState(): CloudState;
|
|
65
|
+
export declare function updateCloudState(update: (s: CloudState) => CloudState): CloudState;
|
|
66
|
+
/** Bench a provider (usage limit hit) until `until`. */
|
|
67
|
+
export declare function benchProvider(id: CloudProviderId, until: string, reason: string): void;
|
|
68
|
+
export declare function benchedUntil(id: CloudProviderId, now?: number): string | undefined;
|
|
69
|
+
export declare function recordUtilization(id: CloudProviderId, value: number, resetsAt?: string): void;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// User-level cloud settings (~/.ezcoder/cloud.json) and runtime state
|
|
2
|
+
// (~/.ezcoder/cloud/state.json). Zero config by default: every provider the
|
|
3
|
+
// user is signed in to is used automatically, as overflow capacity only.
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { getAppPaths } from "@prestyj/core";
|
|
7
|
+
/** Default preference: Codex first, saving the Claude plan for coding. */
|
|
8
|
+
export const DEFAULT_CLOUD_ORDER = ["codex-cloud", "claude-cloud"];
|
|
9
|
+
/** Provider ids in preference order: the user's order, then any left out. */
|
|
10
|
+
export function providerOrder(settings) {
|
|
11
|
+
const out = [];
|
|
12
|
+
for (const id of [...(settings.order ?? []), ...DEFAULT_CLOUD_ORDER]) {
|
|
13
|
+
if (DEFAULT_CLOUD_ORDER.includes(id) && !out.includes(id))
|
|
14
|
+
out.push(id);
|
|
15
|
+
}
|
|
16
|
+
return out;
|
|
17
|
+
}
|
|
18
|
+
export const DEFAULT_CLOUD_MAX_CONCURRENT = 3;
|
|
19
|
+
export const DEFAULT_MAX_PLAN_UTILIZATION = 0.8;
|
|
20
|
+
export function cloudDir() {
|
|
21
|
+
return path.join(getAppPaths().agentDir, "cloud");
|
|
22
|
+
}
|
|
23
|
+
export function cloudSettingsFile() {
|
|
24
|
+
return path.join(getAppPaths().agentDir, "cloud.json");
|
|
25
|
+
}
|
|
26
|
+
export function readCloudSettings(file = cloudSettingsFile()) {
|
|
27
|
+
try {
|
|
28
|
+
return JSON.parse(fs.readFileSync(file, "utf8"));
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** Save the settings atomically (temp file + rename). */
|
|
35
|
+
export function writeCloudSettings(settings, file = cloudSettingsFile()) {
|
|
36
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
37
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
38
|
+
fs.writeFileSync(tmp, JSON.stringify(settings, null, 2) + "\n");
|
|
39
|
+
fs.renameSync(tmp, file);
|
|
40
|
+
}
|
|
41
|
+
export function cloudAllowedFor(settings, use) {
|
|
42
|
+
if (settings.enabled === false)
|
|
43
|
+
return false;
|
|
44
|
+
return (settings.use ?? ["validation", "jobs", "agents"]).includes(use);
|
|
45
|
+
}
|
|
46
|
+
export function providerSettings(settings, id) {
|
|
47
|
+
const p = settings.providers?.[id] ?? {};
|
|
48
|
+
return { ...p, maxConcurrent: Math.max(1, p.maxConcurrent ?? DEFAULT_CLOUD_MAX_CONCURRENT) };
|
|
49
|
+
}
|
|
50
|
+
function stateFile() {
|
|
51
|
+
return path.join(cloudDir(), "state.json");
|
|
52
|
+
}
|
|
53
|
+
export function readCloudState() {
|
|
54
|
+
try {
|
|
55
|
+
return JSON.parse(fs.readFileSync(stateFile(), "utf8"));
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return {};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export function updateCloudState(update) {
|
|
62
|
+
const next = update(readCloudState());
|
|
63
|
+
fs.mkdirSync(cloudDir(), { recursive: true });
|
|
64
|
+
const tmp = `${stateFile()}.${process.pid}.tmp`;
|
|
65
|
+
fs.writeFileSync(tmp, JSON.stringify(next, null, 2) + "\n");
|
|
66
|
+
fs.renameSync(tmp, stateFile());
|
|
67
|
+
return next;
|
|
68
|
+
}
|
|
69
|
+
/** Bench a provider (usage limit hit) until `until`. */
|
|
70
|
+
export function benchProvider(id, until, reason) {
|
|
71
|
+
updateCloudState((s) => ({ ...s, benched: { ...s.benched, [id]: { until, reason } } }));
|
|
72
|
+
}
|
|
73
|
+
export function benchedUntil(id, now = Date.now()) {
|
|
74
|
+
const b = readCloudState().benched?.[id];
|
|
75
|
+
return b && Date.parse(b.until) > now ? b.until : undefined;
|
|
76
|
+
}
|
|
77
|
+
export function recordUtilization(id, value, resetsAt) {
|
|
78
|
+
updateCloudState((s) => ({
|
|
79
|
+
...s,
|
|
80
|
+
utilization: {
|
|
81
|
+
...s.utilization,
|
|
82
|
+
[id]: { value, at: new Date().toISOString(), ...(resetsAt && { resetsAt }) },
|
|
83
|
+
},
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/core/cloud/config.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,4EAA4E;AAC5E,yEAAyE;AACzE,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAuC5C,0EAA0E;AAC1E,MAAM,CAAC,MAAM,mBAAmB,GAA+B,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;AAE/F,6EAA6E;AAC7E,MAAM,UAAU,aAAa,CAAC,QAAuB;IACnD,MAAM,GAAG,GAAsB,EAAE,CAAC;IAClC,KAAK,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE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@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface GitResult {
|
|
2
|
+
code: number;
|
|
3
|
+
stdout: Buffer;
|
|
4
|
+
stderr: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function runGit(cwd: string, args: string[], options?: {
|
|
7
|
+
env?: NodeJS.ProcessEnv;
|
|
8
|
+
input?: Buffer;
|
|
9
|
+
}): Promise<GitResult>;
|
|
10
|
+
export declare function git(cwd: string, args: string[], options?: {
|
|
11
|
+
env?: NodeJS.ProcessEnv;
|
|
12
|
+
input?: Buffer;
|
|
13
|
+
}): Promise<string>;
|
|
14
|
+
/** owner/name from a GitHub remote URL, else undefined. */
|
|
15
|
+
export declare function githubRepoFromUrl(url: string): string | undefined;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Small git helpers for cloud tasks (no shell; binary-safe).
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
export function runGit(cwd, args, options = {}) {
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
const child = spawn("git", args, {
|
|
6
|
+
cwd,
|
|
7
|
+
env: options.env ?? process.env,
|
|
8
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
9
|
+
windowsHide: true,
|
|
10
|
+
});
|
|
11
|
+
const out = [];
|
|
12
|
+
let stderr = "";
|
|
13
|
+
child.stdout.on("data", (chunk) => out.push(chunk));
|
|
14
|
+
child.stderr.on("data", (chunk) => (stderr += chunk.toString()));
|
|
15
|
+
child.on("error", reject);
|
|
16
|
+
child.on("close", (code) => resolve({ code: code ?? 1, stdout: Buffer.concat(out), stderr }));
|
|
17
|
+
child.stdin.on("error", () => { });
|
|
18
|
+
child.stdin.end(options.input);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
export async function git(cwd, args, options = {}) {
|
|
22
|
+
const result = await runGit(cwd, args, options);
|
|
23
|
+
if (result.code !== 0) {
|
|
24
|
+
throw new Error(`git ${args[0]} failed: ${result.stderr.trim() || `exit ${result.code}`}`);
|
|
25
|
+
}
|
|
26
|
+
return result.stdout.toString("utf-8");
|
|
27
|
+
}
|
|
28
|
+
/** owner/name from a GitHub remote URL, else undefined. */
|
|
29
|
+
export function githubRepoFromUrl(url) {
|
|
30
|
+
const m = /github\.com[/:]([^/\s]+)\/([^/\s]+?)(?:\.git)?\/?$/i.exec(url.trim());
|
|
31
|
+
return m ? `${m[1]}/${m[2]}` : undefined;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=git.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git.js","sourceRoot":"","sources":["../../../src/core/cloud/git.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAQ3C,MAAM,UAAU,MAAM,CACpB,GAAW,EACX,IAAc,EACd,UAAuD,EAAE;IAEzD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE;YAC/B,GAAG;YACH,GAAG,EAAE,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG;YAC/B,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;YAC/B,WAAW,EAAE,IAAI;SAClB,CAAC,CAAC;QACH,MAAM,GAAG,GAAa,EAAE,CAAC;QACzB,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAC5D,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;QACzE,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,M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CloudUse } from "./config.js";
|
|
2
|
+
import { type CloudAvailability, type CloudProvider, type CloudProviderId } from "./types.js";
|
|
3
|
+
/** Overridable for tests. */
|
|
4
|
+
export declare function setCloudProvidersForTest(providers: CloudProvider[] | undefined): void;
|
|
5
|
+
export declare function cloudProvider(id: CloudProviderId): CloudProvider;
|
|
6
|
+
/**
|
|
7
|
+
* Every provider with its availability for `use` (and project), in
|
|
8
|
+
* preference order (`order` in cloud.json; Codex first by default). Never throws: problems become `detail`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function cloudAvailability(use: CloudUse, project?: {
|
|
11
|
+
repoRoot?: string;
|
|
12
|
+
repo?: string;
|
|
13
|
+
}, settings?: CloudSettings): Promise<CloudAvailability[]>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// The cloud providers EZ Coder can use. Auto-managed: a provider is available
|
|
2
|
+
// when the user is signed in to it in EZ Coder (Claude subscription / ChatGPT
|
|
3
|
+
// sign-in), it isn't turned off, it isn't benched after a usage limit, and its
|
|
4
|
+
// plan utilization is under the cap. Callers never name providers they don't
|
|
5
|
+
// need: validation, fleet jobs and agents all ask here.
|
|
6
|
+
import { benchedUntil, cloudAllowedFor, DEFAULT_MAX_PLAN_UTILIZATION, providerOrder, providerSettings, readCloudSettings, readCloudState, } from "./config.js";
|
|
7
|
+
import { ClaudeCloudProvider } from "./claude.js";
|
|
8
|
+
import { CodexCloudProvider } from "./codex.js";
|
|
9
|
+
import { CLOUD_LABELS, } from "./types.js";
|
|
10
|
+
let cached;
|
|
11
|
+
/** Overridable for tests. */
|
|
12
|
+
export function setCloudProvidersForTest(providers) {
|
|
13
|
+
cached = providers ? new Map(providers.map((p) => [p.id, p])) : undefined;
|
|
14
|
+
}
|
|
15
|
+
export function cloudProvider(id) {
|
|
16
|
+
cached ??= new Map([
|
|
17
|
+
["claude-cloud", new ClaudeCloudProvider()],
|
|
18
|
+
["codex-cloud", new CodexCloudProvider()],
|
|
19
|
+
]);
|
|
20
|
+
return cached.get(id);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Every provider with its availability for `use` (and project), in
|
|
24
|
+
* preference order (`order` in cloud.json; Codex first by default). Never throws: problems become `detail`.
|
|
25
|
+
*/
|
|
26
|
+
export async function cloudAvailability(use, project, settings = readCloudSettings()) {
|
|
27
|
+
const allowed = cloudAllowedFor(settings, use);
|
|
28
|
+
const cap = settings.maxPlanUtilization ?? DEFAULT_MAX_PLAN_UTILIZATION;
|
|
29
|
+
const state = readCloudState();
|
|
30
|
+
return Promise.all(providerOrder(settings).map(async (id) => {
|
|
31
|
+
if (!allowed) {
|
|
32
|
+
return { id, available: false, detail: `cloud is off for ${use} (~/.ezcoder/cloud.json)` };
|
|
33
|
+
}
|
|
34
|
+
if (providerSettings(settings, id).enabled === false) {
|
|
35
|
+
return { id, available: false, detail: `${CLOUD_LABELS[id]} is turned off` };
|
|
36
|
+
}
|
|
37
|
+
const until = benchedUntil(id);
|
|
38
|
+
if (until) {
|
|
39
|
+
const reason = state.benched?.[id]?.reason ?? "usage limit";
|
|
40
|
+
return {
|
|
41
|
+
id,
|
|
42
|
+
available: false,
|
|
43
|
+
limitedUntil: until,
|
|
44
|
+
detail: `${reason}; paused until ${new Date(until).toLocaleString()}`,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const util = state.utilization?.[id];
|
|
48
|
+
if (util && util.value >= cap && (!util.resetsAt || Date.parse(util.resetsAt) > Date.now())) {
|
|
49
|
+
return {
|
|
50
|
+
id,
|
|
51
|
+
available: false,
|
|
52
|
+
...(util.resetsAt && { limitedUntil: util.resetsAt }),
|
|
53
|
+
detail: `plan ${Math.round(util.value * 100)}% used (cap ${Math.round(cap * 100)}%), saving the rest for you`,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
return await cloudProvider(id).detect(project);
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
return { id, available: false, detail: e instanceof Error ? e.message : String(e) };
|
|
61
|
+
}
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/core/cloud/registry.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,8EAA8E;AAC9E,+EAA+E;AAC/E,6EAA6E;AAC7E,wDAAwD;AACxD,OAAO,EACL,YAAY,EACZ,eAAe,EACf,4BAA4B,EAC5B,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,GAGf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EACL,YAAY,GAIb,MAAM,YAAY,CAAC;AAEpB,IAAI,MAAuD,CAAC;AAE5D,6BAA6B;AAC7B,MAAM,UAAU,wBAAwB,CAAC,SAAsC;IAC7E,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC5E,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,EAAmB;IAC/C,MAAM,KAAK,IAAI,GAAG,CAAiC;QACjD,CAAC,cAAc,EAAE,IAAI,mBAAmB,EAAE,CAAC;QAC3C,CAAC,aAAa,EAAE,IAAI,kBAAkB,EAAE,CAAC;KAC1C,CAAC,CAAC;IACH,OAAO,MAAM,CAAC,GAAG,CAAC,EAAE,CAAE,CAAC;AACzB,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,GAAa,EACb,OAA8C,EAC9C,WAA0B,iBAAiB,EAAE;IAE7C,MAAM,OAAO,GAAG,eAAe,CAAC,QAAQ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,CAAC,EAAE,CAAC;YAC5F,OAAO;gBACL,EAAE;gBACF,SAAS,EAAE,KAAK;gBAChB,GAAG,CAAC,IAAI,CAAC,QAAQ,IAAI,EAAE,YAAY,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACrD,MAAM,EAAE,QAAQ,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC,eAAe,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,CAAC,6BAA6B;aAC9G,CAAC;QACJ,CAAC;QACD,IAAI,CAAC;YACH,OAAO,MAAM,aAAa,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACjD,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;QACtF,CAAC;IACH,CAAC,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { CloudCommandRecord } from "./types.js";
|
|
2
|
+
export declare const RESULT_MARKER = "EZCLOUD-RESULT";
|
|
3
|
+
/** Bytes of log the command prints back (the harness keeps the tail). */
|
|
4
|
+
export declare const LOG_TAIL_BYTES = 40000;
|
|
5
|
+
export interface RunnerSpec {
|
|
6
|
+
/** Job id (letters, digits, - and _ only). */
|
|
7
|
+
jobId: string;
|
|
8
|
+
/** Tree hash the working copy must have before the command runs. */
|
|
9
|
+
tree: string;
|
|
10
|
+
/** Shell command of the stage/job. */
|
|
11
|
+
command: string;
|
|
12
|
+
timeoutMinutes: number;
|
|
13
|
+
/**
|
|
14
|
+
* Run the command as an unprivileged user (created in the sandbox).
|
|
15
|
+
* Default off: sandboxes run as root, and the sandbox's model refused to
|
|
16
|
+
* create users and change ownership when asked to (measured live). Root
|
|
17
|
+
* ignores file permissions, so permission tests can fail there.
|
|
18
|
+
*/
|
|
19
|
+
nonRoot?: boolean;
|
|
20
|
+
/** Start the sandbox's Docker daemon first (stages/jobs that use Docker). */
|
|
21
|
+
docker?: boolean;
|
|
22
|
+
/** Folder of the checkout in the sandbox ("" = current directory). */
|
|
23
|
+
dir?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface RunnerResult {
|
|
26
|
+
verdict: "done" | "wrong-tree" | "timeout";
|
|
27
|
+
exitCode?: number;
|
|
28
|
+
/** Tree the sandbox actually had. */
|
|
29
|
+
tree?: string;
|
|
30
|
+
seconds?: number;
|
|
31
|
+
/** Log tail printed by the command (without the marker line). */
|
|
32
|
+
log: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The exact command line for the sandbox. Self-contained: it checks the tree,
|
|
36
|
+
* runs the stage with a timeout, prints the log tail and the marker line.
|
|
37
|
+
*/
|
|
38
|
+
export declare function runnerCommand(spec: RunnerSpec): string;
|
|
39
|
+
/** The instruction for the sandbox's model. */
|
|
40
|
+
export declare function runnerPrompt(command: string, timeoutMinutes: number): string;
|
|
41
|
+
/**
|
|
42
|
+
* Find the harness record of `command` and read the marker for `jobId`.
|
|
43
|
+
* Undefined when the sandbox never ran that exact command (or its output has
|
|
44
|
+
* no marker for this job): the result is then unverified and must not count.
|
|
45
|
+
*/
|
|
46
|
+
export declare function verifyRunnerResult(records: readonly CloudCommandRecord[], command: string, jobId: string): RunnerResult | undefined;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
export const RESULT_MARKER = "EZCLOUD-RESULT";
|
|
2
|
+
/** Bytes of log the command prints back (the harness keeps the tail). */
|
|
3
|
+
export const LOG_TAIL_BYTES = 40_000;
|
|
4
|
+
const SAFE_ID = /^[A-Za-z0-9_-]{1,80}$/;
|
|
5
|
+
function shellQuote(value) {
|
|
6
|
+
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The exact command line for the sandbox. Self-contained: it checks the tree,
|
|
10
|
+
* runs the stage with a timeout, prints the log tail and the marker line.
|
|
11
|
+
*/
|
|
12
|
+
export function runnerCommand(spec) {
|
|
13
|
+
if (!SAFE_ID.test(spec.jobId))
|
|
14
|
+
throw new Error(`unsafe job id: ${spec.jobId}`);
|
|
15
|
+
if (!/^[0-9a-f]{40,64}$/.test(spec.tree))
|
|
16
|
+
throw new Error(`bad tree hash: ${spec.tree}`);
|
|
17
|
+
const minutes = Math.max(1, Math.ceil(spec.timeoutMinutes));
|
|
18
|
+
const log = `/tmp/ezcloud-${spec.jobId}.log`;
|
|
19
|
+
const marker = (fields) => `printf '%s {"job":"%s",${fields}}\\n' ${RESULT_MARKER} ${spec.jobId}`;
|
|
20
|
+
const script = [
|
|
21
|
+
spec.dir ? `cd ${shellQuote(spec.dir)} || exit 0` : "",
|
|
22
|
+
// Tree of the working copy as it is (tracked + untracked, not ignored).
|
|
23
|
+
// A private index (fixed path; an empty mktemp file is not a valid index)
|
|
24
|
+
// seeded from HEAD, so tracked files that match .gitignore stay in the
|
|
25
|
+
// tree; add -A then folds in every edit, removal and untracked file. No
|
|
26
|
+
// rm: rm makes the sandbox ask for permission.
|
|
27
|
+
`export GIT_INDEX_FILE=/tmp/ezcloud-${spec.jobId}.index; git read-tree HEAD 2>/dev/null || git read-tree --empty; git add -A >/dev/null 2>&1; got=$(git write-tree 2>/dev/null); unset GIT_INDEX_FILE`,
|
|
28
|
+
`if [ "$got" != "${spec.tree}" ]; then ${marker(`"verdict":"wrong-tree","tree":"%s"`)} "$got"; exit 0; fi`,
|
|
29
|
+
`start=$(date +%s)`,
|
|
30
|
+
// Cloud sandboxes ship the docker CLI but no running daemon; root can start one (~5 s).
|
|
31
|
+
spec.docker
|
|
32
|
+
? `if ! docker info >/dev/null 2>&1; then (sudo -n dockerd >/tmp/ezcloud-dockerd.log 2>&1 &); for i in $(seq 1 60); do docker info >/dev/null 2>&1 && break; sleep 1; done; sudo -n chmod 666 /var/run/docker.sock 2>/dev/null; fi`
|
|
33
|
+
: "",
|
|
34
|
+
!spec.nonRoot
|
|
35
|
+
? `runas=""`
|
|
36
|
+
: `runas=""; if [ "$(id -u)" = 0 ]; then id ezrun >/dev/null 2>&1 || useradd -m -s /bin/bash ezrun >/dev/null 2>&1; if id ezrun >/dev/null 2>&1; then chown -R ezrun "$PWD"; runas="sudo -u ezrun -H --preserve-env=PATH,CI"; fi; fi`,
|
|
37
|
+
`timeout --kill-after=30 ${minutes}m $runas bash -c ${shellQuote(spec.command)} > ${log} 2>&1 < /dev/null; code=$?`,
|
|
38
|
+
`tail -c ${LOG_TAIL_BYTES} ${log}`,
|
|
39
|
+
`echo`,
|
|
40
|
+
`verdict=done; if [ $code -eq 124 ] || [ $code -eq 137 ]; then verdict=timeout; fi`,
|
|
41
|
+
`${marker(`"verdict":"%s","exit":%s,"tree":"%s","seconds":%s`)} "$verdict" "$code" "$got" "$(( $(date +%s) - start ))"`,
|
|
42
|
+
]
|
|
43
|
+
.filter(Boolean)
|
|
44
|
+
.join("\n");
|
|
45
|
+
return `bash -c ${shellQuote(script)}`;
|
|
46
|
+
}
|
|
47
|
+
/** The instruction for the sandbox's model. */
|
|
48
|
+
export function runnerPrompt(command, timeoutMinutes) {
|
|
49
|
+
const ms = Math.min(Math.max(1, Math.ceil(timeoutMinutes) + 5) * 60_000, 24 * 3_600_000);
|
|
50
|
+
return [
|
|
51
|
+
"You are a test runner. Do exactly one thing:",
|
|
52
|
+
`run the command below with your shell tool, copied byte for byte, in the repository folder, with a timeout of ${ms} ms.`,
|
|
53
|
+
"Do not change, fix, retry, split or explain it. Do not edit any file. Do not run anything else.",
|
|
54
|
+
`When it finishes, reply with only the last line of its output (the line starting with ${RESULT_MARKER}).`,
|
|
55
|
+
"",
|
|
56
|
+
"```bash",
|
|
57
|
+
command,
|
|
58
|
+
"```",
|
|
59
|
+
].join("\n");
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Find the harness record of `command` and read the marker for `jobId`.
|
|
63
|
+
* Undefined when the sandbox never ran that exact command (or its output has
|
|
64
|
+
* no marker for this job): the result is then unverified and must not count.
|
|
65
|
+
*/
|
|
66
|
+
export function verifyRunnerResult(records, command, jobId) {
|
|
67
|
+
for (let i = records.length - 1; i >= 0; i--) {
|
|
68
|
+
const record = records[i];
|
|
69
|
+
if (record.command.trim() !== command.trim())
|
|
70
|
+
continue;
|
|
71
|
+
const lines = record.output.replace(/\r/g, "").split("\n");
|
|
72
|
+
for (let j = lines.length - 1; j >= 0; j--) {
|
|
73
|
+
const line = lines[j].trim();
|
|
74
|
+
if (!line.startsWith(`${RESULT_MARKER} `))
|
|
75
|
+
continue;
|
|
76
|
+
let parsed;
|
|
77
|
+
try {
|
|
78
|
+
parsed = JSON.parse(line.slice(RESULT_MARKER.length + 1));
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (parsed.job !== jobId)
|
|
84
|
+
continue;
|
|
85
|
+
const verdict = parsed.verdict;
|
|
86
|
+
if (verdict !== "done" && verdict !== "wrong-tree" && verdict !== "timeout")
|
|
87
|
+
continue;
|
|
88
|
+
return {
|
|
89
|
+
verdict,
|
|
90
|
+
...(typeof parsed.exit === "number" && { exitCode: parsed.exit }),
|
|
91
|
+
...(typeof parsed.tree === "string" && { tree: parsed.tree }),
|
|
92
|
+
...(typeof parsed.seconds === "number" && { seconds: parsed.seconds }),
|
|
93
|
+
log: lines.slice(0, j).join("\n").trimEnd(),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../../src/core/cloud/runner.ts"],"names":[],"mappings":"AAWA,MAAM,CAAC,MAAM,aAAa,GAAG,gBAAgB,CAAC;AAE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C,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE;aAC5C,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Claude Code's upload cap for a seed bundle. */
|
|
2
|
+
export declare const MAX_BUNDLE_BYTES: number;
|
|
3
|
+
export declare function isSecretLikePath(file: string): boolean;
|
|
4
|
+
export interface Snapshot {
|
|
5
|
+
/** Tree hash the sandbox must reproduce. */
|
|
6
|
+
tree: string;
|
|
7
|
+
/** Local root commit with that tree (kept in the local object store). */
|
|
8
|
+
commit: string;
|
|
9
|
+
/** Files left out because they look like credentials (agent snapshots). */
|
|
10
|
+
withheld: string[];
|
|
11
|
+
}
|
|
12
|
+
/** Snapshot of exactly commit `sha` (validation). */
|
|
13
|
+
export declare function commitSnapshot(repoRoot: string, sha: string): Promise<Snapshot>;
|
|
14
|
+
/**
|
|
15
|
+
* Snapshot of HEAD plus uncommitted work (agents). Credential-like files that
|
|
16
|
+
* are not committed keep their committed version (or stay out).
|
|
17
|
+
*/
|
|
18
|
+
export declare function workingTreeSnapshot(repoRoot: string): Promise<Snapshot>;
|
|
19
|
+
/**
|
|
20
|
+
* A bundle holding just `commit` as branch `main` with HEAD on it (a seed
|
|
21
|
+
* bundle needs a HEAD to check out). Throws too_large past the upload cap.
|
|
22
|
+
*/
|
|
23
|
+
export declare function bundleOf(repoRoot: string, commit: string): Promise<Buffer>;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// The exact code a cloud task starts from, as a one-commit git bundle.
|
|
2
|
+
//
|
|
3
|
+
// A validation snapshot is a new root commit whose tree IS the tested commit's
|
|
4
|
+
// tree (git commit-tree <sha>^{tree}), so the upload carries no history and
|
|
5
|
+
// the sandbox can prove it has exactly that code by comparing tree hashes. An
|
|
6
|
+
// agent snapshot adds the uncommitted work (tracked edits and untracked,
|
|
7
|
+
// not-ignored files) on top of HEAD, built in a private index so the user's
|
|
8
|
+
// index is never touched.
|
|
9
|
+
import fs from "node:fs/promises";
|
|
10
|
+
import os from "node:os";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
import { git, runGit } from "./git.js";
|
|
13
|
+
import { CloudError } from "./types.js";
|
|
14
|
+
/** Claude Code's upload cap for a seed bundle. */
|
|
15
|
+
export const MAX_BUNDLE_BYTES = 100 * 1024 * 1024;
|
|
16
|
+
/** Files never sent to a cloud sandbox from an uncommitted working tree. */
|
|
17
|
+
const SECRET_NAME = /(^|\/)(\.env(\..*)?|.*\.tfvars|id_rsa|id_ed25519|id_ecdsa|.*\.pem|.*\.p12|.*\.pfx|.*\.key|\.npmrc|\.netrc|credentials(\.json)?)$/i;
|
|
18
|
+
export function isSecretLikePath(file) {
|
|
19
|
+
return SECRET_NAME.test(file.replace(/\\/g, "/"));
|
|
20
|
+
}
|
|
21
|
+
const AUTHOR_ENV = {
|
|
22
|
+
GIT_AUTHOR_NAME: "EZ Coder",
|
|
23
|
+
GIT_AUTHOR_EMAIL: "ezcoder@localhost",
|
|
24
|
+
GIT_COMMITTER_NAME: "EZ Coder",
|
|
25
|
+
GIT_COMMITTER_EMAIL: "ezcoder@localhost",
|
|
26
|
+
// Stable hashes for the same tree: tests and retries reuse one commit.
|
|
27
|
+
GIT_AUTHOR_DATE: "2000-01-01T00:00:00Z",
|
|
28
|
+
GIT_COMMITTER_DATE: "2000-01-01T00:00:00Z",
|
|
29
|
+
};
|
|
30
|
+
/** Root commit whose tree is `tree`. */
|
|
31
|
+
async function rootCommit(repoRoot, tree, message) {
|
|
32
|
+
return (await git(repoRoot, ["commit-tree", tree, "-m", message], {
|
|
33
|
+
env: { ...process.env, ...AUTHOR_ENV },
|
|
34
|
+
})).trim();
|
|
35
|
+
}
|
|
36
|
+
/** Snapshot of exactly commit `sha` (validation). */
|
|
37
|
+
export async function commitSnapshot(repoRoot, sha) {
|
|
38
|
+
const tree = (await git(repoRoot, ["rev-parse", `${sha}^{tree}`])).trim();
|
|
39
|
+
const commit = await rootCommit(repoRoot, tree, `ez snapshot ${sha}`);
|
|
40
|
+
return { tree, commit, withheld: [] };
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Snapshot of HEAD plus uncommitted work (agents). Credential-like files that
|
|
44
|
+
* are not committed keep their committed version (or stay out).
|
|
45
|
+
*/
|
|
46
|
+
export async function workingTreeSnapshot(repoRoot) {
|
|
47
|
+
const head = (await git(repoRoot, ["rev-parse", "HEAD"])).trim();
|
|
48
|
+
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "ez-cloud-snap-"));
|
|
49
|
+
try {
|
|
50
|
+
const index = path.join(tmp, "index");
|
|
51
|
+
const env = { ...process.env, GIT_INDEX_FILE: index };
|
|
52
|
+
await git(repoRoot, ["read-tree", head], { env });
|
|
53
|
+
await git(repoRoot, ["add", "-A"], { env });
|
|
54
|
+
const changed = (await git(repoRoot, ["diff", "--cached", "--name-only", "-z", head], { env }))
|
|
55
|
+
.split("\0")
|
|
56
|
+
.filter(Boolean);
|
|
57
|
+
const withheld = changed.filter(isSecretLikePath);
|
|
58
|
+
for (const file of withheld) {
|
|
59
|
+
// Back to the committed version, or out of the index when it is new.
|
|
60
|
+
const inHead = await runGit(repoRoot, ["cat-file", "-e", `${head}:${file}`]);
|
|
61
|
+
if (inHead.code === 0)
|
|
62
|
+
await git(repoRoot, ["reset", "-q", head, "--", file], { env });
|
|
63
|
+
else
|
|
64
|
+
await git(repoRoot, ["rm", "-q", "--cached", "--", file], { env });
|
|
65
|
+
}
|
|
66
|
+
const tree = (await git(repoRoot, ["write-tree"], { env })).trim();
|
|
67
|
+
const commit = await rootCommit(repoRoot, tree, `ez snapshot of ${head} with local changes`);
|
|
68
|
+
return { tree, commit, withheld };
|
|
69
|
+
}
|
|
70
|
+
finally {
|
|
71
|
+
await fs.rm(tmp, { recursive: true, force: true });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* A bundle holding just `commit` as branch `main` with HEAD on it (a seed
|
|
76
|
+
* bundle needs a HEAD to check out). Throws too_large past the upload cap.
|
|
77
|
+
*/
|
|
78
|
+
export async function bundleOf(repoRoot, commit) {
|
|
79
|
+
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "ez-cloud-bundle-"));
|
|
80
|
+
try {
|
|
81
|
+
const bare = path.join(tmp, "repo.git");
|
|
82
|
+
await git(tmp, ["init", "-q", "--bare", bare]);
|
|
83
|
+
await git(bare, ["fetch", "-q", "--no-tags", repoRoot, `${commit}:refs/heads/main`]);
|
|
84
|
+
await git(bare, ["symbolic-ref", "HEAD", "refs/heads/main"]);
|
|
85
|
+
const file = path.join(tmp, "snapshot.bundle");
|
|
86
|
+
await git(bare, ["bundle", "create", file, "HEAD", "main"]);
|
|
87
|
+
const data = await fs.readFile(file);
|
|
88
|
+
if (data.length > MAX_BUNDLE_BYTES) {
|
|
89
|
+
throw new CloudError(`The code is ${Math.round(data.length / 1e6)} MB packed, over the cloud upload limit of ` +
|
|
90
|
+
`${MAX_BUNDLE_BYTES / 1e6} MB.`, "too_large");
|
|
91
|
+
}
|
|
92
|
+
return data;
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
await fs.rm(tmp, { recursive: true, force: true });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=snapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../../../src/core/cloud/snapshot.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,EAAE;AACF,+EAA+E;AAC/E,4EAA4E;AAC5E,8EAA8E;AAC9E,yEAAyE;AACzE,4EAA4E;AAC5E,0BAA0B;AAC1B,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,UAAU,CA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