@4pm/cli 1.5.40 → 1.5.42

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.
Files changed (2) hide show
  1. package/dist/index.js +47 -29
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -37844,10 +37844,19 @@ async function listDir(path, root) {
37844
37844
 
37845
37845
  // src/core/fs-read.ts
37846
37846
  import { readFile as readFile3 } from "fs/promises";
37847
- import { resolve as resolve2 } from "path";
37847
+ import { resolve as resolve2, sep as sep3 } from "path";
37848
37848
  var MAX_BYTES = 256 * 1024;
37849
- async function readWorkerFile(path) {
37850
- const target = resolve2(path);
37849
+ function resolveInRoot(root, relPath) {
37850
+ if (!root) return null;
37851
+ const base = resolve2(root);
37852
+ const target = resolve2(base, relPath || ".");
37853
+ return target === base || target.startsWith(base + sep3) ? target : null;
37854
+ }
37855
+ async function readWorkerFile(root, path) {
37856
+ const target = resolveInRoot(root, path);
37857
+ if (!target) {
37858
+ return { path, content: "", truncated: false };
37859
+ }
37851
37860
  try {
37852
37861
  const buf = await readFile3(target);
37853
37862
  const truncated = buf.byteLength > MAX_BYTES;
@@ -37860,16 +37869,16 @@ async function readWorkerFile(path) {
37860
37869
 
37861
37870
  // src/core/fs-write.ts
37862
37871
  import { mkdir as mkdir2, writeFile as writeFile2 } from "fs/promises";
37863
- import { dirname as dirname3, resolve as resolve3, sep as sep3 } from "path";
37872
+ import { dirname as dirname3, resolve as resolve3, sep as sep4 } from "path";
37864
37873
  var MAX_BYTES2 = 2 * 1024 * 1024;
37865
- function resolveInRoot(root, relPath) {
37874
+ function resolveInRoot2(root, relPath) {
37866
37875
  if (!root) return null;
37867
37876
  const base = resolve3(root);
37868
37877
  const target = resolve3(base, relPath || ".");
37869
- return target === base || target.startsWith(base + sep3) ? target : null;
37878
+ return target === base || target.startsWith(base + sep4) ? target : null;
37870
37879
  }
37871
37880
  async function writeWorkerFile(root, relPath, content) {
37872
- const target = resolveInRoot(root, relPath);
37881
+ const target = resolveInRoot2(root, relPath);
37873
37882
  if (!target) {
37874
37883
  return { ok: false, path: relPath, bytes: 0, error: "path escapes the project root" };
37875
37884
  }
@@ -37888,12 +37897,12 @@ async function writeWorkerFile(root, relPath, content) {
37888
37897
 
37889
37898
  // src/core/fs-mutate.ts
37890
37899
  import { mkdir as mkdir3, writeFile as writeFile3, rename, rm, stat } from "fs/promises";
37891
- import { basename as basename3, dirname as dirname4, resolve as resolve4, sep as sep4 } from "path";
37900
+ import { basename as basename3, dirname as dirname4, resolve as resolve4, sep as sep5 } from "path";
37892
37901
  var MAX_BYTES3 = 2 * 1024 * 1024;
37893
- function resolveInRoot2(root, rel) {
37902
+ function resolveInRoot3(root, rel) {
37894
37903
  const base = resolve4(root);
37895
37904
  const target = resolve4(base, rel || ".");
37896
- return target === base || target.startsWith(base + sep4) ? target : null;
37905
+ return target === base || target.startsWith(base + sep5) ? target : null;
37897
37906
  }
37898
37907
  async function isDir(p) {
37899
37908
  try {
@@ -37916,13 +37925,13 @@ async function mutateFs(root, req) {
37916
37925
  try {
37917
37926
  switch (req.op) {
37918
37927
  case "mkdir": {
37919
- const target = resolveInRoot2(root, req.path ?? "");
37928
+ const target = resolveInRoot3(root, req.path ?? "");
37920
37929
  if (!target || target === resolve4(root)) return escaped(req.path ?? "");
37921
37930
  await mkdir3(target, { recursive: true });
37922
37931
  return { ok: true, path: target };
37923
37932
  }
37924
37933
  case "create": {
37925
- const target = resolveInRoot2(root, req.path ?? "");
37934
+ const target = resolveInRoot3(root, req.path ?? "");
37926
37935
  if (!target || target === resolve4(root)) return escaped(req.path ?? "");
37927
37936
  if (await exists(target)) return { ok: false, path: target, error: "already exists" };
37928
37937
  const content = req.content ?? "";
@@ -37934,19 +37943,19 @@ async function mutateFs(root, req) {
37934
37943
  return { ok: true, path: target };
37935
37944
  }
37936
37945
  case "move": {
37937
- const from = resolveInRoot2(root, req.from ?? "");
37938
- let to = resolveInRoot2(root, req.to ?? "");
37946
+ const from = resolveInRoot3(root, req.from ?? "");
37947
+ let to = resolveInRoot3(root, req.to ?? "");
37939
37948
  if (!from || !to) return escaped(req.from ?? req.to ?? "");
37940
37949
  if (from === resolve4(root)) return { ok: false, path: from, error: "cannot move the project root" };
37941
37950
  if (await isDir(to)) to = resolve4(to, basename3(from));
37942
- if (to !== resolve4(root) && !to.startsWith(resolve4(root) + sep4)) return escaped(req.to ?? "");
37951
+ if (to !== resolve4(root) && !to.startsWith(resolve4(root) + sep5)) return escaped(req.to ?? "");
37943
37952
  if (await exists(to)) return { ok: false, path: to, error: "destination already exists" };
37944
37953
  await mkdir3(dirname4(to), { recursive: true });
37945
37954
  await rename(from, to);
37946
37955
  return { ok: true, path: to };
37947
37956
  }
37948
37957
  case "delete": {
37949
- const target = resolveInRoot2(root, req.path ?? "");
37958
+ const target = resolveInRoot3(root, req.path ?? "");
37950
37959
  if (!target) return escaped(req.path ?? "");
37951
37960
  if (target === resolve4(root)) return { ok: false, path: target, error: "cannot delete the project root" };
37952
37961
  await rm(target, { recursive: true, force: true });
@@ -37962,12 +37971,12 @@ async function mutateFs(root, req) {
37962
37971
 
37963
37972
  // src/core/fs-transfer.ts
37964
37973
  import { mkdir as mkdir4, readFile as readFile4, stat as stat2, writeFile as writeFile4 } from "fs/promises";
37965
- import { basename as basename4, dirname as dirname5, extname, resolve as resolve5, sep as sep5 } from "path";
37966
- function resolveInRoot3(root, relPath) {
37974
+ import { basename as basename4, dirname as dirname5, extname, resolve as resolve5, sep as sep6 } from "path";
37975
+ function resolveInRoot4(root, relPath) {
37967
37976
  if (!root) return null;
37968
37977
  const base = resolve5(root);
37969
37978
  const target = resolve5(base, relPath || ".");
37970
- return target === base || target.startsWith(base + sep5) ? target : null;
37979
+ return target === base || target.startsWith(base + sep6) ? target : null;
37971
37980
  }
37972
37981
  var MIME_BY_EXT = {
37973
37982
  ".png": "image/png",
@@ -37991,7 +38000,7 @@ function guessMime(path) {
37991
38000
  return MIME_BY_EXT[extname(path).toLowerCase()] ?? "application/octet-stream";
37992
38001
  }
37993
38002
  async function uploadBinaryFile(root, relPath, contentBase64) {
37994
- const target = resolveInRoot3(root, relPath);
38003
+ const target = resolveInRoot4(root, relPath);
37995
38004
  if (!target) {
37996
38005
  return { ok: false, path: relPath, bytes: 0, error: "path escapes the project root" };
37997
38006
  }
@@ -38013,7 +38022,7 @@ async function uploadBinaryFile(root, relPath, contentBase64) {
38013
38022
  }
38014
38023
  }
38015
38024
  async function downloadBinaryFile(root, relPath) {
38016
- const target = resolveInRoot3(root, relPath);
38025
+ const target = resolveInRoot4(root, relPath);
38017
38026
  if (!target) return { error: "path escapes the project root" };
38018
38027
  try {
38019
38028
  const info = await stat2(target);
@@ -38042,7 +38051,7 @@ function handleFsChannels(ctx, message, payload) {
38042
38051
  );
38043
38052
  return true;
38044
38053
  case WsChannels.FS_READ:
38045
- void readWorkerFile(payload.path).then(
38054
+ void readWorkerFile(ctx.physicRoot, payload.path).then(
38046
38055
  (reply) => ctx.send(WsChannels.FS_READ, reply, message.id)
38047
38056
  );
38048
38057
  return true;
@@ -38082,11 +38091,20 @@ function handleFsChannels(ctx, message, payload) {
38082
38091
  // src/core/git-diff.ts
38083
38092
  import { readFile as readFile5 } from "fs/promises";
38084
38093
  import { execFile as execFile4 } from "child_process";
38085
- import { basename as basename5, dirname as dirname6, resolve as resolve6 } from "path";
38094
+ import { basename as basename5, dirname as dirname6, resolve as resolve6, sep as sep7 } from "path";
38086
38095
  import { promisify as promisify4 } from "util";
38087
38096
  var run4 = promisify4(execFile4);
38088
- async function gitDiff(path) {
38089
- const target = resolve6(path);
38097
+ function resolveInRoot5(root, relPath) {
38098
+ if (!root) return null;
38099
+ const base = resolve6(root);
38100
+ const target = resolve6(base, relPath || ".");
38101
+ return target === base || target.startsWith(base + sep7) ? target : null;
38102
+ }
38103
+ async function gitDiff(root, path) {
38104
+ const target = resolveInRoot5(root, path);
38105
+ if (!target) {
38106
+ return { path, oldContent: "", newContent: "" };
38107
+ }
38090
38108
  const dir2 = dirname6(target);
38091
38109
  const base = basename5(target);
38092
38110
  let newContent = "";
@@ -38209,7 +38227,7 @@ async function manageSshKey(op, profileDir2) {
38209
38227
  // src/core/git-history.ts
38210
38228
  import { readdir as readdir3 } from "fs/promises";
38211
38229
  import { execFile as execFile7 } from "child_process";
38212
- import { resolve as resolve7, sep as sep6 } from "path";
38230
+ import { resolve as resolve7, sep as sep8 } from "path";
38213
38231
  import { promisify as promisify7 } from "util";
38214
38232
  var run7 = promisify7(execFile7);
38215
38233
  var FS = "";
@@ -38218,7 +38236,7 @@ function resolveRepo(root, repo) {
38218
38236
  if (!root) return null;
38219
38237
  const base = resolve7(root);
38220
38238
  const requested = resolve7(base, repo && repo.trim() ? repo : ".");
38221
- return requested === base || requested.startsWith(base + sep6) ? requested : base;
38239
+ return requested === base || requested.startsWith(base + sep8) ? requested : base;
38222
38240
  }
38223
38241
  async function git(cwd2, args) {
38224
38242
  try {
@@ -38240,7 +38258,7 @@ async function gitRepos(root) {
38240
38258
  const add = async (dir2) => {
38241
38259
  const inside = await git(dir2, ["rev-parse", "--show-toplevel"]);
38242
38260
  const top = inside.trim();
38243
- if (!top || found.has(top) || !(top === base || top.startsWith(base + sep6))) return;
38261
+ if (!top || found.has(top) || !(top === base || top.startsWith(base + sep8))) return;
38244
38262
  found.add(top);
38245
38263
  const subdir = top === base ? "" : top.slice(base.length + 1);
38246
38264
  const remote = (await git(top, ["remote", "get-url", "origin"])).trim();
@@ -38327,7 +38345,7 @@ async function gitCommitDiff(root, repo, hash, path) {
38327
38345
  function handleGitChannels(ctx, message, payload) {
38328
38346
  switch (message.channel) {
38329
38347
  case WsChannels.GIT_DIFF:
38330
- void gitDiff(payload.path).then(
38348
+ void gitDiff(ctx.physicRoot, payload.path).then(
38331
38349
  (reply) => ctx.send(WsChannels.GIT_DIFF, reply, message.id)
38332
38350
  );
38333
38351
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@4pm/cli",
3
- "version": "1.5.40",
3
+ "version": "1.5.42",
4
4
  "private": false,
5
5
  "description": "4PM CLI — drives Claude/Codex CLIs on AI worker machines (Node + TypeScript)",
6
6
  "license": "LicenseRef-4PM-Source-Available",