qioo777 opened a new pull request, #230:
URL: https://github.com/apache/casbin-gateway/pull/230
## Problem
The working directory on the chat page reached `cmd.Dir`, but only as the raw
text and only when the first prompt ran:
- A relative path was accepted. `os.Stat("data")` succeeds when Gateway's own
directory contains `data`, so the bare string went to `cmd.Dir` and was
resolved against Gateway rather than against anything the user meant. The
agent ran in the wrong place without an error.
- `~` was never expanded, and failed with a raw OS error.
- Nothing was checked when the session was opened, so a path that does not
exist produced a session in the list that only failed on the first turn.
- Reopening a session did not put its directory back in the field.
## Fix
`resolveWorkDir` becomes `ResolveWorkDir`: it trims, expands a leading `~`,
refuses a relative path instead of guessing a base for it, cleans the result
and checks it is a directory. `agentsession.Open` calls it, so an unusable
path is reported while the form is still open, and the resolved absolute path
is what gets stored, persisted, restored and handed to the agent. The session
list puts a session's directory back in the field when it is reopened.
The IM channels share this code path, so `/cd` and a channel's first message
now report the same error rather than binding a directory that does not work.
## Validation
Static checks: `go build ./...`, `go vet` on `agentsession`, `object`,
`controllers` and `imbridge`, `gofmt`, `yarn lint` and `tsc -b` are all
clean.
`ResolveWorkDir` was exercised directly over absolute, forward-slash,
trailing
separator, padded, `~`, `~/x`, relative, missing and non-directory inputs.
Driven from the web UI of a Gateway built from this branch, on its own port
and
its own database, against a stub launcher registered as a manual installation
so the turns make no upstream calls:
| Working directory entered | Result |
| --- | --- |
| `wdtest\alpha` (relative) | `the working directory must be a full path,
not "wdtest\alpha"` on 新建会话; no session created |
| `D:\no-such-directory-xyz` | `the working directory
D:\no-such-directory-xyz cannot be opened`; no session created |
| `...\wdtest\alpha` | agent reported `cwd=...\wdtest\alpha` and listed that
directory's contents |
| `...\wdtest\beta` (second session) | agent reported `cwd=...\wdtest\beta`;
the two sessions kept separate directories |
| `~/AppData/Local/.../wdtest/alpha` | stored as
`C:\Users\<user>\AppData\Local\...\wdtest\alpha`; agent ran there |
Reopening a session replaced the field's contents with that session's
directory,
and switching between the two sessions switched the field with them. After
restarting Gateway, all three sessions came back with their directories, and
a
new turn on a restored session still ran in its own directory.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]