@nemus-cli/nemus 0.15.1 → 0.16.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/CHANGELOG.md CHANGED
@@ -7,6 +7,51 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.16.0] - 2026-09-09
11
+
12
+ ### Added
13
+
14
+ - **Portable workspaces: `nemus lock` & `nemus restore`.** `nemus lock` writes a
15
+ small, committable `nemus.lock` capturing every repo (owner, directory, clone
16
+ URL), the branch each repo is currently on, and its HEAD commit; `-o <file>`
17
+ writes elsewhere and `-o -` prints it to stdout. `nemus restore` recreates the
18
+ workspace from a lockfile (defaults to `./nemus.lock`, or `-` for stdin) on any
19
+ machine — it clones every repo and checks out the recorded branch, then writes
20
+ metadata + agent context exactly like `create`. `--pin` checks out the exact
21
+ recorded commit instead of the branch tip, and `-w/--workspace` overrides the
22
+ name baked into the lockfile. `nemus lock --all` drops a lockfile into every
23
+ workspace at once (skipping existing ones unless `--force`) — the explicit way
24
+ to make a whole machine portable, rather than a hidden side effect in
25
+ `migrate`. The MCP server gains matching `lock-workspace` / `restore-workspace`
26
+ tools (restore accepts the manifest inline via `lockContent`) so agents have
27
+ the same portability as `create`/`update`/`delete`. Restore rebuilds https/ssh URLs for the
28
+ restorer's `cloneProtocol` from the locked host+owner+name (falling back to the
29
+ stored URL), so an ssh-locked workspace restores fine for an https user. The
30
+ lockfile holds only what `git remote -v` already exposes — no secrets — so it's
31
+ safe to commit. Unlike a local `snapshot` (time-travel within an existing
32
+ workspace) or a `suite` (reusable repo template), a lockfile pins one
33
+ workspace's exact repos + branch state and recreates it from nothing.
34
+
35
+ ## [0.15.2] - 2026-09-04
36
+
37
+ ### Fixed
38
+
39
+ - **First-run setup now runs for global installs via yarn and pnpm too — without
40
+ re-introducing the hang for their transient runners.** 0.15.1 gated postinstall
41
+ setup on `npm_config_global`, which only npm sets, so `yarn global add` /
42
+ `pnpm add -g` silently skipped `configure` + shell integration (the auto-cd /
43
+ `nemgo` feature). The gate now classifies the install context: it recognizes a
44
+ global yarn/pnpm install from `npm_config_user_agent`, but detects transient
45
+ one-off runners (`npx`, `pnpm dlx`, `yarn dlx`) by the per-run cache path they
46
+ stage into (`.../_npx/...`, `.../dlx/...`, the OS temp dir, with the macOS
47
+ `/private` symlink normalized) — because `pnpm dlx`/`yarn dlx` set *neither*
48
+ `npm_command` *nor* `npm_config_global`, so a user-agent check alone would
49
+ misclassify them as a global install. Hang-safety itself comes from a separate
50
+ guard — the interactive `configure` only fires for a confirmed npm `-g`
51
+ install, so yarn/pnpm globals get the non-interactive shell integration plus a
52
+ hint and can never hang; the transient path detection's job is to stop a
53
+ throwaway `dlx` run from spuriously writing the shell RC. (#92)
54
+
10
55
  ## [0.15.1] - 2026-09-04
11
56
 
12
57
  ### Fixed
package/README.md CHANGED
@@ -354,6 +354,34 @@ nemus snapshot save ws # (ss) capture exact branches/commits/dirty state
354
354
  nemus snapshot restore <id> # (sr)
355
355
  ```
356
356
 
357
+ ### Portable workspaces — `lock` & `restore`
358
+
359
+ Share the *exact* workspace you're in. `nemus lock` writes a small, committable
360
+ `nemus.lock` (repos + owner + the branch each repo is on + its HEAD commit);
361
+ `nemus restore` recreates that workspace from scratch on any machine — clones
362
+ every repo and checks out the recorded branch.
363
+
364
+ ```bash
365
+ nemus lock # write ./nemus.lock for the current workspace
366
+ nemus lock my-ws -o my-ws.lock # or a named workspace, to a file
367
+ nemus lock my-ws -o - # print the lockfile to stdout (pipe it anywhere)
368
+ nemus lock --all [--force] # drop a nemus.lock into every workspace at once
369
+
370
+ nemus restore # recreate from ./nemus.lock
371
+ nemus restore my-ws.lock # from a specific file (or `-` to read stdin)
372
+ nemus restore my-ws.lock -w exp --pin # new name; pin exact commits, not branch tips
373
+ ```
374
+
375
+ Commit `nemus.lock` next to a design doc or drop it in a ticket, and a teammate
376
+ runs `nemus restore` to land in the identical multi-repo setup. It contains only
377
+ what `git remote -v` already exposes — no secrets — so it's safe to commit.
378
+
379
+ > **`lock`/`restore` vs. `snapshot`:** a *snapshot* is local time-travel for a
380
+ > workspace that already exists on your machine; `lock`/`restore` is portable —
381
+ > it recreates the workspace (repos and all) from nothing, on any machine.
382
+ > **vs. `suite`:** a *suite* is a reusable repo *template*; a lockfile pins one
383
+ > workspace's *exact* repos and branch state.
384
+
357
385
  ### Reflect — improve your setup over time
358
386
 
359
387
  ```bash
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.registerLockCommand = registerLockCommand;
37
+ const path = __importStar(require("path"));
38
+ const fs = __importStar(require("fs/promises"));
39
+ const config_1 = require("../utils/config");
40
+ const workspace_meta_1 = require("../utils/workspace-meta");
41
+ const command_helpers_1 = require("../utils/command-helpers");
42
+ const workspace_lock_1 = require("../utils/workspace-lock");
43
+ const logger_1 = require("../utils/logger");
44
+ const colors_1 = require("../utils/colors");
45
+ function registerLockCommand(parent) {
46
+ parent
47
+ .command('lock [workspace]')
48
+ .description('Snapshot a workspace into a committable nemus.lock (repos + branches)')
49
+ .option('-o, --output <file>', 'Write the lockfile to <file> ("-" for stdout) instead of the workspace root')
50
+ .option('--all', 'Write a nemus.lock into every workspace (skips ones that already have one)')
51
+ .option('--force', 'With --all, overwrite an existing nemus.lock')
52
+ .action(async (workspace, opts, cmd) => {
53
+ const globalOpts = (0, command_helpers_1.getGlobalOpts)(cmd);
54
+ await handleLock({ workspace, ...opts, ...globalOpts });
55
+ });
56
+ }
57
+ async function fileExists(p) {
58
+ try {
59
+ await fs.access(p);
60
+ return true;
61
+ }
62
+ catch {
63
+ return false;
64
+ }
65
+ }
66
+ async function handleLock(opts) {
67
+ if (opts.all) {
68
+ await handleLockAll(opts);
69
+ return;
70
+ }
71
+ try {
72
+ const workspaceName = await (0, command_helpers_1.resolveWorkspace)(opts.workspace);
73
+ const workspacePath = path.join(config_1.WORKSPACES_DIR, workspaceName);
74
+ const metadata = await (0, workspace_meta_1.loadMetadata)(workspacePath);
75
+ if (!metadata) {
76
+ (0, logger_1.logError)(`Workspace not found: ${workspaceName}`);
77
+ process.exit(1);
78
+ }
79
+ const lock = await (0, workspace_lock_1.buildLock)(workspacePath, metadata);
80
+ // `-o -`: emit only the lockfile JSON so it can be piped/redirected cleanly.
81
+ if (opts.output === '-') {
82
+ process.stdout.write((0, workspace_lock_1.serializeLock)(lock));
83
+ return;
84
+ }
85
+ const outPath = opts.output
86
+ ? path.resolve(opts.output)
87
+ : path.join(workspacePath, workspace_lock_1.LOCK_FILENAME);
88
+ await (0, workspace_lock_1.writeLock)(outPath, lock);
89
+ (0, logger_1.logSuccess)(`Wrote ${(0, colors_1.colorize)(workspace_lock_1.LOCK_FILENAME, 'cyan')} (${lock.repositories.length} repos) → ${outPath}`);
90
+ (0, logger_1.logInfo)('Commit or share it, then recreate the workspace with: nemus restore');
91
+ }
92
+ catch (error) {
93
+ (0, logger_1.logError)(error instanceof Error ? error.message : 'Failed to write lockfile');
94
+ process.exit(1);
95
+ }
96
+ }
97
+ /**
98
+ * Bulk mode: drop a nemus.lock into every workspace so a whole machine's
99
+ * workspaces become portable in one shot. Existing lockfiles are left alone
100
+ * (they may be hand-edited / committed) unless --force is given — this is the
101
+ * explicit, discoverable alternative to burying a snapshot side effect inside
102
+ * `migrate`, which is meant to be re-run freely.
103
+ */
104
+ async function handleLockAll(opts) {
105
+ if (opts.output) {
106
+ (0, logger_1.logError)('--all writes one nemus.lock per workspace and cannot be combined with --output.');
107
+ process.exit(1);
108
+ }
109
+ const workspaces = await (0, workspace_meta_1.listWorkspaces)(false);
110
+ if (workspaces.length === 0) {
111
+ (0, logger_1.logInfo)('No workspaces found. Nothing to lock.');
112
+ return;
113
+ }
114
+ let written = 0;
115
+ let skipped = 0;
116
+ let errors = 0;
117
+ for (const ws of workspaces) {
118
+ const metadata = ws.metadata ?? (await (0, workspace_meta_1.loadMetadata)(ws.path));
119
+ if (!metadata) {
120
+ (0, logger_1.logWarning)(` ${ws.name}: no metadata — skipped (run 'nemus migrate' first)`);
121
+ skipped++;
122
+ continue;
123
+ }
124
+ const outPath = path.join(ws.path, workspace_lock_1.LOCK_FILENAME);
125
+ if (!opts.force && (await fileExists(outPath))) {
126
+ (0, logger_1.logInfo)(` ${(0, colors_1.colorize)(ws.name, 'cyan')}: ${workspace_lock_1.LOCK_FILENAME} already exists — skipped (use --force to overwrite)`);
127
+ skipped++;
128
+ continue;
129
+ }
130
+ try {
131
+ const lock = await (0, workspace_lock_1.buildLock)(ws.path, metadata);
132
+ await (0, workspace_lock_1.writeLock)(outPath, lock);
133
+ (0, logger_1.logSuccess)(` ${(0, colors_1.colorize)(ws.name, 'cyan')}: wrote ${workspace_lock_1.LOCK_FILENAME} (${lock.repositories.length} repos)`);
134
+ written++;
135
+ }
136
+ catch (error) {
137
+ (0, logger_1.logError)(` ${ws.name}: ${error instanceof Error ? error.message : 'failed to write lockfile'}`);
138
+ errors++;
139
+ }
140
+ }
141
+ console.log('');
142
+ (0, logger_1.logInfo)('Bulk lock complete:');
143
+ console.log(` ${(0, colors_1.colorize)(String(written), 'green')} written`);
144
+ if (skipped > 0)
145
+ console.log(` ${(0, colors_1.colorize)(String(skipped), 'yellow')} skipped`);
146
+ if (errors > 0)
147
+ console.log(` ${(0, colors_1.colorize)(String(errors), 'red')} errors`);
148
+ }
@@ -0,0 +1,232 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.registerRestoreCommand = registerRestoreCommand;
37
+ exports.restoreWorkspace = restoreWorkspace;
38
+ const child_process_1 = require("child_process");
39
+ const util_1 = require("util");
40
+ const path = __importStar(require("path"));
41
+ const command_helpers_1 = require("../utils/command-helpers");
42
+ const workspace_lock_1 = require("../utils/workspace-lock");
43
+ const git_operations_1 = require("../utils/git-operations");
44
+ const ghq_integration_1 = require("../utils/ghq-integration");
45
+ const workspace_meta_1 = require("../utils/workspace-meta");
46
+ const claude_integration_1 = require("../utils/claude-integration");
47
+ const github_1 = require("../utils/github");
48
+ const validation_1 = require("../utils/validation");
49
+ const logger_1 = require("../utils/logger");
50
+ const colors_1 = require("../utils/colors");
51
+ const banner_1 = require("../utils/banner");
52
+ const execFileAsync = (0, util_1.promisify)(child_process_1.execFile);
53
+ const GIT_TIMEOUT = 30000;
54
+ function registerRestoreCommand(parent) {
55
+ parent
56
+ .command('restore [lockfile]')
57
+ .description('Recreate a workspace from a nemus.lock (defaults to ./nemus.lock, "-" for stdin)')
58
+ .option('-w, --workspace <name>', 'Override the workspace name baked into the lockfile')
59
+ .option('--pin', 'Check out the exact recorded commit instead of the branch tip')
60
+ .action(async (lockfile, opts, cmd) => {
61
+ const globalOpts = (0, command_helpers_1.getGlobalOpts)(cmd);
62
+ await handleRestore({ lockfile, ...opts, ...globalOpts });
63
+ });
64
+ }
65
+ async function readStdin() {
66
+ const chunks = [];
67
+ for await (const chunk of process.stdin)
68
+ chunks.push(chunk);
69
+ return Buffer.concat(chunks).toString('utf-8');
70
+ }
71
+ // `branch`/`commit` come from an untrusted lockfile (already ref-validated in
72
+ // parseLock); the `--end-of-options` guard is defense-in-depth so a ref can
73
+ // never be reparsed as a git option even if validation is bypassed.
74
+ /** Check out `branch` in a freshly-cloned repo, creating a tracking branch if needed. */
75
+ async function checkoutBranch(repoPath, branch) {
76
+ try {
77
+ await execFileAsync('git', ['checkout', '--end-of-options', branch], { cwd: repoPath, timeout: GIT_TIMEOUT });
78
+ return true;
79
+ }
80
+ catch {
81
+ try {
82
+ await execFileAsync('git', ['checkout', '-b', branch, '--end-of-options', `origin/${branch}`], { cwd: repoPath, timeout: GIT_TIMEOUT });
83
+ return true;
84
+ }
85
+ catch {
86
+ return false;
87
+ }
88
+ }
89
+ }
90
+ async function checkoutCommit(repoPath, commit) {
91
+ try {
92
+ await execFileAsync('git', ['checkout', '--end-of-options', commit], { cwd: repoPath, timeout: GIT_TIMEOUT });
93
+ return true;
94
+ }
95
+ catch {
96
+ return false;
97
+ }
98
+ }
99
+ /**
100
+ * Core restore: clone every repo in a (already-validated) lock and check out the
101
+ * recorded branch (or the exact commit with `pin`), then write metadata + agent
102
+ * context — exactly like `create`. Throws on fatal errors (no process.exit) and
103
+ * logs progress via the logger (stderr), so both the CLI and the MCP tool can
104
+ * call it. Callers own presentation (final message, shell-CD hook).
105
+ */
106
+ async function restoreWorkspace(lock, opts = {}) {
107
+ if (lock.repositories.length === 0) {
108
+ throw new Error('Lockfile has no repositories to restore');
109
+ }
110
+ // Resolve the target workspace name
111
+ let workspaceName = (0, validation_1.sanitizeWorkspaceName)(opts.workspace || lock.workspace);
112
+ const nameError = (0, validation_1.validateWorkspaceName)(workspaceName);
113
+ if (nameError !== true) {
114
+ throw new Error(typeof nameError === 'string' ? nameError : 'Invalid workspace name');
115
+ }
116
+ if (await (0, validation_1.checkWorkspaceExists)(workspaceName)) {
117
+ const resolved = await (0, validation_1.resolveWorkspaceNameConflict)(workspaceName, lock.repositories.map(r => r.directoryName));
118
+ (0, logger_1.logInfo)(`Workspace "${workspaceName}" already exists — using "${(0, colors_1.colorize)(resolved, 'cyan')}" instead.`);
119
+ workspaceName = resolved;
120
+ }
121
+ const workspacePath = (0, validation_1.safeWorkspacePath)(workspaceName);
122
+ (0, logger_1.logInfo)(`Restoring ${(0, colors_1.colorize)(String(lock.repositories.length), 'cyan')} repos into workspace "${(0, colors_1.colorize)(workspaceName, 'cyan')}"`);
123
+ // Clone every repo (reuses the create pipeline: ghq, concurrency, dedup)
124
+ (0, logger_1.logStep)(1, 3, 'Cloning repositories...');
125
+ const { mkdir } = await Promise.resolve().then(() => __importStar(require('fs/promises')));
126
+ await mkdir(workspacePath, { recursive: true });
127
+ await (0, ghq_integration_1.warnIfGhqMissing)();
128
+ const entries = lock.repositories.map(r => ({
129
+ repo: (0, workspace_lock_1.reconstructRepo)(r),
130
+ directoryName: r.directoryName,
131
+ }));
132
+ const results = await (0, git_operations_1.cloneRepositories)(entries, workspacePath);
133
+ (0, git_operations_1.reportCloneResults)(results);
134
+ // Check out the recorded branch (or pinned commit) per repo
135
+ (0, logger_1.logStep)(2, 3, opts.pin ? 'Checking out pinned commits...' : 'Checking out recorded branches...');
136
+ const byDir = new Map(lock.repositories.map(r => [r.directoryName, r]));
137
+ for (const result of results) {
138
+ if (result.status !== 'success')
139
+ continue;
140
+ const entry = byDir.get(result.directoryName);
141
+ if (!entry)
142
+ continue;
143
+ const repoPath = path.join(workspacePath, result.directoryName);
144
+ const display = (0, colors_1.colorize)(result.directoryName, 'cyan');
145
+ if (opts.pin && entry.commit) {
146
+ if (!(await checkoutCommit(repoPath, entry.commit))) {
147
+ (0, logger_1.logWarning)(`${display}: could not check out pinned commit ${entry.commit} — left on the default branch`);
148
+ }
149
+ }
150
+ else if (entry.branch) {
151
+ if (await checkoutBranch(repoPath, entry.branch)) {
152
+ (0, logger_1.logInfo)(`${display} → ${entry.branch}`);
153
+ }
154
+ else if (entry.commit && (await checkoutCommit(repoPath, entry.commit))) {
155
+ (0, logger_1.logWarning)(`${display}: branch "${entry.branch}" not found — checked out commit ${entry.commit} instead`);
156
+ }
157
+ else {
158
+ (0, logger_1.logWarning)(`${display}: could not check out "${entry.branch}" — left on the default branch`);
159
+ }
160
+ }
161
+ else if (entry.commit) {
162
+ // No branch was recorded (detached HEAD at lock time) — restore the commit
163
+ // so that state isn't silently lost even without --pin.
164
+ if (await checkoutCommit(repoPath, entry.commit)) {
165
+ (0, logger_1.logInfo)(`${display} → ${entry.commit} (detached)`);
166
+ }
167
+ else {
168
+ (0, logger_1.logWarning)(`${display}: could not check out commit ${entry.commit} — left on the default branch`);
169
+ }
170
+ }
171
+ }
172
+ // Metadata + agent context (same as create)
173
+ (0, logger_1.logStep)(3, 3, 'Saving workspace metadata...');
174
+ const metadata = (0, workspace_meta_1.createMetadata)(workspaceName, results, { prompt: `Restored from ${workspace_lock_1.LOCK_FILENAME}` });
175
+ await (0, workspace_meta_1.saveMetadata)(workspacePath, metadata);
176
+ const successfulRepos = results.filter(r => r.status === 'success').map(r => r.repo);
177
+ if (successfulRepos.length > 0) {
178
+ await (0, claude_integration_1.generateClaudeContext)(workspacePath, workspaceName, successfulRepos, metadata);
179
+ }
180
+ return { workspaceName, workspacePath, results };
181
+ }
182
+ async function handleRestore(opts) {
183
+ (0, banner_1.printBanner)();
184
+ try {
185
+ // Step 1: Load + validate the lockfile
186
+ let lock;
187
+ if (opts.lockfile === '-') {
188
+ lock = (0, workspace_lock_1.parseLock)(await readStdin());
189
+ }
190
+ else {
191
+ const lockPath = path.resolve(opts.lockfile || workspace_lock_1.LOCK_FILENAME);
192
+ try {
193
+ lock = await (0, workspace_lock_1.readLockFile)(lockPath);
194
+ }
195
+ catch (error) {
196
+ (0, logger_1.logError)(`Could not read lockfile at ${lockPath}`);
197
+ if (error instanceof Error)
198
+ (0, logger_1.logError)(error.message);
199
+ (0, logger_1.logInfo)('Pass a path (nemus restore path/to/nemus.lock) or pipe one with: nemus restore -');
200
+ process.exit(1);
201
+ }
202
+ }
203
+ if (lock.repositories.length === 0) {
204
+ (0, logger_1.logError)('Lockfile has no repositories to restore');
205
+ process.exit(1);
206
+ }
207
+ // gh auth (soft — private repos need it, public/other creds may not)
208
+ if (!(await (0, github_1.verifyGhAuth)())) {
209
+ (0, logger_1.logWarning)('GitHub CLI not authenticated — private repositories may fail to clone.');
210
+ }
211
+ const { workspaceName, workspacePath } = await restoreWorkspace(lock, {
212
+ workspace: opts.workspace,
213
+ pin: opts.pin,
214
+ });
215
+ (0, logger_1.logSuccess)(`Workspace "${(0, colors_1.colorize)(workspaceName, 'cyan')}" restored!`);
216
+ // Shell-integration auto-CD (same hook create uses)
217
+ try {
218
+ const { writeFile } = await Promise.resolve().then(() => __importStar(require('fs/promises')));
219
+ const os = await Promise.resolve().then(() => __importStar(require('os')));
220
+ await writeFile(path.join(os.homedir(), '.workspace-last-created'), workspacePath, 'utf-8');
221
+ }
222
+ catch {
223
+ // non-critical
224
+ }
225
+ }
226
+ catch (error) {
227
+ (0, logger_1.logError)('Failed to restore workspace');
228
+ if (error instanceof Error)
229
+ (0, logger_1.logError)(error.message);
230
+ process.exit(1);
231
+ }
232
+ }
@@ -387,6 +387,34 @@ server.tool('save-context', 'Save a progress summary to the workspace. Use this
387
387
  return { content: [{ type: 'text', text: `Error: ${msg}` }], isError: true };
388
388
  }
389
389
  });
