@playcraft/cli 0.1.16 → 0.1.18
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/dist/utils/environment-endpoints.js +0 -9
- package/dist/workspace-runtime/codex/app-server.js +69 -65
- package/dist/workspace-runtime/codex/config-toml.js +83 -0
- package/dist/workspace-runtime/codex/model-broker.js +79 -24
- package/dist/workspace-runtime/previews/publish.js +2 -5
- package/dist/workspace-runtime/serve.js +10 -6
- package/dist/workspace-runtime/server/connectivity.js +201 -0
- package/dist/workspace-runtime/server/dispatch.js +83 -78
- package/dist/workspace-runtime/server/endpoints.js +3 -3
- package/dist/workspace-runtime/server/http.js +15 -1
- package/dist/workspace-runtime/workspaces/cli-credentials.js +2 -6
- package/dist/workspace-runtime/workspaces/file-snapshot.js +20 -161
- package/dist/workspace-runtime/workspaces/git-credential-broker.js +2 -4
- package/dist/workspace-runtime/workspaces/git.js +67 -81
- package/dist/workspace-runtime/workspaces/skill-artifact-loader.js +2 -4
- package/package.json +3 -3
- package/dist/workspace-runtime/codex/transcripts.js +0 -94
- package/dist/workspace-runtime/workspaces/checkpoint-saves.js +0 -79
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { rm } from 'node:fs/promises';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
/** Local copies kept per workspace. Older ones are removed; the remote snapshots stay. */
|
|
4
|
-
const LOCAL_COPIES_KEPT = 3;
|
|
5
|
-
const saves = new WeakMap();
|
|
6
|
-
/** Kept in memory: after a restart the first save writes a new checkpoint and uploads again. */
|
|
7
|
-
export function workspaceSaves(state, workspaceId) {
|
|
8
|
-
let byWorkspace = saves.get(state);
|
|
9
|
-
if (!byWorkspace) {
|
|
10
|
-
byWorkspace = new Map();
|
|
11
|
-
saves.set(state, byWorkspace);
|
|
12
|
-
}
|
|
13
|
-
let entry = byWorkspace.get(workspaceId);
|
|
14
|
-
if (!entry) {
|
|
15
|
-
entry = { uploaded: new Set(), transcripts: new Map(), local: [], queue: Promise.resolve() };
|
|
16
|
-
byWorkspace.set(workspaceId, entry);
|
|
17
|
-
}
|
|
18
|
-
return entry;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Saves of one workspace run one after another. Overlapping saves (the page's timer, Runtime's
|
|
22
|
-
* save after a change, the Save button) would otherwise finish in any order, and the last to finish
|
|
23
|
-
* becomes the recovery point even when it captured the older tree.
|
|
24
|
-
*/
|
|
25
|
-
export function oneSaveAtATime(state, workspaceId, run) {
|
|
26
|
-
const entry = workspaceSaves(state, workspaceId);
|
|
27
|
-
const next = entry.queue.then(run, run);
|
|
28
|
-
entry.queue = next.then(() => undefined, () => undefined);
|
|
29
|
-
return next;
|
|
30
|
-
}
|
|
31
|
-
export function sessionsKey(sessions) {
|
|
32
|
-
return JSON.stringify([...sessions]
|
|
33
|
-
.sort((left, right) => left.sessionId.localeCompare(right.sessionId))
|
|
34
|
-
.map((item) => [item.sessionId, item.nativeThreadId ?? null, item.nativeDurableTurnId ?? null, item.recoverability]));
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* The checkpoint a save can answer with instead of writing a new one: same files on disk, same
|
|
38
|
-
* native session state, and the journal still has it.
|
|
39
|
-
*/
|
|
40
|
-
export function unchangedCheckpoint(state, workspaceId, digest, sessions) {
|
|
41
|
-
const last = workspaceSaves(state, workspaceId).last;
|
|
42
|
-
if (!last || last.digest !== digest || last.sessions !== sessionsKey(sessions))
|
|
43
|
-
return undefined;
|
|
44
|
-
const checkpoint = state.journal.getCheckpoint(last.checkpointId);
|
|
45
|
-
return checkpoint?.workspaceId === workspaceId ? checkpoint : undefined;
|
|
46
|
-
}
|
|
47
|
-
export async function rememberFileCheckpoint(state, workspaceId, saved) {
|
|
48
|
-
const entry = workspaceSaves(state, workspaceId);
|
|
49
|
-
entry.last = { checkpointId: saved.checkpointId, digest: saved.digest, sessions: sessionsKey(saved.sessions) };
|
|
50
|
-
entry.local.push(saved.checkpointId);
|
|
51
|
-
// The journal's current file and consistent checkpoints keep their copy until they are replaced.
|
|
52
|
-
const kept = new Set([state.journal.fileCheckpointId(), state.journal.consistentCheckpointId()]);
|
|
53
|
-
const removable = entry.local
|
|
54
|
-
.slice(0, Math.max(0, entry.local.length - LOCAL_COPIES_KEPT))
|
|
55
|
-
.filter((checkpointId) => !kept.has(checkpointId));
|
|
56
|
-
entry.local = entry.local.filter((checkpointId) => !removable.includes(checkpointId));
|
|
57
|
-
for (const checkpointId of removable) {
|
|
58
|
-
await rm(join(state.config.stateDir, 'file-checkpoints', checkpointId), { recursive: true, force: true }).catch(() => undefined);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* The control credential goes only to Runtime's own object endpoint, never to another store.
|
|
63
|
-
*/
|
|
64
|
-
export function objectStoreHeaders(state, storeUrl) {
|
|
65
|
-
try {
|
|
66
|
-
if (new URL(storeUrl).origin !== new URL(state.config.callbackUrl).origin)
|
|
67
|
-
return {};
|
|
68
|
-
}
|
|
69
|
-
catch {
|
|
70
|
-
return {};
|
|
71
|
-
}
|
|
72
|
-
return {
|
|
73
|
-
authorization: `Bearer ${state.config.controlToken}`,
|
|
74
|
-
'playcraft-env': state.config.environment,
|
|
75
|
-
'x-playcraft-runtime-id': state.config.runtimeId,
|
|
76
|
-
'x-playcraft-generation': String(state.config.generation),
|
|
77
|
-
'x-playcraft-runtime-epoch': String(state.runtimeEpoch),
|
|
78
|
-
};
|
|
79
|
-
}
|