impel-cli 0.19.1 → 0.19.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impel-cli",
3
- "version": "0.19.1",
3
+ "version": "0.19.3",
4
4
  "description": "Prepare isolated Claude and Codex workspaces for every accessible Impel tenant",
5
5
  "type": "module",
6
6
  "bin": {
@@ -127,6 +127,18 @@ function joinNullBuffer(entries) {
127
127
  return Buffer.concat(entries.flatMap((entry) => [entry, Buffer.from([0])]));
128
128
  }
129
129
 
130
+ function claudeProjectStorageKey(projectPath) {
131
+ return String(projectPath).replace(/[^A-Za-z0-9]/gu, "-");
132
+ }
133
+
134
+ export function checkpointRemoteRelativePath(provider, relativePath, remoteProjectPath) {
135
+ const normalized = String(relativePath).split(path.sep).join("/");
136
+ if (provider !== "claude") return normalized;
137
+ const segments = normalized.split("/");
138
+ if (segments[0] !== "projects" || segments.length < 3) return normalized;
139
+ return ["projects", claudeProjectStorageKey(remoteProjectPath), ...segments.slice(2)].join("/");
140
+ }
141
+
130
142
  export async function waitForSsh(state, timeoutSeconds = 120) {
131
143
  const deadline = Date.now() + timeoutSeconds * 1000;
132
144
  let lastError = "SSH did not accept a connection";
@@ -282,6 +294,10 @@ export function transferSessionCheckpoint(state, { provider, sessionId, tenantId
282
294
  }
283
295
  const checkpointList = path.join(runPaths(state.runId).root, `checkpoint-${provider}.list`);
284
296
  const checkpointArchive = path.join(runPaths(state.runId).root, `checkpoint-${provider}.tar`);
297
+ const mappings = files.map((relative) => ({
298
+ source: relative.split(path.sep).join("/"),
299
+ destination: checkpointRemoteRelativePath(provider, relative, state.repository.remoteProjectPath),
300
+ }));
285
301
  writePrivate(checkpointList, Buffer.from(`${files.join("\0")}\0`, "utf8"));
286
302
  try {
287
303
  runCapture(process.env.IMPEL_REMOTE_TAR_BIN || "tar", [
@@ -291,6 +307,33 @@ export function transferSessionCheckpoint(state, { provider, sessionId, tenantId
291
307
  runInteractive(process.env.IMPEL_REMOTE_SSH_BIN || "ssh", sshArgs(state, `tar -xf - -C ${remoteRoot}`), {
292
308
  inputFile: checkpointArchive,
293
309
  });
310
+ if (provider === "claude") {
311
+ remoteNode(state, String.raw`
312
+ const fs = require("node:fs");
313
+ const path = require("node:path");
314
+ const payload = JSON.parse(fs.readFileSync(0, "utf8"));
315
+ const root = path.resolve(payload.root);
316
+ for (const mapping of payload.mappings) {
317
+ const source = path.resolve(root, mapping.source);
318
+ const destination = path.resolve(root, mapping.destination);
319
+ if (!source.startsWith(root + path.sep) || !destination.startsWith(root + path.sep)) {
320
+ throw new Error("unsafe checkpoint path");
321
+ }
322
+ if (source === destination) continue;
323
+ if (!fs.statSync(source, { throwIfNoEntry: false })?.isFile()) {
324
+ throw new Error("checkpoint source is missing");
325
+ }
326
+ if (fs.existsSync(destination)) throw new Error("checkpoint destination already exists");
327
+ fs.mkdirSync(path.dirname(destination), { recursive: true, mode: 0o700 });
328
+ fs.renameSync(source, destination);
329
+ let emptyParent = path.dirname(source);
330
+ while (emptyParent !== root && emptyParent.startsWith(root + path.sep)) {
331
+ try { fs.rmdirSync(emptyParent); } catch { break; }
332
+ emptyParent = path.dirname(emptyParent);
333
+ }
334
+ }
335
+ `, { root: remoteRoot, mappings });
336
+ }
294
337
  } finally {
295
338
  fs.rmSync(checkpointList, { force: true });
296
339
  fs.rmSync(checkpointArchive, { force: true });