openspec-cn 0.23.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.
- package/LICENSE +22 -0
- package/README.md +153 -0
- package/bin/openspec.js +3 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +480 -0
- package/dist/commands/change.d.ts +35 -0
- package/dist/commands/change.js +277 -0
- package/dist/commands/completion.d.ts +72 -0
- package/dist/commands/completion.js +257 -0
- package/dist/commands/config.d.ts +8 -0
- package/dist/commands/config.js +198 -0
- package/dist/commands/feedback.d.ts +9 -0
- package/dist/commands/feedback.js +183 -0
- package/dist/commands/schema.d.ts +6 -0
- package/dist/commands/schema.js +869 -0
- package/dist/commands/show.d.ts +14 -0
- package/dist/commands/show.js +132 -0
- package/dist/commands/spec.d.ts +15 -0
- package/dist/commands/spec.js +225 -0
- package/dist/commands/validate.d.ts +24 -0
- package/dist/commands/validate.js +294 -0
- package/dist/commands/workflow/index.d.ts +17 -0
- package/dist/commands/workflow/index.js +12 -0
- package/dist/commands/workflow/instructions.d.ts +29 -0
- package/dist/commands/workflow/instructions.js +381 -0
- package/dist/commands/workflow/new-change.d.ts +11 -0
- package/dist/commands/workflow/new-change.js +44 -0
- package/dist/commands/workflow/schemas.d.ts +10 -0
- package/dist/commands/workflow/schemas.js +34 -0
- package/dist/commands/workflow/shared.d.ts +52 -0
- package/dist/commands/workflow/shared.js +111 -0
- package/dist/commands/workflow/status.d.ts +14 -0
- package/dist/commands/workflow/status.js +58 -0
- package/dist/commands/workflow/templates.d.ts +16 -0
- package/dist/commands/workflow/templates.js +68 -0
- package/dist/core/archive.d.ts +11 -0
- package/dist/core/archive.js +280 -0
- package/dist/core/artifact-graph/graph.d.ts +56 -0
- package/dist/core/artifact-graph/graph.js +141 -0
- package/dist/core/artifact-graph/index.d.ts +7 -0
- package/dist/core/artifact-graph/index.js +13 -0
- package/dist/core/artifact-graph/instruction-loader.d.ts +143 -0
- package/dist/core/artifact-graph/instruction-loader.js +214 -0
- package/dist/core/artifact-graph/resolver.d.ts +81 -0
- package/dist/core/artifact-graph/resolver.js +257 -0
- package/dist/core/artifact-graph/schema.d.ts +13 -0
- package/dist/core/artifact-graph/schema.js +108 -0
- package/dist/core/artifact-graph/state.d.ts +12 -0
- package/dist/core/artifact-graph/state.js +54 -0
- package/dist/core/artifact-graph/types.d.ts +45 -0
- package/dist/core/artifact-graph/types.js +43 -0
- package/dist/core/command-generation/adapters/amazon-q.d.ts +13 -0
- package/dist/core/command-generation/adapters/amazon-q.js +26 -0
- package/dist/core/command-generation/adapters/antigravity.d.ts +13 -0
- package/dist/core/command-generation/adapters/antigravity.js +26 -0
- package/dist/core/command-generation/adapters/auggie.d.ts +13 -0
- package/dist/core/command-generation/adapters/auggie.js +27 -0
- package/dist/core/command-generation/adapters/claude.d.ts +13 -0
- package/dist/core/command-generation/adapters/claude.js +50 -0
- package/dist/core/command-generation/adapters/cline.d.ts +14 -0
- package/dist/core/command-generation/adapters/cline.js +27 -0
- package/dist/core/command-generation/adapters/codebuddy.d.ts +13 -0
- package/dist/core/command-generation/adapters/codebuddy.js +28 -0
- package/dist/core/command-generation/adapters/codex.d.ts +13 -0
- package/dist/core/command-generation/adapters/codex.js +27 -0
- package/dist/core/command-generation/adapters/continue.d.ts +13 -0
- package/dist/core/command-generation/adapters/continue.js +28 -0
- package/dist/core/command-generation/adapters/costrict.d.ts +13 -0
- package/dist/core/command-generation/adapters/costrict.js +27 -0
- package/dist/core/command-generation/adapters/crush.d.ts +13 -0
- package/dist/core/command-generation/adapters/crush.js +30 -0
- package/dist/core/command-generation/adapters/cursor.d.ts +14 -0
- package/dist/core/command-generation/adapters/cursor.js +44 -0
- package/dist/core/command-generation/adapters/factory.d.ts +13 -0
- package/dist/core/command-generation/adapters/factory.js +27 -0
- package/dist/core/command-generation/adapters/gemini.d.ts +13 -0
- package/dist/core/command-generation/adapters/gemini.js +26 -0
- package/dist/core/command-generation/adapters/github-copilot.d.ts +13 -0
- package/dist/core/command-generation/adapters/github-copilot.js +26 -0
- package/dist/core/command-generation/adapters/iflow.d.ts +13 -0
- package/dist/core/command-generation/adapters/iflow.js +29 -0
- package/dist/core/command-generation/adapters/index.d.ts +27 -0
- package/dist/core/command-generation/adapters/index.js +27 -0
- package/dist/core/command-generation/adapters/kilocode.d.ts +14 -0
- package/dist/core/command-generation/adapters/kilocode.js +23 -0
- package/dist/core/command-generation/adapters/opencode.d.ts +13 -0
- package/dist/core/command-generation/adapters/opencode.js +26 -0
- package/dist/core/command-generation/adapters/qoder.d.ts +13 -0
- package/dist/core/command-generation/adapters/qoder.js +30 -0
- package/dist/core/command-generation/adapters/qwen.d.ts +13 -0
- package/dist/core/command-generation/adapters/qwen.js +26 -0
- package/dist/core/command-generation/adapters/roocode.d.ts +14 -0
- package/dist/core/command-generation/adapters/roocode.js +27 -0
- package/dist/core/command-generation/adapters/windsurf.d.ts +14 -0
- package/dist/core/command-generation/adapters/windsurf.js +51 -0
- package/dist/core/command-generation/generator.d.ts +21 -0
- package/dist/core/command-generation/generator.js +27 -0
- package/dist/core/command-generation/index.d.ts +22 -0
- package/dist/core/command-generation/index.js +24 -0
- package/dist/core/command-generation/registry.d.ts +36 -0
- package/dist/core/command-generation/registry.js +88 -0
- package/dist/core/command-generation/types.d.ts +55 -0
- package/dist/core/command-generation/types.js +8 -0
- package/dist/core/completions/command-registry.d.ts +7 -0
- package/dist/core/completions/command-registry.js +456 -0
- package/dist/core/completions/completion-provider.d.ts +60 -0
- package/dist/core/completions/completion-provider.js +102 -0
- package/dist/core/completions/factory.d.ts +64 -0
- package/dist/core/completions/factory.js +75 -0
- package/dist/core/completions/generators/bash-generator.d.ts +32 -0
- package/dist/core/completions/generators/bash-generator.js +174 -0
- package/dist/core/completions/generators/fish-generator.d.ts +32 -0
- package/dist/core/completions/generators/fish-generator.js +157 -0
- package/dist/core/completions/generators/powershell-generator.d.ts +33 -0
- package/dist/core/completions/generators/powershell-generator.js +207 -0
- package/dist/core/completions/generators/zsh-generator.d.ts +44 -0
- package/dist/core/completions/generators/zsh-generator.js +250 -0
- package/dist/core/completions/installers/bash-installer.d.ts +87 -0
- package/dist/core/completions/installers/bash-installer.js +318 -0
- package/dist/core/completions/installers/fish-installer.d.ts +43 -0
- package/dist/core/completions/installers/fish-installer.js +143 -0
- package/dist/core/completions/installers/powershell-installer.d.ts +88 -0
- package/dist/core/completions/installers/powershell-installer.js +327 -0
- package/dist/core/completions/installers/zsh-installer.d.ts +125 -0
- package/dist/core/completions/installers/zsh-installer.js +449 -0
- package/dist/core/completions/templates/bash-templates.d.ts +6 -0
- package/dist/core/completions/templates/bash-templates.js +24 -0
- package/dist/core/completions/templates/fish-templates.d.ts +7 -0
- package/dist/core/completions/templates/fish-templates.js +39 -0
- package/dist/core/completions/templates/powershell-templates.d.ts +6 -0
- package/dist/core/completions/templates/powershell-templates.js +25 -0
- package/dist/core/completions/templates/zsh-templates.d.ts +6 -0
- package/dist/core/completions/templates/zsh-templates.js +36 -0
- package/dist/core/completions/types.d.ts +79 -0
- package/dist/core/completions/types.js +2 -0
- package/dist/core/config-prompts.d.ts +9 -0
- package/dist/core/config-prompts.js +34 -0
- package/dist/core/config-schema.d.ts +76 -0
- package/dist/core/config-schema.js +200 -0
- package/dist/core/config.d.ts +17 -0
- package/dist/core/config.js +30 -0
- package/dist/core/converters/json-converter.d.ts +6 -0
- package/dist/core/converters/json-converter.js +51 -0
- package/dist/core/global-config.d.ts +39 -0
- package/dist/core/global-config.js +115 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +3 -0
- package/dist/core/init.d.ts +32 -0
- package/dist/core/init.js +433 -0
- package/dist/core/legacy-cleanup.d.ts +162 -0
- package/dist/core/legacy-cleanup.js +501 -0
- package/dist/core/list.d.ts +9 -0
- package/dist/core/list.js +171 -0
- package/dist/core/parsers/change-parser.d.ts +13 -0
- package/dist/core/parsers/change-parser.js +193 -0
- package/dist/core/parsers/markdown-parser.d.ts +22 -0
- package/dist/core/parsers/markdown-parser.js +187 -0
- package/dist/core/parsers/requirement-blocks.d.ts +37 -0
- package/dist/core/parsers/requirement-blocks.js +201 -0
- package/dist/core/project-config.d.ts +64 -0
- package/dist/core/project-config.js +223 -0
- package/dist/core/schemas/base.schema.d.ts +13 -0
- package/dist/core/schemas/base.schema.js +13 -0
- package/dist/core/schemas/change.schema.d.ts +73 -0
- package/dist/core/schemas/change.schema.js +31 -0
- package/dist/core/schemas/index.d.ts +4 -0
- package/dist/core/schemas/index.js +4 -0
- package/dist/core/schemas/spec.schema.d.ts +18 -0
- package/dist/core/schemas/spec.schema.js +15 -0
- package/dist/core/shared/index.d.ts +8 -0
- package/dist/core/shared/index.js +8 -0
- package/dist/core/shared/skill-generation.d.ts +41 -0
- package/dist/core/shared/skill-generation.js +74 -0
- package/dist/core/shared/tool-detection.d.ts +66 -0
- package/dist/core/shared/tool-detection.js +140 -0
- package/dist/core/specs-apply.d.ts +73 -0
- package/dist/core/specs-apply.js +384 -0
- package/dist/core/styles/palette.d.ts +7 -0
- package/dist/core/styles/palette.js +8 -0
- package/dist/core/templates/index.d.ts +8 -0
- package/dist/core/templates/index.js +9 -0
- package/dist/core/templates/skill-templates.d.ts +112 -0
- package/dist/core/templates/skill-templates.js +2893 -0
- package/dist/core/update.d.ts +42 -0
- package/dist/core/update.js +306 -0
- package/dist/core/validation/constants.d.ts +34 -0
- package/dist/core/validation/constants.js +40 -0
- package/dist/core/validation/types.d.ts +18 -0
- package/dist/core/validation/types.js +2 -0
- package/dist/core/validation/validator.d.ts +33 -0
- package/dist/core/validation/validator.js +409 -0
- package/dist/core/view.d.ts +8 -0
- package/dist/core/view.js +168 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/prompts/searchable-multi-select.d.ts +27 -0
- package/dist/prompts/searchable-multi-select.js +149 -0
- package/dist/telemetry/config.d.ts +32 -0
- package/dist/telemetry/config.js +68 -0
- package/dist/telemetry/index.d.ts +31 -0
- package/dist/telemetry/index.js +145 -0
- package/dist/ui/ascii-patterns.d.ts +16 -0
- package/dist/ui/ascii-patterns.js +133 -0
- package/dist/ui/welcome-screen.d.ts +10 -0
- package/dist/ui/welcome-screen.js +146 -0
- package/dist/utils/change-metadata.d.ts +51 -0
- package/dist/utils/change-metadata.js +147 -0
- package/dist/utils/change-utils.d.ts +62 -0
- package/dist/utils/change-utils.js +121 -0
- package/dist/utils/file-system.d.ts +36 -0
- package/dist/utils/file-system.js +281 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.js +7 -0
- package/dist/utils/interactive.d.ts +18 -0
- package/dist/utils/interactive.js +21 -0
- package/dist/utils/item-discovery.d.ts +4 -0
- package/dist/utils/item-discovery.js +72 -0
- package/dist/utils/match.d.ts +3 -0
- package/dist/utils/match.js +22 -0
- package/dist/utils/shell-detection.d.ts +20 -0
- package/dist/utils/shell-detection.js +41 -0
- package/dist/utils/task-progress.d.ts +8 -0
- package/dist/utils/task-progress.js +36 -0
- package/package.json +84 -0
- package/schemas/spec-driven/schema.yaml +148 -0
- package/schemas/spec-driven/templates/design.md +19 -0
- package/schemas/spec-driven/templates/proposal.md +23 -0
- package/schemas/spec-driven/templates/spec.md +8 -0
- package/schemas/spec-driven/templates/tasks.md +9 -0
- package/schemas/tdd/schema.yaml +213 -0
- package/schemas/tdd/templates/docs.md +15 -0
- package/schemas/tdd/templates/implementation.md +11 -0
- package/schemas/tdd/templates/spec.md +11 -0
- package/schemas/tdd/templates/test.md +11 -0
- package/scripts/postinstall.js +147 -0
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import os from 'os';
|
|
4
|
+
/**
|
|
5
|
+
* Installer for PowerShell completion scripts.
|
|
6
|
+
* Works with both Windows PowerShell 5.1 and PowerShell Core 7+
|
|
7
|
+
*/
|
|
8
|
+
export class PowerShellInstaller {
|
|
9
|
+
homeDir;
|
|
10
|
+
/**
|
|
11
|
+
* Markers for PowerShell profile configuration management
|
|
12
|
+
*/
|
|
13
|
+
PROFILE_MARKERS = {
|
|
14
|
+
start: '# OPENSPEC:START',
|
|
15
|
+
end: '# OPENSPEC:END',
|
|
16
|
+
};
|
|
17
|
+
constructor(homeDir = os.homedir()) {
|
|
18
|
+
this.homeDir = homeDir;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Get PowerShell profile path
|
|
22
|
+
* Prefers $PROFILE environment variable, falls back to platform defaults
|
|
23
|
+
*
|
|
24
|
+
* @returns Profile path
|
|
25
|
+
*/
|
|
26
|
+
getProfilePath() {
|
|
27
|
+
// Check $PROFILE environment variable (set when running in PowerShell)
|
|
28
|
+
if (process.env.PROFILE) {
|
|
29
|
+
return process.env.PROFILE;
|
|
30
|
+
}
|
|
31
|
+
// Fall back to platform-specific defaults
|
|
32
|
+
if (process.platform === 'win32') {
|
|
33
|
+
// Windows: Documents/PowerShell/Microsoft.PowerShell_profile.ps1
|
|
34
|
+
return path.join(this.homeDir, 'Documents', 'PowerShell', 'Microsoft.PowerShell_profile.ps1');
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
// macOS/Linux: .config/powershell/Microsoft.PowerShell_profile.ps1
|
|
38
|
+
return path.join(this.homeDir, '.config', 'powershell', 'Microsoft.PowerShell_profile.ps1');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get all PowerShell profile paths to configure.
|
|
43
|
+
* On Windows, returns both PowerShell Core and Windows PowerShell 5.1 paths.
|
|
44
|
+
* On Unix, returns PowerShell Core path only.
|
|
45
|
+
*/
|
|
46
|
+
getAllProfilePaths() {
|
|
47
|
+
// If PROFILE env var is set, use only that path
|
|
48
|
+
if (process.env.PROFILE) {
|
|
49
|
+
return [process.env.PROFILE];
|
|
50
|
+
}
|
|
51
|
+
if (process.platform === 'win32') {
|
|
52
|
+
return [
|
|
53
|
+
// PowerShell Core 6+ (cross-platform)
|
|
54
|
+
path.join(this.homeDir, 'Documents', 'PowerShell', 'Microsoft.PowerShell_profile.ps1'),
|
|
55
|
+
// Windows PowerShell 5.1 (Windows-only)
|
|
56
|
+
path.join(this.homeDir, 'Documents', 'WindowsPowerShell', 'Microsoft.PowerShell_profile.ps1'),
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
// Unix systems: PowerShell Core only
|
|
61
|
+
return [path.join(this.homeDir, '.config', 'powershell', 'Microsoft.PowerShell_profile.ps1')];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get the installation path for the completion script
|
|
66
|
+
*
|
|
67
|
+
* @returns Installation path
|
|
68
|
+
*/
|
|
69
|
+
getInstallationPath() {
|
|
70
|
+
const profilePath = this.getProfilePath();
|
|
71
|
+
const profileDir = path.dirname(profilePath);
|
|
72
|
+
return path.join(profileDir, 'OpenSpecCompletion.ps1');
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Backup an existing completion file if it exists
|
|
76
|
+
*
|
|
77
|
+
* @param targetPath - Path to the file to backup
|
|
78
|
+
* @returns Path to the backup file, or undefined if no backup was needed
|
|
79
|
+
*/
|
|
80
|
+
async backupExistingFile(targetPath) {
|
|
81
|
+
try {
|
|
82
|
+
await fs.access(targetPath);
|
|
83
|
+
// File exists, create a backup
|
|
84
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
85
|
+
const backupPath = `${targetPath}.backup-${timestamp}`;
|
|
86
|
+
await fs.copyFile(targetPath, backupPath);
|
|
87
|
+
return backupPath;
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
// File doesn't exist, no backup needed
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Generate PowerShell profile configuration content
|
|
96
|
+
*
|
|
97
|
+
* @param scriptPath - Path to the completion script
|
|
98
|
+
* @returns Configuration content
|
|
99
|
+
*/
|
|
100
|
+
generateProfileConfig(scriptPath) {
|
|
101
|
+
return [
|
|
102
|
+
'# OpenSpec shell completions configuration',
|
|
103
|
+
`if (Test-Path "${scriptPath}") {`,
|
|
104
|
+
` . "${scriptPath}"`,
|
|
105
|
+
'}',
|
|
106
|
+
].join('\n');
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Configure PowerShell profile to source the completion script
|
|
110
|
+
*
|
|
111
|
+
* @param scriptPath - Path to the completion script
|
|
112
|
+
* @returns true if configured successfully, false otherwise
|
|
113
|
+
*/
|
|
114
|
+
async configureProfile(scriptPath) {
|
|
115
|
+
const profilePaths = this.getAllProfilePaths();
|
|
116
|
+
let anyConfigured = false;
|
|
117
|
+
for (const profilePath of profilePaths) {
|
|
118
|
+
try {
|
|
119
|
+
// Create profile file if it doesn't exist
|
|
120
|
+
const profileDir = path.dirname(profilePath);
|
|
121
|
+
await fs.mkdir(profileDir, { recursive: true });
|
|
122
|
+
let profileContent = '';
|
|
123
|
+
try {
|
|
124
|
+
profileContent = await fs.readFile(profilePath, 'utf-8');
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
// Profile doesn't exist yet, that's fine
|
|
128
|
+
}
|
|
129
|
+
// Check if already configured
|
|
130
|
+
const scriptLine = `. "${scriptPath}"`;
|
|
131
|
+
if (profileContent.includes(scriptLine)) {
|
|
132
|
+
continue; // Already configured, skip
|
|
133
|
+
}
|
|
134
|
+
// Add OpenSpec completion configuration with markers
|
|
135
|
+
const openspecBlock = [
|
|
136
|
+
'',
|
|
137
|
+
'# OPENSPEC:START - OpenSpec completion (managed block, do not edit manually)',
|
|
138
|
+
scriptLine,
|
|
139
|
+
'# OPENSPEC:END',
|
|
140
|
+
'',
|
|
141
|
+
].join('\n');
|
|
142
|
+
const newContent = profileContent + openspecBlock;
|
|
143
|
+
await fs.writeFile(profilePath, newContent, 'utf-8');
|
|
144
|
+
anyConfigured = true;
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
// Continue to next profile if this one fails
|
|
148
|
+
console.warn(`Warning: Could not configure ${profilePath}: ${error}`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return anyConfigured;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Remove PowerShell profile configuration
|
|
155
|
+
* Used during uninstallation
|
|
156
|
+
*
|
|
157
|
+
* @returns true if removed successfully, false otherwise
|
|
158
|
+
*/
|
|
159
|
+
async removeProfileConfig() {
|
|
160
|
+
const profilePaths = this.getAllProfilePaths();
|
|
161
|
+
let anyRemoved = false;
|
|
162
|
+
for (const profilePath of profilePaths) {
|
|
163
|
+
try {
|
|
164
|
+
// Read profile content
|
|
165
|
+
let profileContent;
|
|
166
|
+
try {
|
|
167
|
+
profileContent = await fs.readFile(profilePath, 'utf-8');
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
continue; // Profile doesn't exist, nothing to remove
|
|
171
|
+
}
|
|
172
|
+
// Remove OPENSPEC:START -> OPENSPEC:END block
|
|
173
|
+
const startMarker = '# OPENSPEC:START';
|
|
174
|
+
const endMarker = '# OPENSPEC:END';
|
|
175
|
+
const startIndex = profileContent.indexOf(startMarker);
|
|
176
|
+
if (startIndex === -1) {
|
|
177
|
+
continue; // No OpenSpec block found
|
|
178
|
+
}
|
|
179
|
+
const endIndex = profileContent.indexOf(endMarker, startIndex);
|
|
180
|
+
if (endIndex === -1) {
|
|
181
|
+
console.warn(`Warning: Found start marker but no end marker in ${profilePath}`);
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
// Remove the block (including markers and surrounding newlines)
|
|
185
|
+
const beforeBlock = profileContent.substring(0, startIndex);
|
|
186
|
+
const afterBlock = profileContent.substring(endIndex + endMarker.length);
|
|
187
|
+
// Clean up extra newlines
|
|
188
|
+
const newContent = (beforeBlock.trimEnd() + '\n' + afterBlock.trimStart()).trim() + '\n';
|
|
189
|
+
await fs.writeFile(profilePath, newContent, 'utf-8');
|
|
190
|
+
anyRemoved = true;
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
console.warn(`Warning: Could not clean ${profilePath}: ${error}`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return anyRemoved;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Install the completion script
|
|
200
|
+
*
|
|
201
|
+
* @param completionScript - The completion script content to install
|
|
202
|
+
* @returns Installation result with status and instructions
|
|
203
|
+
*/
|
|
204
|
+
async install(completionScript) {
|
|
205
|
+
try {
|
|
206
|
+
const targetPath = this.getInstallationPath();
|
|
207
|
+
// Check if already installed with same content
|
|
208
|
+
let isUpdate = false;
|
|
209
|
+
try {
|
|
210
|
+
const existingContent = await fs.readFile(targetPath, 'utf-8');
|
|
211
|
+
if (existingContent === completionScript) {
|
|
212
|
+
// Already installed and up to date
|
|
213
|
+
return {
|
|
214
|
+
success: true,
|
|
215
|
+
installedPath: targetPath,
|
|
216
|
+
message: 'Completion script is already installed (up to date)',
|
|
217
|
+
instructions: [
|
|
218
|
+
'The completion script is already installed and up to date.',
|
|
219
|
+
'If completions are not working, try restarting PowerShell or run: . $PROFILE',
|
|
220
|
+
],
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
// File exists but content is different - this is an update
|
|
224
|
+
isUpdate = true;
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
// File doesn't exist or can't be read, proceed with installation
|
|
228
|
+
console.debug(`Unable to read existing completion file at ${targetPath}: ${error.message}`);
|
|
229
|
+
}
|
|
230
|
+
// Ensure the directory exists
|
|
231
|
+
const targetDir = path.dirname(targetPath);
|
|
232
|
+
await fs.mkdir(targetDir, { recursive: true });
|
|
233
|
+
// Backup existing file if updating
|
|
234
|
+
const backupPath = isUpdate ? await this.backupExistingFile(targetPath) : undefined;
|
|
235
|
+
// Write the completion script
|
|
236
|
+
await fs.writeFile(targetPath, completionScript, 'utf-8');
|
|
237
|
+
// Auto-configure PowerShell profile
|
|
238
|
+
const profileConfigured = await this.configureProfile(targetPath);
|
|
239
|
+
// Generate instructions if profile wasn't auto-configured
|
|
240
|
+
const instructions = profileConfigured ? undefined : this.generateInstructions(targetPath);
|
|
241
|
+
// Determine appropriate message
|
|
242
|
+
let message;
|
|
243
|
+
if (isUpdate) {
|
|
244
|
+
message = backupPath
|
|
245
|
+
? 'Completion script updated successfully (previous version backed up)'
|
|
246
|
+
: 'Completion script updated successfully';
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
message = profileConfigured
|
|
250
|
+
? 'Completion script installed and PowerShell profile configured successfully'
|
|
251
|
+
: 'Completion script installed successfully for PowerShell';
|
|
252
|
+
}
|
|
253
|
+
return {
|
|
254
|
+
success: true,
|
|
255
|
+
installedPath: targetPath,
|
|
256
|
+
backupPath,
|
|
257
|
+
profileConfigured,
|
|
258
|
+
message,
|
|
259
|
+
instructions,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
catch (error) {
|
|
263
|
+
return {
|
|
264
|
+
success: false,
|
|
265
|
+
message: `Failed to install completion script: ${error instanceof Error ? error.message : String(error)}`,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Generate user instructions for enabling completions
|
|
271
|
+
*
|
|
272
|
+
* @param installedPath - Path where the script was installed
|
|
273
|
+
* @returns Array of instruction strings
|
|
274
|
+
*/
|
|
275
|
+
generateInstructions(installedPath) {
|
|
276
|
+
const profilePath = this.getProfilePath();
|
|
277
|
+
return [
|
|
278
|
+
'Completion script installed successfully.',
|
|
279
|
+
'',
|
|
280
|
+
`To enable completions, add the following to your PowerShell profile (${profilePath}):`,
|
|
281
|
+
'',
|
|
282
|
+
' # Source OpenSpec completions',
|
|
283
|
+
` if (Test-Path "${installedPath}") {`,
|
|
284
|
+
` . "${installedPath}"`,
|
|
285
|
+
' }',
|
|
286
|
+
'',
|
|
287
|
+
'Then restart PowerShell or run: . $PROFILE',
|
|
288
|
+
];
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Uninstall the completion script
|
|
292
|
+
*
|
|
293
|
+
* @param options - Optional uninstall options
|
|
294
|
+
* @param options.yes - Skip confirmation prompt (handled by command layer)
|
|
295
|
+
* @returns Uninstallation result
|
|
296
|
+
*/
|
|
297
|
+
async uninstall(options) {
|
|
298
|
+
try {
|
|
299
|
+
const targetPath = this.getInstallationPath();
|
|
300
|
+
// Check if installed
|
|
301
|
+
try {
|
|
302
|
+
await fs.access(targetPath);
|
|
303
|
+
}
|
|
304
|
+
catch {
|
|
305
|
+
return {
|
|
306
|
+
success: false,
|
|
307
|
+
message: 'Completion script is not installed',
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
// Remove the completion script
|
|
311
|
+
await fs.unlink(targetPath);
|
|
312
|
+
// Remove profile configuration
|
|
313
|
+
await this.removeProfileConfig();
|
|
314
|
+
return {
|
|
315
|
+
success: true,
|
|
316
|
+
message: 'Completion script uninstalled successfully',
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
catch (error) {
|
|
320
|
+
return {
|
|
321
|
+
success: false,
|
|
322
|
+
message: `Failed to uninstall completion script: ${error instanceof Error ? error.message : String(error)}`,
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
//# sourceMappingURL=powershell-installer.js.map
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { InstallationResult } from '../factory.js';
|
|
2
|
+
/**
|
|
3
|
+
* Installer for Zsh completion scripts.
|
|
4
|
+
* Supports both Oh My Zsh and standard Zsh configurations.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ZshInstaller {
|
|
7
|
+
private readonly homeDir;
|
|
8
|
+
/**
|
|
9
|
+
* Markers for .zshrc configuration management
|
|
10
|
+
*/
|
|
11
|
+
private readonly ZSHRC_MARKERS;
|
|
12
|
+
constructor(homeDir?: string);
|
|
13
|
+
/**
|
|
14
|
+
* Check if Oh My Zsh is installed
|
|
15
|
+
*
|
|
16
|
+
* @returns true if Oh My Zsh is detected via $ZSH env var or directory exists
|
|
17
|
+
*/
|
|
18
|
+
isOhMyZshInstalled(): Promise<boolean>;
|
|
19
|
+
/**
|
|
20
|
+
* Get the appropriate installation path for the completion script
|
|
21
|
+
*
|
|
22
|
+
* @returns Object with installation path and whether it's Oh My Zsh
|
|
23
|
+
*/
|
|
24
|
+
getInstallationPath(): Promise<{
|
|
25
|
+
path: string;
|
|
26
|
+
isOhMyZsh: boolean;
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* Backup an existing completion file if it exists
|
|
30
|
+
*
|
|
31
|
+
* @param targetPath - Path to the file to backup
|
|
32
|
+
* @returns Path to the backup file, or undefined if no backup was needed
|
|
33
|
+
*/
|
|
34
|
+
backupExistingFile(targetPath: string): Promise<string | undefined>;
|
|
35
|
+
/**
|
|
36
|
+
* Get the path to .zshrc file
|
|
37
|
+
*
|
|
38
|
+
* @returns Path to .zshrc
|
|
39
|
+
*/
|
|
40
|
+
private getZshrcPath;
|
|
41
|
+
/**
|
|
42
|
+
* Generate .zshrc configuration content
|
|
43
|
+
*
|
|
44
|
+
* @param completionsDir - Directory containing completion scripts
|
|
45
|
+
* @returns Configuration content
|
|
46
|
+
*/
|
|
47
|
+
private generateZshrcConfig;
|
|
48
|
+
/**
|
|
49
|
+
* Configure .zshrc to enable completions
|
|
50
|
+
* Only applies to standard Zsh (not Oh My Zsh)
|
|
51
|
+
*
|
|
52
|
+
* @param completionsDir - Directory containing completion scripts
|
|
53
|
+
* @returns true if configured successfully, false otherwise
|
|
54
|
+
*/
|
|
55
|
+
configureZshrc(completionsDir: string): Promise<boolean>;
|
|
56
|
+
/**
|
|
57
|
+
* Check if .zshrc has OpenSpec configuration markers
|
|
58
|
+
*
|
|
59
|
+
* @returns true if .zshrc exists and has markers
|
|
60
|
+
*/
|
|
61
|
+
private hasZshrcConfig;
|
|
62
|
+
/**
|
|
63
|
+
* Check if fpath configuration is needed for a given directory
|
|
64
|
+
* Used to verify if Oh My Zsh (or other) completions directory is already in fpath
|
|
65
|
+
*
|
|
66
|
+
* @param completionsDir - Directory to check for in fpath
|
|
67
|
+
* @returns true if configuration is needed, false if directory is already referenced
|
|
68
|
+
*/
|
|
69
|
+
private needsFpathConfig;
|
|
70
|
+
/**
|
|
71
|
+
* Remove .zshrc configuration
|
|
72
|
+
* Used during uninstallation
|
|
73
|
+
*
|
|
74
|
+
* @returns true if removed successfully, false otherwise
|
|
75
|
+
*/
|
|
76
|
+
removeZshrcConfig(): Promise<boolean>;
|
|
77
|
+
/**
|
|
78
|
+
* Install the completion script
|
|
79
|
+
*
|
|
80
|
+
* @param completionScript - The completion script content to install
|
|
81
|
+
* @returns Installation result with status and instructions
|
|
82
|
+
*/
|
|
83
|
+
install(completionScript: string): Promise<InstallationResult>;
|
|
84
|
+
/**
|
|
85
|
+
* Generate Oh My Zsh fpath verification guidance
|
|
86
|
+
*
|
|
87
|
+
* @param completionsDir - Custom completions directory path
|
|
88
|
+
* @returns Array of guidance strings, or undefined if not needed
|
|
89
|
+
*/
|
|
90
|
+
private generateOhMyZshFpathGuidance;
|
|
91
|
+
/**
|
|
92
|
+
* Generate user instructions for enabling completions
|
|
93
|
+
*
|
|
94
|
+
* @param isOhMyZsh - Whether Oh My Zsh is being used
|
|
95
|
+
* @param installedPath - Path where the script was installed
|
|
96
|
+
* @returns Array of instruction strings
|
|
97
|
+
*/
|
|
98
|
+
private generateInstructions;
|
|
99
|
+
/**
|
|
100
|
+
* Uninstall the completion script
|
|
101
|
+
*
|
|
102
|
+
* @returns true if uninstalled successfully, false otherwise
|
|
103
|
+
*/
|
|
104
|
+
uninstall(): Promise<{
|
|
105
|
+
success: boolean;
|
|
106
|
+
message: string;
|
|
107
|
+
}>;
|
|
108
|
+
/**
|
|
109
|
+
* Check if completion script is currently installed
|
|
110
|
+
*
|
|
111
|
+
* @returns true if the completion script exists
|
|
112
|
+
*/
|
|
113
|
+
isInstalled(): Promise<boolean>;
|
|
114
|
+
/**
|
|
115
|
+
* Get information about the current installation
|
|
116
|
+
*
|
|
117
|
+
* @returns Installation status information
|
|
118
|
+
*/
|
|
119
|
+
getInstallationInfo(): Promise<{
|
|
120
|
+
installed: boolean;
|
|
121
|
+
path?: string;
|
|
122
|
+
isOhMyZsh?: boolean;
|
|
123
|
+
}>;
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=zsh-installer.d.ts.map
|