@polymorphism-tech/morph-spec 4.7.1 → 4.8.1
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/.morph/analytics/threads-log.jsonl +54 -0
- package/.morph/state.json +198 -0
- package/LICENSE +1 -2
- package/README.md +379 -414
- package/bin/morph-spec.js +57 -403
- package/bin/validate.js +2 -26
- package/claude-plugin.json +2 -2
- package/docs/ARCHITECTURE.md +43 -46
- package/docs/CHEATSHEET.md +203 -221
- package/docs/COMMAND-FLOWS.md +319 -289
- package/docs/QUICKSTART.md +2 -8
- package/docs/plans/2026-02-22-claude-docs-morph-alignment-analysis.md +2 -0
- package/docs/plans/2026-02-22-claude-settings.md +2 -0
- package/docs/plans/2026-02-22-morph-cc-alignment-impl.md +2 -0
- package/docs/plans/2026-02-22-morph-spec-next.md +2 -0
- package/docs/plans/2026-02-22-native-alignment-design.md +2 -0
- package/docs/plans/2026-02-22-native-alignment-impl.md +2 -0
- package/docs/plans/2026-02-22-native-enrichment-design.md +2 -0
- package/docs/plans/2026-02-22-native-enrichment.md +2 -0
- package/docs/plans/2026-02-23-ddd-architecture-refactor.md +2 -0
- package/docs/plans/2026-02-23-ddd-nextsteps.md +2 -0
- package/docs/plans/2026-02-23-infra-architect-refactor.md +2 -0
- package/docs/plans/2026-02-23-nextjs-code-review-design.md +2 -1
- package/docs/plans/2026-02-23-nextjs-code-review-impl.md +2 -0
- package/docs/plans/2026-02-23-nextjs-standards-design.md +2 -1
- package/docs/plans/2026-02-23-nextjs-standards-impl.md +2 -0
- package/docs/plans/2026-02-24-cli-radical-simplification.md +592 -0
- package/docs/plans/2026-02-24-framework-failure-points.md +125 -0
- package/docs/plans/2026-02-24-morph-init-design.md +337 -0
- package/docs/plans/2026-02-24-morph-init-impl.md +1269 -0
- package/docs/plans/2026-02-24-tutorial-command-design.md +71 -0
- package/docs/plans/2026-02-24-tutorial-command.md +298 -0
- package/framework/CLAUDE.md +2 -2
- package/framework/commands/morph-proposal.md +3 -3
- package/framework/hooks/README.md +11 -10
- package/framework/hooks/claude-code/notification/approval-reminder.js +2 -0
- package/framework/hooks/claude-code/post-tool-use/dispatch.js +1 -1
- package/framework/hooks/claude-code/pre-tool-use/protect-readonly-files.js +4 -55
- package/framework/hooks/claude-code/session-start/inject-morph-context.js +20 -5
- package/framework/hooks/claude-code/statusline.py +6 -1
- package/framework/hooks/claude-code/stop/validate-completion.js +1 -1
- package/framework/hooks/claude-code/user-prompt/enrich-prompt.js +1 -1
- package/framework/hooks/dev/check-sync-health.js +117 -0
- package/framework/hooks/dev/guard-version-numbers.js +57 -0
- package/framework/hooks/dev/sync-standards-registry.js +60 -0
- package/framework/hooks/dev/sync-template-registry.js +60 -0
- package/framework/hooks/dev/validate-skill-format.js +70 -0
- package/framework/hooks/dev/validate-standard-format.js +73 -0
- package/framework/hooks/shared/payload-utils.js +39 -0
- package/framework/hooks/shared/state-reader.js +25 -1
- package/framework/rules/morph-workflow.md +1 -1
- package/framework/skills/level-0-meta/morph-init/SKILL.md +216 -0
- package/framework/skills/level-0-meta/morph-replicate/SKILL.md +4 -4
- package/framework/skills/level-0-meta/tool-usage-guide/SKILL.md +4 -4
- package/framework/skills/level-0-meta/verification-before-completion/SKILL.md +1 -1
- package/framework/skills/level-1-workflows/phase-clarify/SKILL.md +192 -191
- package/framework/skills/level-1-workflows/phase-codebase-analysis/SKILL.md +181 -180
- package/framework/skills/level-1-workflows/phase-design/SKILL.md +339 -338
- package/framework/skills/level-1-workflows/phase-implement/SKILL.md +254 -253
- package/framework/skills/level-1-workflows/phase-setup/SKILL.md +168 -170
- package/framework/skills/level-1-workflows/phase-tasks/SKILL.md +284 -283
- package/framework/skills/level-1-workflows/phase-uiux/SKILL.md +246 -245
- package/framework/templates/examples/design-system-examples.md +1 -1
- package/framework/templates/ui/FluentDesignTheme.cs +1 -1
- package/framework/templates/ui/MudTheme.cs +1 -1
- package/framework/templates/ui/design-system.css +1 -1
- package/package.json +4 -2
- package/scripts/bump-version.js +248 -0
- package/scripts/install-dev-hooks.js +138 -0
- package/src/commands/agents/index.js +1 -2
- package/src/commands/index.js +13 -16
- package/src/commands/project/doctor.js +100 -14
- package/src/commands/project/index.js +7 -10
- package/src/commands/project/init.js +398 -555
- package/src/commands/project/install-plugin-cmd.js +28 -0
- package/src/commands/project/setup-infra-cmd.js +12 -0
- package/src/commands/project/tutorial.js +115 -0
- package/src/commands/project/update.js +22 -37
- package/src/commands/state/approve.js +213 -221
- package/src/commands/state/index.js +0 -1
- package/src/commands/state/state.js +337 -365
- package/src/commands/templates/index.js +0 -4
- package/src/commands/trust/trust.js +1 -93
- package/src/commands/utils/index.js +1 -5
- package/src/commands/validation/index.js +1 -5
- package/src/core/registry/command-registry.js +11 -285
- package/src/core/state/state-manager.js +5 -2
- package/src/lib/detectors/index.js +81 -87
- package/src/lib/detectors/structure-detector.js +275 -273
- package/src/lib/generators/recap-generator.js +232 -225
- package/src/lib/installers/mcp-installer.js +18 -3
- package/src/scripts/global-install.js +34 -0
- package/src/scripts/install-plugin.js +126 -0
- package/src/scripts/setup-infra.js +203 -0
- package/src/utils/agents-installer.js +10 -1
- package/src/utils/hooks-installer.js +70 -17
- package/CLAUDE.md +0 -77
- package/docs/claude-alignment-report.md +0 -137
- package/docs/examples/order-management/contracts.cs +0 -84
- package/docs/examples/order-management/proposal.md +0 -24
- package/docs/examples/order-management/spec.md +0 -162
- package/src/commands/feature/create-story.js +0 -362
- package/src/commands/feature/index.js +0 -6
- package/src/commands/feature/shard-spec.js +0 -225
- package/src/commands/feature/sprint-status.js +0 -250
- package/src/commands/generation/generate-onboarding.js +0 -169
- package/src/commands/generation/generate.js +0 -276
- package/src/commands/generation/index.js +0 -5
- package/src/commands/learning/capture-pattern.js +0 -121
- package/src/commands/learning/index.js +0 -5
- package/src/commands/learning/search-patterns.js +0 -126
- package/src/commands/mcp/mcp.js +0 -102
- package/src/commands/project/changes.js +0 -66
- package/src/commands/project/cost.js +0 -179
- package/src/commands/project/detect.js +0 -114
- package/src/commands/project/diff.js +0 -278
- package/src/commands/project/revert.js +0 -173
- package/src/commands/project/standards.js +0 -80
- package/src/commands/project/sync.js +0 -167
- package/src/commands/project/update-agents.js +0 -23
- package/src/commands/state/rollback-phase.js +0 -185
- package/src/commands/templates/template-customize.js +0 -87
- package/src/commands/templates/template-list.js +0 -114
- package/src/commands/templates/template-show.js +0 -129
- package/src/commands/templates/template-validate.js +0 -91
- package/src/commands/utils/troubleshoot.js +0 -222
- package/src/commands/validation/analyze-blazor-concurrency.js +0 -193
- package/src/commands/validation/lint-fluent.js +0 -352
- package/src/commands/validation/validate-blazor-state.js +0 -210
- package/src/commands/validation/validate-blazor.js +0 -156
- package/src/commands/validation/validate-css.js +0 -84
- package/src/lib/detectors/conversation-analyzer.js +0 -163
- package/src/lib/learning/index.js +0 -7
- package/src/lib/learning/learning-system.js +0 -520
- package/src/lib/troubleshooting/index.js +0 -8
- package/src/lib/troubleshooting/troubleshoot-grep.js +0 -198
- package/src/lib/troubleshooting/troubleshoot-index.js +0 -144
- package/src/llm/environment-detector.js +0 -43
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// src/scripts/install-plugin.js
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import { homedir } from 'os';
|
|
4
|
+
import { existsSync, mkdirSync, writeFileSync, readFileSync } from 'fs';
|
|
5
|
+
import { mkdir, writeFile } from 'fs/promises';
|
|
6
|
+
import https from 'node:https';
|
|
7
|
+
|
|
8
|
+
const PLUGINS_DIR = join(homedir(), '.claude', 'plugins');
|
|
9
|
+
const CACHE_DIR = join(PLUGINS_DIR, 'cache', 'claude-plugins-official');
|
|
10
|
+
const INSTALLED_FILE = join(PLUGINS_DIR, 'installed_plugins.json');
|
|
11
|
+
const GH_REPO = 'anthropics/claude-plugins-official';
|
|
12
|
+
|
|
13
|
+
/** Fetch JSON from GitHub API (no auth — public repo) */
|
|
14
|
+
async function fetchGitHub(path) {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
const opts = {
|
|
17
|
+
hostname: 'api.github.com',
|
|
18
|
+
path,
|
|
19
|
+
headers: { 'User-Agent': 'morph-spec', 'Accept': 'application/vnd.github.v3+json' }
|
|
20
|
+
};
|
|
21
|
+
https.get(opts, (res) => {
|
|
22
|
+
let data = '';
|
|
23
|
+
res.on('data', c => data += c);
|
|
24
|
+
res.on('end', () => {
|
|
25
|
+
try { resolve(JSON.parse(data)); }
|
|
26
|
+
catch (e) { reject(new Error(`GitHub API parse error: ${data.slice(0, 200)}`)); }
|
|
27
|
+
});
|
|
28
|
+
}).on('error', reject);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Download raw file content from a URL, following one redirect */
|
|
33
|
+
async function downloadFile(rawUrl) {
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
const doGet = (url) => {
|
|
36
|
+
const parsed = new URL(url);
|
|
37
|
+
https.get({
|
|
38
|
+
hostname: parsed.hostname,
|
|
39
|
+
path: parsed.pathname + parsed.search,
|
|
40
|
+
headers: { 'User-Agent': 'morph-spec' }
|
|
41
|
+
}, (res) => {
|
|
42
|
+
if (res.statusCode === 301 || res.statusCode === 302) {
|
|
43
|
+
return doGet(res.headers.location);
|
|
44
|
+
}
|
|
45
|
+
const chunks = [];
|
|
46
|
+
res.on('data', c => chunks.push(c));
|
|
47
|
+
res.on('end', () => resolve(Buffer.concat(chunks)));
|
|
48
|
+
}).on('error', reject);
|
|
49
|
+
};
|
|
50
|
+
doGet(rawUrl);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Read installed_plugins.json safely */
|
|
55
|
+
export function readInstalledPlugins() {
|
|
56
|
+
if (!existsSync(INSTALLED_FILE)) return { version: 2, plugins: {} };
|
|
57
|
+
try { return JSON.parse(readFileSync(INSTALLED_FILE, 'utf8')); }
|
|
58
|
+
catch { return { version: 2, plugins: {} }; }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Check if plugin key exists in the plugins map */
|
|
62
|
+
export function isPluginInstalled(plugins, name) {
|
|
63
|
+
return `${name}@claude-plugins-official` in plugins;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Build an installed_plugins.json entry */
|
|
67
|
+
export function buildInstallEntry(pluginName, installPath, gitCommitSha, version) {
|
|
68
|
+
const now = new Date().toISOString();
|
|
69
|
+
return { scope: 'user', installPath, version, installedAt: now, lastUpdated: now, gitCommitSha };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Resolve latest commit SHA for a plugin path in the repo */
|
|
73
|
+
export async function resolvePluginVersion(pluginName) {
|
|
74
|
+
const commits = await fetchGitHub(`/repos/${GH_REPO}/commits?path=${pluginName}&per_page=1`);
|
|
75
|
+
if (!Array.isArray(commits) || commits.length === 0) {
|
|
76
|
+
throw new Error(`Could not resolve version for plugin: ${pluginName}`);
|
|
77
|
+
}
|
|
78
|
+
const sha = commits[0].sha;
|
|
79
|
+
return { sha, shortSha: sha.slice(0, 12) };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Download all files for a plugin from the repo tree */
|
|
83
|
+
async function downloadPluginFiles(pluginName, sha, destDir) {
|
|
84
|
+
const tree = await fetchGitHub(`/repos/${GH_REPO}/git/trees/${sha}?recursive=1`);
|
|
85
|
+
if (!tree.tree) throw new Error('GitHub tree API returned unexpected shape');
|
|
86
|
+
|
|
87
|
+
const pluginFiles = tree.tree.filter(f => f.path.startsWith(`${pluginName}/`) && f.type === 'blob');
|
|
88
|
+
if (pluginFiles.length === 0) throw new Error(`Plugin "${pluginName}" not found in repository`);
|
|
89
|
+
|
|
90
|
+
for (const file of pluginFiles) {
|
|
91
|
+
const relativePath = file.path.slice(pluginName.length + 1);
|
|
92
|
+
const destPath = join(destDir, relativePath);
|
|
93
|
+
await mkdir(join(destPath, '..'), { recursive: true });
|
|
94
|
+
const content = await downloadFile(
|
|
95
|
+
`https://raw.githubusercontent.com/${GH_REPO}/${sha}/${file.path}`
|
|
96
|
+
);
|
|
97
|
+
await writeFile(destPath, content);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Install a Claude Code plugin from GitHub.
|
|
103
|
+
* @param {string} pluginName - e.g. "superpowers"
|
|
104
|
+
* @returns {{ installed: boolean, version: string, alreadyInstalled: boolean }}
|
|
105
|
+
*/
|
|
106
|
+
export async function installPlugin(pluginName) {
|
|
107
|
+
const data = readInstalledPlugins();
|
|
108
|
+
if (isPluginInstalled(data.plugins, pluginName)) {
|
|
109
|
+
const existing = data.plugins[`${pluginName}@claude-plugins-official`];
|
|
110
|
+
const version = Array.isArray(existing) ? existing[0]?.version : 'unknown';
|
|
111
|
+
return { installed: true, alreadyInstalled: true, version };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const { sha, shortSha } = await resolvePluginVersion(pluginName);
|
|
115
|
+
const installPath = join(CACHE_DIR, pluginName, shortSha);
|
|
116
|
+
|
|
117
|
+
await mkdir(installPath, { recursive: true });
|
|
118
|
+
await downloadPluginFiles(pluginName, sha, installPath);
|
|
119
|
+
|
|
120
|
+
const entry = buildInstallEntry(pluginName, installPath, sha, shortSha);
|
|
121
|
+
data.plugins[`${pluginName}@claude-plugins-official`] = [entry];
|
|
122
|
+
mkdirSync(PLUGINS_DIR, { recursive: true });
|
|
123
|
+
writeFileSync(INSTALLED_FILE, JSON.stringify(data, null, 2));
|
|
124
|
+
|
|
125
|
+
return { installed: true, alreadyInstalled: false, version: shortSha };
|
|
126
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* setup-infra.js
|
|
3
|
+
*
|
|
4
|
+
* Headless infrastructure setup for MORPH-SPEC.
|
|
5
|
+
* Extracted from init.js (steps 1-10) so it can be called by the
|
|
6
|
+
* /morph-init Claude Code skill via `morph-spec setup-infra` without
|
|
7
|
+
* interactive prompts or stack detection.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* import { setupInfra } from './setup-infra.js';
|
|
11
|
+
* await setupInfra('/path/to/project');
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { join, dirname } from 'path';
|
|
15
|
+
import { fileURLToPath } from 'url';
|
|
16
|
+
import {
|
|
17
|
+
copyDirectory,
|
|
18
|
+
copyFile,
|
|
19
|
+
pathExists,
|
|
20
|
+
writeJson,
|
|
21
|
+
ensureDir,
|
|
22
|
+
writeFile,
|
|
23
|
+
updateGitignore
|
|
24
|
+
} from '../utils/file-copier.js';
|
|
25
|
+
import { saveProjectMorphVersion, getInstalledCLIVersion } from '../utils/version-checker.js';
|
|
26
|
+
import { installClaudeHooks, installGlobalStatusline } from '../utils/claude-settings-manager.js';
|
|
27
|
+
import { installSkills } from '../utils/skills-installer.js';
|
|
28
|
+
import { installAgents, installDomainAgents } from '../utils/agents-installer.js';
|
|
29
|
+
|
|
30
|
+
const FRAMEWORK_DIR = join(dirname(fileURLToPath(import.meta.url)), '..', '..', 'framework');
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Installs MORPH-SPEC infrastructure into the target project directory.
|
|
34
|
+
* Headless — no prompts, no spinner (suppressed when MORPH_QUIET=1), no stack detection.
|
|
35
|
+
*
|
|
36
|
+
* @param {string} targetPath - Absolute path to the target project directory
|
|
37
|
+
*/
|
|
38
|
+
export async function setupInfra(targetPath) {
|
|
39
|
+
const quiet = process.env.MORPH_QUIET === '1';
|
|
40
|
+
|
|
41
|
+
function log(msg) {
|
|
42
|
+
if (!quiet) process.stdout.write(msg + '\n');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// --- 1. Copy CLAUDE.md (backup existing non-MORPH CLAUDE.md) ---
|
|
46
|
+
log('Step 1: Copying CLAUDE.md...');
|
|
47
|
+
const claudeMdSrc = join(FRAMEWORK_DIR, 'CLAUDE.md');
|
|
48
|
+
const claudeMdDest = join(targetPath, 'CLAUDE.md');
|
|
49
|
+
|
|
50
|
+
if (await pathExists(claudeMdDest)) {
|
|
51
|
+
const { readFile } = await import('../utils/file-copier.js');
|
|
52
|
+
const existingContent = await readFile(claudeMdDest);
|
|
53
|
+
if (!existingContent.includes('MORPH-SPEC')) {
|
|
54
|
+
await copyFile(claudeMdDest, `${claudeMdDest}.backup`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
await copyFile(claudeMdSrc, claudeMdDest);
|
|
58
|
+
|
|
59
|
+
// --- 2. Create .morph directory structure ---
|
|
60
|
+
log('Step 2: Creating .morph structure...');
|
|
61
|
+
const morphPath = join(targetPath, '.morph');
|
|
62
|
+
const configDir = join(morphPath, 'config');
|
|
63
|
+
const frameworkDestDir = join(morphPath, 'framework');
|
|
64
|
+
const contextDir = join(morphPath, 'context');
|
|
65
|
+
const featuresDir = join(morphPath, 'features');
|
|
66
|
+
const checkpointsDir = join(morphPath, 'checkpoints');
|
|
67
|
+
const memoryDir = join(morphPath, 'memory');
|
|
68
|
+
const archiveDir = join(morphPath, 'archive');
|
|
69
|
+
|
|
70
|
+
await ensureDir(configDir);
|
|
71
|
+
await ensureDir(frameworkDestDir);
|
|
72
|
+
await ensureDir(contextDir);
|
|
73
|
+
await ensureDir(featuresDir);
|
|
74
|
+
await ensureDir(checkpointsDir);
|
|
75
|
+
await ensureDir(memoryDir);
|
|
76
|
+
await ensureDir(archiveDir);
|
|
77
|
+
|
|
78
|
+
// --- 3. Write minimal config.json (only if not exists) ---
|
|
79
|
+
log('Step 3: Writing config.json...');
|
|
80
|
+
const configPath = join(configDir, 'config.json');
|
|
81
|
+
if (!(await pathExists(configPath))) {
|
|
82
|
+
const dirName = targetPath.split(/[\/]/).pop();
|
|
83
|
+
const config = {
|
|
84
|
+
framework: 'global',
|
|
85
|
+
frameworkVersion: getInstalledCLIVersion(),
|
|
86
|
+
project: {
|
|
87
|
+
name: dirName
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
await writeJson(configPath, config);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// --- 4. Write placeholder context/README.md (only if not exists) ---
|
|
94
|
+
log('Step 4: Writing context/README.md...');
|
|
95
|
+
const contextReadmePath = join(contextDir, 'README.md');
|
|
96
|
+
if (!(await pathExists(contextReadmePath))) {
|
|
97
|
+
const dirName = targetPath.split(/[\/]/).pop();
|
|
98
|
+
const readmeContent = `# ${dirName} — Project Context\n\nRun /morph-init to generate project context.\n`;
|
|
99
|
+
await writeFile(contextReadmePath, readmeContent);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// --- 5. Copy framework/templates → .morph/framework/templates ---
|
|
103
|
+
log('Step 5: Copying framework templates...');
|
|
104
|
+
const frameworkTemplatesSrc = join(FRAMEWORK_DIR, 'templates');
|
|
105
|
+
const templatesDest = join(frameworkDestDir, 'templates');
|
|
106
|
+
if (await pathExists(frameworkTemplatesSrc)) {
|
|
107
|
+
await copyDirectory(frameworkTemplatesSrc, templatesDest);
|
|
108
|
+
} else {
|
|
109
|
+
await ensureDir(templatesDest);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// --- 6. Copy framework/standards → .morph/framework/standards ---
|
|
113
|
+
log('Step 6: Copying framework standards...');
|
|
114
|
+
const frameworkStandardsSrc = join(FRAMEWORK_DIR, 'standards');
|
|
115
|
+
const frameworkStandardsDest = join(frameworkDestDir, 'standards');
|
|
116
|
+
if (await pathExists(frameworkStandardsSrc)) {
|
|
117
|
+
await copyDirectory(frameworkStandardsSrc, frameworkStandardsDest);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// --- 7. Copy framework/hooks → .morph/framework/hooks ---
|
|
121
|
+
log('Step 7: Copying hooks...');
|
|
122
|
+
const hooksSrc = join(FRAMEWORK_DIR, 'hooks');
|
|
123
|
+
const hooksDest = join(frameworkDestDir, 'hooks');
|
|
124
|
+
if (await pathExists(hooksSrc)) {
|
|
125
|
+
await copyDirectory(hooksSrc, hooksDest);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// --- 8. Copy framework/agents.json → .morph/framework/agents.json ---
|
|
129
|
+
log('Step 8: Copying agents.json...');
|
|
130
|
+
const agentsSrc = join(FRAMEWORK_DIR, 'agents.json');
|
|
131
|
+
const agentsDest = join(frameworkDestDir, 'agents.json');
|
|
132
|
+
if (await pathExists(agentsSrc)) {
|
|
133
|
+
await copyFile(agentsSrc, agentsDest);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// --- 9. Copy framework/commands → .claude/commands ---
|
|
137
|
+
log('Step 9: Setting up Claude Code integration...');
|
|
138
|
+
const claudeDest = join(targetPath, '.claude');
|
|
139
|
+
const commandsSrc = join(FRAMEWORK_DIR, 'commands');
|
|
140
|
+
const commandsDest = join(claudeDest, 'commands');
|
|
141
|
+
if (await pathExists(commandsSrc)) {
|
|
142
|
+
await copyDirectory(commandsSrc, commandsDest);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// --- 10. Copy framework/rules → .claude/rules ---
|
|
146
|
+
log('Step 10: Installing path-scoped rules...');
|
|
147
|
+
const rulesSrc = join(FRAMEWORK_DIR, 'rules');
|
|
148
|
+
const rulesDest = join(claudeDest, 'rules');
|
|
149
|
+
if (await pathExists(rulesSrc)) {
|
|
150
|
+
await copyDirectory(rulesSrc, rulesDest);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// --- 11. installSkills ---
|
|
154
|
+
log('Step 11: Installing skills...');
|
|
155
|
+
await installSkills(targetPath);
|
|
156
|
+
|
|
157
|
+
// --- 12. installAgents ---
|
|
158
|
+
log('Step 12: Installing agents...');
|
|
159
|
+
const agentCounts = await installAgents(targetPath, FRAMEWORK_DIR, { projectStack: null });
|
|
160
|
+
|
|
161
|
+
// --- 13. installDomainAgents ---
|
|
162
|
+
log('Step 13: Installing domain agents...');
|
|
163
|
+
const domainCounts = await installDomainAgents(targetPath, FRAMEWORK_DIR);
|
|
164
|
+
|
|
165
|
+
// --- 14. Copy framework/CLAUDE.md → .claude/CLAUDE.md ---
|
|
166
|
+
log('Step 14: Installing .claude/CLAUDE.md...');
|
|
167
|
+
const runtimeClaudeMdDest = join(claudeDest, 'CLAUDE.md');
|
|
168
|
+
if (await pathExists(claudeMdSrc)) {
|
|
169
|
+
await copyFile(claudeMdSrc, runtimeClaudeMdDest);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// --- 15. installGlobalStatusline (non-critical) ---
|
|
173
|
+
log('Step 15: Installing global statusline...');
|
|
174
|
+
const HOOKS_SRC = join(FRAMEWORK_DIR, 'hooks', 'claude-code');
|
|
175
|
+
try {
|
|
176
|
+
await installGlobalStatusline(HOOKS_SRC);
|
|
177
|
+
} catch {
|
|
178
|
+
// Non-critical — global ~/.claude may not be writable
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// --- 16. installClaudeHooks ---
|
|
182
|
+
log('Step 16: Installing Claude Code hooks...');
|
|
183
|
+
await installClaudeHooks(targetPath);
|
|
184
|
+
|
|
185
|
+
// --- 17. saveProjectMorphVersion ---
|
|
186
|
+
log('Step 17: Saving version info...');
|
|
187
|
+
const cliVersion = getInstalledCLIVersion();
|
|
188
|
+
await saveProjectMorphVersion(targetPath, cliVersion);
|
|
189
|
+
|
|
190
|
+
// --- 18. updateGitignore ---
|
|
191
|
+
log('Step 18: Updating .gitignore...');
|
|
192
|
+
await updateGitignore(targetPath);
|
|
193
|
+
|
|
194
|
+
log('setup-infra: complete.');
|
|
195
|
+
|
|
196
|
+
return {
|
|
197
|
+
agents: {
|
|
198
|
+
tier1: agentCounts?.tier1 ?? 0,
|
|
199
|
+
tier2: agentCounts?.tier2 ?? 0,
|
|
200
|
+
specialists: domainCounts?.specialists ?? 0,
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
}
|
|
@@ -47,6 +47,8 @@ export async function installAgents(projectDir, frameworkDir = 'framework', opti
|
|
|
47
47
|
return true;
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
+
let tier1 = 0;
|
|
51
|
+
let tier2 = 0;
|
|
50
52
|
for (const agent of eligible) {
|
|
51
53
|
const slug = agent.id ?? agent.name?.toLowerCase().replace(/\s+/g, '-');
|
|
52
54
|
const filename = `morph-${slug}.md`;
|
|
@@ -58,7 +60,11 @@ export async function installAgents(projectDir, frameworkDir = 'framework', opti
|
|
|
58
60
|
const frontmatter = buildFrontmatter(agent, description);
|
|
59
61
|
const content = `---\n${frontmatter}---\n\n${body}\n`;
|
|
60
62
|
writeFileSync(targetPath, content, 'utf-8');
|
|
63
|
+
|
|
64
|
+
if (agent.tier === 1) tier1++;
|
|
65
|
+
else if (agent.tier === 2) tier2++;
|
|
61
66
|
}
|
|
67
|
+
return { tier1, tier2 };
|
|
62
68
|
}
|
|
63
69
|
|
|
64
70
|
/**
|
|
@@ -191,11 +197,12 @@ export function collectSkillFiles(dir) {
|
|
|
191
197
|
*/
|
|
192
198
|
export async function installDomainAgents(projectDir, frameworkDir = 'framework') {
|
|
193
199
|
const domainsDir = join(frameworkDir, 'agents');
|
|
194
|
-
if (!existsSync(domainsDir)) return;
|
|
200
|
+
if (!existsSync(domainsDir)) return { specialists: 0 };
|
|
195
201
|
|
|
196
202
|
const targetDir = join(projectDir, '.claude', 'agents');
|
|
197
203
|
mkdirSync(targetDir, { recursive: true });
|
|
198
204
|
|
|
205
|
+
let specialists = 0;
|
|
199
206
|
for (const filePath of collectSkillFiles(domainsDir)) {
|
|
200
207
|
const raw = readFileSync(filePath, 'utf-8');
|
|
201
208
|
const { name, description, allowedTools, body } = parseSkillFile(raw);
|
|
@@ -214,5 +221,7 @@ export async function installDomainAgents(projectDir, frameworkDir = 'framework'
|
|
|
214
221
|
|
|
215
222
|
const targetPath = join(targetDir, `morph-domain-${name}.md`);
|
|
216
223
|
writeFileSync(targetPath, `---\n${frontmatter}---\n\n${body.trimStart()}`, 'utf-8');
|
|
224
|
+
specialists++;
|
|
217
225
|
}
|
|
226
|
+
return { specialists };
|
|
218
227
|
}
|
|
@@ -10,11 +10,12 @@
|
|
|
10
10
|
|
|
11
11
|
import { join } from 'path';
|
|
12
12
|
import { readFile, writeFile, mkdir, copyFile } from 'fs/promises';
|
|
13
|
-
import { existsSync, chmodSync } from 'fs';
|
|
13
|
+
import { existsSync, chmodSync, readdirSync } from 'fs';
|
|
14
14
|
import { homedir } from 'os';
|
|
15
|
+
import { execSync } from 'child_process';
|
|
15
16
|
|
|
16
17
|
/** Current hooks schema version — bump when hook definitions change */
|
|
17
|
-
const HOOKS_VERSION = '2.
|
|
18
|
+
const HOOKS_VERSION = '2.5.1';
|
|
18
19
|
|
|
19
20
|
/** Marker for old dispatch.js (v1) */
|
|
20
21
|
const OLD_DISPATCH_COMMAND = 'node framework/hooks/agent-teams/dispatch.js';
|
|
@@ -25,10 +26,26 @@ const OLD_DISPATCH_COMMAND = 'node framework/hooks/agent-teams/dispatch.js';
|
|
|
25
26
|
* using Claude Code's built-in permissions system instead.
|
|
26
27
|
*/
|
|
27
28
|
const MORPH_PERMISSIONS = [
|
|
29
|
+
// Core framework state and readonly files
|
|
28
30
|
'Write(.morph/state.json)',
|
|
29
31
|
'Edit(.morph/state.json)',
|
|
30
32
|
'Write(.morph/framework/**)',
|
|
31
33
|
'Edit(.morph/framework/**)',
|
|
34
|
+
// Root CLAUDE.md (managed copy — source is framework/CLAUDE.md)
|
|
35
|
+
'Write(CLAUDE.md)',
|
|
36
|
+
'Edit(CLAUDE.md)',
|
|
37
|
+
// .claude/CLAUDE.md (managed copy — source is framework/CLAUDE_runtime.md)
|
|
38
|
+
'Write(.claude/CLAUDE.md)',
|
|
39
|
+
'Edit(.claude/CLAUDE.md)',
|
|
40
|
+
// .claude/rules/ (copied from framework/rules/)
|
|
41
|
+
'Write(.claude/rules/**)',
|
|
42
|
+
'Edit(.claude/rules/**)',
|
|
43
|
+
// .claude/agents/morph-* (generated by agents-installer)
|
|
44
|
+
'Write(.claude/agents/morph-*)',
|
|
45
|
+
'Edit(.claude/agents/morph-*)',
|
|
46
|
+
// .claude/skills/ (copied from framework/skills/)
|
|
47
|
+
'Write(.claude/skills/**)',
|
|
48
|
+
'Edit(.claude/skills/**)',
|
|
32
49
|
];
|
|
33
50
|
|
|
34
51
|
/**
|
|
@@ -104,19 +121,8 @@ Otherwise respond: {"ok": true}`
|
|
|
104
121
|
event: 'Stop',
|
|
105
122
|
matcher: null,
|
|
106
123
|
hooks: [{
|
|
107
|
-
type: '
|
|
108
|
-
|
|
109
|
-
1. Read the file .morph/state.json to find features with status "in_progress".
|
|
110
|
-
2. For each in_progress feature, check if required output files for the current phase exist and are non-empty.
|
|
111
|
-
- proposal phase: .morph/features/{feature}/0-proposal/proposal.md
|
|
112
|
-
- design phase: .morph/features/{feature}/1-design/spec.md
|
|
113
|
-
- tasks phase: .morph/features/{feature}/3-tasks/tasks.md
|
|
114
|
-
- implement phase: check tasks.completed vs tasks.total from state.json
|
|
115
|
-
3. If all required outputs exist and tasks are complete, return {"ok": true}.
|
|
116
|
-
4. If any required output is missing or empty, return {"ok": false, "reason": "Missing output: <path>"}.
|
|
117
|
-
5. If state.json does not exist or no feature is in_progress, return {"ok": true}.
|
|
118
|
-
Do NOT modify any files. Read only.`,
|
|
119
|
-
timeout: 60
|
|
124
|
+
type: 'command',
|
|
125
|
+
command: 'node framework/hooks/claude-code/stop/validate-completion.js'
|
|
120
126
|
}]
|
|
121
127
|
},
|
|
122
128
|
|
|
@@ -209,9 +215,10 @@ export async function installClaudeHooks(targetPath) {
|
|
|
209
215
|
return agentHook;
|
|
210
216
|
}
|
|
211
217
|
// Command hooks: transform path to use $CLAUDE_PROJECT_DIR
|
|
218
|
+
// Hooks are copied to .morph/framework/hooks/ during `morph-spec init/update`
|
|
212
219
|
return {
|
|
213
220
|
type: h.type,
|
|
214
|
-
command: `node "$CLAUDE_PROJECT_DIR/framework/hooks/claude-code/${getHookSubpath(h.command)}"`,
|
|
221
|
+
command: `node "$CLAUDE_PROJECT_DIR/.morph/framework/hooks/claude-code/${getHookSubpath(h.command)}"`,
|
|
215
222
|
...(h.timeout !== undefined ? { timeout: h.timeout } : {})
|
|
216
223
|
};
|
|
217
224
|
});
|
|
@@ -265,6 +272,47 @@ export async function installClaudeHooks(targetPath) {
|
|
|
265
272
|
return { installed, updated: !alreadyCurrent };
|
|
266
273
|
}
|
|
267
274
|
|
|
275
|
+
/**
|
|
276
|
+
/**
|
|
277
|
+
* Resolve Python executable suitable for the statusLine command.
|
|
278
|
+
*
|
|
279
|
+
* On non-Windows: returns 'python3' (standard PATH name).
|
|
280
|
+
* On Windows: Claude Code runs commands via the system shell where python3/python
|
|
281
|
+
* may not be on PATH. We probe with execSync first, then fall back to known
|
|
282
|
+
* Windows install locations (AppData\Local\Programs\Python\Python3*).
|
|
283
|
+
*
|
|
284
|
+
* @returns {string} Python executable (full path on Windows if needed)
|
|
285
|
+
*/
|
|
286
|
+
function resolvePythonForStatusline() {
|
|
287
|
+
if (process.platform !== 'win32') {
|
|
288
|
+
return 'python3';
|
|
289
|
+
}
|
|
290
|
+
// Try PATH-visible commands first (works if user added Python to PATH)
|
|
291
|
+
// 'py' is the Windows Python Launcher — standard on any Windows Python install
|
|
292
|
+
for (const cmd of ['python3', 'py', 'python']) {
|
|
293
|
+
try {
|
|
294
|
+
const ver = execSync(`${cmd} --version`, { encoding: 'utf-8', timeout: 3000, stdio: ['pipe', 'pipe', 'pipe'] });
|
|
295
|
+
if ((ver + '').includes('Python 3')) return cmd;
|
|
296
|
+
} catch { /* not on PATH */ }
|
|
297
|
+
}
|
|
298
|
+
// Probe known Windows install locations
|
|
299
|
+
const base = join(homedir(), 'AppData', 'Local', 'Programs', 'Python');
|
|
300
|
+
if (existsSync(base)) {
|
|
301
|
+
let dirs;
|
|
302
|
+
try { dirs = readdirSync(base); } catch { dirs = []; }
|
|
303
|
+
const py3 = dirs
|
|
304
|
+
.filter(d => /^Python3\d*/i.test(d))
|
|
305
|
+
.sort()
|
|
306
|
+
.reverse(); // prefer highest version
|
|
307
|
+
for (const dir of py3) {
|
|
308
|
+
const exe = join(base, dir, 'python.exe');
|
|
309
|
+
if (existsSync(exe)) return exe;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
// Last resort: return python3 and let it fail with a clear error
|
|
313
|
+
return 'python3';
|
|
314
|
+
}
|
|
315
|
+
|
|
268
316
|
/**
|
|
269
317
|
* Install the morph-spec statusline globally into ~/.claude/.
|
|
270
318
|
*
|
|
@@ -305,9 +353,14 @@ export async function installGlobalStatusline(hooksSourceDir, globalClaudeDirOve
|
|
|
305
353
|
}
|
|
306
354
|
}
|
|
307
355
|
|
|
356
|
+
// On Windows, Claude Code cannot execute .sh files directly — call Python instead.
|
|
357
|
+
const statuslineCommand = process.platform === 'win32'
|
|
358
|
+
? `"${resolvePythonForStatusline()}" "${join(globalDir, 'statusline.py').replace(/\\/g, '/')}"`
|
|
359
|
+
: join(globalDir, 'statusline.sh').replace(/\\/g, '/');
|
|
360
|
+
|
|
308
361
|
settings.statusLine = {
|
|
309
362
|
type: 'command',
|
|
310
|
-
command:
|
|
363
|
+
command: statuslineCommand,
|
|
311
364
|
padding: 2
|
|
312
365
|
};
|
|
313
366
|
|
package/CLAUDE.md
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
# MORPH-SPEC Runtime Instructions
|
|
2
|
-
|
|
3
|
-
> by Polymorphism Tech — Spec-driven development for .NET/Blazor/Next.js/Azure
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## Project Context
|
|
8
|
-
|
|
9
|
-
@.morph/context/README.md
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
## Critical Rules
|
|
14
|
-
|
|
15
|
-
**NEVER:**
|
|
16
|
-
- Skip to code without a specification
|
|
17
|
-
- Implement without design approval
|
|
18
|
-
- Ignore standards in `.morph/framework/standards/`
|
|
19
|
-
- Create infrastructure manually
|
|
20
|
-
- Generate code without defined contracts
|
|
21
|
-
|
|
22
|
-
**ALWAYS:**
|
|
23
|
-
- Follow the mandatory phases
|
|
24
|
-
- Generate outputs in `.morph/features/{feature}/`
|
|
25
|
-
- Document decisions in `decisions.md`
|
|
26
|
-
- Checkpoint every 3 implemented tasks
|
|
27
|
-
- Use Infrastructure as Code
|
|
28
|
-
|
|
29
|
-
---
|
|
30
|
-
|
|
31
|
-
## Quick Reference
|
|
32
|
-
|
|
33
|
-
| Command | Purpose |
|
|
34
|
-
|---------|---------|
|
|
35
|
-
| `/morph-proposal {feature}` | Full spec pipeline (phases 1–4, pauses for approval) |
|
|
36
|
-
| `/morph-apply {feature}` | Implement feature (phase 5) |
|
|
37
|
-
| `/morph-status` | Feature status dashboard |
|
|
38
|
-
| `/morph-preflight` | Pre-implementation validation |
|
|
39
|
-
|
|
40
|
-
---
|
|
41
|
-
|
|
42
|
-
## State & Outputs
|
|
43
|
-
|
|
44
|
-
| Path | Notes |
|
|
45
|
-
|------|-------|
|
|
46
|
-
| `.morph/state.json` | **READ-ONLY** — use `morph-spec` CLI to update |
|
|
47
|
-
| `.morph/features/{feature}/{phase}/` | Feature outputs organized by phase |
|
|
48
|
-
| `.morph/framework/` | **READ-ONLY** — framework files managed by morph-spec |
|
|
49
|
-
| `.morph/config/config.json` | Project configuration (editable) |
|
|
50
|
-
|
|
51
|
-
---
|
|
52
|
-
|
|
53
|
-
## Phase Sequence
|
|
54
|
-
|
|
55
|
-
```
|
|
56
|
-
proposal → setup → [uiux] → design → clarify → tasks → implement → [sync]
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
Use `morph-spec state show {feature}` to see current phase and pending approval gates.
|
|
60
|
-
|
|
61
|
-
---
|
|
62
|
-
|
|
63
|
-
## Agents
|
|
64
|
-
|
|
65
|
-
Tier-1 and tier-2 MORPH agents are available as native subagents in `.claude/agents/`.
|
|
66
|
-
They can be invoked directly by Claude Code during multi-agent workflows.
|
|
67
|
-
|
|
68
|
-
---
|
|
69
|
-
|
|
70
|
-
## Context Window Tip
|
|
71
|
-
|
|
72
|
-
When using 3+ MCPs, add `"experimental": { "mcpCliMode": true }` to `.claude/settings.json`.
|
|
73
|
-
MCP tools load on-demand instead of all at startup — keeps context clean for actual work.
|
|
74
|
-
|
|
75
|
-
---
|
|
76
|
-
|
|
77
|
-
*MORPH-SPEC v4.5.0 by Polymorphism Tech*
|