vanspod 0.5.5 → 0.5.7

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 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.5.tgz`;可在 Windows 用 `npm install -g <套件路徑>` 安裝測試。圖片、favicon、系統匣與移除腳本均包含在發佈產物中。更新 logo 後執行 `powershell.exe -NoProfile -File scripts/build-icon.ps1` 重建多尺寸 Windows icon。
41
+ exe 產物為 `dist/VansPod.exe`,本機套件為 `dist/vanspod-0.5.7.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.5` 為例:
49
+ 發版前同步 `package.json`、`package-lock.json` 與 `src/version.ts` 的版本;tag 必須等於 `v` 加版本號,否則流程失敗。以 `0.5.7` 為例:
50
50
 
51
51
  ```powershell
52
52
  git push origin master
53
- git tag -a v0.5.5 -m "VansPod 0.5.5"
54
- git push origin v0.5.5
53
+ git tag -a v0.5.7 -m "VansPod 0.5.7"
54
+ git push origin v0.5.7
55
55
  ```
56
56
 
57
57
  新版本使用新的版本號與 tag。相同 tag 的 Actions 重跑會更新該 Release 的產物。
@@ -19,13 +19,14 @@ exports.CONNECTION_CANCELLED = "連線已取消";
19
19
  const CONNECTION_FAILED = "連線失敗,請再按一次「連線」。";
20
20
  const CLIENT_ROUTE_OF = { codex: "codex", claude: "claudeCode", vscode: "vsCodeChat" };
21
21
  // 新工具加在最後,不改既有 id。
22
- exports.ENVIRONMENT_TOOLS = ["uv", "git", "node", "pwsh", "vscode"];
22
+ exports.ENVIRONMENT_TOOLS = ["uv", "git", "node", "pwsh", "vscode", "gh"];
23
23
  exports.ENVIRONMENT_LABEL = {
24
24
  uv: "uv",
25
25
  git: "git",
26
26
  node: "Node.js",
27
27
  pwsh: "PowerShell 7",
28
28
  vscode: "VS Code",
29
+ gh: "GitHub CLI",
29
30
  };
30
31
  exports.AUTO_APPROVAL_DURATIONS = {
31
32
  "10": { label: "10 分鐘", ms: 10 * 60_000 },
@@ -184,6 +185,7 @@ class ClassroomApp {
184
185
  secondsLeft: Math.max(0, Math.ceil((shown.expiresAt - Date.now()) / 1000)),
185
186
  waiting: shown.waiting,
186
187
  ...(shown.exception ? { exception: localToolApproval_1.AUTO_APPROVAL_EXCEPTION_LABELS[shown.exception] } : {}),
188
+ ...(shown.request.outside ? { outside: true } : {}),
187
189
  };
188
190
  }
189
191
  const auto = this.deps.approvals?.autoApproval();
@@ -3,10 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.environmentIcons = void 0;
4
4
  // Brand icons from https://github.com/simple-icons/simple-icons (CC0-1.0).
5
5
  // PowerShell from 11.15.0; VS Code (visualstudiocode) from 7.21.0, before it was removed; other icons from develop.
6
+ // GitHub CLI uses the github icon.
6
7
  exports.environmentIcons = {
7
8
  "uv": "<svg aria-hidden=\"true\" fill=\"currentColor\" viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"m0 .1058.0504 11.9496.0403 9.5597c.0055 1.3199 1.08 2.3854 2.4 2.3798l9.5596-.0403 5.9749-.0252.6075-.0026c1.316-.0056 2.3799-1.0963 2.3799-2.4123h1.0946v2.3894L24 23.9042 23.8992.005 12.9056.0513l.0463 9.5245v5.9637h-1.9583L11.04 9.584 10.9936.0594Z\"/></svg>",
8
9
  "git": "<svg aria-hidden=\"true\" fill=\"currentColor\" viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M13.09 23.549a1.54 1.54 0 0 1-2.18 0L.451 13.089a1.54 1.54 0 0 1 0-2.179l7.191-7.19 2.733 2.733a1.85 1.85 0 0 0 .964 2.326v6.66a1.849 1.849 0 1 0 1.54 0V8.957l2.508 2.508a1.85 1.85 0 1 0 1.09-1.09l-2.634-2.634a1.85 1.85 0 0 0-2.378-2.377L8.73 2.63 10.91.451a1.54 1.54 0 0 1 2.179 0l10.459 10.46a1.54 1.54 0 0 1 0 2.179z\"/></svg>",
9
10
  "node": "<svg aria-hidden=\"true\" fill=\"currentColor\" viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M11.998,24c-0.321,0-0.641-0.084-0.922-0.247l-2.936-1.737c-0.438-0.245-0.224-0.332-0.08-0.383 c0.585-0.203,0.703-0.25,1.328-0.604c0.065-0.037,0.151-0.023,0.218,0.017l2.256,1.339c0.082,0.045,0.197,0.045,0.272,0l8.795-5.076 c0.082-0.047,0.134-0.141,0.134-0.238V6.921c0-0.099-0.053-0.192-0.137-0.242l-8.791-5.072c-0.081-0.047-0.189-0.047-0.271,0 L3.075,6.68C2.99,6.729,2.936,6.825,2.936,6.921v10.15c0,0.097,0.054,0.189,0.139,0.235l2.409,1.392 c1.307,0.654,2.108-0.116,2.108-0.89V7.787c0-0.142,0.114-0.253,0.256-0.253h1.115c0.139,0,0.255,0.112,0.255,0.253v10.021 c0,1.745-0.95,2.745-2.604,2.745c-0.508,0-0.909,0-2.026-0.551L2.28,18.675c-0.57-0.329-0.922-0.945-0.922-1.604V6.921 c0-0.659,0.353-1.275,0.922-1.603l8.795-5.082c0.557-0.315,1.296-0.315,1.848,0l8.794,5.082c0.57,0.329,0.924,0.944,0.924,1.603 v10.15c0,0.659-0.354,1.273-0.924,1.604l-8.794,5.078C12.643,23.916,12.324,24,11.998,24z M19.099,13.993 c0-1.9-1.284-2.406-3.987-2.763c-2.731-0.361-3.009-0.548-3.009-1.187c0-0.528,0.235-1.233,2.258-1.233 c1.807,0,2.473,0.389,2.747,1.607c0.024,0.115,0.129,0.199,0.247,0.199h1.141c0.071,0,0.138-0.031,0.186-0.081 c0.048-0.054,0.074-0.123,0.067-0.196c-0.177-2.098-1.571-3.076-4.388-3.076c-2.508,0-4.004,1.058-4.004,2.833 c0,1.925,1.488,2.457,3.895,2.695c2.88,0.282,3.103,0.703,3.103,1.269c0,0.983-0.789,1.402-2.642,1.402 c-2.327,0-2.839-0.584-3.011-1.742c-0.02-0.124-0.126-0.215-0.253-0.215h-1.137c-0.141,0-0.254,0.112-0.254,0.253 c0,1.482,0.806,3.248,4.655,3.248C17.501,17.007,19.099,15.91,19.099,13.993z\"/></svg>",
10
11
  "pwsh": "<svg aria-hidden=\"true\" fill=\"currentColor\" viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M23.181 2.974c.568 0 .923.463.792 1.035l-3.659 15.982c-.13.572-.697 1.035-1.265 1.035H.819c-.568 0-.923-.463-.792-1.035L3.686 4.009c.13-.572.697-1.035 1.265-1.035zm-8.375 9.346c.251-.394.227-.905-.09-1.243L9.122 5.125c-.38-.404-1.037-.407-1.466-.003-.429.402-.468 1.056-.088 1.46l4.662 4.96v.11l-7.42 5.374c-.45.327-.533.977-.187 1.453.346.476.991.597 1.44.27l8.229-5.91c.28-.196.438-.365.514-.52zm-2.796 4.399a.928.928 0 00-.934.923c0 .51.418.923.934.923h4.433a.928.928 0 00.934-.923.928.928 0 00-.934-.923z\"/></svg>",
11
- "vscode": "<svg aria-hidden=\"true\" fill=\"currentColor\" viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M23.15 2.587L18.21.21a1.494 1.494 0 0 0-1.705.29l-9.46 8.63-4.12-3.128a.999.999 0 0 0-1.276.057L.327 7.261A1 1 0 0 0 .326 8.74L3.899 12 .326 15.26a1 1 0 0 0 .001 1.479L1.65 17.94a.999.999 0 0 0 1.276.057l4.12-3.128 9.46 8.63a1.492 1.492 0 0 0 1.704.29l4.942-2.377A1.5 1.5 0 0 0 24 20.06V3.939a1.5 1.5 0 0 0-.85-1.352zm-5.146 14.861L10.826 12l7.178-5.448v10.896z\"/></svg>"
12
+ "vscode": "<svg aria-hidden=\"true\" fill=\"currentColor\" viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M23.15 2.587L18.21.21a1.494 1.494 0 0 0-1.705.29l-9.46 8.63-4.12-3.128a.999.999 0 0 0-1.276.057L.327 7.261A1 1 0 0 0 .326 8.74L3.899 12 .326 15.26a1 1 0 0 0 .001 1.479L1.65 17.94a.999.999 0 0 0 1.276.057l4.12-3.128 9.46 8.63a1.492 1.492 0 0 0 1.704.29l4.942-2.377A1.5 1.5 0 0 0 24 20.06V3.939a1.5 1.5 0 0 0-.85-1.352zm-5.146 14.861L10.826 12l7.178-5.448v10.896z\"/></svg>",
13
+ "gh": "<svg aria-hidden=\"true\" fill=\"currentColor\" viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12\"/></svg>"
12
14
  };
@@ -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 projectPath_1 = require("./projectPath");
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: the file name, and for `write_file` also a private key in the text.
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, projectPath_1.isSecretFileName)(request.target) || (request.contents ?? []).some(projectPath_1.hasPrivateKey);
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 (commandWords(request.target).some(projectPath_1.isSecretFileName))
63
+ if ((0, secretFile_1.commandNamesSecretFile)(request.target))
64
64
  return "secret_file";
65
65
  return deletesOutside(request.target) ? "delete_outside" : undefined;
66
66
  }
@@ -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
- async function listFiles(projectFolder, args) {
58
- const target = await (0, projectPath_1.resolveProjectPath)(projectFolder, args.path ?? ".");
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.relative}」是檔案,不是資料夾。請用 read_file 讀取它。` };
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.relative, entries, truncated: true } : { path: target.relative, entries } };
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 (0, projectPath_1.resolveProjectPath)(projectFolder, args.path);
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, projectPath_1.isSecretFileName)(target.relative) || (0, projectPath_1.isSecretFileName)(target.absolute))
75
- return (0, projectPath_1.secretFileRefusal)(target.relative);
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.relative}」是資料夾,不是檔案。請用 list_files 看裡面有什麼。` };
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.relative}」不是文字檔,read_file 只能讀取文字檔。` };
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, projectPath_1.hasPrivateKey)(text))
95
- return (0, projectPath_1.secretFileRefusal)(target.relative);
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.relative, content: text, truncated: false } };
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.relative,
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 (0, projectPath_1.resolveProjectPath)(projectFolder, args.path, { allowMissing: true });
150
+ const target = await resolveCallPath(projectFolder, args.path, context);
116
151
  if (!target.ok)