390
+ server.tool('lock-workspace', 'Snapshot a workspace into a committable nemus.lock manifest (repos + owner + the branch each repo is on + its HEAD commit) so it can be shared and recreated elsewhere with restore-workspace. Writes nemus.lock to the workspace root by default and returns the manifest.', {
391
+ workspace: wsName.describe('Name of the workspace to lock'),
392
+ output: zod_1.z.string().optional().describe('Optional path to write the lockfile to instead of <workspace>/nemus.lock'),
393
+ }, async ({ workspace, output }) => {
394
+ try {
395
+ const result = await (0, tools_1.handleLockWorkspace)(workspace, output);
396
+ return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
397
+ }
398
+ catch (error) {
399
+ const msg = error instanceof Error ? error.message : 'Unknown error';
400
+ return { content: [{ type: 'text', text: `Error: ${msg}` }], isError: true };
401
+ }
402
+ });
403
+ server.tool('restore-workspace', 'Recreate a workspace from a nemus.lock manifest: clone every repo and check out the recorded branch (or the exact commit with pin). Provide the manifest inline via lockContent, or a path via lockfile (defaults to ./nemus.lock).', {
404
+ lockContent: zod_1.z.string().optional().describe('The nemus.lock manifest JSON, inline (preferred for agents)'),
405
+ lockfile: zod_1.z.string().optional().describe('Path to a nemus.lock file (used when lockContent is not given; defaults to ./nemus.lock)'),
406
+ workspace: wsName.optional().describe('Override the workspace name baked into the lockfile'),
407
+ pin: zod_1.z.boolean().optional().describe('Check out the exact recorded commit instead of the branch tip'),
408
+ }, async ({ lockContent, lockfile, workspace, pin }) => {
409
+ try {
410
+ const result = await (0, tools_1.handleRestoreWorkspace)({ lockContent, lockfile, workspace, pin });
411
+ return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
412
+ }
413
+ catch (error) {
414
+ const msg = error instanceof Error ? error.message : 'Unknown error';
415
+ return { content: [{ type: 'text', text: `Error: ${msg}` }], isError: true };
416
+ }
417
+ });
390
418
  async function main() {
391
419
  const transport = new stdio_js_1.StdioServerTransport();
392
420
  await server.connect(transport);
package/dist/mcp/tools.js CHANGED
@@ -65,6 +65,8 @@ exports.handleSuiteExport = handleSuiteExport;
65
65
  exports.handleSuiteImport = handleSuiteImport;
66
66
  exports.handleSuiteUse = handleSuiteUse;
67
67
  exports.handleSaveContext = handleSaveContext;
68
+ exports.handleLockWorkspace = handleLockWorkspace;
69
+ exports.handleRestoreWorkspace = handleRestoreWorkspace;
68
70
  const fs = __importStar(require("fs/promises"));
69
71
  const path = __importStar(require("path"));
70
72
  const os = __importStar(require("os"));
@@ -87,6 +89,8 @@ const branch_operations_1 = require("../utils/branch-operations");
87
89
  const cleanup_operations_1 = require("../utils/cleanup-operations");
88
90
  const hooks_1 = require("../utils/hooks");
89
91
  const validation_1 = require("../utils/validation");
92
+ const workspace_lock_1 = require("../utils/workspace-lock");
93
+ const restore_1 = require("../commands/restore");
90
94
  /**
91
95
  * Redirects stdout to stderr for the duration of a function call.
92
96
  * MCP uses stdout exclusively for JSON-RPC, so any console.log from
@@ -920,3 +924,60 @@ async function handleSaveContext(workspace, content, append) {
920
924
  };
921
925
  });
922
926
  }
927
+ // ── Portable workspaces: lock / restore ─────────────────────────────────────
928
+ /**
929
+ * Snapshot a workspace into a nemus.lock manifest (repos + branch + commit).
930
+ * Writes it to the workspace root by default and also returns the manifest so
931
+ * an agent can share/commit it.
932
+ */
933
+ async function handleLockWorkspace(workspace, output) {
934
+ return withStdoutProtection(async () => {
935
+ if (!workspace || workspace.trim().length === 0) {
936
+ throw new Error('Workspace name is required');
937
+ }
938
+ const workspacePath = (0, validation_1.safeWorkspacePath)((0, validation_1.sanitizeWorkspaceName)(workspace));
939
+ const metadata = await (0, workspace_meta_1.loadMetadata)(workspacePath);
940
+ if (!metadata) {
941
+ throw new Error(`Workspace not found: ${workspace}`);
942
+ }
943
+ const lock = await (0, workspace_lock_1.buildLock)(workspacePath, metadata);
944
+ const outPath = output ? path.resolve(output) : path.join(workspacePath, workspace_lock_1.LOCK_FILENAME);
945
+ await (0, workspace_lock_1.writeLock)(outPath, lock);
946
+ return {
947
+ workspace: metadata.workspaceName,
948
+ lockfilePath: outPath,
949
+ repoCount: lock.repositories.length,
950
+ lock,
951
+ };
952
+ });
953
+ }
954
+ /**
955
+ * Recreate a workspace from a nemus.lock. Accepts either inline `lockContent`
956
+ * (the manifest JSON) or a `lockfile` path (defaults to ./nemus.lock). Clones
957
+ * every repo and checks out the recorded branch (or exact commit with `pin`).
958
+ */
959
+ async function handleRestoreWorkspace(opts) {
960
+ return withStdoutProtection(async () => {
961
+ const lock = opts.lockContent
962
+ ? (0, workspace_lock_1.parseLock)(opts.lockContent)
963
+ : await (0, workspace_lock_1.readLockFile)(path.resolve(opts.lockfile || workspace_lock_1.LOCK_FILENAME));
964
+ const { workspaceName, workspacePath, results } = await (0, restore_1.restoreWorkspace)(lock, {
965
+ workspace: opts.workspace,
966
+ pin: opts.pin,
967
+ });
968
+ const cloned = results.filter(r => r.status === 'success');
969
+ const failed = results.filter(r => r.status === 'failed');
970
+ return {
971
+ workspace: workspaceName,
972
+ path: workspacePath,
973
+ cloned: cloned.length,
974
+ failed: failed.length,
975
+ repositories: results.map(r => ({
976
+ name: r.repo.name,
977
+ directoryName: r.directoryName,
978
+ status: r.status,
979
+ ...(r.error ? { error: r.error } : {}),
980
+ })),
981
+ };
982
+ });
983
+ }
package/dist/program.js CHANGED
@@ -95,6 +95,8 @@ const migrate_1 = require("./commands/migrate");
95
95
  const report_bug_1 = require("./commands/report-bug");
96
96
  const completion_1 = require("./commands/completion");
97
97
  const reflect_1 = require("./commands/reflect");
98
+ const lock_1 = require("./commands/lock");
99
+ const restore_1 = require("./commands/restore");
98
100
  (0, create_1.registerCreateCommand)(exports.program);
99
101
  (0, list_1.registerListCommand)(exports.program);
100
102
  (0, update_1.registerUpdateCommand)(exports.program);
@@ -122,6 +124,8 @@ const reflect_1 = require("./commands/reflect");
122
124
  (0, report_bug_1.registerReportBugCommand)(exports.program);
123
125
  (0, completion_1.registerCompletionCommand)(exports.program);
124
126
  (0, reflect_1.registerReflectCommand)(exports.program);
127
+ (0, lock_1.registerLockCommand)(exports.program);
128
+ (0, restore_1.registerRestoreCommand)(exports.program);
125
129
  // Register TUI (delegates to existing Ink/React implementation)
126
130
  exports.program
127
131
  .command('tui')