autosnippet 3.2.21 → 3.3.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.
Files changed (107) hide show
  1. package/dashboard/dist/assets/{icons-C1dUryS-.js → icons-BofcEZ3f.js} +1 -1
  2. package/dashboard/dist/assets/index-SiN1GChm.js +128 -0
  3. package/dashboard/dist/index.html +2 -2
  4. package/dist/bin/cli.d.ts +0 -1
  5. package/dist/bin/cli.js +0 -133
  6. package/dist/lib/cli/SetupService.d.ts +46 -2
  7. package/dist/lib/cli/SetupService.js +2 -27
  8. package/dist/lib/{platform/ios/spm → core/discovery}/SpmDiscoverer.d.ts +2 -5
  9. package/dist/lib/{platform/ios/spm → core/discovery}/SpmDiscoverer.js +159 -44
  10. package/dist/lib/core/discovery/index.d.ts +1 -1
  11. package/dist/lib/core/discovery/index.js +2 -2
  12. package/dist/lib/external/mcp/handlers/guard.js +6 -3
  13. package/dist/lib/http/HttpServer.js +0 -6
  14. package/dist/lib/http/routes/commands.d.ts +1 -1
  15. package/dist/lib/http/routes/commands.js +1 -66
  16. package/dist/lib/http/routes/remote.js +0 -5
  17. package/dist/lib/injection/ServiceMap.d.ts +0 -9
  18. package/dist/lib/injection/modules/AppModule.d.ts +2 -3
  19. package/dist/lib/injection/modules/AppModule.js +3 -30
  20. package/dist/lib/injection/modules/GuardModule.js +33 -1
  21. package/dist/lib/service/guard/GuardCheckEngine.d.ts +13 -1
  22. package/dist/lib/service/guard/GuardCheckEngine.js +44 -2
  23. package/dist/lib/service/module/ModuleService.js +3 -13
  24. package/dist/lib/service/search/SearchEngine.js +1 -1
  25. package/dist/lib/shared/constants.d.ts +0 -15
  26. package/dist/lib/shared/constants.js +0 -10
  27. package/dist/lib/shared/schemas/config.d.ts +4 -1
  28. package/dist/lib/shared/schemas/config.js +8 -1
  29. package/dist/scripts/release.js +2 -10
  30. package/package.json +4 -19
  31. package/dashboard/dist/assets/index-DdvZE4Yd.js +0 -128
  32. package/dist/lib/http/routes/snippets.d.ts +0 -6
  33. package/dist/lib/http/routes/snippets.js +0 -49
  34. package/dist/lib/platform/ClipboardManager.d.ts +0 -24
  35. package/dist/lib/platform/ClipboardManager.js +0 -142
  36. package/dist/lib/platform/NativeUi.d.ts +0 -53
  37. package/dist/lib/platform/NativeUi.js +0 -284
  38. package/dist/lib/platform/ios/index.d.ts +0 -38
  39. package/dist/lib/platform/ios/index.js +0 -42
  40. package/dist/lib/platform/ios/routes/spm.d.ts +0 -9
  41. package/dist/lib/platform/ios/routes/spm.js +0 -371
  42. package/dist/lib/platform/ios/snippet/PlaceholderConverter.d.ts +0 -21
  43. package/dist/lib/platform/ios/snippet/PlaceholderConverter.js +0 -48
  44. package/dist/lib/platform/ios/snippet/XcodeCodec.d.ts +0 -23
  45. package/dist/lib/platform/ios/snippet/XcodeCodec.js +0 -96
  46. package/dist/lib/platform/ios/spm/DependencyGraph.d.ts +0 -56
  47. package/dist/lib/platform/ios/spm/DependencyGraph.js +0 -195
  48. package/dist/lib/platform/ios/spm/PackageSwiftParser.d.ts +0 -69
  49. package/dist/lib/platform/ios/spm/PackageSwiftParser.js +0 -231
  50. package/dist/lib/platform/ios/spm/PathFinder.d.ts +0 -28
  51. package/dist/lib/platform/ios/spm/PathFinder.js +0 -117
  52. package/dist/lib/platform/ios/spm/PolicyEngine.d.ts +0 -44
  53. package/dist/lib/platform/ios/spm/PolicyEngine.js +0 -79
  54. package/dist/lib/platform/ios/spm/SpmHelper.d.ts +0 -102
  55. package/dist/lib/platform/ios/spm/SpmHelper.js +0 -464
  56. package/dist/lib/platform/ios/xcode/HeaderResolver.d.ts +0 -33
  57. package/dist/lib/platform/ios/xcode/HeaderResolver.js +0 -90
  58. package/dist/lib/platform/ios/xcode/SaveEventFilter.d.ts +0 -66
  59. package/dist/lib/platform/ios/xcode/SaveEventFilter.js +0 -142
  60. package/dist/lib/platform/ios/xcode/XcodeAutomation.d.ts +0 -71
  61. package/dist/lib/platform/ios/xcode/XcodeAutomation.js +0 -327
  62. package/dist/lib/platform/ios/xcode/XcodeImportResolver.d.ts +0 -130
  63. package/dist/lib/platform/ios/xcode/XcodeImportResolver.js +0 -404
  64. package/dist/lib/platform/ios/xcode/XcodeIntegration.d.ts +0 -89
  65. package/dist/lib/platform/ios/xcode/XcodeIntegration.js +0 -588
  66. package/dist/lib/platform/ios/xcode/XcodeWriteUtils.d.ts +0 -99
  67. package/dist/lib/platform/ios/xcode/XcodeWriteUtils.js +0 -190
  68. package/dist/lib/service/automation/ActionPipeline.d.ts +0 -34
  69. package/dist/lib/service/automation/ActionPipeline.js +0 -53
  70. package/dist/lib/service/automation/AutomationOrchestrator.d.ts +0 -86
  71. package/dist/lib/service/automation/AutomationOrchestrator.js +0 -57
  72. package/dist/lib/service/automation/ContextCollector.d.ts +0 -24
  73. package/dist/lib/service/automation/ContextCollector.js +0 -35
  74. package/dist/lib/service/automation/DirectiveDetector.d.ts +0 -51
  75. package/dist/lib/service/automation/DirectiveDetector.js +0 -112
  76. package/dist/lib/service/automation/FileWatcher.d.ts +0 -51
  77. package/dist/lib/service/automation/FileWatcher.js +0 -366
  78. package/dist/lib/service/automation/TriggerResolver.d.ts +0 -36
  79. package/dist/lib/service/automation/TriggerResolver.js +0 -62
  80. package/dist/lib/service/automation/handlers/AlinkHandler.d.ts +0 -7
  81. package/dist/lib/service/automation/handlers/AlinkHandler.js +0 -80
  82. package/dist/lib/service/automation/handlers/CreateHandler.d.ts +0 -11
  83. package/dist/lib/service/automation/handlers/CreateHandler.js +0 -170
  84. package/dist/lib/service/automation/handlers/GuardHandler.d.ts +0 -17
  85. package/dist/lib/service/automation/handlers/GuardHandler.js +0 -218
  86. package/dist/lib/service/automation/handlers/HeaderHandler.d.ts +0 -2
  87. package/dist/lib/service/automation/handlers/HeaderHandler.js +0 -32
  88. package/dist/lib/service/automation/handlers/SearchHandler.d.ts +0 -11
  89. package/dist/lib/service/automation/handlers/SearchHandler.js +0 -278
  90. package/dist/lib/service/snippet/SnippetFactory.d.ts +0 -101
  91. package/dist/lib/service/snippet/SnippetFactory.js +0 -145
  92. package/dist/lib/service/snippet/SnippetInstaller.d.ts +0 -91
  93. package/dist/lib/service/snippet/SnippetInstaller.js +0 -276
  94. package/dist/lib/service/snippet/codecs/SnippetCodec.d.ts +0 -44
  95. package/dist/lib/service/snippet/codecs/SnippetCodec.js +0 -35
  96. package/dist/lib/service/snippet/codecs/VSCodeCodec.d.ts +0 -27
  97. package/dist/lib/service/snippet/codecs/VSCodeCodec.js +0 -82
  98. package/dist/scripts/build-native-ui.d.ts +0 -3
  99. package/dist/scripts/build-native-ui.js +0 -62
  100. package/dist/scripts/init-snippets.d.ts +0 -30
  101. package/dist/scripts/init-snippets.js +0 -298
  102. package/dist/scripts/install-full.d.ts +0 -7
  103. package/dist/scripts/install-full.js +0 -38
  104. package/resources/native-ui/README.md +0 -29
  105. package/resources/native-ui/combined-window.swift +0 -494
  106. package/resources/native-ui/main.swift +0 -598
  107. package/scripts/postinstall-safe.mjs +0 -89
