homeagent-runner 0.0.0-stage → 0.4.5
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 +137 -0
- package/CONTRIBUTING.md +65 -0
- package/LICENSE +21 -0
- package/README.en.md +329 -0
- package/README.md +271 -2
- package/SECURITY.md +59 -0
- package/THIRD_PARTY_NOTICES.md +45 -0
- package/bin/runner.mjs +2 -0
- package/dist/runner/agent.js +254 -0
- package/dist/runner/cli.js +66 -0
- package/dist/runner/config-location.js +67 -0
- package/dist/runner/config.js +43 -0
- package/dist/runner/context.js +86 -0
- package/dist/runner/credentials.js +68 -0
- package/dist/runner/editor.js +262 -0
- package/dist/runner/files.js +298 -0
- package/dist/runner/git.js +333 -0
- package/dist/runner/lock.js +28 -0
- package/dist/runner/output-log.js +59 -0
- package/dist/runner/patch.js +103 -0
- package/dist/runner/permissions.js +93 -0
- package/dist/runner/policy.js +87 -0
- package/dist/runner/process-tree.js +28 -0
- package/dist/runner/processes.js +367 -0
- package/dist/runner/service.js +53 -0
- package/dist/runner/setup.js +79 -0
- package/dist/runner/tools.js +118 -0
- package/dist/shared/permissions.js +40 -0
- package/dist/shared/protocol.js +98 -0
- package/dist/shared/tools.js +108 -0
- package/docs/ARCHITECTURE.md +92 -0
- package/docs/CLIENTS.md +130 -0
- package/docs/COMPARISON.md +36 -0
- package/docs/DEPLOYMENT.md +295 -0
- package/docs/DEVELOPMENT_WORKFLOW.md +126 -0
- package/docs/OPEN_SOURCE.md +129 -0
- package/docs/README.md +26 -0
- package/docs/TOOLS.md +105 -0
- package/docs/VALIDATION.md +172 -0
- package/docs/WEBCODEX_CODE_AUDIT.md +107 -0
- package/docs/screenshots/dashboard.png +0 -0
- package/docs/screenshots/jobs.png +0 -0
- package/docs/screenshots/permissions.png +0 -0
- package/docs/webcodex-parity-map.json +75 -0
- package/docs/webcodex-source-inventory.json +2254 -0
- package/licenses/npm-runtime.txt +3673 -0
- package/package.json +45 -4
- package/public/icon.png +0 -0
- package/runtime/windows-process-tree.cs +105 -0
- package/runtime/windows-process-tree.ps1 +19 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { remotePermissionsSchema } from './permissions.js';
|
|
3
|
+
export const VERSION = '0.4.5';
|
|
4
|
+
export const RUNNER_PROTOCOL = 2;
|
|
5
|
+
export const MAX_FRAME = 2 * 1024 * 1024;
|
|
6
|
+
export const SCOPES = ['read', 'write', 'execute', 'git'];
|
|
7
|
+
export const principalSchema = z.object({
|
|
8
|
+
id: z.string().max(200),
|
|
9
|
+
scopes: z.array(z.enum(SCOPES)),
|
|
10
|
+
devices: z.array(z.string()).nullable(),
|
|
11
|
+
projects: z.array(z.string()).nullable(),
|
|
12
|
+
projectGrants: z.record(z.string(), z.array(z.string())).optional(),
|
|
13
|
+
tools: z.array(z.string().max(64)).max(100).optional(),
|
|
14
|
+
authorizationId: z.string().max(200).optional(),
|
|
15
|
+
authorizationExpiresAt: z.number().int().positive().optional(),
|
|
16
|
+
authorizationRevision: z.number().int().min(0).optional(),
|
|
17
|
+
machineAccess: z.boolean().optional(),
|
|
18
|
+
unrestrictedExecution: z.boolean().optional(),
|
|
19
|
+
});
|
|
20
|
+
export function projectGranted(principal, deviceId, projectId) {
|
|
21
|
+
return (!principal.devices || principal.devices.includes(deviceId))
|
|
22
|
+
&& (!principal.projects || principal.projects.includes(projectId))
|
|
23
|
+
&& (!principal.projectGrants || !!principal.projectGrants[deviceId]?.includes(projectId));
|
|
24
|
+
}
|
|
25
|
+
export const projectViewSchema = z.object({
|
|
26
|
+
id: z.string().regex(/^[a-zA-Z0-9_-]{1,64}$/),
|
|
27
|
+
name: z.string().max(128),
|
|
28
|
+
readOnly: z.boolean(),
|
|
29
|
+
allowGitWrite: z.boolean().default(false),
|
|
30
|
+
allowGitNetwork: z.boolean().default(false),
|
|
31
|
+
allowGitPush: z.boolean().default(false),
|
|
32
|
+
commandMode: z.enum(['allowlist', 'unrestricted']).default('allowlist'),
|
|
33
|
+
filesystemScope: z.enum(['project', 'device']).default('project'),
|
|
34
|
+
commands: z.array(z.string().max(512)).max(64),
|
|
35
|
+
commandAliasNames: z.array(z.string().max(64)).max(64).optional(),
|
|
36
|
+
environmentNames: z.array(z.string().max(64)).max(64).optional(),
|
|
37
|
+
});
|
|
38
|
+
export const resultSchema = z.object({
|
|
39
|
+
content: z.array(z.object({ type: z.literal('text'), text: z.string().max(MAX_FRAME) })).max(8),
|
|
40
|
+
isError: z.boolean().optional(),
|
|
41
|
+
structuredContent: z.record(z.string(), z.unknown()).optional(),
|
|
42
|
+
});
|
|
43
|
+
export const jobViewSchema = z.object({
|
|
44
|
+
id: z.string().uuid(), owner: z.string().min(1).max(200), projectId: z.string().min(1).max(64),
|
|
45
|
+
executable: z.string().max(512), revision: z.number().int().min(0),
|
|
46
|
+
started: z.number().int().positive(), finished: z.number().int().positive().optional(),
|
|
47
|
+
state: z.enum(['starting', 'running', 'stopping', 'exited', 'failed', 'stopped', 'timed_out', 'interrupted']),
|
|
48
|
+
exitCode: z.number().int().nullable().optional(), signal: z.string().max(64).nullable().optional(),
|
|
49
|
+
outputBytes: z.number().int().min(0).max(64 * 1024 * 1024), truncated: z.boolean(),
|
|
50
|
+
totalOutputBytes: z.number().int().min(0).optional(),
|
|
51
|
+
authorizationId: z.string().max(200).optional(),
|
|
52
|
+
authorizationExpiresAt: z.number().int().positive().optional(),
|
|
53
|
+
authorizationRevision: z.number().int().min(0).optional(),
|
|
54
|
+
});
|
|
55
|
+
export const terminalJob = (job) => !['starting', 'running', 'stopping'].includes(job.state);
|
|
56
|
+
export const agentMessageSchema = z.discriminatedUnion('type', [
|
|
57
|
+
z.object({
|
|
58
|
+
type: z.literal('hello'), protocol: z.literal(RUNNER_PROTOCOL),
|
|
59
|
+
name: z.string().min(1).max(128), platform: z.string().max(64),
|
|
60
|
+
version: z.string().max(32), projects: z.array(projectViewSchema).max(100),
|
|
61
|
+
instanceId: z.string().uuid(),
|
|
62
|
+
capabilities: z.array(z.string().max(64)).max(64),
|
|
63
|
+
}).strict(),
|
|
64
|
+
z.object({ type: z.literal('permissions_applied'), revision: z.number().int().min(0), projects: z.array(projectViewSchema).max(100), error: z.string().max(512).optional() }),
|
|
65
|
+
z.object({ type: z.literal('result'), id: z.string().uuid(), result: resultSchema }),
|
|
66
|
+
z.object({ type: z.literal('job_update'), job: jobViewSchema }),
|
|
67
|
+
z.object({ type: z.literal('jobs_snapshot'), snapshotId: z.string().uuid(), page: z.number().int().min(0).max(100), done: z.boolean(), jobs: z.array(jobViewSchema).max(100) }),
|
|
68
|
+
]);
|
|
69
|
+
export const relayMessageSchema = z.discriminatedUnion('type', [
|
|
70
|
+
z.object({ type: z.literal('welcome'), protocol: z.literal(RUNNER_PROTOCOL), deviceId: z.string(), permissions: remotePermissionsSchema, authorizations: z.array(z.object({ id: z.string().max(200), revision: z.number().int().min(0) })).max(10000) }),
|
|
71
|
+
z.object({ type: z.literal('permissions'), permissions: remotePermissionsSchema }),
|
|
72
|
+
z.object({ type: z.literal('authorization_changed'), authorizationId: z.string().max(200) }),
|
|
73
|
+
z.object({
|
|
74
|
+
type: z.literal('call'), id: z.string().uuid(), tool: z.string().max(64),
|
|
75
|
+
args: z.record(z.string(), z.unknown()), principal: principalSchema,
|
|
76
|
+
}),
|
|
77
|
+
z.object({ type: z.literal('cancel'), id: z.string().uuid() }),
|
|
78
|
+
]);
|
|
79
|
+
export function result(value, isError = false) {
|
|
80
|
+
const structuredContent = value && typeof value === 'object' ? Array.isArray(value) ? { items: value } : value : undefined;
|
|
81
|
+
const output = { content: [{ type: 'text', text: typeof value === 'string' ? value : JSON.stringify(value) }], ...(structuredContent ? { structuredContent } : {}), ...(isError ? { isError } : {}) };
|
|
82
|
+
if (Buffer.byteLength(JSON.stringify(output)) > MAX_FRAME - 4096)
|
|
83
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: 'result_limit', message: 'Result exceeds the transport limit; narrow the query or requested range' }) }], isError: true };
|
|
84
|
+
return output;
|
|
85
|
+
}
|
|
86
|
+
export class AppError extends Error {
|
|
87
|
+
code;
|
|
88
|
+
status;
|
|
89
|
+
constructor(code, message, status = 400) {
|
|
90
|
+
super(message);
|
|
91
|
+
this.code = code;
|
|
92
|
+
this.status = status;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
export function errorText(error) {
|
|
96
|
+
return error instanceof Error ? error.message : 'Unknown error';
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
const target = {
|
|
3
|
+
deviceId: z.string().min(1).max(100).optional().describe('Required when more than one authorized device is online'),
|
|
4
|
+
projectId: z.string().min(1).max(64).describe('Project ID from list_devices'),
|
|
5
|
+
};
|
|
6
|
+
const path = z.string().max(4096).default('.');
|
|
7
|
+
const gitTarget = { ...target, repository: z.string().max(4096).default('.').describe('Repository directory relative to the project root; absolute paths require device-wide file access') };
|
|
8
|
+
const sha = z.string().regex(/^[a-f0-9]{64}$/);
|
|
9
|
+
const launch = {
|
|
10
|
+
executable: z.string().min(1).max(4096), args: z.array(z.string().max(8192)).max(256).default([]),
|
|
11
|
+
cwd: path, timeoutMs: z.number().int().min(100).max(86400000).default(3600000),
|
|
12
|
+
environment: z.string().min(1).max(64).optional().describe('Administrator-configured environment profile name; values are delivered by the Server'),
|
|
13
|
+
idempotencyKey: z.string().min(8).max(128).optional().describe('Reuse the same key and identical arguments after an uncertain response; retained for 48 hours'),
|
|
14
|
+
};
|
|
15
|
+
const change = z.discriminatedUnion('operation', [
|
|
16
|
+
z.object({ operation: z.literal('create'), path: z.string().min(1).max(4096), content: z.string().max(262144) }).strict(),
|
|
17
|
+
z.object({ operation: z.literal('replace'), path: z.string().min(1).max(4096), expectedSha256: sha, content: z.string().max(262144) }).strict(),
|
|
18
|
+
z.object({ operation: z.literal('delete'), path: z.string().min(1).max(4096), expectedSha256: sha }).strict(),
|
|
19
|
+
z.object({ operation: z.literal('edit'), path: z.string().min(1).max(4096), expectedSha256: sha, edits: z.array(z.object({ oldText: z.string().min(1).max(131072), newText: z.string().max(131072) }).strict()).min(1).max(100) }).strict(),
|
|
20
|
+
]);
|
|
21
|
+
const schemas = {
|
|
22
|
+
get_project_context: z.object({ ...target, includeInstructions: z.boolean().default(true) }).strict(),
|
|
23
|
+
save_project_note: z.object({ ...target, text: z.string().max(8192) }).strict(),
|
|
24
|
+
read_files: z.object({ ...target, files: z.array(z.object({ path: z.string().min(1).max(4096), startLine: z.number().int().min(1).default(1), endLine: z.number().int().min(1).optional(), expectedSha256: sha.optional() }).strict()).min(1).max(16), maxBytes: z.number().int().min(1024).max(262144).default(131072) }).strict(),
|
|
25
|
+
edit_files: z.object({ ...target, changes: z.array(change).min(1).max(32), dryRun: z.boolean().default(false) }).strict(),
|
|
26
|
+
apply_unified_diff: z.object({ ...target, diff: z.string().min(1).max(262144), expectedSha256: z.record(z.string(), sha.nullable()), dryRun: z.boolean().default(false) }).strict(),
|
|
27
|
+
get_edit_transactions: z.object({ ...target }).strict(),
|
|
28
|
+
recover_edit_transaction: z.object({ ...target, transactionId: z.string().uuid() }).strict(),
|
|
29
|
+
list_directory: z.object({ ...target, path, offset: z.number().int().min(0).max(100000).default(0), limit: z.number().int().min(1).max(1000).default(200) }).strict(),
|
|
30
|
+
read_file: z.object({ ...target, path, offset: z.number().int().min(0).default(0), length: z.number().int().min(1).max(131072).default(65536), expectedRevision: z.string().regex(/^[a-f0-9]{64}$/).optional() }).strict(),
|
|
31
|
+
write_file: z.object({ ...target, path, content: z.string().max(262144), append: z.boolean().default(false), expectedSha256: z.string().regex(/^[a-f0-9]{64}$/).optional() }).strict(),
|
|
32
|
+
create_directory: z.object({ ...target, path }).strict(),
|
|
33
|
+
move_file: z.object({ ...target, source: path, destination: path }).strict(),
|
|
34
|
+
search_files: z.object({ ...target, path, query: z.string().min(1).max(512), content: z.boolean().default(false), caseSensitive: z.boolean().default(false), limit: z.number().int().min(1).max(500).default(100), include: z.array(z.string().max(512)).max(20).default([]), exclude: z.array(z.string().max(512)).max(20).default([]), contextLines: z.number().int().min(0).max(5).default(0), respectGitIgnore: z.boolean().default(true) }).strict(),
|
|
35
|
+
edit_block: z.object({ ...target, path, oldText: z.string().min(1).max(131072), newText: z.string().max(131072), expectedSha256: z.string().regex(/^[a-f0-9]{64}$/).optional() }).strict(),
|
|
36
|
+
get_file_info: z.object({ ...target, path }).strict(),
|
|
37
|
+
start_process: z.object({ ...target, ...launch }).strict(),
|
|
38
|
+
run_command: z.object({ ...target, ...launch, waitMs: z.number().int().min(0).max(20000).default(1500), length: z.number().int().min(1).max(65536).default(32768) }).strict(),
|
|
39
|
+
wait_process: z.object({ ...target, processId: z.string().uuid(), waitMs: z.number().int().min(0).max(20000).default(10000), until: z.enum(['output', 'finished']).default('finished'), cursor: z.number().int().min(0).optional(), length: z.number().int().min(1).max(65536).default(32768) }).strict(),
|
|
40
|
+
tail_process_output: z.object({ ...target, processId: z.string().uuid(), cursor: z.number().int().min(0).optional(), length: z.number().int().min(1).max(65536).default(32768) }).strict(),
|
|
41
|
+
read_process_output: z.object({ ...target, processId: z.string().uuid(), cursor: z.number().int().min(0).default(0), length: z.number().int().min(1).max(131072).default(65536) }).strict(),
|
|
42
|
+
write_process_input: z.object({ ...target, processId: z.string().uuid(), input: z.string().max(65536), close: z.boolean().default(false) }).strict(),
|
|
43
|
+
list_processes: z.object({ ...target }).strict(),
|
|
44
|
+
stop_process: z.object({ ...target, processId: z.string().uuid() }).strict(),
|
|
45
|
+
git_status: z.object({ ...gitTarget }).strict(),
|
|
46
|
+
git_diff: z.object({ ...gitTarget, staged: z.boolean().default(false), path: z.string().max(4096).optional() }).strict(),
|
|
47
|
+
git_log: z.object({ ...gitTarget, limit: z.number().int().min(1).max(100).default(20) }).strict(),
|
|
48
|
+
git_add: z.object({ ...gitTarget, paths: z.array(z.string().min(1).max(4096)).min(1).max(100) }).strict(),
|
|
49
|
+
git_commit: z.object({ ...gitTarget, message: z.string().min(1).max(4096) }).strict(),
|
|
50
|
+
git_commit_paths: z.object({ ...gitTarget, files: z.array(z.object({ path: z.string().min(1).max(4096), expectedSha256: sha.nullable() }).strict()).min(1).max(100), expectedHead: z.string().regex(/^[a-f0-9]{40}([a-f0-9]{24})?$/), message: z.string().min(1).max(4096) }).strict(),
|
|
51
|
+
git_branches: z.object({ ...gitTarget }).strict(),
|
|
52
|
+
git_switch_branch: z.object({ ...gitTarget, branch: z.string().min(1).max(200), create: z.boolean().default(false) }).strict(),
|
|
53
|
+
git_fetch: z.object({ ...gitTarget, remote: z.string().min(1).max(128).default('origin'), branch: z.string().min(1).max(200).optional() }).strict(),
|
|
54
|
+
git_pull: z.object({ ...gitTarget, remote: z.string().min(1).max(128).default('origin'), branch: z.string().min(1).max(200).optional() }).strict(),
|
|
55
|
+
git_push: z.object({ ...gitTarget, remote: z.string().min(1).max(128).default('origin'), branch: z.string().min(1).max(200).optional() }).strict(),
|
|
56
|
+
};
|
|
57
|
+
export const toolSchemas = schemas;
|
|
58
|
+
const descriptions = {
|
|
59
|
+
get_project_context: 'Inspect project manifests, local instructions, configured commands/aliases/environment names and Git state. Does not execute project scripts or expose environment values.',
|
|
60
|
+
save_project_note: 'Save your bounded project handoff note for the next conversation. Note is tied to this client identity, project and local root; it grants no authority.',
|
|
61
|
+
read_files: 'Read up to 16 UTF-8 files by line range in one bounded call. Returns full-file SHA-256 for revision-fenced edits, per-file errors and nextStartLine.',
|
|
62
|
+
edit_files: 'Preflight a batch of explicit create/replace/exact-edit/delete operations. Existing files require SHA-256. Uses a durable journal and conflict-aware rollback; dryRun previews without writes. Not filesystem snapshot isolation.',
|
|
63
|
+
apply_unified_diff: 'Apply a strict textual unified diff (---/+++/@@) through the journaled editor. Every path requires its expected SHA-256, or null for creation. Rejects binary diffs, renames, fuzzy matches and stale contexts.',
|
|
64
|
+
get_edit_transactions: 'List your recent edit receipts and unresolved recovery transactions for this project; does not expose backup contents.',
|
|
65
|
+
recover_edit_transaction: 'Recover your interrupted edit batch. Restores only paths still matching transaction after-images; refuses to overwrite external changes.',
|
|
66
|
+
list_directory: 'List a project directory in bounded live pages using nextOffset. Concurrent directory changes can shift entries.',
|
|
67
|
+
read_file: 'Read a UTF-8 file in byte ranges; reuse revision as expectedRevision on continuation to reject changed files. Returns SHA-256 for small files.',
|
|
68
|
+
write_file: 'Write or append UTF-8 text; optional expectedSha256 prevents stale edits.',
|
|
69
|
+
create_directory: 'Create directories inside the selected project.',
|
|
70
|
+
move_file: 'Move a file or directory within one project; refuses overwrite.',
|
|
71
|
+
search_files: 'Search file names or literal text; bounded scan, skips symlinks and .git.',
|
|
72
|
+
edit_block: 'Replace one unique exact text block in a file.',
|
|
73
|
+
get_file_info: 'Inspect file size, modification time and type.',
|
|
74
|
+
start_process: 'Start a tracked subprocess with executable + argv (no shell). Requires a locally allowed executable. Returns processId immediately; poll read_process_output.',
|
|
75
|
+
run_command: 'Run a permitted executable or local alias; wait briefly for completion and return its tail output in one call. Longer commands return a tracked process ID for wait_process. No implicit shell.',
|
|
76
|
+
wait_process: 'Wait up to 20 seconds for output changes or completion, without restarting the job. Returns bounded tail, status and absolute byte cursor; cancellation only stops waiting.',
|
|
77
|
+
tail_process_output: 'Read the rolling last 64 KiB of a job, including errors produced after the initial output cap. Absolute cursors and skippedBytes explicitly report overwritten output.',
|
|
78
|
+
read_process_output: 'Read bounded process output by byte cursor, including completion status.',
|
|
79
|
+
write_process_input: 'Send text to a tracked process stdin, optionally closing it.',
|
|
80
|
+
list_processes: 'List your tracked processes for this project.',
|
|
81
|
+
stop_process: 'Terminate a tracked process and its process tree.',
|
|
82
|
+
git_status: 'Read Git porcelain status.',
|
|
83
|
+
git_diff: 'Read bounded working tree or staged Git diff.',
|
|
84
|
+
git_log: 'Read recent commits.',
|
|
85
|
+
git_add: 'Stage explicitly named project paths.',
|
|
86
|
+
git_commit: 'Commit staged changes; hooks/signing disabled. Requires locally enabled Git writes.',
|
|
87
|
+
git_commit_paths: 'Commit only explicit file snapshots with expected HEAD and SHA-256 checks. Refuses selected paths with pre-existing staged changes and preserves unrelated staged entries. Requires Git writes.',
|
|
88
|
+
git_branches: 'Inspect current branch, exact HEAD and bounded local branch list.',
|
|
89
|
+
git_switch_branch: 'Switch to or create a local branch only in a clean working tree/index. Refuses force switching and does not push.',
|
|
90
|
+
git_fetch: 'Fetch a named configured HTTPS/SSH remote without submodules. Requires owner-enabled Git writes and network access. Use repository to select a nested repository.',
|
|
91
|
+
git_pull: 'Fast-forward a clean repository from a named configured HTTPS/SSH remote; never rebase, merge divergent history or recurse into submodules. Requires Git network access.',
|
|
92
|
+
git_push: 'Push HEAD to one branch on a named configured HTTPS/SSH remote, without force, deletion or tags. Requires the owner to separately enable Git push.',
|
|
93
|
+
};
|
|
94
|
+
export function toolScope(name) {
|
|
95
|
+
if (['write_file', 'create_directory', 'move_file', 'edit_block', 'edit_files', 'apply_unified_diff', 'recover_edit_transaction', 'save_project_note'].includes(name))
|
|
96
|
+
return 'write';
|
|
97
|
+
if (['start_process', 'run_command', 'write_process_input', 'stop_process'].includes(name))
|
|
98
|
+
return 'execute';
|
|
99
|
+
if (['git_add', 'git_commit', 'git_commit_paths', 'git_switch_branch', 'git_fetch', 'git_pull', 'git_push'].includes(name))
|
|
100
|
+
return 'git';
|
|
101
|
+
return 'read';
|
|
102
|
+
}
|
|
103
|
+
export const toolDefinitions = Object.entries(schemas).map(([name, schema]) => ({
|
|
104
|
+
name, description: descriptions[name],
|
|
105
|
+
inputSchema: z.toJSONSchema(schema, { target: 'draft-7' }),
|
|
106
|
+
annotations: { readOnlyHint: toolScope(name) === 'read', destructiveHint: toolScope(name) !== 'read', idempotentHint: false, openWorldHint: ['start_process', 'run_command', 'write_process_input', 'git_fetch', 'git_pull', 'git_push'].includes(name) },
|
|
107
|
+
}));
|
|
108
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# 架构与技术选型
|
|
2
|
+
|
|
3
|
+
v0.4 在 v0.3 的 context/editor/output-log/patch 基础上增加权限协议、Dashboard 权限编辑器和受控 Git 网络工具,MCP 目录扩展为 35 个工具。设备能力上限与客户端授权分层保存,临时授权可过期并触发任务收回。新增工具的执行语义和持久化恢复详见 [日常开发工作流](DEVELOPMENT_WORKFLOW.md)。
|
|
4
|
+
|
|
5
|
+
## 数据流与信任边界
|
|
6
|
+
|
|
7
|
+
```mermaid
|
|
8
|
+
flowchart LR
|
|
9
|
+
AI[AI MCP Client] -->|HTTPS /mcp + OAuth or PAT| S[Server]
|
|
10
|
+
B[Owner Browser] -->|Secure cookie + CSRF| D[Dashboard / Admin API]
|
|
11
|
+
D --> S
|
|
12
|
+
S --> DB[(SQLite)]
|
|
13
|
+
R[Runner] -->|Outbound WSS /runner + device credential| S
|
|
14
|
+
R --> P[Local project policy]
|
|
15
|
+
P --> F[File tools]
|
|
16
|
+
P --> T[Tracked processes]
|
|
17
|
+
P --> G[Git]
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
MCP 客户端不能调用管理 API;设备凭据不能访问 MCP;Dashboard cookie 不能作为 Runner 凭据。单管理员管理多个设备,外部客户端通过 OAuth 或 PAT 获得明确设备和权限范围。
|
|
21
|
+
|
|
22
|
+
Server 和 Runner 都是可信代码。Runner 不信任请求中的路径、工具参数和权限范围,必须再次检查 Server 下发的项目策略及实际文件系统边界;但 Runner 不能抵御被完全攻陷的 Server 伪造主体,因此必须保护 Server 主机和数据库。项目目录中的内容是潜在不可信输入,不能允许它修改 Runner 配置或凭据目录。
|
|
23
|
+
|
|
24
|
+
## 选型
|
|
25
|
+
|
|
26
|
+
| 层 | 选择 | 理由与限制 |
|
|
27
|
+
| --- | --- | --- |
|
|
28
|
+
| 运行时 | Node.js 24 LTS、TypeScript strict | Linux/Windows 共用实现,原生进程/文件 API,内置 SQLite;最低 24.14,容器固定 24.22.1 |
|
|
29
|
+
| MCP | `@modelcontextprotocol/server` 2.4.0、`@modelcontextprotocol/node` 2.1.2 | 官方 v2 `createMcpHandler`:2026-07-28 server/discover/逐请求 envelope,以及无状态 2025 initialize/tools;v1 SDK 1.32.2 仅保留自托管 OAuth 授权服务器辅助路由和旧客户端测试 |
|
|
30
|
+
| HTTP | Express 5 | 与 SDK OAuth 路由兼容,减少自制协议处理 |
|
|
31
|
+
| Runner 通道 | `ws`,TLS 由反代终止 | 主动连接、请求 UUID、心跳、连接替换、断线重连、帧大小限制 |
|
|
32
|
+
| 数据 | `node:sqlite` WAL | 无附加数据库服务,适合个人单节点;不支持多副本共享数据库 |
|
|
33
|
+
| Dashboard | 原生 HTML/CSS/JS | 无前端构建链、外部 CDN、字体或运行时云依赖;5 秒刷新 |
|
|
34
|
+
| 部署 | Docker Compose + 可选 Caddy/Nginx | 同机、VPS、内网反代均可;Cloudflare 是可选方案,会引入第三方链路 |
|
|
35
|
+
|
|
36
|
+
MCP 由官方 v2 serving entry 处理协议协商,工具定义由 Zod 生成 JSON Schema。2026 使用 server/discover 和每请求 `_meta` envelope;2025 兼容路径使用 initialize。两者都每请求创建独立 Server,不生成 MCP-Session-Id。本项目只广告工具能力,不承诺资源、prompts、MCP Apps、sampling 或 Host continuation。Dashboard 分别展示客户端授权、管理员登录会话和 Runner 任务;它们不等同于上游 Workflow Session。长任务保存在 Runner,不依赖 HTTP 会话。
|
|
37
|
+
|
|
38
|
+
依据:[MCP 传输规范](https://modelcontextprotocol.io/specification/2025-11-25/basic/transports)、[MCP 授权规范](https://modelcontextprotocol.io/specification/2025-11-25/basic/authorization)、[TypeScript SDK](https://github.com/modelcontextprotocol/typescript-sdk)、[Node.js SQLite](https://nodejs.org/api/sqlite.html)。
|
|
39
|
+
|
|
40
|
+
## 模块与执行顺序
|
|
41
|
+
|
|
42
|
+
1. `server/app.ts`、`server/mcp.ts`:HTTP 管理 API、标准新旧 MCP 入口、WebSocket upgrade 和应用生命周期。
|
|
43
|
+
2. `server/hub.ts`:在线设备、认证后的 hello、调用路由、超时取消、断线错误和每次调用审计。
|
|
44
|
+
3. `runner/agent.ts`、`runner/lock.ts`:主动连接、回退重连、心跳监测、并发限额、OS 状态目录锁及本机分发。
|
|
45
|
+
4. `server/security.ts`、`oauth.ts`、配对 API:Cookie/CSRF、DCR、S256 PKCE、资源绑定、刷新轮换、设备一次性码。
|
|
46
|
+
5. `server/jobs.ts`、`public/`:持久任务观察、设备状态、项目摘要、配对、暂停/恢复/撤销、登录会话、客户端令牌和审计。
|
|
47
|
+
6. `runner/files.ts`、`processes.ts`、`git.ts`:文件、长进程、Git 工具;`policy.ts` 统一验证。
|
|
48
|
+
|
|
49
|
+
## 内部协议
|
|
50
|
+
|
|
51
|
+
Runner 协议版本为 `2`,不接受旧版握手,一个 WebSocket 消息对应一个 JSON 信封,最大 2 MiB,禁用压缩。长期设备令牌仅在 TLS 握手的 Authorization 头使用;设备 ID 位于 `X-Device-ID`,不放在 URL。
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
{"type":"hello","protocol":2,"name":"workstation","platform":"win32/x64","version":"current","instanceId":"12345678-1234-4234-8234-123456789abc","capabilities":["read_file"],"projects":[]}
|
|
55
|
+
{"type":"welcome","protocol":2,"deviceId":"device-uuid","authorizations":[],"permissions":{"revision":3,"projects":[{"id":"app","name":"App","root":"E:/Projects/app","readOnly":false,"commands":[],"commandMode":"unrestricted","filesystemScope":"device","allowGitWrite":true,"allowGitNetwork":true,"allowGitPush":false}],"expiresAt":null,"fallbackProjects":[]}}
|
|
56
|
+
{"type":"permissions_applied","revision":3,"projects":[{"id":"app","name":"App","readOnly":false,"commands":[],"commandMode":"unrestricted","filesystemScope":"device","allowGitWrite":true,"allowGitNetwork":true,"allowGitPush":false}]}
|
|
57
|
+
{"type":"call","id":"request-uuid","tool":"read_file","args":{"projectId":"app","path":"README.md"},"principal":{"id":"pat:uuid","scopes":["read"],"devices":["device-uuid"],"projects":["app"]}}
|
|
58
|
+
{"type":"result","id":"request-uuid","result":{"content":[{"type":"text","text":"..."}]}}
|
|
59
|
+
{"type":"cancel","id":"request-uuid"}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Zod 严格验证工具参数与消息结构。Server 只接受发给当前连接的请求结果,其他设备或被替换的旧连接不能提交该请求的结果。Runner 最多 32 个同时调用,Server 每设备最多 32 个、总计最多 256 个待处理调用。
|
|
63
|
+
|
|
64
|
+
Runner v0.2 另外报告 instanceId、工具 capabilities、job_update,以及每页最多 100 项、总计最多 10000 项的 jobs_snapshot。Server 校验快照页序、主体/项目/准入时间不可变、revision 单调及终态不可回退。快照完成后才能从 Dashboard 控制该确切实例的历史任务。元数据不含 argv、原始 cwd、输出或错误正文。旧连接的迟到事件不会覆盖新连接。
|
|
65
|
+
|
|
66
|
+
WS 原生 ping 每 15 秒发送一次,漏回 pong 将断开;Runner 45 秒无心跳会主动重连。连接后 10 秒内必须发送 hello。重连使用指数回退,最高约 30 秒并附随机抖动。设备暂停关闭连接并停止托管任务,恢复后 Runner 可重新连接;撤销则停止自动连接,需要显式配对。Server 断线后 Runner 收回项目访问并停止托管任务,重连后重新应用 Server 配置。
|
|
67
|
+
|
|
68
|
+
### 权限同步与收回
|
|
69
|
+
|
|
70
|
+
Server 是设备项目设置的唯一来源,保存当前项目、永久回退项目、应用 revision 和应用错误。本机连接配置不接受项目列表或权限开关;Runner 收到 `welcome` 或 `permissions` 后串行停止活动调用和托管进程,验证每个根目录、受保护路径、项目 ID 和 Git 配置,再回复 `permissions_applied`。应用失败时 Runner 保持不可调用状态,避免继续使用上一份高权限配置。
|
|
71
|
+
|
|
72
|
+
客户端每次 MCP dispatch 都重新从 Server 解析当前 token family 的永久或临时授权,并动态过滤 `tools/list`。`authorization_changed` 会让 Runner 停止该授权创建的任务;临时授权到期由 Server 定时清理,Runner 也依据调用和任务上的到期时间独立停止。`expectedRevision` 防止 Dashboard 中的旧编辑器覆盖较新的权限修改。
|
|
73
|
+
|
|
74
|
+
## 配对与认证
|
|
75
|
+
|
|
76
|
+
配对码为 40 bit 随机值(10 位十六进制),10 分钟过期。Runner 另外持有 256 bit 轮询凭据;管理员仅能批准码,不能从码直接领取设备令牌。领取操作和状态转移使用 SQLite 事务,成功后立即消费。Server 只保存设备令牌的 SHA-256。
|
|
77
|
+
|
|
78
|
+
OAuth 元数据、DCR、授权码、S256 PKCE、token、revoke 路由由官方 SDK 提供;实际授权状态和令牌由本项目实现。浏览器确认客户端、回调地址、设备和 scopes。授权码 2 分钟有效、只使用一次;Access Token 1 小时,Refresh Token 30 天且每次刷新轮换。重用已消费的 Refresh Token 会撤销整个令牌族。Token 的 resource 始终绑定当前 `/mcp`。
|
|
79
|
+
|
|
80
|
+
PAT 有效期 1–365 天,必须指定已配对设备,可指定项目或设备限定的 projectGrants。新 OAuth grant 必须选择具体设备与项目,刷新不扩大这个快照;v0.1 的旧 grant 不被静默重写,需撤销并重新授权以收紧项目范围。Token 存 SHA-256 摘要;OAuth 客户端 confidential secret 用 SESSION_SECRET 派生密钥做 AES-256-GCM 加密。更换 SESSION_SECRET 会使旧 cookie/OAuth 客户端失效。dispatch 再检查当前令牌,族撤销会取消仍在排队的调用;已产生的副作用和已启动的独立任务不自动回滚。
|
|
81
|
+
|
|
82
|
+
## 持久化与任务
|
|
83
|
+
|
|
84
|
+
Server 数据库保存设备、配对、客户端、授权码、令牌、浏览器 session 和审计。审计只有参数摘要,不存参数正文和输出。启动及每小时清理过期授权临时状态和超过保留期的审计。
|
|
85
|
+
|
|
86
|
+
Server 还保存每设备最多 10000 条 Job 元数据,按审计保留天数过期;上限时只逐出较旧终态记录。在线/终态保留/离线未确认/Runner 未报告是不同的观察状态。查询先按设备、项目和主体过滤后取有界结果,不复制进程输出到 Server 数据库。
|
|
87
|
+
|
|
88
|
+
Runner 的 `jobs.sqlite` 保存主体、项目、开始结束时间、状态、退出码和输出计数;`<job-uuid>.output` 保存合并 stdout/stderr,默认最多 8 MiB。每个任务的输出达上限后继续排空进程管道,丢弃新增输出并标记截断,避免输出阻塞与磁盘无限增长。最多保留配置数量的历史任务,下次启动任务时清理较旧已结束记录。
|
|
89
|
+
|
|
90
|
+
任务不在 Server 断线时重放。HTTP 45 秒超时或断线可能意味着结果未知;文件修改/提交仍需先检查再决定重试。进程启动可用 idempotencyKey:48 小时内按主体、项目和参数摘要去重;准入先持久化,崩溃后保留 interrupted/未知结果,不再次 spawn。历史任务清理后仍保留拒绝重放的收据,最多 10000 个 key;过期后不再保证去重。这不是所有工具 exactly-once,也不是 detached supervisor。
|
|
91
|
+
|
|
92
|
+
Runner 正常退出会停止并等待托管树,再关闭数据库和锁;同一 stateDir 的运行/配对互斥,OS 释放崩溃进程的 SQLite 锁,无 PID 锁文件回收猜测。Windows supervisor 用 suspended admission + Job Object 并监视 Runner 死亡,Linux 在 leader 退出时清理原组;Linux Runner 被强制杀死仍需 systemd control-group/容器清理。启动时未结束记录标为 interrupted,不按旧 PID 杀进程、不自动恢复。没有 PTY、跨 Runner 重启存活的 detached 任务、工作流会话、集群或多租户。完整源码差异见 WEBCODEX_CODE_AUDIT.md。
|
package/docs/CLIENTS.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# AI 客户端连接
|
|
2
|
+
|
|
3
|
+
核对日期:2026-10-26。客户端界面和账户权限可能变化;本项目不提供模型服务,也不要求模型 API Key。
|
|
4
|
+
|
|
5
|
+
v0.3 日常编码优先采用 [开发工作流](DEVELOPMENT_WORKFLOW.md):get_project_context → read_files/search_files → edit_files/apply_unified_diff → run_command/wait_process → git_commit_paths。原有工具继续可用。
|
|
6
|
+
|
|
7
|
+
## 共同前提
|
|
8
|
+
|
|
9
|
+
先确保 Runner 配对且在线,客户端可以访问 `https://mcp.example.com/mcp`,TLS 证书有效。Server 同时支持 OAuth discovery + DCR + S256 PKCE 和 Dashboard 创建的 Bearer PAT,后者必须限制到具体设备,可以进一步限制项目和 scopes。
|
|
10
|
+
|
|
11
|
+
`/mcp` 使用无状态 Streamable HTTP,支持 MCP 2026-07-28 的 server/discover/每请求 envelope,并兼容 2025 客户端 initialize。官方 SDK 会处理协商、Accept、JSON/SSE 和协议头;原始请求不能把 SSE 响应直接当 JSON 解析。不要使用旧版 `/sse` URL。
|
|
12
|
+
|
|
13
|
+
### 授权按钮无反应或提示 expired
|
|
14
|
+
|
|
15
|
+
v0.3.0 的授权表单直接重定向到外部回调,Chrome 可能按 `form-action 'self'` 拦截该跳转;授权请求却已被消费,第二次点击便显示 `Authorization request expired`。**升级 Server 到 v0.3.1**:新版本先进入站内完成页,再返回已注册客户端,保留严格 CSP;按钮显示提交状态并防止重复提交。
|
|
16
|
+
|
|
17
|
+
升级后重启 Server,回到 AI 客户端重新发起 OAuth 授权,不要刷新或重复提交旧标签页。npm 部署升级 `homeagent-server` 包后重启对应服务;Runner 使用独立的 `homeagent-runner` 包,两者应升级到相同版本。Compose 部署检出 v0.4.5 后重新构建并启动,保留原 `.env` 和数据卷。Runner v0.3.0 不需要为 OAuth 回调修复升级;要使用 v0.4 的 Web 权限管理,则 Server 和 Runner 都应升级到 v0.4.5。
|
|
18
|
+
|
|
19
|
+
若完成页没有自动返回,点击“继续返回客户端”。已使用或过期的授权码不会被重新签发;客户端仍未连接时,从客户端新建一次授权请求。设备凭据及已完成的客户端授权不因升级被主动清空。
|
|
20
|
+
|
|
21
|
+
## ChatGPT
|
|
22
|
+
|
|
23
|
+
根据目前的 [OpenAI 官方连接文档](https://developers.openai.com/plugins/deploy/connect-chatgpt),在 **ChatGPT Plugins** 页面使用加号 → **Add custom MCP server**,填写名称与描述,选择公共 HTTPS 连接方式,URL 为 `https://mcp.example.com/mcp`,配置 OAuth 并完成风险确认。可用性受账户和 workspace 策略影响;若你的产品界面仍使用 Apps/Connectors 名称,请在该界面寻找对应的自定义 MCP 入口,并以实际账户提供的入口为准。
|
|
24
|
+
|
|
25
|
+
OAuth 会打开 HomeAgent 登录页。确认:
|
|
26
|
+
|
|
27
|
+
1. 地址是自己的 Server。
|
|
28
|
+
2. 显示的客户端与 HTTPS/loopback 回调地址符合当前操作。
|
|
29
|
+
3. 勾选允许使用的已配对设备、该设备上的具体项目与权限。默认只勾选 read;写入需 write,终端需 execute,Git add/commit 需 git。新增项目不会自动进入这次授权,刷新令牌也不扩大范围。
|
|
30
|
+
4. 允许后回到 ChatGPT,刷新工具列表并在对话中启用该连接。
|
|
31
|
+
|
|
32
|
+
自托管 Server 不依赖 OpenAI 的托管隧道。如果使用 ChatGPT,返回的文件内容、命令结果会进入你选择的 AI 服务;“自托管执行系统”并不等于“AI 服务无法看到工具结果”。完全离线时使用局域网可达的本地 MCP 客户端和本地模型。
|
|
33
|
+
|
|
34
|
+
这里提供的是协议与官方接入流程;仓库自动化测试使用 MCP SDK 客户端,不宣称已替你登录真实 ChatGPT 账户完成验收。
|
|
35
|
+
|
|
36
|
+
## Claude Code
|
|
37
|
+
|
|
38
|
+
[Claude Code 官方 MCP 文档](https://code.claude.com/docs/en/mcp) 支持 HTTP 远程服务器和 OAuth:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
claude mcp add --transport http homeagent https://mcp.example.com/mcp
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
在 Claude Code 的 `/mcp` 中选择该服务并认证,浏览器完成 HomeAgent 授权。只需 read 时保持默认,写入/执行需在授权页面勾选相应权限。
|
|
45
|
+
|
|
46
|
+
若使用 PAT,可使用客户端支持的 `--header`:
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
claude mcp add --transport http homeagent https://mcp.example.com/mcp \
|
|
50
|
+
--header "Authorization: Bearer <Dashboard 创建的令牌>"
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
注意 shell 历史和客户端配置文件会保存命令中的静态令牌;生产更推荐 OAuth 或客户端自己的安全凭据管理。Claude 网页或 Desktop 的远程自定义连接器也应使用同一个 HTTPS `/mcp`,前提是账户提供远程自定义 MCP 功能;不用本地 stdio 配置冒充远程连接。
|
|
54
|
+
|
|
55
|
+
## Cursor
|
|
56
|
+
|
|
57
|
+
按照 [Cursor 官方 MCP 文档](https://cursor.com/docs/context/mcp),在用户级 MCP 配置中添加:
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"mcpServers": {
|
|
62
|
+
"homeagent": {
|
|
63
|
+
"url": "https://mcp.example.com/mcp"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
支持 OAuth 的 Cursor 会通过元数据发起登录,完成设备与权限批准。若需要静态令牌:
|
|
70
|
+
|
|
71
|
+
```json
|
|
72
|
+
{
|
|
73
|
+
"mcpServers": {
|
|
74
|
+
"homeagent": {
|
|
75
|
+
"url": "https://mcp.example.com/mcp",
|
|
76
|
+
"headers": {
|
|
77
|
+
"Authorization": "Bearer <Dashboard 创建的令牌>"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
把实际令牌放在用户私有配置,不要提交到项目 `.cursor/mcp.json`。Cursor 当前文档列出的远程 OAuth 回调使用固定 HTTPS 地址,本项目 DCR 会记录实际请求的 redirect_uris 并在授权时展示,不要求手工添加回调覆盖。
|
|
85
|
+
|
|
86
|
+
## 通用 MCP 客户端与调试
|
|
87
|
+
|
|
88
|
+
```sh
|
|
89
|
+
npx @modelcontextprotocol/inspector
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
在 Inspector 选择 Streamable HTTP,填写 `/mcp` URL,提供 Bearer Token 或完成 OAuth。先初始化、列出工具,再调用:
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
{"name":"list_devices","arguments":{}}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
取得允许的设备和项目后:
|
|
99
|
+
|
|
100
|
+
```json
|
|
101
|
+
{
|
|
102
|
+
"name": "read_file",
|
|
103
|
+
"arguments": {
|
|
104
|
+
"deviceId": "实际设备 UUID",
|
|
105
|
+
"projectId": "my-app",
|
|
106
|
+
"path": "README.md"
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
长任务示例:
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
{
|
|
115
|
+
"name": "start_process",
|
|
116
|
+
"arguments": {
|
|
117
|
+
"deviceId": "实际设备 UUID",
|
|
118
|
+
"projectId": "my-app",
|
|
119
|
+
"executable": "/usr/bin/node",
|
|
120
|
+
"args": ["--test"],
|
|
121
|
+
"cwd": ".",
|
|
122
|
+
"timeoutMs": 3600000,
|
|
123
|
+
"idempotencyKey": "为本次启动生成并保留的唯一键"
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
读取输出时使用返回的 `id` 作为 `processId`,把下一次 `cursor` 设为前次 `nextCursor`。不能向另一个客户端主体查询该任务。OAuth 刷新仍使用同一主体,新的独立 PAT 则是另一个主体。
|
|
129
|
+
|
|
130
|
+
如果工具调用超时或断线,写入/提交先读取文件或 Git 状态确认;进程启动可用相同 idempotencyKey 和完全相同参数重试,在 48 小时收据窗口内返回原任务而不再次启动。换 key、改参数、过期后的请求不在这个保证内。也可以在 Dashboard 查看保留的任务元数据并对在线的准确实例读取输出/停止。
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# 参考项目对比
|
|
2
|
+
|
|
3
|
+
核对日期:2026-10-26。比较基于公开源码,而非仅依据功能宣传。
|
|
4
|
+
|
|
5
|
+
本文件是架构概览。更完整的源码核查、逐工具映射、本轮发现并修复的缺口,以及仍未实现的全部领域,见 [WebCodex 源码对照审计](WEBCODEX_CODE_AUDIT.md) 与 [192 条声明清单](webcodex-source-inventory.json)。当前实现不具备 WebCodex 的全量产品能力。
|
|
6
|
+
|
|
7
|
+
用户给出的 `https://github.com/better-remote-commander` 不是具体仓库地址。本实现核对并参考的是 [shahidx0x/better-remote-commander](https://github.com/shahidx0x/better-remote-commander)。如实际指向其他项目,需要重新比较。
|
|
8
|
+
|
|
9
|
+
| 参考项目 | 本次核对的 main 修订 | 主要来源 |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| WebCodex | `4ab06a5574792a86302dcd9a13bb4214ee09cc50` | [README](https://github.com/yyjeqhc/webcodex/blob/4ab06a5574792a86302dcd9a13bb4214ee09cc50/README.zh-CN.md)、[Runner 信封](https://github.com/yyjeqhc/webcodex/blob/4ab06a5574792a86302dcd9a13bb4214ee09cc50/crates/webcodex-core/src/runner_protocol/transport.rs)、[架构](https://github.com/yyjeqhc/webcodex/blob/4ab06a5574792a86302dcd9a13bb4214ee09cc50/docs/ARCHITECTURE.md) |
|
|
12
|
+
| Better Remote Commander | `cbe511702dd0147650353c29ac6ab1decd8afda1` | [架构及阶段记录](https://github.com/shahidx0x/better-remote-commander/blob/cbe511702dd0147650353c29ac6ab1decd8afda1/docs/architecture.md)、[协议](https://github.com/shahidx0x/better-remote-commander/blob/cbe511702dd0147650353c29ac6ab1decd8afda1/packages/shared/src/protocol.ts)、[安全说明](https://github.com/shahidx0x/better-remote-commander/blob/cbe511702dd0147650353c29ac6ab1decd8afda1/SECURITY.md) |
|
|
13
|
+
|
|
14
|
+
## 架构与协议
|
|
15
|
+
|
|
16
|
+
| 维度 | WebCodex | Better Remote Commander | HomeAgent 的选择 |
|
|
17
|
+
| --- | --- | --- | --- |
|
|
18
|
+
| 组织方式 | Rust 多 crate 的完整运行时,包含 Desktop、CLI、Server、Runner、注册表等 | TypeScript 的 relay/agent/shared,工具核心移植自 Desktop Commander | TypeScript 的 server/runner/shared,独立工具实现,降低构建成本 |
|
|
19
|
+
| 客户端入口 | Server 认证并路由到真实开发环境,含丰富运行时工作流 | `/mcp` Streamable HTTP,OAuth discovery、DCR、PKCE | 官方 MCP SDK,固定 `/mcp`,OAuth 和具范围的 PAT |
|
|
20
|
+
| Runner 通道 | 传输中立的注册、请求、结果、job_update 等信封;源码还定义 QUIC 帧 | 主动 WS,hello/call/result/ping/pong | 主动 WSS,版本化 hello/call/result/cancel,WS ping/pong |
|
|
21
|
+
| 项目边界 | 项目、能力授权、任务生命周期体系更丰富 | 设备路由 + allowedDirectories + blockedCommands | 每项目独立 root/readOnly/commands/Git 写入开关,本地再次验证 |
|
|
22
|
+
| 长任务 | Job、持久 shell、观察与会话接续等完整模型 | start_process、读取输出、进程管理 | 持久进程元数据、限额输出文件、游标读取、stdin、整组终止、归属校验 |
|
|
23
|
+
| 运维形态 | 更全面,但组件、构建与原生安装验收更复杂 | SQLite、Compose、Dashboard、反代/隧道、自启动 | SQLite 单节点、Compose、原生 Runner、Caddy/Nginx、可选隧道 |
|
|
24
|
+
| 工具覆盖 | 强调真实项目开发流程与可审查工作结果 | Desktop Commander 的文件、搜索、编辑、终端能力更广,还含非核心文档功能 | 直接使用实用工具名,覆盖本需求文件/终端/Git,不引入 PDF/浏览器下载依赖 |
|
|
25
|
+
|
|
26
|
+
WebCodex 的优势是开发任务的上下文、生命周期和项目治理比较完整,适合持续运行与审查。代价是系统规模更大,原生构建和平台安装面更广;其 README 本身也明确区分安装交付目标与尚待完成的真实平台验收,不能把计划能力当作已验证能力。HomeAgent 吸收项目边界、Runner 主动连接、长任务观察、多设备与审计,但不重建它的 Desktop、工作流会话和 QUIC 栈。
|
|
27
|
+
|
|
28
|
+
BRC 的优势是轻量、工具实用,OAuth、配对和 Dashboard 与远程 MCP 的常见接入需求贴合。代价是移植工具核心的依赖与维护负担;它的阶段记录提到 PDF 工具存在首次使用下载 Chrome 的行为。它使用目录限制与命令阻止表,这种策略不能自动隔离可执行的解释器和构建脚本。HomeAgent 采用默认空的可执行文件允许列表,不提供远程修改本机策略的工具。
|
|
29
|
+
|
|
30
|
+
## 安全结论与兼容边界
|
|
31
|
+
|
|
32
|
+
两种项目都把 Runner/Agent 作为执行实际系统操作的信任主体。主动连出解决 NAT 和入站暴露问题,不会减少一个获准执行命令的 AI 客户端本身拥有的操作权限。
|
|
33
|
+
|
|
34
|
+
HomeAgent 的 Server 协议是标准 MCP;Runner 信封是项目自己的内部协议,不与 WebCodex 或 BRC 的 Runner 二进制互通。工具命名参考 Desktop Commander 常用语义,参数刻意增加 `projectId`、权限与进程归属,也不宣称与其全部工具逐参数兼容。
|
|
35
|
+
|
|
36
|
+
本项目仅借鉴架构与行为设计,代码独立编写。没有将第三方遥测、云中继或托管配对服务引入运行链路。
|