Skip to content

Fully autonomous AI Agents system capable of performing complex penetration testing tasks

refactor(resources): update MoveResourceRequest to allow empty destination

Dmitry Nga9aeb81e4e2a
diff --git a/backend/pkg/server/docs/docs.go b/backend/pkg/server/docs/docs.go
index 0c5d5236..771e1d43 100644
--- a/backend/pkg/server/docs/docs.go
+++ b/backend/pkg/server/docs/docs.go
@@ -8582,12 +8582,9 @@ const docTemplate = `{
},
"models.MoveResourceRequest": {
"type": "object",
- "required": [
- "destination"
- ],
"properties": {
"destination": {
- "description": "Destination is the exact target path (single source) or base directory\n(multiple sources). Required.",
+ "description": "Destination is the exact target path (single source) or base directory\n(multiple sources). Empty string means the root directory.",
"type": "string"
},
"force": {
diff --git a/backend/pkg/server/docs/swagger.json b/backend/pkg/server/docs/swagger.json
index c90caccb..090a04c7 100644
--- a/backend/pkg/server/docs/swagger.json
+++ b/backend/pkg/server/docs/swagger.json
@@ -8574,12 +8574,9 @@
},
"models.MoveResourceRequest": {
"type": "object",
- "required": [
- "destination"
- ],
"properties": {
"destination": {
- "description": "Destination is the exact target path (single source) or base directory\n(multiple sources). Required.",
+ "description": "Destination is the exact target path (single source) or base directory\n(multiple sources). Empty string means the root directory.",
"type": "string"
},
"force": {
diff --git a/backend/pkg/server/docs/swagger.yaml b/backend/pkg/server/docs/swagger.yaml
index 975abf8c..6afd04d5 100644
--- a/backend/pkg/server/docs/swagger.yaml
+++ b/backend/pkg/server/docs/swagger.yaml
@@ -969,7 +969,7 @@ definitions:
destination:
description: |-
Destination is the exact target path (single source) or base directory
- (multiple sources). Required.
+ (multiple sources). Empty string means the root directory.
type: string
force:
description: Force overwrites existing resources at the target paths when
@@ -987,8 +987,6 @@ definitions:
items:
type: string
type: array
- required:
- - destination
type: object
models.Msglog:
properties:
diff --git a/backend/pkg/server/models/resources.go b/backend/pkg/server/models/resources.go
index f8fb3431..4b3ae2c7 100644
--- a/backend/pkg/server/models/resources.go
+++ b/backend/pkg/server/models/resources.go
@@ -60,8 +60,8 @@ type MoveResourceRequest struct {
// Combined with Source when both are provided; duplicates are removed.
Sources []string `json:"sources"`
// Destination is the exact target path (single source) or base directory
- // (multiple sources). Required.
- Destination string `json:"destination" binding:"required"`
+ // (multiple sources). Empty string means the root directory.
+ Destination string `json:"destination"`
// Force overwrites existing resources at the target paths when true.
Force bool `json:"force"`
}
diff --git a/backend/pkg/server/services/resources.go b/backend/pkg/server/services/resources.go
index 2fed11a8..8fae9956 100644
--- a/backend/pkg/server/services/resources.go
+++ b/backend/pkg/server/services/resources.go
@@ -590,7 +590,8 @@ func (s *ResourceService) MoveResource(c *gin.Context) {
}
// ── Sanitize destination ──────────────────────────────────────────────────
- dstPath, err := resources.SanitizeResourcePath(req.Destination)
+ // Empty destination is allowed and means "move into the root directory".
+ dstPath, err := resources.SanitizeResourceDir(req.Destination)
if err != nil {
response.Error(c, response.ErrResourcesInvalidRequest, fmt.Errorf("invalid destination: %w", err))
return
@@ -611,7 +612,10 @@ func (s *ResourceService) MoveResource(c *gin.Context) {
var result moveResourceResult
if len(srcPaths) == 1 {
srcPath := srcPaths[0]
- if srcPath == dstPath {
+ // When destination is root (""), the effective target is <root>/<src.Name>.
+ // A source already living at root would land on itself — catch it early.
+ dstIsDirHint := dstPath == "" || pathHasTrailingSeparator(req.Destination)
+ if srcPath == dstPath || (dstPath == "" && !strings.Contains(srcPath, "/")) {
response.Error(c, response.ErrResourcesInvalidRequest, errors.New("source and destination are the same"))
return
}
@@ -625,7 +629,7 @@ func (s *ResourceService) MoveResource(c *gin.Context) {
response.Error(c, response.ErrInternal, err)
return
}
- result, err = s.moveResource(uid, src, srcPath, dstPath, req.Force, pathHasTrailingSeparator(req.Destination))
+ result, err = s.moveResource(uid, src, srcPath, dstPath, req.Force, dstIsDirHint)
} else {
result, err = s.moveMultipleSources(uid, srcPaths, dstPath, req.Force)
}
@@ -827,6 +831,19 @@ func (s *ResourceService) moveResource(
return result, nil
}
+ // For directory sources: if the destination is an existing directory,
+ // move the source INTO it (Unix mv semantics: "mv docs archive" where
+ // archive exists → archive/docs), just like moveFileResource already does
+ // for files. When the destination is absent the source is renamed to it.
+ dest, destExists, err := findResourceByPath(tx, uid, dstPath)
+ if err != nil {
+ tx.Rollback()
+ return moveResourceResult{}, err
+ }
+ if destExists && dest.IsDir {
+ dstPath = resources.FilePath(dstPath, src.Name)
+ }
+
result, err := s.moveDirResource(tx, uid, srcPath, dstPath, force)
if err != nil {
tx.Rollback()
@@ -917,6 +934,10 @@ func (s *ResourceService) moveDirResource(
if resources.PathHasPrefix(dstPath, srcPath) {
return result, fmt.Errorf("%w: cannot move directory into itself", errResourceInvalid)
}
+ // Moving a directory to root (dstPath=="") means placing it at root level
+ if dstPath == "" {
+ dstPath = path.Base(srcPath)
+ }
createdParents, deletedParents, orphanHashes, err := ensureResourceDirs(tx, uid, resources.ParentDir(dstPath), force)
if err != nil {
diff --git a/backend/pkg/server/services/resources_test.go b/backend/pkg/server/services/resources_test.go
index 7ce19779..f5e4abc4 100644
--- a/backend/pkg/server/services/resources_test.go
+++ b/backend/pkg/server/services/resources_test.go
@@ -2455,14 +2455,16 @@ func TestResourceService_MoveResourceScenarios(t *testing.T) {
wantDeletedBlobTexts: []string{"file"},
},
{
- name: "directory to existing directory without force conflicts",
- seeds: []seed{{path: "docs", isDir: true}, {path: "archive", isDir: true}},
- req: moveRequest{Source: "docs", Destination: "archive"},
- wantStatus: http.StatusConflict,
- wantPaths: []string{"archive", "docs"},
+ name: "directory to existing directory moves inside",
+ seeds: []seed{{path: "docs", isDir: true}, {path: "archive", isDir: true}},
+ req: moveRequest{Source: "docs", Destination: "archive"},
+ wantStatus: http.StatusOK,
+ wantPaths: []string{"archive", "archive/docs"},
+ wantResponsePaths: []string{"archive/docs"},
+ wantEvents: []resourceEvent{{action: "updated", path: "archive/docs"}},
},
{
- name: "directory to existing directory with force merges",
+ name: "directory to existing directory moves whole tree inside",
seeds: []seed{
{path: "docs", isDir: true},
{path: "docs/a.txt", content: "a"},
@@ -2470,57 +2472,76 @@ func TestResourceService_MoveResourceScenarios(t *testing.T) {
{path: "docs/sub/b.txt", content: "b"},
{path: "archive", isDir: true},
},
- req: moveRequest{Source: "docs", Destination: "archive", Force: true},
+ req: moveRequest{Source: "docs", Destination: "archive"},
wantStatus: http.StatusOK,
- wantPaths: []string{"archive", "archive/a.txt", "archive/sub", "archive/sub/b.txt"},
- wantResponsePaths: []string{"archive/a.txt", "archive/sub", "archive/sub/b.txt"},
+ wantPaths: []string{"archive", "archive/docs", "archive/docs/a.txt", "archive/docs/sub", "archive/docs/sub/b.txt"},
+ wantResponsePaths: []string{"archive/docs", "archive/docs/a.txt", "archive/docs/sub", "archive/docs/sub/b.txt"},
wantEvents: []resourceEvent{
- {action: "updated", path: "archive/a.txt"},
- {action: "updated", path: "archive/sub"},
- {action: "updated", path: "archive/sub/b.txt"},
- {action: "deleted", path: "docs"},
+ {action: "updated", path: "archive/docs"},
+ {action: "updated", path: "archive/docs/a.txt"},
+ {action: "updated", path: "archive/docs/sub"},
+ {action: "updated", path: "archive/docs/sub/b.txt"},
},
},
{
- name: "directory merge with existing file overwrites file",
+ name: "directory moved into existing dir that already contains same-name subdir conflicts without force",
+ seeds: []seed{
+ {path: "docs", isDir: true},
+ {path: "archive", isDir: true},
+ {path: "archive/docs", isDir: true},
+ },
+ req: moveRequest{Source: "docs", Destination: "archive"},
+ wantStatus: http.StatusConflict,
+ wantPaths: []string{"archive", "archive/docs", "docs"},
+ },
+ {
+ name: "directory merged into existing subdirectory overwrites file with force",
seeds: []seed{
{path: "docs", isDir: true},
{path: "docs/a.txt", content: "src-a"},
{path: "archive", isDir: true},
- {path: "archive/a.txt", content: "dst-a"},
+ {path: "archive/docs", isDir: true},
+ {path: "archive/docs/a.txt", content: "dst-a"},
},
req: moveRequest{Source: "docs", Destination: "archive", Force: true},
wantStatus: http.StatusOK,
- wantPaths: []string{"archive", "archive/a.txt"},
- wantResponsePaths: []string{"archive/a.txt"},
- wantEvents: []resourceEvent{{action: "deleted", path: "archive/a.txt"}, {action: "updated", path: "archive/a.txt"}, {action: "deleted", path: "docs"}},
+ wantPaths: []string{"archive", "archive/docs", "archive/docs/a.txt"},
+ wantResponsePaths: []string{"archive/docs/a.txt"},
+ wantEvents: []resourceEvent{{action: "deleted", path: "archive/docs/a.txt"}, {action: "updated", path: "archive/docs/a.txt"}, {action: "deleted", path: "docs"}},
wantDeletedBlobTexts: []string{"dst-a"},
},
{
- name: "directory merge with existing subdirectory keeps destination directory",
+ name: "directory merged into existing subdirectory keeps destination subdirectory with force",
seeds: []seed{
{path: "docs", isDir: true},
{path: "docs/sub", isDir: true},
{path: "docs/sub/a.txt", content: "a"},
{path: "archive", isDir: true},
- {path: "archive/sub", isDir: true},
+ {path: "archive/docs", isDir: true},
+ {path: "archive/docs/sub", isDir: true},
},
req: moveRequest{Source: "docs", Destination: "archive", Force: true},
wantStatus: http.StatusOK,
- wantPaths: []string{"archive", "archive/sub", "archive/sub/a.txt"},
- wantResponsePaths: []string{"archive/sub/a.txt"},
+ wantPaths: []string{"archive", "archive/docs", "archive/docs/sub", "archive/docs/sub/a.txt"},
+ wantResponsePaths: []string{"archive/docs/sub/a.txt"},
wantEvents: []resourceEvent{
- {action: "updated", path: "archive/sub/a.txt"},
+ {action: "updated", path: "archive/docs/sub/a.txt"},
{action: "deleted", path: "docs/sub"},
{action: "deleted", path: "docs"},
},
},
{
- name: "directory merge file over existing directory conflicts",
- seeds: []seed{{path: "docs", isDir: true}, {path: "docs/a.txt", content: "a"}, {path: "archive", isDir: true}, {path: "archive/a.txt", isDir: true}},
+ name: "directory merged into existing subdirectory with file-vs-dir conflict fails",
+ seeds: []seed{
+ {path: "docs", isDir: true},
+ {path: "docs/a.txt", content: "a"},
+ {path: "archive", isDir: true},
+ {path: "archive/docs", isDir: true},
+ {path: "archive/docs/a.txt", isDir: true},
+ },
req: moveRequest{Source: "docs", Destination: "archive", Force: true},
wantStatus: http.StatusConflict,
- wantPaths: []string{"archive", "archive/a.txt", "docs", "docs/a.txt"},
+ wantPaths: []string{"archive", "archive/docs", "archive/docs/a.txt", "docs", "docs/a.txt"},
},
{
name: "directory into itself is invalid",
@@ -2690,6 +2711,63 @@ func TestResourceService_MoveResourceScenarios(t *testing.T) {
wantStatus: http.StatusBadRequest,
wantPaths: []string{"a.txt"},
},
+
+ // ── move to root (destination == "") ─────────────────────────────────
+ {
+ name: "single source: file in subdirectory moved to root",
+ seeds: []seed{{path: "reports", isDir: true}, {path: "reports/openai-report.md", content: "rpt"}},
+ req: moveRequest{Source: "reports/openai-report.md", Destination: ""},
+ wantStatus: http.StatusOK,
+ wantPaths: []string{"reports", "openai-report.md"},
+ wantResponsePaths: []string{"openai-report.md"},
+ wantEvents: []resourceEvent{{action: "updated", path: "openai-report.md"}},
+ },
+ {
+ name: "single source: file already at root moved to root returns same-location error",
+ seeds: []seed{{path: "report.md", content: "rpt"}},
+ req: moveRequest{Source: "report.md", Destination: ""},
+ wantStatus: http.StatusBadRequest,
+ wantPaths: []string{"report.md"},
+ },
+ {
+ name: "single source: directory in subdirectory moved to root",
+ seeds: []seed{
+ {path: "sub", isDir: true},
+ {path: "sub/docs", isDir: true},
+ {path: "sub/docs/a.txt", content: "a"},
+ },
+ req: moveRequest{Source: "sub/docs", Destination: ""},
+ wantStatus: http.StatusOK,
+ wantPaths: []string{"sub", "docs", "docs/a.txt"},
+ wantResponsePaths: []string{"docs", "docs/a.txt"},
+ wantEvents: []resourceEvent{
+ {action: "updated", path: "docs"},
+ {action: "updated", path: "docs/a.txt"},
+ },
+ },
+ {
+ name: "single source: directory already at root moved to root returns same-location error",
+ seeds: []seed{{path: "docs", isDir: true}},
+ req: moveRequest{Source: "docs", Destination: ""},
+ wantStatus: http.StatusBadRequest,
+ wantPaths: []string{"docs"},
+ },
+ {
+ name: "multi-source: files moved to root",
+ seeds: []seed{
+ {path: "sub", isDir: true},
+ {path: "sub/a.txt", content: "aaa"},
+ {path: "sub/b.txt", content: "bbb"},
+ },
+ req: moveRequest{Sources: []string{"sub/a.txt", "sub/b.txt"}, Destination: ""},
+ wantStatus: http.StatusOK,
+ wantPaths: []string{"sub", "a.txt", "b.txt"},
+ wantResponsePaths: []string{"a.txt", "b.txt"},
+ wantEvents: []resourceEvent{
+ {action: "updated", path: "a.txt"},
+ {action: "updated", path: "b.txt"},
+ },
+ },
}
for _, tt := range tests {
diff --git a/frontend/src/lib/axios.ts b/frontend/src/lib/axios.ts
index a25b9f2b..cf496cd2 100644
--- a/frontend/src/lib/axios.ts
+++ b/frontend/src/lib/axios.ts
@@ -142,6 +142,13 @@ axios.interceptors.response.use(
break;
}
+ case 409: {
+ // Conflict is an expected outcome for operations with an
+ // overwrite workflow (move, copy, etc.). The calling hook
+ // handles it and shows a prompt; there is nothing to log.
+ break;
+ }
+
default: {
Log.error(err.response?.data);
}
diff --git a/frontend/src/pages/knowledges/knowledges.tsx b/frontend/src/pages/knowledges/knowledges.tsx
index 1d525e00..7cae2f89 100644
--- a/frontend/src/pages/knowledges/knowledges.tsx
+++ b/frontend/src/pages/knowledges/knowledges.tsx
@@ -379,7 +379,7 @@ const Knowledges = () => {
columns={columns}
data={knowledges}
filterColumn="question"
- filterPlaceholder="Filter by question..."
+ filterPlaceholder="Filter knowledge documents..."
onRowClick={(k) => handleOpen(k.id)}
renderRowContextMenu={renderRowContextMenu}
/>