117
152
  return target;
118
- let title = `寫入新檔案 ${target.relative}`;
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.relative}」是資料夾,不能寫成檔案。` };
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.relative}`;
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, { tool: "write_file", title, body, target: target.relative, folder: projectFolder, contents }, signal, NOT_WRITTEN);
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: the folder may have changed while the student decided.
141
- const now = await (0, projectPath_1.resolveProjectPath)(projectFolder, args.path, { allowMissing: true });
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.relative}」:${error instanceof Error ? error.message : "原因不明"}。` };
190
+ return { ok: false, error: "failed", message: `無法寫入「${now.display}」:${error instanceof Error ? error.message : "原因不明"}。` };
150
191
  }
151
- return { ok: true, result: { path: now.relative, created: !now.exists } };
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 = {
@@ -4,13 +4,19 @@ exports.vsCodeInstaller = vsCodeInstaller;
4
4
  exports.lookupDownload = lookupDownload;
5
5
  exports.wingetToolInstaller = wingetToolInstaller;
6
6
  const classroomApp_1 = require("./classroomApp");
7
- /** Authenticode 簽署者憑證主體裡的組織(O=)必須完全是這個名字。 */
7
+ /**
8
+ * Authenticode 簽署者憑證主體裡的組織(O=)必須完全是這個名字。
9
+ * 名字含逗號等特殊字元時,Windows 把它加上引號,例如 O="GitHub, Inc."。
10
+ */
8
11
  function signedBy(organization) {
9
- const escaped = organization.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
12
+ // 引號內的 " 寫成 ""。
13
+ const value = /[,+"\\<>;=]/.test(organization) ? `"${organization.replace(/"/g, '""')}"` : organization;
14
+ const escaped = value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
10
15
  return new RegExp(`(?:^|,\\s*)O=${escaped}(?:,|$)`);
