@moon791017/neo-skills 1.0.38 → 1.0.39
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 +2 -1
- package/bin/_cli-utils.js +1 -0
- package/bin/install-system-instructions.js +20 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -186,6 +186,7 @@ install-system-instructions --instructions <key> [--ai-agent <name>] [--project-
|
|
|
186
186
|
| `--instructions <key>` | ✅ | 指定要安裝的系統提示詞(見下方種類表)。 |
|
|
187
187
|
| `--ai-agent <name>` | 否 | 指定目標 Agent(`claude` / `copilot` / `codex`)。省略時安裝至全部。 |
|
|
188
188
|
| `--project-path <path>` | 否 | 指定專案根目錄。省略時安裝至 `$HOME` 全域路徑。 |
|
|
189
|
+
| `--replace-all` | 否 | 若先前已安裝過該提示詞,則先將其移除後重裝。 |
|
|
189
190
|
|
|
190
191
|
**指導檔路徑對照:**
|
|
191
192
|
|
|
@@ -222,7 +223,7 @@ npx -p @moon791017/neo-skills install-system-instructions \
|
|
|
222
223
|
--ai-agent copilot --instructions technical-co-founder --project-path /my/project -y
|
|
223
224
|
```
|
|
224
225
|
|
|
225
|
-
> **💡**
|
|
226
|
+
> **💡** 重複執行相同指令不會重複寫入,系統會自動偵測並跳過已安裝的提示詞。若您希望覆蓋或更新之前安裝的提示詞,可以加上 `--replace-all` 參數進行重裝。
|
|
226
227
|
|
|
227
228
|
## 💡 常用指令範例
|
|
228
229
|
|
package/bin/_cli-utils.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* 用法:
|
|
6
6
|
* install-system-instructions --instructions technical-co-founder
|
|
7
|
+
* install-system-instructions --instructions technical-co-founder --replace-all
|
|
7
8
|
* install-system-instructions --ai-agent claude --instructions technical-co-founder
|
|
8
9
|
* install-system-instructions --ai-agent copilot --instructions technical-co-founder --project-path .
|
|
9
10
|
*
|
|
@@ -12,6 +13,7 @@
|
|
|
12
13
|
* 省略時安裝至全部已註冊 agent。
|
|
13
14
|
* --instructions <key> 指定要安裝的系統提示詞(可用值見 _system-instructions.js 的 INSTRUCTIONS)。必填。
|
|
14
15
|
* --project-path <path> 指定專案根目錄作為安裝基底(取代 $HOME)。省略時安裝至全域路徑。
|
|
16
|
+
* --replace-all 如果指定此參數,若先前已安裝過該提示詞,則會將其移除後重裝。
|
|
15
17
|
*/
|
|
16
18
|
import { readFile, writeFile, mkdir, access } from 'node:fs/promises';
|
|
17
19
|
import { join, resolve, dirname } from 'node:path';
|
|
@@ -58,7 +60,7 @@ function wrapContent(key, content) {
|
|
|
58
60
|
* @param {string | undefined} projectPath - 使用者指定的專案路徑
|
|
59
61
|
* @returns {Promise<{success: boolean, message: string}>}
|
|
60
62
|
*/
|
|
61
|
-
async function installForAgent(agentKey, agentConfig, instructionsKey, instruction, projectPath) {
|
|
63
|
+
async function installForAgent(agentKey, agentConfig, instructionsKey, instruction, projectPath, replaceAll) {
|
|
62
64
|
if (!agentConfig.instructionFile) {
|
|
63
65
|
const msg = `agent "${agentKey}" 未設定 instructionFile,跳過。`;
|
|
64
66
|
console.warn(`⚠️ ${msg}`);
|
|
@@ -86,17 +88,26 @@ async function installForAgent(agentKey, agentConfig, instructionsKey, instructi
|
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
if (fileExists) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
let existing = await readFile(targetFile, 'utf8');
|
|
92
|
+
const hadInstructions = existing.includes(startMarker(instructionsKey));
|
|
93
|
+
|
|
94
|
+
if (replaceAll) {
|
|
95
|
+
const regex = new RegExp(`\\s*${startMarker(instructionsKey)}[\\s\\S]*?${endMarker(instructionsKey)}\\s*`, 'g');
|
|
96
|
+
if (hadInstructions) {
|
|
97
|
+
existing = existing.replace(regex, '').trimEnd();
|
|
98
|
+
console.log(`🧹 [${agentConfig.name}] 已移除舊的 "${instruction.name}" 提示詞。`);
|
|
99
|
+
}
|
|
100
|
+
} else if (hadInstructions) {
|
|
92
101
|
const msg = `指導檔中已包含 "${instruction.name}" 提示詞,跳過安裝。`;
|
|
93
102
|
console.log(`⏭️ ${msg}`);
|
|
94
103
|
return { success: true, message: msg };
|
|
95
104
|
}
|
|
96
105
|
|
|
97
|
-
const newContent = existing.trimEnd() + '\n\n' + wrappedContent + '\n';
|
|
106
|
+
const newContent = existing.trimEnd() ? existing.trimEnd() + '\n\n' + wrappedContent + '\n' : wrappedContent + '\n';
|
|
98
107
|
await writeFile(targetFile, newContent, 'utf8');
|
|
99
|
-
const msg =
|
|
108
|
+
const msg = replaceAll && hadInstructions
|
|
109
|
+
? `已重裝 "${instruction.name}" 系統提示詞。`
|
|
110
|
+
: `已將 "${instruction.name}" 附加至既有指導檔。`;
|
|
100
111
|
console.log(`✅ [${agentConfig.name}] ${msg}`);
|
|
101
112
|
return { success: true, message: msg };
|
|
102
113
|
}
|
|
@@ -113,6 +124,7 @@ async function main() {
|
|
|
113
124
|
const agentKey = args['ai-agent'];
|
|
114
125
|
const projectPath = args['project-path'];
|
|
115
126
|
const instructionsKey = args['instructions'];
|
|
127
|
+
const replaceAll = args['replace-all'];
|
|
116
128
|
|
|
117
129
|
// ── 驗證 --instructions(兩種模式皆需要)──
|
|
118
130
|
if (!instructionsKey) {
|
|
@@ -142,7 +154,7 @@ async function main() {
|
|
|
142
154
|
process.exit(1);
|
|
143
155
|
}
|
|
144
156
|
|
|
145
|
-
const result = await installForAgent(agentKey, agentConfig, instructionsKey, instruction, projectPath);
|
|
157
|
+
const result = await installForAgent(agentKey, agentConfig, instructionsKey, instruction, projectPath, replaceAll);
|
|
146
158
|
if (!result.success) process.exit(1);
|
|
147
159
|
return;
|
|
148
160
|
}
|
|
@@ -158,7 +170,7 @@ async function main() {
|
|
|
158
170
|
for (const [key, config] of Object.entries(AGENTS)) {
|
|
159
171
|
console.log(`━━━ 正在安裝: ${config.name} ━━━`);
|
|
160
172
|
try {
|
|
161
|
-
const result = await installForAgent(key, config, instructionsKey, instruction, projectPath);
|
|
173
|
+
const result = await installForAgent(key, config, instructionsKey, instruction, projectPath, replaceAll);
|
|
162
174
|
results.push({ name: config.name, ...result });
|
|
163
175
|
} catch (error) {
|
|
164
176
|
console.error(`❌ [${config.name}] 安裝失敗:`, error.message || error);
|