@foldrun/core 24.1.1 → 24.2.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.
@@ -122,6 +122,19 @@ export declare function deployWarnings(files: DeployFile[]): DeployIssue[];
122
122
  * this as the server's view of the same rules, not a second set.
123
123
  */
124
124
  export declare function checkFiles(files: DeployFile[], options?: ScanOptions): ScanFinding[];
125
+ /**
126
+ * The deploy paths that cannot be written whatever the workspace holds: one
127
+ * that names no file (empty, ".", ending in "/") and one that is also a
128
+ * folder of another path in the same deploy. They reached open() — an
129
+ * EISDIR, a 500 from POST …/deploy (FOL-199, hosted fuzz). The route answers
130
+ * them 400 before anything reads the files; deployIssues reports them too.
131
+ */
132
+ export declare function deployPathProblems(files: {
133
+ path: string;
134
+ }[]): {
135
+ issues: DeployIssue[];
136
+ unwritable: Set<string>;
137
+ };
125
138
  export declare function deployIssues(files: DeployFile[]): DeployIssue[];
126
139
  /**
127
140
  * Runs that make this a bad moment to swap the files under them.
@@ -454,6 +454,35 @@ function structuralWarnings(files, extraOutward = []) {
454
454
  }
455
455
  return out;
456
456
  }
457
+ /**
458
+ * The deploy paths that cannot be written whatever the workspace holds: one
459
+ * that names no file (empty, ".", ending in "/") and one that is also a
460
+ * folder of another path in the same deploy. They reached open() — an
461
+ * EISDIR, a 500 from POST …/deploy (FOL-199, hosted fuzz). The route answers
462
+ * them 400 before anything reads the files; deployIssues reports them too.
463
+ */
464
+ export function deployPathProblems(files) {
465
+ const issues = [];
466
+ const unwritable = new Set();
467
+ const folders = new Set();
468
+ for (const f of files) {
469
+ const parts = path.normalize(f.path).split("/");
470
+ for (let i = 1; i < parts.length; i++)
471
+ folders.add(parts.slice(0, i).join("/"));
472
+ }
473
+ for (const f of files) {
474
+ const norm = path.normalize(f.path);
475
+ if (!f.path.trim() || norm === "." || norm === "./" || /[/\\]$/.test(f.path)) {
476
+ issues.push({ where: f.path, message: "not a file path — a deploy names files, never a folder" });
477
+ unwritable.add(f.path);
478
+ }
479
+ else if (folders.has(norm)) {
480
+ issues.push({ where: f.path, message: "is a folder of another file in this deploy — one path cannot be both" });
481
+ unwritable.add(f.path);
482
+ }
483
+ }
484
+ return { issues, unwritable };
485
+ }
457
486
  export function deployIssues(files) {
458
487
  const issues = [];
459
488
  const at = (where, message) => issues.push({ where, message });
@@ -463,6 +492,10 @@ export function deployIssues(files) {
463
492
  at("/", `${files.length} files — a workspace is capped at 500`);
464
493
  // Path safety, as questions rather than exceptions: a push should report
465
494
  // everything wrong with it at once, not fail on the first bad path.
495
+ // Paths that name no file, or one that is also a folder here (FOL-199).
496
+ const shape = deployPathProblems(files);
497
+ issues.push(...shape.issues);
498
+ const unwritable = shape.unwritable;
466
499
  for (const f of files) {
467
500
  const norm = path.normalize(f.path);
468
501
  if (norm.startsWith("..") || path.isAbsolute(norm) || norm.startsWith("runs")) {
@@ -637,13 +670,23 @@ export function deployIssues(files) {
637
670
  try {
638
671
  for (const f of files) {
639
672
  const norm = path.normalize(f.path);
640
- if (norm.startsWith("..") || path.isAbsolute(norm))
673
+ if (norm.startsWith("..") || path.isAbsolute(norm) || unwritable.has(f.path))
641
674
  continue;
642
675
  const target = path.join(staged, norm);
643
676
  fs.mkdirSync(path.dirname(target), { recursive: true });
644
677
  fs.writeFileSync(target, f.content);
645
678
  }
679
+ // Only a bundle that is a folder: a FILE called knowledge is not one
680
+ // (readdir of it was an ENOTDIR, a 500 — FOL-199).
681
+ const isDir = (d) => { try {
682
+ return fs.statSync(d).isDirectory();
683
+ }
684
+ catch {
685
+ return false;
686
+ } };
646
687
  for (const bundle of ["memory", "knowledge"]) {
688
+ if (!isDir(path.join(staged, bundle)))
689
+ continue;
647
690
  for (const { file, issue } of conformanceIssues(path.join(staged, bundle))) {
648
691
  at(`${bundle}/${file}`, issue);
649
692
  }
@@ -651,6 +694,8 @@ export function deployIssues(files) {
651
694
  for (const agent of agents) {
652
695
  for (const bundle of ["memory", "knowledge"]) {
653
696
  const dir = path.join(staged, "agents", agent, bundle);
697
+ if (!isDir(dir))
698
+ continue;
654
699
  for (const { file, issue } of conformanceIssues(dir)) {
655
700
  at(`agents/${agent}/${bundle}/${file}`, issue);
656
701
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foldrun/core",
3
- "version": "24.1.1",
3
+ "version": "24.2.0",
4
4
  "description": "Agents are just folders. The format, the runner, the checks.",
5
5
  "license": "FSL-1.1-ALv2",
6
6
  "type": "module",
package/src/deploy.ts CHANGED
@@ -492,6 +492,34 @@ function structuralWarnings(files: DeployFile[], extraOutward: Iterable<string>
492
492
  return out;
493
493
  }
494
494
 
495
+ /**
496
+ * The deploy paths that cannot be written whatever the workspace holds: one
497
+ * that names no file (empty, ".", ending in "/") and one that is also a
498
+ * folder of another path in the same deploy. They reached open() — an
499
+ * EISDIR, a 500 from POST …/deploy (FOL-199, hosted fuzz). The route answers
500
+ * them 400 before anything reads the files; deployIssues reports them too.
501
+ */
502
+ export function deployPathProblems(files: { path: string }[]): { issues: DeployIssue[]; unwritable: Set<string> } {
503
+ const issues: DeployIssue[] = [];
504
+ const unwritable = new Set<string>();
505
+ const folders = new Set<string>();
506
+ for (const f of files) {
507
+ const parts = path.normalize(f.path).split("/");
508
+ for (let i = 1; i < parts.length; i++) folders.add(parts.slice(0, i).join("/"));
509
+ }
510
+ for (const f of files) {
511
+ const norm = path.normalize(f.path);
512
+ if (!f.path.trim() || norm === "." || norm === "./" || /[/\\]$/.test(f.path)) {
513
+ issues.push({ where: f.path, message: "not a file path — a deploy names files, never a folder" });
514
+ unwritable.add(f.path);
515
+ } else if (folders.has(norm)) {
516
+ issues.push({ where: f.path, message: "is a folder of another file in this deploy — one path cannot be both" });
517
+ unwritable.add(f.path);
518
+ }
519
+ }
520
+ return { issues, unwritable };
521
+ }
522
+
495
523
  export function deployIssues(files: DeployFile[]): DeployIssue[] {
496
524
  const issues: DeployIssue[] = [];
497
525
  const at = (where: string, message: string) => issues.push({ where, message });
@@ -501,6 +529,10 @@ export function deployIssues(files: DeployFile[]): DeployIssue[] {
501
529
 
502
530
  // Path safety, as questions rather than exceptions: a push should report
503
531
  // everything wrong with it at once, not fail on the first bad path.
532
+ // Paths that name no file, or one that is also a folder here (FOL-199).
533
+ const shape = deployPathProblems(files);
534
+ issues.push(...shape.issues);
535
+ const unwritable = shape.unwritable;
504
536
  for (const f of files) {
505
537
  const norm = path.normalize(f.path);
506
538
  if (norm.startsWith("..") || path.isAbsolute(norm) || norm.startsWith("runs")) {
@@ -654,12 +686,16 @@ export function deployIssues(files: DeployFile[]): DeployIssue[] {
654
686
  try {
655
687
  for (const f of files) {
656
688
  const norm = path.normalize(f.path);
657
- if (norm.startsWith("..") || path.isAbsolute(norm)) continue;
689
+ if (norm.startsWith("..") || path.isAbsolute(norm) || unwritable.has(f.path)) continue;
658
690
  const target = path.join(staged, norm);
659
691
  fs.mkdirSync(path.dirname(target), { recursive: true });
660
692
  fs.writeFileSync(target, f.content);
661
693
  }
694
+ // Only a bundle that is a folder: a FILE called knowledge is not one
695
+ // (readdir of it was an ENOTDIR, a 500 — FOL-199).
696
+ const isDir = (d: string) => { try { return fs.statSync(d).isDirectory(); } catch { return false; } };
662
697
  for (const bundle of ["memory", "knowledge"]) {
698
+ if (!isDir(path.join(staged, bundle))) continue;
663
699
  for (const { file, issue } of conformanceIssues(path.join(staged, bundle))) {
664
700
  at(`${bundle}/${file}`, issue);
665
701
  }
@@ -667,6 +703,7 @@ export function deployIssues(files: DeployFile[]): DeployIssue[] {
667
703
  for (const agent of agents) {
668
704
  for (const bundle of ["memory", "knowledge"]) {
669
705
  const dir = path.join(staged, "agents", agent, bundle);
706
+ if (!isDir(dir)) continue;
670
707
  for (const { file, issue } of conformanceIssues(dir)) {
671
708
  at(`agents/${agent}/${bundle}/${file}`, issue);
672
709
  }