@fission-ai/openspec 1.6.0 → 1.8.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/README.md +31 -2
- package/dist/cli/index.js +79 -8
- package/dist/commands/change.d.ts +0 -1
- package/dist/commands/change.js +105 -51
- package/dist/commands/config.js +14 -8
- package/dist/commands/doctor.js +9 -4
- package/dist/commands/feedback.js +74 -23
- package/dist/commands/schema.js +110 -31
- package/dist/commands/show.js +5 -2
- package/dist/commands/spec.js +49 -29
- package/dist/commands/validate.js +20 -5
- package/dist/commands/workflow/index.d.ts +1 -1
- package/dist/commands/workflow/index.js +1 -1
- package/dist/commands/workflow/instructions.d.ts +7 -1
- package/dist/commands/workflow/instructions.js +121 -33
- package/dist/commands/workflow/shared.d.ts +13 -2
- package/dist/commands/workflow/shared.js +34 -4
- package/dist/commands/workflow/status.js +9 -4
- package/dist/commands/workflow/templates.js +15 -5
- package/dist/core/archive.d.ts +14 -1
- package/dist/core/archive.js +1332 -155
- package/dist/core/artifact-graph/graph.d.ts +16 -0
- package/dist/core/artifact-graph/graph.js +30 -6
- package/dist/core/artifact-graph/index.d.ts +1 -1
- package/dist/core/artifact-graph/index.js +1 -1
- package/dist/core/artifact-graph/instruction-loader.d.ts +30 -3
- package/dist/core/artifact-graph/instruction-loader.js +70 -12
- package/dist/core/artifact-graph/outputs.d.ts +1 -0
- package/dist/core/artifact-graph/outputs.js +67 -5
- package/dist/core/artifact-graph/resolver.d.ts +14 -0
- package/dist/core/artifact-graph/resolver.js +69 -15
- package/dist/core/artifact-graph/types.js +21 -3
- package/dist/core/available-tools.d.ts +2 -2
- package/dist/core/available-tools.js +14 -3
- package/dist/core/change-metadata/schema.d.ts +2 -0
- package/dist/core/change-metadata/schema.js +13 -0
- package/dist/core/change-status-policy.d.ts +1 -1
- package/dist/core/change-status-policy.js +2 -2
- package/dist/core/command-generation/adapters/amazon-q.d.ts +4 -0
- package/dist/core/command-generation/adapters/amazon-q.js +7 -1
- package/dist/core/command-generation/adapters/antigravity.js +2 -1
- package/dist/core/command-generation/adapters/auggie.js +2 -1
- package/dist/core/command-generation/adapters/bob.d.ts +5 -1
- package/dist/core/command-generation/adapters/bob.js +6 -5
- package/dist/core/command-generation/adapters/claude.js +1 -8
- package/dist/core/command-generation/adapters/codebuddy.js +3 -2
- package/dist/core/command-generation/adapters/continue.js +3 -2
- package/dist/core/command-generation/adapters/costrict.js +2 -1
- package/dist/core/command-generation/adapters/crush.js +5 -5
- package/dist/core/command-generation/adapters/cursor.js +2 -2
- package/dist/core/command-generation/adapters/devin.d.ts +19 -0
- package/dist/core/command-generation/adapters/devin.js +36 -0
- package/dist/core/command-generation/adapters/factory.js +2 -1
- package/dist/core/command-generation/adapters/gemini.js +37 -2
- package/dist/core/command-generation/adapters/github-copilot.js +2 -1
- package/dist/core/command-generation/adapters/iflow.js +5 -4
- package/dist/core/command-generation/adapters/index.d.ts +2 -2
- package/dist/core/command-generation/adapters/index.js +2 -2
- package/dist/core/command-generation/adapters/junie.js +2 -1
- package/dist/core/command-generation/adapters/kiro.js +2 -1
- package/dist/core/command-generation/adapters/lingma.js +5 -5
- package/dist/core/command-generation/adapters/oh-my-pi.d.ts +2 -2
- package/dist/core/command-generation/adapters/oh-my-pi.js +3 -5
- package/dist/core/command-generation/adapters/opencode.js +3 -5
- package/dist/core/command-generation/adapters/pi.d.ts +2 -2
- package/dist/core/command-generation/adapters/pi.js +3 -6
- package/dist/core/command-generation/adapters/qoder.js +5 -5
- package/dist/core/command-generation/adapters/qwen.d.ts +7 -3
- package/dist/core/command-generation/adapters/qwen.js +12 -7
- package/dist/core/command-generation/adapters/roocode.d.ts +4 -4
- package/dist/core/command-generation/adapters/roocode.js +4 -4
- package/dist/core/command-generation/adapters/trae.js +1 -21
- package/dist/core/command-generation/adapters/zcode.d.ts +16 -0
- package/dist/core/command-generation/adapters/zcode.js +33 -0
- package/dist/core/command-generation/generator.d.ts +8 -0
- package/dist/core/command-generation/generator.js +15 -1
- package/dist/core/command-generation/index.d.ts +1 -1
- package/dist/core/command-generation/index.js +1 -1
- package/dist/core/command-generation/invocation.d.ts +73 -0
- package/dist/core/command-generation/invocation.js +77 -0
- package/dist/core/command-generation/registry.js +4 -4
- package/dist/core/command-generation/types.d.ts +9 -2
- package/dist/core/command-generation/yaml.d.ts +20 -6
- package/dist/core/command-generation/yaml.js +31 -21
- package/dist/core/command-surface.d.ts +15 -0
- package/dist/core/command-surface.js +33 -0
- package/dist/core/completions/command-registry.js +16 -2
- package/dist/core/completions/generators/powershell-generator.js +15 -8
- package/dist/core/completions/installers/zsh-installer.d.ts +9 -0
- package/dist/core/completions/installers/zsh-installer.js +20 -4
- package/dist/core/config-prompts.d.ts +1 -1
- package/dist/core/config-prompts.js +14 -1
- package/dist/core/config-schema.d.ts +10 -1
- package/dist/core/config-schema.js +67 -1
- package/dist/core/config.d.ts +15 -0
- package/dist/core/config.js +45 -5
- package/dist/core/file-state.js +56 -24
- package/dist/core/github-copilot/cloud-agent.d.ts +95 -0
- package/dist/core/github-copilot/cloud-agent.js +497 -0
- package/dist/core/global-config.d.ts +16 -0
- package/dist/core/init.d.ts +58 -0
- package/dist/core/init.js +450 -69
- package/dist/core/legacy-cleanup.d.ts +59 -0
- package/dist/core/legacy-cleanup.js +253 -24
- package/dist/core/list.js +5 -7
- package/dist/core/migration.d.ts +73 -1
- package/dist/core/migration.js +360 -11
- package/dist/core/onboarding-commands.d.ts +30 -0
- package/dist/core/onboarding-commands.js +38 -0
- package/dist/core/parsers/change-parser.d.ts +17 -2
- package/dist/core/parsers/change-parser.js +33 -20
- package/dist/core/parsers/code-fence.d.ts +15 -0
- package/dist/core/parsers/code-fence.js +49 -0
- package/dist/core/parsers/markdown-parser.js +2 -1
- package/dist/core/parsers/requirement-blocks.d.ts +18 -0
- package/dist/core/parsers/requirement-blocks.js +120 -35
- package/dist/core/parsers/requirement-text.d.ts +1 -8
- package/dist/core/parsers/requirement-text.js +4 -42
- package/dist/core/parsers/spec-structure.d.ts +1 -1
- package/dist/core/parsers/spec-structure.js +20 -30
- package/dist/core/profile-sync-drift.d.ts +0 -8
- package/dist/core/profile-sync-drift.js +48 -49
- package/dist/core/project-config.d.ts +28 -6
- package/dist/core/project-config.js +108 -8
- package/dist/core/references.js +42 -4
- package/dist/core/relationship-health.d.ts +8 -0
- package/dist/core/relationship-health.js +13 -0
- package/dist/core/root-selection.d.ts +9 -6
- package/dist/core/root-selection.js +42 -5
- package/dist/core/shared/index.d.ts +1 -0
- package/dist/core/shared/index.js +1 -0
- package/dist/core/shared/skill-content-equivalence.d.ts +7 -0
- package/dist/core/shared/skill-content-equivalence.js +41 -0
- package/dist/core/shared/skill-paths.d.ts +13 -0
- package/dist/core/shared/skill-paths.js +23 -0
- package/dist/core/shared/tool-detection.d.ts +25 -5
- package/dist/core/shared/tool-detection.js +166 -36
- package/dist/core/shared-skill-target.d.ts +16 -0
- package/dist/core/shared-skill-target.js +156 -0
- package/dist/core/specs-apply.d.ts +80 -33
- package/dist/core/specs-apply.js +659 -171
- package/dist/core/store/git.d.ts +13 -0
- package/dist/core/store/git.js +24 -0
- package/dist/core/templates/skill-templates.d.ts +1 -1
- package/dist/core/templates/skill-templates.js +1 -1
- package/dist/core/templates/workflows/apply-change.d.ts +10 -0
- package/dist/core/templates/workflows/apply-change.js +48 -158
- package/dist/core/templates/workflows/archive-change.js +170 -42
- package/dist/core/templates/workflows/bulk-archive-change.js +256 -75
- package/dist/core/templates/workflows/continue-change.js +38 -46
- package/dist/core/templates/workflows/explore.js +54 -18
- package/dist/core/templates/workflows/ff-change.js +46 -30
- package/dist/core/templates/workflows/new-change.js +2 -2
- package/dist/core/templates/workflows/onboard.js +13 -7
- package/dist/core/templates/workflows/propose.js +116 -46
- package/dist/core/templates/workflows/store-selection.d.ts +1 -1
- package/dist/core/templates/workflows/store-selection.js +1 -1
- package/dist/core/templates/workflows/sync-specs.js +260 -32
- package/dist/core/templates/workflows/update-change.js +26 -16
- package/dist/core/templates/workflows/verify-change.js +16 -10
- package/dist/core/update.d.ts +40 -5
- package/dist/core/update.js +389 -93
- package/dist/core/validation/constants.d.ts +4 -1
- package/dist/core/validation/constants.js +4 -1
- package/dist/core/validation/validator.d.ts +22 -8
- package/dist/core/validation/validator.js +222 -50
- package/dist/core/version-check.d.ts +152 -0
- package/dist/core/version-check.js +731 -0
- package/dist/core/view.js +12 -17
- package/dist/prompts/searchable-multi-select.js +1 -1
- package/dist/telemetry/config.d.ts +3 -4
- package/dist/telemetry/index.d.ts +10 -5
- package/dist/telemetry/index.js +75 -41
- package/dist/ui/welcome-screen.d.ts +9 -1
- package/dist/ui/welcome-screen.js +91 -38
- package/dist/utils/change-metadata.d.ts +43 -0
- package/dist/utils/change-metadata.js +123 -7
- package/dist/utils/change-utils.d.ts +10 -4
- package/dist/utils/change-utils.js +20 -13
- package/dist/utils/ci.d.ts +12 -0
- package/dist/utils/ci.js +16 -0
- package/dist/utils/command-references.d.ts +92 -6
- package/dist/utils/command-references.js +180 -7
- package/dist/utils/date.d.ts +8 -0
- package/dist/utils/date.js +13 -0
- package/dist/utils/file-system.d.ts +10 -0
- package/dist/utils/file-system.js +70 -0
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/interactive.d.ts +23 -0
- package/dist/utils/interactive.js +32 -0
- package/dist/utils/item-discovery.d.ts +19 -0
- package/dist/utils/item-discovery.js +30 -48
- package/dist/utils/shell-detection.d.ts +1 -1
- package/dist/utils/shell-detection.js +64 -11
- package/dist/utils/spec-discovery.d.ts +40 -0
- package/dist/utils/spec-discovery.js +115 -0
- package/dist/utils/task-progress.d.ts +17 -0
- package/dist/utils/task-progress.js +41 -13
- package/package.json +14 -12
- package/schemas/spec-driven/schema.yaml +67 -10
- package/schemas/spec-driven/templates/design.md +2 -2
- package/schemas/spec-driven/templates/proposal.md +10 -4
- package/schemas/spec-driven/templates/spec.md +3 -0
- package/dist/core/command-generation/adapters/codex.d.ts +0 -16
- package/dist/core/command-generation/adapters/codex.js +0 -39
- package/dist/core/command-generation/adapters/windsurf.d.ts +0 -14
- package/dist/core/command-generation/adapters/windsurf.js +0 -38
package/dist/core/migration.js
CHANGED
|
@@ -4,26 +4,359 @@
|
|
|
4
4
|
* One-time migration logic for existing projects when profile system is introduced.
|
|
5
5
|
* Called by both init and update commands before profile resolution.
|
|
6
6
|
*/
|
|
7
|
+
import { AI_TOOLS } from './config.js';
|
|
7
8
|
import { getGlobalConfig, getGlobalConfigPath, saveGlobalConfig } from './global-config.js';
|
|
8
9
|
import { CommandAdapterRegistry } from './command-generation/index.js';
|
|
10
|
+
import { resolveCommandInvocation, resolveCommandSurfaceCapability, shouldGenerateCommandsForTool, } from './command-surface.js';
|
|
9
11
|
import { WORKFLOW_TO_SKILL_DIR } from './profile-sync-drift.js';
|
|
12
|
+
import { COMMAND_IDS } from './shared/tool-detection.js';
|
|
10
13
|
import { ALL_WORKFLOWS } from './profiles.js';
|
|
14
|
+
import { getSkillReferenceTransformer, getTransformerForTool } from '../utils/command-references.js';
|
|
15
|
+
import { FileSystemUtils } from '../utils/file-system.js';
|
|
16
|
+
import { isSharedSkillTargetActive } from './shared-skill-target.js';
|
|
17
|
+
import { isLegacyCodexSkillEquivalentToCurrent } from './shared/skill-content-equivalence.js';
|
|
11
18
|
import path from 'path';
|
|
12
19
|
import * as fs from 'fs';
|
|
13
|
-
|
|
20
|
+
import { resolveToolSkillsDir, toolSupportsSkills } from './shared/skill-paths.js';
|
|
21
|
+
/**
|
|
22
|
+
* Former tool roots whose OpenSpec-managed content belongs under the tool's
|
|
23
|
+
* current skillsDir. User files are never touched.
|
|
24
|
+
*/
|
|
25
|
+
export const LEGACY_TOOL_ROOTS = {
|
|
26
|
+
// Kimi CLI became Kimi Code and moved from .kimi to .kimi-code.
|
|
27
|
+
kimi: [{ root: '.kimi', needsConsent: false }],
|
|
28
|
+
// Windsurf was rebranded to Devin Desktop on 2026-06-02 and its config
|
|
29
|
+
// directory moved to .devin/. Devin Desktop reads .windsurf/ only as a
|
|
30
|
+
// fallback and Devin Local does not read it at all, so moving is the right
|
|
31
|
+
// default — but a pre-rebrand Windsurf build reads ONLY .windsurf/, and
|
|
32
|
+
// nothing on disk tells that user apart, so the move is offered, not taken.
|
|
33
|
+
devin: [{ root: '.windsurf', needsConsent: true }],
|
|
34
|
+
// Codex now reads the canonical shared .agents root. Generate the current
|
|
35
|
+
// replacement first so a divergent legacy file is preserved, not overwritten.
|
|
36
|
+
codex: [{ root: '.codex', needsConsent: false, timing: 'after-generation' }],
|
|
37
|
+
};
|
|
38
|
+
function classifyManagedFile(source, destination) {
|
|
39
|
+
if (isSamePath(source, destination))
|
|
40
|
+
return 'skip';
|
|
41
|
+
if (!fs.existsSync(destination))
|
|
42
|
+
return 'move';
|
|
43
|
+
try {
|
|
44
|
+
const sourceContent = fs.readFileSync(source, 'utf-8');
|
|
45
|
+
const destinationContent = fs.readFileSync(destination, 'utf-8');
|
|
46
|
+
const equivalentGeneratedSkills = path.basename(source) === 'SKILL.md' &&
|
|
47
|
+
path.basename(destination) === 'SKILL.md' &&
|
|
48
|
+
isLegacyCodexSkillEquivalentToCurrent(sourceContent, destinationContent);
|
|
49
|
+
return sourceContent === destinationContent || equivalentGeneratedSkills
|
|
50
|
+
? 'drop'
|
|
51
|
+
: 'keep';
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return 'keep';
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Rewrites a generated command path from the tool's current root to a legacy
|
|
59
|
+
* one, so `.devin/workflows/opsx-apply.md` locates its `.windsurf/` twin
|
|
60
|
+
* without the migration hard-coding either layout.
|
|
61
|
+
*
|
|
62
|
+
* Returns undefined for adapters whose paths are absolute (global-scoped
|
|
63
|
+
* command files) or do not start at the tool root — neither can be relocated
|
|
64
|
+
* by swapping a leading segment.
|
|
65
|
+
*/
|
|
66
|
+
function legacyCommandPath(commandPath, currentRoot, legacyRoot) {
|
|
67
|
+
if (path.isAbsolute(commandPath))
|
|
68
|
+
return undefined;
|
|
69
|
+
const segments = commandPath.split(/[\\/]/);
|
|
70
|
+
if (segments[0] !== currentRoot)
|
|
71
|
+
return undefined;
|
|
72
|
+
segments[0] = legacyRoot;
|
|
73
|
+
return path.join(...segments);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Reports the OpenSpec content sitting under each tool's legacy root, without
|
|
77
|
+
* moving anything. Callers use this to ask before a move that needs consent.
|
|
78
|
+
*/
|
|
79
|
+
export function findLegacyToolMigrations(projectPath, timing = 'before-generation') {
|
|
80
|
+
return collectLegacyToolMigrations(projectPath, false, undefined, timing);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Moves OpenSpec-managed skill directories (openspec-*) and command files
|
|
84
|
+
* (opsx-*) from a tool's legacy root to its current one. When the destination
|
|
85
|
+
* already exists the legacy copy is removed instead. Legacy directories are
|
|
86
|
+
* deleted only when left empty, so user files under the old location — a
|
|
87
|
+
* hand-written Cascade workflow next to the generated ones — are preserved.
|
|
88
|
+
*
|
|
89
|
+
* @param projectPath - Project root
|
|
90
|
+
* @param toolIds - Restrict the move to these tools; omit to move every tool
|
|
91
|
+
* whose legacy root needs no consent
|
|
92
|
+
*/
|
|
93
|
+
export function migrateLegacyToolDirs(projectPath, toolIds, timing = 'before-generation') {
|
|
94
|
+
return collectLegacyToolMigrations(projectPath, true, toolIds, timing);
|
|
95
|
+
}
|
|
96
|
+
function collectLegacyToolMigrations(projectPath, apply, toolIds, timing = 'before-generation') {
|
|
97
|
+
const migrations = [];
|
|
98
|
+
for (const tool of AI_TOOLS) {
|
|
99
|
+
if (!tool.skillsDir)
|
|
100
|
+
continue;
|
|
101
|
+
if (toolIds && !toolIds.includes(tool.value))
|
|
102
|
+
continue;
|
|
103
|
+
for (const legacy of LEGACY_TOOL_ROOTS[tool.value] ?? []) {
|
|
104
|
+
const legacyTiming = legacy.timing ?? 'before-generation';
|
|
105
|
+
if (legacyTiming !== timing)
|
|
106
|
+
continue;
|
|
107
|
+
if (legacy.root === tool.skillsDir)
|
|
108
|
+
continue;
|
|
109
|
+
// Without an explicit tool list, only moves that need no consent run.
|
|
110
|
+
if (apply && !toolIds && legacy.needsConsent)
|
|
111
|
+
continue;
|
|
112
|
+
const legacyRootPath = path.join(projectPath, legacy.root);
|
|
113
|
+
if (!fs.existsSync(legacyRootPath))
|
|
114
|
+
continue;
|
|
115
|
+
try {
|
|
116
|
+
FileSystemUtils.assertProjectArtifactPath(projectPath, legacyRootPath);
|
|
117
|
+
FileSystemUtils.assertProjectArtifactPath(projectPath, path.join(projectPath, tool.skillsDir));
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
console.warn(`Skipping legacy ${legacy.root}/ migration because the directory resolves outside this project.`);
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
const skills = migrateSkillDirs(projectPath, tool.skillsDir, legacy.root, apply, legacyTiming === 'after-generation');
|
|
124
|
+
const commands = migrateCommandFiles(projectPath, tool, legacy.root, apply);
|
|
125
|
+
if (apply) {
|
|
126
|
+
removeDirIfEmpty(path.join(legacyRootPath, 'skills'));
|
|
127
|
+
removeDirIfEmpty(path.join(legacyRootPath, 'workflows'));
|
|
128
|
+
removeDirIfEmpty(legacyRootPath);
|
|
129
|
+
}
|
|
130
|
+
// Kept-only results are retained deliberately. When every legacy file
|
|
131
|
+
// differs from its counterpart nothing is movable, and dropping the
|
|
132
|
+
// record here would leave the user with two divergent copies and no
|
|
133
|
+
// word of it.
|
|
134
|
+
if (skills.moved > 0 || commands.moved > 0 || skills.kept > 0 || commands.kept > 0) {
|
|
135
|
+
migrations.push({
|
|
136
|
+
toolId: tool.value,
|
|
137
|
+
from: legacy.root,
|
|
138
|
+
to: tool.skillsDir,
|
|
139
|
+
skillDirs: skills.moved,
|
|
140
|
+
commandFiles: commands.moved,
|
|
141
|
+
keptInPlace: skills.kept + commands.kept,
|
|
142
|
+
needsConsent: legacy.needsConsent,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return migrations;
|
|
148
|
+
}
|
|
149
|
+
function migrateSkillDirs(projectPath, currentRoot, legacyRoot, apply, requireDestination = false) {
|
|
150
|
+
const legacySkillsDir = path.join(projectPath, legacyRoot, 'skills');
|
|
151
|
+
if (!fs.existsSync(legacySkillsDir))
|
|
152
|
+
return { moved: 0, kept: 0 };
|
|
153
|
+
const currentSkillsDir = path.join(projectPath, currentRoot, 'skills');
|
|
154
|
+
let moved = 0;
|
|
155
|
+
let kept = 0;
|
|
156
|
+
for (const workflowId of ALL_WORKFLOWS) {
|
|
157
|
+
const dirName = WORKFLOW_TO_SKILL_DIR[workflowId];
|
|
158
|
+
const source = path.join(legacySkillsDir, dirName);
|
|
159
|
+
const sourceSkill = path.join(source, 'SKILL.md');
|
|
160
|
+
if (!fs.existsSync(sourceSkill))
|
|
161
|
+
continue;
|
|
162
|
+
const destination = path.join(currentSkillsDir, dirName);
|
|
163
|
+
const destinationSkill = path.join(destination, 'SKILL.md');
|
|
164
|
+
if (requireDestination && !fs.existsSync(destinationSkill))
|
|
165
|
+
continue;
|
|
166
|
+
if (!areProjectArtifacts(projectPath, sourceSkill, destinationSkill)) {
|
|
167
|
+
console.warn(`Skipping legacy ${legacyRoot}/skills/${dirName} migration because it resolves outside this project.`);
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
const disposition = classifyManagedFile(sourceSkill, destinationSkill);
|
|
171
|
+
if (disposition === 'skip')
|
|
172
|
+
continue;
|
|
173
|
+
if (disposition === 'keep') {
|
|
174
|
+
kept++;
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
if (!apply) {
|
|
178
|
+
moved++;
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
try {
|
|
182
|
+
// Move the generated file, never the directory around it. A skill
|
|
183
|
+
// directory can also hold files the user wrote, and this destination is
|
|
184
|
+
// one OpenSpec deletes on its own — commands-only delivery and a
|
|
185
|
+
// deselected workflow both remove the whole skill directory. Carrying a
|
|
186
|
+
// user's file across would be handing it to that later removal.
|
|
187
|
+
if (disposition === 'drop') {
|
|
188
|
+
fs.rmSync(sourceSkill, { force: true });
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
fs.mkdirSync(destination, { recursive: true });
|
|
192
|
+
fs.renameSync(sourceSkill, destinationSkill);
|
|
193
|
+
}
|
|
194
|
+
// Anything the user left beside it stays under the legacy root.
|
|
195
|
+
removeDirIfEmpty(source);
|
|
196
|
+
moved++;
|
|
197
|
+
}
|
|
198
|
+
catch {
|
|
199
|
+
// Leave the legacy directory in place if it cannot be moved
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return { moved, kept };
|
|
203
|
+
}
|
|
204
|
+
function migrateCommandFiles(projectPath, tool, legacyRoot, apply) {
|
|
205
|
+
const adapter = CommandAdapterRegistry.get(tool.value);
|
|
206
|
+
if (!adapter || !tool.skillsDir)
|
|
207
|
+
return { moved: 0, kept: 0 };
|
|
208
|
+
let moved = 0;
|
|
209
|
+
let kept = 0;
|
|
210
|
+
for (const commandId of COMMAND_IDS) {
|
|
211
|
+
const currentPath = adapter.getFilePath(commandId);
|
|
212
|
+
const legacyPath = legacyCommandPath(currentPath, tool.skillsDir, legacyRoot);
|
|
213
|
+
if (!legacyPath)
|
|
214
|
+
continue;
|
|
215
|
+
const source = path.join(projectPath, legacyPath);
|
|
216
|
+
if (!fs.existsSync(source))
|
|
217
|
+
continue;
|
|
218
|
+
const destination = path.join(projectPath, currentPath);
|
|
219
|
+
if (!areProjectArtifacts(projectPath, source, destination)) {
|
|
220
|
+
console.warn(`Skipping legacy ${legacyPath} migration because it resolves outside this project.`);
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
const disposition = classifyManagedFile(source, destination);
|
|
224
|
+
if (disposition === 'skip')
|
|
225
|
+
continue;
|
|
226
|
+
if (disposition === 'keep') {
|
|
227
|
+
kept++;
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
if (!apply) {
|
|
231
|
+
moved++;
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
try {
|
|
235
|
+
if (disposition === 'drop') {
|
|
236
|
+
fs.rmSync(source, { force: true });
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
fs.mkdirSync(path.dirname(destination), { recursive: true });
|
|
240
|
+
fs.renameSync(source, destination);
|
|
241
|
+
}
|
|
242
|
+
moved++;
|
|
243
|
+
}
|
|
244
|
+
catch {
|
|
245
|
+
// Leave the legacy file in place if it cannot be moved
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return { moved, kept };
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Summarizes what a migration moved, e.g. "6 skills and 6 commands".
|
|
252
|
+
*/
|
|
253
|
+
export function describeLegacyMigration(migration) {
|
|
254
|
+
const parts = [];
|
|
255
|
+
if (migration.skillDirs > 0) {
|
|
256
|
+
parts.push(`${migration.skillDirs} skill${migration.skillDirs === 1 ? '' : 's'}`);
|
|
257
|
+
}
|
|
258
|
+
if (migration.commandFiles > 0) {
|
|
259
|
+
parts.push(`${migration.commandFiles} command${migration.commandFiles === 1 ? '' : 's'}`);
|
|
260
|
+
}
|
|
261
|
+
return parts.join(' and ');
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Names OpenSpec-managed files the move deliberately left behind, so a user
|
|
265
|
+
* who customized one knows there are now two copies to reconcile.
|
|
266
|
+
*/
|
|
267
|
+
export function keptInPlaceNotice(migration) {
|
|
268
|
+
if (migration.keptInPlace === 0)
|
|
269
|
+
return undefined;
|
|
270
|
+
const n = migration.keptInPlace;
|
|
271
|
+
// Deliberately does not claim the difference came from an edit: an older
|
|
272
|
+
// OpenSpec version's output differs too. Either way nothing was overwritten,
|
|
273
|
+
// and the user is the one who decides which copy to keep.
|
|
274
|
+
return (`Left ${n} file${n === 1 ? '' : 's'} in ${migration.from}/ that ` +
|
|
275
|
+
`differ${n === 1 ? 's' : ''} from the copy in ${migration.to}/. Nothing was ` +
|
|
276
|
+
`overwritten — compare the two and delete the ${migration.from}/ copy once ` +
|
|
277
|
+
`you have kept anything you customized.`);
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Whether a migration has anything to move, as opposed to only files left in
|
|
281
|
+
* place. Callers use this to avoid offering a move of nothing.
|
|
282
|
+
*/
|
|
283
|
+
export function hasMovableContent(migration) {
|
|
284
|
+
return migration.skillDirs > 0 || migration.commandFiles > 0;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Explains why a consent-gated move is being offered, in the user's terms.
|
|
288
|
+
* Keyed by tool so the reason is specific rather than a generic "files moved".
|
|
289
|
+
*/
|
|
290
|
+
export function legacyMigrationNotice(migration) {
|
|
291
|
+
if (migration.toolId === 'devin') {
|
|
292
|
+
return (`Windsurf is now Devin Desktop, and its config directory moved from ` +
|
|
293
|
+
`${migration.from}/ to ${migration.to}/. Devin Desktop reads ${migration.from}/ ` +
|
|
294
|
+
`only as a fallback, and Devin Local does not read it at all.`);
|
|
295
|
+
}
|
|
296
|
+
return `${migration.from}/ is the former location for this tool; ${migration.to}/ is current.`;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Whether two paths are the same file on disk once symlinks are resolved.
|
|
300
|
+
*
|
|
301
|
+
* Symlinking one tool root at the other is a realistic way to straddle a
|
|
302
|
+
* rebrand (`ln -s .devin .windsurf` to keep an older build working). Without
|
|
303
|
+
* this check the "destination already exists, drop the legacy copy" branch
|
|
304
|
+
* deletes the destination itself, taking the only copy with it.
|
|
305
|
+
*/
|
|
306
|
+
function isSamePath(a, b) {
|
|
307
|
+
try {
|
|
308
|
+
return fs.realpathSync(a) === fs.realpathSync(b);
|
|
309
|
+
}
|
|
310
|
+
catch {
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
function areProjectArtifacts(projectPath, ...artifactPaths) {
|
|
315
|
+
try {
|
|
316
|
+
for (const artifactPath of artifactPaths) {
|
|
317
|
+
FileSystemUtils.assertProjectArtifactPath(projectPath, artifactPath);
|
|
318
|
+
}
|
|
319
|
+
return true;
|
|
320
|
+
}
|
|
321
|
+
catch {
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
function removeDirIfEmpty(dirPath) {
|
|
326
|
+
try {
|
|
327
|
+
if (fs.readdirSync(dirPath).length === 0) {
|
|
328
|
+
fs.rmdirSync(dirPath);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
catch {
|
|
332
|
+
// Missing or non-empty directory — nothing to do
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
function scanInstalledWorkflowArtifacts(projectPath, tools, includeLegacySkills = false) {
|
|
14
336
|
const installed = new Set();
|
|
15
337
|
let hasSkills = false;
|
|
16
338
|
let hasCommands = false;
|
|
17
339
|
for (const tool of tools) {
|
|
18
|
-
if (!tool
|
|
340
|
+
if (!toolSupportsSkills(tool))
|
|
19
341
|
continue;
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
342
|
+
const skillsDirs = [];
|
|
343
|
+
if (tool.globalSkillsDir) {
|
|
344
|
+
skillsDirs.push(resolveToolSkillsDir(projectPath, tool));
|
|
345
|
+
}
|
|
346
|
+
else if (isSharedSkillTargetActive(projectPath, tool.value)) {
|
|
347
|
+
skillsDirs.push(resolveToolSkillsDir(projectPath, tool));
|
|
348
|
+
if (includeLegacySkills) {
|
|
349
|
+
skillsDirs.push(...(tool.legacySkillsDirs ?? []).map((root) => path.join(projectPath, root, 'skills')));
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
for (const skillsDir of skillsDirs) {
|
|
353
|
+
for (const workflowId of ALL_WORKFLOWS) {
|
|
354
|
+
const skillDirName = WORKFLOW_TO_SKILL_DIR[workflowId];
|
|
355
|
+
const skillFile = path.join(skillsDir, skillDirName, 'SKILL.md');
|
|
356
|
+
if (fs.existsSync(skillFile)) {
|
|
357
|
+
installed.add(workflowId);
|
|
358
|
+
hasSkills = true;
|
|
359
|
+
}
|
|
27
360
|
}
|
|
28
361
|
}
|
|
29
362
|
const adapter = CommandAdapterRegistry.get(tool.value);
|
|
@@ -89,7 +422,7 @@ export function migrateIfNeeded(projectPath, tools) {
|
|
|
89
422
|
return;
|
|
90
423
|
}
|
|
91
424
|
// Scan for installed workflows
|
|
92
|
-
const artifacts = scanInstalledWorkflowArtifacts(projectPath, tools);
|
|
425
|
+
const artifacts = scanInstalledWorkflowArtifacts(projectPath, tools, true);
|
|
93
426
|
const installedWorkflows = artifacts.workflows;
|
|
94
427
|
if (installedWorkflows.length === 0) {
|
|
95
428
|
// No workflows installed, new user — defaults will apply
|
|
@@ -103,6 +436,22 @@ export function migrateIfNeeded(projectPath, tools) {
|
|
|
103
436
|
}
|
|
104
437
|
saveGlobalConfig(config);
|
|
105
438
|
console.log(`Migrated: custom profile with ${installedWorkflows.length} workflows`);
|
|
106
|
-
|
|
439
|
+
// Each detected tool resolves to a propose reference for its surface: the
|
|
440
|
+
// command name its generated files answer to when commands will exist for it
|
|
441
|
+
// under the effective delivery (/opsx:propose when namespaced under opsx/,
|
|
442
|
+
// /opsx-propose when the filename is the command), its documented skill
|
|
443
|
+
// invocation otherwise. When the tools disagree — including command tools
|
|
444
|
+
// mixed with skill-only tools — stay syntax-neutral rather than advertise a
|
|
445
|
+
// form that is wrong for one of them.
|
|
446
|
+
const effectiveDelivery = config.delivery ?? 'both';
|
|
447
|
+
const proposeReferences = new Set(tools.map((tool) => {
|
|
448
|
+
if (shouldGenerateCommandsForTool(tool.value, effectiveDelivery)) {
|
|
449
|
+
const transformer = getTransformerForTool(tool.value, effectiveDelivery, resolveCommandSurfaceCapability(tool.value), resolveCommandInvocation(tool.value));
|
|
450
|
+
return transformer ? transformer('/opsx:propose') : '/opsx:propose';
|
|
451
|
+
}
|
|
452
|
+
return getSkillReferenceTransformer(tool.value)('/opsx:propose');
|
|
453
|
+
}));
|
|
454
|
+
const proposeReference = proposeReferences.size === 1 ? [...proposeReferences][0] : 'the openspec-propose skill';
|
|
455
|
+
console.log(`New in this version: ${proposeReference}. Try 'openspec config profile core' for the streamlined experience.`);
|
|
107
456
|
}
|
|
108
457
|
//# sourceMappingURL=migration.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Onboarding command hints.
|
|
3
|
+
*
|
|
4
|
+
* The commands shown to a user after setup must be limited to the workflows
|
|
5
|
+
* their profile actually installs, otherwise we advertise slash commands that
|
|
6
|
+
* were correctly never generated.
|
|
7
|
+
*
|
|
8
|
+
* This module decides WHICH hints to show. How each one is spelled for a given
|
|
9
|
+
* tool — command, skill, or a tool-specific skill prefix — is decided by
|
|
10
|
+
* src/utils/command-references.ts at the call site.
|
|
11
|
+
*/
|
|
12
|
+
import type { WorkflowId } from './profiles.js';
|
|
13
|
+
export type OnboardingCommand = {
|
|
14
|
+
workflow: WorkflowId;
|
|
15
|
+
command: string;
|
|
16
|
+
description: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Longest description the welcome screen can render. It shows these beside a
|
|
20
|
+
* 24-column art column and only animates at MIN_WIDTH (60) columns or wider; a
|
|
21
|
+
* longer line wraps, and the animation's cursor-up count assumes unwrapped
|
|
22
|
+
* lines. See src/ui/welcome-screen.ts.
|
|
23
|
+
*/
|
|
24
|
+
export declare const DESCRIPTION_BUDGET = 17;
|
|
25
|
+
/**
|
|
26
|
+
* Returns the onboarding hints for the installed workflows, in lifecycle order.
|
|
27
|
+
* Returns an empty array when none of the onboarding workflows are installed.
|
|
28
|
+
*/
|
|
29
|
+
export declare function getOnboardingCommands(workflows: readonly string[]): OnboardingCommand[];
|
|
30
|
+
//# sourceMappingURL=onboarding-commands.d.ts.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Onboarding command hints.
|
|
3
|
+
*
|
|
4
|
+
* The commands shown to a user after setup must be limited to the workflows
|
|
5
|
+
* their profile actually installs, otherwise we advertise slash commands that
|
|
6
|
+
* were correctly never generated.
|
|
7
|
+
*
|
|
8
|
+
* This module decides WHICH hints to show. How each one is spelled for a given
|
|
9
|
+
* tool — command, skill, or a tool-specific skill prefix — is decided by
|
|
10
|
+
* src/utils/command-references.ts at the call site.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Longest description the welcome screen can render. It shows these beside a
|
|
14
|
+
* 24-column art column and only animates at MIN_WIDTH (60) columns or wider; a
|
|
15
|
+
* longer line wraps, and the animation's cursor-up count assumes unwrapped
|
|
16
|
+
* lines. See src/ui/welcome-screen.ts.
|
|
17
|
+
*/
|
|
18
|
+
export const DESCRIPTION_BUDGET = 17;
|
|
19
|
+
/**
|
|
20
|
+
* Ordered onboarding hints. Each entry is shown only when its workflow is
|
|
21
|
+
* installed, so the list follows the change lifecycle: start, then build,
|
|
22
|
+
* then implement.
|
|
23
|
+
*/
|
|
24
|
+
const ONBOARDING_COMMANDS = [
|
|
25
|
+
{ workflow: 'propose', command: '/opsx:propose', description: 'Start a change' },
|
|
26
|
+
{ workflow: 'new', command: '/opsx:new', description: 'Scaffold a change' },
|
|
27
|
+
{ workflow: 'continue', command: '/opsx:continue', description: 'Next artifact' },
|
|
28
|
+
{ workflow: 'apply', command: '/opsx:apply', description: 'Implement tasks' },
|
|
29
|
+
];
|
|
30
|
+
/**
|
|
31
|
+
* Returns the onboarding hints for the installed workflows, in lifecycle order.
|
|
32
|
+
* Returns an empty array when none of the onboarding workflows are installed.
|
|
33
|
+
*/
|
|
34
|
+
export function getOnboardingCommands(workflows) {
|
|
35
|
+
const installed = new Set(workflows);
|
|
36
|
+
return ONBOARDING_COMMANDS.filter((entry) => installed.has(entry.workflow));
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=onboarding-commands.js.map
|
|
@@ -1,10 +1,25 @@
|
|
|
1
|
-
import { MarkdownParser } from './markdown-parser.js';
|
|
2
|
-
import { Change } from '../schemas/index.js';
|
|
1
|
+
import { MarkdownParser, Section } from './markdown-parser.js';
|
|
2
|
+
import { Change, Requirement } from '../schemas/index.js';
|
|
3
3
|
export declare class ChangeParser extends MarkdownParser {
|
|
4
4
|
private changeDir;
|
|
5
5
|
constructor(content: string, changeDir: string);
|
|
6
6
|
parseChangeWithDeltas(name: string): Promise<Change>;
|
|
7
7
|
private parseDeltaSpecs;
|
|
8
|
+
/**
|
|
9
|
+
* Read requirements from a delta section, ignoring headers that are not
|
|
10
|
+
* `### Requirement: <name>`.
|
|
11
|
+
*
|
|
12
|
+
* A delta section often carries divider headers such as
|
|
13
|
+
* `### Documentation Requirements`. The base parser treats every child header
|
|
14
|
+
* as a requirement, which invented a scenario-less requirement that does not
|
|
15
|
+
* exist (#498): archive warned about a missing scenario, and `show --json`
|
|
16
|
+
* reported an extra delta. The delta reader already skips these headers and
|
|
17
|
+
* notes them, so this keeps the two readers in agreement.
|
|
18
|
+
*
|
|
19
|
+
* Overriding here rather than in MarkdownParser keeps main spec parsing —
|
|
20
|
+
* `view`, `list`, `spec --json`, spec validation — untouched.
|
|
21
|
+
*/
|
|
22
|
+
protected parseRequirements(section: Section): Requirement[];
|
|
8
23
|
private parseSpecDeltas;
|
|
9
24
|
private parseRenames;
|
|
10
25
|
private parseSectionsFromContent;
|
|
@@ -2,6 +2,7 @@ import { MarkdownParser } from './markdown-parser.js';
|
|
|
2
2
|
import { buildCodeFenceMask } from './requirement-text.js';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { promises as fs } from 'fs';
|
|
5
|
+
import { discoverSpecFiles } from '../../utils/spec-discovery.js';
|
|
5
6
|
export class ChangeParser extends MarkdownParser {
|
|
6
7
|
changeDir;
|
|
7
8
|
constructor(content, changeDir) {
|
|
@@ -38,30 +39,42 @@ export class ChangeParser extends MarkdownParser {
|
|
|
38
39
|
}
|
|
39
40
|
async parseDeltaSpecs(specsDir) {
|
|
40
41
|
const deltas = [];
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
catch (error) {
|
|
54
|
-
// Spec file might not exist, which is okay
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
42
|
+
// Discover delta specs recursively so nested layouts like
|
|
43
|
+
// specs/<area>/<capability>/spec.md are parsed too (#1353)
|
|
44
|
+
const specFiles = await discoverSpecFiles(specsDir);
|
|
45
|
+
for (const { id, specFile } of specFiles) {
|
|
46
|
+
try {
|
|
47
|
+
const content = await fs.readFile(specFile, 'utf-8');
|
|
48
|
+
const specDeltas = this.parseSpecDeltas(id, content);
|
|
49
|
+
deltas.push(...specDeltas);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
// Spec file might not be readable, which is okay
|
|
53
|
+
continue;
|
|
57
54
|
}
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
// Specs directory might not exist, which is okay
|
|
61
|
-
return [];
|
|
62
55
|
}
|
|
63
56
|
return deltas;
|
|
64
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Read requirements from a delta section, ignoring headers that are not
|
|
60
|
+
* `### Requirement: <name>`.
|
|
61
|
+
*
|
|
62
|
+
* A delta section often carries divider headers such as
|
|
63
|
+
* `### Documentation Requirements`. The base parser treats every child header
|
|
64
|
+
* as a requirement, which invented a scenario-less requirement that does not
|
|
65
|
+
* exist (#498): archive warned about a missing scenario, and `show --json`
|
|
66
|
+
* reported an extra delta. The delta reader already skips these headers and
|
|
67
|
+
* notes them, so this keeps the two readers in agreement.
|
|
68
|
+
*
|
|
69
|
+
* Overriding here rather than in MarkdownParser keeps main spec parsing —
|
|
70
|
+
* `view`, `list`, `spec --json`, spec validation — untouched.
|
|
71
|
+
*/
|
|
72
|
+
parseRequirements(section) {
|
|
73
|
+
return super.parseRequirements({
|
|
74
|
+
...section,
|
|
75
|
+
children: section.children.filter((child) => /^Requirement:\s*\S/i.test(child.title.trim())),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
65
78
|
parseSpecDeltas(specName, content) {
|
|
66
79
|
const deltas = [];
|
|
67
80
|
const sections = this.parseSectionsFromContent(content);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared fenced-code-block detection for the Markdown parsers.
|
|
3
|
+
*
|
|
4
|
+
* Several parsers need to ignore Markdown structure (headers, requirement
|
|
5
|
+
* blocks, scenarios, delta sections) that appears inside fenced code blocks.
|
|
6
|
+
* Keeping this logic in one place avoids the drift that previously left
|
|
7
|
+
* `requirement-blocks.ts` treating fenced `### Requirement:` lines as real
|
|
8
|
+
* requirements during validation and archiving.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Builds a per-line mask where `true` marks a line that is part of a fenced
|
|
12
|
+
* code block (including the opening and closing fence lines themselves).
|
|
13
|
+
*/
|
|
14
|
+
export declare function buildCodeFenceMask(lines: string[]): boolean[];
|
|
15
|
+
//# sourceMappingURL=code-fence.d.ts.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared fenced-code-block detection for the Markdown parsers.
|
|
3
|
+
*
|
|
4
|
+
* Several parsers need to ignore Markdown structure (headers, requirement
|
|
5
|
+
* blocks, scenarios, delta sections) that appears inside fenced code blocks.
|
|
6
|
+
* Keeping this logic in one place avoids the drift that previously left
|
|
7
|
+
* `requirement-blocks.ts` treating fenced `### Requirement:` lines as real
|
|
8
|
+
* requirements during validation and archiving.
|
|
9
|
+
*/
|
|
10
|
+
function getFenceMarker(line) {
|
|
11
|
+
const fenceMatch = line.match(/^\s*(`{3,}|~{3,})/);
|
|
12
|
+
if (!fenceMatch) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
marker: fenceMatch[1][0],
|
|
17
|
+
length: fenceMatch[1].length,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function isClosingFence(line, activeFence) {
|
|
21
|
+
const fenceMatch = line.match(/^\s*(`{3,}|~{3,})\s*$/);
|
|
22
|
+
return Boolean(fenceMatch &&
|
|
23
|
+
fenceMatch[1][0] === activeFence.marker &&
|
|
24
|
+
fenceMatch[1].length >= activeFence.length);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Builds a per-line mask where `true` marks a line that is part of a fenced
|
|
28
|
+
* code block (including the opening and closing fence lines themselves).
|
|
29
|
+
*/
|
|
30
|
+
export function buildCodeFenceMask(lines) {
|
|
31
|
+
const mask = new Array(lines.length).fill(false);
|
|
32
|
+
let activeFence = null;
|
|
33
|
+
for (let i = 0; i < lines.length; i++) {
|
|
34
|
+
if (!activeFence) {
|
|
35
|
+
const fence = getFenceMarker(lines[i]);
|
|
36
|
+
if (fence) {
|
|
37
|
+
activeFence = fence;
|
|
38
|
+
mask[i] = true;
|
|
39
|
+
}
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
mask[i] = true;
|
|
43
|
+
if (isClosingFence(lines[i], activeFence)) {
|
|
44
|
+
activeFence = null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return mask;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=code-fence.js.map
|
|
@@ -10,7 +10,8 @@ export class MarkdownParser {
|
|
|
10
10
|
this.currentLine = 0;
|
|
11
11
|
}
|
|
12
12
|
static normalizeContent(content) {
|
|
13
|
-
|
|
13
|
+
// Strip a UTF-8 BOM so a header on the first line still matches.
|
|
14
|
+
return content.replace(/^/, '').replace(/\r\n?/g, '\n');
|
|
14
15
|
}
|
|
15
16
|
parseSpec(name) {
|
|
16
17
|
const sections = this.parseSections();
|