@@ -1,6 +0,0 @@
1
- /**
2
- * Snippets API 路由
3
- * Snippet = Recipe 的附属产物,从 Recipe 实时生成,不存 DB
4
- */
5
- declare const router: import("express-serve-static-core").Router;
6
- export default router;
@@ -1,49 +0,0 @@
1
- /**
2
- * Snippets API 路由
3
- * Snippet = Recipe 的附属产物,从 Recipe 实时生成,不存 DB
4
- */
5
- import express from 'express';
6
- import { getServiceContainer } from '../../injection/ServiceContainer.js';
7
- import { NotFoundError } from '../../shared/errors/index.js';
8
- const router = express.Router();
9
- /**
10
- * GET /api/v1/snippets
11
- * 从 Recipe 实时生成 Snippet 列表
12
- */
13
- router.get('/', async (req, res) => {
14
- const container = getServiceContainer();
15
- const snippetFactory = container.get('snippetFactory');
16
- const { language, category, keyword } = req.query;
17
- const filters = {};
18
- if (language) {
19
- filters.language = String(language);
20
- }
21
- if (category) {
22
- filters.category = String(category);
23
- }
24
- if (keyword) {
25
- filters.keyword = String(keyword);
26
- }
27
- const snippets = await snippetFactory.listSnippets(filters);
28
- res.json({
29
- success: true,
30
- data: {
31
- snippets,
32
- total: snippets.length,
33
- },
34
- });
35
- });
36
- /**
37
- * GET /api/v1/snippets/:id
38
- * 从单个 Recipe 实时生成 Snippet
39
- */
40
- router.get('/:id', async (req, res) => {
41
- const container = getServiceContainer();
42
- const snippetFactory = container.get('snippetFactory');
43
- const snippet = await snippetFactory.getSnippet(String(req.params.id));
44
- if (!snippet) {
45
- throw new NotFoundError('Snippet (recipe)', String(req.params.id));
46
- }
47
- res.json({ success: true, data: snippet });
48
- });
49
- export default router;
@@ -1,24 +0,0 @@
1
- /**
2
- * ClipboardManager - 跨平台剪贴板读写
3
- *
4
- * macOS: pbcopy / pbpaste
5
- * Linux: xclip 或 xsel (X11),wl-copy / wl-paste (Wayland)
6
- * Windows: PowerShell Get-Clipboard / Set-Clipboard
7
- *
8
- * 支持保存/恢复剪贴板内容,避免破坏用户原有剪贴板。
9
- * V2 ESM 版本。
10
- */
11
- /**
12
- * 读取剪贴板内容
13
- * @returns 剪贴板文本,失败返回空字符串
14
- */
15
- export declare function read(): string;
16
- /** 写入内容到剪贴板 */
17
- export declare function write(text: string): boolean;
18
- /**
19
- * 保存当前剪贴板 → 执行回调 → 恢复剪贴板
20
- *
21
- * @param fn 在剪贴板保存期间执行的函数
22
- * @returns fn 的返回值
23
- */
24
- export declare function withClipboardSave(fn: () => Promise<unknown>): Promise<unknown>;
@@ -1,142 +0,0 @@
1
- /**
2
- * ClipboardManager - 跨平台剪贴板读写
3
- *
4
- * macOS: pbcopy / pbpaste
5
- * Linux: xclip 或 xsel (X11),wl-copy / wl-paste (Wayland)
6
- * Windows: PowerShell Get-Clipboard / Set-Clipboard
7
- *
8
- * 支持保存/恢复剪贴板内容,避免破坏用户原有剪贴板。
9
- * V2 ESM 版本。
10
- */
11
- import { execSync } from 'node:child_process';
12
- const TIMEOUT = 3000;
13
- const PLATFORM = process.platform;
14
- /** 检测 Linux 剪贴板后端 */
15
- function _linuxBackend() {
16
- // Wayland
17
- if (process.env.WAYLAND_DISPLAY) {
18
- try {
19
- execSync('which wl-copy', { stdio: 'ignore', timeout: TIMEOUT });
20
- return 'wl';
21
- }
22
- catch {
23
- /* fallthrough */
24
- }
25
- }
26
- // X11
27
- try {
28
- execSync('which xclip', { stdio: 'ignore', timeout: TIMEOUT });
29
- return 'xclip';
30
- }
31
- catch {
32
- /* fallthrough */
33
- }
34
- try {
35
- execSync('which xsel', { stdio: 'ignore', timeout: TIMEOUT });
36
- return 'xsel';
37
- }
38
- catch {
39
- /* fallthrough */
40
- }
41
- return null;
42
- }
43
- /** 缓存 Linux 后端检测结果 */
44
- let _cachedLinuxBackend;
45
- function getLinuxBackend() {
46
- if (_cachedLinuxBackend === undefined) {
47
- _cachedLinuxBackend = _linuxBackend();
48
- }
49
- return _cachedLinuxBackend;
50
- }
51
- /**
52
- * 读取剪贴板内容
53
- * @returns 剪贴板文本,失败返回空字符串
54
- */
55
- export function read() {
56
- try {
57
- if (PLATFORM === 'darwin') {
58
- return execSync('pbpaste', { encoding: 'utf8', timeout: TIMEOUT });
59
- }
60
- if (PLATFORM === 'win32') {
61
- return execSync('powershell.exe -NoProfile -Command Get-Clipboard', {
62
- encoding: 'utf8',
63
- timeout: TIMEOUT,
64
- }).replace(/\r?\n$/, '');
65
- }
66
- // Linux
67
- const backend = getLinuxBackend();
68
- if (backend === 'wl') {
69
- return execSync('wl-paste --no-newline 2>/dev/null', { encoding: 'utf8', timeout: TIMEOUT });
70
- }
71
- if (backend === 'xclip') {
72
- return execSync('xclip -selection clipboard -o', { encoding: 'utf8', timeout: TIMEOUT });
73
- }
74
- if (backend === 'xsel') {
75
- return execSync('xsel --clipboard --output', { encoding: 'utf8', timeout: TIMEOUT });
76
- }
77
- return '';
78
- }
79
- catch {
80
- return '';
81
- }
82
- }
83
- /** 写入内容到剪贴板 */
84
- export function write(text) {
85
- try {
86
- if (PLATFORM === 'darwin') {
87
- execSync('pbcopy', { input: text, timeout: TIMEOUT, stdio: ['pipe', 'ignore', 'ignore'] });
88
- return true;
89
- }
90
- if (PLATFORM === 'win32') {
91
- execSync('powershell.exe -NoProfile -Command "$input | Set-Clipboard"', {
92
- input: text,
93
- timeout: TIMEOUT,
94
- stdio: ['pipe', 'ignore', 'ignore'],
95
- });
96
- return true;
97
- }
98
- // Linux
99
- const backend = getLinuxBackend();
100
- if (backend === 'wl') {
101
- execSync('wl-copy', { input: text, timeout: TIMEOUT, stdio: ['pipe', 'ignore', 'ignore'] });
102
- return true;
103
- }
104
- if (backend === 'xclip') {
105
- execSync('xclip -selection clipboard', {
106
- input: text,
107
- timeout: TIMEOUT,
108
- stdio: ['pipe', 'ignore', 'ignore'],
109
- });
110
- return true;
111
- }
112
- if (backend === 'xsel') {
113
- execSync('xsel --clipboard --input', {
114
- input: text,
115
- timeout: TIMEOUT,
116
- stdio: ['pipe', 'ignore', 'ignore'],
117
- });
118
- return true;
119
- }
120
- return false;
121
- }
122
- catch {
123
- return false;
124
- }
125
- }
126
- /**
127
- * 保存当前剪贴板 → 执行回调 → 恢复剪贴板
128
- *
129
- * @param fn 在剪贴板保存期间执行的函数
130
- * @returns fn 的返回值
131
- */
132
- export async function withClipboardSave(fn) {
133
- const saved = read();
134
- try {
135
- return await fn();
136
- }
137
- finally {
138
- if (saved) {
139
- write(saved);
140
- }
141
- }
142
- }
@@ -1,53 +0,0 @@
1
- /**
2
- * NativeUi - macOS 原生 UI 交互层
3
- *
4
- * 三层降级策略:
5
- * 1. Swift Helper 二进制 (resources/native-ui/native-ui)
6
- * 2. AppleScript 回退 (choose from list / display alert)
7
- * 3. 控制台输出回退 (非 macOS 或非 TTY)
8
- *
9
- * V2 ESM 版本,对应 V1 NativeUi.js
10
- */
11
- /** 检查 Swift Helper 是否可用 */
12
- export declare function isNativeUiAvailable(): boolean;
13
- /**
14
- * 用组合窗口展示搜索结果(列表 + 预览)
15
- *
16
- * @param items
17
- * @param keyword 搜索关键词
18
- * @returns 选中的索引(0-based),-1 表示取消
19
- */
20
- export declare function showCombinedWindow(items: Array<{
21
- title: string;
22
- code: string;
23
- explanation?: string;
24
- groupSize?: number;
25
- }>, keyword?: string): number;
26
- /**
27
- * 简单列表选择弹窗
28
- *
29
- * @param items 选项列表
30
- * @param title 窗口标题
31
- * @param prompt 提示文本
32
- * @returns 选中索引(0-based),-1 取消
33
- */
34
- export declare function showListSelection(items: string[], title?: string, prompt?: string): number;
35
- /**
36
- * 代码预览确认弹窗
37
- *
38
- * @param title 标题
39
- * @param code 代码内容
40
- * @returns 用户是否确认
41
- */
42
- export declare function showPreviewConfirm(title: string, code: string): boolean;
43
- /**
44
- * macOS / Linux / Windows 系统通知
45
- * @param message 通知内容
46
- */
47
- export declare function notify(message: string, title?: string): void;
48
- /**
49
- * macOS 带按钮的对话框
50
- * @param buttons 按钮列表(从右到左排列)
51
- * @returns 点击的按钮名,或 null 表示取消
52
- */
53
- export declare function promptWithButtons(message: string, buttons?: string[], title?: string): string | null;
@@ -1,284 +0,0 @@
1
- /**
2
- * NativeUi - macOS 原生 UI 交互层
3
- *
4
- * 三层降级策略:
5
- * 1. Swift Helper 二进制 (resources/native-ui/native-ui)
6
- * 2. AppleScript 回退 (choose from list / display alert)
7
- * 3. 控制台输出回退 (非 macOS 或非 TTY)
8
- *
9
- * V2 ESM 版本,对应 V1 NativeUi.js
10
- */
11
- import { execFileSync, execSync } from 'node:child_process';
12
- import { existsSync } from 'node:fs';
13
- import { join } from 'node:path';
14
- import { RESOURCES_DIR } from '#shared/package-root.js';
15
- const NATIVE_UI_PATH = join(RESOURCES_DIR, 'native-ui/native-ui');
16
- const NATIVE_UI_SRC = join(RESOURCES_DIR, 'native-ui/main.swift');
17
- const NATIVE_UI_COMBINED = join(RESOURCES_DIR, 'native-ui/combined-window.swift');
18
- /** 记录是否已尝试过 lazy build,避免重复 */
19
- let _lazyBuildAttempted = false;
20
- /**
21
- * 尝试即时编译 native-ui(仅 macOS + swiftc 可用时)
22
- * 只调用一次,结果缓存到 _lazyBuildAttempted
23
- */
24
- function _tryLazyBuild() {
25
- if (_lazyBuildAttempted) {
26
- return;
27
- }
28
- _lazyBuildAttempted = true;
29
- if (process.platform !== 'darwin') {
30
- return;
31
- }
32
- if (!existsSync(NATIVE_UI_SRC) || !existsSync(NATIVE_UI_COMBINED)) {
33
- return;
34
- }
35
- try {
36
- execSync('which swiftc', { stdio: 'pipe' });
37
- }
38
- catch {
39
- return;
40
- }
41
- try {
42
- execSync(`swiftc "${NATIVE_UI_SRC}" "${NATIVE_UI_COMBINED}" -o "${NATIVE_UI_PATH}" -framework AppKit`, { stdio: 'pipe', timeout: 120_000 });
43
- }
44
- catch {
45
- // 编译失败 — 静默降级
46
- }
47
- }
48
- /** 检查 Swift Helper 是否可用 */
49
- export function isNativeUiAvailable() {
50
- if (process.platform !== 'darwin') {
51
- return false;
52
- }
53
- try {
54
- if (existsSync(NATIVE_UI_PATH)) {
55
- return true;
56
- }
57
- // 二进制不存在 — 尝试即时编译
58
- _tryLazyBuild();
59
- return existsSync(NATIVE_UI_PATH);
60
- }
61
- catch {
62
- return false;
63
- }
64
- }
65
- /**
66
- * 用组合窗口展示搜索结果(列表 + 预览)
67
- *
68
- * @param items
69
- * @param keyword 搜索关键词
70
- * @returns 选中的索引(0-based),-1 表示取消
71
- */
72
- export function showCombinedWindow(items, keyword = '') {
73
- if (!items || items.length === 0) {
74
- return -1;
75
- }
76
- // 1. 尝试 Swift Helper
77
- if (isNativeUiAvailable()) {
78
- try {
79
- const safeKeyword = keyword.replace(/'/g, "'\\''");
80
- const json = JSON.stringify(items);
81
- const safeJson = json.replace(/'/g, "'\\''");
82
- const result = execFileSync(NATIVE_UI_PATH, ['combined', safeKeyword, safeJson], {
83
- encoding: 'utf8',
84
- timeout: 60000,
85
- }).trim();
86
- const index = parseInt(result, 10);
87
- return Number.isNaN(index) ? -1 : index;
88
- }
89
- catch (err) {
90
- // exit(1) = 用户取消,直接返回 -1,不降级
91
- if (err.status === 1) {
92
- return -1;
93
- }
94
- // 其他错误(崩溃等)才降级到 AppleScript
95
- }
96
- }
97
- // 2. macOS AppleScript 回退(choose from list → display dialog 预览)
98
- if (process.platform === 'darwin') {
99
- try {
100
- return _appleScriptCombinedWindow(items, keyword);
101
- }
102
- catch {
103
- // 回退
104
- }
105
- }
106
- // 3. 控制台输出回退
107
- return _consoleFallback(items, keyword);
108
- }
109
- /**
110
- * 简单列表选择弹窗
111
- *
112
- * @param items 选项列表
113
- * @param title 窗口标题
114
- * @param prompt 提示文本
115
- * @returns 选中索引(0-based),-1 取消
116
- */
117
- export function showListSelection(items, title = 'AutoSnippet', prompt = '请选择:') {
118
- if (!items || items.length === 0) {
119
- return -1;
120
- }
121
- // 1. Swift Helper
122
- if (isNativeUiAvailable()) {
123
- try {
124
- const args = ['list', ...items];
125
- const result = execFileSync(NATIVE_UI_PATH, args, {
126
- encoding: 'utf8',
127
- timeout: 60000,
128
- }).trim();
129
- const index = parseInt(result, 10);
130
- return Number.isNaN(index) ? -1 : index;
131
- }
132
- catch (err) {
133
- // exit(1) = 用户取消,直接返回
134
- if (err.status === 1) {
135
- return -1;
136
- }
137
- // 其他错误才降级
138
- }
139
- }
140
- // 2. AppleScript
141
- if (process.platform === 'darwin') {
142
- try {
143
- const listStr = items.map((i) => `"${i.replace(/"/g, '\\"')}"`).join(', ');
144
- const script = `choose from list {${listStr}} with title "${_escAS(title)}" with prompt "${_escAS(prompt)}" default items {"${_escAS(items[0])}"}`;
145
- const result = execSync(`osascript -e '${script}'`, {
146
- encoding: 'utf8',
147
- timeout: 30000,
148
- }).trim();
149
- if (result === 'false') {
150
- return -1;
151
- }
152
- return items.indexOf(result);
153
- }
154
- catch {
155
- return -1;
156
- }
157
- }
158
- return -1;
159
- }
160
- /**
161
- * 代码预览确认弹窗
162
- *
163
- * @param title 标题
164
- * @param code 代码内容
165
- * @returns 用户是否确认
166
- */
167
- export function showPreviewConfirm(title, code) {
168
- // 1. Swift Helper
169
- if (isNativeUiAvailable()) {
170
- try {
171
- const _result = execFileSync(NATIVE_UI_PATH, ['preview', title, code], {
172
- encoding: 'utf8',
173
- timeout: 60000,
174
- });
175
- return true; // exit 0 = confirmed
176
- }
177
- catch {
178
- return false;
179
- }
180
- }
181
- // 2. AppleScript
182
- if (process.platform === 'darwin') {
183
- try {
184
- const preview = code.length > 300 ? `${code.substring(0, 297)}...` : code;
185
- const script = `display dialog "${_escAS(title)}\\n\\n${_escAS(preview)}" with title "AutoSnippet" buttons {"取消", "确认"} default button "确认"`;
186
- const result = execSync(`osascript -e '${script}'`, { encoding: 'utf8', timeout: 30000 });
187
- return result.includes('确认');
188
- }
189
- catch {
190
- return false;
191
- }
192
- }
193
- return true; // 非 macOS 默认确认
194
- }
195
- /**
196
- * macOS / Linux / Windows 系统通知
197
- * @param message 通知内容
198
- */
199
- export function notify(message, title = 'AutoSnippet') {
200
- try {
201
- if (process.platform === 'darwin') {
202
- const safeMsg = message.replace(/"/g, '\\"').replace(/\n/g, '\\n');
203
- const safeTitle = title.replace(/"/g, '\\"');
204
- execSync(`osascript -e 'display notification "${safeMsg}" with title "${safeTitle}"'`, {
205
- timeout: 5000,
206
- stdio: 'ignore',
207
- });
208
- return;
209
- }
210
- if (process.platform === 'linux') {
211
- // notify-send (libnotify) — 绝大多数 Linux 桌面都有
212
- const safeMsg = message.replace(/'/g, "'\\''");
213
- const safeTitle = title.replace(/'/g, "'\\''");
214
- execSync(`notify-send '${safeTitle}' '${safeMsg}' 2>/dev/null`, {
215
- timeout: 5000,
216
- stdio: 'ignore',
217
- });
218
- return;
219
- }
220
- if (process.platform === 'win32') {
221
- // PowerShell toast notification
222
- const safeMsg = message.replace(/'/g, "''");
223
- const safeTitle = title.replace(/'/g, "''");
224
- const ps = `
225
- [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null;
226
- $template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02);
227
- $textNodes = $template.GetElementsByTagName('text');
228
- $textNodes.Item(0).AppendChild($template.CreateTextNode('${safeTitle}')) | Out-Null;
229
- $textNodes.Item(1).AppendChild($template.CreateTextNode('${safeMsg}')) | Out-Null;
230
- $toast = [Windows.UI.Notifications.ToastNotification]::new($template);
231
- [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier('AutoSnippet').Show($toast);
232
- `.replace(/\n\s+/g, ' ');
233
- execSync(`powershell.exe -NoProfile -Command "${ps}"`, {
234
- timeout: 5000,
235
- stdio: 'ignore',
236
- });
237
- }
238
- }
239
- catch {
240
- /* Windows toast notification is best-effort */
241
- }
242
- }
243
- /**
244
- * macOS 带按钮的对话框
245
- * @param buttons 按钮列表(从右到左排列)
246
- * @returns 点击的按钮名,或 null 表示取消
247
- */
248
- export function promptWithButtons(message, buttons = ['确认', '取消'], title = 'AutoSnippet') {
249
- if (process.platform !== 'darwin') {
250
- return null;
251
- }
252
- try {
253
- const btnStr = buttons.map((b) => `"${_escAS(b)}"`).join(', ');
254
- const script = `display dialog "${_escAS(message)}" with title "${_escAS(title)}" buttons {${btnStr}} default button "${_escAS(buttons[0])}"`;
255
- const result = execSync(`osascript -e '${script}'`, { encoding: 'utf8', timeout: 30000 });
256
- const match = result.match(/button returned:(.+)/);
257
- return match ? match[1].trim() : null;
258
- }
259
- catch {
260
- return null;
261
- }
262
- }
263
- /* ────────── 内部实现 ────────── */
264
- function _escAS(str) {
265
- return String(str || '')
266
- .replace(/\\/g, '\\\\')
267
- .replace(/"/g, '\\"')
268
- .replace(/\n/g, '\\n');
269
- }
270
- function _appleScriptCombinedWindow(items, keyword) {
271
- // 两步:先选择,再预览确认
272
- const titles = items.map((it, i) => `${i + 1}. ${it.title || 'Recipe'}`);
273
- const idx = showListSelection(titles, 'AutoSnippet Search', `搜索: ${keyword}`);
274
- if (idx < 0 || idx >= items.length) {
275
- return -1;
276
- }
277
- const item = items[idx];
278
- const confirmed = showPreviewConfirm(item.title || 'Recipe', item.code || item.explanation || '');
279
- return confirmed ? idx : -1;
280
- }
281
- function _consoleFallback(items, _keyword) {
282
- items.forEach((_item, _i) => { });
283
- return -1;
284
- }
@@ -1,38 +0,0 @@
1
- /**
2
- * @module platform/ios
3
- * @description iOS + Xcode 平台支持模块
4
- *
5
- * 将所有 iOS/Xcode 特有功能集中到 lib/platform/ios/ 下:
6
- *
7
- * xcode/
8
- * XcodeAutomation.js — AppleScript/osascript Xcode IDE 自动化
9
- * XcodeIntegration.js — Xcode 代码自动插入 + Header 管理 + 依赖检查
10
- * SaveEventFilter.js — 保存事件过滤(Xcode 焦点检测 + 内容哈希去重)
11
- *
12
- * snippet/
13
- * XcodeCodec.js — Xcode .codesnippet (plist XML) 编解码
14
- * PlaceholderConverter.js — Xcode <#…#> ↔ VSCode ${N:…} 占位符转换
15
- *
16
- * spm/
17
- * SpmHelper.js — SPM 包结构解析与依赖操作辅助工具
18
- * SpmDiscoverer.js — SPM 项目自动发现(ProjectDiscoverer 接口)
19
- * PackageSwiftParser.js — Package.swift 解析器
20
- * DependencyGraph.js — SPM Target 依赖图
21
- * PolicyEngine.js — 依赖策略引擎(层级检查 / 循环检测)
22
- *
23
- * routes/
24
- * spm.js — /api/v1/spm/* REST 路由(向后兼容遗留端点)
25
- *
26
- * 旧路径保留了 re-export shim 确保向后兼容。
27
- */
28
- export { default as spmRouter } from './routes/spm.js';
29
- export { PlaceholderConverter } from './snippet/PlaceholderConverter.js';
30
- export { XcodeCodec } from './snippet/XcodeCodec.js';
31
- export { DependencyGraph } from './spm/DependencyGraph.js';
32
- export { PackageSwiftParser } from './spm/PackageSwiftParser.js';
33
- export { PolicyEngine } from './spm/PolicyEngine.js';
34
- export { SpmDiscoverer } from './spm/SpmDiscoverer.js';
35
- export { SpmHelper } from './spm/SpmHelper.js';
36
- export { saveEventFilter } from './xcode/SaveEventFilter.js';
37
- export { cutLineInXcode, deleteLineContentInXcode, insertAtLineStartInXcode, isXcodeFrontmost, isXcodeRunning, jumpToLineInXcode, pasteInXcode, saveActiveDocumentInXcode, selectAndPasteInXcode, } from './xcode/XcodeAutomation.js';
38
- export { findImportInsertLine, findTriggerLineNumber, insertCodeToXcode, insertHeaders, } from './xcode/XcodeIntegration.js';
@@ -1,42 +0,0 @@
1
- /**
2
- * @module platform/ios
3
- * @description iOS + Xcode 平台支持模块
4
- *
5
- * 将所有 iOS/Xcode 特有功能集中到 lib/platform/ios/ 下:
6
- *
7
- * xcode/
8
- * XcodeAutomation.js — AppleScript/osascript Xcode IDE 自动化
9
- * XcodeIntegration.js — Xcode 代码自动插入 + Header 管理 + 依赖检查
10
- * SaveEventFilter.js — 保存事件过滤(Xcode 焦点检测 + 内容哈希去重)
11
- *
12
- * snippet/
13
- * XcodeCodec.js — Xcode .codesnippet (plist XML) 编解码
14
- * PlaceholderConverter.js — Xcode <#…#> ↔ VSCode ${N:…} 占位符转换
15
- *
16
- * spm/
17
- * SpmHelper.js — SPM 包结构解析与依赖操作辅助工具
18
- * SpmDiscoverer.js — SPM 项目自动发现(ProjectDiscoverer 接口)
19
- * PackageSwiftParser.js — Package.swift 解析器
20
- * DependencyGraph.js — SPM Target 依赖图
21
- * PolicyEngine.js — 依赖策略引擎(层级检查 / 循环检测)
22
- *
23
- * routes/
24
- * spm.js — /api/v1/spm/* REST 路由(向后兼容遗留端点)
25
- *
26
- * 旧路径保留了 re-export shim 确保向后兼容。
27
- */
28
- // ── SPM Legacy Routes ──
29
- export { default as spmRouter } from './routes/spm.js';
30
- export { PlaceholderConverter } from './snippet/PlaceholderConverter.js';
31
- // ── Xcode Snippet 编解码 ──
32
- export { XcodeCodec } from './snippet/XcodeCodec.js';
33
- export { DependencyGraph } from './spm/DependencyGraph.js';
34
- export { PackageSwiftParser } from './spm/PackageSwiftParser.js';
35
- export { PolicyEngine } from './spm/PolicyEngine.js';
36
- export { SpmDiscoverer } from './spm/SpmDiscoverer.js';
37
- // ── Swift Package Manager ──
38
- export { SpmHelper } from './spm/SpmHelper.js';
39
- export { saveEventFilter } from './xcode/SaveEventFilter.js';
40
- // ── Xcode IDE 自动化 ──
41
- export { cutLineInXcode, deleteLineContentInXcode, insertAtLineStartInXcode, isXcodeFrontmost, isXcodeRunning, jumpToLineInXcode, pasteInXcode, saveActiveDocumentInXcode, selectAndPasteInXcode, } from './xcode/XcodeAutomation.js';
42
- export { findImportInsertLine, findTriggerLineNumber, insertCodeToXcode, insertHeaders, } from './xcode/XcodeIntegration.js';
@@ -1,9 +0,0 @@
1
- /**
2
- * SPM API 路由 — 向后兼容层
3
- *
4
- * 所有端点统一委派到 ModuleService(语言无关模块扫描服务)。
5
- * SPM Discoverer 作为 ModuleService 的一个 discoverer 自动匹配 Swift/SPM 项目。
6
- * 新代码应直接使用 /api/v1/modules/* 端点。
7
- */
8
- declare const router: import("express-serve-static-core").Router;
9
- export default router;