homeagent-runner 0.4.18 → 0.4.19
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.
- package/CHANGELOG.md +12 -0
- package/README.md +6 -6
- package/README.zh-CN.md +22 -22
- package/dist/shared/protocol.js +1 -1
- package/docs/ARCHITECTURE.md +46 -44
- package/docs/ARCHITECTURE.zh-CN.md +102 -0
- package/docs/CLIENTS.md +38 -36
- package/docs/CLIENTS.zh-CN.md +132 -0
- package/docs/COMPARISON.md +24 -22
- package/docs/COMPARISON.zh-CN.md +38 -0
- package/docs/DEPLOYMENT.md +119 -106
- package/docs/DEPLOYMENT.zh-CN.md +316 -0
- package/docs/DEVELOPMENT_WORKFLOW.md +41 -39
- package/docs/DEVELOPMENT_WORKFLOW.zh-CN.md +128 -0
- package/docs/OPEN_SOURCE.md +69 -65
- package/docs/OPEN_SOURCE.zh-CN.md +133 -0
- package/docs/README.md +24 -20
- package/docs/README.zh-CN.md +31 -0
- package/docs/REMOTE_ASSIST.md +31 -29
- package/docs/REMOTE_ASSIST.zh-CN.md +48 -0
- package/docs/TOOLS.md +86 -84
- package/docs/TOOLS.zh-CN.md +122 -0
- package/docs/VALIDATION.md +114 -107
- package/docs/VALIDATION.zh-CN.md +179 -0
- package/docs/WEBCODEX_CODE_AUDIT.md +81 -79
- package/docs/WEBCODEX_CODE_AUDIT.zh-CN.md +109 -0
- package/package.json +1 -1
package/docs/TOOLS.md
CHANGED
|
@@ -1,120 +1,122 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Tool and Configuration Reference
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**English** · [简体中文](TOOLS.zh-CN.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The 13 development tools introduced in v0.3, command aliases / environment profiles, batch-edit recovery and safe commits are fully described in the [Development Workflow](DEVELOPMENT_WORKFLOW.md). v0.4 added controlled Git network operations, a Web permission editor, fuzzy unified-diff hunk relocation, persistent shell sessions and lightweight LSP integration. The current release exposes **45 MCP tools**. The v0.2 APIs below remain available; the exclusion strategies for Git add and diff were tightened.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Permission Combinations
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Every call must satisfy the client's device/project grants, scopes and the Runner's local project policy. All machine tools require `projectId`; `deviceId` may be omitted when exactly one authorized device is online. The Server cannot modify Runner configuration through a tool.
|
|
10
|
+
|
|
11
|
+
| Scope | Tools | Additional local condition |
|
|
10
12
|
| --- | --- | --- |
|
|
11
|
-
| read | list_directory/read_file/read_files/search_files/get_file_info/get_edit_transactions/read_process_output/tail_process_output/wait_process/list_processes/list_shells/lsp_document_symbols/lsp_workspace_symbols/lsp_definition/lsp_references/lsp_hover/lsp_diagnostics/git_status/git_diff/git_log/git_branches |
|
|
12
|
-
| write | write_file/create_directory/move_file/edit_block/edit_files/apply_unified_diff/recover_edit_transaction/save_project_note | readOnly=false |
|
|
13
|
-
| execute | start_process/run_command/write_process_input/stop_process/start_shell/run_shell/
|
|
14
|
-
| git | git_add/git_commit/git_commit_paths/git_switch_branch/git_fetch/git_pull/git_push | readOnly=false
|
|
13
|
+
| read | list_directory/read_file/read_files/search_files/get_file_info/get_edit_transactions/read_process_output/tail_process_output/wait_process/list_processes/list_shells/lsp_document_symbols/lsp_workspace_symbols/lsp_definition/lsp_references/lsp_hover/lsp_diagnostics/git_status/git_diff/git_log/git_branches | Project exists and file is not excluded; processes and shell sessions must belong to the current principal |
|
|
14
|
+
| write | write_file/create_directory/move_file/edit_block/edit_files/apply_unified_diff/recover_edit_transaction/save_project_note | `readOnly=false` |
|
|
15
|
+
| execute | start_process/run_command/write_process_input/stop_process/start_shell/run_shell/stop_shell | `readOnly=false`; launch must satisfy the program allowlist/aliases, or both the device project and the client must allow all programs |
|
|
16
|
+
| git | git_add/git_commit/git_commit_paths/git_switch_branch/git_fetch/git_pull/git_push | `readOnly=false`, `allowGitWrite=true`; network operations also need the corresponding device switch |
|
|
15
17
|
|
|
16
|
-
`readOnly`
|
|
18
|
+
`readOnly` blocks every write and execution entry point; a read token on a writable project still cannot write. The `git` scope does not automatically include `read`. New OAuth grants must select concrete devices/projects and are stored in `projectGrants[deviceId]`; newly added projects do not gain access automatically, and refresh preserves the original scope. PATs support both global `projects` and device-scoped `projectGrants`, intersected. Legacy v0.1 OAuth grants must be revoked and re-authorized to be narrowed.
|
|
17
19
|
|
|
18
|
-
### Web
|
|
20
|
+
### Two-layer Web permission model
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
The device configuration is the capability ceiling and the client authorization is an independent grant for the calling principal; effective access is the intersection:
|
|
21
23
|
|
|
22
|
-
1. Dashboard
|
|
23
|
-
2. Dashboard
|
|
24
|
-
3.
|
|
24
|
+
1. The Dashboard device editor changes each project's file scope, command execution mode, local Git writes, Git network fetch/pull and Git push.
|
|
25
|
+
2. The Dashboard client editor changes an existing PAT/OAuth authorization's devices, projects, scopes, tool set, device-wide file access and allow-all-programs switch.
|
|
26
|
+
3. Temporary settings carry a minute-level expiry. Server and Runner both check expiry independently; in-flight calls and the corresponding long jobs are stopped, then permanent permissions are restored.
|
|
25
27
|
|
|
26
|
-
`
|
|
28
|
+
`commandMode` / `filesystemScope` on a `list_devices` project and the project fields of `get_project_context` are the effective policy for the current client. Both provide `executionPolicy` (`configuredMode`, `effectiveMode`, `unrestrictedExecutionGranted`, `executeScopeGranted`, `readOnly`, `limitedBy`) and `filesystemPolicy` (`configuredScope`, `machineAccessGranted`, `limitedBy`). `limitedBy=project` means the device project has not opened the capability, `authorization` means the device opened it but the current client was not granted it, and `null` means both layers are open; execution still requires scope, tool-set and non-read-only conditions. `command_denied` / `path_escape` errors also carry the relevant policy and where to change it.
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
Device project directories, permissions, command aliases and environment profiles are all stored on the Server. Local config accepts no project configuration or permission switches; there is no project access before Server settings are received and successfully applied. Disconnect, clearing projects or a failed policy application all revoke project permissions. `stateDir` remains the hosted machine's local credential and job directory. `homeagent check-config` inspects only local connection settings; the terminal shows the actually applied directories after sync.
|
|
29
31
|
|
|
30
|
-
##
|
|
32
|
+
## File Tools
|
|
31
33
|
|
|
32
|
-
- `list_directory(path=".", offset=0, limit=200)
|
|
33
|
-
- `read_file(path, offset=0, length=65536, expectedRevision?)
|
|
34
|
-
- `write_file(path, content, append=false, expectedSha256?)
|
|
35
|
-
- `create_directory(path)
|
|
36
|
-
- `move_file(source,destination)
|
|
37
|
-
- `get_file_info(path)
|
|
38
|
-
- `search_files(path=".",query,content=false,caseSensitive=false,limit=100,include=[],exclude=[],contextLines=0,respectGitIgnore=true)
|
|
39
|
-
- `edit_block(path,oldText,newText,expectedSha256?)
|
|
40
|
-
- `apply_unified_diff(diff,expectedSha256,dryRun=false,fuzz=20,ignoreWhitespace=false)
|
|
34
|
+
- `list_directory(path=".", offset=0, limit=200)`: up to 1000 entries per page, streaming enumeration, no symlink following. Continue with `nextOffset`; scans at most 100,000 entries and never emits a fake `nextOffset` when the source is truncated. A live directory can produce duplicates/omissions; in-page ordering is not a whole-directory snapshot.
|
|
35
|
+
- `read_file(path, offset=0, length=65536, expectedRevision?)`: up to 131,072 bytes, returning text/size/nextOffset/eof/revision; continuing with `revision` rejects a version change. `revision` is a digest of dev/inode/size/mtime/ctime, not a full upstream content snapshot. For files ≤ 1 MiB it also returns the full-content sha256. Multi-byte character boundaries may show replacement characters; binary files do not support editing.
|
|
36
|
+
- `write_file(path, content, append=false, expectedSha256?)`: input up to 262,144 characters, result up to 1 MiB; temp file write/fsync then rename; missing parent directories are not created automatically. A mismatched `expectedSha256` is rejected to prevent silently overwriting an older version.
|
|
37
|
+
- `create_directory(path)`: recursively creates directories inside a validated path.
|
|
38
|
+
- `move_file(source,destination)`: moves within a project, refuses to overwrite the target or move the project root; cross-project moves are not allowed.
|
|
39
|
+
- `get_file_info(path)`: size, modification time and file/directory type.
|
|
40
|
+
- `search_files(path=".",query,content=false,caseSensitive=false,limit=100,include=[],exclude=[],contextLines=0,respectGitIgnore=true)`: literal matching with Node glob filtering and up to 5 context lines; Git projects use tracked/untracked non-ignored sources; non-Git uses bounded traversal and explicitly reports that ignore rules were not applied. Bounded to roughly 10,000 paths, 500 results and 256 KiB of content results.
|
|
41
|
+
- `edit_block(path,oldText,newText,expectedSha256?)`: `oldText` must match exactly and uniquely; edits within a project are serialized so built-in edits from two clients cannot interleave. An external editor or a running command can still modify files concurrently; the application lock is not a filesystem transaction.
|
|
42
|
+
- `apply_unified_diff(diff,expectedSha256,dryRun=false,fuzz=20,ignoreWhitespace=false)`: applies a text unified diff through the journaled editor, with `fuzz` (0–200 lines) for bounded context-line relocation and `ignoreWhitespace` tolerance of leading/trailing horizontal whitespace. When several matches occur inside the fuzzy window it rejects with `ambiguous_patch`, and returns `relocatedHunks` describing offsets. Strict `fuzz: 0` mode is still available.
|
|
41
43
|
|
|
42
|
-
## LSP
|
|
44
|
+
## LSP and Code-Intelligence Tools
|
|
43
45
|
|
|
44
|
-
- `lsp_document_symbols(path)
|
|
45
|
-
- `lsp_workspace_symbols(path=".",query?,kind?,exportedOnly=false,limit=100,respectGitIgnore=true)
|
|
46
|
-
- `lsp_definition(path,line?,column?,symbol?,respectGitIgnore=true)
|
|
47
|
-
- `lsp_references(path,line?,column?,symbol?,includeDeclaration=true,contextLines=0,limit=100,respectGitIgnore=true)
|
|
48
|
-
- `lsp_hover(path,line?,column?,symbol?,respectGitIgnore=true)
|
|
49
|
-
- `lsp_diagnostics(path?,limit=100,respectGitIgnore=true,serverExecutable?,serverArgs=[])
|
|
46
|
+
- `lsp_document_symbols(path)`: extracts structured source symbols (classes, interfaces, types, enums, functions, methods, constants, variables, etc.), exact line/column ranges, doc comments and module import relations.
|
|
47
|
+
- `lsp_workspace_symbols(path=".",query?,kind?,exportedOnly=false,limit=100,respectGitIgnore=true)`: searches symbol definitions across the workspace, ordered by exact match, prefix match and substring match.
|
|
48
|
+
- `lsp_definition(path,line?,column?,symbol?,respectGitIgnore=true)`: locates a definition from 1-based line/column coordinates or a symbol name, supporting the current file, relative module imports (including TypeScript `.js` → `.ts` mapping and Python modules) and workspace exported-symbol jumps.
|
|
49
|
+
- `lsp_references(path,line?,column?,symbol?,includeDeclaration=true,contextLines=0,limit=100,respectGitIgnore=true)`: finds identifier-word-boundary references across the workspace, automatically filtering comments and distinguishing declarations, imports and ordinary references.
|
|
50
|
+
- `lsp_hover(path,line?,column?,symbol?,respectGitIgnore=true)`: returns the declaration signature, extracted JSDoc/Docstring comments, definition location and a code preview for a position or named symbol.
|
|
51
|
+
- `lsp_diagnostics(path?,limit=100,respectGitIgnore=true,serverExecutable?,serverArgs=[])`: under the `read` scope provides built-in syntax, JSON, TypeScript AST and unresolved-relative-import diagnostics with no external process; with `serverExecutable` (requires `execute` and a policy-allowed command) it can query an external language server over stdio JSON-RPC 2.0.
|
|
50
52
|
|
|
51
|
-
|
|
53
|
+
Paths may be project-relative or absolute inside the project. `..` escapes, symlinks / Windows junctions in any path component, hard-linked regular files and `deniedNames` are refused. Windows additionally refuses device reserved names, NTFS alternate data streams and trailing-dot/space aliases.
|
|
52
54
|
|
|
53
|
-
##
|
|
55
|
+
## Terminal Tools
|
|
54
56
|
|
|
55
|
-
`start_process(executable,args=[],cwd=".",timeoutMs=3600000)`
|
|
57
|
+
`start_process(executable,args=[],cwd=".",timeoutMs=3600000)` spawns directly without concatenating a shell; the timeout range is 100 ms to 24 hours. `commands` is empty by default; add specific programs in the Dashboard, or enable "Allow all programs" in both the device project and the current client authorization. A specified program matches the full string, case-insensitively on Windows; absolute paths are recommended to avoid PATH hijacking. Interpreters may live outside the project; a `cwd` outside the project also requires device-wide paths allowed by both device and client. Windows `.cmd`/`.bat` is not implicitly launched through a shell and is refused outright; to run a shell you must allow the shell executable and accept its full privileges.
|
|
56
58
|
|
|
57
|
-
|
|
59
|
+
The optional `idempotencyKey` (8–128 characters) should be generated by the caller and kept unchanged when retrying after an uncertain response. The same principal/project/key with identical executable/args/normalized cwd/timeout returns the original job; conflicting parameters are rejected. Admission is written to SQLite before spawn. Receipts are kept for 48 hours, so a cleaned-up job is not re-run; after the key expires or changes, de-duplication no longer applies. This is not exactly-once for all file/Git operations.
|
|
58
60
|
|
|
59
|
-
|
|
61
|
+
Child processes inherit only a limited environment (PATH, system paths, HOME, TEMP, language, etc.), never the Server password or arbitrary token environment variables. There is no interface for MCP to inject arbitrary environment variables. Extra configuration for build environments should be defined in a dedicated account or a trusted launcher.
|
|
60
62
|
|
|
61
|
-
v0.3
|
|
63
|
+
Since v0.3, administrators can configure local `environmentProfiles` names and `commandAliases`; both values and targets are pre-authorized by the operator, and clients cannot pass arbitrary env maps. `run_command`, `wait_process` and `tail_process_output` provide short-command returns and rolling-tail observation of long jobs. Beyond the prefix cap, a fixed 64 KiB tail is retained so the final error is still visible after overflow; the discarded middle is never presented as a complete log.
|
|
62
64
|
|
|
63
|
-
|
|
65
|
+
The return value is an `id` (UUID), never an arbitrary OS PID. Follow-up calls:
|
|
64
66
|
|
|
65
|
-
- `read_process_output(processId,cursor=0,length=65536)
|
|
66
|
-
- `write_process_input(processId,input,close=false)
|
|
67
|
-
- `list_processes()
|
|
68
|
-
- `stop_process(processId)
|
|
69
|
-
- `start_shell(shell?,cwd=".",timeoutMs=3600000,environment?)
|
|
70
|
-
- `run_shell(command,sessionId?,shell?,cwd=".",timeoutMs=3600000,environment?,waitMs=10000)
|
|
71
|
-
- `list_shells()` / `stop_shell(sessionId)
|
|
67
|
+
- `read_process_output(processId,cursor=0,length=65536)`: reads merged stdout/stderr, nextCursor, state, exitCode, signal, finished, truncated.
|
|
68
|
+
- `write_process_input(processId,input,close=false)`: input up to 65,536 characters; `close=true` sends EOF.
|
|
69
|
+
- `list_processes()`: historical and running jobs of the current principal and current project only.
|
|
70
|
+
- `stop_process(processId)`: enters `stopping` and keeps the slot occupied, terminating only after the real tree is gone. Linux sends SIGTERM to the group then SIGKILL on timeout, cleaning the remaining group even if the leader exits early; Windows uses a suspended-admission Job Object supervisor for the whole tree and stops the supervisor via taskkill.
|
|
71
|
+
- `start_shell(shell?,cwd=".",timeoutMs=3600000,environment?)`: starts a persistent stateful shell session supervised by `Processes` (Windows default `powershell.exe`, POSIX default `sh`/`bash`), still subject to the command allowlist or allow-all-programs policy.
|
|
72
|
+
- `run_shell(command,sessionId?,shell?,cwd=".",timeoutMs=3600000,environment?,waitMs=10000)`: runs a command in a persistent shell session (reusing an idle session or starting a new one when `sessionId` is omitted), preserving the working directory (`cd`) and shell/environment variables across commands, and returning the isolated `output`, `exitCode` and updated `cwd` for this command.
|
|
73
|
+
- `list_shells()` / `stop_shell(sessionId)`: inspect persistent shell sessions for the current project (`ready`/`running`, current `cwd`, last exit code) or terminate a session and its process tree.
|
|
72
74
|
|
|
73
|
-
|
|
75
|
+
States include starting/running/stopping/exited/failed/stopped/timed_out/interrupted. Defaults: at most 8 running processes, 8 MiB output per process, roughly 500 historical jobs. A Server reconnect does not restart jobs; a Runner restart marks unfinished records interrupted. On Windows the supervisor kills its Job when the Runner dies; on Linux, forced Runner kill cleanup is handled by systemd/container. There is no PTY and no job migration across Runners.
|
|
74
76
|
|
|
75
|
-
Windows
|
|
77
|
+
Windows needs system PowerShell/.NET `Add-Type`, using the independently written C# helper under this project's `runtime/`; it downloads no binaries and does not bypass organizational execution policy automatically. If policy blocks it or Job assignment fails, the job fails closed rather than degrading to an unprotected process tree.
|
|
76
78
|
|
|
77
|
-
|
|
79
|
+
Allowing `node`, `python`, `bash`, `powershell`, `npm`, `git` or a project build program may execute arbitrary local code. The argv structure only avoids accidental shell parsing; it does not restrict interpreter capabilities. Use a low-privilege account, container or VM for real system isolation.
|
|
78
80
|
|
|
79
|
-
## Git
|
|
81
|
+
## Git Tools
|
|
80
82
|
|
|
81
|
-
|
|
83
|
+
By default `project.root` is an ordinary standalone Git repository. Since v0.3, linked worktrees with a configured `gitCommonDir` are supported after validation; without it, `.git` files are still refused, and arbitrary gitdir pointers of general submodules are not supported.
|
|
82
84
|
|
|
83
|
-
- `git_status()
|
|
84
|
-
- `git_diff(staged=false,path?)
|
|
85
|
-
- `git_log(limit=20)
|
|
86
|
-
- `git_add(paths)
|
|
87
|
-
- `git_commit(message)
|
|
85
|
+
- `git_status()`: porcelain v1.
|
|
86
|
+
- `git_diff(staged=false,path?)`: bounded output, external diff, textconv and submodule diff execution disabled.
|
|
87
|
+
- `git_log(limit=20)`: up to 100 entries, short hash/time/author/title.
|
|
88
|
+
- `git_add(paths)`: explicit file path array, up to 100 items, no directories (including `.`), pathspec magic disabled; refuses writes when local config contains clean/process filters.
|
|
89
|
+
- `git_commit(message)`: commits only staged content; hooks and GPG signing disabled, no push, no automatic author identity configuration.
|
|
88
90
|
|
|
89
|
-
|
|
91
|
+
All Git tools accept a `repository` parameter, a repository-relative directory under the project root defaulting to `.`; absolute paths need device-wide file access. Ordinary Git tools disable system and global Git config, fsmonitor and external diff; network Git uses local SSH config/credentials and only allows configured HTTPS/SSH remotes. Output is capped at 256 KiB, network execution at 35 seconds, other Git execution at 20 seconds. Author identity should be set in the repository beforehand via `git -C <project> config user.name ...` and `user.email`. There is no arbitrary git subcommand interface; `reset --hard`, `clean`, force push and similar actions are not in the tool set.
|
|
90
92
|
|
|
91
|
-
`git_fetch(remote="origin",branch?)`
|
|
93
|
+
`git_fetch(remote="origin",branch?)` fetches only configured HTTPS/SSH remotes. `git_pull` requires a clean worktree, performs fast-forward only, and does no rebase, merge, force or recursive submodule update. `git_push` pushes HEAD to a single branch, requires push to be enabled separately on the device, and supports no force, deletion, tags or arbitrary refspec.
|
|
92
94
|
|
|
93
|
-
|
|
95
|
+
These limits reduce implicit execution risk, but Git still reads its own metadata. Against a local malicious user who can replace files or repository config simultaneously, OS isolation is required; a project-root policy cannot replace it.
|
|
94
96
|
|
|
95
|
-
##
|
|
97
|
+
## Admin and Operations API
|
|
96
98
|
|
|
97
|
-
|
|
99
|
+
The browser must be signed in and supply `X-CSRF-Token` on every modifying request (forms use `_csrf`). The token comes from `/api/state` and belongs only to the current browser session.
|
|
98
100
|
|
|
99
|
-
|
|
|
101
|
+
| Method | Path | Purpose |
|
|
100
102
|
| --- | --- | --- |
|
|
101
|
-
| GET | /health |
|
|
102
|
-
| GET | /api/state |
|
|
103
|
-
| GET | /api/jobs?deviceId=UUID&projectId=ID&limit=200 |
|
|
104
|
-
| GET | /api/jobs/:deviceId/:id/output?cursor=0&length=65536 |
|
|
105
|
-
| GET | /api/jobs/:deviceId/:id/output?view=tail&length=65536 | v0.3
|
|
106
|
-
| POST | /api/jobs/:deviceId/:id/stop |
|
|
107
|
-
| POST | /api/sessions/:id/revoke |
|
|
108
|
-
| POST | /api/pair/inspect |
|
|
109
|
-
| POST | /api/pair/approve |
|
|
110
|
-
| GET/POST | /pair/verify?id=UUID&token
|
|
111
|
-
| POST | /api/devices/:id/pause,resume,revoke,rename |
|
|
112
|
-
| POST | /api/devices/:id/permissions |
|
|
113
|
-
| POST | /api/tokens |
|
|
114
|
-
| POST | /api/tokens/:tokenId/revoke |
|
|
115
|
-
| POST | /api/authorizations/:id/permissions |
|
|
116
|
-
| GET | /api/clients |
|
|
117
|
-
| POST | /api/clients/:id/revoke |
|
|
118
|
-
| GET | /api/audit?limit=100&before
|
|
119
|
-
|
|
120
|
-
|
|
103
|
+
| GET | /health | Health and database probe; returns Server `version` and `runnerProtocol` |
|
|
104
|
+
| GET | /api/state | Devices, client activity, recent audits, current CSRF, plus Server `version`, `runnerProtocol` and Node/platform info |
|
|
105
|
+
| GET | /api/jobs?deviceId=UUID&projectId=ID&limit=200 | Bounded persistent job metadata, up to 1000 items |
|
|
106
|
+
| GET | /api/jobs/:deviceId/:id/output?cursor=0&length=65536 | Admin reads Runner output by exact instance; not stored on the Server |
|
|
107
|
+
| GET | /api/jobs/:deviceId/:id/output?view=tail&length=65536 | Rolling tail (introduced in v0.3); continue with an absolute cursor, returns overrun notice |
|
|
108
|
+
| POST | /api/jobs/:deviceId/:id/stop | Admin stops a hosted job of the exact instance; action audited as admin |
|
|
109
|
+
| POST | /api/sessions/:id/revoke | Revoke an administrator browser login session |
|
|
110
|
+
| POST | /api/pair/inspect | Inspect the device name and expiry for a pairing code before approval |
|
|
111
|
+
| POST | /api/pair/approve | Verify and approve a one-time pairing code |
|
|
112
|
+
| GET/POST | /pair/verify?id=UUID&token=short-credential | Signed-in administrator approves device pairing from the browser link printed by the Runner |
|
|
113
|
+
| POST | /api/devices/:id/pause,resume,revoke,rename | Device management |
|
|
114
|
+
| POST | /api/devices/:id/permissions | Edit or clear device project permissions; supports `expectedRevision`, `durationMinutes` and temporary fallback |
|
|
115
|
+
| POST | /api/tokens | Create a scoped PAT |
|
|
116
|
+
| POST | /api/tokens/:tokenId/revoke | Revoke a token family; OAuth access also revokes the client |
|
|
117
|
+
| POST | /api/authorizations/:id/permissions | Edit an existing PAT/OAuth authorization's devices, projects, scopes, tools and temporary advanced permissions |
|
|
118
|
+
| GET | /api/clients | List registered OAuth client names and callbacks |
|
|
119
|
+
| POST | /api/clients/:id/revoke | Revoke an OAuth client and all its tokens |
|
|
120
|
+
| GET | /api/audit?limit=100&before=millisecond-timestamp&beforeId=UUID | Paginate the JSON audit log |
|
|
121
|
+
|
|
122
|
+
Audit pagination is ordered by (at, id) descending. Pass the last row's `at` and `id` of the previous page as `before` and `beforeId` to traverse multiple rows in the same millisecond stably. The current Dashboard shows the most recent 100 rows; the API returns at most 1000 per page.
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# 工具与配置参考
|
|
2
|
+
|
|
3
|
+
[English](TOOLS.md) · **简体中文**
|
|
4
|
+
|
|
5
|
+
v0.3 新增的 13 个开发工具、命令别名/环境配置、批量编辑恢复和安全提交的完整说明见 [日常开发工作流](DEVELOPMENT_WORKFLOW.zh-CN.md)。v0.4 增加受控 Git 网络操作、Web 权限编辑器、统一 diff 模糊重定位、持久 Shell 会话与轻量 LSP 集成,当前共 **45 个 MCP 工具**。下列 v0.2 原有 API 继续保留;Git add 和 diff 的排除策略有所收紧。
|
|
6
|
+
|
|
7
|
+
## 权限组合
|
|
8
|
+
|
|
9
|
+
每次调用都必须满足客户端设备/项目范围、scope 和 Runner 本地项目策略。所有机器工具都要求 `projectId`;`deviceId` 可在只有一台有权限的在线设备时省略。Server 不能通过工具修改 Runner 配置。
|
|
10
|
+
|
|
11
|
+
| scope | 工具 | 本地额外条件 |
|
|
12
|
+
| --- | --- | --- |
|
|
13
|
+
| read | list_directory/read_file/read_files/search_files/get_file_info/get_edit_transactions/read_process_output/tail_process_output/wait_process/list_processes/list_shells/lsp_document_symbols/lsp_workspace_symbols/lsp_definition/lsp_references/lsp_hover/lsp_diagnostics/git_status/git_diff/git_log/git_branches | 项目存在,文件未被排除;进程与 Shell 会话必须属于当前主体 |
|
|
14
|
+
| write | write_file/create_directory/move_file/edit_block/edit_files/apply_unified_diff/recover_edit_transaction/save_project_note | `readOnly=false` |
|
|
15
|
+
| execute | start_process/run_command/write_process_input/stop_process/start_shell/run_shell/stop_shell | `readOnly=false`;启动时需满足程序名单/别名,或设备项目与客户端均允许全部程序 |
|
|
16
|
+
| git | git_add/git_commit/git_commit_paths/git_switch_branch/git_fetch/git_pull/git_push | `readOnly=false`,`allowGitWrite=true`;网络操作还需对应设备开关 |
|
|
17
|
+
|
|
18
|
+
`readOnly` 禁止所有写入和执行入口;对可写项目的 read token 仍不允许写入。`git` scope 不自动包含 read。新 OAuth grant 必须选择具体设备/项目,存入 `projectGrants[deviceId]`;新增项目不自动获得访问,刷新保持原范围。PAT 同时支持全局 `projects` 和设备限定 `projectGrants`,两者取交集。v0.1 旧 OAuth grant 需撤销重授权才能收紧。
|
|
19
|
+
|
|
20
|
+
### Web 权限的两层模型
|
|
21
|
+
|
|
22
|
+
设备配置是能力上限,客户端授权是调用主体的独立授权,最终权限取两者交集:
|
|
23
|
+
|
|
24
|
+
1. Dashboard 的设备编辑器修改每个项目的文件范围、命令执行模式、Git 本地写入、Git 网络 fetch/pull 和 Git push。
|
|
25
|
+
2. Dashboard 的客户端编辑器修改既有 PAT/OAuth 授权的设备、项目、scope、工具集合、设备范围文件和任意程序开关。
|
|
26
|
+
3. 临时设置带有分钟级到期时间。Server 和 Runner 都独立检查过期;在途调用和对应长任务会被停止,随后恢复永久权限。
|
|
27
|
+
|
|
28
|
+
`list_devices` 的项目 `commandMode` / `filesystemScope` 与 `get_project_context` 的项目字段均为当前客户端的有效策略。两者的 `executionPolicy` 提供 `configuredMode`、`effectiveMode`、`unrestrictedExecutionGranted`、`executeScopeGranted`、`readOnly` 和 `limitedBy`;`filesystemPolicy` 提供 `configuredScope`、`machineAccessGranted` 和 `limitedBy`。`limitedBy=project` 表示设备项目未开放对应能力,`authorization` 表示设备已开放但当前客户端未获授权,`null` 表示该能力两层均已开放;执行仍需满足 scope、工具集合和非只读等条件。`command_denied` / `path_escape` 错误也附带相应策略和修改位置。
|
|
29
|
+
|
|
30
|
+
设备项目目录、权限、命令别名和环境配置统一保存在 Server 上。本地不接受项目配置或权限开关;未收到并成功应用 Server 设置前,没有项目访问权限。断线、清空项目或配置应用失败均收回项目权限。`stateDir` 仍是被控端本机的凭据与任务目录。`homeagent check-config` 只检查本机连接设置,终端同步后显示实际应用目录。
|
|
31
|
+
|
|
32
|
+
## 文件工具
|
|
33
|
+
|
|
34
|
+
- `list_directory(path=".", offset=0, limit=200)`:每页最多 1000 项,流式枚举,不跟随链接。用 `nextOffset` 继续;扫描最多 100,000 项,源截断时不给伪 `nextOffset`。活目录变动可能造成重复/遗漏,页内排序不代表全目录快照。
|
|
35
|
+
- `read_file(path, offset=0, length=65536, expectedRevision?)`:最多 131,072 字节,返回 text/size/nextOffset/eof/revision;用 `revision` 继续读取可拒绝版本变化。`revision` 是 dev/inode/size/mtime/ctime 的摘要,不是上游完整内容快照。小于等于 1 MiB 时另返回完整内容 sha256。多字节字符边界可能显示替换字符;非文本文件不支持二进制编辑。
|
|
36
|
+
- `write_file(path, content, append=false, expectedSha256?)`:输入最多 262,144 个字符,结果最多 1 MiB,临时文件写入/fsync 后 rename;不自动创建缺失父目录。`expectedSha256` 不匹配则拒绝,防止静默覆盖旧版本。
|
|
37
|
+
- `create_directory(path)`:递归创建已验证路径内的目录。
|
|
38
|
+
- `move_file(source,destination)`:同项目内移动,拒绝覆盖目标及移动项目根;不允许跨项目移动。
|
|
39
|
+
- `get_file_info(path)`:大小、修改时间和文件/目录类型。
|
|
40
|
+
- `search_files(path=".",query,content=false,caseSensitive=false,limit=100,include=[],exclude=[],contextLines=0,respectGitIgnore=true)`:字面量匹配,支持 Node glob 过滤和最多 5 行上下文;Git 项目使用 tracked/untracked 非 ignored 源;非 Git 有界遍历并明确报告 ignore 未应用。最多约 10,000 路径、500 结果和 256 KiB 内容结果。
|
|
41
|
+
- `edit_block(path,oldText,newText,expectedSha256?)`:`oldText` 必须唯一精确匹配;同项目内修改序列化,不让两个客户端的内置修改相互交错。外部编辑器或运行中的命令仍可能并发修改,不能把应用锁当作文件系统事务。
|
|
42
|
+
- `apply_unified_diff(diff,expectedSha256,dryRun=false,fuzz=20,ignoreWhitespace=false)`:通过带恢复日志的编辑器应用文本 unified diff,支持 `fuzz`(0–200 行)有界上下文行重定位及 `ignoreWhitespace` 行首尾水平空白容错;当模糊窗口内出现多处匹配时以 `ambiguous_patch` 拒绝,并返回 `relocatedHunks` 记录偏移详情。严格 `fuzz: 0` 模式仍可用。
|
|
43
|
+
|
|
44
|
+
## LSP 与代码智能工具
|
|
45
|
+
|
|
46
|
+
- `lsp_document_symbols(path)`:提取源文件结构化符号(类、接口、类型、枚举、函数、方法、常量、变量等)、精确行列范围、文档注释与模块导入关系。
|
|
47
|
+
- `lsp_workspace_symbols(path=".",query?,kind?,exportedOnly=false,limit=100,respectGitIgnore=true)`:跨工作区检索符号定义,按精确匹配、前缀匹配和子串匹配排序。
|
|
48
|
+
- `lsp_definition(path,line?,column?,symbol?,respectGitIgnore=true)`:根据 1-based 行列坐标或符号名定位定义,支持当前文件、相对模块导入(含 TypeScript `.js` → `.ts` 映射及 Python 模块)与工作区导出符号跳转。
|
|
49
|
+
- `lsp_references(path,line?,column?,symbol?,includeDeclaration=true,contextLines=0,limit=100,respectGitIgnore=true)`:按标识符词边界查找整个工作区内的符号引用,自动过滤注释并区分声明、导入与普通引用。
|
|
50
|
+
- `lsp_hover(path,line?,column?,symbol?,respectGitIgnore=true)`:返回指定位置或名称符号的声明签名、提取的 JSDoc/Docstring 文档注释、定义位置与代码预览。
|
|
51
|
+
- `lsp_diagnostics(path?,limit=100,respectGitIgnore=true,serverExecutable?,serverArgs=[])`:在 `read` 权限下提供零外部进程的内置语法、JSON、TypeScript AST 与未解析相对导入诊断;传入 `serverExecutable` 时(需 `execute` 权限及命令策略允许)可通过 stdio JSON-RPC 2.0 查询外部语言服务器诊断。
|
|
52
|
+
|
|
53
|
+
路径可以是项目相对路径或项目内绝对路径。拒绝 `..` 越界、所有路径组件中的符号链接/Windows junction、硬链接普通文件,以及 `deniedNames`。Windows 额外拒绝设备保留名、NTFS alternate data streams 和尾随点/空格别名。
|
|
54
|
+
|
|
55
|
+
## 终端工具
|
|
56
|
+
|
|
57
|
+
`start_process(executable,args=[],cwd=".",timeoutMs=3600000)` 直接 spawn,不拼接 shell;超时范围 100 ms 到 24 小时。默认 `commands` 为空;可在 Dashboard 添加指定程序,或在设备项目与当前客户端授权中开启"允许全部程序"。指定程序匹配完整字符串,Windows 忽略大小写;推荐绝对路径,避免 PATH 劫持。解释器可位于项目外;项目外的 `cwd` 还需设备与客户端均允许设备范围路径。Windows .cmd/.bat 不会隐式启动 shell,直接拒绝;要执行 shell 必须允许 shell 可执行文件并承担其完整权限。
|
|
58
|
+
|
|
59
|
+
可选 `idempotencyKey`(8–128 字符)应由调用方生成并在不确定响应重试时保持不变。相同主体/项目/key 和相同 executable/args/规范化 cwd/timeout 返回原任务;冲突参数拒绝。准入先写 SQLite,再 spawn。48 小时内保留收据,已清理任务不会因此重跑;key 过期或换 key 后不再去重。不是所有文件/Git 操作的 exactly-once 保证。
|
|
60
|
+
|
|
61
|
+
子进程只继承 PATH、系统路径、HOME、TEMP、语言等有限环境变量,不继承 Server 密码或其他任意 token 环境变量。不提供由 MCP 任意注入环境变量的接口。编译环境需要的额外配置应在专用账户或可信启动器中定义。
|
|
62
|
+
|
|
63
|
+
自 v0.3 起可选择本机 `environmentProfiles` 名称与 `commandAliases` 别名;配置值和目标均由操作者事先授权,客户端不能传入任意 env 映射。`run_command`、`wait_process`、`tail_process_output` 提供短命令返回和长任务尾部观察。前段上限之外,另保留固定 64 KiB 尾部,因此超限后仍可看到最后错误,已丢弃中段不会伪装成完整日志。
|
|
64
|
+
|
|
65
|
+
返回 `id`(UUID),不是任意 OS PID。后续使用:
|
|
66
|
+
|
|
67
|
+
- `read_process_output(processId,cursor=0,length=65536)`:读取合并 stdout/stderr、nextCursor、state、exitCode、signal、finished、truncated。
|
|
68
|
+
- `write_process_input(processId,input,close=false)`:输入最多 65,536 个字符,`close=true` 发送 EOF。
|
|
69
|
+
- `list_processes()`:仅当前主体、当前项目的历史与运行任务。
|
|
70
|
+
- `stop_process(processId)`:先进入 `stopping` 并继续占槽,实际树结束后才终结。Linux 向组发 SIGTERM,超时 SIGKILL,leader 提前结束时也清理剩余组;Windows 用 suspended admission 的 Job Object supervisor 托管整个树,并通过 taskkill 停止 supervisor。
|
|
71
|
+
- `start_shell(shell?,cwd=".",timeoutMs=3600000,environment?)`:启动受 `Processes` 监管的持久状态化 Shell 会话(Windows 默认 `powershell.exe`,POSIX 默认 `sh`/`bash`,仍须满足命令允许列表或全部程序策略)。
|
|
72
|
+
- `run_shell(command,sessionId?,shell?,cwd=".",timeoutMs=3600000,environment?,waitMs=10000)`:在持久 Shell 会话中执行命令(省略 `sessionId` 时自动复用空闲会话或新建会话),跨命令保留工作目录(`cd`)与 Shell/环境变量,返回本次命令隔离后的 `output`、`exitCode` 和更新后的 `cwd`。
|
|
73
|
+
- `list_shells()` / `stop_shell(sessionId)`:查看当前项目的持久 Shell 会话状态(`ready`/`running`、当前 `cwd`、最近退出码)或终止会话及其进程树。
|
|
74
|
+
|
|
75
|
+
状态包括 starting/running/stopping/exited/failed/stopped/timed_out/interrupted。默认最多 8 个运行进程、单进程输出 8 MiB、约 500 个历史任务。Server 重连不重启任务,Runner 重启把未结束记录标记 interrupted。Windows supervisor 会在 Runner 死亡时终止其 Job;Linux 强制杀死 Runner 的清理由 systemd/容器负责。没有 PTY 或跨 Runner 的任务迁移。
|
|
76
|
+
|
|
77
|
+
Windows 需要系统 PowerShell/.NET 的 Add-Type 能力,使用本项目 `runtime/` 下独立编写的 C# 辅助代码;不下载二进制、不自动绕过组织执行策略。策略阻止或 Job assignment 失败时,任务失败关闭,不降级为无保护的进程树。
|
|
78
|
+
|
|
79
|
+
允许 `node`、`python`、`bash`、`powershell`、`npm`、`git` 或项目构建程序均可能执行任意本机代码。argv 结构只避免意外 shell 解析,不限制解释器功能。需要真正系统隔离时用低权限账户、容器/VM。
|
|
80
|
+
|
|
81
|
+
## Git 工具
|
|
82
|
+
|
|
83
|
+
默认 `project.root` 是普通独立 Git 仓库。自 v0.3 起,对已配置 `gitCommonDir` 的 linked worktree 提供校验后的支持;未配置仍拒绝 `.git` 文件,不支持一般 submodule 的任意 gitdir 指向。
|
|
84
|
+
|
|
85
|
+
- `git_status()`:porcelain v1。
|
|
86
|
+
- `git_diff(staged=false,path?)`:限制输出,禁用外部 diff、textconv 和子模块差异执行。
|
|
87
|
+
- `git_log(limit=20)`:最多 100 条,短 hash/时间/作者/标题。
|
|
88
|
+
- `git_add(paths)`:显式文件路径数组,最多 100 项,不接受目录(包括 `.`),关闭 pathspec magic;本地配置包含 clean/process filter 时拒绝写入。
|
|
89
|
+
- `git_commit(message)`:只提交已 stage 内容;禁用 hooks 和 GPG signing,不 push、不自动配置作者身份。
|
|
90
|
+
|
|
91
|
+
所有 Git 工具接受 `repository` 参数,表示项目根目录下的仓库相对目录,默认 `.`;绝对路径需要设备范围文件访问。普通 Git 工具禁用系统和全局 Git 配置、fsmonitor、外部 diff;网络 Git 使用本机 SSH 配置/凭据并只允许配置好的 HTTPS/SSH remote。输出上限 256 KiB,网络执行上限 35 秒,其他 Git 执行上限 20 秒。作者身份应预先通过 `git -C <project> config user.name ...` 和 `user.email` 在仓库内设置。没有任意 git 子命令接口,`reset --hard`、`clean`、force push 等不在工具集中。
|
|
92
|
+
|
|
93
|
+
`git_fetch(remote="origin",branch?)` 只获取已配置的 HTTPS/SSH remote。`git_pull` 要求 clean worktree,只做 fast-forward,不 rebase、merge、force 或递归 submodule。`git_push` 只把 HEAD 推送到一个分支,要求设备单独开启 push,不支持 force、删除、tag 或 arbitrary refspec。
|
|
94
|
+
|
|
95
|
+
这些限制降低隐式执行风险,但 Git 内部依然会读取其元数据。面对本机恶意用户能同时替换文件或仓库配置的威胁,需要 OS 隔离;项目根策略不能代替它。
|
|
96
|
+
|
|
97
|
+
## 管理与运维接口
|
|
98
|
+
|
|
99
|
+
浏览器必须登录并在所有修改请求提供 `X-CSRF-Token`(表单使用 `_csrf`)。Token 从 `/api/state` 获取,只属于当前浏览器 session。
|
|
100
|
+
|
|
101
|
+
| 方法 | 路径 | 用途 |
|
|
102
|
+
| --- | --- | --- |
|
|
103
|
+
| GET | /health | 健康与数据库探测,返回 Server `version` 与 `runnerProtocol` |
|
|
104
|
+
| GET | /api/state | 设备、客户端活动、最近审计、当前 CSRF,以及 Server `version`、`runnerProtocol` 和 Node/平台信息 |
|
|
105
|
+
| GET | /api/jobs?deviceId=UUID&projectId=ID&limit=200 | 有界持久任务元数据,最多 1000 项 |
|
|
106
|
+
| GET | /api/jobs/:deviceId/:id/output?cursor=0&length=65536 | 管理员按准确实例读取 Runner 输出,不保存到 Server |
|
|
107
|
+
| GET | /api/jobs/:deviceId/:id/output?view=tail&length=65536 | v0.3 引入的环形尾部;可用绝对 cursor 继续,返回覆盖提示 |
|
|
108
|
+
| POST | /api/jobs/:deviceId/:id/stop | 管理员停止准确实例的托管任务,动作以 admin 审计 |
|
|
109
|
+
| POST | /api/sessions/:id/revoke | 撤销管理员浏览器登录会话 |
|
|
110
|
+
| POST | /api/pair/inspect | 在批准前查看配对码对应设备名称和过期时间 |
|
|
111
|
+
| POST | /api/pair/approve | 核对并批准一次性配对码 |
|
|
112
|
+
| GET/POST | /pair/verify?id=UUID&token=短期凭据 | 已登录管理员通过 Runner 输出的浏览器链接批准设备配对 |
|
|
113
|
+
| POST | /api/devices/:id/pause,resume,revoke,rename | 设备管理 |
|
|
114
|
+
| POST | /api/devices/:id/permissions | 修改或清空设备项目权限;支持 `expectedRevision`、`durationMinutes` 和临时回退 |
|
|
115
|
+
| POST | /api/tokens | 创建范围化 PAT |
|
|
116
|
+
| POST | /api/tokens/:tokenId/revoke | 撤销令牌族;OAuth access 同时撤销客户端 |
|
|
117
|
+
| POST | /api/authorizations/:id/permissions | 修改现有 PAT/OAuth 授权的设备、项目、scope、工具和临时高级权限 |
|
|
118
|
+
| GET | /api/clients | 查看已注册 OAuth 客户端名称和回调 |
|
|
119
|
+
| POST | /api/clients/:id/revoke | 撤销 OAuth 客户端和其全部令牌 |
|
|
120
|
+
| GET | /api/audit?limit=100&before=毫秒时间戳&beforeId=UUID | 分页查看 JSON 审计 |
|
|
121
|
+
|
|
122
|
+
审计分页按 at、id 联合降序排列,把前一页最后一行的 at 和 id 分别传为 `before` 与 `beforeId`,可稳定遍历同毫秒内的多行。本版本 Dashboard 展示最近 100 条,API 单页最多 1000 条。
|