@@ -99,6 +99,78 @@ namespace
9999 return true ;
100100 }
101101
102+ std::string default_workspace_title ()
103+ {
104+ std::error_code ec;
105+ fs::path cwd = fs::current_path (ec);
106+
107+ if (!ec)
108+ {
109+ const std::string name = cwd.filename ().string ();
110+
111+ if (!name.empty ())
112+ {
113+ return name;
114+ }
115+ }
116+
117+ return " Untitled Note" ;
118+ }
119+
120+ fs::path next_untitled_note_path ()
121+ {
122+ for (int i = 0 ; i < 1000 ; ++i)
123+ {
124+ fs::path candidate =
125+ i == 0
126+ ? fs::path (" Untitled.vixnote" )
127+ : fs::path (" Untitled-" + std::to_string (i) + " .vixnote" );
128+
129+ std::error_code ec;
130+
131+ if (!fs::exists (candidate, ec) && !ec)
132+ {
133+ return candidate;
134+ }
135+ }
136+
137+ return fs::path (" Untitled.vixnote" );
138+ }
139+
140+ vix::note::NoteDocument make_workspace_note_document ()
141+ {
142+ const std::string title = default_workspace_title ();
143+
144+ vix::note::NoteDocument document (title);
145+ document.set_path (next_untitled_note_path ().string ());
146+
147+ document.add_cell (
148+ vix::note::NoteCell (
149+ " intro" ,
150+ vix::note::NoteCellKind::Markdown,
151+ " # " + title + " \n\n Start writing your note here." ));
152+
153+ return document;
154+ }
155+
156+ fs::path note_context_path (const fs::path ¬ePath)
157+ {
158+ if (!notePath.empty ())
159+ {
160+ return notePath;
161+ }
162+
163+ std::error_code ec;
164+ fs::path cwd = fs::current_path (ec);
165+
166+ if (!ec)
167+ {
168+ return cwd;
169+ }
170+
171+ return fs::path (" ." );
172+ }
173+
102174 int run_export_command (const std::vector<std::string> &args)
103175 {
104176 using namespace vix ::cli::style;
@@ -547,47 +619,55 @@ namespace vix::commands
547619 notePath = arg;
548620 }
549621
550- if (notePath.empty ())
551- {
552- error (" No Vix Note file provided." );
553- hint (" Usage: vix note <file.vixnote> [options]" );
554- hint (" Example: vix note examples/hello.vixnote" );
555- return 1 ;
556- }
622+ const bool workspaceMode = notePath.empty ();
557623
558624 std::error_code ec;
625+ vix::note::NoteDocument document;
559626
560- if (! fs::exists (notePath, ec) || ec )
627+ if (workspaceMode )
561628 {
562- error (" Note file not found: " + notePath.string ());
563- hint (" Create a .vixnote file or pass the correct path." );
564- return 1 ;
565- }
629+ document = make_workspace_note_document ();
566630
567- if (!fs::is_regular_file (notePath, ec) || ec)
568- {
569- error (" Note path is not a file: " + notePath.string ());
570- return 1 ;
631+ info (" Starting Vix Note workspace:" );
632+ step (fs::current_path (ec).string ());
571633 }
572-
573- if (notePath.extension () != " .vixnote" )
634+ else
574635 {
575- error (" Invalid note file extension: " + notePath.string ());
576- hint (" Expected a .vixnote file." );
577- return 1 ;
578- }
636+ if (!fs::exists (notePath, ec) || ec)
637+ {
638+ error (" Note file not found: " + notePath.string ());
639+ hint (" Create a .vixnote file or pass the correct path." );
640+ return 1 ;
641+ }
579642
580- vix::note::NoteLoadResult loaded = vix::note::load_note (notePath);
643+ if (!fs::is_regular_file (notePath, ec) || ec)
644+ {
645+ error (" Note path is not a file: " + notePath.string ());
646+ return 1 ;
647+ }
581648
582- if (!loaded.ok )
583- {
584- error (" Unable to load note file." );
585- hint (loaded.error .empty () ? notePath.string () : loaded.error );
586- return 1 ;
649+ if (notePath.extension () != " .vixnote" )
650+ {
651+ error (" Invalid note file extension: " + notePath.string ());
652+ hint (" Expected a .vixnote file." );
653+ return 1 ;
654+ }
655+
656+ vix::note::NoteLoadResult loaded =
657+ vix::note::load_note (notePath);
658+
659+ if (!loaded.ok )
660+ {
661+ error (" Unable to load note file." );
662+ hint (loaded.error .empty () ? notePath.string () : loaded.error );
663+ return 1 ;
664+ }
665+
666+ document = std::move (loaded.document );
587667 }
588668
589669 vix::note::ProjectContext projectContext =
590- vix::note::detect_project_context (notePath);
670+ vix::note::detect_project_context (note_context_path ( notePath) );
591671
592672 vix::note::NoteServerOptions options;
593673 options.host = host;
@@ -597,7 +677,7 @@ namespace vix::commands
597677 options.logRequests = true ;
598678
599679 vix::note::NoteServer server (
600- std::move (loaded. document ),
680+ std::move (document),
601681 options);
602682
603683 vix::note::NoteResult started = server.start ();
@@ -627,7 +707,7 @@ namespace vix::commands
627707#ifdef VIX_CLI_HAS_UI
628708 return run_note_desktop_shell (
629709 server,
630- notePath,
710+ workspaceMode ? note_context_path (notePath) : notePath,
631711 shellWidth,
632712 shellHeight,
633713 devtools,
@@ -668,12 +748,13 @@ namespace vix::commands
668748 {
669749 std::cout
670750 << " Usage:\n "
671- << " vix note < file.vixnote> [options]\n "
751+ << " vix note [ file.vixnote] [options]\n "
672752 << " vix note export <file.vixnote> --out <file.html> [options]\n\n "
673753
674754 << " Description:\n "
675755 << " Open a Vix Note document in a local browser UI or desktop WebView shell.\n "
676- << " The command loads a .vixnote file, starts a local note server,\n "
756+ << " Without a file, the command starts a Vix Note workspace in the current directory.\n "
757+ << " With a .vixnote file, it loads that document and starts a local note server.\n "
677758 << " and exposes the visual workspace through HTTP.\n "
678759 << " It can also export a .vixnote file to a standalone HTML lesson.\n\n "
679760
@@ -691,9 +772,12 @@ namespace vix::commands
691772 << " --devtools Enable WebView developer tools when supported\n "
692773 << " --fullscreen Start desktop shell fullscreen\n "
693774 << " --no-resizable Disable desktop shell resizing\n "
775+ << " file.vixnote Optional note file to open. If omitted, starts in the current directory\n "
694776 << " -h, --help Show this help\n\n "
695777
696778 << " Examples:\n "
779+ << " vix note\n "
780+ << " vix note --desktop\n "
697781 << " vix note examples/hello.vixnote\n "
698782 << " vix note lessons/pointers.vixnote --port 5180\n "
699783 << " vix note export examples/hello.vixnote --out hello.html\n "
0 commit comments