summer-engine 2.5.0 → 2.6.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/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +5 -4
- package/.codex-plugin/plugin.json +5 -4
- package/.cursor-plugin/plugin.json +4 -3
- package/.factory-plugin/plugin.json +3 -3
- package/AGENTS.md +6 -4
- package/CHANGELOG.md +20 -2
- package/GEMINI.md +3 -3
- package/README.md +83 -97
- package/dist/bin/summer.js +6 -1
- package/dist/commands/cloud.d.ts +2 -0
- package/dist/commands/cloud.js +80 -0
- package/dist/commands/doctor.js +19 -0
- package/dist/commands/login.js +4 -1
- package/dist/commands/logout.js +1 -1
- package/dist/commands/open.js +1 -1
- package/dist/commands/plan.d.ts +2 -0
- package/dist/commands/plan.js +60 -0
- package/dist/commands/run.js +132 -35
- package/dist/lib/auth.d.ts +2 -0
- package/dist/lib/auth.js +13 -0
- package/dist/lib/cloud/api.d.ts +79 -0
- package/dist/lib/cloud/api.js +107 -0
- package/dist/lib/cloud/apply.d.ts +32 -0
- package/dist/lib/cloud/apply.js +294 -0
- package/dist/lib/cloud/checkpoint.d.ts +26 -0
- package/dist/lib/cloud/checkpoint.js +142 -0
- package/dist/lib/cloud/conflicts.d.ts +55 -0
- package/dist/lib/cloud/conflicts.js +131 -0
- package/dist/lib/cloud/containment.d.ts +8 -0
- package/dist/lib/cloud/containment.js +52 -0
- package/dist/lib/cloud/diff.d.ts +39 -0
- package/dist/lib/cloud/diff.js +138 -0
- package/dist/lib/cloud/engine-bridge.d.ts +21 -0
- package/dist/lib/cloud/engine-bridge.js +105 -0
- package/dist/lib/cloud/hash-cache.d.ts +23 -0
- package/dist/lib/cloud/hash-cache.js +44 -0
- package/dist/lib/cloud/hash.d.ts +10 -0
- package/dist/lib/cloud/hash.js +111 -0
- package/dist/lib/cloud/http.d.ts +17 -0
- package/dist/lib/cloud/http.js +47 -0
- package/dist/lib/cloud/lock-path.d.ts +1 -0
- package/dist/lib/cloud/lock-path.js +5 -0
- package/dist/lib/cloud/lock.d.ts +14 -0
- package/dist/lib/cloud/lock.js +143 -0
- package/dist/lib/cloud/manifest.d.ts +6 -0
- package/dist/lib/cloud/manifest.js +41 -0
- package/dist/lib/cloud/paths.d.ts +20 -0
- package/dist/lib/cloud/paths.js +90 -0
- package/dist/lib/cloud/project-godot-merge.d.ts +32 -0
- package/dist/lib/cloud/project-godot-merge.js +185 -0
- package/dist/lib/cloud/rules.d.ts +39 -0
- package/dist/lib/cloud/rules.js +159 -0
- package/dist/lib/cloud/sync.d.ts +21 -0
- package/dist/lib/cloud/sync.js +518 -0
- package/dist/lib/cloud/transfer.d.ts +23 -0
- package/dist/lib/cloud/transfer.js +184 -0
- package/dist/lib/cloud/types.d.ts +62 -0
- package/dist/lib/cloud/types.js +1 -0
- package/dist/lib/cloud/validate-path.d.ts +23 -0
- package/dist/lib/cloud/validate-path.js +103 -0
- package/dist/lib/engine.d.ts +6 -0
- package/dist/lib/engine.js +36 -1
- package/dist/lib/game-task-plan.d.ts +42 -0
- package/dist/lib/game-task-plan.js +376 -0
- package/dist/mcp/server.js +2 -0
- package/dist/mcp/tools/asset-tools.js +265 -45
- package/dist/mcp/tools/cloud-tools.d.ts +2 -0
- package/dist/mcp/tools/cloud-tools.js +42 -0
- package/dist/mcp/tools/generate-tools.js +101 -13
- package/dist/mcp/tools/project-tools.js +59 -16
- package/gemini-extension.json +3 -3
- package/package.json +16 -5
- package/skills/3d-assets/character-model/SKILL.md +27 -5
- package/skills/3d-assets/environment-kit/SKILL.md +7 -2
- package/skills/3d-assets/organic-model/SKILL.md +4 -3
- package/skills/3d-assets/prop-model/SKILL.md +16 -8
- package/skills/3d-assets/vehicle-model/SKILL.md +4 -3
- package/skills/animation/animation-tree/SKILL.md +2 -0
- package/skills/animation/generate-motion/SKILL.md +25 -4
- package/skills/asset-pipeline/asset-strategy/SKILL.md +3 -2
- package/skills/workflow/mcpupdate/SKILL.md +134 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { lstat, mkdir, realpath } from "fs/promises";
|
|
2
|
+
import { join, resolve, sep } from "path";
|
|
3
|
+
import { validateCloudPath } from "./validate-path.js";
|
|
4
|
+
/**
|
|
5
|
+
* Write containment (spec 9): after joining a manifest key to the project
|
|
6
|
+
* root, resolve the parent chain and assert the final absolute path is
|
|
7
|
+
* strictly inside the realpath of the project root; refuse to write through
|
|
8
|
+
* any symlinked directory component; create nested parents per component so
|
|
9
|
+
* a hostile manifest can never escape the project.
|
|
10
|
+
*/
|
|
11
|
+
export async function containedProjectPath(projectRoot, key) {
|
|
12
|
+
const valid = validateCloudPath(key);
|
|
13
|
+
if (!valid.ok) {
|
|
14
|
+
throw new Error(`Refusing unsafe path ${key}: ${valid.reason}`);
|
|
15
|
+
}
|
|
16
|
+
const rootReal = await realpath(projectRoot);
|
|
17
|
+
const segments = key.split("/");
|
|
18
|
+
let current = rootReal;
|
|
19
|
+
for (let i = 0; i < segments.length - 1; i += 1) {
|
|
20
|
+
current = join(current, segments[i]);
|
|
21
|
+
let info;
|
|
22
|
+
try {
|
|
23
|
+
info = await lstat(current);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
await mkdir(current);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (info.isSymbolicLink()) {
|
|
30
|
+
throw new Error(`Refusing to write through symlinked directory component: ${current}`);
|
|
31
|
+
}
|
|
32
|
+
if (!info.isDirectory()) {
|
|
33
|
+
throw new Error(`Path component is not a directory: ${current}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const target = join(current, segments[segments.length - 1]);
|
|
37
|
+
const normalizedRoot = rootReal.endsWith(sep) ? rootReal : rootReal + sep;
|
|
38
|
+
if (!resolve(target).startsWith(normalizedRoot)) {
|
|
39
|
+
throw new Error(`Path escapes project root: ${key}`);
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const info = await lstat(target);
|
|
43
|
+
if (info.isSymbolicLink()) {
|
|
44
|
+
throw new Error(`Refusing to replace a symlink: ${key}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
if (err.code !== "ENOENT")
|
|
49
|
+
throw err;
|
|
50
|
+
}
|
|
51
|
+
return target;
|
|
52
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { CloudManifest, ManifestFile } from "./types.js";
|
|
2
|
+
export type DecisionKind = "push" | "pull" | "delete-local" | "delete-remote" | "conflict-remote-wins" | "keep-local" | "converged";
|
|
3
|
+
export interface PathDecision {
|
|
4
|
+
path: string;
|
|
5
|
+
kind: DecisionKind;
|
|
6
|
+
base?: ManifestFile;
|
|
7
|
+
local?: ManifestFile;
|
|
8
|
+
remote?: ManifestFile;
|
|
9
|
+
}
|
|
10
|
+
export interface DiffPlan {
|
|
11
|
+
decisions: PathDecision[];
|
|
12
|
+
pushPaths: string[];
|
|
13
|
+
pullPaths: string[];
|
|
14
|
+
deleteLocalPaths: string[];
|
|
15
|
+
deleteRemotePaths: string[];
|
|
16
|
+
conflictPaths: string[];
|
|
17
|
+
/** Row 14: local edit beat a remote delete; surfaced as a notice. */
|
|
18
|
+
keepLocalPaths: string[];
|
|
19
|
+
/** Row 15: remote edit beat a local delete; surfaced as a notice. */
|
|
20
|
+
restoredRemotePaths: string[];
|
|
21
|
+
}
|
|
22
|
+
export declare function diffManifests(base: CloudManifest, local: CloudManifest, remote: CloudManifest): DiffPlan;
|
|
23
|
+
/**
|
|
24
|
+
* Sidecar pairing (spec 8.4): foo.png + foo.png.import and foo.gd + foo.gd.uid
|
|
25
|
+
* diff, transfer, delete, and conflict-resolve as one atomic unit. When the
|
|
26
|
+
* primary and its sidecar disagree about which side wins, the primary's
|
|
27
|
+
* direction wins and the sidecar decision is recomputed under that direction.
|
|
28
|
+
*/
|
|
29
|
+
export declare function sidecarPrimary(path: string): string | null;
|
|
30
|
+
/**
|
|
31
|
+
* Mass-deletion guardrail (spec 8.5). Confirmation required when deletions
|
|
32
|
+
* exceed 10 files, reach 20% of the base, or cover the entire base.
|
|
33
|
+
*/
|
|
34
|
+
export declare function assertDeleteGuard(plan: DiffPlan, baseFileCount: number, confirmDeletes?: boolean): void;
|
|
35
|
+
/**
|
|
36
|
+
* Hard abort (spec 8.5): base non-empty and the local tree reads as completely
|
|
37
|
+
* empty (unmounted volume, wrong directory). No confirmation can override this.
|
|
38
|
+
*/
|
|
39
|
+
export declare function assertNotEmptyLocalTree(baseFileCount: number, localFileCount: number): void;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
export function diffManifests(base, local, remote) {
|
|
2
|
+
const paths = new Set([...Object.keys(base.files), ...Object.keys(local.files), ...Object.keys(remote.files)]);
|
|
3
|
+
const decisions = [];
|
|
4
|
+
for (const path of [...paths].sort()) {
|
|
5
|
+
const b = base.files[path];
|
|
6
|
+
const l = local.files[path];
|
|
7
|
+
const r = remote.files[path];
|
|
8
|
+
const kind = decide(b, l, r);
|
|
9
|
+
decisions.push({ path, kind, base: b, local: l, remote: r });
|
|
10
|
+
}
|
|
11
|
+
pairSidecars(decisions);
|
|
12
|
+
return planFromDecisions(decisions);
|
|
13
|
+
}
|
|
14
|
+
function planFromDecisions(decisions) {
|
|
15
|
+
return {
|
|
16
|
+
decisions,
|
|
17
|
+
pushPaths: decisions.filter((d) => d.kind === "push").map((d) => d.path),
|
|
18
|
+
pullPaths: decisions.filter((d) => d.kind === "pull").map((d) => d.path),
|
|
19
|
+
deleteLocalPaths: decisions.filter((d) => d.kind === "delete-local").map((d) => d.path),
|
|
20
|
+
deleteRemotePaths: decisions.filter((d) => d.kind === "delete-remote").map((d) => d.path),
|
|
21
|
+
conflictPaths: decisions.filter((d) => d.kind === "conflict-remote-wins").map((d) => d.path),
|
|
22
|
+
keepLocalPaths: decisions.filter((d) => d.kind === "keep-local").map((d) => d.path),
|
|
23
|
+
restoredRemotePaths: decisions
|
|
24
|
+
.filter((d) => d.kind === "pull" && d.base && !d.local && d.remote && !same(d.remote, d.base))
|
|
25
|
+
.map((d) => d.path),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function decide(base, local, remote) {
|
|
29
|
+
if (same(local, remote))
|
|
30
|
+
return "converged";
|
|
31
|
+
if (!base && local && !remote)
|
|
32
|
+
return "push";
|
|
33
|
+
if (!base && !local && remote)
|
|
34
|
+
return "pull";
|
|
35
|
+
if (!base && local && remote)
|
|
36
|
+
return same(local, remote) ? "converged" : "conflict-remote-wins";
|
|
37
|
+
if (base && same(local, base) && remote && !same(remote, base))
|
|
38
|
+
return "pull";
|
|
39
|
+
if (base && local && !same(local, base) && same(remote, base))
|
|
40
|
+
return "push";
|
|
41
|
+
if (base && local && remote && same(local, remote))
|
|
42
|
+
return "converged";
|
|
43
|
+
if (base && local && remote && !same(local, base) && !same(remote, base))
|
|
44
|
+
return "conflict-remote-wins";
|
|
45
|
+
if (base && !local && same(remote, base))
|
|
46
|
+
return "delete-remote";
|
|
47
|
+
if (base && same(local, base) && !remote)
|
|
48
|
+
return "delete-local";
|
|
49
|
+
if (base && !local && remote && !same(remote, base))
|
|
50
|
+
return "pull";
|
|
51
|
+
if (base && local && !same(local, base) && !remote)
|
|
52
|
+
return "keep-local";
|
|
53
|
+
return "converged";
|
|
54
|
+
}
|
|
55
|
+
function same(a, b) {
|
|
56
|
+
if (!a && !b)
|
|
57
|
+
return true;
|
|
58
|
+
if (!a || !b)
|
|
59
|
+
return false;
|
|
60
|
+
return a.sha256 === b.sha256 && a.size === b.size;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Sidecar pairing (spec 8.4): foo.png + foo.png.import and foo.gd + foo.gd.uid
|
|
64
|
+
* diff, transfer, delete, and conflict-resolve as one atomic unit. When the
|
|
65
|
+
* primary and its sidecar disagree about which side wins, the primary's
|
|
66
|
+
* direction wins and the sidecar decision is recomputed under that direction.
|
|
67
|
+
*/
|
|
68
|
+
export function sidecarPrimary(path) {
|
|
69
|
+
if (path.endsWith(".import"))
|
|
70
|
+
return path.slice(0, -".import".length);
|
|
71
|
+
if (path.endsWith(".uid"))
|
|
72
|
+
return path.slice(0, -".uid".length);
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
const REMOTE_WINS = new Set(["pull", "delete-local", "conflict-remote-wins"]);
|
|
76
|
+
const LOCAL_WINS = new Set(["push", "delete-remote", "keep-local"]);
|
|
77
|
+
function pairSidecars(decisions) {
|
|
78
|
+
const byPath = new Map(decisions.map((d) => [d.path, d]));
|
|
79
|
+
for (const sidecar of decisions) {
|
|
80
|
+
const primaryPath = sidecarPrimary(sidecar.path);
|
|
81
|
+
if (!primaryPath)
|
|
82
|
+
continue;
|
|
83
|
+
const primary = byPath.get(primaryPath);
|
|
84
|
+
if (!primary)
|
|
85
|
+
continue;
|
|
86
|
+
// A converged sidecar (L == R) is compatible with either side and a
|
|
87
|
+
// converged primary lets the sidecar act alone; only direction
|
|
88
|
+
// disagreement inside the pair is overridden, with the primary winning.
|
|
89
|
+
if (sidecar.kind === "converged" || primary.kind === "converged")
|
|
90
|
+
continue;
|
|
91
|
+
if (REMOTE_WINS.has(primary.kind) && !REMOTE_WINS.has(sidecar.kind)) {
|
|
92
|
+
sidecar.kind = forceRemoteSide(sidecar);
|
|
93
|
+
}
|
|
94
|
+
else if (LOCAL_WINS.has(primary.kind) && !LOCAL_WINS.has(sidecar.kind)) {
|
|
95
|
+
sidecar.kind = forceLocalSide(sidecar);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function forceRemoteSide(sidecar) {
|
|
100
|
+
if (sidecar.remote && sidecar.local && !same(sidecar.local, sidecar.remote))
|
|
101
|
+
return "conflict-remote-wins";
|
|
102
|
+
if (sidecar.remote && !sidecar.local)
|
|
103
|
+
return "pull";
|
|
104
|
+
if (!sidecar.remote && sidecar.local)
|
|
105
|
+
return "delete-local";
|
|
106
|
+
return "converged";
|
|
107
|
+
}
|
|
108
|
+
function forceLocalSide(sidecar) {
|
|
109
|
+
if (sidecar.local && !same(sidecar.local, sidecar.remote))
|
|
110
|
+
return "push";
|
|
111
|
+
if (!sidecar.local && sidecar.remote)
|
|
112
|
+
return "delete-remote";
|
|
113
|
+
return "converged";
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Mass-deletion guardrail (spec 8.5). Confirmation required when deletions
|
|
117
|
+
* exceed 10 files, reach 20% of the base, or cover the entire base.
|
|
118
|
+
*/
|
|
119
|
+
export function assertDeleteGuard(plan, baseFileCount, confirmDeletes) {
|
|
120
|
+
const deletes = plan.deleteRemotePaths.length;
|
|
121
|
+
if (!deletes)
|
|
122
|
+
return;
|
|
123
|
+
const tooMany = deletes > 10 ||
|
|
124
|
+
(baseFileCount > 0 && deletes >= Math.ceil(baseFileCount * 0.2)) ||
|
|
125
|
+
deletes === baseFileCount;
|
|
126
|
+
if (tooMany && !confirmDeletes) {
|
|
127
|
+
throw new Error(`Push would delete ${deletes} cloud files. Re-run with --confirm-deletes after verifying the project path.`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Hard abort (spec 8.5): base non-empty and the local tree reads as completely
|
|
132
|
+
* empty (unmounted volume, wrong directory). No confirmation can override this.
|
|
133
|
+
*/
|
|
134
|
+
export function assertNotEmptyLocalTree(baseFileCount, localFileCount) {
|
|
135
|
+
if (baseFileCount > 0 && localFileCount === 0) {
|
|
136
|
+
throw new Error("Local project tree is empty but the sync base is not. This looks like an unmounted volume or wrong directory. Aborting sync; no confirmation can push this.");
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Engine coordination (spec 8.6.1 and 8.7). All calls degrade gracefully: an
|
|
3
|
+
* unreachable engine never blocks a sync; the stability check and conflict
|
|
4
|
+
* routing cover the gaps.
|
|
5
|
+
*/
|
|
6
|
+
/** sha256 hex of the stable .summer/local/.project_id (mirrors SummerEngineIdentity::project_id_hash). */
|
|
7
|
+
export declare function readProjectIdHash(projectRoot: string): Promise<string | null>;
|
|
8
|
+
export declare function readProjectPathMarker(projectRoot: string): Promise<string | null>;
|
|
9
|
+
export declare function writeProjectPathMarker(projectRoot: string): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Before hashing (spec 8.6.1): ask the running engine to flush dirty scenes
|
|
12
|
+
* to disk so the walk hashes what the user actually sees.
|
|
13
|
+
*/
|
|
14
|
+
export declare function saveDirtyScenesIfRunning(projectRoot: string): Promise<boolean>;
|
|
15
|
+
/**
|
|
16
|
+
* After apply (spec 8.7): trigger a filesystem rescan and reload the open
|
|
17
|
+
* scene if the pull replaced it. ScanChanges is the engine-side hook; older
|
|
18
|
+
* engines without it simply reject the op and the editor's own focus scan
|
|
19
|
+
* picks the changes up.
|
|
20
|
+
*/
|
|
21
|
+
export declare function notifyEngineAfterApply(projectRoot: string, appliedPaths: readonly string[]): Promise<void>;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { createHash } from "crypto";
|
|
2
|
+
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
import { EngineApiClient } from "../api-client.js";
|
|
5
|
+
import { checkEngineHealth, getApiPort, getApiToken } from "../engine.js";
|
|
6
|
+
/**
|
|
7
|
+
* Engine coordination (spec 8.6.1 and 8.7). All calls degrade gracefully: an
|
|
8
|
+
* unreachable engine never blocks a sync; the stability check and conflict
|
|
9
|
+
* routing cover the gaps.
|
|
10
|
+
*/
|
|
11
|
+
/** sha256 hex of the stable .summer/local/.project_id (mirrors SummerEngineIdentity::project_id_hash). */
|
|
12
|
+
export async function readProjectIdHash(projectRoot) {
|
|
13
|
+
try {
|
|
14
|
+
const id = (await readFile(join(projectRoot, ".summer", "local", ".project_id"), "utf8")).trim();
|
|
15
|
+
if (!id)
|
|
16
|
+
return null;
|
|
17
|
+
return createHash("sha256").update(id, "utf8").digest("hex");
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export async function readProjectPathMarker(projectRoot) {
|
|
24
|
+
try {
|
|
25
|
+
const marker = (await readFile(join(projectRoot, ".summer", "local", ".project_path"), "utf8")).trim();
|
|
26
|
+
return marker || null;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export async function writeProjectPathMarker(projectRoot) {
|
|
33
|
+
const dir = join(projectRoot, ".summer", "local");
|
|
34
|
+
await mkdir(dir, { recursive: true });
|
|
35
|
+
await writeFile(join(dir, ".project_path"), projectRoot, "utf8");
|
|
36
|
+
}
|
|
37
|
+
async function connectForProject(projectRoot) {
|
|
38
|
+
const projectIdHash = await readProjectIdHash(projectRoot);
|
|
39
|
+
if (!projectIdHash)
|
|
40
|
+
return null;
|
|
41
|
+
try {
|
|
42
|
+
const port = await getApiPort();
|
|
43
|
+
const token = await getApiToken();
|
|
44
|
+
if (!token)
|
|
45
|
+
return null;
|
|
46
|
+
const health = await checkEngineHealth(port);
|
|
47
|
+
if (!health)
|
|
48
|
+
return null;
|
|
49
|
+
// A different project's engine instance must never be asked to save or
|
|
50
|
+
// rescan; the executor rejects mismatches too, but skip the round trip.
|
|
51
|
+
if (health.projectIdHash && health.projectIdHash !== projectIdHash)
|
|
52
|
+
return null;
|
|
53
|
+
return { client: new EngineApiClient(port, token), projectIdHash, scene: health.scene };
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Before hashing (spec 8.6.1): ask the running engine to flush dirty scenes
|
|
61
|
+
* to disk so the walk hashes what the user actually sees.
|
|
62
|
+
*/
|
|
63
|
+
export async function saveDirtyScenesIfRunning(projectRoot) {
|
|
64
|
+
const session = await connectForProject(projectRoot);
|
|
65
|
+
if (!session)
|
|
66
|
+
return false;
|
|
67
|
+
try {
|
|
68
|
+
await session.client.executeOps([{ op: "SaveDirtyScenes" }], { projectIdHash: session.projectIdHash });
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* After apply (spec 8.7): trigger a filesystem rescan and reload the open
|
|
77
|
+
* scene if the pull replaced it. ScanChanges is the engine-side hook; older
|
|
78
|
+
* engines without it simply reject the op and the editor's own focus scan
|
|
79
|
+
* picks the changes up.
|
|
80
|
+
*/
|
|
81
|
+
export async function notifyEngineAfterApply(projectRoot, appliedPaths) {
|
|
82
|
+
if (!appliedPaths.length)
|
|
83
|
+
return;
|
|
84
|
+
const session = await connectForProject(projectRoot);
|
|
85
|
+
if (!session)
|
|
86
|
+
return;
|
|
87
|
+
try {
|
|
88
|
+
await session.client.executeOps([{ op: "ScanChanges" }], { projectIdHash: session.projectIdHash });
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
// Engine build without the ScanChanges op; non-fatal.
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
const scene = session.scene;
|
|
95
|
+
if (scene && scene.startsWith("res://")) {
|
|
96
|
+
const sceneRel = scene.slice("res://".length);
|
|
97
|
+
if (appliedPaths.includes(sceneRel)) {
|
|
98
|
+
await session.client.executeOps([{ op: "OpenScene", path: scene }], { projectIdHash: session.projectIdHash });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// Reload is best-effort; the editor reloads from disk on focus.
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface HashCacheEntry {
|
|
2
|
+
sha256: string;
|
|
3
|
+
size: number;
|
|
4
|
+
mtimeNs: string;
|
|
5
|
+
ctimeNs: string;
|
|
6
|
+
inode: string;
|
|
7
|
+
}
|
|
8
|
+
export type HashCache = Record<string, HashCacheEntry>;
|
|
9
|
+
export declare function readHashCache(projectRoot: string): Promise<HashCache>;
|
|
10
|
+
export declare function writeHashCache(projectRoot: string, cache: HashCache): Promise<void>;
|
|
11
|
+
export interface StatLike {
|
|
12
|
+
size: bigint;
|
|
13
|
+
mtimeNs: bigint;
|
|
14
|
+
ctimeNs: bigint;
|
|
15
|
+
ino: bigint;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Cache hit rule (spec 6.2): rehash when any field differs, and apply Git's
|
|
19
|
+
* racily-clean rule: any file whose mtime is at or after the sync start time
|
|
20
|
+
* is rehashed regardless of cache.
|
|
21
|
+
*/
|
|
22
|
+
export declare function cacheHit(entry: HashCacheEntry | undefined, stat: StatLike, syncStartMs: number): boolean;
|
|
23
|
+
export declare function cacheEntryFor(sha256: string, stat: StatLike): HashCacheEntry;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { readFile } from "fs/promises";
|
|
2
|
+
import { hashCachePath, writeJsonAtomic } from "./paths.js";
|
|
3
|
+
export async function readHashCache(projectRoot) {
|
|
4
|
+
try {
|
|
5
|
+
const parsed = JSON.parse(await readFile(hashCachePath(projectRoot), "utf8"));
|
|
6
|
+
return parsed && typeof parsed === "object" ? parsed : {};
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return {};
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export async function writeHashCache(projectRoot, cache) {
|
|
13
|
+
await writeJsonAtomic(hashCachePath(projectRoot), cache);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Cache hit rule (spec 6.2): rehash when any field differs, and apply Git's
|
|
17
|
+
* racily-clean rule: any file whose mtime is at or after the sync start time
|
|
18
|
+
* is rehashed regardless of cache.
|
|
19
|
+
*/
|
|
20
|
+
export function cacheHit(entry, stat, syncStartMs) {
|
|
21
|
+
if (!entry)
|
|
22
|
+
return false;
|
|
23
|
+
if (BigInt(entry.size) !== stat.size)
|
|
24
|
+
return false;
|
|
25
|
+
if (entry.mtimeNs !== stat.mtimeNs.toString())
|
|
26
|
+
return false;
|
|
27
|
+
if (entry.ctimeNs !== stat.ctimeNs.toString())
|
|
28
|
+
return false;
|
|
29
|
+
if (entry.inode !== stat.ino.toString())
|
|
30
|
+
return false;
|
|
31
|
+
const mtimeMs = Number(stat.mtimeNs / 1000000n);
|
|
32
|
+
if (mtimeMs >= syncStartMs)
|
|
33
|
+
return false;
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
export function cacheEntryFor(sha256, stat) {
|
|
37
|
+
return {
|
|
38
|
+
sha256,
|
|
39
|
+
size: Number(stat.size),
|
|
40
|
+
mtimeNs: stat.mtimeNs.toString(),
|
|
41
|
+
ctimeNs: stat.ctimeNs.toString(),
|
|
42
|
+
inode: stat.ino.toString(),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type TrackedRules } from "./rules.js";
|
|
2
|
+
import type { WalkResult } from "./types.js";
|
|
3
|
+
export interface WalkOptions {
|
|
4
|
+
/** Sync start time for the racily-clean rule. Defaults to now. */
|
|
5
|
+
syncStartMs?: number;
|
|
6
|
+
/** Skip reading/writing hash-cache.json (used by tests). */
|
|
7
|
+
noCache?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function walkProject(projectRoot: string, options?: WalkOptions): Promise<WalkResult>;
|
|
10
|
+
export type { TrackedRules };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { createHash } from "crypto";
|
|
2
|
+
import { open, readdir } from "fs/promises";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
import { cacheEntryFor, cacheHit, readHashCache, writeHashCache } from "./hash-cache.js";
|
|
5
|
+
import { isHardExcludedDir, isHardExcludedFile, isIgnoredByRules, loadTrackedRules } from "./rules.js";
|
|
6
|
+
import { findPathCollisions, validateCloudPath } from "./validate-path.js";
|
|
7
|
+
export async function walkProject(projectRoot, options = {}) {
|
|
8
|
+
const rules = await loadTrackedRules(projectRoot);
|
|
9
|
+
const syncStartMs = options.syncStartMs ?? Date.now();
|
|
10
|
+
const cache = options.noCache ? {} : await readHashCache(projectRoot);
|
|
11
|
+
const nextCache = {};
|
|
12
|
+
const files = {};
|
|
13
|
+
const fileByHash = new Map();
|
|
14
|
+
const diskPathByKey = new Map();
|
|
15
|
+
const statByKey = new Map();
|
|
16
|
+
const skippedSymlinks = [];
|
|
17
|
+
const unstablePaths = [];
|
|
18
|
+
async function walk(dir, relKey) {
|
|
19
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
20
|
+
const siblingNames = new Set(entries.map((entry) => entry.name.normalize("NFC")));
|
|
21
|
+
for (const entry of entries) {
|
|
22
|
+
// Manifest keys are NFC; diskPathByKey keeps the actual byte names for I/O.
|
|
23
|
+
const nfcName = entry.name.normalize("NFC");
|
|
24
|
+
const fullPath = join(dir, entry.name);
|
|
25
|
+
const key = relKey ? `${relKey}/${nfcName}` : nfcName;
|
|
26
|
+
if (!key || key === "summer-cloud.json")
|
|
27
|
+
continue;
|
|
28
|
+
if (entry.isSymbolicLink()) {
|
|
29
|
+
skippedSymlinks.push(key);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (entry.isDirectory()) {
|
|
33
|
+
if (isHardExcludedDir(key, nfcName))
|
|
34
|
+
continue;
|
|
35
|
+
if (isIgnoredByRules(key, true, rules))
|
|
36
|
+
continue;
|
|
37
|
+
await walk(fullPath, key);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (!entry.isFile())
|
|
41
|
+
continue;
|
|
42
|
+
if (isHardExcludedFile(key, nfcName, siblingNames))
|
|
43
|
+
continue;
|
|
44
|
+
if (isIgnoredByRules(key, false, rules))
|
|
45
|
+
continue;
|
|
46
|
+
const valid = validateCloudPath(key);
|
|
47
|
+
if (!valid.ok) {
|
|
48
|
+
throw new Error(`Refusing to sync invalid path ${key}: ${valid.reason}`);
|
|
49
|
+
}
|
|
50
|
+
const hashed = await hashStableFile(fullPath, cache[key], syncStartMs);
|
|
51
|
+
if (!hashed) {
|
|
52
|
+
unstablePaths.push(key);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
files[key] = { sha256: hashed.sha256, size: hashed.size };
|
|
56
|
+
nextCache[key] = cacheEntryFor(hashed.sha256, hashed.stat);
|
|
57
|
+
diskPathByKey.set(key, fullPath);
|
|
58
|
+
statByKey.set(key, {
|
|
59
|
+
size: hashed.size,
|
|
60
|
+
mtimeNs: hashed.stat.mtimeNs.toString(),
|
|
61
|
+
inode: hashed.stat.ino.toString(),
|
|
62
|
+
});
|
|
63
|
+
if (!fileByHash.has(hashed.sha256)) {
|
|
64
|
+
fileByHash.set(hashed.sha256, fullPath);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
await walk(projectRoot, "");
|
|
69
|
+
const collisions = findPathCollisions(Object.keys(files));
|
|
70
|
+
if (collisions.length) {
|
|
71
|
+
const lines = collisions.map((c) => `${c.a} and ${c.b} (${c.kind})`).join("; ");
|
|
72
|
+
throw new Error(`On-disk file names collide after normalization and cannot sync: ${lines}. Rename one of each pair.`);
|
|
73
|
+
}
|
|
74
|
+
if (!options.noCache) {
|
|
75
|
+
await writeHashCache(projectRoot, nextCache).catch(() => { });
|
|
76
|
+
}
|
|
77
|
+
return { files, fileByHash, diskPathByKey, statByKey, skippedSymlinks, unstablePaths };
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Per-file stability check (spec 8.6.2): fstat the open fd before hashing,
|
|
81
|
+
* hash, fstat again; on any difference re-read; after 3 attempts return null
|
|
82
|
+
* so the caller excludes the file from THIS push and carries forward its
|
|
83
|
+
* previous manifest entry. Never throws for instability.
|
|
84
|
+
*/
|
|
85
|
+
async function hashStableFile(path, cached, syncStartMs) {
|
|
86
|
+
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
87
|
+
const handle = await open(path, "r");
|
|
88
|
+
try {
|
|
89
|
+
const before = statLike(await handle.stat({ bigint: true }));
|
|
90
|
+
if (cacheHit(cached, before, syncStartMs)) {
|
|
91
|
+
return { sha256: cached.sha256, size: Number(before.size), stat: before };
|
|
92
|
+
}
|
|
93
|
+
const bytes = await handle.readFile();
|
|
94
|
+
const after = statLike(await handle.stat({ bigint: true }));
|
|
95
|
+
if (before.size === after.size && before.mtimeNs === after.mtimeNs && before.ino === after.ino) {
|
|
96
|
+
return {
|
|
97
|
+
sha256: createHash("sha256").update(bytes).digest("hex"),
|
|
98
|
+
size: bytes.length,
|
|
99
|
+
stat: after,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
await handle.close();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
function statLike(stat) {
|
|
110
|
+
return { size: stat.size, mtimeNs: stat.mtimeNs, ctimeNs: stat.ctimeNs, ino: stat.ino };
|
|
111
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Blob transport boundary. Production talks to presigned R2 URLs; tests swap
|
|
3
|
+
* in a double so no test ever needs the network.
|
|
4
|
+
*/
|
|
5
|
+
export interface BlobTransport {
|
|
6
|
+
/** Streams a GET to a file, hashing as it goes. Returns sha256 hex and size. */
|
|
7
|
+
getToFile(url: string, destPath: string): Promise<{
|
|
8
|
+
sha256: string;
|
|
9
|
+
size: number;
|
|
10
|
+
status: number;
|
|
11
|
+
}>;
|
|
12
|
+
/** PUTs bytes from a file or buffer. Returns the HTTP status. */
|
|
13
|
+
put(url: string, headers: Record<string, string>, body: Buffer): Promise<number>;
|
|
14
|
+
}
|
|
15
|
+
export declare function getBlobTransport(): BlobTransport;
|
|
16
|
+
export declare function setBlobTransportForTests(transport: BlobTransport | null): void;
|
|
17
|
+
export declare function readFileBytes(path: string): Promise<Buffer>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createHash } from "crypto";
|
|
2
|
+
import { createWriteStream } from "fs";
|
|
3
|
+
import { open, readFile } from "fs/promises";
|
|
4
|
+
import { Readable } from "stream";
|
|
5
|
+
import { pipeline } from "stream/promises";
|
|
6
|
+
const realTransport = {
|
|
7
|
+
async getToFile(url, destPath) {
|
|
8
|
+
const res = await fetch(url);
|
|
9
|
+
if (!res.ok || !res.body) {
|
|
10
|
+
return { sha256: "", size: 0, status: res.status };
|
|
11
|
+
}
|
|
12
|
+
const hash = createHash("sha256");
|
|
13
|
+
let size = 0;
|
|
14
|
+
const out = createWriteStream(destPath, { mode: 0o600 });
|
|
15
|
+
await pipeline(Readable.fromWeb(res.body), async function* (source) {
|
|
16
|
+
for await (const chunk of source) {
|
|
17
|
+
const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
18
|
+
hash.update(buf);
|
|
19
|
+
size += buf.length;
|
|
20
|
+
yield buf;
|
|
21
|
+
}
|
|
22
|
+
}, out);
|
|
23
|
+
// fsync so a staged blob survives a crash before apply.
|
|
24
|
+
const handle = await open(destPath, "r+");
|
|
25
|
+
try {
|
|
26
|
+
await handle.sync();
|
|
27
|
+
}
|
|
28
|
+
finally {
|
|
29
|
+
await handle.close();
|
|
30
|
+
}
|
|
31
|
+
return { sha256: hash.digest("hex"), size, status: res.status };
|
|
32
|
+
},
|
|
33
|
+
async put(url, headers, body) {
|
|
34
|
+
const res = await fetch(url, { method: "PUT", headers, body: new Uint8Array(body) });
|
|
35
|
+
return res.status;
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
let activeTransport = realTransport;
|
|
39
|
+
export function getBlobTransport() {
|
|
40
|
+
return activeTransport;
|
|
41
|
+
}
|
|
42
|
+
export function setBlobTransportForTests(transport) {
|
|
43
|
+
activeTransport = transport ?? realTransport;
|
|
44
|
+
}
|
|
45
|
+
export async function readFileBytes(path) {
|
|
46
|
+
return readFile(path);
|
|
47
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function lockPath(projectRoot: string): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface CloudLock {
|
|
2
|
+
release(): Promise<void>;
|
|
3
|
+
}
|
|
4
|
+
type Face = "cli" | "mcp" | "engine";
|
|
5
|
+
/**
|
|
6
|
+
* Per-project sync mutex (spec 8.2). O_EXCL create, 30s heartbeat, stale only
|
|
7
|
+
* by heartbeat age (120s). Two fixed races: the payload is written to the fd
|
|
8
|
+
* before close and verified by token after create (a contender that reads an
|
|
9
|
+
* empty just-created file treats parse failure as FRESH while the file is
|
|
10
|
+
* young); takeover goes through an atomic rename so two waiters can never
|
|
11
|
+
* both remove the same stale lock and both proceed.
|
|
12
|
+
*/
|
|
13
|
+
export declare function acquireCloudLock(projectRoot: string, face?: Face): Promise<CloudLock>;
|
|
14
|
+
export {};
|