vini-ds 0.1.0-alpha.0 → 0.1.0-alpha.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/README.md +3 -3
- package/cli.mjs +116 -9
- package/package.json +25 -2
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# VINi CLI
|
|
2
2
|
|
|
3
|
-
Connect with `npx vini-ds init`. This is
|
|
3
|
+
Connect with `npx vini-ds init`. This is a public alpha, 0.1.0-alpha.1; it supports the bounded setup described below. For a reproducible installation, use the exact version.
|
|
4
4
|
|
|
5
|
-
Preview: `npx vini-ds@0.1.0-alpha.
|
|
5
|
+
Preview: `npx vini-ds@0.1.0-alpha.1 init --plan`. Connect: `npx vini-ds@0.1.0-alpha.1 init`.
|
|
6
6
|
|
|
7
7
|
Requires an existing React 18/Vite project and Node 20+. Detects npm or pnpm; configures CSS, ThemeBrandProvider and project-local Codex MCP/Skill. Does not change global Codex settings or project trust. This alpha supports the direct createRoot(...).render(JSX) entry form; use --entry for an explicit supported entry. New desktop Codex session discovery is a separate check.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Check an existing project with `npx vini-ds@latest status` (or `status --json`). A registry error means the available version is unknown. Review the suggested exact version with `npx vini-ds@0.1.0-alpha.1 update --plan`, then run the same command without `--plan`. Restart the project-local agent and read `vini://system/current` to verify the installed context. Update creates a recovery backup; if installation fails, inspect the reported recovery path before retrying. Previously installed private-GitHub Kits need an explicit migration and are not overwritten.
|
package/cli.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import path from 'node:path';
|
|
|
4
4
|
import { createHash, randomUUID } from 'node:crypto';
|
|
5
5
|
import { createRequire } from 'node:module';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
7
8
|
import { spawn } from 'node:child_process';
|
|
8
9
|
import ts from 'typescript';
|
|
9
10
|
|
|
@@ -13,18 +14,21 @@ const fail=message=>{throw new Error(`VINi: ${message}`);};
|
|
|
13
14
|
const exists=async file=>fs.lstat(file).catch(error=>{if(error.code==='ENOENT')return null;throw error;});
|
|
14
15
|
const css=['@vini/tokens/fonts.css','@vini/tokens/themes.css','@vini/tokens/typography.css','@vini/ui/styles.css'];
|
|
15
16
|
const pointer='<!-- BEGIN:vini-npm -->\nFor VINi interface work, use `.agents/skills/vini-ds/SKILL.md` and the project-local `vini-ds` MCP server.\n<!-- END:vini-npm -->';
|
|
16
|
-
const usage='vini init|update [--plan] [--cwd PROJECT] [--app-root APP] [--entry src/main.tsx] [--package-manager npm|pnpm] [--registry HTTPS_URL]';
|
|
17
|
+
const usage='vini init|update [--plan] | status [--json] [--cwd PROJECT] [--app-root APP] [--entry src/main.tsx] [--package-manager npm|pnpm] [--registry HTTPS_URL]';
|
|
17
18
|
|
|
18
19
|
export function parseArgs(args) {
|
|
19
20
|
if(args.length===1&&['--help','-h'].includes(args[0]))return {help:true};
|
|
20
21
|
const options={command:args[0]??'init',plan:false};
|
|
21
|
-
if(!['init','update'].includes(options.command))fail(usage);
|
|
22
|
+
if(!['init','update','status'].includes(options.command))fail(usage);
|
|
22
23
|
const names={'--cwd':'cwd','--app-root':'appRoot','--entry':'entry','--package-manager':'packageManager','--registry':'registry'};
|
|
23
24
|
for(let i=1;i<args.length;i++) {
|
|
24
25
|
if(args[i]==='--plan'){if(options.plan)fail('duplicate --plan');options.plan=true;continue;}
|
|
26
|
+
if(args[i]==='--json'){if(options.json)fail('duplicate --json');options.json=true;continue;}
|
|
25
27
|
const key=names[args[i]];if(!key||options[key]||!args[i+1]||args[i+1].startsWith('--'))fail(usage);options[key]=args[++i];
|
|
26
28
|
}
|
|
27
29
|
if(options.packageManager&&!['npm','pnpm'].includes(options.packageManager))fail('only npm and pnpm are supported');
|
|
30
|
+
if(options.json&&options.command!=='status')fail('--json is supported by status');
|
|
31
|
+
if(options.command==='status'&&(options.plan||options.entry||options.packageManager))fail(usage);
|
|
28
32
|
if(options.registry){const url=new URL(options.registry);if(url.username||url.password||url.search||url.hash||(url.protocol!=='https:'&&!(url.protocol==='http:'&&['localhost','127.0.0.1','[::1]'].includes(url.hostname))))fail('registry must use HTTPS (HTTP localhost is allowed for testing)');}
|
|
29
33
|
return options;
|
|
30
34
|
}
|
|
@@ -116,6 +120,101 @@ async function verifyAgentContext(runner,entry,distribution,cwd) {
|
|
|
116
120
|
for(const key of ['ui','tokens','agent'])if(result.packages?.[key]?.name!==distribution[key]||result.packages[key].version!==distribution.version)fail('agent contract and installed npm package pair differ');
|
|
117
121
|
return result;
|
|
118
122
|
}
|
|
123
|
+
// This is a description of one published transition, never a universal changelog.
|
|
124
|
+
function transition(release,fromVersion,toVersion) {
|
|
125
|
+
const changes=release?.changes;
|
|
126
|
+
if(!changes||changes.fromVersion!==fromVersion||!Array.isArray(changes.components)||!changes.components.every(x=>typeof x==='string'&&x.length<100)||typeof changes.summary!=='string'||changes.summary.length>2000)return {status:'not-available',from:fromVersion??null,to:toVersion};
|
|
127
|
+
return {status:'available',from:fromVersion,to:toVersion,summary:changes.summary,components:changes.components};
|
|
128
|
+
}
|
|
129
|
+
async function readInstallation(root,requestedApp,expected) {
|
|
130
|
+
const receiptPath=path.join(root,'.vini-ds/npm-install.json');await safeParents(root,receiptPath);
|
|
131
|
+
const raw=await fileBytes(receiptPath,true);let receipt=null;
|
|
132
|
+
if(raw){receipt=json(raw,receiptPath);if(receipt.installer!=='vini-npm'||!receipt.distribution||typeof receipt.configTable!=='string')fail('unrecognized npm setup receipt');distributionCheck(receipt.distribution);}
|
|
133
|
+
const relative=requestedApp??receipt?.appRoot??'.';const app=await fs.realpath(path.resolve(root,relative));
|
|
134
|
+
if(app!==root&&!app.startsWith(root+path.sep))fail('app root must be inside project');
|
|
135
|
+
const manifestPath=path.join(app,'package.json');await safeParents(root,manifestPath);
|
|
136
|
+
const manifest=json(await fileBytes(manifestPath),manifestPath);const req=createRequire(manifestPath);
|
|
137
|
+
const dependencies={...manifest.optionalDependencies,...manifest.devDependencies,...manifest.dependencies};
|
|
138
|
+
const lockfiles=[];for(const name of ['package-lock.json','pnpm-lock.yaml']){const bytes=await fileBytes(path.join(app,name),true);if(bytes)lockfiles.push({name,sha256:`sha256:${digest(bytes)}`});}
|
|
139
|
+
const installed={};let installedAgent;
|
|
140
|
+
for(const key of ['ui','tokens','agent']) {
|
|
141
|
+
const alias=`@vini/${key}`;let actual=null,error=null;
|
|
142
|
+
try{const pkg=await resolveManifest(req,alias,key==='agent'?'/mcp':'');actual={name:pkg.manifest.name,version:pkg.manifest.version};if(key==='agent')installedAgent=pkg;}
|
|
143
|
+
catch(problem){if(problem.code==='MODULE_NOT_FOUND'||problem.code==='ERR_PACKAGE_PATH_NOT_EXPORTED')error='not-resolvable';else error='metadata-unavailable';}
|
|
144
|
+
const declared=dependencies[alias]??null,recorded=receipt?(receipt.distribution[key]===alias?receipt.distribution.version:`npm:${receipt.distribution[key]}@${receipt.distribution.version}`):null;
|
|
145
|
+
installed[key]={declared,actual,error,matchesLauncher:!!actual&&actual.name===expected[key]&&actual.version===expected.version,matchesReceipt:!!actual&&!!receipt&&actual.name===receipt.distribution[key]&&actual.version===receipt.distribution.version&&declared===recorded};
|
|
146
|
+
}
|
|
147
|
+
let launcher='not-installed';
|
|
148
|
+
if(receipt){const file=path.join(root,'.vini-ds/npm-launcher.mjs');await safeParents(root,file);const bytes=await fileBytes(file,true);launcher=bytes&&digest(bytes)===receipt.launcherSha256?'matches-receipt':'missing-or-modified';}
|
|
149
|
+
let agentContext=null;
|
|
150
|
+
if(installedAgent){const file=path.join(installedAgent.root,'context/current.json');const bytes=await fileBytes(file,true);if(bytes){const current=json(bytes,file);agentContext={version:current.version??null,baseline:current.baseline??null,release:current.viniRelease??null};}}
|
|
151
|
+
return {projectRoot:root,appRoot:app,receipt:receipt?{distribution:receipt.distribution,appRoot:receipt.appRoot}:null,launcher:{status:launcher,expected:receipt?.distribution??null},installed,lockfiles,agentContext};
|
|
152
|
+
}
|
|
153
|
+
const validIntegrity=value=>{if(typeof value!=='string'||!/^sha512-[A-Za-z0-9+/]+={0,2}$/u.test(value))return false;const encoded=value.slice(7),bytes=Buffer.from(encoded,'base64');return bytes.length===64&&bytes.toString('base64')===encoded;};
|
|
154
|
+
function validRelease(value) {
|
|
155
|
+
const safe=x=>typeof x==='string'&&x.length>0&&x.length<=2000&&!/[\u0000-\u001f\u007f]/u.test(x);
|
|
156
|
+
const web=x=>{if(!safe(x))return false;try{const u=new URL(x);return u.protocol==='https:'&&!u.username&&!u.password&&!u.search&&!u.hash;}catch{return false;}};
|
|
157
|
+
return value===null||!!value&&web(value.atlas?.url)&&/^sha256:[0-9a-f]{64}$/u.test(value.atlas.archiveSha256??'')&&safe(value.atlas.siteRelease)&&/^[0-9a-f]{40}$/u.test(value.atlas.commit??'')&&safe(value.delivery?.id)&&/^sha256:[0-9a-f]{64}$/u.test(value.delivery.manifestSha256??'')&&/^sha256:[0-9a-f]{64}$/u.test(value.delivery.packageManifestSha256??'')&&safe(value.changes?.fromVersion)&&safe(value.changes?.summary)&&Array.isArray(value.changes?.components)&&value.changes.components.length<=500&&value.changes.components.every(x=>safe(x)&&x.length<=100);
|
|
158
|
+
}
|
|
159
|
+
function compareVersions(a,b) {
|
|
160
|
+
const parse=x=>{const m=/^(\d+)\.(\d+)\.(\d+)(?:-([a-z0-9.-]+))?$/u.exec(x??'');if(!m)throw new Error('invalid published version');return {core:m.slice(1,4).map(Number),pre:m[4]?.split('.')??null};};
|
|
161
|
+
const x=parse(a),y=parse(b);for(let i=0;i<3;i++)if(x.core[i]!==y.core[i])return Math.sign(x.core[i]-y.core[i]);
|
|
162
|
+
if(!x.pre||!y.pre)return x.pre? -1:y.pre?1:0;
|
|
163
|
+
for(let i=0;i<Math.max(x.pre.length,y.pre.length);i++){const l=x.pre[i],r=y.pre[i];if(l===undefined||r===undefined)return l===undefined?-1:1;if(l===r)continue;const ln=/^\d+$/u.test(l),rn=/^\d+$/u.test(r);if(ln&&rn)return Math.sign(Number(l)-Number(r));if(ln!==rn)return ln?-1:1;return l<r?-1:1;}return 0;
|
|
164
|
+
}
|
|
165
|
+
function registryUrl(raw) {
|
|
166
|
+
const url=new URL(raw);if(url.username||url.password||url.search||url.hash||(url.protocol!=='https:'&&!(url.protocol==='http:'&&['localhost','127.0.0.1','[::1]'].includes(url.hostname))))fail('registry must use HTTPS (HTTP localhost is allowed for testing)');
|
|
167
|
+
if(!url.pathname.endsWith('/'))url.pathname+='/';return url;
|
|
168
|
+
}
|
|
169
|
+
async function requestMetadata(url) {
|
|
170
|
+
const response=await fetch(url,{headers:{accept:'application/vnd.npm.install-v1+json, application/json'},redirect:'error',signal:AbortSignal.timeout(8000)});
|
|
171
|
+
if(!response.ok)throw new Error(`registry HTTP ${response.status}`);
|
|
172
|
+
const length=Number(response.headers.get('content-length')??0);if(length>2*1024*1024)throw new Error('registry metadata too large');
|
|
173
|
+
const reader=response.body?.getReader();if(!reader)throw new Error('registry metadata body missing');let total=0,chunks=[];
|
|
174
|
+
try{while(true){const {done,value}=await reader.read();if(done)break;total+=value.length;if(total>2*1024*1024)throw new Error('registry metadata too large');chunks.push(value);}}finally{reader.releaseLock();}
|
|
175
|
+
return JSON.parse(Buffer.concat(chunks.map(x=>Buffer.from(x))).toString('utf8'));
|
|
176
|
+
}
|
|
177
|
+
async function availableRelease(registry,cliName,expected,request=requestMetadata) {
|
|
178
|
+
try {
|
|
179
|
+
const root=registryUrl(registry),endpoint=(name,version)=>new URL(`${encodeURIComponent(name)}/${encodeURIComponent(version)}`,root).href;
|
|
180
|
+
const latest=await request(endpoint(cliName,'latest'));
|
|
181
|
+
if(latest?.name!==cliName||!validIntegrity(latest?.dist?.integrity)||latest.version!==latest.viniDistribution?.version)throw new Error('invalid latest CLI identity or integrity');
|
|
182
|
+
const distribution=distributionCheck(latest.viniDistribution);
|
|
183
|
+
if(!validRelease(latest.viniRelease??null))throw new Error('invalid release metadata');
|
|
184
|
+
if(['ui','tokens','agent'].some(key=>distribution[key]!==expected[key]))throw new Error('latest CLI publishes a different package family');
|
|
185
|
+
const entries=await Promise.all(['ui','tokens','agent'].map(async key=>{
|
|
186
|
+
const info=await request(endpoint(distribution[key],distribution.version));
|
|
187
|
+
if(info?.name!==distribution[key]||info.version!==distribution.version||!validIntegrity(info?.dist?.integrity))throw new Error(`${key} exact-version metadata is unavailable or invalid`);
|
|
188
|
+
if(key==='ui'){const alias=distribution.tokens==='@vini/tokens'?distribution.version:`npm:${distribution.tokens}@${distribution.version}`;if(info.dependencies?.['@vini/tokens']!==alias)throw new Error('published UI token dependency does not match the release');}
|
|
189
|
+
if(key==='agent'&&!isDeepStrictEqual(info.viniRelease??null,latest.viniRelease??null))throw new Error('CLI and agent release metadata differ');
|
|
190
|
+
return [key,{name:info.name,version:info.version,integrity:info.dist.integrity}];
|
|
191
|
+
}));const packages=Object.fromEntries(entries);
|
|
192
|
+
return {status:'available',distribution,cli:{name:latest.name,version:latest.version,integrity:latest.dist.integrity},packages,release:latest.viniRelease??null};
|
|
193
|
+
} catch(error) {return {status:'unavailable',reason:String(error.message??error)};}
|
|
194
|
+
}
|
|
195
|
+
export async function status(options={},suppliedDistribution,{request=requestMetadata,cliName,release}={}) {
|
|
196
|
+
const cli=suppliedDistribution?{name:cliName??'vini-ds',viniDistribution:suppliedDistribution,viniRelease:release}:json(await fileBytes(path.join(path.dirname(self),'package.json')),'CLI package');
|
|
197
|
+
const expected=distributionCheck(cli.viniDistribution),root=await fs.realpath(path.resolve(options.cwd??process.cwd()));
|
|
198
|
+
const state=await readInstallation(root,options.appRoot,expected);
|
|
199
|
+
const registry=options.registry??process.env.npm_config_registry??'https://registry.npmjs.org/';
|
|
200
|
+
const published=await availableRelease(registry,cli.name,expected,request);
|
|
201
|
+
const aligned=!!state.receipt&&state.launcher.status==='matches-receipt'&&['ui','tokens','agent'].every(key=>state.installed[key].matchesReceipt);
|
|
202
|
+
const installedVersion=aligned?state.receipt.distribution.version:null;
|
|
203
|
+
const installedToLauncher=aligned&&['ui','tokens','agent'].every(key=>state.installed[key].matchesLauncher);
|
|
204
|
+
const latest=published.status==='available'?published.distribution.version:null;
|
|
205
|
+
const ordering=aligned&&latest?compareVersions(installedVersion,latest):null;
|
|
206
|
+
const relation=!state.receipt?'not-installed':!aligned?'mismatch':published.status!=='available'?'unknown':ordering===0?'current':ordering<0?'update-available':'ahead-of-latest';
|
|
207
|
+
const next=relation==='not-installed'?`npx ${cli.name}@${expected.version} init --plan`:relation==='mismatch'?'Installed packages or launcher differ from the receipt; resolve the mismatch before updating.':relation==='unknown'?'Registry unavailable; retry status before deciding about updates.':relation==='update-available'?`npx ${cli.name}@${latest} update --plan`:relation==='ahead-of-latest'?'Installed release is newer than the registry latest tag; no downgrade is selected.':'Installed package versions match the latest available release.';
|
|
208
|
+
return {status:relation,...state,launcherVersion:expected.version,launcherMatchesInstalled:installedToLauncher,available:published,changes:published.status==='available'?transition(published.release,installedVersion,latest):{status:'unknown'},nextStep:next,mutated:false};
|
|
209
|
+
}
|
|
210
|
+
export function formatStatus(result) {
|
|
211
|
+
const installed=['ui','tokens','agent'].map(key=>{const p=result.installed[key];return `${key}: ${p.actual?`${p.actual.name}@${p.actual.version}`:'not installed'}${p.error?` (${p.error})`:''}`;}).join('\n');
|
|
212
|
+
const available=result.available.status==='available'?result.available.distribution.version:`unknown (${result.available.reason})`;
|
|
213
|
+
const changes=result.changes.status==='available'?`\nChanges: ${result.changes.summary}\nComponents: ${result.changes.components.join(', ')||'none listed'}`:'';
|
|
214
|
+
const release=result.available.release;
|
|
215
|
+
const site=release?`\nAtlas: ${release.atlas.url} (${release.atlas.siteRelease}, commit ${release.atlas.commit})\nAtlas archive: ${release.atlas.archiveSha256}\nDelivery: ${release.delivery.id}; package manifest: ${release.delivery.packageManifestSha256}; gateway manifest: ${release.delivery.manifestSha256}`:'';
|
|
216
|
+
return `VINi status: ${result.status}\n${installed}\nLauncher expects: ${result.launcherVersion}\nReceipt: ${result.receipt?.distribution.version??'not installed'}; launcher: ${result.launcher.status}\nAvailable published release: ${available}${site}${changes}\n${result.nextStep}`;
|
|
217
|
+
}
|
|
119
218
|
function launcher(distribution,appRelative) {
|
|
120
219
|
return `// Generated by VINi npm CLI; resolves persistent project packages, never npx cache.\nimport { createRequire } from 'node:module';\nimport { readFileSync, existsSync } from 'node:fs';\nimport { spawn } from 'node:child_process';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nconst project=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..');\nconst req=createRequire(path.join(project,${JSON.stringify(appRelative)},'package.json'));\nconst expected=${JSON.stringify(distribution)};\nlet server;\nfor(const key of ['tokens','ui','agent']) { const entry=req.resolve('@vini/'+key+(key==='agent'?'/mcp':'')); let dir=path.dirname(entry), meta; while(true){const file=path.join(dir,'package.json');if(existsSync(file)){meta=JSON.parse(readFileSync(file,'utf8'));if(meta.name&&meta.version)break;} const parent=path.dirname(dir);if(parent===dir)throw Error('VINi package metadata missing');dir=parent;} if(meta.name!==expected[key]||meta.version!==expected.version)throw Error('VINi installed package/agent versions differ; run matching VINi CLI update');if(key==='agent')server=entry;}\nconst child=spawn(process.execPath,[server],{stdio:'inherit',cwd:project});\nfor(const sig of ['SIGINT','SIGTERM'])process.on(sig,()=>child.kill(sig));\nchild.on('error',error=>{console.error(error.message);process.exitCode=1;});\nchild.on('exit',(code,signal)=>{process.exitCode=code??1;});\n`;
|
|
121
220
|
}
|
|
@@ -132,8 +231,11 @@ async function managerFor(root,app,options,manifest) {
|
|
|
132
231
|
if(manifest.workspaces)fail('workspace root is not supported by this alpha; choose a standalone Vite app');
|
|
133
232
|
return manager??'npm';
|
|
134
233
|
}
|
|
135
|
-
export async function init(options={},suppliedDistribution,{runner=run}={}) {
|
|
136
|
-
const
|
|
234
|
+
export async function init(options={},suppliedDistribution,{runner=run,releaseMetadata}={}) {
|
|
235
|
+
const cli=suppliedDistribution?null:json(await fileBytes(path.join(path.dirname(self),'package.json')),'CLI package');
|
|
236
|
+
const distribution=distributionCheck(suppliedDistribution??cli.viniDistribution);
|
|
237
|
+
const release=releaseMetadata??cli?.viniRelease;
|
|
238
|
+
if(release&&!validRelease(release))fail('invalid CLI release metadata');
|
|
137
239
|
const root=await fs.realpath(path.resolve(options.cwd??process.cwd()));
|
|
138
240
|
const app=await fs.realpath(path.resolve(root,options.appRoot??'.'));
|
|
139
241
|
if(app!==root&&!app.startsWith(root+path.sep))fail('app root must be inside project');
|
|
@@ -165,26 +267,30 @@ export async function init(options={},suppliedDistribution,{runner=run}={}) {
|
|
|
165
267
|
const configTable=`[mcp_servers.vini-ds]\ncommand = "node"\nargs = [${JSON.stringify(launchFile)}]\nenabled = true\nstartup_timeout_sec = 10`;
|
|
166
268
|
const config=Buffer.from(configMerge(before.get(configFile)?text(before.get(configFile),configFile):'',configTable,previous?.configTable));
|
|
167
269
|
const agents=Buffer.from(agentsMerge(before.get(agentsFile)?text(before.get(agentsFile),agentsFile):''));
|
|
168
|
-
const
|
|
270
|
+
const current=await readInstallation(root,path.relative(root,app)||'.',distribution);
|
|
271
|
+
const installedAligned=!!previous&¤t.launcher.status==='matches-receipt'&&['ui','tokens','agent'].every(key=>current.installed[key].matchesReceipt);
|
|
272
|
+
const plan={status:'plan-only',command:options.command??'init',projectRoot:root,appRoot:app,entry:path.relative(app,entry),packageManager:manager,installed:current.installed,installedStatus:previous?(installedAligned?'matches-receipt':'mismatch'):'not-installed',from:previous?.distribution??null,to:distribution,distribution,changes:transition(release,installedAligned?previous.distribution.version:null,distribution.version),release:release??null,restart:'Restart the project-local agent after updating; then check vini://system/current.',dependencies:{'@vini/ui':alias('ui'),'@vini/tokens':alias('tokens')},devDependencies:{'@vini/agent':alias('agent')},agent:'project-local Codex MCP + Skill',nativeClient:'not-verified',globalConfig:'unchanged',supported:'React 18, Vite direct createRoot(...).render(JSX), standalone npm/pnpm app'};
|
|
169
273
|
if(options.plan)return plan;
|
|
170
274
|
const recoveryRoot=path.join(root,'.vini-ds-recovery');await safeParents(root,path.join(recoveryRoot,'placeholder'));
|
|
275
|
+
const recoveryRootExisted=!!await exists(recoveryRoot);
|
|
171
276
|
const modules=path.join(app,'node_modules');
|
|
172
277
|
const moduleStat=await exists(modules);if(moduleStat&&(moduleStat.isSymbolicLink()||!moduleStat.isDirectory()))fail('node_modules must be a real directory');
|
|
173
278
|
const operationLock=path.join(root,'.vini-npm-install.lock');try{await fs.mkdir(operationLock,{mode:0o700});}catch(error){if(error.code==='EEXIST')fail('another VINi setup is active or previous recovery needs review');throw error;}
|
|
174
279
|
let backup;try{await fs.mkdir(recoveryRoot,{recursive:true,mode:0o700});backup=await fs.mkdtemp(path.join(recoveryRoot,'npm-'));}catch(error){await fs.rmdir(operationLock);throw error;}
|
|
175
|
-
const expected=new Map(before);let modulesMoved=false,installFailed=false,buildAttempted=false,uncertain=false;
|
|
280
|
+
const expected=new Map(before);let modulesMoved=false,projectMutationStarted=false,installFailed=false,buildAttempted=false,uncertain=false;
|
|
176
281
|
const write=async(file,bytes)=>{await safeParents(root,file);const current=await fileBytes(file,true),expectedBytes=expected.get(file);if(current===null?expectedBytes!==null:expectedBytes===null||!current.equals(expectedBytes))fail(`concurrent change: ${file}`);await fs.mkdir(path.dirname(file),{recursive:true});const temporary=path.join(path.dirname(file),`.vini-${randomUUID()}`);await fs.writeFile(temporary,bytes,{flag:'wx',mode:(await exists(file))?.mode&0o777||0o600});await fs.rename(temporary,file);expected.set(file,bytes);};
|
|
177
282
|
const pm=async(args)=>runner(manager==='npm'?'npm':'corepack',manager==='npm'?args:['pnpm',...args],{cwd:app});
|
|
178
283
|
const registry=options.registry?[`--registry=${options.registry}`]:[];
|
|
179
284
|
try {
|
|
180
|
-
for(const [file,bytes]of before)if(bytes!==null){const target=path.join(backup,'files',path.relative(root,file));await fs.mkdir(path.dirname(target),{recursive:true});await fs.writeFile(target,bytes);}
|
|
181
285
|
const next=structuredClone(manifest);next.dependencies={...next.dependencies,'@vini/tokens':alias('tokens'),'@vini/ui':alias('ui')};next.devDependencies={...next.devDependencies,'@vini/agent':alias('agent')};delete next.dependencies['@vini/agent'];delete next.devDependencies['@vini/ui'];delete next.devDependencies['@vini/tokens'];
|
|
182
286
|
const manifestAfter=Buffer.from(JSON.stringify(next,null,2)+'\n');
|
|
183
287
|
const unchanged=previous&&JSON.stringify(previous.distribution)===JSON.stringify(distribution)&&before.get(manifestFile).equals(manifestAfter)&&entryBefore.equals(entryAfter)&&before.get(configFile)?.equals(config)&&before.get(agentsFile)?.equals(agents)&&before.get(skillFile)!==null&&before.get(setupFile)!==null;
|
|
184
288
|
let verified=false;
|
|
185
289
|
if(unchanged){try{const req=createRequire(manifestFile);for(const key of ['tokens','ui','agent']){const pkg=await resolveManifest(req,`@vini/${key}`,key==='agent'?'/mcp':'');if(pkg.manifest.name!==distribution[key]||pkg.manifest.version!==distribution.version)throw new Error('mismatch');if(key==='agent')await verifyAgentContext(runner,pkg.entry,distribution,app);}verified=true;}catch{}}
|
|
186
|
-
if(verified)return {...plan,status:'already-installed',build:'not-rerun'};
|
|
290
|
+
if(verified){await fs.rmdir(backup);if(!recoveryRootExisted)await fs.rmdir(recoveryRoot).catch(error=>{if(error.code!=='ENOTEMPTY'&&error.code!=='ENOENT')throw error;});return {...plan,status:'already-installed',build:'not-rerun'};}
|
|
291
|
+
for(const [file,bytes]of before)if(bytes!==null){const target=path.join(backup,'files',path.relative(root,file));await fs.mkdir(path.dirname(target),{recursive:true});await fs.writeFile(target,bytes);}
|
|
187
292
|
if(moduleStat){await fs.rename(modules,path.join(backup,'node_modules'));modulesMoved=true;}
|
|
293
|
+
projectMutationStarted=true;
|
|
188
294
|
await write(manifestFile,manifestAfter);
|
|
189
295
|
try {await pm(manager==='npm'?['install','--ignore-scripts','--strict-peer-deps','--no-audit','--no-fund',...registry]:['install','--ignore-scripts','--config.strict-peer-dependencies=true','--no-frozen-lockfile',...registry]);}
|
|
190
296
|
catch(error){installFailed=true;throw error;}
|
|
@@ -204,6 +310,7 @@ export async function init(options={},suppliedDistribution,{runner=run}={}) {
|
|
|
204
310
|
return {...plan,status:'installed',build:buildAttempted?'passed':'not-configured',recovery:backup};
|
|
205
311
|
} catch(error) {
|
|
206
312
|
if(error.uncertainChildren){uncertain=true;throw new Error(`${error.message}; retained lock and recovery: ${backup}`);}
|
|
313
|
+
if(!projectMutationStarted&&!modulesMoved)throw new Error(`${error.message}; no project files or dependencies changed; recovery retained: ${backup}`);
|
|
207
314
|
const issues=[];
|
|
208
315
|
let mayRecover=!installFailed;
|
|
209
316
|
if(installFailed)try{
|
|
@@ -230,4 +337,4 @@ export async function init(options={},suppliedDistribution,{runner=run}={}) {
|
|
|
230
337
|
throw new Error(`${error.message}; ${issues.length?'recovery incomplete: '+issues.join('; '):'original files and dependencies restored'}; saved originals: ${backup}${buildAttempted?'; build outputs are not automatically restored':''}`);
|
|
231
338
|
} finally {if(!uncertain)await fs.rmdir(operationLock);}
|
|
232
339
|
}
|
|
233
|
-
if(process.argv[1]&&await fs.realpath(process.argv[1]).catch(()=>null)===self){try{const options=parseArgs(process.argv.slice(2));console.log(options.
|
|
340
|
+
if(process.argv[1]&&await fs.realpath(process.argv[1]).catch(()=>null)===self){try{const options=parseArgs(process.argv.slice(2));if(options.help)console.log(usage);else if(options.command==='status'){const result=await status(options);console.log(options.json?JSON.stringify(result,null,2):formatStatus(result));}else console.log(JSON.stringify(await init(options),null,2));}catch(error){console.error(error.message);process.exitCode=1;}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vini-ds",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "VINi React project and local agent setup",
|
|
6
6
|
"bin": {
|
|
@@ -20,9 +20,32 @@
|
|
|
20
20
|
"typescript": "5.5.4"
|
|
21
21
|
},
|
|
22
22
|
"viniDistribution": {
|
|
23
|
-
"version": "0.1.0-alpha.
|
|
23
|
+
"version": "0.1.0-alpha.1",
|
|
24
24
|
"ui": "@timelex/vini-ui",
|
|
25
25
|
"tokens": "@timelex/vini-tokens",
|
|
26
26
|
"agent": "@timelex/vini-agent"
|
|
27
|
+
},
|
|
28
|
+
"viniRelease": {
|
|
29
|
+
"atlas": {
|
|
30
|
+
"url": "https://vini-atlas-pilot.layero.app/",
|
|
31
|
+
"archiveSha256": "sha256:d34523af2875a85b00fb41177ec4e3d539d6281cef23523b6253156781503647",
|
|
32
|
+
"siteRelease": "public-atlas-20261103-final",
|
|
33
|
+
"commit": "5b77933f6f7c37bea346e8e2276fc4952086be1d"
|
|
34
|
+
},
|
|
35
|
+
"delivery": {
|
|
36
|
+
"id": "candidate-33650c3731824b54",
|
|
37
|
+
"manifestSha256": "sha256:2d5f20b571a1ca5d330e46641c044afa5c97b14477ad83bfe1670df9b464893a",
|
|
38
|
+
"packageManifestSha256": "sha256:e937711fe54769b392b1cffc2982b4801e1339eee87ddbc1e6f726916bc06d8e"
|
|
39
|
+
},
|
|
40
|
+
"changes": {
|
|
41
|
+
"fromVersion": "0.1.0-alpha.0",
|
|
42
|
+
"summary": "Среди изменений — компоненты компоновки Container, Grid, Inline и Stack. Пакеты UI и токенов обновлены до сборки Atlas от 03.11.2026; в CLI добавлены проверка версии и план обновления, в MCP — проверка обновлений. Перечень изменений компонентов не является полным.",
|
|
43
|
+
"components": [
|
|
44
|
+
"Container",
|
|
45
|
+
"Grid",
|
|
46
|
+
"Inline",
|
|
47
|
+
"Stack"
|
|
48
|
+
]
|
|
49
|
+
}
|
|
27
50
|
}
|
|
28
51
|
}
|