@fission-ai/openspec 1.7.0 → 1.9.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 +3 -1
- package/dist/cli/index.d.ts +15 -0
- package/dist/cli/index.js +39 -5
- package/dist/commands/change.js +16 -1
- package/dist/commands/config.d.ts +5 -0
- package/dist/commands/config.js +5 -1
- package/dist/commands/schema.js +281 -47
- package/dist/commands/spec.js +30 -6
- package/dist/commands/validate.d.ts +23 -0
- package/dist/commands/validate.js +148 -4
- package/dist/commands/workflow/instructions.js +32 -27
- package/dist/commands/workflow/schemas.d.ts +2 -0
- package/dist/commands/workflow/schemas.js +9 -2
- package/dist/commands/workflow/status.js +2 -2
- package/dist/commands/workflow/templates.js +15 -5
- package/dist/core/archive.d.ts +14 -0
- package/dist/core/archive.js +1272 -151
- 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 +3 -1
- package/dist/core/artifact-graph/instruction-loader.js +15 -5
- 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 +0 -12
- package/dist/core/artifact-graph/resolver.js +49 -9
- 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 +1 -0
- package/dist/core/change-metadata/schema.js +7 -0
- package/dist/core/change-status-policy.js +2 -2
- package/dist/core/command-generation/adapters/command-code.d.ts +19 -0
- package/dist/core/command-generation/adapters/command-code.js +34 -0
- package/dist/core/command-generation/adapters/index.d.ts +1 -0
- package/dist/core/command-generation/adapters/index.js +1 -0
- package/dist/core/command-generation/registry.js +2 -0
- package/dist/core/completions/command-registry.js +13 -0
- package/dist/core/config-schema.d.ts +3 -0
- package/dist/core/config-schema.js +28 -1
- package/dist/core/config.d.ts +4 -0
- package/dist/core/config.js +40 -17
- 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 +11 -0
- package/dist/core/init.d.ts +23 -0
- package/dist/core/init.js +253 -46
- package/dist/core/legacy-cleanup.d.ts +10 -0
- package/dist/core/legacy-cleanup.js +52 -28
- package/dist/core/migration.d.ts +6 -4
- package/dist/core/migration.js +78 -22
- package/dist/core/parsers/requirement-blocks.d.ts +10 -0
- package/dist/core/parsers/requirement-blocks.js +93 -1
- package/dist/core/parsers/requirement-text.d.ts +8 -0
- package/dist/core/parsers/requirement-text.js +4 -3
- package/dist/core/parsers/spec-structure.d.ts +1 -1
- package/dist/core/parsers/spec-structure.js +17 -1
- package/dist/core/profile-sync-drift.js +40 -5
- package/dist/core/project-config.d.ts +3 -0
- package/dist/core/project-config.js +31 -1
- package/dist/core/root-selection.d.ts +1 -1
- 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.js +66 -35
- package/dist/core/shared-skill-target.d.ts +31 -0
- package/dist/core/shared-skill-target.js +186 -0
- package/dist/core/specs-apply.d.ts +72 -0
- package/dist/core/specs-apply.js +459 -59
- 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 +25 -182
- package/dist/core/templates/workflows/archive-change.js +8 -4
- package/dist/core/templates/workflows/bulk-archive-change.js +30 -26
- package/dist/core/templates/workflows/continue-change.js +6 -6
- package/dist/core/templates/workflows/explore.js +42 -18
- package/dist/core/templates/workflows/onboard.js +9 -3
- package/dist/core/templates/workflows/propose.js +72 -20
- 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 +96 -18
- package/dist/core/templates/workflows/update-change.js +10 -8
- package/dist/core/update.d.ts +1 -0
- package/dist/core/update.js +136 -30
- package/dist/core/validation/task-numbering.d.ts +16 -0
- package/dist/core/validation/task-numbering.js +57 -0
- package/dist/core/validation/validator.d.ts +26 -3
- package/dist/core/validation/validator.js +189 -19
- package/dist/core/version-check.js +6 -11
- package/dist/telemetry/config.d.ts +3 -4
- package/dist/telemetry/index.d.ts +12 -5
- package/dist/telemetry/index.js +27 -9
- package/dist/utils/change-metadata.d.ts +17 -4
- package/dist/utils/change-metadata.js +26 -4
- package/dist/utils/ci.d.ts +12 -0
- package/dist/utils/ci.js +16 -0
- package/dist/utils/command-references.d.ts +14 -2
- package/dist/utils/command-references.js +45 -3
- package/dist/utils/file-system.d.ts +10 -0
- package/dist/utils/file-system.js +70 -0
- package/dist/utils/interactive.d.ts +52 -0
- package/dist/utils/interactive.js +135 -0
- package/dist/utils/spec-discovery.d.ts +4 -4
- package/dist/utils/spec-discovery.js +19 -6
- package/dist/utils/task-progress.d.ts +51 -1
- package/dist/utils/task-progress.js +93 -41
- package/package.json +1 -1
- package/schemas/spec-driven/schema.yaml +8 -6
- package/schemas/spec-driven/templates/proposal.md +6 -4
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type AIToolOption } from '../config.js';
|
|
2
|
+
export type SkillCapableTool = AIToolOption & ({
|
|
3
|
+
skillsDir: string;
|
|
4
|
+
} | {
|
|
5
|
+
globalSkillsDir: string;
|
|
6
|
+
});
|
|
7
|
+
export declare function toolSupportsSkills(tool: AIToolOption): tool is SkillCapableTool;
|
|
8
|
+
export declare function getSkillCapableTools(): SkillCapableTool[];
|
|
9
|
+
export declare function hasGlobalSkillTarget(tool: AIToolOption): boolean;
|
|
10
|
+
export declare function resolveToolSkillsDir(projectRoot: string, tool: SkillCapableTool, options?: {
|
|
11
|
+
homeDir?: string;
|
|
12
|
+
}): string;
|
|
13
|
+
//# sourceMappingURL=skill-paths.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { AI_TOOLS } from '../config.js';
|
|
4
|
+
export function toolSupportsSkills(tool) {
|
|
5
|
+
return Boolean(tool.skillsDir || tool.globalSkillsDir);
|
|
6
|
+
}
|
|
7
|
+
export function getSkillCapableTools() {
|
|
8
|
+
return AI_TOOLS.filter(toolSupportsSkills);
|
|
9
|
+
}
|
|
10
|
+
export function hasGlobalSkillTarget(tool) {
|
|
11
|
+
return Boolean(tool.globalSkillsDir);
|
|
12
|
+
}
|
|
13
|
+
export function resolveToolSkillsDir(projectRoot, tool, options = {}) {
|
|
14
|
+
if (tool.globalSkillsDir) {
|
|
15
|
+
const homeDir = options.homeDir ?? process.env.USERPROFILE ?? process.env.HOME ?? os.homedir();
|
|
16
|
+
return path.join(homeDir, tool.globalSkillsDir, 'skills');
|
|
17
|
+
}
|
|
18
|
+
if (tool.skillsDir) {
|
|
19
|
+
return path.join(projectRoot, tool.skillsDir, 'skills');
|
|
20
|
+
}
|
|
21
|
+
throw new Error(`Tool '${tool.value}' does not support skill generation.`);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=skill-paths.js.map
|
|
@@ -5,28 +5,18 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import * as fs from 'fs';
|
|
8
|
-
import { AI_TOOLS } from '../config.js';
|
|
8
|
+
import { AI_TOOLS, OPENSPEC_SKILL_NAMES } from '../config.js';
|
|
9
9
|
import { CommandAdapterRegistry, generateCommands } from '../command-generation/index.js';
|
|
10
10
|
import { getCommandContents } from './skill-generation.js';
|
|
11
11
|
import { getGlobalConfig } from '../global-config.js';
|
|
12
12
|
import { getProfileWorkflows, ALL_WORKFLOWS } from '../profiles.js';
|
|
13
|
+
import { isSharedSkillTargetActive, readSharedSkillTarget, reconcileSharedSkillTargets, } from '../shared-skill-target.js';
|
|
14
|
+
import { shouldGenerateCommandsForTool, shouldGenerateSkillsForTool, } from '../command-surface.js';
|
|
15
|
+
import { getSkillCapableTools, resolveToolSkillsDir, toolSupportsSkills, } from './skill-paths.js';
|
|
13
16
|
/**
|
|
14
17
|
* Names of skill directories created by openspec init.
|
|
15
18
|
*/
|
|
16
|
-
export const SKILL_NAMES =
|
|
17
|
-
'openspec-explore',
|
|
18
|
-
'openspec-new-change',
|
|
19
|
-
'openspec-continue-change',
|
|
20
|
-
'openspec-apply-change',
|
|
21
|
-
'openspec-update-change',
|
|
22
|
-
'openspec-ff-change',
|
|
23
|
-
'openspec-sync-specs',
|
|
24
|
-
'openspec-archive-change',
|
|
25
|
-
'openspec-bulk-archive-change',
|
|
26
|
-
'openspec-verify-change',
|
|
27
|
-
'openspec-onboard',
|
|
28
|
-
'openspec-propose',
|
|
29
|
-
];
|
|
19
|
+
export const SKILL_NAMES = OPENSPEC_SKILL_NAMES;
|
|
30
20
|
/**
|
|
31
21
|
* IDs of command templates created by openspec init.
|
|
32
22
|
*/
|
|
@@ -48,21 +38,26 @@ export const COMMAND_IDS = [
|
|
|
48
38
|
* Gets the list of tools with skillsDir configured.
|
|
49
39
|
*/
|
|
50
40
|
export function getToolsWithSkillsDir() {
|
|
51
|
-
return
|
|
41
|
+
return getSkillCapableTools().map((tool) => tool.value);
|
|
52
42
|
}
|
|
53
43
|
/**
|
|
54
44
|
* Checks which skill files exist for a tool.
|
|
55
45
|
*/
|
|
56
46
|
export function getToolSkillStatus(projectRoot, toolId) {
|
|
57
47
|
const tool = AI_TOOLS.find((t) => t.value === toolId);
|
|
58
|
-
if (!tool
|
|
48
|
+
if (!tool || !toolSupportsSkills(tool)) {
|
|
49
|
+
return { configured: false, fullyConfigured: false, skillCount: 0 };
|
|
50
|
+
}
|
|
51
|
+
if (tool.skillsDir && !isSharedSkillTargetActive(projectRoot, toolId)) {
|
|
59
52
|
return { configured: false, fullyConfigured: false, skillCount: 0 };
|
|
60
53
|
}
|
|
61
|
-
const
|
|
54
|
+
const skillsDirs = [
|
|
55
|
+
resolveToolSkillsDir(projectRoot, tool),
|
|
56
|
+
...(tool.legacySkillsDirs ?? []).map((root) => path.join(projectRoot, root, 'skills')),
|
|
57
|
+
];
|
|
62
58
|
let skillCount = 0;
|
|
63
59
|
for (const skillName of SKILL_NAMES) {
|
|
64
|
-
|
|
65
|
-
if (fs.existsSync(skillFile)) {
|
|
60
|
+
if (skillsDirs.some((skillsDir) => fs.existsSync(path.join(skillsDir, skillName, 'SKILL.md')))) {
|
|
66
61
|
skillCount++;
|
|
67
62
|
}
|
|
68
63
|
}
|
|
@@ -159,9 +154,21 @@ export function areCommandFilesUpToDate(projectRoot, toolId, options) {
|
|
|
159
154
|
*/
|
|
160
155
|
export function getToolStates(projectRoot) {
|
|
161
156
|
const states = new Map();
|
|
162
|
-
const
|
|
163
|
-
for (const
|
|
164
|
-
|
|
157
|
+
const tools = getSkillCapableTools();
|
|
158
|
+
for (const tool of tools) {
|
|
159
|
+
const skillStatus = getToolSkillStatus(projectRoot, tool.value);
|
|
160
|
+
const markerConfigured = Boolean(tool.skillsDir) &&
|
|
161
|
+
readSharedSkillTarget(projectRoot, tool.skillsDir) === tool.value;
|
|
162
|
+
states.set(tool.value, markerConfigured
|
|
163
|
+
? { ...skillStatus, configured: true }
|
|
164
|
+
: skillStatus);
|
|
165
|
+
}
|
|
166
|
+
const configuredTools = tools.filter((tool) => tool.skillsDir && states.get(tool.value)?.configured);
|
|
167
|
+
const activeSharedTargets = new Set(reconcileSharedSkillTargets(projectRoot, configuredTools).map((tool) => tool.value));
|
|
168
|
+
for (const tool of configuredTools) {
|
|
169
|
+
if (!activeSharedTargets.has(tool.value)) {
|
|
170
|
+
states.set(tool.value, { configured: false, fullyConfigured: false, skillCount: 0 });
|
|
171
|
+
}
|
|
165
172
|
}
|
|
166
173
|
return states;
|
|
167
174
|
}
|
|
@@ -200,7 +207,7 @@ export function extractGeneratedByVersion(skillFilePath) {
|
|
|
200
207
|
*/
|
|
201
208
|
export function getToolVersionStatus(projectRoot, toolId, currentVersion, options) {
|
|
202
209
|
const tool = AI_TOOLS.find((t) => t.value === toolId);
|
|
203
|
-
if (!tool
|
|
210
|
+
if (!tool || !toolSupportsSkills(tool)) {
|
|
204
211
|
return {
|
|
205
212
|
toolId,
|
|
206
213
|
toolName: toolId,
|
|
@@ -209,25 +216,43 @@ export function getToolVersionStatus(projectRoot, toolId, currentVersion, option
|
|
|
209
216
|
needsUpdate: false,
|
|
210
217
|
};
|
|
211
218
|
}
|
|
212
|
-
const
|
|
219
|
+
const skillsDirs = [
|
|
220
|
+
resolveToolSkillsDir(projectRoot, tool),
|
|
221
|
+
...(tool.legacySkillsDirs ?? []).map((root) => path.join(projectRoot, root, 'skills')),
|
|
222
|
+
];
|
|
213
223
|
let generatedByVersion = null;
|
|
224
|
+
let foundSkill = false;
|
|
214
225
|
// 1. Find the first skill file that exists and read its version
|
|
215
226
|
for (const skillName of SKILL_NAMES) {
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
227
|
+
for (const skillsDir of skillsDirs) {
|
|
228
|
+
const skillFile = path.join(skillsDir, skillName, 'SKILL.md');
|
|
229
|
+
if (fs.existsSync(skillFile)) {
|
|
230
|
+
generatedByVersion = extractGeneratedByVersion(skillFile);
|
|
231
|
+
foundSkill = true;
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
220
234
|
}
|
|
235
|
+
if (foundSkill)
|
|
236
|
+
break;
|
|
221
237
|
}
|
|
222
238
|
const skillConfigured = getToolSkillStatus(projectRoot, toolId).configured;
|
|
223
239
|
const commandConfigured = toolHasAnyConfiguredCommand(projectRoot, toolId);
|
|
224
|
-
const
|
|
240
|
+
const markerConfigured = Boolean(tool.skillsDir) &&
|
|
241
|
+
readSharedSkillTarget(projectRoot, tool.skillsDir) === toolId;
|
|
242
|
+
const configured = skillConfigured || commandConfigured || markerConfigured;
|
|
225
243
|
// 2. Commands-only installs have no skill file to read a version from, so fall
|
|
226
244
|
// back to comparing the generated command content. Deliberately skipped when
|
|
227
245
|
// skill files exist: an unreadable version there must still force a rewrite.
|
|
228
246
|
if (!skillConfigured && commandConfigured && areCommandFilesUpToDate(projectRoot, toolId, options)) {
|
|
229
247
|
generatedByVersion = currentVersion;
|
|
230
248
|
}
|
|
249
|
+
if (!skillConfigured && !commandConfigured && markerConfigured) {
|
|
250
|
+
const delivery = getGlobalConfig().delivery ?? 'both';
|
|
251
|
+
if (!shouldGenerateSkillsForTool(toolId, delivery) &&
|
|
252
|
+
!shouldGenerateCommandsForTool(toolId, delivery)) {
|
|
253
|
+
generatedByVersion = currentVersion;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
231
256
|
const needsUpdate = configured && (generatedByVersion === null || generatedByVersion !== currentVersion);
|
|
232
257
|
return {
|
|
233
258
|
toolId,
|
|
@@ -241,13 +266,19 @@ export function getToolVersionStatus(projectRoot, toolId, currentVersion, option
|
|
|
241
266
|
* Gets all configured tools in the project (configured via skills or commands).
|
|
242
267
|
*/
|
|
243
268
|
export function getConfiguredTools(projectRoot) {
|
|
244
|
-
|
|
269
|
+
const configured = AI_TOOLS
|
|
245
270
|
.filter((t) => {
|
|
246
|
-
if (!t
|
|
271
|
+
if (!toolSupportsSkills(t))
|
|
247
272
|
return false;
|
|
248
|
-
return getToolSkillStatus(projectRoot, t.value).configured ||
|
|
249
|
-
|
|
250
|
-
|
|
273
|
+
return (getToolSkillStatus(projectRoot, t.value).configured ||
|
|
274
|
+
toolHasAnyConfiguredCommand(projectRoot, t.value) ||
|
|
275
|
+
(Boolean(t.skillsDir) &&
|
|
276
|
+
readSharedSkillTarget(projectRoot, t.skillsDir) === t.value));
|
|
277
|
+
});
|
|
278
|
+
const activeProjectTools = new Set(reconcileSharedSkillTargets(projectRoot, configured.filter((tool) => tool.skillsDir)).map((tool) => tool.value));
|
|
279
|
+
return configured
|
|
280
|
+
.filter((tool) => tool.globalSkillsDir || activeProjectTools.has(tool.value))
|
|
281
|
+
.map((tool) => tool.value);
|
|
251
282
|
}
|
|
252
283
|
/**
|
|
253
284
|
* Gets version status for all configured tools.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type AIToolOption } from './config.js';
|
|
2
|
+
/** Reads a valid-looking marker value without letting linked roots escape. */
|
|
3
|
+
export declare function readSharedSkillTarget(projectPath: string, skillsDir: string): string | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* A shared skill root can only hold one rendered variant of each skill.
|
|
6
|
+
* Keep the writer recorded so later updates do not infer every tool that
|
|
7
|
+
* happens to use the same directory.
|
|
8
|
+
*/
|
|
9
|
+
export declare function reconcileSharedSkillTargets(projectPath: string, tools: AIToolOption[]): AIToolOption[];
|
|
10
|
+
/**
|
|
11
|
+
* Returns whether a tool is the active writer for its physical skills root.
|
|
12
|
+
* Non-shared roots are always active.
|
|
13
|
+
*/
|
|
14
|
+
export declare function isSharedSkillTargetActive(projectPath: string, toolId: string): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The tool that already owns `toolId`'s shared skills root, when a DIFFERENT
|
|
17
|
+
* one does. Returns the owner's tool id only when the root already carries an
|
|
18
|
+
* ownership signal (a marker or generated skills) AND reconciliation resolves
|
|
19
|
+
* it to another tool. An empty or unclaimed root returns undefined, so a
|
|
20
|
+
* genuine first-time legacy upgrade — e.g. a Codex-only user with no `.agents`
|
|
21
|
+
* yet — is never reported as owned.
|
|
22
|
+
*/
|
|
23
|
+
export declare function sharedSkillRootOwner(projectPath: string, toolId: string): string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Whether generating `toolId` into its shared skills root would clobber a tree
|
|
26
|
+
* a DIFFERENT tool already owns — the guard the legacy-upgrade path uses before
|
|
27
|
+
* writing skills. See {@link sharedSkillRootOwner} for the ownership rules.
|
|
28
|
+
*/
|
|
29
|
+
export declare function sharedSkillRootOwnedByOther(projectPath: string, toolId: string): boolean;
|
|
30
|
+
export declare function writeSharedSkillTarget(projectPath: string, toolId: string): void;
|
|
31
|
+
//# sourceMappingURL=shared-skill-target.d.ts.map
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import { AI_TOOLS, OPENSPEC_SKILL_NAMES } from './config.js';
|
|
4
|
+
import { FileSystemUtils } from '../utils/file-system.js';
|
|
5
|
+
const TARGET_MARKER = '.openspec-target';
|
|
6
|
+
/** Returns the ownership-marker path for one shared skills root. */
|
|
7
|
+
function markerPath(projectPath, skillsDir) {
|
|
8
|
+
return path.join(projectPath, skillsDir, 'skills', TARGET_MARKER);
|
|
9
|
+
}
|
|
10
|
+
/** Reads a valid-looking marker value without letting linked roots escape. */
|
|
11
|
+
export function readSharedSkillTarget(projectPath, skillsDir) {
|
|
12
|
+
try {
|
|
13
|
+
const target = markerPath(projectPath, skillsDir);
|
|
14
|
+
FileSystemUtils.assertProjectArtifactPath(projectPath, target);
|
|
15
|
+
return fs.readFileSync(target, 'utf-8').trim() || undefined;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** Whether a tool still has an allowlisted managed skill under an old root. */
|
|
22
|
+
function hasLegacySkills(projectPath, tool) {
|
|
23
|
+
return (tool.legacySkillsDirs ?? []).some((root) => {
|
|
24
|
+
const skillsDir = path.join(projectPath, root, 'skills');
|
|
25
|
+
return OPENSPEC_SKILL_NAMES.some((skillName) => {
|
|
26
|
+
try {
|
|
27
|
+
const skillFile = path.join(skillsDir, skillName, 'SKILL.md');
|
|
28
|
+
FileSystemUtils.assertProjectArtifactPath(projectPath, skillFile);
|
|
29
|
+
return fs.existsSync(skillFile);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Infers pre-marker ownership from generated invocation syntax. This preserves
|
|
39
|
+
* both existing generic `.agents` trees and Codex trees users moved manually.
|
|
40
|
+
*/
|
|
41
|
+
function inferSharedSkillTarget(projectPath, skillsDir) {
|
|
42
|
+
let foundGenericReference = false;
|
|
43
|
+
for (const skillName of OPENSPEC_SKILL_NAMES) {
|
|
44
|
+
const skillFile = path.join(projectPath, skillsDir, 'skills', skillName, 'SKILL.md');
|
|
45
|
+
try {
|
|
46
|
+
FileSystemUtils.assertProjectArtifactPath(projectPath, skillFile);
|
|
47
|
+
const content = fs.readFileSync(skillFile, 'utf-8');
|
|
48
|
+
if (content.includes('$openspec-'))
|
|
49
|
+
return 'codex';
|
|
50
|
+
if (content.includes('/openspec-'))
|
|
51
|
+
foundGenericReference = true;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
// Missing, unreadable, or out-of-project files provide no ownership signal.
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return foundGenericReference ? 'agents' : undefined;
|
|
58
|
+
}
|
|
59
|
+
/** Whether the canonical shared root already contains an OpenSpec skill. */
|
|
60
|
+
function hasCurrentSkills(projectPath, skillsDir) {
|
|
61
|
+
return OPENSPEC_SKILL_NAMES.some((skillName) => {
|
|
62
|
+
const skillFile = path.join(projectPath, skillsDir, 'skills', skillName, 'SKILL.md');
|
|
63
|
+
try {
|
|
64
|
+
FileSystemUtils.assertProjectArtifactPath(projectPath, skillFile);
|
|
65
|
+
return fs.existsSync(skillFile);
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* A shared skill root can only hold one rendered variant of each skill.
|
|
74
|
+
* Keep the writer recorded so later updates do not infer every tool that
|
|
75
|
+
* happens to use the same directory.
|
|
76
|
+
*/
|
|
77
|
+
export function reconcileSharedSkillTargets(projectPath, tools) {
|
|
78
|
+
const byRoot = new Map();
|
|
79
|
+
for (const tool of tools) {
|
|
80
|
+
if (!tool.skillsDir)
|
|
81
|
+
continue;
|
|
82
|
+
const group = byRoot.get(tool.skillsDir) ?? [];
|
|
83
|
+
group.push(tool);
|
|
84
|
+
byRoot.set(tool.skillsDir, group);
|
|
85
|
+
}
|
|
86
|
+
const reconciled = [];
|
|
87
|
+
for (const group of byRoot.values()) {
|
|
88
|
+
if (group.length === 1) {
|
|
89
|
+
reconciled.push(group[0]);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const root = group[0].skillsDir;
|
|
93
|
+
const marked = readSharedSkillTarget(projectPath, root);
|
|
94
|
+
const markedTool = group.find((tool) => tool.value === marked);
|
|
95
|
+
if (markedTool) {
|
|
96
|
+
reconciled.push(markedTool);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const inferred = inferSharedSkillTarget(projectPath, root);
|
|
100
|
+
const legacyCodex = group.find((tool) => tool.value === 'codex' && hasLegacySkills(projectPath, tool));
|
|
101
|
+
if (inferred === 'agents' && legacyCodex) {
|
|
102
|
+
// Before ownership markers existed, selecting both targets produced a
|
|
103
|
+
// generic canonical tree plus a Codex-only legacy tree. Codex now emits
|
|
104
|
+
// a dual-syntax canonical tree, so it can safely consolidate that state.
|
|
105
|
+
reconciled.push(legacyCodex);
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
const inferredTool = group.find((tool) => tool.value === inferred);
|
|
109
|
+
if (inferredTool) {
|
|
110
|
+
reconciled.push(inferredTool);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
// An unmarked canonical tree predates Codex's move into `.agents`; keep
|
|
114
|
+
// that established agents target instead of overwriting it from `.codex`.
|
|
115
|
+
if (hasCurrentSkills(projectPath, root)) {
|
|
116
|
+
reconciled.push(group.find((tool) => tool.value === 'agents') ?? group[0]);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const legacyTool = group.find((tool) => hasLegacySkills(projectPath, tool));
|
|
120
|
+
if (legacyTool) {
|
|
121
|
+
reconciled.push(legacyTool);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
// `.agents` existed as the vendor-neutral target before Codex adopted it.
|
|
125
|
+
// Unmarked trees therefore retain that established meaning.
|
|
126
|
+
reconciled.push(group.find((tool) => tool.value === 'agents') ?? group[0]);
|
|
127
|
+
}
|
|
128
|
+
return reconciled;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Returns whether a tool is the active writer for its physical skills root.
|
|
132
|
+
* Non-shared roots are always active.
|
|
133
|
+
*/
|
|
134
|
+
export function isSharedSkillTargetActive(projectPath, toolId) {
|
|
135
|
+
const tool = AI_TOOLS.find((candidate) => candidate.value === toolId);
|
|
136
|
+
if (!tool?.skillsDir)
|
|
137
|
+
return false;
|
|
138
|
+
const sharingRoot = AI_TOOLS.filter((candidate) => candidate.skillsDir === tool.skillsDir);
|
|
139
|
+
if (sharingRoot.length < 2)
|
|
140
|
+
return true;
|
|
141
|
+
return reconcileSharedSkillTargets(projectPath, sharingRoot)
|
|
142
|
+
.some((candidate) => candidate.value === toolId);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* The tool that already owns `toolId`'s shared skills root, when a DIFFERENT
|
|
146
|
+
* one does. Returns the owner's tool id only when the root already carries an
|
|
147
|
+
* ownership signal (a marker or generated skills) AND reconciliation resolves
|
|
148
|
+
* it to another tool. An empty or unclaimed root returns undefined, so a
|
|
149
|
+
* genuine first-time legacy upgrade — e.g. a Codex-only user with no `.agents`
|
|
150
|
+
* yet — is never reported as owned.
|
|
151
|
+
*/
|
|
152
|
+
export function sharedSkillRootOwner(projectPath, toolId) {
|
|
153
|
+
const tool = AI_TOOLS.find((candidate) => candidate.value === toolId);
|
|
154
|
+
if (!tool?.skillsDir)
|
|
155
|
+
return undefined;
|
|
156
|
+
const sharingRoot = AI_TOOLS.filter((candidate) => candidate.skillsDir === tool.skillsDir);
|
|
157
|
+
if (sharingRoot.length < 2)
|
|
158
|
+
return undefined;
|
|
159
|
+
const hasOwnerSignal = readSharedSkillTarget(projectPath, tool.skillsDir) !== undefined ||
|
|
160
|
+
hasCurrentSkills(projectPath, tool.skillsDir);
|
|
161
|
+
if (!hasOwnerSignal)
|
|
162
|
+
return undefined;
|
|
163
|
+
const owner = reconcileSharedSkillTargets(projectPath, sharingRoot)[0]?.value;
|
|
164
|
+
return owner && owner !== toolId ? owner : undefined;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Whether generating `toolId` into its shared skills root would clobber a tree
|
|
168
|
+
* a DIFFERENT tool already owns — the guard the legacy-upgrade path uses before
|
|
169
|
+
* writing skills. See {@link sharedSkillRootOwner} for the ownership rules.
|
|
170
|
+
*/
|
|
171
|
+
export function sharedSkillRootOwnedByOther(projectPath, toolId) {
|
|
172
|
+
return sharedSkillRootOwner(projectPath, toolId) !== undefined;
|
|
173
|
+
}
|
|
174
|
+
export function writeSharedSkillTarget(projectPath, toolId) {
|
|
175
|
+
const tool = AI_TOOLS.find((candidate) => candidate.value === toolId);
|
|
176
|
+
if (!tool?.skillsDir)
|
|
177
|
+
return;
|
|
178
|
+
const sharingRoot = AI_TOOLS.filter((candidate) => candidate.skillsDir === tool.skillsDir);
|
|
179
|
+
if (sharingRoot.length < 2)
|
|
180
|
+
return;
|
|
181
|
+
const target = markerPath(projectPath, tool.skillsDir);
|
|
182
|
+
FileSystemUtils.assertProjectArtifactPath(projectPath, target);
|
|
183
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
184
|
+
fs.writeFileSync(target, `${toolId}\n`, 'utf-8');
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=shared-skill-target.js.map
|
|
@@ -7,7 +7,11 @@
|
|
|
7
7
|
export interface SpecUpdate {
|
|
8
8
|
/** Capability id relative to the specs root, forward-slash separated (e.g. "web" or "platform/session-layout"). */
|
|
9
9
|
id: string;
|
|
10
|
+
/** Allowed root for the delta source. */
|
|
11
|
+
sourceRoot: string;
|
|
10
12
|
source: string;
|
|
13
|
+
/** Allowed root for the main-spec target. */
|
|
14
|
+
targetRoot: string;
|
|
11
15
|
target: string;
|
|
12
16
|
exists: boolean;
|
|
13
17
|
}
|
|
@@ -30,7 +34,74 @@ export declare function buildUpdatedSpec(update: SpecUpdate, changeName: string,
|
|
|
30
34
|
renamed: number;
|
|
31
35
|
};
|
|
32
36
|
warnings: string[];
|
|
37
|
+
/**
|
|
38
|
+
* Every canonical `### Requirement:` block the delta could act on is gone.
|
|
39
|
+
* This is only a *candidate* signal for retirement (#1302): the validator, not
|
|
40
|
+
* this count, decides whether `rebuilt` is actually unwritable - it recognises
|
|
41
|
+
* requirement shapes this parser sweeps into the preamble, so a spec can be
|
|
42
|
+
* blockless here and still validate. See `isRetirableSpec` in archive.ts.
|
|
43
|
+
*/
|
|
44
|
+
noRequirementBlocks: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Every non-blank line of the spec this merge cannot name.
|
|
47
|
+
*
|
|
48
|
+
* Retirement deletes the whole file, so the only safe question is whether the
|
|
49
|
+
* merge can account for all of it. `extractRequirementsSection` splits a spec
|
|
50
|
+
* into five slices, and auditing a subset is how this guard kept failing: for
|
|
51
|
+
* seven rounds it looked for requirement-SHAPED text and was beaten by a new
|
|
52
|
+
* disguise each time, and when it started asking where content landed it
|
|
53
|
+
* still read only the preamble and the tail - so content simply moved into a
|
|
54
|
+
* slice nobody checked, and authored prose sitting inside a removed block's
|
|
55
|
+
* raw was deleted while the report said only "Purpose" was lost.
|
|
56
|
+
*
|
|
57
|
+
* So this accounts for the whole file: the title, the `## Purpose` section,
|
|
58
|
+
* the `## Requirements` header, and, inside each requirement block, the parts
|
|
59
|
+
* that make up a requirement - its header, its statement, and its scenarios'
|
|
60
|
+
* bullets. Every other non-blank line is reported and refuses the retirement.
|
|
61
|
+
*
|
|
62
|
+
* Fails safe in every direction: a line this cannot classify counts as
|
|
63
|
+
* unaccounted, which refuses rather than deletes.
|
|
64
|
+
*/
|
|
65
|
+
unaccountedContent: string[];
|
|
33
66
|
}>;
|
|
67
|
+
/**
|
|
68
|
+
* Retire a capability whose last requirement a delta removed: delete its main
|
|
69
|
+
* spec and prune any directories the deletion leaves empty. Returns false when
|
|
70
|
+
* there was nothing to delete.
|
|
71
|
+
*
|
|
72
|
+
* Gated by the caller on the change's `retire_capabilities` marker, so the one
|
|
73
|
+
* archive action that removes a file from `openspec/specs/` is always something
|
|
74
|
+
* the author asked for rather than something inferred from a delta's shape. The
|
|
75
|
+
* file is recoverable from git, which the report names; applying REMOVED already
|
|
76
|
+
* deletes requirement content from a main spec, so deleting the spec once
|
|
77
|
+
* nothing is left is the same operation carried to its end rather than a new
|
|
78
|
+
* kind of act.
|
|
79
|
+
*
|
|
80
|
+
* Only the generated `spec.md` is removed - a directory holding anything else (a
|
|
81
|
+
* nested capability, a hand-kept note) is left in place.
|
|
82
|
+
*
|
|
83
|
+
* The target must resolve inside the selected specs root. A capability-directory
|
|
84
|
+
* symlink must not turn a retirement marker into authorization to delete an
|
|
85
|
+
* unrelated external file. A symlinked `spec.md` itself is safe: unlink removes
|
|
86
|
+
* the link and leaves its target alone.
|
|
87
|
+
*
|
|
88
|
+
* Directory pruning IS bounded, by REAL paths rather than string prefixes:
|
|
89
|
+
* `path.resolve` collapses `..` but does not resolve symlinks, and `readdir` and
|
|
90
|
+
* `rmdir` both follow them, so a symlinked capability directory would otherwise
|
|
91
|
+
* let the walk delete directories outside the specs root entirely.
|
|
92
|
+
*/
|
|
93
|
+
export declare function retireSpec(update: SpecUpdate, mainSpecsDir: string, options?: {
|
|
94
|
+
silent?: boolean;
|
|
95
|
+
displayPath?: string;
|
|
96
|
+
beforeMutate?: () => Promise<void>;
|
|
97
|
+
verifyDisplaced?: (displacedPath: string) => Promise<void>;
|
|
98
|
+
deferDelete?: boolean;
|
|
99
|
+
}): Promise<{
|
|
100
|
+
retired: boolean;
|
|
101
|
+
resolvedPath?: string;
|
|
102
|
+
displacedPath?: string;
|
|
103
|
+
}>;
|
|
104
|
+
export declare function finalizeRetiredSpec(target: string, displacedPath: string, mainSpecsDir: string): Promise<void>;
|
|
34
105
|
/**
|
|
35
106
|
* Write an updated spec to disk.
|
|
36
107
|
*/
|
|
@@ -42,6 +113,7 @@ export declare function writeUpdatedSpec(update: SpecUpdate, rebuilt: string, co
|
|
|
42
113
|
}, options?: {
|
|
43
114
|
silent?: boolean;
|
|
44
115
|
displayPath?: string;
|
|
116
|
+
beforeMutate?: () => Promise<void>;
|
|
45
117
|
}): Promise<void>;
|
|
46
118
|
/**
|
|
47
119
|
* Build a skeleton spec for new capabilities. When the delta spec authored a
|