@spunto/build 0.34.0 → 0.35.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spunto/build",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.35.0",
|
|
4
4
|
"description": "Spunto's shared Build engine — the devcontainer image protocol and VS Code extension registry clients, with no database, no HTTP framework and no UI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -145,7 +145,12 @@ export type PlatformMessage =
|
|
|
145
145
|
|
|
146
146
|
/** Agent → control plane. */
|
|
147
147
|
export type AgentMessage =
|
|
148
|
-
|
|
148
|
+
/**
|
|
149
|
+
* `gitToken`: the machine token (`sbxg_`) the plan of an earlier hello of this same boot handed
|
|
150
|
+
* out (agent 0.12.0+). The platform keeps it when it is still this sandbox's, instead of minting
|
|
151
|
+
* one that the processes already running would not have.
|
|
152
|
+
*/
|
|
153
|
+
| { type: "hello"; token: string; info: AgentInfo; gitToken?: string }
|
|
149
154
|
| { type: "heartbeat" }
|
|
150
155
|
| { type: "pong"; at: number }
|
|
151
156
|
/** After a resume (SIGUSR1): does this socket still reach the platform? */
|
|
@@ -19,7 +19,7 @@ import { fileURLToPath } from "node:url"
|
|
|
19
19
|
import os from "node:os"
|
|
20
20
|
import net from "node:net"
|
|
21
21
|
|
|
22
|
-
const VERSION = "0.
|
|
22
|
+
const VERSION = "0.12.0"
|
|
23
23
|
const API = (process.env.SPUNTO_API_URL ?? "").replace(/\/$/, "")
|
|
24
24
|
// `let`: a fork (RFC 0039 § 4.10) hands this process the identity of the copy it now runs in.
|
|
25
25
|
let TOKEN = process.env.SPUNTO_SANDBOX_TOKEN ?? ""
|
|
@@ -279,6 +279,33 @@ function refreshGitIdentity(plan) {
|
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
281
|
|
|
282
|
+
// The machine token (`sbxg_`) of this boot, shown back at every hello of the same boot so the
|
|
283
|
+
// platform keeps it rather than minting another (`buildProjectPlan`, sandbox-project.ts). Every
|
|
284
|
+
// process started since holds it in its env — the agent sessions' MCP servers, the doorbell, the
|
|
285
|
+
// setup's git helper — and a mere reconnect (the API redeployed, the network dropped) must not
|
|
286
|
+
// take it from them. On the disk, root's, with the boot it was handed out in: an agent restarted
|
|
287
|
+
// in the same boot (or a box resumed with its RAM) shows it; a new boot does not, and gets a new
|
|
288
|
+
// one. A copy (a fork) shows its source's, which the platform refuses: another sandbox's.
|
|
289
|
+
const GIT_TOKEN_FILE = () => join(DIR, "git-token.json")
|
|
290
|
+
function keepGitToken(plan) {
|
|
291
|
+
const token = plan.env?.SPUNTO_WORKER_TOKEN
|
|
292
|
+
if (!token) return
|
|
293
|
+
try {
|
|
294
|
+
writeFileSync(GIT_TOKEN_FILE(), JSON.stringify({ boot: bootId(), token }), { mode: 0o600 })
|
|
295
|
+
} catch (err) {
|
|
296
|
+
console.warn(`[sandbox-agent] git token not kept: ${err.message}`)
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
function gitTokenOfThisBoot() {
|
|
300
|
+
try {
|
|
301
|
+
const kept = JSON.parse(readFileSync(GIT_TOKEN_FILE(), "utf8"))
|
|
302
|
+
const boot = bootId()
|
|
303
|
+
return boot && kept?.boot === boot && typeof kept.token === "string" ? kept.token : null
|
|
304
|
+
} catch {
|
|
305
|
+
return null
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
282
309
|
/**
|
|
283
310
|
* The image's own ENV (the plan's `imageEnv`), for a box whose provider booted the image's files
|
|
284
311
|
* without it (a microVM): its PATH in front of ours — `claude` in spunto-worker-base is in
|
|
@@ -305,6 +332,7 @@ function applyProject(plan) {
|
|
|
305
332
|
childEnv = { ...baseEnv, ...underImageEnv(baseEnv, plan.imageEnv), ...plan.env }
|
|
306
333
|
runAs = plan.user || null
|
|
307
334
|
refreshGitIdentity(plan)
|
|
335
|
+
keepGitToken(plan)
|
|
308
336
|
project = { plan, exitCode: project?.exitCode ?? null }
|
|
309
337
|
|
|
310
338
|
if (runnerPid()) {
|
|
@@ -1027,7 +1055,10 @@ function connect() {
|
|
|
1027
1055
|
const sock = (ws = new WebSocket(CONNECT_URL))
|
|
1028
1056
|
wsDialedAt = uptime()
|
|
1029
1057
|
ws.binaryType = "arraybuffer"
|
|
1030
|
-
ws.addEventListener("open", () =>
|
|
1058
|
+
ws.addEventListener("open", () => {
|
|
1059
|
+
const gitToken = gitTokenOfThisBoot()
|
|
1060
|
+
send({ type: "hello", token: TOKEN, info: info(), ...(gitToken ? { gitToken } : {}) })
|
|
1061
|
+
})
|
|
1031
1062
|
ws.addEventListener("message", (ev) => {
|
|
1032
1063
|
// A socket given up on after a resume (see SIGUSR1) may still deliver late: not ours anymore.
|
|
1033
1064
|
if (ws !== sock) return
|
|
@@ -278,8 +278,12 @@ while IFS= read -r line; do
|
|
|
278
278
|
esac
|
|
279
279
|
done
|
|
280
280
|
REPO="\${REPO%.git}"
|
|
281
|
+
# The machine token the sandbox agent keeps current, before the one frozen in this process's env:
|
|
282
|
+
# a shell of an earlier boot, or of a fork's source, still holds that one (RFC 0039 § 4.10).
|
|
283
|
+
T=$(cat "$HOME/.spunto/git-token" 2>/dev/null); [ -n "$T" ] || T="$SPUNTO_WORKER_TOKEN"
|
|
284
|
+
A=$(cat "$HOME/.spunto/api-url" 2>/dev/null); [ -n "$A" ] || A="$SPUNTO_API_URL"
|
|
281
285
|
# No -f: a refusal's body says why (which account the member authorized, what to do about it).
|
|
282
|
-
RESPONSE=$(curl -sS -m 20 -X POST "$
|
|
286
|
+
RESPONSE=$(curl -sS -m 20 -X POST "$A/api/workers/git-credential" -H "Authorization: Bearer $T" -H "Content-Type: application/json" -d "{\\"repo\\":\\"$REPO\\"}" 2>/dev/null)
|
|
283
287
|
PASSWORD=$(printf "%s" "$RESPONSE" | sed -n 's/.*"password":"\\([^"]*\\)".*/\\1/p')
|
|
284
288
|
if [ -z "$PASSWORD" ]; then
|
|
285
289
|
REASON=$(printf "%s" "$RESPONSE" | sed -n 's/.*"error":"\\([^"]*\\)".*/\\1/p')
|