vanspod 0.5.4 → 0.5.6
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/README.md +4 -4
- package/dist/classroomApp.js +1 -0
- package/dist/localCommands.js +13 -2
- package/dist/localToolApproval.js +7 -7
- package/dist/localTools.js +64 -23
- package/dist/page.js +4 -1
- package/dist/projectPath.js +61 -43
- package/dist/remoteAgentLog.js +1 -0
- package/dist/remoteAgentLogView.js +8 -2
- package/dist/secretFile.js +126 -0
- package/dist/trayChannel.js +1 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/scripts/tray.ps1 +17 -2
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ npm run dist
|
|
|
38
38
|
npm pack --pack-destination dist
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
exe 產物為 `dist/VansPod.exe`,本機套件為 `dist/vanspod-0.5.
|
|
41
|
+
exe 產物為 `dist/VansPod.exe`,本機套件為 `dist/vanspod-0.5.6.tgz`;可在 Windows 用 `npm install -g <套件路徑>` 安裝測試。圖片、favicon、系統匣與移除腳本均包含在發佈產物中。更新 logo 後執行 `powershell.exe -NoProfile -File scripts/build-icon.ps1` 重建多尺寸 Windows icon。
|
|
42
42
|
|
|
43
43
|
exe 發佈管道為本專案 GitHub Releases,npm 為公開 registry 的 [`vanspod`](https://www.npmjs.com/package/vanspod) 套件。更新時不要執行完整移除,否則會清除課堂資料。
|
|
44
44
|
|
|
@@ -46,12 +46,12 @@ exe 發佈管道為本專案 GitHub Releases,npm 為公開 registry 的 [`vans
|
|
|
46
46
|
|
|
47
47
|
一般 push 不發佈;推送 `v*` tag 會在 Windows runner 安裝 Node.js 24、檢查型別、執行測試、打包並驗證 exe/npm 生命週期,全部通過後才建立 GitHub Release,最後發佈 npm 套件。學生從 Release 下載 `VansPod.exe`,同頁提供 `SHA256SUMS.txt`。Release 另附 brotli 壓縮的 `VansPod.exe.br`(約三分之一大小),程式內更新只下載這份,解壓後再比對 `VansPod.exe` 的 SHA-256;SHA256SUMS 沒列出它的舊版 Release 則下載完整 exe。
|
|
48
48
|
|
|
49
|
-
發版前同步 `package.json`、`package-lock.json` 與 `src/version.ts` 的版本;tag 必須等於 `v` 加版本號,否則流程失敗。以 `0.5.
|
|
49
|
+
發版前同步 `package.json`、`package-lock.json` 與 `src/version.ts` 的版本;tag 必須等於 `v` 加版本號,否則流程失敗。以 `0.5.6` 為例:
|
|
50
50
|
|
|
51
51
|
```powershell
|
|
52
52
|
git push origin master
|
|
53
|
-
git tag -a v0.5.
|
|
54
|
-
git push origin v0.5.
|
|
53
|
+
git tag -a v0.5.6 -m "VansPod 0.5.6"
|
|
54
|
+
git push origin v0.5.6
|
|
55
55
|
```
|
|
56
56
|
|
|
57
57
|
新版本使用新的版本號與 tag。相同 tag 的 Actions 重跑會更新該 Release 的產物。
|
package/dist/classroomApp.js
CHANGED
|
@@ -184,6 +184,7 @@ class ClassroomApp {
|
|
|
184
184
|
secondsLeft: Math.max(0, Math.ceil((shown.expiresAt - Date.now()) / 1000)),
|
|
185
185
|
waiting: shown.waiting,
|
|
186
186
|
...(shown.exception ? { exception: localToolApproval_1.AUTO_APPROVAL_EXCEPTION_LABELS[shown.exception] } : {}),
|
|
187
|
+
...(shown.request.outside ? { outside: true } : {}),
|
|
187
188
|
};
|
|
188
189
|
}
|
|
189
190
|
const auto = this.deps.approvals?.autoApproval();
|
package/dist/localCommands.js
CHANGED
|
@@ -95,11 +95,22 @@ let nextRun = 0;
|
|
|
95
95
|
*/
|
|
96
96
|
async function runBashCommand(bash, command, folder, signal, options) {
|
|
97
97
|
const timeoutMs = options.timeoutMs;
|
|
98
|
+
// The log shows the command as running from here, so 停止 must work at once:
|
|
99
|
+
// a stop that comes while VansPod reads the PATH keeps Git Bash from starting.
|
|
100
|
+
let stopNow;
|
|
101
|
+
let stoppedEarly = false;
|
|
102
|
+
options.stoppable(() => { if (stopNow)
|
|
103
|
+
stopNow();
|
|
104
|
+
else
|
|
105
|
+
stoppedEarly = true; });
|
|
98
106
|
const env = await (0, systemPath_1.envWithRegistryPath)();
|
|
99
|
-
// From here to the spawn nothing waits, so a listed running command can always be stopped.
|
|
100
107
|
const stdout = collector();
|
|
101
108
|
const stderr = collector();
|
|
102
109
|
const ended = await new Promise(resolve => {
|
|
110
|
+
if (stoppedEarly || signal.aborted) {
|
|
111
|
+
resolve({ why: stoppedEarly ? "stopped" : "cancelled" });
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
103
114
|
let why;
|
|
104
115
|
let settled = false;
|
|
105
116
|
// The command and the pid file go in the environment, so no Windows argument quoting or globbing changes them.
|
|
@@ -136,7 +147,7 @@ async function runBashCommand(bash, command, folder, signal, options) {
|
|
|
136
147
|
child.stderr.on("data", (chunk) => collect(stderr, chunk));
|
|
137
148
|
child.on("error", error => finish({ error: error.message }));
|
|
138
149
|
child.on("close", code => finish(code === null ? {} : { code }));
|
|
139
|
-
|
|
150
|
+
stopNow = () => end("stopped");
|
|
140
151
|
});
|
|
141
152
|
if (ended.error) {
|
|
142
153
|
options.ended({});
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.APPROVAL_TIMEOUT_MS = exports.AUTO_APPROVAL_EXCEPTION_LABELS = void 0;
|
|
3
|
+
exports.APPROVAL_TIMEOUT_MS = exports.AUTO_APPROVAL_EXCEPTION_LABELS = exports.OUTSIDE_PROJECT_FOLDER_LABEL = void 0;
|
|
4
4
|
exports.askApproval = askApproval;
|
|
5
5
|
exports.approvalRefusal = approvalRefusal;
|
|
6
6
|
exports.autoApprovalException = autoApprovalException;
|
|
7
7
|
exports.createApprovalQueue = createApprovalQueue;
|
|
8
|
-
const
|
|
8
|
+
const secretFile_1 = require("./secretFile");
|
|
9
|
+
/** The mark of a path outside the Project Folder, on the Approval Popup, the page and the Remote Agent Log. */
|
|
10
|
+
exports.OUTSIDE_PROJECT_FOLDER_LABEL = "專案資料夾外";
|
|
9
11
|
/**
|
|
10
12
|
* Asks `approver` and turns anything but approval into the reply for the agent.
|
|
11
13
|
* `notDone` says what did not happen, for example "沒有寫入檔案".
|
|
@@ -27,8 +29,6 @@ exports.AUTO_APPROVAL_EXCEPTION_LABELS = {
|
|
|
27
29
|
secret_file: "碰到機密檔案",
|
|
28
30
|
delete_outside: "刪除專案資料夾以外的檔案",
|
|
29
31
|
};
|
|
30
|
-
// The words of a command, split at spaces, quotes and shell punctuation.
|
|
31
|
-
const commandWords = (command) => command.split(/[\s'"`=<>|;&()]+/).filter(Boolean);
|
|
32
32
|
// A target outside the Project Folder: absolute, the home folder, the parent folder, or a drive letter.
|
|
33
33
|
const OUTSIDE_TARGET = /^(\/|~|\$HOME\b|\$\{HOME\}|\.\.|[A-Za-z]:)/;
|
|
34
34
|
// The parts of a command that run on their own: split at `;`, `&&`, `||`, `|`, `&`, line ends, `( )`, `$(` and backquotes.
|
|
@@ -51,16 +51,16 @@ function deletesOutside(command) {
|
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
53
|
* The Auto Approval Exception of a request, or undefined. The rules match text, so they catch only clear cases (ADR 0014).
|
|
54
|
-
* The Secret File check is the one that `read_file` uses:
|
|
54
|
+
* The Secret File check is the one that `read_file` uses (secretFile.ts): a secret file name or a folder that is wholly secret, and for `write_file` also its full path and a private key in the text.
|
|
55
55
|
*/
|
|
56
56
|
function autoApprovalException(request) {
|
|
57
57
|
if (request.tool === "write_file") {
|
|
58
|
-
const secret = (0,
|
|
58
|
+
const secret = (0, secretFile_1.isSecretPath)(request.target) || (request.absolute !== undefined && (0, secretFile_1.isSecretPath)(request.absolute)) || (request.contents ?? []).some(secretFile_1.hasPrivateKey);
|
|
59
59
|
return secret ? "secret_file" : undefined;
|
|
60
60
|
}
|
|
61
61
|
if (request.tool !== "bash")
|
|
62
62
|
return undefined;
|
|
63
|
-
if (
|
|
63
|
+
if ((0, secretFile_1.commandNamesSecretFile)(request.target))
|
|
64
64
|
return "secret_file";
|
|
65
65
|
return deletesOutside(request.target) ? "delete_outside" : undefined;
|
|
66
66
|
}
|
package/dist/localTools.js
CHANGED
|
@@ -16,6 +16,7 @@ const localCommands_1 = require("./localCommands");
|
|
|
16
16
|
const localToolApproval_1 = require("./localToolApproval");
|
|
17
17
|
const projectPath_1 = require("./projectPath");
|
|
18
18
|
const remoteAgentLog_1 = require("./remoteAgentLog");
|
|
19
|
+
const secretFile_1 = require("./secretFile");
|
|
19
20
|
const saveImage_1 = require("./saveImage");
|
|
20
21
|
const systemPath_1 = require("./systemPath");
|
|
21
22
|
const windowsEnvironmentSystem_1 = require("./windowsEnvironmentSystem");
|
|
@@ -54,28 +55,62 @@ async function localStatus(options) {
|
|
|
54
55
|
result.python = python ?? null;
|
|
55
56
|
return { ok: true, result };
|
|
56
57
|
}
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Resolves the path of a `list_files`, `read_file`, or `write_file` call. A path outside the Project Folder
|
|
60
|
+
* gets the 「專案資料夾外」 mark and its full path in the Remote Agent Log, whatever the call ends with.
|
|
61
|
+
*/
|
|
62
|
+
async function resolveCallPath(projectFolder, requested, context) {
|
|
63
|
+
const target = await (0, projectPath_1.resolveLocalPath)(projectFolder, requested);
|
|
64
|
+
if (target.ok && !target.inside)
|
|
65
|
+
context.call.outside(target.display);
|
|
66
|
+
return target;
|
|
67
|
+
}
|
|
68
|
+
const NOT_READ = "沒有讀取";
|
|
69
|
+
/**
|
|
70
|
+
* A read outside the Project Folder waits for a Local Tool Approval (ADR 0016); inside, it needs none.
|
|
71
|
+
* The tool asks before it looks at the path, so a denied read says nothing about what is there.
|
|
72
|
+
*/
|
|
73
|
+
async function approveRead(tool, target, projectFolder, signal, context) {
|
|
74
|
+
if (target.inside)
|
|
75
|
+
return undefined;
|
|
76
|
+
const title = tool === "read_file" ? `讀取檔案 ${target.display}` : `列出資料夾 ${target.display}`;
|
|
77
|
+
return (0, localToolApproval_1.askApproval)(context.approver, { tool, title, body: target.display, target: target.display, folder: projectFolder, outside: true }, signal, NOT_READ);
|
|
78
|
+
}
|
|
79
|
+
async function listFiles(projectFolder, args, signal, context) {
|
|
80
|
+
const target = await resolveCallPath(projectFolder, args.path ?? ".", context);
|
|
59
81
|
if (!target.ok)
|
|
60
82
|
return target;
|
|
83
|
+
// A folder that is wholly secret, or a folder in one, is not listed (ADR 0016). A normal folder still shows Secret File names.
|
|
84
|
+
if ((0, secretFile_1.isInWhollySecretFolder)(target.absolute))
|
|
85
|
+
return (0, secretFile_1.whollySecretFolderRefusal)(target.display);
|
|
86
|
+
const refusal = await approveRead("list_files", target, projectFolder, signal, context);
|
|
87
|
+
if (refusal)
|
|
88
|
+
return refusal;
|
|
89
|
+
if (!target.exists)
|
|
90
|
+
return (0, projectPath_1.notFoundRefusal)(target);
|
|
61
91
|
if (!(await promises_1.default.stat(target.absolute)).isDirectory()) {
|
|
62
|
-
return { ok: false, error: "invalid_arguments", message: `「${target.
|
|
92
|
+
return { ok: false, error: "invalid_arguments", message: `「${target.display}」是檔案,不是資料夾。請用 read_file 讀取它。` };
|
|
63
93
|
}
|
|
64
94
|
const { entries, truncated } = await topLevelEntries(target.absolute);
|
|
65
|
-
return { ok: true, result: truncated ? { path: target.
|
|
95
|
+
return { ok: true, result: truncated ? { path: target.display, entries, truncated: true } : { path: target.display, entries } };
|
|
66
96
|
}
|
|
67
97
|
exports.MAX_READ_CHARS = 30_000;
|
|
68
98
|
// A UTF-8 character has at most 4 bytes, so this many bytes always hold MAX_READ_CHARS characters.
|
|
69
99
|
const MAX_READ_BYTES = exports.MAX_READ_CHARS * 4;
|
|
70
|
-
async function readFile(projectFolder, args) {
|
|
71
|
-
const target = await (
|
|
100
|
+
async function readFile(projectFolder, args, signal, context) {
|
|
101
|
+
const target = await resolveCallPath(projectFolder, args.path, context);
|
|
72
102
|
if (!target.ok)
|
|
73
103
|
return target;
|
|
74
|
-
if ((0,
|
|
75
|
-
return (0,
|
|
104
|
+
if ((0, secretFile_1.isSecretPath)(target.display) || (0, secretFile_1.isSecretPath)(target.absolute))
|
|
105
|
+
return (0, secretFile_1.secretFileRefusal)(target.display);
|
|
106
|
+
const refusal = await approveRead("read_file", target, projectFolder, signal, context);
|
|
107
|
+
if (refusal)
|
|
108
|
+
return refusal;
|
|
109
|
+
if (!target.exists)
|
|
110
|
+
return (0, projectPath_1.notFoundRefusal)(target);
|
|
76
111
|
const stat = await promises_1.default.stat(target.absolute);
|
|
77
112
|
if (stat.isDirectory()) {
|
|
78
|
-
return { ok: false, error: "invalid_arguments", message: `「${target.
|
|
113
|
+
return { ok: false, error: "invalid_arguments", message: `「${target.display}」是資料夾,不是檔案。請用 list_files 看裡面有什麼。` };
|
|
79
114
|
}
|
|
80
115
|
const file = await promises_1.default.open(target.absolute, "r");
|
|
81
116
|
let bytes;
|
|
@@ -88,19 +123,19 @@ async function readFile(projectFolder, args) {
|
|
|
88
123
|
await file.close();
|
|
89
124
|
}
|
|
90
125
|
if (bytes.includes(0)) {
|
|
91
|
-
return { ok: false, error: "failed", message: `「${target.
|
|
126
|
+
return { ok: false, error: "failed", message: `「${target.display}」不是文字檔,read_file 只能讀取文字檔。` };
|
|
92
127
|
}
|
|
93
128
|
const text = new TextDecoder("utf-8").decode(bytes);
|
|
94
|
-
if ((0,
|
|
95
|
-
return (0,
|
|
129
|
+
if ((0, secretFile_1.hasPrivateKey)(text))
|
|
130
|
+
return (0, secretFile_1.secretFileRefusal)(target.display);
|
|
96
131
|
const chars = Array.from(text);
|
|
97
132
|
const truncated = chars.length > exports.MAX_READ_CHARS || stat.size > bytes.length;
|
|
98
133
|
if (!truncated)
|
|
99
|
-
return { ok: true, result: { path: target.
|
|
134
|
+
return { ok: true, result: { path: target.display, content: text, truncated: false } };
|
|
100
135
|
return {
|
|
101
136
|
ok: true,
|
|
102
137
|
result: {
|
|
103
|
-
path: target.
|
|
138
|
+
path: target.display,
|
|
104
139
|
content: chars.slice(0, exports.MAX_READ_CHARS).join(""),
|
|
105
140
|
truncated: true,
|
|
106
141
|
note: `檔案太長,只回傳前 ${exports.MAX_READ_CHARS.toLocaleString("en-US")} 個字元(檔案共 ${stat.size} 位元組)。`,
|
|
@@ -112,18 +147,18 @@ async function writeFile(projectFolder, args, signal, context) {
|
|
|
112
147
|
if (typeof args.content !== "string")
|
|
113
148
|
return { ok: false, error: "invalid_arguments", message: "content 必須是要寫入的文字。" };
|
|
114
149
|
const content = args.content;
|
|
115
|
-
const target = await (
|
|
150
|
+
const target = await resolveCallPath(projectFolder, args.path, context);
|
|
116
151
|
if (!target.ok)
|
|
117
152
|
return target;
|
|
118
|
-
let title = `寫入新檔案 ${target.
|
|
153
|
+
let title = `寫入新檔案 ${target.display}`;
|
|
119
154
|
let body = content;
|
|
120
155
|
let before;
|
|
121
156
|
if (target.exists) {
|
|
122
157
|
if ((await promises_1.default.stat(target.absolute)).isDirectory()) {
|
|
123
|
-
return { ok: false, error: "invalid_arguments", message: `「${target.
|
|
158
|
+
return { ok: false, error: "invalid_arguments", message: `「${target.display}」是資料夾,不能寫成檔案。` };
|
|
124
159
|
}
|
|
125
160
|
const old = await promises_1.default.readFile(target.absolute);
|
|
126
|
-
title = `修改檔案 ${target.
|
|
161
|
+
title = `修改檔案 ${target.display}`;
|
|
127
162
|
before = old.includes(0) ? undefined : old.toString("utf8");
|
|
128
163
|
body = before === undefined
|
|
129
164
|
? `(原本不是文字檔,整個檔案會換成下面的內容)\n${content}`
|
|
@@ -134,21 +169,27 @@ async function writeFile(projectFolder, args, signal, context) {
|
|
|
134
169
|
context.call.wrote(content, undefined, true);
|
|
135
170
|
}
|
|
136
171
|
const contents = before === undefined ? [content] : [content, before];
|
|
137
|
-
const refusal = await (0, localToolApproval_1.askApproval)(context.approver, {
|
|
172
|
+
const refusal = await (0, localToolApproval_1.askApproval)(context.approver, {
|
|
173
|
+
tool: "write_file", title, body, target: target.display, absolute: target.absolute, folder: projectFolder, contents,
|
|
174
|
+
...(target.inside ? {} : { outside: true }),
|
|
175
|
+
}, signal, NOT_WRITTEN);
|
|
138
176
|
if (refusal)
|
|
139
177
|
return refusal;
|
|
140
|
-
// Resolve again:
|
|
141
|
-
const now = await (0, projectPath_1.
|
|
178
|
+
// Resolve again: a link may have changed while the student decided. Write only where the student approved.
|
|
179
|
+
const now = await (0, projectPath_1.resolveLocalPath)(projectFolder, args.path);
|
|
142
180
|
if (!now.ok)
|
|
143
181
|
return now;
|
|
182
|
+
if (now.absolute !== target.absolute) {
|
|
183
|
+
return { ok: false, error: "failed", message: `「${target.display}」在學生確認時改到了別的位置,${NOT_WRITTEN}。` };
|
|
184
|
+
}
|
|
144
185
|
try {
|
|
145
186
|
await promises_1.default.mkdir(node_path_1.default.dirname(now.absolute), { recursive: true });
|
|
146
187
|
await promises_1.default.writeFile(now.absolute, content, "utf8");
|
|
147
188
|
}
|
|
148
189
|
catch (error) {
|
|
149
|
-
return { ok: false, error: "failed", message: `無法寫入「${now.
|
|
190
|
+
return { ok: false, error: "failed", message: `無法寫入「${now.display}」:${error instanceof Error ? error.message : "原因不明"}。` };
|
|
150
191
|
}
|
|
151
|
-
return { ok: true, result: { path: now.
|
|
192
|
+
return { ok: true, result: { path: now.display, created: !now.exists } };
|
|
152
193
|
}
|
|
153
194
|
/** Add a Project Folder tool here. */
|
|
154
195
|
const PROJECT_TOOLS = {
|
package/dist/page.js
CHANGED
|
@@ -229,9 +229,10 @@ function approvalBlock(approval, auto) {
|
|
|
229
229
|
return NO_APPROVAL;
|
|
230
230
|
const waiting = approval.waiting > 0 ? `<span class="remote-chip local-approval-queue">還有 ${approval.waiting} 個在排隊</span>` : "";
|
|
231
231
|
const exception = auto && approval.exception;
|
|
232
|
+
const outside = approval.outside ? `<span class="remote-chip local-approval-outside">${localToolApproval_1.OUTSIDE_PROJECT_FOLDER_LABEL}</span>` : "";
|
|
232
233
|
return `<section class="tile local-approval${exception ? " is-exception" : ""}" role="group" aria-label="Local Tool 確認" data-local-approval data-approval-key="${(0, html_1.escapeHtml)(approvalKey(approval, auto))}">`
|
|
233
234
|
+ (exception ? `<p class="local-approval-exception">${BOLT}自動允許期間仍要確認:<b>${(0, html_1.escapeHtml)(exception)}</b></p>` : "")
|
|
234
|
-
+ `<div class="local-approval-head"><p class="local-approval-title">Agent 想要:<strong>${(0, html_1.escapeHtml)(approval.title)}</strong></p><code>${(0, html_1.escapeHtml)(approval.tool)}</code>${waiting}</div>`
|
|
235
|
+
+ `<div class="local-approval-head"><p class="local-approval-title">Agent 想要:<strong>${(0, html_1.escapeHtml)(approval.title)}</strong></p><code>${(0, html_1.escapeHtml)(approval.tool)}</code>${outside}${waiting}</div>`
|
|
235
236
|
+ `<p class="hint">電腦:${(0, html_1.escapeHtml)(approval.device)} 資料夾:${(0, html_1.escapeHtml)(approval.folder)}</p>`
|
|
236
237
|
+ approvalBodyHtml(approval)
|
|
237
238
|
+ `<div class="local-approval-timer"><span data-approval-bar style="width: ${approvalBarWidth(approval)}"></span></div>`
|
|
@@ -1431,6 +1432,7 @@ const AUTO_APPROVAL_DIALOG = `<dialog class="auto-dialog" data-auto-dialog aria-
|
|
|
1431
1432
|
+ `<h3>${BOLT}打開自動允許(<span data-auto-dialog-label>10 分鐘</span>)</h3>`
|
|
1432
1433
|
+ `<p>自動允許期間,Agent 可以不經過你,直接執行指令、寫入檔案和儲存圖片。</p>`
|
|
1433
1434
|
+ `<p class="auto-dialog-warn">如果你的 Agent 會讀網頁或電子郵件,那些內容可能藏著給 Agent 的指令。</p>`
|
|
1435
|
+
+ `<p class="auto-dialog-warn">Agent 可以不問你就讀取這台電腦上的檔案(機密檔案除外),並把內容送到遠端。</p>`
|
|
1434
1436
|
+ `<p class="hint">下面這兩種情況仍然會問你:</p><ul class="hint"><li>碰到機密檔案,例如 <code>.env</code>、私密金鑰</li><li>刪除專案資料夾以外的檔案</li></ul>`
|
|
1435
1437
|
+ `<p class="hint">排隊中的確認也會一起允許。你隨時可以按「停止自動允許」。</p>`
|
|
1436
1438
|
+ `<div class="auto-dialog-actions"><button type="button" data-auto-dialog-cancel>取消</button><button type="submit" class="auto-dialog-ok">確定打開</button></div></form></dialog>`;
|
|
@@ -1459,6 +1461,7 @@ const REMOTE_AGENT_STYLES = `
|
|
|
1459
1461
|
.local-approval-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
|
1460
1462
|
.local-approval-title { margin: 0; font-size: 15px; overflow-wrap: anywhere; }
|
|
1461
1463
|
.local-approval-queue { margin-left: auto; }
|
|
1464
|
+
.local-approval-outside { color: light-dark(#b45309, #fbbf24); border-color: color-mix(in srgb, light-dark(#b45309, #fbbf24) 45%, transparent); }
|
|
1462
1465
|
.local-approval-body { margin: 0; max-height: 16rem; overflow: auto; padding: 8px 10px; background: var(--input); border-radius: 6px; font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
1463
1466
|
main button.local-approval-full { align-self: flex-start; min-height: 0; background: none; color: var(--accent); padding: 0; text-decoration: underline; }
|
|
1464
1467
|
.local-approval-timer { height: 4px; border-radius: 999px; background: var(--modes); overflow: hidden; }
|
package/dist/projectPath.js
CHANGED
|
@@ -3,14 +3,60 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.expandPath = expandPath;
|
|
7
|
+
exports.resolveLocalPath = resolveLocalPath;
|
|
8
|
+
exports.notFoundRefusal = notFoundRefusal;
|
|
6
9
|
exports.resolveProjectPath = resolveProjectPath;
|
|
7
|
-
|
|
8
|
-
exports.hasPrivateKey = hasPrivateKey;
|
|
9
|
-
exports.secretFileRefusal = secretFileRefusal;
|
|
10
|
-
// The Project Folder boundary for the Local Tools (ADR 0013).
|
|
10
|
+
// The path resolver for the Local Tools (ADR 0013, ADR 0016).
|
|
11
11
|
// `list_files`, `read_file`, and `write_file` resolve every path here before they touch the disk.
|
|
12
|
+
// A path can be anywhere on the computer; a relative path starts at the Project Folder.
|
|
12
13
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
14
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
13
15
|
const node_path_1 = __importDefault(require("node:path"));
|
|
16
|
+
/**
|
|
17
|
+
* Expands the two path forms that Node.js does not know (ADR 0016): `~/...` and, on Windows, Git Bash `/c/...`.
|
|
18
|
+
* `C:\...` and `C:/...` need nothing. A relative path stays relative, so it starts at the Project Folder.
|
|
19
|
+
* The Secret File check uses this expansion too.
|
|
20
|
+
*/
|
|
21
|
+
function expandPath(requested) {
|
|
22
|
+
const home = /^~(?=$|[\\/])/;
|
|
23
|
+
if (home.test(requested))
|
|
24
|
+
return node_path_1.default.join(node_os_1.default.homedir(), requested.slice(1));
|
|
25
|
+
if (process.platform === "win32") {
|
|
26
|
+
const gitBash = /^\/([A-Za-z])(?=$|\/)/.exec(requested);
|
|
27
|
+
if (gitBash)
|
|
28
|
+
return `${gitBash[1].toUpperCase()}:/${requested.slice(2)}`;
|
|
29
|
+
}
|
|
30
|
+
return requested;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Resolves `requested` from the Project Folder, in any of the four path forms, and says whether it is
|
|
34
|
+
* inside the Project Folder. It follows links as far as the path exists; the rest is lexical.
|
|
35
|
+
* It does not refuse a path that is outside or that does not exist, so a tool can ask the student first.
|
|
36
|
+
*/
|
|
37
|
+
async function resolveLocalPath(projectFolder, requested) {
|
|
38
|
+
if (typeof requested !== "string" || requested.trim() === "") {
|
|
39
|
+
return { ok: false, error: "invalid_arguments", message: "path 必須是路徑文字。相對路徑從專案資料夾開始算。" };
|
|
40
|
+
}
|
|
41
|
+
const root = node_path_1.default.resolve(projectFolder);
|
|
42
|
+
let realRoot;
|
|
43
|
+
try {
|
|
44
|
+
realRoot = await promises_1.default.realpath(root);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return { ok: false, error: "not_found", message: "VansPod 讀不到專案資料夾,它可能已被移動或刪除。請在 VansPod 重新選擇專案資料夾。" };
|
|
48
|
+
}
|
|
49
|
+
const lexical = node_path_1.default.resolve(root, expandPath(requested));
|
|
50
|
+
const real = await realTarget(lexical);
|
|
51
|
+
const isInside = inside(realRoot, real);
|
|
52
|
+
const fromRoot = inside(root, lexical) ? node_path_1.default.relative(root, lexical) : node_path_1.default.relative(realRoot, real);
|
|
53
|
+
const display = isInside ? fromRoot.split(node_path_1.default.sep).join("/") || "." : real;
|
|
54
|
+
return { ok: true, absolute: real, display, inside: isInside, exists: await exists(lexical) };
|
|
55
|
+
}
|
|
56
|
+
/** The reply for a path where nothing exists. */
|
|
57
|
+
function notFoundRefusal(target) {
|
|
58
|
+
return { ok: false, error: "not_found", message: target.inside ? `專案資料夾裡沒有「${target.display}」。` : `這台電腦上沒有「${target.display}」。` };
|
|
59
|
+
}
|
|
14
60
|
function inside(folder, target) {
|
|
15
61
|
const relative = node_path_1.default.relative(folder, target);
|
|
16
62
|
return relative === "" || (relative.split(node_path_1.default.sep)[0] !== ".." && !node_path_1.default.isAbsolute(relative));
|
|
@@ -42,45 +88,17 @@ async function realTarget(target) {
|
|
|
42
88
|
}
|
|
43
89
|
}
|
|
44
90
|
/**
|
|
45
|
-
* Resolves `requested`
|
|
46
|
-
*
|
|
91
|
+
* Resolves `requested` like `resolveLocalPath`, and refuses it when it is outside the Project Folder.
|
|
92
|
+
* `save_image` still stays in the Project Folder (its images/ folder).
|
|
93
|
+
* Without `allowMissing`, a path that does not exist is `not_found`.
|
|
47
94
|
*/
|
|
48
95
|
async function resolveProjectPath(projectFolder, requested, options = {}) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
let realRoot;
|
|
58
|
-
try {
|
|
59
|
-
realRoot = await promises_1.default.realpath(root);
|
|
60
|
-
}
|
|
61
|
-
catch {
|
|
62
|
-
return { ok: false, error: "not_found", message: "VansPod 讀不到專案資料夾,它可能已被移動或刪除。請在 VansPod 重新選擇專案資料夾。" };
|
|
63
|
-
}
|
|
64
|
-
const real = await realTarget(lexical);
|
|
65
|
-
if (!inside(realRoot, real))
|
|
66
|
-
return outside;
|
|
67
|
-
const found = await exists(lexical);
|
|
68
|
-
if (!found && !options.allowMissing)
|
|
69
|
-
return { ok: false, error: "not_found", message: `專案資料夾裡沒有「${requested}」。` };
|
|
70
|
-
const relative = node_path_1.default.relative(root, lexical).split(node_path_1.default.sep).join("/") || ".";
|
|
71
|
-
return { ok: true, absolute: real, relative, exists: found };
|
|
72
|
-
}
|
|
73
|
-
const SSH_KEY_NAMES = /^id_(rsa|dsa|ecdsa|ed25519)(_sk)?$/;
|
|
74
|
-
/** A secret file by its name: `.env`, `.env.*`, `.dev.vars`, `*.pem`, `*.key`, or an SSH private key. */
|
|
75
|
-
function isSecretFileName(name) {
|
|
76
|
-
const lower = node_path_1.default.basename(name).toLowerCase();
|
|
77
|
-
return lower === ".env" || lower.startsWith(".env.") || lower === ".dev.vars"
|
|
78
|
-
|| lower.endsWith(".pem") || lower.endsWith(".key") || SSH_KEY_NAMES.test(lower);
|
|
79
|
-
}
|
|
80
|
-
/** A secret file by its content: a PEM or OpenSSH private key block, whatever the file name is. */
|
|
81
|
-
function hasPrivateKey(text) {
|
|
82
|
-
return /-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----/.test(text);
|
|
83
|
-
}
|
|
84
|
-
function secretFileRefusal(requested) {
|
|
85
|
-
return { ok: false, error: "secret_file", message: `「${requested}」是機密檔案(例如金鑰或密碼設定),Local Tool 不會讀取它。` };
|
|
96
|
+
const target = await resolveLocalPath(projectFolder, requested);
|
|
97
|
+
if (!target.ok)
|
|
98
|
+
return target;
|
|
99
|
+
if (!target.inside)
|
|
100
|
+
return { ok: false, error: "outside_project_folder", message: `「${String(requested)}」在專案資料夾外面,這個 Local Tool 只能用專案資料夾裡的檔案。` };
|
|
101
|
+
if (!target.exists && !options.allowMissing)
|
|
102
|
+
return { ok: false, error: "not_found", message: `專案資料夾裡沒有「${String(requested)}」。` };
|
|
103
|
+
return { ok: true, absolute: target.absolute, relative: target.display, exists: target.exists };
|
|
86
104
|
}
|
package/dist/remoteAgentLog.js
CHANGED
|
@@ -80,6 +80,7 @@ function createRemoteAgentLog(options = {}) {
|
|
|
80
80
|
notify();
|
|
81
81
|
const logCall = {
|
|
82
82
|
target(next) { entry.target = cutText(next); notify(); },
|
|
83
|
+
outside(fullPath) { entry.target = cutText(fullPath); entry.outside = true; notify(); },
|
|
83
84
|
async ask(approver, request, signal) {
|
|
84
85
|
entry.state = "waiting";
|
|
85
86
|
notify();
|
|
@@ -13,6 +13,7 @@ exports.logEntryResponse = logEntryResponse;
|
|
|
13
13
|
const html_1 = require("./html");
|
|
14
14
|
const lineChanges_1 = require("./lineChanges");
|
|
15
15
|
const localCommands_1 = require("./localCommands");
|
|
16
|
+
const localToolApproval_1 = require("./localToolApproval");
|
|
16
17
|
const remoteAgentLog_1 = require("./remoteAgentLog");
|
|
17
18
|
const TOOL_LABELS = {
|
|
18
19
|
local_status: "查看狀態",
|
|
@@ -65,6 +66,10 @@ function badge(entry) {
|
|
|
65
66
|
})();
|
|
66
67
|
return `<span class="log-badge ${tone}">${(0, html_1.escapeHtml)(text)}</span>`;
|
|
67
68
|
}
|
|
69
|
+
/** The 「專案資料夾外」 mark of a call outside the Project Folder (ADR 0016), or "". */
|
|
70
|
+
function outsideTag(entry) {
|
|
71
|
+
return entry.outside ? `<span class="log-outside">${localToolApproval_1.OUTSIDE_PROJECT_FOLDER_LABEL}</span>` : "";
|
|
72
|
+
}
|
|
68
73
|
function approvalTag(entry) {
|
|
69
74
|
return `<span class="log-approval ${entry.approval}">${(0, html_1.escapeHtml)(remoteAgentLog_1.APPROVAL_METHOD_LABELS[entry.approval])}</span>`;
|
|
70
75
|
}
|
|
@@ -81,7 +86,7 @@ function row(entry, selected) {
|
|
|
81
86
|
return `<button type="button" class="log-row" data-log-entry="${(0, html_1.escapeHtml)(entry.id)}" data-entry-key="${(0, html_1.escapeHtml)(entryKey(entry))}"`
|
|
82
87
|
+ ` data-approval="${(0, html_1.escapeHtml)(entry.approval)}" data-tool-group="${(0, html_1.escapeHtml)(toolGroup(entry.tool))}" data-log-filters="${(0, html_1.escapeHtml)(filters)}" aria-selected="${selected}">`
|
|
83
88
|
+ `<span class="log-name">${(0, html_1.escapeHtml)(toolLabel(entry.tool))}</span>`
|
|
84
|
-
+ `<span class="log-right">${badge(entry)}<span>${(0, html_1.escapeHtml)(time(entry.startedAt))}</span></span>`
|
|
89
|
+
+ `<span class="log-right">${outsideTag(entry)}${badge(entry)}<span>${(0, html_1.escapeHtml)(time(entry.startedAt))}</span></span>`
|
|
85
90
|
+ `<span class="log-target">${(0, html_1.escapeHtml)(Array.from(target).slice(0, 200).join(""))}</span></button>`;
|
|
86
91
|
}
|
|
87
92
|
/** The list. The newest entry is chosen until the student picks another one. */
|
|
@@ -208,7 +213,7 @@ function logDetailBlock(entry) {
|
|
|
208
213
|
+ (entry.tool === "local_status" ? "" : `<dt>${targetName}</dt><dd>${(0, html_1.escapeHtml)(entry.target || "—")}</dd>`)
|
|
209
214
|
+ `<dt>時間</dt><dd>${(0, html_1.escapeHtml)(time(entry.startedAt))}</dd></dl>`;
|
|
210
215
|
return `<section class="tile log-detail" data-log-detail data-entry-id="${(0, html_1.escapeHtml)(entry.id)}" data-entry-key="${(0, html_1.escapeHtml)(entryKey(entry))}">`
|
|
211
|
-
+ `<h3>${(0, html_1.escapeHtml)(toolLabel(entry.tool))}<span class="log-detail-tags">${approvalTag(entry)}${badge(entry)}${stop}</span></h3>`
|
|
216
|
+
+ `<h3>${(0, html_1.escapeHtml)(toolLabel(entry.tool))}<span class="log-detail-tags">${outsideTag(entry)}${approvalTag(entry)}${badge(entry)}${stop}</span></h3>`
|
|
212
217
|
+ `${facts}${toolDetail(entry)}</section>`;
|
|
213
218
|
}
|
|
214
219
|
/** The list and the details, side by side. The details show the newest entry first. */
|
|
@@ -400,6 +405,7 @@ exports.REMOTE_AGENT_LOG_STYLES = `
|
|
|
400
405
|
.log-badge.err { color: var(--log-err); background: color-mix(in srgb, var(--log-err) 13%, transparent); }
|
|
401
406
|
.log-badge.warn { color: var(--log-warn); background: color-mix(in srgb, var(--log-warn) 14%, transparent); }
|
|
402
407
|
.log-badge.run { color: var(--accent); background: color-mix(in srgb, var(--accent) 15%, transparent); }
|
|
408
|
+
.log-outside { font-size: 11px; color: var(--log-warn); border: 1px solid color-mix(in srgb, var(--log-warn) 45%, transparent); border-radius: 4px; padding: 0 5px; white-space: nowrap; }
|
|
403
409
|
.log-approval { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; white-space: nowrap; }
|
|
404
410
|
.remote-main .log-detail { max-height: var(--log-height, 40rem); min-height: 0; box-sizing: border-box; overflow: auto; }
|
|
405
411
|
.log-detail h3 { margin: 0; font-size: 16px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isSecretFileName = isSecretFileName;
|
|
7
|
+
exports.hasPrivateKey = hasPrivateKey;
|
|
8
|
+
exports.isInWhollySecretFolder = isInWhollySecretFolder;
|
|
9
|
+
exports.isSecretPath = isSecretPath;
|
|
10
|
+
exports.commandNamesSecretFile = commandNamesSecretFile;
|
|
11
|
+
exports.secretFileRefusal = secretFileRefusal;
|
|
12
|
+
exports.whollySecretFolderRefusal = whollySecretFolderRefusal;
|
|
13
|
+
// The one Secret File definition for every Local Tool (ADR 0014, ADR 0016).
|
|
14
|
+
// A Secret File is a single file (`.env`, a private key, `.git-credentials`) or any file in a folder
|
|
15
|
+
// that is wholly secret. These folders are the real ones of this computer: `~/.ssh/`, the GitHub CLI
|
|
16
|
+
// config folder, the Chrome and Edge user data folders, and the VansPod data folders. A folder with
|
|
17
|
+
// the same name in another place is a normal folder. The check matches text, so it catches only clear cases.
|
|
18
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
19
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
20
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
21
|
+
const projectPath_1 = require("./projectPath");
|
|
22
|
+
const SSH_KEY_NAMES = /^id_(rsa|dsa|ecdsa|ed25519)(_sk)?$/;
|
|
23
|
+
/** A secret file by its name: `.env`, `.env.*`, `.dev.vars`, `*.pem`, `*.key`, an SSH private key, or `.git-credentials`. */
|
|
24
|
+
function isSecretFileName(name) {
|
|
25
|
+
const lower = node_path_1.default.basename(name).toLowerCase();
|
|
26
|
+
return lower === ".env" || lower.startsWith(".env.") || lower === ".dev.vars" || lower === ".git-credentials"
|
|
27
|
+
|| lower.endsWith(".pem") || lower.endsWith(".key") || SSH_KEY_NAMES.test(lower);
|
|
28
|
+
}
|
|
29
|
+
/** A secret file by its content: a PEM or OpenSSH private key block, whatever the file name is. */
|
|
30
|
+
function hasPrivateKey(text) {
|
|
31
|
+
return /-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----/.test(text);
|
|
32
|
+
}
|
|
33
|
+
const roaming = () => process.env.APPDATA || node_path_1.default.join(node_os_1.default.homedir(), "AppData", "Roaming");
|
|
34
|
+
const local = () => process.env.LOCALAPPDATA || node_path_1.default.join(node_os_1.default.homedir(), "AppData", "Local");
|
|
35
|
+
/** The one list of the folders that are wholly secret on this computer. It reads the environment at each call. */
|
|
36
|
+
function whollySecretFolders() {
|
|
37
|
+
const home = node_os_1.default.homedir();
|
|
38
|
+
const folders = [
|
|
39
|
+
node_path_1.default.join(home, ".ssh"),
|
|
40
|
+
node_path_1.default.join(roaming(), "GitHub CLI"),
|
|
41
|
+
node_path_1.default.join(process.env.XDG_CONFIG_HOME || node_path_1.default.join(home, ".config"), "gh"),
|
|
42
|
+
node_path_1.default.join(local(), "Google", "Chrome", "User Data"),
|
|
43
|
+
node_path_1.default.join(local(), "Microsoft", "Edge", "User Data"),
|
|
44
|
+
node_path_1.default.join(home, ".vanspod"),
|
|
45
|
+
node_path_1.default.join(local(), "VansPod"),
|
|
46
|
+
];
|
|
47
|
+
if (process.env.GH_CONFIG_DIR)
|
|
48
|
+
folders.push(process.env.GH_CONFIG_DIR);
|
|
49
|
+
// A temp or home folder can have a short or linked form; the Local Tools compare the real path.
|
|
50
|
+
return [...folders, ...folders.map(realPrefix)].map(comparable);
|
|
51
|
+
}
|
|
52
|
+
/** Follows links in the longest part of `folder` that exists, then adds the rest unchanged. */
|
|
53
|
+
function realPrefix(folder) {
|
|
54
|
+
const rest = [];
|
|
55
|
+
let current = folder;
|
|
56
|
+
for (;;) {
|
|
57
|
+
try {
|
|
58
|
+
return node_path_1.default.join(node_fs_1.default.realpathSync.native(current), ...rest.reverse());
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
const parent = node_path_1.default.dirname(current);
|
|
62
|
+
if (parent === current)
|
|
63
|
+
return folder;
|
|
64
|
+
rest.push(node_path_1.default.basename(current));
|
|
65
|
+
current = parent;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** A path in one form for text comparison: "/" between parts, no "/" at the end, lower case on Windows. */
|
|
70
|
+
function comparable(text) {
|
|
71
|
+
const slashed = node_path_1.default.resolve(text).replace(/\\/g, "/").replace(/\/+$/, "");
|
|
72
|
+
return process.platform === "win32" ? slashed.toLowerCase() : slashed;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* True when `pathText` is a folder that is wholly secret, or is in one. It does not check the file name.
|
|
76
|
+
* `pathText` can use `~` or Git Bash `/c/`. A relative path is never in one: it starts at the Project Folder.
|
|
77
|
+
*/
|
|
78
|
+
function isInWhollySecretFolder(pathText) {
|
|
79
|
+
const expanded = (0, projectPath_1.expandPath)(pathText);
|
|
80
|
+
if (!node_path_1.default.isAbsolute(expanded))
|
|
81
|
+
return false;
|
|
82
|
+
const target = comparable(expanded);
|
|
83
|
+
return whollySecretFolders().some(folder => target === folder || target.startsWith(`${folder}/`));
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The Secret File check by path, for every Local Tool: a secret file name, or a path in a folder
|
|
87
|
+
* that is wholly secret. `pathText` can be a full path, a relative path, or a path with `~`.
|
|
88
|
+
*/
|
|
89
|
+
function isSecretPath(pathText) {
|
|
90
|
+
return isSecretFileName(pathText) || isInWhollySecretFolder(pathText);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Expands the home folder and app-data names that a `bash` command can use: `$HOME`, `${HOME}`,
|
|
94
|
+
* `$USERPROFILE`, `%USERPROFILE%`, `$APPDATA`, `%APPDATA%`, `$LOCALAPPDATA`, `%LOCALAPPDATA%`.
|
|
95
|
+
* `expandPath` then expands `~` and Git Bash `/c/`.
|
|
96
|
+
*/
|
|
97
|
+
function expandShellPath(word) {
|
|
98
|
+
const home = node_os_1.default.homedir();
|
|
99
|
+
return (0, projectPath_1.expandPath)(word
|
|
100
|
+
.replace(/^(\$HOME|\$\{HOME\}|\$USERPROFILE|\$\{USERPROFILE\}|%USERPROFILE%)(?=$|[\\/])/i, home)
|
|
101
|
+
.replace(/^(\$APPDATA|\$\{APPDATA\}|%APPDATA%)(?=$|[\\/])/i, roaming())
|
|
102
|
+
.replace(/^(\$LOCALAPPDATA|\$\{LOCALAPPDATA\}|%LOCALAPPDATA%)(?=$|[\\/])/i, local()));
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The words of a command that can be a path: the words split at spaces, quotes and shell punctuation,
|
|
106
|
+
* the text in each pair of quotes, and a word with `\ ` in it. So a path can have spaces in it.
|
|
107
|
+
*/
|
|
108
|
+
function pathWords(command) {
|
|
109
|
+
const words = command.split(/[\s'"`=<>|;&()]+/).filter(Boolean);
|
|
110
|
+
const quoted = [...command.matchAll(/"([^"]+)"|'([^']+)'/g)].map(match => match[1] ?? match[2]);
|
|
111
|
+
const escaped = [...command.matchAll(/(?:\\ |[^\s'"`=<>|;&()])+/g)].map(match => match[0]).filter(word => word.includes("\\ ")).map(word => word.replace(/\\ /g, " "));
|
|
112
|
+
return [...words, ...quoted, ...escaped];
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* True when a `bash` command names a Secret File: a word with a secret file name, or a path word
|
|
116
|
+
* (`~/...`, `$HOME/...`, `%APPDATA%\...`, a full path, or `/c/...`) in a folder that is wholly secret.
|
|
117
|
+
*/
|
|
118
|
+
function commandNamesSecretFile(command) {
|
|
119
|
+
return pathWords(command).some(word => isSecretFileName(word) || isInWhollySecretFolder(expandShellPath(word)));
|
|
120
|
+
}
|
|
121
|
+
function secretFileRefusal(requested) {
|
|
122
|
+
return { ok: false, error: "secret_file", message: `「${requested}」是機密檔案(例如金鑰或密碼設定),Local Tool 不會讀取它。` };
|
|
123
|
+
}
|
|
124
|
+
function whollySecretFolderRefusal(requested) {
|
|
125
|
+
return { ok: false, error: "secret_file", message: `「${requested}」是整個算機密的資料夾(例如金鑰或登入資料),裡面都是機密檔案,list_files 不會列出它。` };
|
|
126
|
+
}
|
package/dist/trayChannel.js
CHANGED
package/dist/version.js
CHANGED
package/package.json
CHANGED
package/scripts/tray.ps1
CHANGED
|
@@ -211,6 +211,7 @@ if ($script:mascot) {
|
|
|
211
211
|
$textLeft = 64
|
|
212
212
|
}
|
|
213
213
|
$autoColor = [System.Drawing.Color]::FromArgb(124, 58, 237)
|
|
214
|
+
$outsideColor = [System.Drawing.Color]::FromArgb(180, 83, 9)
|
|
214
215
|
$script:heading = New-Object System.Windows.Forms.Label
|
|
215
216
|
$script:heading.Text = "Agent 想要使用這台電腦"
|
|
216
217
|
$script:heading.Font = $bold
|
|
@@ -282,10 +283,17 @@ $reminderWarn.Font = New-Object System.Drawing.Font("Microsoft JhengHei UI", 9,
|
|
|
282
283
|
$reminderWarn.ForeColor = [System.Drawing.Color]::FromArgb(192, 54, 44)
|
|
283
284
|
$reminderWarn.SetBounds(12, 80, 376, 36)
|
|
284
285
|
$script:reminder.Controls.Add($reminderWarn)
|
|
286
|
+
# ADR 0016: Local Tools can read the whole computer, so the reminder names the read risk.
|
|
287
|
+
$reminderReadWarn = New-Object System.Windows.Forms.Label
|
|
288
|
+
$reminderReadWarn.Text = "Agent 可以不問你就讀取這台電腦上的檔案(機密檔案除外),並把內容送到遠端。"
|
|
289
|
+
$reminderReadWarn.Font = $reminderWarn.Font
|
|
290
|
+
$reminderReadWarn.ForeColor = $reminderWarn.ForeColor
|
|
291
|
+
$reminderReadWarn.SetBounds(12, 120, 376, 36)
|
|
292
|
+
$script:reminder.Controls.Add($reminderReadWarn)
|
|
285
293
|
$reminderExceptions = New-Object System.Windows.Forms.Label
|
|
286
294
|
$reminderExceptions.Text = "下面這兩種情況仍然會問你:`r`n・碰到機密檔案,例如 .env、私密金鑰`r`n・刪除專案資料夾以外的檔案`r`n`r`n排隊中的確認也會一起允許。你隨時可以按「停止自動允許」。"
|
|
287
295
|
$reminderExceptions.ForeColor = [System.Drawing.Color]::FromArgb(90, 90, 90)
|
|
288
|
-
$reminderExceptions.SetBounds(12,
|
|
296
|
+
$reminderExceptions.SetBounds(12, 160, 376, 100)
|
|
289
297
|
$script:reminder.Controls.Add($reminderExceptions)
|
|
290
298
|
$reminderCancel = New-Object VansPodTray.MouseOnlyButton
|
|
291
299
|
$reminderCancel.Text = "取消"
|
|
@@ -384,7 +392,14 @@ function Show-State($state) {
|
|
|
384
392
|
if ($approval.id -ne $script:shownId) {
|
|
385
393
|
$script:shownId = [string]$approval.id
|
|
386
394
|
$script:deadline = [DateTime]::UtcNow.AddSeconds([int]$approval.secondsLeft)
|
|
387
|
-
|
|
395
|
+
# 位置在 Project Folder 以外(ADR 0016):標題前標上「專案資料夾外」,並換成醒目的顏色。
|
|
396
|
+
if ($approval.outside) {
|
|
397
|
+
$script:titleLabel.Text = "【專案資料夾外】" + [string]$approval.title
|
|
398
|
+
$script:titleLabel.ForeColor = $outsideColor
|
|
399
|
+
} else {
|
|
400
|
+
$script:titleLabel.Text = [string]$approval.title
|
|
401
|
+
$script:titleLabel.ForeColor = [System.Drawing.SystemColors]::ControlText
|
|
402
|
+
}
|
|
388
403
|
$script:bodyBox.Text = ([string]$approval.body) -replace "`r?`n", "`r`n"
|
|
389
404
|
$script:whereLabel.Text = "電腦:$($approval.device)`r`n資料夾:$($approval.folder)"
|
|
390
405
|
Set-Buttons $true
|