11
16
  }
12
17
  const MICROSOFT_SIGNER = signedBy("Microsoft Corporation");
13
18
  const OPENJS_SIGNER = signedBy("OpenJS Foundation");
19
+ const GITHUB_SIGNER = signedBy("GitHub, Inc.");
14
20
  // Git for Windows 由維護者 Johannes Schindelin 個人簽署,不是「Git for Windows」。
15
21
  const GIT_FOR_WINDOWS_SIGNER = signedBy("Johannes Schindelin");
16
22
  /** VS Code User 版:裝在學生自己的帳號下,不需要系統管理員;不自動啟動,等驗證完由學生開啟。 */
@@ -43,6 +49,10 @@ const GITHUB_LATEST = {
43
49
  url: "https://api.github.com/repos/PowerShell/PowerShell/releases/latest",
44
50
  asset: { x64: /^PowerShell-\d[\d.]*-win-x64\.msi$/, arm64: /^PowerShell-\d[\d.]*-win-arm64\.msi$/ },
45
51
  },
52
+ gh: {
53
+ url: "https://api.github.com/repos/cli/cli/releases/latest",
54
+ asset: { x64: /^gh_\d[\d.]*_windows_amd64\.msi$/, arm64: /^gh_\d[\d.]*_windows_arm64\.msi$/ },
55
+ },
46
56
  };
