troy-mode 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "troy-mode-marketplace",
3
+ "owner": {
4
+ "name": "Troy",
5
+ "url": "https://github.com/DoubleTian-tw"
6
+ },
7
+ "plugins": [
8
+ {
9
+ "name": "troy-mode",
10
+ "source": "./",
11
+ "description": "9 modular workflow skills: troy-mode, troy-how, troy-why, troy-blast-radius, troy-grilling, troy-research, troy-teach-me, troy-wait-what, troy-eval."
12
+ }
13
+ ]
14
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "troy-mode",
3
+ "version": "0.1.0",
4
+ "description": "Cross-project AI Agent workflow playbook and thinking skills for Claude Code, Codex, and Gemini / Antigravity.",
5
+ "author": {
6
+ "name": "Troy",
7
+ "url": "https://github.com/DoubleTian-tw"
8
+ },
9
+ "homepage": "https://github.com/DoubleTian-tw/troy-mode",
10
+ "repository": "https://github.com/DoubleTian-tw/troy-mode",
11
+ "license": "MIT",
12
+ "skills": "./skills/"
13
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Troy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,88 @@
1
- # Temporary Holding Version
1
+ # troy-mode
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 跨專案 AI Agent 工作流工具包(台灣繁體中文為主),同時相容 **Claude Code**、**Codex** 與 **Gemini / Antigravity**。
4
+
5
+ 以 `troy-mode` 作為 Playbook 總路由,依任務性質分流至 8 個專責 Skill,落實「先理解再動手、證據優先、雙盲驗證」的工程工作流。
6
+
7
+ ## 安裝方式
8
+
9
+ ### 1. npm / npx CLI(推薦:同時同步三個 Agent)
10
+
11
+ ```bash
12
+ # 全域安裝(預設互動選擇 Agent,或加 -y 直接套用 claude,codex,gemini)
13
+ npx troy-mode
14
+
15
+ # 只裝到當前專案(.agents/skills + .claude/skills + .codex/skills + .gemini/skills)
16
+ npx troy-mode install --scope project -y
17
+
18
+ # 只裝特定幾個 skill
19
+ npx troy-mode install --skills troy-how,troy-why,troy-blast-radius -y
20
+
21
+ # 檢查目前安裝與 symlink 狀態
22
+ npx troy-mode status
23
+
24
+ # 安全移除(僅移除本套件管理的 troy-*,不動其他 skill)
25
+ npx troy-mode uninstall
26
+ ```
27
+
28
+ 常用選項:
29
+
30
+ - `--scope <global|project>`:安裝範圍(預設 `global`)
31
+ - `--agents <list>`:`claude,codex,gemini` 逗號分隔(預設全部)
32
+ - `--skills <list>`:指定要安裝的 skill(預設全部 9 個)
33
+ - `--mode <copy|link>`:`copy` 複製實體檔案(預設);`link` 連回本機 repo 供開發同步
34
+ - `--force`:遇到同名非 symlink 目錄時先備份再覆蓋
35
+ - `--dry-run`:只預覽動作,不寫入檔案
36
+
37
+ ### 2. Vercel Skills CLI
38
+
39
+ ```bash
40
+ # 安裝整組
41
+ npx skills add DoubleTian-tw/troy-mode -g
42
+
43
+ # 只裝單一 skill
44
+ npx skills add DoubleTian-tw/troy-mode@troy-why -g
45
+ ```
46
+
47
+ ### 3. Claude Code Plugin
48
+
49
+ ```text
50
+ /plugin marketplace add DoubleTian-tw/troy-mode
51
+ /plugin install troy-mode
52
+ ```
53
+
54
+ ### 4. Antigravity Plugin
55
+
56
+ ```bash
57
+ agy plugin install https://github.com/DoubleTian-tw/troy-mode
58
+ ```
59
+
60
+ ## 內建 Skills
61
+
62
+ | Skill | 定位 | 觸發方式 |
63
+ | :--- | :--- | :--- |
64
+ | `troy-mode` | 個人跨專案工作流總入口(Playbook Router) | 手動 (`/troy-mode`, `$troy-mode`) |
65
+ | `troy-how` | 唯讀追蹤程式呼叫鏈、模組邊界與 State Owner | 手動 |
66
+ | `troy-why` | 查證 `git log` / PR / 歷史文件,區分事實、推論與空白 | 手動 |
67
+ | `troy-blast-radius` | 找出 grep 看不到的隱性耦合並實跑證實關鍵假設 | 手動 |
68
+ | `troy-grilling` | 依設計樹逐輪深度盤問,逼出未定決策 | 自動 / 手動 |
69
+ | `troy-research` | 從一手來源查證技術與產品問題,產出可追溯筆記 | 自動 / 手動 |
70
+ | `troy-teach-me` | 觀念採蘇格拉底式引導;Review 採白話直解 + 漸進小圖 | 自動 / 手動 |
71
+ | `troy-wait-what` | 將上一段難懂的 AI 回覆用台灣繁中白話重述 | 手動 |
72
+ | `troy-eval` | 雙盲 A/B 評測工作流程,驗證 skill/規範改動前後差異 | 手動 |
73
+
74
+ ## 本機開發與驗證
75
+
76
+ ```bash
77
+ # 將本機三個 Agent 透過 symlink 連回此 repo 開發
78
+ node bin/cli.mjs install --mode link --force -y
79
+
80
+ # 驗證所有 skill frontmatter、路由表、可移植性與 CLI 行為
81
+ npm run validate
82
+ ```
83
+
84
+ 維護與撰寫規範見 [AGENTS.md](./AGENTS.md)。
85
+
86
+ ## License
87
+
88
+ MIT
package/bin/cli.mjs ADDED
@@ -0,0 +1,503 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from 'node:fs';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import readline from 'node:readline/promises';
7
+ import { fileURLToPath } from 'node:url';
8
+ import { parseArgs } from 'node:util';
9
+
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = path.dirname(__filename);
12
+ const PKG_ROOT = path.resolve(__dirname, '..');
13
+ const SKILLS_SRC = path.join(PKG_ROOT, 'skills');
14
+
15
+ const SUPPORTED_AGENTS = ['claude', 'codex', 'gemini'];
16
+ const VALID_SCOPES = ['global', 'project'];
17
+ const VALID_MODES = ['copy', 'link'];
18
+
19
+ function readPkg() {
20
+ return JSON.parse(fs.readFileSync(path.join(PKG_ROOT, 'package.json'), 'utf8'));
21
+ }
22
+
23
+ function listAvailableSkills() {
24
+ if (!fs.existsSync(SKILLS_SRC)) return [];
25
+ return fs
26
+ .readdirSync(SKILLS_SRC, { withFileTypes: true })
27
+ .filter((entry) => entry.isDirectory() && entry.name.startsWith('troy-'))
28
+ .map((entry) => entry.name)
29
+ .sort();
30
+ }
31
+
32
+ function readSkillSummary(skillName) {
33
+ const skillMdPath = path.join(SKILLS_SRC, skillName, 'SKILL.md');
34
+ if (!fs.existsSync(skillMdPath)) return '';
35
+ const content = fs.readFileSync(skillMdPath, 'utf8');
36
+ const match = content.match(/^---\s*\n([\s\S]*?)\n---/);
37
+ if (!match) return '';
38
+ const descMatch = match[1].match(/^description:\s*(?:>-?\s*\n([\s\S]*?)(?=\n[a-zA-Z0-9_-]+:|\n*$)|(.+))/m);
39
+ if (!descMatch) return '';
40
+ const raw = (descMatch[1] || descMatch[2] || '').replace(/\s+/g, ' ').trim();
41
+ return raw.replace(/^['"]|['"]$/g, '');
42
+ }
43
+
44
+ function resolvePaths(scope, cwd = process.cwd(), homeDir = os.homedir()) {
45
+ if (scope === 'project') {
46
+ return {
47
+ canonicalDir: path.join(cwd, '.agents', 'skills'),
48
+ agentDirs: {
49
+ claude: path.join(cwd, '.claude', 'skills'),
50
+ codex: path.join(cwd, '.codex', 'skills'),
51
+ gemini: path.join(cwd, '.gemini', 'skills'),
52
+ },
53
+ };
54
+ }
55
+ return {
56
+ canonicalDir: path.join(homeDir, '.agents', 'skills'),
57
+ agentDirs: {
58
+ claude: path.join(homeDir, '.claude', 'skills'),
59
+ codex: path.join(homeDir, '.codex', 'skills'),
60
+ gemini: path.join(homeDir, '.gemini', 'config', 'skills'),
61
+ },
62
+ };
63
+ }
64
+
65
+ function parseCsvList(value) {
66
+ return value
67
+ .split(',')
68
+ .map((s) => s.trim())
69
+ .filter(Boolean);
70
+ }
71
+
72
+ function printHelp(pkg) {
73
+ console.log(`troy-mode v${pkg.version}
74
+
75
+ 用法:
76
+ troy-mode [command] [options]
77
+
78
+ 指令:
79
+ install 安裝 troy-* skills 到本機或專案(預設指令)
80
+ uninstall 安全移除由本套件管理的 troy-* skills
81
+ status 檢查目前安裝狀態與 symlink 指向
82
+ list 列出內建的 9 個 skills
83
+
84
+ 選項:
85
+ --scope <global|project> 安裝範圍(預設:global)
86
+ --agents <list> 目標 agent,逗號分隔:claude,codex,gemini(預設:全部)
87
+ --skills <list> 指定要處理的 skill,逗號分隔(預設:全部 troy-*)
88
+ --mode <copy|link> Canonical 層方式:copy 複製檔案 / link 連回本機 repo(預設:copy)
89
+ --force 若目標已存在同名非 symlink 目錄,先備份再覆蓋
90
+ --dry-run 僅預覽將執行的動作,不實際寫入檔案
91
+ -y, --yes 跳過互動確認,直接依預設/參數執行
92
+ -h, --help 顯示說明
93
+ -v, --version 顯示版本
94
+
95
+ 範例:
96
+ npx troy-mode
97
+ npx troy-mode install --scope project --agents claude,codex -y
98
+ npx troy-mode install --mode link -y
99
+ npx troy-mode status
100
+ npx troy-mode uninstall --scope global -y`);
101
+ }
102
+
103
+ function lstatSafe(targetPath) {
104
+ try {
105
+ return fs.lstatSync(targetPath);
106
+ } catch {
107
+ return null;
108
+ }
109
+ }
110
+
111
+ function symlinkTargetMatches(linkPath, expectedTarget) {
112
+ const stat = lstatSafe(linkPath);
113
+ if (!stat || !stat.isSymbolicLink()) return false;
114
+ const rawTarget = fs.readlinkSync(linkPath);
115
+ const resolved = path.resolve(path.dirname(linkPath), rawTarget);
116
+ return resolved === path.resolve(expectedTarget);
117
+ }
118
+
119
+ function copyDirClean(src, dest) {
120
+ fs.mkdirSync(dest, { recursive: true });
121
+ for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
122
+ if (entry.name === '.DS_Store') continue;
123
+ const srcPath = path.join(src, entry.name);
124
+ const destPath = path.join(dest, entry.name);
125
+ if (entry.isDirectory()) {
126
+ copyDirClean(srcPath, destPath);
127
+ } else if (entry.isFile()) {
128
+ fs.copyFileSync(srcPath, destPath);
129
+ }
130
+ }
131
+ }
132
+
133
+ function createDirSymlink(target, linkPath) {
134
+ const type = process.platform === 'win32' ? 'junction' : 'dir';
135
+ fs.symlinkSync(target, linkPath, type);
136
+ }
137
+
138
+ function backupExisting(targetPath) {
139
+ const stamp = new Date().toISOString().replace(/[:.]/g, '-');
140
+ const skillsDir = path.dirname(targetPath);
141
+ const backupRoot = path.join(path.dirname(skillsDir), '.troy-mode-backups', stamp);
142
+ fs.mkdirSync(backupRoot, { recursive: true });
143
+ fs.renameSync(targetPath, path.join(backupRoot, path.basename(targetPath)));
144
+ }
145
+
146
+ function removeEntry(targetPath) {
147
+ const stat = lstatSafe(targetPath);
148
+ if (!stat) return;
149
+ if (stat.isSymbolicLink() || stat.isFile()) {
150
+ fs.unlinkSync(targetPath);
151
+ } else {
152
+ fs.rmSync(targetPath, { recursive: true, force: true });
153
+ }
154
+ }
155
+
156
+ function prepareCanonicalSkill(skillName, canonicalDir, { mode, force, dryRun }) {
157
+ const srcDir = path.join(SKILLS_SRC, skillName);
158
+ const destDir = path.join(canonicalDir, skillName);
159
+ const existing = lstatSafe(destDir);
160
+
161
+ if (mode === 'link') {
162
+ if (symlinkTargetMatches(destDir, srcDir)) {
163
+ return { action: 'unchanged', path: destDir };
164
+ }
165
+ if (existing) {
166
+ if (!existing.isSymbolicLink() && !force) {
167
+ return { action: 'skipped', reason: '已存在非 symlink 目錄(可加 --force 備份覆蓋)', path: destDir };
168
+ }
169
+ if (!dryRun) {
170
+ if (!existing.isSymbolicLink() && force) {
171
+ backupExisting(destDir);
172
+ } else {
173
+ removeEntry(destDir);
174
+ }
175
+ }
176
+ }
177
+ if (!dryRun) {
178
+ fs.mkdirSync(canonicalDir, { recursive: true });
179
+ createDirSymlink(srcDir, destDir);
180
+ }
181
+ return { action: 'linked', path: destDir, target: srcDir };
182
+ }
183
+
184
+ // mode === 'copy'
185
+ if (existing) {
186
+ if (existing.isSymbolicLink()) {
187
+ if (!force) {
188
+ return { action: 'skipped', reason: '目前為 symlink(可加 --force 改為實體複製)', path: destDir };
189
+ }
190
+ if (!dryRun) removeEntry(destDir);
191
+ } else {
192
+ // Updating previously copied directory: safe to replace unless we want backup on --force
193
+ if (!dryRun) {
194
+ if (force) {
195
+ backupExisting(destDir);
196
+ } else {
197
+ fs.rmSync(destDir, { recursive: true, force: true });
198
+ }
199
+ }
200
+ }
201
+ }
202
+ if (!dryRun) {
203
+ copyDirClean(srcDir, destDir);
204
+ }
205
+ return { action: existing ? 'updated' : 'copied', path: destDir };
206
+ }
207
+
208
+ function linkAgentSkill(skillName, canonicalDir, agentDir, { force, dryRun }) {
209
+ const canonicalSkillDir = path.join(canonicalDir, skillName);
210
+ const linkPath = path.join(agentDir, skillName);
211
+ const existing = lstatSafe(linkPath);
212
+
213
+ if (symlinkTargetMatches(linkPath, canonicalSkillDir)) {
214
+ return { action: 'unchanged', path: linkPath };
215
+ }
216
+
217
+ if (existing) {
218
+ if (!existing.isSymbolicLink() && !force) {
219
+ return { action: 'skipped', reason: '已存在非 symlink 目錄(可加 --force 備份覆蓋)', path: linkPath };
220
+ }
221
+ if (!dryRun) {
222
+ if (!existing.isSymbolicLink() && force) {
223
+ backupExisting(linkPath);
224
+ } else {
225
+ removeEntry(linkPath);
226
+ }
227
+ }
228
+ }
229
+
230
+ if (!dryRun) {
231
+ fs.mkdirSync(agentDir, { recursive: true });
232
+ try {
233
+ createDirSymlink(canonicalSkillDir, linkPath);
234
+ } catch (err) {
235
+ if (process.platform === 'win32') {
236
+ copyDirClean(canonicalSkillDir, linkPath);
237
+ return { action: 'copied-fallback', path: linkPath };
238
+ }
239
+ throw err;
240
+ }
241
+ }
242
+ return { action: 'linked', path: linkPath, target: canonicalSkillDir };
243
+ }
244
+
245
+ async function promptSelectionIfInteractive(opts, availableSkills) {
246
+ const shouldPrompt =
247
+ !opts.yes &&
248
+ !opts.agentsExplicit &&
249
+ process.stdin.isTTY &&
250
+ process.stdout.isTTY;
251
+
252
+ if (!shouldPrompt) return opts;
253
+
254
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
255
+ try {
256
+ console.log(`將安裝 ${availableSkills.length} 個 troy-* skills(scope: ${opts.scope}, mode: ${opts.mode})`);
257
+ const agentAnswer = await rl.question(
258
+ `選擇目標 Agent(逗號分隔,直接按 Enter 全選 [${SUPPORTED_AGENTS.join(',')}]):`
259
+ );
260
+ const chosenAgents = agentAnswer.trim() ? parseCsvList(agentAnswer) : SUPPORTED_AGENTS;
261
+ for (const a of chosenAgents) {
262
+ if (!SUPPORTED_AGENTS.includes(a)) {
263
+ throw new Error(`不支援的 agent: ${a}(可選:${SUPPORTED_AGENTS.join(', ')})`);
264
+ }
265
+ }
266
+ opts.agents = chosenAgents;
267
+ return opts;
268
+ } finally {
269
+ rl.close();
270
+ }
271
+ }
272
+
273
+ async function runInstall(opts, pkg) {
274
+ const availableSkills = listAvailableSkills();
275
+ const targetSkills = opts.skillsExplicit ? opts.skills : availableSkills;
276
+
277
+ for (const s of targetSkills) {
278
+ if (!availableSkills.includes(s)) {
279
+ throw new Error(`找不到 skill "${s}"(可用:${availableSkills.join(', ')})`);
280
+ }
281
+ }
282
+
283
+ await promptSelectionIfInteractive(opts, targetSkills);
284
+
285
+ const { canonicalDir, agentDirs } = resolvePaths(opts.scope);
286
+ const prefix = opts.dryRun ? '[dry-run] ' : '';
287
+
288
+ console.log(`\n${prefix}troy-mode v${pkg.version} — 安裝開始`);
289
+ console.log(`- Scope: ${opts.scope}`);
290
+ console.log(`- Mode: ${opts.mode}`);
291
+ console.log(`- Canonical: ${canonicalDir}`);
292
+ console.log(`- Agents: ${opts.agents.join(', ')}`);
293
+ console.log(`- Skills (${targetSkills.length}): ${targetSkills.join(', ')}\n`);
294
+
295
+ let skippedCount = 0;
296
+
297
+ for (const skill of targetSkills) {
298
+ const res = prepareCanonicalSkill(skill, canonicalDir, opts);
299
+ if (res.action === 'skipped') {
300
+ skippedCount += 1;
301
+ console.log(`${prefix}[skip] canonical ${skill}: ${res.reason}`);
302
+ continue;
303
+ }
304
+ console.log(`${prefix}[${res.action}] ${res.path}`);
305
+
306
+ for (const agent of opts.agents) {
307
+ const linkRes = linkAgentSkill(skill, canonicalDir, agentDirs[agent], opts);
308
+ if (linkRes.action === 'skipped') {
309
+ skippedCount += 1;
310
+ console.log(`${prefix} [skip] ${agent}: ${linkRes.reason}`);
311
+ } else {
312
+ console.log(`${prefix} [${linkRes.action}] ${agent} -> ${linkRes.path}`);
313
+ }
314
+ }
315
+ }
316
+
317
+ console.log(
318
+ skippedCount > 0
319
+ ? `\n${prefix}完成(有 ${skippedCount} 個項目因既有衝突而略過,詳見上方提示)。`
320
+ : `\n${prefix}完成!所有選定的 skills 與 agent 連結已同步。`
321
+ );
322
+ }
323
+
324
+ function runStatus(opts, pkg) {
325
+ const availableSkills = listAvailableSkills();
326
+ const targetSkills = opts.skillsExplicit ? opts.skills : availableSkills;
327
+ const { canonicalDir, agentDirs } = resolvePaths(opts.scope);
328
+
329
+ console.log(`troy-mode v${pkg.version} — 狀態檢查 (scope: ${opts.scope})`);
330
+ console.log(`Canonical: ${canonicalDir}\n`);
331
+
332
+ for (const skill of targetSkills) {
333
+ const cPath = path.join(canonicalDir, skill);
334
+ const cStat = lstatSafe(cPath);
335
+ let cStatus = 'missing';
336
+ if (cStat) {
337
+ if (cStat.isSymbolicLink()) {
338
+ const target = fs.readlinkSync(cPath);
339
+ const exists = fs.existsSync(cPath);
340
+ cStatus = exists ? `symlink -> ${target}` : `broken symlink -> ${target}`;
341
+ } else {
342
+ cStatus = 'installed (copy)';
343
+ }
344
+ }
345
+
346
+ const agentStatuses = opts.agents.map((agent) => {
347
+ const aPath = path.join(agentDirs[agent], skill);
348
+ const aStat = lstatSafe(aPath);
349
+ if (!aStat) return `${agent}: missing`;
350
+ if (aStat.isSymbolicLink()) {
351
+ if (!fs.existsSync(aPath)) return `${agent}: broken-link`;
352
+ return symlinkTargetMatches(aPath, cPath) ? `${agent}: ok` : `${agent}: other-link`;
353
+ }
354
+ return `${agent}: dir(non-link)`;
355
+ });
356
+
357
+ console.log(`- ${skill}`);
358
+ console.log(` canonical: ${cStatus}`);
359
+ console.log(` agents: ${agentStatuses.join(' | ')}`);
360
+ }
361
+ }
362
+
363
+ async function runUninstall(opts, pkg) {
364
+ const availableSkills = listAvailableSkills();
365
+ const targetSkills = opts.skillsExplicit ? opts.skills : availableSkills;
366
+ const { canonicalDir, agentDirs } = resolvePaths(opts.scope);
367
+ const prefix = opts.dryRun ? '[dry-run] ' : '';
368
+
369
+ if (!opts.yes && !opts.dryRun && process.stdin.isTTY && process.stdout.isTTY) {
370
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
371
+ try {
372
+ const ans = await rl.question(
373
+ `確定要移除 ${opts.scope} 範圍內的 ${targetSkills.length} 個 troy-* skills 嗎?(y/N) `
374
+ );
375
+ if (!/^y(es)?$/i.test(ans.trim())) {
376
+ console.log('已取消。');
377
+ return;
378
+ }
379
+ } finally {
380
+ rl.close();
381
+ }
382
+ }
383
+
384
+ console.log(`${prefix}troy-mode v${pkg.version} — 移除開始 (scope: ${opts.scope})`);
385
+
386
+ for (const skill of targetSkills) {
387
+ for (const agent of opts.agents) {
388
+ const aPath = path.join(agentDirs[agent], skill);
389
+ const aStat = lstatSafe(aPath);
390
+ if (!aStat) continue;
391
+ const canonicalSkill = path.join(canonicalDir, skill);
392
+ const isManagedLink =
393
+ aStat.isSymbolicLink() &&
394
+ (symlinkTargetMatches(aPath, canonicalSkill) || opts.force);
395
+
396
+ if (isManagedLink) {
397
+ if (!opts.dryRun) removeEntry(aPath);
398
+ console.log(`${prefix}[removed] ${aPath}`);
399
+ } else {
400
+ console.log(`${prefix}[skip] ${aPath}(非本套件 symlink,加 --force 才會移除)`);
401
+ }
402
+ }
403
+
404
+ // Only remove canonical if removing all agents or no managed symlinks remain
405
+ const cPath = path.join(canonicalDir, skill);
406
+ const cStat = lstatSafe(cPath);
407
+ if (cStat) {
408
+ const stillReferenced = SUPPORTED_AGENTS.some((agent) => {
409
+ const aPath = path.join(agentDirs[agent], skill);
410
+ return Boolean(lstatSafe(aPath)) && symlinkTargetMatches(aPath, cPath);
411
+ });
412
+ if (!stillReferenced || opts.force) {
413
+ if (!opts.dryRun) removeEntry(cPath);
414
+ console.log(`${prefix}[removed] ${cPath}`);
415
+ } else {
416
+ console.log(`${prefix}[kept] ${cPath}(仍有其他 agent 連結)`);
417
+ }
418
+ }
419
+ }
420
+ }
421
+
422
+ function runList(pkg) {
423
+ const skills = listAvailableSkills();
424
+ console.log(`troy-mode v${pkg.version} — 內建 ${skills.length} 個 Skills:\n`);
425
+ for (const skill of skills) {
426
+ const summary = readSkillSummary(skill);
427
+ console.log(`- ${skill}`);
428
+ if (summary) console.log(` ${summary}`);
429
+ }
430
+ }
431
+
432
+ async function main() {
433
+ const pkg = readPkg();
434
+ const { values, positionals } = parseArgs({
435
+ allowPositionals: true,
436
+ options: {
437
+ scope: { type: 'string', default: 'global' },
438
+ agents: { type: 'string' },
439
+ skills: { type: 'string' },
440
+ mode: { type: 'string', default: 'copy' },
441
+ force: { type: 'boolean', default: false },
442
+ 'dry-run': { type: 'boolean', default: false },
443
+ yes: { type: 'boolean', short: 'y', default: false },
444
+ help: { type: 'boolean', short: 'h', default: false },
445
+ version: { type: 'boolean', short: 'v', default: false },
446
+ },
447
+ });
448
+
449
+ if (values.help) {
450
+ printHelp(pkg);
451
+ return;
452
+ }
453
+ if (values.version) {
454
+ console.log(pkg.version);
455
+ return;
456
+ }
457
+
458
+ const command = positionals[0] || 'install';
459
+ if (!['install', 'uninstall', 'status', 'list'].includes(command)) {
460
+ throw new Error(`未知指令 "${command}",請執行 troy-mode --help 查看用法。`);
461
+ }
462
+
463
+ if (!VALID_SCOPES.includes(values.scope)) {
464
+ throw new Error(`無效的 --scope "${values.scope}"(可選:${VALID_SCOPES.join(', ')})`);
465
+ }
466
+ if (!VALID_MODES.includes(values.mode)) {
467
+ throw new Error(`無效的 --mode "${values.mode}"(可選:${VALID_MODES.join(', ')})`);
468
+ }
469
+
470
+ const agents = values.agents ? parseCsvList(values.agents) : [...SUPPORTED_AGENTS];
471
+ for (const a of agents) {
472
+ if (!SUPPORTED_AGENTS.includes(a)) {
473
+ throw new Error(`不支援的 agent "${a}"(可選:${SUPPORTED_AGENTS.join(', ')})`);
474
+ }
475
+ }
476
+
477
+ const opts = {
478
+ scope: values.scope,
479
+ mode: values.mode,
480
+ agents,
481
+ agentsExplicit: Boolean(values.agents),
482
+ skills: values.skills ? parseCsvList(values.skills) : [],
483
+ skillsExplicit: Boolean(values.skills),
484
+ force: values.force,
485
+ dryRun: values['dry-run'],
486
+ yes: values.yes,
487
+ };
488
+
489
+ if (command === 'list') {
490
+ runList(pkg);
491
+ } else if (command === 'status') {
492
+ runStatus(opts, pkg);
493
+ } else if (command === 'uninstall') {
494
+ await runUninstall(opts, pkg);
495
+ } else {
496
+ await runInstall(opts, pkg);
497
+ }
498
+ }
499
+
500
+ main().catch((err) => {
501
+ console.error(`錯誤:${err.message}`);
502
+ process.exit(1);
503
+ });
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
2
  "name": "troy-mode",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Cross-project AI Agent workflow playbook and skills toolkit for Claude Code, Codex, and Gemini / Antigravity.",
5
+ "type": "module",
6
+ "bin": {
7
+ "troy-mode": "bin/cli.mjs"
8
+ },
9
+ "scripts": {
10
+ "validate": "node scripts/validate.mjs",
11
+ "test": "node scripts/validate.mjs"
12
+ },
13
+ "license": "MIT",
14
+ "author": {
15
+ "name": "Troy",
16
+ "url": "https://github.com/DoubleTian-tw"
17
+ },
18
+ "homepage": "https://github.com/DoubleTian-tw/troy-mode#readme",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/DoubleTian-tw/troy-mode.git"
22
+ },
23
+ "bugs": {
24
+ "url": "https://github.com/DoubleTian-tw/troy-mode/issues"
25
+ },
26
+ "keywords": [
27
+ "agent-skills",
28
+ "ai-workflow",
29
+ "claude-code",
30
+ "codex",
31
+ "gemini",
32
+ "antigravity",
33
+ "troy-mode"
34
+ ],
35
+ "files": [
36
+ "bin/",
37
+ "skills/",
38
+ "plugin.json",
39
+ ".claude-plugin/",
40
+ "README.md",
41
+ "LICENSE"
42
+ ],
43
+ "engines": {
44
+ "node": ">=18.0.0"
45
+ }
46
+ }