toc-ocra 0.2.0
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/LICENSE +21 -0
- package/README.md +70 -0
- package/assets/icon.svg +1 -0
- package/dist/plugin/renderer.css +2 -0
- package/dist/plugin/renderer.css.map +7 -0
- package/dist/plugin/renderer.js +2 -0
- package/dist/plugin/renderer.js.map +7 -0
- package/dist/src/config.d.ts +66 -0
- package/dist/src/config.js +173 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/control/pairing.d.ts +44 -0
- package/dist/src/control/pairing.js +99 -0
- package/dist/src/control/pairing.js.map +1 -0
- package/dist/src/exec/script-runner.d.ts +9 -0
- package/dist/src/exec/script-runner.js +110 -0
- package/dist/src/exec/script-runner.js.map +1 -0
- package/dist/src/health/server.d.ts +74 -0
- package/dist/src/health/server.js +248 -0
- package/dist/src/health/server.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +173 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/logging/diagnostic-log.d.ts +16 -0
- package/dist/src/logging/diagnostic-log.js +128 -0
- package/dist/src/logging/diagnostic-log.js.map +1 -0
- package/dist/src/providers/cli/claude.d.ts +2 -0
- package/dist/src/providers/cli/claude.js +48 -0
- package/dist/src/providers/cli/claude.js.map +1 -0
- package/dist/src/providers/cli/codex.d.ts +2 -0
- package/dist/src/providers/cli/codex.js +67 -0
- package/dist/src/providers/cli/codex.js.map +1 -0
- package/dist/src/providers/cli/gemini.d.ts +2 -0
- package/dist/src/providers/cli/gemini.js +30 -0
- package/dist/src/providers/cli/gemini.js.map +1 -0
- package/dist/src/providers/cli/grok.d.ts +2 -0
- package/dist/src/providers/cli/grok.js +29 -0
- package/dist/src/providers/cli/grok.js.map +1 -0
- package/dist/src/providers/cli/opencode.d.ts +2 -0
- package/dist/src/providers/cli/opencode.js +29 -0
- package/dist/src/providers/cli/opencode.js.map +1 -0
- package/dist/src/providers/detection.d.ts +11 -0
- package/dist/src/providers/detection.js +96 -0
- package/dist/src/providers/detection.js.map +1 -0
- package/dist/src/providers/model-catalog-collector.d.ts +22 -0
- package/dist/src/providers/model-catalog-collector.js +66 -0
- package/dist/src/providers/model-catalog-collector.js.map +1 -0
- package/dist/src/providers/model-catalog.d.ts +45 -0
- package/dist/src/providers/model-catalog.js +382 -0
- package/dist/src/providers/model-catalog.js.map +1 -0
- package/dist/src/providers/provider.d.ts +49 -0
- package/dist/src/providers/provider.js +63 -0
- package/dist/src/providers/provider.js.map +1 -0
- package/dist/src/providers/registry.d.ts +31 -0
- package/dist/src/providers/registry.js +60 -0
- package/dist/src/providers/registry.js.map +1 -0
- package/dist/src/runs/orphan-registry.d.ts +24 -0
- package/dist/src/runs/orphan-registry.js +63 -0
- package/dist/src/runs/orphan-registry.js.map +1 -0
- package/dist/src/runs/process-tree.d.ts +21 -0
- package/dist/src/runs/process-tree.js +95 -0
- package/dist/src/runs/process-tree.js.map +1 -0
- package/dist/src/runs/run-supervisor.d.ts +63 -0
- package/dist/src/runs/run-supervisor.js +285 -0
- package/dist/src/runs/run-supervisor.js.map +1 -0
- package/dist/src/runtime/agent-runtime.d.ts +68 -0
- package/dist/src/runtime/agent-runtime.js +340 -0
- package/dist/src/runtime/agent-runtime.js.map +1 -0
- package/dist/src/runtime/agent-service.d.ts +33 -0
- package/dist/src/runtime/agent-service.js +181 -0
- package/dist/src/runtime/agent-service.js.map +1 -0
- package/dist/src/runtime/cli/hydrate-shell-path.d.ts +33 -0
- package/dist/src/runtime/cli/hydrate-shell-path.js +173 -0
- package/dist/src/runtime/cli/hydrate-shell-path.js.map +1 -0
- package/dist/src/session/terminal-line-sanitizer.d.ts +7 -0
- package/dist/src/session/terminal-line-sanitizer.js +21 -0
- package/dist/src/session/terminal-line-sanitizer.js.map +1 -0
- package/dist/src/session/terminal-tail-buffer.d.ts +70 -0
- package/dist/src/session/terminal-tail-buffer.js +149 -0
- package/dist/src/session/terminal-tail-buffer.js.map +1 -0
- package/dist/src/shared/cli-detection-types.d.ts +19 -0
- package/dist/src/shared/cli-detection-types.js +2 -0
- package/dist/src/shared/cli-detection-types.js.map +1 -0
- package/dist/src/shared/node-cli-command-resolution.d.ts +19 -0
- package/dist/src/shared/node-cli-command-resolution.js +173 -0
- package/dist/src/shared/node-cli-command-resolution.js.map +1 -0
- package/dist/src/transport/gateway-client.d.ts +38 -0
- package/dist/src/transport/gateway-client.js +73 -0
- package/dist/src/transport/gateway-client.js.map +1 -0
- package/dist/src/types/protocol.d.ts +172 -0
- package/dist/src/types/protocol.js +55 -0
- package/dist/src/types/protocol.js.map +1 -0
- package/dist/src/workspace/directory-browser.d.ts +17 -0
- package/dist/src/workspace/directory-browser.js +47 -0
- package/dist/src/workspace/directory-browser.js.map +1 -0
- package/dist/src/workspace/workspace-manager.d.ts +41 -0
- package/dist/src/workspace/workspace-manager.js +436 -0
- package/dist/src/workspace/workspace-manager.js.map +1 -0
- package/locales/en.json +66 -0
- package/locales/zh-CN.json +66 -0
- package/package.json +90 -0
- package/scripts/service.mjs +174 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { accessSync, constants, existsSync, readdirSync, statSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { delimiter, dirname, join } from 'node:path';
|
|
4
|
+
function getExecutableNames(platform, commandName) {
|
|
5
|
+
if (platform === 'win32') {
|
|
6
|
+
return [`${commandName}.cmd`, `${commandName}.exe`, `${commandName}.bat`, commandName];
|
|
7
|
+
}
|
|
8
|
+
return [commandName];
|
|
9
|
+
}
|
|
10
|
+
function splitPath(pathEnv) {
|
|
11
|
+
if (!pathEnv) {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
return pathEnv
|
|
15
|
+
.split(delimiter)
|
|
16
|
+
.map((entry) => entry.trim())
|
|
17
|
+
.filter(Boolean);
|
|
18
|
+
}
|
|
19
|
+
function parseVersionSegment(raw) {
|
|
20
|
+
return raw
|
|
21
|
+
.replace(/^v/i, '')
|
|
22
|
+
.split('.')
|
|
23
|
+
.map((segment) => Number.parseInt(segment, 10))
|
|
24
|
+
.map((segment) => (Number.isFinite(segment) ? segment : 0));
|
|
25
|
+
}
|
|
26
|
+
function compareVersionDesc(left, right) {
|
|
27
|
+
const leftParts = parseVersionSegment(left);
|
|
28
|
+
const rightParts = parseVersionSegment(right);
|
|
29
|
+
const length = Math.max(leftParts.length, rightParts.length);
|
|
30
|
+
for (let index = 0; index < length; index += 1) {
|
|
31
|
+
const delta = (rightParts[index] ?? 0) - (leftParts[index] ?? 0);
|
|
32
|
+
if (delta !== 0) {
|
|
33
|
+
return delta;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return right.localeCompare(left);
|
|
37
|
+
}
|
|
38
|
+
function findFirstExecutable(platform, directories, executableNames) {
|
|
39
|
+
for (const directory of directories) {
|
|
40
|
+
for (const executableName of executableNames) {
|
|
41
|
+
const candidate = join(directory, executableName);
|
|
42
|
+
if (isRunnableCommand(platform, candidate)) {
|
|
43
|
+
return candidate;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
function isRunnableCommand(platform, candidate) {
|
|
50
|
+
try {
|
|
51
|
+
const stats = statSync(candidate);
|
|
52
|
+
if (!stats.isFile()) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
if (platform === 'win32') {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
// Why: GUI fallback probing should skip placeholders/directories so spawn
|
|
59
|
+
// can continue to a runnable CLI instead of failing later with EACCES/EISDIR.
|
|
60
|
+
accessSync(candidate, constants.X_OK);
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function getBaseVersionManagerDirectories(platform, homePath) {
|
|
68
|
+
const directories = [
|
|
69
|
+
join(homePath, '.volta', 'bin'),
|
|
70
|
+
join(homePath, '.asdf', 'shims'),
|
|
71
|
+
join(homePath, '.fnm', 'aliases', 'default', 'bin'),
|
|
72
|
+
// Why: mise (formerly rtx) exposes managed tool binaries via a shims
|
|
73
|
+
// directory, similar to asdf.
|
|
74
|
+
join(homePath, '.local', 'share', 'mise', 'shims')
|
|
75
|
+
];
|
|
76
|
+
if (platform === 'win32') {
|
|
77
|
+
// Why: Anthropic's native Windows installer places claude.exe here, and
|
|
78
|
+
// GUI-launched Orca may not inherit the user's PATH entry for it.
|
|
79
|
+
directories.push(join(homePath, '.local', 'bin'));
|
|
80
|
+
directories.push(join(homePath, 'AppData', 'Roaming', 'npm'));
|
|
81
|
+
directories.push(join(homePath, 'AppData', 'Local', 'pnpm'));
|
|
82
|
+
directories.push(join(homePath, 'AppData', 'Local', 'Yarn', 'bin'));
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
directories.push(join(homePath, '.local', 'bin'));
|
|
86
|
+
// Why: pnpm uses platform-specific global bin directories that differ from
|
|
87
|
+
// npm's ~/.local/bin.
|
|
88
|
+
if (platform === 'darwin') {
|
|
89
|
+
directories.push(join(homePath, 'Library', 'pnpm'));
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
directories.push(join(homePath, '.local', 'share', 'pnpm'));
|
|
93
|
+
}
|
|
94
|
+
directories.push(join(homePath, '.yarn', 'bin'));
|
|
95
|
+
}
|
|
96
|
+
directories.push(join(homePath, '.bun', 'bin'));
|
|
97
|
+
return directories;
|
|
98
|
+
}
|
|
99
|
+
function getNvmVersionDirectories(homePath) {
|
|
100
|
+
const nvmVersionsDir = join(homePath, '.nvm', 'versions', 'node');
|
|
101
|
+
if (!existsSync(nvmVersionsDir)) {
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
return readdirSync(nvmVersionsDir, { withFileTypes: true })
|
|
105
|
+
.filter((entry) => entry.isDirectory())
|
|
106
|
+
.map((entry) => entry.name)
|
|
107
|
+
.sort(compareVersionDesc)
|
|
108
|
+
.map((entry) => join(nvmVersionsDir, entry, 'bin'));
|
|
109
|
+
}
|
|
110
|
+
function getVersionManagerDirectories(platform, homePath, executableNames) {
|
|
111
|
+
const directories = getBaseVersionManagerDirectories(platform, homePath);
|
|
112
|
+
const firstNvmMatch = findFirstExecutable(platform, getNvmVersionDirectories(homePath), executableNames);
|
|
113
|
+
if (firstNvmMatch) {
|
|
114
|
+
directories.unshift(dirname(firstNvmMatch));
|
|
115
|
+
}
|
|
116
|
+
return directories;
|
|
117
|
+
}
|
|
118
|
+
export function resolveCliCommand(commandName, options = {}) {
|
|
119
|
+
return findCliCommand(commandName, options) ?? commandName;
|
|
120
|
+
}
|
|
121
|
+
export function findCliCommand(commandName, options = {}) {
|
|
122
|
+
const platform = options.platform ?? process.platform;
|
|
123
|
+
const executableNames = getExecutableNames(platform, commandName);
|
|
124
|
+
const pathEnv = options.pathEnv ?? process.env.PATH ?? process.env.Path ?? null;
|
|
125
|
+
const pathCandidate = findFirstExecutable(platform, splitPath(pathEnv), executableNames);
|
|
126
|
+
if (pathCandidate) {
|
|
127
|
+
return pathCandidate;
|
|
128
|
+
}
|
|
129
|
+
const homePath = options.homePath ?? homedir();
|
|
130
|
+
const nvmCandidate = findFirstExecutable(platform, getNvmVersionDirectories(homePath), executableNames);
|
|
131
|
+
const versionManagerCandidate = nvmCandidate ??
|
|
132
|
+
findFirstExecutable(platform, getBaseVersionManagerDirectories(platform, homePath), executableNames);
|
|
133
|
+
return versionManagerCandidate;
|
|
134
|
+
}
|
|
135
|
+
/** Resolve without conflating a launch fallback with an installed executable. */
|
|
136
|
+
export function resolveCliCommandDetailed(commandName, options = {}) {
|
|
137
|
+
const resolved = findCliCommand(commandName, options);
|
|
138
|
+
return resolved
|
|
139
|
+
? { command: resolved, found: true, path: resolved }
|
|
140
|
+
: { command: commandName, found: false };
|
|
141
|
+
}
|
|
142
|
+
export function resolveCliCommands(commandNames, options = {}) {
|
|
143
|
+
const platform = options.platform ?? process.platform;
|
|
144
|
+
const pathEnv = options.pathEnv ?? process.env.PATH ?? process.env.Path ?? null;
|
|
145
|
+
const pathDirectories = splitPath(pathEnv);
|
|
146
|
+
const homePath = options.homePath ?? homedir();
|
|
147
|
+
const installDirectories = [
|
|
148
|
+
...getNvmVersionDirectories(homePath),
|
|
149
|
+
...getBaseVersionManagerDirectories(platform, homePath)
|
|
150
|
+
];
|
|
151
|
+
const resolved = new Map();
|
|
152
|
+
for (const commandName of new Set(commandNames)) {
|
|
153
|
+
const executableNames = getExecutableNames(platform, commandName);
|
|
154
|
+
const pathCandidate = findFirstExecutable(platform, pathDirectories, executableNames);
|
|
155
|
+
const installCandidate = pathCandidate ?? findFirstExecutable(platform, installDirectories, executableNames);
|
|
156
|
+
resolved.set(commandName, installCandidate ?? commandName);
|
|
157
|
+
}
|
|
158
|
+
return resolved;
|
|
159
|
+
}
|
|
160
|
+
export function resolveCodexCommand(options = {}) {
|
|
161
|
+
return resolveCliCommand('codex', options);
|
|
162
|
+
}
|
|
163
|
+
export function resolveClaudeCommand(options = {}) {
|
|
164
|
+
return resolveCliCommand('claude', options);
|
|
165
|
+
}
|
|
166
|
+
// Why: Node-script CLIs need their version-manager sibling `node` on PATH.
|
|
167
|
+
export function getVersionManagerBinPaths(options = {}) {
|
|
168
|
+
const platform = options.platform ?? process.platform;
|
|
169
|
+
const homePath = options.homePath ?? homedir();
|
|
170
|
+
const nodeNames = getExecutableNames(platform, 'node');
|
|
171
|
+
return getVersionManagerDirectories(platform, homePath, nodeNames);
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=node-cli-command-resolution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-cli-command-resolution.js","sourceRoot":"","sources":["../../../src/shared/node-cli-command-resolution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClF,OAAO,EAAE,O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AmB,CAAC,UAAiC,EAAE;IACrE,OAAO,iBAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;AAC5C,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,UAAiC,EAAE;IACtE,OAAO,iBAAiB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;AAC7C,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,yBAAyB,CAAC,UAAiC,EAAE;IAC3E,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAA;IACrD,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,EAAE,CAAA;IAC9C,MAAM,SAAS,GAAG,kBAAkB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;IACtD,OAAO,4BAA4B,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAA;AACpE,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { AgentConfig } from '../config.js';
|
|
2
|
+
import type { DeviceCommand, HeartbeatResponse, ModelCatalogReport, RunFinishedReport, RunStartedReport } from '../types/protocol.js';
|
|
3
|
+
/**
|
|
4
|
+
* Plain HTTPS client for the echo_admin agent gateway. There is no
|
|
5
|
+
* long-lived connection: heartbeats and a long-poll for commands, plus one
|
|
6
|
+
* request per report. Every call has a timeout.
|
|
7
|
+
*/
|
|
8
|
+
export declare class GatewayError extends Error {
|
|
9
|
+
readonly status: number;
|
|
10
|
+
constructor(message: string, status: number);
|
|
11
|
+
/** The device token was revoked or the device was deleted. */
|
|
12
|
+
get unauthorized(): boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare class GatewayClient {
|
|
15
|
+
private readonly config;
|
|
16
|
+
constructor(config: AgentConfig);
|
|
17
|
+
private request;
|
|
18
|
+
heartbeat(body: {
|
|
19
|
+
agent_version: string;
|
|
20
|
+
hostname: string;
|
|
21
|
+
capabilities: unknown;
|
|
22
|
+
active_runs: string[];
|
|
23
|
+
model_catalogs?: ModelCatalogReport;
|
|
24
|
+
}): Promise<HeartbeatResponse>;
|
|
25
|
+
/** Long-poll: resolves when a command arrives or after `waitSeconds`. */
|
|
26
|
+
poll(waitSeconds: number, signal?: AbortSignal): Promise<DeviceCommand[]>;
|
|
27
|
+
commandResult(commandId: string, body: {
|
|
28
|
+
success: boolean;
|
|
29
|
+
result?: unknown;
|
|
30
|
+
error?: string;
|
|
31
|
+
session_key?: string;
|
|
32
|
+
agent_session_id?: string;
|
|
33
|
+
}): Promise<unknown>;
|
|
34
|
+
runStarted(runId: string, body: RunStartedReport): Promise<unknown>;
|
|
35
|
+
runFinished(runId: string, body: RunFinishedReport): Promise<{
|
|
36
|
+
accepted: boolean;
|
|
37
|
+
}>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plain HTTPS client for the echo_admin agent gateway. There is no
|
|
3
|
+
* long-lived connection: heartbeats and a long-poll for commands, plus one
|
|
4
|
+
* request per report. Every call has a timeout.
|
|
5
|
+
*/
|
|
6
|
+
export class GatewayError extends Error {
|
|
7
|
+
status;
|
|
8
|
+
constructor(message, status) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.status = status;
|
|
11
|
+
}
|
|
12
|
+
/** The device token was revoked or the device was deleted. */
|
|
13
|
+
get unauthorized() {
|
|
14
|
+
return this.status === 401;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export class GatewayClient {
|
|
18
|
+
config;
|
|
19
|
+
constructor(config) {
|
|
20
|
+
this.config = config;
|
|
21
|
+
}
|
|
22
|
+
async request(method, path, body, timeoutMs, signal) {
|
|
23
|
+
const controller = new AbortController();
|
|
24
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
25
|
+
const onAbort = () => controller.abort();
|
|
26
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
27
|
+
try {
|
|
28
|
+
const response = await fetch(`${this.config.serverUrl}/api/agent${path}`, {
|
|
29
|
+
method,
|
|
30
|
+
headers: {
|
|
31
|
+
authorization: `Bearer ${this.config.token}`,
|
|
32
|
+
...(body === undefined ? {} : { 'content-type': 'application/json' })
|
|
33
|
+
},
|
|
34
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
35
|
+
signal: controller.signal
|
|
36
|
+
});
|
|
37
|
+
const envelope = await response.json().catch(() => null);
|
|
38
|
+
if (!response.ok || !envelope?.success) {
|
|
39
|
+
throw new GatewayError(envelope?.message || `HTTP ${response.status}`, response.status);
|
|
40
|
+
}
|
|
41
|
+
return envelope.data;
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
if (error instanceof GatewayError)
|
|
45
|
+
throw error;
|
|
46
|
+
if (controller.signal.aborted && !signal?.aborted)
|
|
47
|
+
throw new GatewayError(`请求超时:${path}`, 0);
|
|
48
|
+
throw new GatewayError(error instanceof Error ? error.message : String(error), 0);
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
clearTimeout(timer);
|
|
52
|
+
signal?.removeEventListener('abort', onAbort);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
heartbeat(body) {
|
|
56
|
+
return this.request('POST', '/heartbeat', body, 15_000);
|
|
57
|
+
}
|
|
58
|
+
/** Long-poll: resolves when a command arrives or after `waitSeconds`. */
|
|
59
|
+
async poll(waitSeconds, signal) {
|
|
60
|
+
const data = await this.request('GET', `/commands?wait=${waitSeconds}`, undefined, (waitSeconds + 15) * 1_000, signal);
|
|
61
|
+
return data.items ?? [];
|
|
62
|
+
}
|
|
63
|
+
commandResult(commandId, body) {
|
|
64
|
+
return this.request('POST', `/commands/${encodeURIComponent(commandId)}/result`, body, 15_000);
|
|
65
|
+
}
|
|
66
|
+
runStarted(runId, body) {
|
|
67
|
+
return this.request('POST', `/runs/${encodeURIComponent(runId)}/started`, body, 15_000);
|
|
68
|
+
}
|
|
69
|
+
runFinished(runId, body) {
|
|
70
|
+
return this.request('POST', `/runs/${encodeURIComponent(runId)}/finished`, body, 15_000);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=gateway-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway-client.js","sourceRoot":"","sources":["../../../src/transport/gateway-client.ts"],"names":[],"mappings":"AAUA;;;;GAIG;AAEH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACC;IAAtC,YAAY,OAAe,EAAW,MAAc;QAClD,KAAK,CAAC,OAAO,CAAC,CAAA;QADsB,WAAM,GAAN,MAAM,CAAQ;IAEpD,CAAC;IAED,8DAA8D;IAC9D,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,MAAM,KAAK,GAAG,CAAA;IAC5B,CAAC;CACF;AAED,MAAM,OAAO,aAAa;IACK;IAA7B,YAA6B,MAAmB;QAAnB,WAAM,GAAN,MAAM,CAAa;IAAG,CAAC;IAE5C,KAAK,CAAC,OAAO,CAAI,MAAc,EAAE,IAAY,EAAE,IAAa,EAAE,SAAiB,EAAE,MAAoB;QAC3G,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAA;QACxC,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,SAAS,CAAC,CAAA;QAC7D,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,CAAA;QACxC,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;QAC1D,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,aAAa,IAAI,EAAE,EAAE;gBACxE,MAAM;gBACN,OAAO,EAAE;oBACP,aAAa,EAAE,UAAU,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE;oBAC5C,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,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AAI,CAAC,OAAO,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;IACzD,CAAC;IAED,yEAAyE;IACzE,KAAK,CAAC,IAAI,CAAC,WAAmB,EAAE,MAAoB;QAClD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAA6B,KAAK,EAAE,kBAAkB,WAAW,EAAE,EAAE,SAAS,EAAE,CAAC,WAAW,GAAG,EAAE,CAAC,GAAG,KAAK,EAAE,MAAM,CAAC,CAAA;QAClJ,OAAO,IAAI,CAAC,KAAK,IAAI,EAAE,CAAA;IACzB,CAAC;IAED,aAAa,CAAC,SAAiB,EAAE,IAA6G;QAC5I,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,aAAa,kBAAkB,CAAC,SAAS,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;IAChG,CAAC;IAED,UAAU,CAAC,KAAa,EAAE,IAAsB;QAC9C,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,SAAS,kBAAkB,CAAC,KAAK,CAAC,UAAU,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;IACzF,CAAC;IAED,WAAW,CAAC,KAAa,EAAE,IAAuB;QAChD,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,SAAS,kBAAkB,CAAC,KAAK,CAAC,WAAW,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;IAC1F,CAAC;CACF"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export type ApiEnvelope<T> = {
|
|
3
|
+
success: boolean;
|
|
4
|
+
message?: string;
|
|
5
|
+
data?: T;
|
|
6
|
+
};
|
|
7
|
+
export type EnrollResponse = {
|
|
8
|
+
device_id: string;
|
|
9
|
+
device_name: string;
|
|
10
|
+
token: string;
|
|
11
|
+
heartbeat_interval: number;
|
|
12
|
+
poll_wait: number;
|
|
13
|
+
};
|
|
14
|
+
export type ExecPolicy = {
|
|
15
|
+
enabled: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type DevicePolicy = {
|
|
18
|
+
script: ExecPolicy;
|
|
19
|
+
sql: ExecPolicy;
|
|
20
|
+
};
|
|
21
|
+
export declare const DEFAULT_POLICY: DevicePolicy;
|
|
22
|
+
export type HeartbeatResponse = {
|
|
23
|
+
device_id: string;
|
|
24
|
+
device_name: string;
|
|
25
|
+
policy: DevicePolicy;
|
|
26
|
+
server_time: number;
|
|
27
|
+
heartbeat_interval: number;
|
|
28
|
+
poll_wait: number;
|
|
29
|
+
/** Hash of the model catalogs the server stores for this device. */
|
|
30
|
+
model_catalog_hash?: string;
|
|
31
|
+
};
|
|
32
|
+
/** A command queued by the server (device_commands row). */
|
|
33
|
+
export type DeviceCommand = {
|
|
34
|
+
id: string;
|
|
35
|
+
device_id: string;
|
|
36
|
+
type: string;
|
|
37
|
+
payload: unknown;
|
|
38
|
+
workstation_id: string;
|
|
39
|
+
created_at: number;
|
|
40
|
+
};
|
|
41
|
+
export declare const RunStartPayloadSchema: z.ZodObject<{
|
|
42
|
+
run_id: z.ZodString;
|
|
43
|
+
workstation_id: z.ZodString;
|
|
44
|
+
workstation_name: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
45
|
+
agent_type: z.ZodString;
|
|
46
|
+
task_chain_id: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
47
|
+
message_id: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
48
|
+
prompt: z.ZodString;
|
|
49
|
+
session_id: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
50
|
+
model: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
51
|
+
reasoning_effort: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
52
|
+
workdir: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
53
|
+
}, z.core.$strip>;
|
|
54
|
+
export type RunStartPayload = z.infer<typeof RunStartPayloadSchema>;
|
|
55
|
+
export declare const RunCancelPayloadSchema: z.ZodObject<{
|
|
56
|
+
run_id: z.ZodString;
|
|
57
|
+
}, z.core.$strip>;
|
|
58
|
+
export declare const RunTailPayloadSchema: z.ZodObject<{
|
|
59
|
+
run_id: z.ZodOptional<z.ZodString>;
|
|
60
|
+
workstation_id: z.ZodOptional<z.ZodString>;
|
|
61
|
+
lines: z.ZodOptional<z.ZodNumber>;
|
|
62
|
+
before_cursor: z.ZodOptional<z.ZodNumber>;
|
|
63
|
+
}, z.core.$strip>;
|
|
64
|
+
export declare const ScriptRunPayloadSchema: z.ZodObject<{
|
|
65
|
+
cmd: z.ZodString;
|
|
66
|
+
workdir: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
67
|
+
timeout_s: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
68
|
+
policy: z.ZodOptional<z.ZodObject<{
|
|
69
|
+
script: z.ZodObject<{
|
|
70
|
+
enabled: z.ZodBoolean;
|
|
71
|
+
}, z.core.$strip>;
|
|
72
|
+
sql: z.ZodObject<{
|
|
73
|
+
enabled: z.ZodBoolean;
|
|
74
|
+
}, z.core.$strip>;
|
|
75
|
+
}, z.core.$strip>>;
|
|
76
|
+
}, z.core.$strip>;
|
|
77
|
+
export declare const SqlRunPayloadSchema: z.ZodObject<{
|
|
78
|
+
database_id: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
79
|
+
sql: z.ZodString;
|
|
80
|
+
timeout_s: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
81
|
+
policy: z.ZodOptional<z.ZodObject<{
|
|
82
|
+
script: z.ZodObject<{
|
|
83
|
+
enabled: z.ZodBoolean;
|
|
84
|
+
}, z.core.$strip>;
|
|
85
|
+
sql: z.ZodObject<{
|
|
86
|
+
enabled: z.ZodBoolean;
|
|
87
|
+
}, z.core.$strip>;
|
|
88
|
+
}, z.core.$strip>>;
|
|
89
|
+
}, z.core.$strip>;
|
|
90
|
+
export type RunFinishStatus = 'succeeded' | 'failed' | 'cancelled';
|
|
91
|
+
export type RunFinishedReport = {
|
|
92
|
+
status: RunFinishStatus;
|
|
93
|
+
exit_code?: number;
|
|
94
|
+
session_id?: string;
|
|
95
|
+
error?: string;
|
|
96
|
+
final_message?: string;
|
|
97
|
+
duration_ms: number;
|
|
98
|
+
};
|
|
99
|
+
export type RunStartedReport = {
|
|
100
|
+
pid?: number;
|
|
101
|
+
session_id?: string;
|
|
102
|
+
};
|
|
103
|
+
export type AgentCliModelCatalogEntry = {
|
|
104
|
+
id: string;
|
|
105
|
+
name: string;
|
|
106
|
+
description?: string;
|
|
107
|
+
default_reasoning_effort?: string;
|
|
108
|
+
supported_reasoning_efforts: string[];
|
|
109
|
+
};
|
|
110
|
+
export type AgentCliModelCatalog = {
|
|
111
|
+
agent_type: string;
|
|
112
|
+
default_model?: string;
|
|
113
|
+
default_reasoning_effort?: string;
|
|
114
|
+
fetched_at: string;
|
|
115
|
+
models: AgentCliModelCatalogEntry[];
|
|
116
|
+
};
|
|
117
|
+
/** One CLI's catalog, or why it could not be read. */
|
|
118
|
+
export type ModelCatalogReportItem = {
|
|
119
|
+
agent_type: string;
|
|
120
|
+
catalog?: AgentCliModelCatalog;
|
|
121
|
+
error?: string;
|
|
122
|
+
};
|
|
123
|
+
/** Every installed CLI's catalog, with a content hash for change detection. */
|
|
124
|
+
export type ModelCatalogReport = {
|
|
125
|
+
hash: string;
|
|
126
|
+
items: ModelCatalogReportItem[];
|
|
127
|
+
};
|
|
128
|
+
export declare const CliModelsPayloadSchema: z.ZodObject<{
|
|
129
|
+
agent_type: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
130
|
+
}, z.core.$strip>;
|
|
131
|
+
export declare const FsListPayloadSchema: z.ZodObject<{
|
|
132
|
+
path: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
133
|
+
}, z.core.$strip>;
|
|
134
|
+
export declare const WorkspaceScanPayloadSchema: z.ZodObject<{
|
|
135
|
+
root_path: z.ZodString;
|
|
136
|
+
max_depth: z.ZodOptional<z.ZodNumber>;
|
|
137
|
+
scan_roots: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
138
|
+
relative_path: z.ZodString;
|
|
139
|
+
max_depth: z.ZodNumber;
|
|
140
|
+
}, z.core.$strip>>>;
|
|
141
|
+
}, z.core.$strip>;
|
|
142
|
+
export type WorkspaceScanPayload = z.infer<typeof WorkspaceScanPayloadSchema>;
|
|
143
|
+
export declare const WorkspaceSyncPayloadSchema: z.ZodObject<{
|
|
144
|
+
root_path: z.ZodString;
|
|
145
|
+
directories: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
146
|
+
repos: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
147
|
+
relative_path: z.ZodString;
|
|
148
|
+
git_url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
149
|
+
branch: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
150
|
+
}, z.core.$strip>>>;
|
|
151
|
+
timeout_s: z.ZodOptional<z.ZodNumber>;
|
|
152
|
+
git_auth: z.ZodOptional<z.ZodObject<{
|
|
153
|
+
username: z.ZodString;
|
|
154
|
+
password: z.ZodString;
|
|
155
|
+
}, z.core.$strip>>;
|
|
156
|
+
}, z.core.$strip>;
|
|
157
|
+
export type WorkspaceSyncPayload = z.infer<typeof WorkspaceSyncPayloadSchema>;
|
|
158
|
+
export type WorkspaceNode = {
|
|
159
|
+
relative_path: string;
|
|
160
|
+
node_type: 'folder' | 'repo';
|
|
161
|
+
git_url?: string | null;
|
|
162
|
+
branch?: string | null;
|
|
163
|
+
commit_hash?: string | null;
|
|
164
|
+
};
|
|
165
|
+
export type WorkspaceOperationResult = {
|
|
166
|
+
relative_path: string;
|
|
167
|
+
status: 'created' | 'updated' | 'skipped' | 'failed';
|
|
168
|
+
kind?: 'directory' | 'repo';
|
|
169
|
+
action?: 'mkdir' | 'clone' | 'pull' | 'skip' | 'sync';
|
|
170
|
+
message?: string;
|
|
171
|
+
error?: string;
|
|
172
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const DEFAULT_POLICY = { script: { enabled: false }, sql: { enabled: false } };
|
|
3
|
+
export const RunStartPayloadSchema = z.object({
|
|
4
|
+
run_id: z.string().min(1).max(64),
|
|
5
|
+
workstation_id: z.string().min(1).max(64),
|
|
6
|
+
workstation_name: z.string().optional().default(''),
|
|
7
|
+
agent_type: z.string().min(1).max(40),
|
|
8
|
+
task_chain_id: z.string().optional().default(''),
|
|
9
|
+
message_id: z.string().optional().default(''),
|
|
10
|
+
prompt: z.string().min(1).max(512 * 1024),
|
|
11
|
+
session_id: z.string().max(200).optional().default(''),
|
|
12
|
+
model: z.string().max(100).optional().default(''),
|
|
13
|
+
reasoning_effort: z.string().max(40).optional().default(''),
|
|
14
|
+
workdir: z.string().max(4096).optional().default('')
|
|
15
|
+
});
|
|
16
|
+
export const RunCancelPayloadSchema = z.object({ run_id: z.string().min(1).max(64) });
|
|
17
|
+
export const RunTailPayloadSchema = z.object({
|
|
18
|
+
run_id: z.string().max(64).optional(),
|
|
19
|
+
workstation_id: z.string().max(64).optional(),
|
|
20
|
+
lines: z.number().int().positive().max(2_000).optional(),
|
|
21
|
+
before_cursor: z.number().int().min(0).optional()
|
|
22
|
+
});
|
|
23
|
+
export const ScriptRunPayloadSchema = z.object({
|
|
24
|
+
cmd: z.string().min(1).max(256 * 1024),
|
|
25
|
+
workdir: z.string().max(4096).optional().default(''),
|
|
26
|
+
timeout_s: z.number().int().positive().max(3_600).optional().default(60),
|
|
27
|
+
policy: z.object({ script: z.object({ enabled: z.boolean() }), sql: z.object({ enabled: z.boolean() }) }).optional()
|
|
28
|
+
});
|
|
29
|
+
export const SqlRunPayloadSchema = z.object({
|
|
30
|
+
database_id: z.string().max(64).optional().default(''),
|
|
31
|
+
sql: z.string().min(1).max(1024 * 1024),
|
|
32
|
+
timeout_s: z.number().int().positive().max(3_600).optional().default(60),
|
|
33
|
+
policy: z.object({ script: z.object({ enabled: z.boolean() }), sql: z.object({ enabled: z.boolean() }) }).optional()
|
|
34
|
+
});
|
|
35
|
+
export const CliModelsPayloadSchema = z.object({ agent_type: z.string().max(40).optional().default('') });
|
|
36
|
+
// ---- Device directories ----
|
|
37
|
+
const RelativePathSchema = z.string().min(1).max(500);
|
|
38
|
+
export const FsListPayloadSchema = z.object({ path: z.string().max(4096).optional().default('') });
|
|
39
|
+
export const WorkspaceScanPayloadSchema = z.object({
|
|
40
|
+
root_path: z.string().min(1).max(4096),
|
|
41
|
+
max_depth: z.number().int().positive().max(20).optional(),
|
|
42
|
+
scan_roots: z.array(z.object({ relative_path: RelativePathSchema, max_depth: z.number().int().positive().max(20) })).max(2_000).optional()
|
|
43
|
+
});
|
|
44
|
+
export const WorkspaceSyncPayloadSchema = z.object({
|
|
45
|
+
root_path: z.string().min(1).max(4096),
|
|
46
|
+
directories: z.array(RelativePathSchema).max(2_000).default([]),
|
|
47
|
+
repos: z.array(z.object({
|
|
48
|
+
relative_path: RelativePathSchema,
|
|
49
|
+
git_url: z.string().max(2_000).nullable().optional(),
|
|
50
|
+
branch: z.string().max(200).nullable().optional()
|
|
51
|
+
})).max(2_000).default([]),
|
|
52
|
+
timeout_s: z.number().int().positive().max(3_600).optional(),
|
|
53
|
+
git_auth: z.object({ username: z.string().min(1).max(500), password: z.string().min(1).max(4_096) }).optional()
|
|
54
|
+
});
|
|
55
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/types/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAkBvB,MAAM,CAAC,MAAM,cAAc,GAAiB,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,CAAA;AAuBnG,MAAM,CAAC,MAAM,qBAAqB,GAAG,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C,MAAM,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;QACpD,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;KAClD,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;IAC1B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE;IAC5D,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE;CAChH,CAAC,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type DirectoryEntry = {
|
|
2
|
+
name: string;
|
|
3
|
+
path: string;
|
|
4
|
+
hidden: boolean;
|
|
5
|
+
};
|
|
6
|
+
export type DirectoryListing = {
|
|
7
|
+
path: string;
|
|
8
|
+
parent_path: string | null;
|
|
9
|
+
directories: DirectoryEntry[];
|
|
10
|
+
files: DirectoryEntry[];
|
|
11
|
+
truncated: boolean;
|
|
12
|
+
places: Array<{
|
|
13
|
+
label: string;
|
|
14
|
+
path: string;
|
|
15
|
+
}>;
|
|
16
|
+
};
|
|
17
|
+
export declare function listDirectory(requested: string, allowedRoots: readonly string[]): Promise<DirectoryListing>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { readdir, realpath, stat } from 'node:fs/promises';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { dirname, parse, resolve } from 'node:path';
|
|
4
|
+
/**
|
|
5
|
+
* Read-only, one-level directory listing for the remote folder picker.
|
|
6
|
+
* Only names and paths leave the device, never file contents. Without a
|
|
7
|
+
* path it opens the home directory; `places` offers quick jumps.
|
|
8
|
+
*/
|
|
9
|
+
const MAX_ENTRIES = 1_000;
|
|
10
|
+
export async function listDirectory(requested, allowedRoots) {
|
|
11
|
+
const raw = requested.trim().replace(/^~(?=$|[\\/])/, homedir()) || homedir();
|
|
12
|
+
const directory = await realpath(resolve(raw)).catch(() => {
|
|
13
|
+
throw new Error(`目录不存在:${requested}`);
|
|
14
|
+
});
|
|
15
|
+
if (!(await stat(directory)).isDirectory())
|
|
16
|
+
throw new Error('这不是一个目录');
|
|
17
|
+
const entries = await readdir(directory, { withFileTypes: true }).catch((error) => {
|
|
18
|
+
throw new Error(error.code === 'EACCES' || error.code === 'EPERM' ? '没有权限读取这个目录' : error.message);
|
|
19
|
+
});
|
|
20
|
+
const byName = (a, b) => a.name.localeCompare(b.name, undefined, { sensitivity: 'base', numeric: true });
|
|
21
|
+
const directories = [];
|
|
22
|
+
const files = [];
|
|
23
|
+
for (const entry of entries) {
|
|
24
|
+
if (entry.isSymbolicLink())
|
|
25
|
+
continue;
|
|
26
|
+
const item = { name: entry.name, path: resolve(directory, entry.name), hidden: entry.name.startsWith('.') };
|
|
27
|
+
if (entry.isDirectory())
|
|
28
|
+
directories.push(item);
|
|
29
|
+
else if (entry.isFile())
|
|
30
|
+
files.push(item);
|
|
31
|
+
}
|
|
32
|
+
const parent = dirname(directory);
|
|
33
|
+
const places = [{ label: '主目录', path: homedir() }];
|
|
34
|
+
for (const root of allowedRoots)
|
|
35
|
+
if (root !== homedir())
|
|
36
|
+
places.push({ label: '允许的目录', path: root });
|
|
37
|
+
places.push({ label: '根目录', path: process.platform === 'win32' ? parse(directory).root : '/' });
|
|
38
|
+
return {
|
|
39
|
+
path: directory,
|
|
40
|
+
parent_path: parent === directory ? null : parent,
|
|
41
|
+
directories: directories.sort(byName).slice(0, MAX_ENTRIES),
|
|
42
|
+
files: files.sort(byName).slice(0, MAX_ENTRIES),
|
|
43
|
+
truncated: directories.length > MAX_ENTRIES || files.length > MAX_ENTRIES,
|
|
44
|
+
places
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=directory-browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directory-browser.js","sourceRoot":"","sources":["../../../src/workspace/directory-browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnD;;;;GAIG;AACH,MAAM,WAAW,GAAG,KAAK,CAAA;AAYzB,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,SAAiB,EAAE,YAA+B;IACpF,MAAM,GAAG,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,eAAe,EAAE,OAAO,EAAE,CAAC,IAAI,OAAO,EAAE,CAAA;IAC7E,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;QACxD,MAAM,IAAI,KAAK,CAAC,SAAS,SAAS,EAAE,CAAC,CAAA;IACvC,CAAC,CAAC,CAAA;IACF,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,CAAA;IACtE,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,SAAS,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,KAA4B,EAAE,EAAE;QACvG,MAAM,I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AE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;IACpG,MAAM,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAA;IAC/F,OAAO;QACL,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM;QACjD,WAAW,EAAE,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC;QAC3D,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC;QAC/C,SAAS,EAAE,WAAW,CAAC,MAAM,GAAG,WAAW,IAAI,KAAK,CAAC,MAAM,GAAG,WAAW;QACzE,MAAM;KACP,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type AgentConfig } from '../config.js';
|
|
2
|
+
import type { DiagnosticLogger } from '../logging/diagnostic-log.js';
|
|
3
|
+
import type { WorkspaceNode, WorkspaceOperationResult, WorkspaceScanPayload, WorkspaceSyncPayload } from '../types/protocol.js';
|
|
4
|
+
export type WorkspaceScanResult = {
|
|
5
|
+
root_path: string;
|
|
6
|
+
nodes: WorkspaceNode[];
|
|
7
|
+
truncated: boolean;
|
|
8
|
+
duration_ms: number;
|
|
9
|
+
};
|
|
10
|
+
export type WorkspaceSyncResult = {
|
|
11
|
+
root_path: string;
|
|
12
|
+
results: WorkspaceOperationResult[];
|
|
13
|
+
error?: string;
|
|
14
|
+
duration_ms: number;
|
|
15
|
+
};
|
|
16
|
+
export declare class WorkspaceManager {
|
|
17
|
+
private readonly config;
|
|
18
|
+
private readonly logger;
|
|
19
|
+
constructor(config: AgentConfig, logger: DiagnosticLogger);
|
|
20
|
+
/**
|
|
21
|
+
* Reads folders and Git repositories below the root. The root becomes an
|
|
22
|
+
* allowed CLI work directory: the user chose it for this device.
|
|
23
|
+
*/
|
|
24
|
+
scan(request: WorkspaceScanPayload): Promise<WorkspaceScanResult>;
|
|
25
|
+
/** Creates missing folders, clones missing repos, fast-forwards clean ones. */
|
|
26
|
+
sync(request: WorkspaceSyncPayload): Promise<WorkspaceSyncResult>;
|
|
27
|
+
private validateRootPath;
|
|
28
|
+
private syncTree;
|
|
29
|
+
private syncRepository;
|
|
30
|
+
private scanTree;
|
|
31
|
+
private readGitMetadata;
|
|
32
|
+
private isGitRepository;
|
|
33
|
+
private cleanRelativePath;
|
|
34
|
+
private isSafeRelativePath;
|
|
35
|
+
private resolveWithinRoot;
|
|
36
|
+
private runGit;
|
|
37
|
+
private createGitAuthEnvironment;
|
|
38
|
+
private message;
|
|
39
|
+
}
|
|
40
|
+
/** Keeps the lines that explain a git failure, dropping progress noise. */
|
|
41
|
+
export declare function gitErrorSummary(stderr: string): string;
|