Repository navigation
Commit a54c342
committed
fix(harness): keep the workspace subtree invisible to the project layer
## Description
With the default local filesystem, the project layer reaches across
namespaces in three ways:
- Enumeration: `grep(pattern, "")` returns matches from another user's
`MEMORY.md`, content included; `ls("")` and `glob("**/*.md", "")` list the
sibling namespaces. The overlay hands the same path to the upper (workspace)
and lower (project) layers, the default workspace is a subtree of the
project directory, and the lower layer carries no namespace.
- Direct content access: `read`, `exists`, `edit` (copy-on-write),
`downloadFiles` and `move` fall back to the lower layer too, so a relative
path spelling the physical layout - `.agentscope/workspace/alice/MEMORY.md`
- reads alice's file, and `edit` copies it into the caller's namespace
before modifying it.
- Absolute paths: the namespace prefix is skipped for absolute spellings, so
without a boundary the `projectFs` write route would run a delete or move
against an absolute path inside the workspace subtree.
Previously `LocalFilesystem.resolvePath` passed a blank key to the namespace
prefix unchanged, so it resolved to the workspace root; the physical layout
was reachable whenever the caller named it.
### What changed
- A blank key is resolved as `.` before the namespace is applied, so an
empty path means "the caller's root" instead of the shared workspace root.
Deployments without a namespace resolve to the same directory as before.
- `LocalFilesystem` can hide a subtree entirely: enumeration skips it while
walking, and the content operations - reads, edits, writes, deletes, moves,
downloads, uploads and existence checks - see nothing there. `delete`
treats the subtree as absent (an idempotent no-op that never walks it),
`move` can neither move a file out of or into the subtree, and both `move`
and recursive `delete` refuse a directory that contains it outright rather
than partially touch it. Explicitly addressing a hidden subtree as a
search root yields nothing rather than walking it, and a `walkFileTree`
visitor that cannot enter a directory skips and continues instead of
propagating.
- `LocalFilesystemSpec` hides the workspace from the project layers when the
workspace is a proper subtree of the project and namespace scoping is on -
both the read-only lower layer and, for the same reason, the `projectFs`
write route, whose absolute paths skip the namespace prefix. A workspace
equal to or outside the project has no nesting to hide, a shared workspace
belongs to every caller equally, and project files outside the workspace
subtree stay shared, like `AGENTS.md` and `knowledge/`.
- `relativeForGlob` compares the first path name instead of the string, so a
legitimate directory literally named `..cache` is a descendant, not a
traversal escape.
- `docs/v2/{zh,en}/docs/harness/filesystem.md` note the boundary in the
Overlay filesystem section, the project-writable read behavior, and the
mode table.
Absolute paths in the upper (workspace) layer and `..` segments are out of
scope: #3292 covers the former, #3378 the latter. The shell keeps its own
project-rooted working directory, so `execute` is not bound by these guards
(#2329). The ripgrep `--glob` exclusions assume rg matches globs against
paths relative to the search root; where that does not hold, the boundary
still holds because the default workspace lives under a hidden directory
that rg skips by default, and the `walkFileTree` fallback applies the same
exclusions directly.
### Tests
- New: as one user, a blank, relative or glob search sees nothing under
another user's namespace - in both the default and the writable-project
construction - and the content operations answer "not found" for a
sibling namespace spelled through the physical layout, while project
files outside the workspace and the caller's own namespace stay readable.
- New: direct use of the hidden lower layer - `delete` leaves the subtree
untouched, `move` cannot cross the boundary in either direction, writes
cannot land inside it (the target does not exist yet, so the assertion
cannot pass merely because the file is there), and operations that start
at an ancestor (recursive delete, directory move) are refused outright
instead of partially touching the hidden subtree. Each of these assertions
was verified to fail with its guard removed.
- New: a shared workspace stays enumerable through the project layer, so
the boundary does not over-reach into single-tenant deployments.
- New: `memory_get` cannot fetch a sibling namespace's content. This test's
workspace is a standalone temp directory, so it pins the blank-key and
namespace-prefix resolution end to end; the real project-layer boundary is
exercised by the boundary tests below.
- `mvn -pl agentscope-harness test`: 1626 tests, 0 failures.
Fixes #40691 parent c52d1fc commit a54c342
6 files changed
Lines changed: 479 additions & 43 deletions
File tree
- agentscope-harness/src
- main/java/io/agentscope/harness/agent/filesystem
- local
- spec
- test/java/io/agentscope/harness/agent
- example
- filesystem
- docs/v2
- en/docs/harness
- zh/docs/harness
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| |||
92 | 93 | | |
93 | 94 | | |
94 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
95 | 109 | | |
96 | 110 | | |
97 | 111 | | |
| |||
237 | 251 | | |
238 | 252 | | |
239 | 253 | | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
240 | 257 | | |
241 | 258 | | |
242 | 259 | | |
| |||
247 | 264 | | |
248 | 265 | | |
249 | 266 | | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
250 | 270 | | |
251 | 271 | | |
252 | 272 | | |
| |||
274 | 294 | | |
275 | 295 | | |
276 | 296 | | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
277 | 300 | | |
278 | 301 | | |
279 | 302 | | |
| |||
324 | 347 | | |
325 | 348 | | |
326 | 349 | | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
327 | 353 | | |
328 | 354 | | |
329 | 355 | | |
| |||
357 | 383 | | |
358 | 384 | | |
359 | 385 | | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
360 | 389 | | |
361 | 390 | | |
362 | 391 | | |
| |||
403 | 432 | | |
404 | 433 | | |
405 | 434 | | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
406 | 438 | | |
407 | 439 | | |
408 | 440 | | |
| |||
428 | 460 | | |
429 | 461 | | |
430 | 462 | | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
431 | 466 | | |
432 | 467 | | |
433 | 468 | | |
| |||
451 | 486 | | |
452 | 487 | | |
453 | 488 | | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
454 | 497 | | |
455 | 498 | | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
456 | 502 | | |
457 | 503 | | |
458 | 504 | | |
| |||
486 | 532 | | |
487 | 533 | | |
488 | 534 | | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
489 | 539 | | |
490 | 540 | | |
491 | 541 | | |
| |||
507 | 557 | | |
508 | 558 | | |
509 | 559 | | |
510 | | - | |
| 560 | + | |
511 | 561 | | |
512 | 562 | | |
513 | 563 | | |
| |||
530 | 580 | | |
531 | 581 | | |
532 | 582 | | |
533 | | - | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
534 | 586 | | |
535 | 587 | | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
536 | 593 | | |
537 | 594 | | |
| 595 | + | |
| 596 | + | |
538 | 597 | | |
539 | 598 | | |
540 | 599 | | |
| |||
561 | 620 | | |
562 | 621 | | |
563 | 622 | | |
564 | | - | |
| 623 | + | |
565 | 624 | | |
566 | 625 | | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
567 | 633 | | |
568 | 634 | | |
569 | 635 | | |
| |||
582 | 648 | | |
583 | 649 | | |
584 | 650 | | |
585 | | - | |
| 651 | + | |
| 652 | + | |
586 | 653 | | |
587 | 654 | | |
588 | 655 | | |
| |||
600 | 667 | | |
601 | 668 | | |
602 | 669 | | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
603 | 712 | | |
604 | 713 | | |
605 | 714 | | |
606 | 715 | | |
607 | 716 | | |
608 | | - | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
609 | 720 | | |
610 | 721 | | |
611 | 722 | | |
| |||
780 | 891 | | |
781 | 892 | | |
782 | 893 | | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
783 | 910 | | |
784 | 911 | | |
785 | 912 | | |
| |||
790 | 917 | | |
791 | 918 | | |
792 | 919 | | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
793 | 927 | | |
794 | 928 | | |
795 | 929 | | |
| |||
889 | 1023 | | |
890 | 1024 | | |
891 | 1025 | | |
| 1026 | + | |
892 | 1027 | | |
893 | 1028 | | |
894 | 1029 | | |
895 | 1030 | | |
896 | | - | |
897 | | - | |
898 | | - | |
899 | | - | |
900 | | - | |
901 | | - | |
902 | | - | |
903 | | - | |
904 | | - | |
905 | | - | |
906 | | - | |
907 | | - | |
908 | | - | |
909 | | - | |
910 | | - | |
911 | | - | |
912 | | - | |
913 | | - | |
914 | | - | |
915 | | - | |
916 | | - | |
917 | | - | |
918 | | - | |
919 | | - | |
920 | | - | |
921 | | - | |
922 | | - | |
923 | | - | |
924 | | - | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
925 | 1062 | | |
926 | | - | |
927 | | - | |
928 | 1063 | | |
929 | | - | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
930 | 1075 | | |
931 | 1076 | | |
932 | 1077 | | |
| |||
0 commit comments