@sentropic/remote-cli 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ import {
2
+ emptyMetrics,
3
+ mergedState,
4
+ readSyncStatus,
5
+ syncStatusPath,
6
+ writeSyncStatus
7
+ } from "./chunk-RLFQALHC.js";
8
+ import "./chunk-3RG5ZIWI.js";
9
+ export {
10
+ emptyMetrics,
11
+ mergedState,
12
+ readSyncStatus,
13
+ syncStatusPath,
14
+ writeSyncStatus
15
+ };
@@ -0,0 +1,38 @@
1
+ import {
2
+ acquireWorkspaceLock,
3
+ baseSnapshotPath,
4
+ createWorkspace,
5
+ deleteWorkspace,
6
+ downloadWorkspaceExport,
7
+ listWorkspaces,
8
+ lockHolderId,
9
+ markerPath,
10
+ readBaseSnapshot,
11
+ readLineageRecord,
12
+ readWorkspaceMarker,
13
+ releaseWorkspaceLock,
14
+ requestWorkspaceGc,
15
+ writeBaseSnapshot,
16
+ writeLineageRecord,
17
+ writeWorkspaceMarker
18
+ } from "./chunk-PG4CWJNC.js";
19
+ import "./chunk-E3GXAKJ3.js";
20
+ import "./chunk-3RG5ZIWI.js";
21
+ export {
22
+ acquireWorkspaceLock,
23
+ baseSnapshotPath,
24
+ createWorkspace,
25
+ deleteWorkspace,
26
+ downloadWorkspaceExport,
27
+ listWorkspaces,
28
+ lockHolderId,
29
+ markerPath,
30
+ readBaseSnapshot,
31
+ readLineageRecord,
32
+ readWorkspaceMarker,
33
+ releaseWorkspaceLock,
34
+ requestWorkspaceGc,
35
+ writeBaseSnapshot,
36
+ writeLineageRecord,
37
+ writeWorkspaceMarker
38
+ };
@@ -0,0 +1,159 @@
1
+ import "./chunk-3RG5ZIWI.js";
2
+
3
+ // src/workspace-sync-incremental.ts
4
+ import { createHash } from "crypto";
5
+ import { readFileSync, statSync } from "fs";
6
+ import { spawnSync } from "child_process";
7
+ import { join } from "path";
8
+ var FILE_SIZE_LIMIT = 1e7;
9
+ function sha256Buf(buf) {
10
+ return createHash("sha256").update(buf).digest("hex");
11
+ }
12
+ function sha256File(path) {
13
+ return sha256Buf(readFileSync(path));
14
+ }
15
+ function isGitRepo(cwd) {
16
+ return spawnSync("git", ["rev-parse", "--git-dir"], { cwd, encoding: "utf8" }).status === 0;
17
+ }
18
+ function getHeadSha(cwd) {
19
+ const r = spawnSync("git", ["rev-parse", "HEAD"], {
20
+ cwd,
21
+ encoding: "utf8"
22
+ });
23
+ return r.status === 0 ? r.stdout.trim() : void 0;
24
+ }
25
+ function buildGitBundle(cwd) {
26
+ const r = spawnSync("git", ["bundle", "create", "-", "--all"], {
27
+ cwd,
28
+ maxBuffer: 512 * 1024 * 1024
29
+ });
30
+ if (r.status !== 0) {
31
+ throw new Error(
32
+ `git bundle failed: ${r.stderr?.toString()?.slice(0, 200) ?? "unknown error"}`
33
+ );
34
+ }
35
+ return r.stdout;
36
+ }
37
+ function buildTrackedDiff(cwd, baseSha) {
38
+ const opts = {
39
+ cwd,
40
+ maxBuffer: 256 * 1024 * 1024
41
+ };
42
+ const rCommitted = spawnSync(
43
+ "git",
44
+ ["diff", "--binary", baseSha, "HEAD"],
45
+ opts
46
+ );
47
+ const rStaged = spawnSync(
48
+ "git",
49
+ ["diff", "--binary", "--cached", "HEAD"],
50
+ opts
51
+ );
52
+ const combined = Buffer.concat([
53
+ rCommitted.stdout ?? Buffer.alloc(0),
54
+ rStaged.stdout ?? Buffer.alloc(0)
55
+ ]);
56
+ return combined.toString("base64");
57
+ }
58
+ function buildIncrementalManifest(cwd, baseSha) {
59
+ const tracked = buildTrackedDiff(cwd, baseSha);
60
+ const utR = spawnSync("git", ["ls-files", "-o", "--exclude-standard", "-z"], {
61
+ cwd,
62
+ encoding: "buffer"
63
+ });
64
+ const untrackedPaths = utR.stdout.toString("utf8").split("\0").map((p) => p.trim()).filter(Boolean);
65
+ const untrackedManifest = untrackedPaths.map((p) => {
66
+ const abs = join(cwd, p);
67
+ return { path: p, sha256: sha256File(abs), size: statSync(abs).size };
68
+ });
69
+ return {
70
+ base: baseSha,
71
+ tracked,
72
+ untrackedManifest,
73
+ deleted: [],
74
+ renames: [],
75
+ modes: []
76
+ };
77
+ }
78
+ function buildUntrackedTarball(cwd, paths) {
79
+ if (paths.length === 0) return Buffer.alloc(0);
80
+ const input = paths.join("\0");
81
+ const r = spawnSync("tar", ["-czf", "-", "-C", cwd, "--null", "-T", "-"], {
82
+ input: Buffer.from(input),
83
+ maxBuffer: 256 * 1024 * 1024
84
+ });
85
+ if (r.status !== 0) {
86
+ throw new Error(
87
+ `tar untracked failed: ${r.stderr?.toString()?.slice(0, 200) ?? "unknown error"}`
88
+ );
89
+ }
90
+ return r.stdout;
91
+ }
92
+ async function classifyWorkingSet(args) {
93
+ const { cwd } = args;
94
+ const hotSetMaxBytes = args.hotSetMaxBytes ?? 5e7;
95
+ const hotSetMtimeSec = args.hotSetMtimeSec ?? 86400;
96
+ const nowMs = Date.now();
97
+ const mtimeCutoffMs = nowMs - hotSetMtimeSec * 1e3;
98
+ const diffR = spawnSync("git", ["diff", "--name-only", "HEAD"], {
99
+ cwd,
100
+ encoding: "utf8",
101
+ maxBuffer: 8 * 1024 * 1024
102
+ });
103
+ const trackedModified = diffR.status === 0 ? diffR.stdout.split("\n").map((p) => p.trim()).filter(Boolean) : [];
104
+ const utR = spawnSync(
105
+ "git",
106
+ ["ls-files", "-o", "--exclude-standard", "-z"],
107
+ { cwd, encoding: "buffer", maxBuffer: 8 * 1024 * 1024 }
108
+ );
109
+ const untracked = utR.status === 0 ? utR.stdout.toString("utf8").split("\0").map((p) => p.trim()).filter(Boolean) : [];
110
+ const recentUntracked = untracked.filter((p) => {
111
+ try {
112
+ return statSync(join(cwd, p)).mtimeMs >= mtimeCutoffMs;
113
+ } catch {
114
+ return false;
115
+ }
116
+ });
117
+ const candidateSet = /* @__PURE__ */ new Set([...trackedModified, ...recentUntracked]);
118
+ const candidates = Array.from(candidateSet);
119
+ const entries = [];
120
+ const coldFromSize = [];
121
+ for (const p of candidates) {
122
+ let st;
123
+ try {
124
+ st = statSync(join(cwd, p));
125
+ } catch {
126
+ continue;
127
+ }
128
+ if (st.size > FILE_SIZE_LIMIT) {
129
+ coldFromSize.push(p);
130
+ } else {
131
+ entries.push({ path: p, size: st.size, mtimeMs: st.mtimeMs });
132
+ }
133
+ }
134
+ entries.sort((a, b) => b.mtimeMs - a.mtimeMs);
135
+ const hot = [];
136
+ const coldFromCap = [];
137
+ let hotBytes = 0;
138
+ for (const e of entries) {
139
+ if (hotBytes + e.size <= hotSetMaxBytes) {
140
+ hot.push(e.path);
141
+ hotBytes += e.size;
142
+ } else {
143
+ coldFromCap.push(e.path);
144
+ }
145
+ }
146
+ const cold = [...coldFromSize, ...coldFromCap];
147
+ return { hot, cold, estimatedHotBytes: hotBytes };
148
+ }
149
+ export {
150
+ buildGitBundle,
151
+ buildIncrementalManifest,
152
+ buildTrackedDiff,
153
+ buildUntrackedTarball,
154
+ classifyWorkingSet,
155
+ getHeadSha,
156
+ isGitRepo,
157
+ sha256Buf,
158
+ sha256File
159
+ };
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@sentropic/remote-cli",
3
+ "version": "0.0.3",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/index.d.ts",
8
+ "default": "./dist/index.js"
9
+ }
10
+ },
11
+ "bin": {
12
+ "remote": "dist/index.js"
13
+ },
14
+ "scripts": {
15
+ "build": "tsup src/index.ts src/llm-gateway-runtime/index.ts --format esm --dts --clean",
16
+ "dev": "tsx src/index.ts",
17
+ "lint": "tsc --noEmit",
18
+ "test": "vitest run",
19
+ "typecheck": "tsc --noEmit"
20
+ },
21
+ "dependencies": {
22
+ "@aws-sdk/client-s3": "^3.1075.0",
23
+ "@hono/node-server": "^1.19.14",
24
+ "@hono/node-ws": "^1.3.1",
25
+ "@sentropic/llm-gateway": "^0.2.0",
26
+ "ajv": "^8.20.0",
27
+ "ajv-formats": "^3.0.1",
28
+ "commander": "^15.0.0",
29
+ "hono": "^4.12.18",
30
+ "node-pty": "^1.1.0",
31
+ "ws": "^8.20.1"
32
+ },
33
+ "devDependencies": {
34
+ "@types/node": "^22.19.18",
35
+ "@types/ws": "^8.18.1",
36
+ "tsup": "^8.5.1",
37
+ "tsx": "^4.21.0"
38
+ },
39
+ "files": [
40
+ "dist",
41
+ "README.md"
42
+ ],
43
+ "publishConfig": {
44
+ "access": "public"
45
+ }
46
+ }