47
57
  /** 查詢官方來源的 JSON;失敗時回傳學生看得懂、可以重試的原因。 */
48
58
  async function fetchLatest(system, label, url, signal) {
@@ -91,7 +101,8 @@ async function lookupDownload(system, tool, architecture, signal) {
91
101
  return missing;
92
102
  return { download: { url: asset.browser_download_url, fileName: asset.name } };
93
103
  }
94
- /** 官方安裝檔:Git 是 Inno Setup,Node.js 與 PowerShell 是 MSI;全部靜默、不自動重新開機,並寫安裝器自己的 log。 */
104
+ const MSI_SIGNER = { node: OPENJS_SIGNER, pwsh: MICROSOFT_SIGNER, gh: GITHUB_SIGNER };
105
+ /** 官方安裝檔:Git 是 Inno Setup,Node.js、PowerShell 與 GitHub CLI 是 MSI;全部靜默、不自動重新開機,並寫安裝器自己的 log。 */
95
106
  function wingetToolInstaller(tool, download, setupLog) {
96
107
  const base = { label: classroomApp_1.ENVIRONMENT_LABEL[tool], url: download.url, fileName: download.fileName };
97
108
  if (tool === "git") {
@@ -106,7 +117,7 @@ function wingetToolInstaller(tool, download, setupLog) {
106
117
  }
107
118
  return {
108
119
  ...base,
109
- signer: tool === "node" ? OPENJS_SIGNER : MICROSOFT_SIGNER,
120
+ signer: MSI_SIGNER[tool],
110
121
  launch: (installer) => ({
111
122
  command: "msiexec",
112
123
  args: ["/i", installer, "/qn", "/norestart", ...(tool === "pwsh" ? ["ADD_PATH=1"] : []), "/L*v", setupLog],
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; }
@@ -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
- exports.isSecretFileName = isSecretFileName;
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` (relative to the Project Folder) and refuses it when it resolves outside,
46
- * through `..`, an absolute path, or a link. Without `allowMissing`, a path that does not exist is `not_found`.
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
- if (typeof requested !== "string" || requested.trim() === "") {
50
- return { ok: false, error: "invalid_arguments", message: "path 必須是專案資料夾裡的相對路徑文字。" };
51
- }
52
- const outside = { ok: false, error: "outside_project_folder", message: `「${requested}」在專案資料夾外面,Local Tool 只能用專案資料夾裡的檔案。` };
53
- const root = node_path_1.default.resolve(projectFolder);
54
- const lexical = node_path_1.default.resolve(root, requested);
55
- if (!inside(root, lexical))
56
- return outside;
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
  }
@@ -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/start.js CHANGED
@@ -143,9 +143,12 @@ async function exchangeCode(body) {
143
143
  function isEnvironmentTool(value) {
144
144
  return classroomApp_1.ENVIRONMENT_TOOLS.includes(value);
145
145
  }
146
- const MAC_PWSH_PAGE = "https://learn.microsoft.com/powershell/scripting/install/installing-powershell-on-macos";
147
- // VS Code 的直接下載安裝只做 Windows;macOS 開啟官方下載頁,由學生自己安裝。
148
- const MAC_VSCODE_PAGE = "https://code.visualstudio.com/download";
146
+ // 直接下載安裝只做 Windows;這些工具在 macOS 開啟官方安裝頁,由學生自己安裝。
147
+ const MAC_INSTALL_PAGE = {
148
+ pwsh: "https://learn.microsoft.com/powershell/scripting/install/installing-powershell-on-macos",
149
+ vscode: "https://code.visualstudio.com/download",
150
+ gh: "https://cli.github.com/",
151
+ };
149
152
  /** 首頁最多等啟動這麼久;涵蓋 Course Catalog 重試與 Session Model Allowlist 的抓取。 */
150
153
  const PAGE_STARTUP_WAIT_MS = 30_000;
151
154
  /** macOS 維持原本的偵測:找得到且有輸出版本就算已就緒(ADR-0008:第一版只完整支援 Windows)。 */
@@ -160,11 +163,8 @@ function probeMacEnvironment(tool) {
160
163
  /** 開發工具與 Project Folder 無關,安裝一律在使用者家目錄執行。 */
161
164
  function installMacEnvironment(tool, signal, onProgress) {
162
165
  onProgress?.({ stage: "installing" });
163
- const launch = tool === "pwsh"
164
- ? { command: "open", args: [MAC_PWSH_PAGE] }
165
- : tool === "vscode"
166
- ? { command: "open", args: [MAC_VSCODE_PAGE] }
167
- : (0, commandRunner_1.shellLaunch)(macEnvironmentInstallCommand(tool));
166
+ const page = MAC_INSTALL_PAGE[tool];
167
+ const launch = page ? { command: "open", args: [page] } : (0, commandRunner_1.shellLaunch)(macEnvironmentInstallCommand(tool));
168
168
  return (0, commandRunner_1.collectOutput)(launch.command, launch.args, node_os_1.default.homedir(), undefined, signal).then((result) => {
169
169
  if (result.aborted)
170
170
  return { exitCode: result.exitCode, output: result.output, aborted: true };
@@ -43,6 +43,7 @@ function createTrayChannel(options) {
43
43
  secondsLeft: shown.secondsLeft,
44
44
  waiting: shown.waiting,
45
45
  ...(shown.exception ? { exception: shown.exception } : {}),
46
+ ...(shown.outside ? { outside: true } : {}),
46
47
  } : null,
47
48
  };
48
49
  };
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = "0.5.5";
4
+ exports.VERSION = "0.5.7";
@@ -20,6 +20,8 @@ const VERSION_CHECK = {
20
20
  pwsh: { command: "pwsh", pattern: /^PowerShell 7\.\d+\.\d+/ },
21
21
  // code --version 印出版本、commit 與架構三行;只看第一行。
22
22
  vscode: { command: "code", pattern: /^\d+\.\d+\.\d+(?:[-+]\S+)?(?:\r?\n|$)/ },
23
+ // gh --version 第二行是 release 網址。只檢查指令,不檢查 GitHub 登入:登入是學生自己的身分。
24
+ gh: { command: "gh", pattern: /^gh version \d+\.\d+\.\d+/ },
23
25
  };
24
26
  const CHECK_TIMEOUT_MS = 15_000;
25
27
  const NODE_LTS_REASON = "需要 Node.js LTS,且 npm 必須可正常執行";
@@ -43,6 +45,7 @@ const WINGET_ID = {
43
45
  git: "Git.Git",
44
46
  node: "OpenJS.NodeJS.LTS",
45
47
  pwsh: "Microsoft.PowerShell",
48
+ gh: "GitHub.cli",
46
49
  };
47
50
  function isWingetTool(tool) {
48
51
  return tool in WINGET_ID;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vanspod",
3
- "version": "0.5.5",
3
+ "version": "0.5.7",
4
4
  "bin": { "vanspod": "bin/vanspod.cjs" },
5
5
  "engines": { "node": ">=24" },
6
6
  "os": ["win32"],
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, 122, 376, 132)
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
- $script:titleLabel.Text = [string]$approval.title
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