@gleapai/kai-bridge 0.5.0 → 0.7.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/fly/Dockerfile +11 -0
- package/fly/UPDATES.md +76 -0
- package/fly/codex-auth.mjs +5 -0
- package/fly/entrypoint.sh +12 -0
- package/fly/login-codex.sh +9 -0
- package/fly/runtime-cli.mjs +15 -0
- package/fly/runtime-cli.sh +10 -0
- package/fly/runtime-launch.mjs +8 -0
- package/fly/runtime-update.mjs +137 -0
- package/fly/start.mjs +7 -0
- package/fly/supervisord.conf +45 -0
- package/npm-shrinkwrap.json +2196 -0
- package/package.json +19 -7
- package/runner/lib/acp/harnesses.mjs +6 -1
- package/scripts/runtime-smoke.mjs +60 -0
- package/src/codex-broker-client.mjs +16 -0
- package/src/codex-broker.mjs +85 -0
- package/src/daemon.mjs +64 -62
- package/src/executor.mjs +22 -4
- package/src/harnesses.mjs +20 -9
- package/src/hosted-auth.mjs +42 -0
- package/src/hosted-git-credential.mjs +24 -0
- package/src/hosted-git.mjs +33 -0
- package/src/hosted-ports.mjs +20 -0
- package/src/hosted-resources.mjs +35 -0
- package/src/hosted-tunnel.mjs +76 -0
- package/src/hosted.mjs +86 -0
- package/src/preview.mjs +45 -9
- package/src/profiles.mjs +5 -2
- package/src/repository-setup.mjs +96 -0
- package/src/workspace.mjs +14 -2
package/src/workspace.mjs
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import { execFileSync } from "node:child_process";
|
|
16
16
|
import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
17
17
|
import { dirname, join } from "node:path";
|
|
18
|
+
import { createHash } from 'node:crypto';
|
|
18
19
|
|
|
19
20
|
import { seedNodeModules } from "./deps.mjs";
|
|
20
21
|
|
|
@@ -23,13 +24,18 @@ function git(cwd, args, opts = {}) {
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
export function sessionSlug(sessionId, title) {
|
|
27
|
+
if (process.env.KAI_HOSTED === '1') {
|
|
28
|
+
if (!/^[a-zA-Z0-9_-]{1,128}$/.test(String(sessionId))) throw new Error('Invalid session identity.');
|
|
29
|
+
return `session-${sessionId}`;
|
|
30
|
+
}
|
|
26
31
|
const t = String(title || "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 32);
|
|
27
32
|
const id = String(sessionId || "").slice(-8);
|
|
28
33
|
return t ? `${t}-${id}` : `session-${id}`;
|
|
29
34
|
}
|
|
30
35
|
|
|
31
36
|
export function worktreePath(kaiHome, repoName, slug) {
|
|
32
|
-
|
|
37
|
+
const repo = process.env.KAI_HOSTED === '1' ? createHash('sha256').update(String(repoName)).digest('hex') : repoName;
|
|
38
|
+
return join(kaiHome, "worktrees", repo, slug);
|
|
33
39
|
}
|
|
34
40
|
|
|
35
41
|
/**
|
|
@@ -81,7 +87,7 @@ export function materializeBinding({ kaiHome, repo, binding, sessionId, title, b
|
|
|
81
87
|
// Resume: the worktree from the previous turn is the session state.
|
|
82
88
|
return { cwd: dir, mode, branch, base, resumed: true };
|
|
83
89
|
}
|
|
84
|
-
mkdirSync(
|
|
90
|
+
mkdirSync(dirname(dir), { recursive: true });
|
|
85
91
|
git(repo.primaryPath, ["fetch", "origin", base, "--quiet"]);
|
|
86
92
|
git(repo.primaryPath, ["worktree", "add", "-b", branch, dir, `origin/${base}`]);
|
|
87
93
|
// A fresh worktree has no node_modules; clone the primary checkout's
|
|
@@ -170,6 +176,12 @@ export function discardChanges(cwd) {
|
|
|
170
176
|
export function removeWorktree({ kaiHome, repo, sessionId, title }) {
|
|
171
177
|
const dir = worktreePath(kaiHome, repo.name, sessionSlug(sessionId, title));
|
|
172
178
|
if (!existsSync(dir)) return false;
|
|
179
|
+
if (process.env.KAI_HOSTED === '1') {
|
|
180
|
+
// Never destroy dirty or unpushed work during session cleanup.
|
|
181
|
+
if (collectChanges(dir).files.length || git(dir, ['log', '--branches', '--not', '--remotes', '--oneline'])) return false;
|
|
182
|
+
git(repo.primaryPath, ['worktree', 'remove', dir]);
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
173
185
|
try {
|
|
174
186
|
git(repo.primaryPath, ["worktree", "remove", "--force", dir]);
|
|
175
187
|
} catch {
|