create-pmos 0.546.0 → 0.547.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-pmos",
3
- "version": "0.546.0",
3
+ "version": "0.547.0",
4
4
  "description": "Scaffold the PMOS portable kit — run the PMOS product-management workflow (initiative → lane-fit spec → contract → build → three gates, with work-type lanes for features, research, maintenance, incidents, and content) entirely inside your own repo, with all state as git-versioned files. Includes `workflow-sweep`, which audits the state every board derives from and separates real defects from work you simply have not done. `create-pmos workspace` also installs + launches the local Terminal Workspace GUI. No database, no network, no telemetry.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -32,6 +32,19 @@
32
32
  "audit"
33
33
  ],
34
34
  "pmosChanges": [
35
+ {
36
+ "v": "0.547.0",
37
+ "at": "2026-11-09T23:58:24.564Z",
38
+ "f": 4,
39
+ "prs": [
40
+ {
41
+ "n": 1275,
42
+ "t": "A Mac running PMOS keeps working unattended — minute check + Remote Control keeper",
43
+ "s": "A Mac running PMOS keeps working unattended — minute check + Remote Control keeper",
44
+ "k": "new"
45
+ }
46
+ ]
47
+ },
35
48
  {
36
49
  "v": "0.546.0",
37
50
  "at": "2026-11-09T15:25:03.150Z",
@@ -380,19 +393,6 @@
380
393
  "k": "fix"
381
394
  }
382
395
  ]
383
- },
384
- {
385
- "v": "0.527.0",
386
- "at": "2026-11-04T11:15:45.443Z",
387
- "f": 4,
388
- "prs": [
389
- {
390
- "n": 1237,
391
- "t": "Chat refinements keep drafting the open report",
392
- "s": "Chat refinements keep drafting the open report",
393
- "k": "fix"
394
- }
395
- ]
396
396
  }
397
397
  ]
398
398
  }
@@ -1,3 +1,3 @@
1
- kernel-source: pmos@e6b2ed40
1
+ kernel-source: pmos@6054bc9a
2
2
  assembled: 2026-11-09
3
3
  mode: vendor
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Eval calibration log"
4
4
  description: "Append-only record of every PM override of an evaluator verdict."
5
- generated: {by: process:create-pmos, at: "2026-11-09T15:25:00Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-09T23:58:21Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Health budgets"
4
4
  description: "Closed registry of health-budget anchors (D59), edited only by the PM."
5
- generated: {by: process:create-pmos, at: "2026-11-09T15:25:00Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-09T23:58:21Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Discoveries and friction log"
4
4
  description: "Append-only record of what runs discovered and where the process rubbed."
5
- generated: {by: process:create-pmos, at: "2026-11-09T15:25:00Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-09T23:58:21Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -33,7 +33,7 @@ pmos status # is it running? which sessions?
33
33
  pmos stop # shut it down (scrollback is preserved; sessions respawn next time)
34
34
  pmos doctor # diagnose the environment (node-pty arch, PTY spawn test, ports)
35
35
  ```
36
- **Without a terminal.** Mac and Windows setup creates a launcher and login item automatically. Windows gets a Start menu shortcut. To repair or change a launcher, `pmos launcher on` writes a PMOS app — `~/Applications/PMOS.app` on macOS, an app-menu entry on Linux — and a login item that starts the server at login without opening a browser. Both run `pmos up <repo>` with the PATH your terminal had at setup. `pmos launcher status` checks it, `pmos launcher off` removes it. Guide: [`guide/layout.md`](guide/layout.md).
36
+ **Without a terminal.** Mac and Windows setup creates a launcher and login item automatically. Windows gets a Start menu shortcut. To repair or change a launcher, `pmos launcher on` writes a PMOS app — `~/Applications/PMOS.app` on macOS, an app-menu entry on Linux — and a login item that starts the server at login without opening a browser (on macOS it checks every minute and restarts a stopped server; `--remote-control` also keeps `claude remote-control` running). Both run `pmos up <repo>` with the PATH your terminal had at setup. `pmos launcher status` checks it, `pmos launcher off` removes it. Guide: [`guide/layout.md`](guide/layout.md).
37
37
 
38
38
  **The port is found, not assumed.** A running server records the port it serves, so `pmos` in a second repo joins the workspace you already have open — whatever port it ended up on, and however it was started. If another program holds the default port (7433), `pmos` starts on the next free one and says so; `PMOS_WS_PORT=7500 pmos` pins it by hand. `pmos stop` shuts down every workspace server it finds, which is how you collapse two back into one.
39
39
 
@@ -50,6 +50,17 @@ const urlOf = (port) => `http://127.0.0.1:${port}`;
50
50
  // Tests set PMOS_NO_OPEN. `--no-open` is the login item's (`pmos launcher on`): a flag, not the env var, so the
51
51
  // server it starts does not hand PMOS_NO_OPEN to every session, where a `pmos` typed later would open nothing.
52
52
  const NO_OPEN = process.env.PMOS_NO_OPEN === '1' || process.argv.includes('--no-open');
53
+ // `--keep` is the login item's check, run by launchd every minute (`pmos launcher on`). It answers "is the workspace
54
+ // up, on this install's version?" and does nothing more when it is: it registers no repository, opens nothing and
55
+ // prints nothing. When no server answers (it crashed, or an update stopped it and did not bring it back) it starts
56
+ // one; when a server is stuck for a minute it stops that server and starts a new one. While an in-page update is
57
+ // running (its log was written in the last few minutes) it waits, because that update stops the server and starts
58
+ // the new one itself.
59
+ const KEEP = process.argv.includes('--keep');
60
+ const UPDATE_GRACE_MS = 5 * 60000;
61
+ function updateRunning(now = Date.now()) {
62
+ try { return now - fs.statSync(path.join(STATE, 'app-update.log')).mtimeMs < UPDATE_GRACE_MS; } catch { return false; }
63
+ }
53
64
 
54
65
  const say = (s) => console.log(s);
55
66
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
@@ -323,6 +334,11 @@ async function up(dir, { remote = false, open = true, waited = false } = {}) {
323
334
  }
324
335
  // 1. Is a workspace already running — on ANY port it recorded, not just the one this shell guesses?
325
336
  let live = await discover();
337
+ if (KEEP) {
338
+ if (live.some((l) => l.version === APP_VERSION)) return 0;
339
+ if (updateRunning()) return 0;
340
+ say(`${new Date().toISOString()} keep: ${live.length ? `the workspace runs ${live[0].version || 'an older version'}, this install is ${APP_VERSION}` : 'no workspace server answered'} — starting it`);
341
+ }
326
342
  // A server that predates this install is running OLD code under NEW files (or the reverse). Reusing
327
343
  // it is the failure behind "not found is not valid JSON": the page asks for routes that process
328
344
  // never learned. Sessions are tmux-backed, so replacing the server does not end them.
@@ -357,6 +373,12 @@ async function up(dir, { remote = false, open = true, waited = false } = {}) {
357
373
  const slow = waited ? [] : await busy();
358
374
  if (slow.length) {
359
375
  if (await waitForBusy(slow)) return up(dir, { remote, open, waited: true }); // re-run: it may be an older version
376
+ if (KEEP) {
377
+ // Unattended, nobody will read the advice below. A server that has not answered for a minute is stuck: replace it.
378
+ say(`${new Date().toISOString()} keep: the server on port ${slow[0].port} has not answered for a minute — restarting it`);
379
+ for (const b of slow) if (await stopOne(b.port)) return 1;
380
+ return up(dir, { remote, open, waited: true });
381
+ }
360
382
  say(`✗ the workspace server on port ${slow[0].port} (pid ${slow[0].pid}) is running but has not answered for a minute.`);
361
383
  say(' Run `pmos stop`, then `pmos` to restart it. If it happens again, run `pmos doctor` and send its output.');
362
384
  return 1;
@@ -1,4 +1,17 @@
1
1
  [
2
+ {
3
+ "v": "0.547.0",
4
+ "at": "2026-11-09T23:58:24.564Z",
5
+ "f": 4,
6
+ "prs": [
7
+ {
8
+ "n": 1275,
9
+ "t": "A Mac running PMOS keeps working unattended — minute check + Remote Control keeper",
10
+ "s": "A Mac running PMOS keeps working unattended — minute check + Remote Control keeper",
11
+ "k": "new"
12
+ }
13
+ ]
14
+ },
2
15
  {
3
16
  "v": "0.546.0",
4
17
  "at": "2026-11-09T15:25:03.150Z",
@@ -27,6 +27,16 @@ Mac and Windows setup creates the PMOS app and a login item automatically. [Layo
27
27
 
28
28
  Open a terminal in the repository you want. Type `pmos launcher on`. To choose another repository, add its path. Repeat this command after moving Node or the installed PMOS app.
29
29
 
30
+ #### Keep a Mac working when you are away
31
+
32
+ Type `pmos launcher on --profile=claude-personal --remote-control`. Use the name of your own Claude profile.
33
+
34
+ - The login item checks the server every minute. It starts the server again after a crash or an update that did not finish.
35
+ - `--profile=<id>` sets the Claude profile for unattended Claude work, the same as Settings → Claude.
36
+ - `--remote-control` keeps `claude remote-control` running under that profile in the tmux session `pmos-remote-control`. Claude can then reach this Mac when the Claude desktop app is closed. Type `tmux attach -t pmos-remote-control` to see it, and Ctrl-b d to leave it.
37
+
38
+ The Mac must stay awake and signed in. A later `pmos launcher on` without `--remote-control` keeps the Remote Control item. `pmos launcher off` removes it.
39
+
30
40
  To create only the app, use `pmos launcher on --no-login` on a fresh installation. To skip launcher creation during app activation, use `npx create-pmos@latest workspace --no-launcher`.
31
41
 
32
42
  Type `pmos launcher status` to check the launcher. The result names the repository, Node, PMOS and login item. A missing target means the launcher needs repair.
@@ -185,7 +185,7 @@ To change, repair or remove the launcher, use `pmos launcher on`, `pmos launcher
185
185
 
186
186
  ### Limits
187
187
 
188
- The login item starts the server once at login. Open the app if the server stops. Login does not enable remote access. Mac and Linux launcher output goes to `launcher.log` in the runtime state folder. Windows launchers run without a command window and use the server's normal logs.
188
+ On macOS the login item checks the server every minute. It starts the server when the server stops, and replaces a server that does not answer for a minute. It waits while an in-app update runs. On Linux the login item starts the server once at login. Open the app if the server stops. Login does not enable remote access. Mac and Linux launcher output goes to `launcher.log` in the runtime state folder. Windows launchers run without a command window and use the server's normal logs.
189
189
 
190
190
  ## Adler, Claude's face
191
191
 
@@ -9,7 +9,13 @@
9
9
  * opens the browser. The login item passes --no-open, so a login starts the server and opens nothing.
10
10
  *
11
11
  * macOS ~/Applications/PMOS.app Spotlight, Launchpad, drag it to the Dock
12
- * ~/Library/LaunchAgents/com.pmos.workspace.plist runs at login (RunAtLoad), once
12
+ * ~/Library/LaunchAgents/com.pmos.workspace.plist runs at login and then every minute: `pmos up --keep`
13
+ * starts the server when it is down (a crash, an update that
14
+ * did not bring it back) and does nothing when it is up
15
+ * ~/Library/LaunchAgents/com.pmos.remote-control.plist with --remote-control: keeps `claude remote-control`
16
+ * running in a tmux session named pmos-remote-control, so
17
+ * Claude can reach this Mac when the desktop app is closed.
18
+ * A later `on` without the flag leaves it; `off` removes it.
13
19
  * Linux $XDG_DATA_HOME/applications/pmos.desktop the app menu
14
20
  * $XDG_CONFIG_HOME/autostart/pmos-workspace.desktop
15
21
  *
@@ -18,6 +24,11 @@
18
24
  * `off` deletes a file only when it carries MARK, so a file of the same name that the PM wrote is left alone.
19
25
  * Windows uses a Start-menu shortcut and hidden Windows Script Host launchers, including a Startup entry.
20
26
  *
27
+ * --profile=<id> names the Claude profile unattended work runs under: Remote Control starts with that profile's
28
+ * CLAUDE_CONFIG_DIR, and the workspace's own Claude preference (prefs.json `claude`, Settings → Claude) is set to it.
29
+ * Only CLAUDE_CONFIG_DIR is written into a script. Any other variable a profile sets (a key, a proxy) is never written.
30
+ * On macOS `on` loads the LaunchAgents with launchctl at once, and `off` unloads them, so no logout is needed.
31
+ *
21
32
  * plan() is pure: every input is injected, so each platform's files are assertable from any machine.
22
33
  */
23
34
  const fs = require('fs');
@@ -29,9 +40,14 @@ const stateRoot = require('./state-root');
29
40
  const COMMANDS = { launcher: ['on', 'off', 'status'] };
30
41
  const MARK = 'pmos-launcher: written by `pmos launcher on`';
31
42
  const LABEL = 'com.pmos.workspace';
43
+ const RC_LABEL = 'com.pmos.remote-control';
44
+ const RC_SESSION = 'pmos-remote-control';
45
+ const KEEP_SECONDS = 60;
32
46
  const USAGE = [
33
47
  'usage: pmos launcher on|off|status — start the workspace without a terminal',
34
- ' pmos launcher on [<path>] [--no-login] a PMOS app for this repository, and a login item that starts the server',
48
+ ' pmos launcher on [<path>] [--no-login] a PMOS app for this repository, and a login item that keeps the server up',
49
+ ' --profile=<id> unattended Claude work uses this Claude profile (such as claude-personal)',
50
+ ' --remote-control macOS: keep `claude remote-control` running, so Claude reaches this Mac with the app closed',
35
51
  ' pmos launcher off remove the app and the login item',
36
52
  ' pmos launcher status what is installed, and for which repository',
37
53
  ];
@@ -54,9 +70,30 @@ function script({ node, bin, repo, pathEnv, log }) {
54
70
  ].join('\n');
55
71
  }
56
72
 
73
+ // The Remote Control keeper. launchd runs it every minute; it does nothing while the tmux session is there. Inside tmux,
74
+ // `claude remote-control` has the terminal it expects, and when it exits the session ends and the next minute starts it
75
+ // again. --permission-mode auto: nobody is at this Mac to answer a permission question.
76
+ function rcScript({ repo, pathEnv, log, configDir, name }) {
77
+ const inner = [
78
+ `PATH=${shq(pathEnv)}; export PATH;`,
79
+ ...(configDir ? [`CLAUDE_CONFIG_DIR=${shq(configDir)}; export CLAUDE_CONFIG_DIR;`] : []),
80
+ `exec claude remote-control --name ${shq(name)} --permission-mode auto`,
81
+ ].join(' ');
82
+ return [
83
+ '#!/bin/sh',
84
+ `# ${MARK} (workspace/lib/launcher-cli.js). \`pmos launcher off\` removes it.`,
85
+ `# It keeps \`claude remote-control\` running in the tmux session ${RC_SESSION}. \`tmux attach -t ${RC_SESSION}\` shows it.`,
86
+ `PATH=${shq(pathEnv)}; export PATH`,
87
+ `tmux has-session -t ${RC_SESSION} 2>/dev/null && exit 0`,
88
+ `echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) remote-control: starting" >>${shq(log)}`,
89
+ `exec tmux new-session -d -s ${RC_SESSION} -c ${shq(repo)} ${shq(inner)} >>${shq(log)} 2>&1`,
90
+ '',
91
+ ].join('\n');
92
+ }
93
+
57
94
  function plist(dict) {
58
95
  const v = (x) => Array.isArray(x) ? `<array>${x.map((s) => `<string>${xml(s)}</string>`).join('')}</array>`
59
- : typeof x === 'boolean' ? (x ? '<true/>' : '<false/>') : `<string>${xml(x)}</string>`;
96
+ : typeof x === 'boolean' ? (x ? '<true/>' : '<false/>') : typeof x === 'number' ? `<integer>${x}</integer>` : `<string>${xml(x)}</string>`;
60
97
  return [
61
98
  '<?xml version="1.0" encoding="UTF-8"?>',
62
99
  '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
@@ -80,7 +117,7 @@ function desktop(entries) {
80
117
  * → { files: [{ role: 'app'|'login', path, content, mode }], app, login } or { refused: '<reason>' }
81
118
  * `login: false` leaves the login item out.
82
119
  */
83
- function plan({ platform, home, env = {}, node, bin, repo, login = true }) {
120
+ function plan({ platform, home, env = {}, node, bin, repo, login = true, remoteControl = null }) {
84
121
  if (platform === 'win32') {
85
122
  const wp = path.win32;
86
123
  const appData = env.APPDATA || wp.join(home, 'AppData', 'Roaming');
@@ -110,6 +147,7 @@ function plan({ platform, home, env = {}, node, bin, repo, login = true }) {
110
147
  host: wp.join(env.SystemRoot || 'C:\\Windows', 'System32', 'wscript.exe') } };
111
148
  }
112
149
  if (platform !== 'darwin' && platform !== 'linux') return { refused: `no launcher is made for ${platform}. Start the workspace with \`pmos\`.` };
150
+ if (remoteControl && platform !== 'darwin') return { refused: '--remote-control is made for macOS only. Run `claude remote-control` in a terminal.' };
113
151
  const log = path.join(stateRoot.defaultRoot({ env, platform, home }), 'launcher.log');
114
152
  const body = script({ node, bin, repo, pathEnv: env.PATH || '/usr/bin:/bin', log });
115
153
  const files = [];
@@ -125,11 +163,25 @@ function plan({ platform, home, env = {}, node, bin, repo, login = true }) {
125
163
  }) });
126
164
  const agent = path.join(home, 'Library', 'LaunchAgents', `${LABEL}.plist`);
127
165
  if (login) files.push({ role: 'login', path: agent, mode: 0o644, content: plist({
128
- Label: LABEL, ProgramArguments: ['/bin/sh', exe, '--no-open'], RunAtLoad: true,
166
+ Label: LABEL, ProgramArguments: ['/bin/sh', exe, '--no-open', '--keep'], RunAtLoad: true,
167
+ // Every minute, not KeepAlive: `pmos up` detaches the server and exits, so launchd cannot watch the server itself.
168
+ StartInterval: KEEP_SECONDS,
129
169
  // `pmos up` detaches the server and exits; launchd must not reap the group it leaves behind.
130
170
  AbandonProcessGroup: true,
131
171
  }) });
132
- return { files, app: appDir, login: login ? agent : null, removable: [appDir, agent] };
172
+ const rcAgent = path.join(home, 'Library', 'LaunchAgents', `${RC_LABEL}.plist`);
173
+ const rcExe = path.join(appDir, 'Contents', 'MacOS', 'pmos-remote-control');
174
+ if (remoteControl) {
175
+ files.push({ role: 'app', path: rcExe, mode: 0o755, content: rcScript({ repo, pathEnv: env.PATH || '/usr/bin:/bin', log,
176
+ configDir: remoteControl.configDir || null, name: remoteControl.name || `${path.basename(repo)} (PMOS)` }) });
177
+ files.push({ role: 'remote-control', path: rcAgent, mode: 0o644, content: plist({
178
+ Label: RC_LABEL, ProgramArguments: ['/bin/sh', rcExe], RunAtLoad: true, StartInterval: KEEP_SECONDS,
179
+ // The tmux session outlives this script on purpose.
180
+ AbandonProcessGroup: true,
181
+ }) });
182
+ }
183
+ return { files, app: appDir, login: login ? agent : null, remoteControl: remoteControl ? rcAgent : null,
184
+ removable: [appDir, agent, rcAgent], agents: [[LABEL, agent], [RC_LABEL, rcAgent]] };
133
185
  }
134
186
  const data = env.XDG_DATA_HOME && path.isAbsolute(env.XDG_DATA_HOME) ? env.XDG_DATA_HOME : path.join(home, '.local', 'share');
135
187
  const conf = env.XDG_CONFIG_HOME && path.isAbsolute(env.XDG_CONFIG_HOME) ? env.XDG_CONFIG_HOME : path.join(home, '.config');
@@ -192,11 +244,56 @@ function shortcutAction(shortcut, action) {
192
244
  if (r.error || r.status !== 0) throw new Error(String(r.stderr || r.error || 'Could not manage PMOS shortcut').trim());
193
245
  }
194
246
 
247
+ // Load or unload one LaunchAgent in this user's GUI session, so a change takes effect without a logout. Best effort:
248
+ // the file on disk is what counts at the next login.
249
+ function launchctlAction(label, file, action, { uid = process.getuid ? process.getuid() : 0 } = {}) {
250
+ const domain = `gui/${uid}`;
251
+ spawnSync('launchctl', ['bootout', `${domain}/${label}`], { stdio: 'ignore' });
252
+ // The Remote Control keeper's tmux session outlives launchd's job: end it too, or the old profile keeps serving.
253
+ if (label === RC_LABEL && action !== 'load') spawnSync('tmux', ['kill-session', '-t', RC_SESSION], { stdio: 'ignore' });
254
+ if (action !== 'load') return { ok: true };
255
+ const r = spawnSync('launchctl', ['bootstrap', domain, file], { encoding: 'utf8' });
256
+ return r.status === 0 ? { ok: true } : { ok: false, error: String(r.stderr || r.error || `exit ${r.status}`).trim() };
257
+ }
258
+
259
+ // The Claude profile named by --profile=<id>: a descriptor or a detected profile (lib/profiles.js). Only its
260
+ // CLAUDE_CONFIG_DIR is used, and a profile that names Claude's own folder needs none.
261
+ function resolveProfile(id, home) {
262
+ const read = require('./profiles').readProfiles(home, { detect: true });
263
+ const p = (read.profiles || []).find((x) => x.id === id);
264
+ if (!p) {
265
+ const ids = (read.profiles || []).map((x) => x.id);
266
+ return { error: `no Claude profile named ${id}${ids.length ? ` (found: ${ids.join(', ')})` : ' was found'}` };
267
+ }
268
+ const dir = p.env && p.env.CLAUDE_CONFIG_DIR ? String(p.env.CLAUDE_CONFIG_DIR) : null;
269
+ const configDir = dir && !require('./claude-home').isDefaultDir(dir, home) ? dir : null;
270
+ const skipped = Object.keys(p.env || {}).filter((k) => k !== 'CLAUDE_CONFIG_DIR');
271
+ return { id: p.id, configDir, skipped };
272
+ }
273
+
274
+ // prefs.json `claude` is the profile every Claude call of the workspace starts under (Settings → Claude). Other keys stay.
275
+ function preferProfile(stateDir, id) {
276
+ const f = path.join(stateDir, 'prefs.json');
277
+ let prefs = {};
278
+ try { const o = JSON.parse(fs.readFileSync(f, 'utf8')); if (o && typeof o === 'object' && !Array.isArray(o)) prefs = o; } catch { /* none yet */ }
279
+ if (prefs.claude === id) return false;
280
+ prefs.claude = id;
281
+ fs.mkdirSync(stateDir, { recursive: true });
282
+ const tmp = `${f}.${process.pid}.tmp`;
283
+ fs.writeFileSync(tmp, JSON.stringify(prefs));
284
+ fs.renameSync(tmp, f);
285
+ return true;
286
+ }
287
+
195
288
  function run(argv, { say = console.log, platform = process.platform, home = os.homedir(), env = process.env,
196
- manageShortcut = shortcutAction, node = process.execPath, bin = path.join(__dirname, '..', 'bin', 'pmos.js'), cwd = process.cwd() } = {}) {
289
+ manageShortcut = shortcutAction, node = process.execPath, bin = path.join(__dirname, '..', 'bin', 'pmos.js'), cwd = process.cwd(),
290
+ launchctl = launchctlAction, hostname = os.hostname() } = {}) {
197
291
  const pos = argv.slice(1).filter((a) => !a.startsWith('--'));
198
- const flags = new Set(argv.slice(1).filter((a) => a.startsWith('--')).map((a) => a.slice(2)));
199
- const unknown = [...flags].filter((f) => f !== 'no-login' && f !== 'help');
292
+ const opts = {};
293
+ for (const a of argv.slice(1)) { const m = a.match(/^--([a-z-]+)=(.*)$/); if (m) opts[m[1]] = m[2]; }
294
+ const flags = new Set(argv.slice(1).filter((a) => a.startsWith('--') && !a.includes('=')).map((a) => a.slice(2)));
295
+ const unknown = [...flags].filter((f) => !['no-login', 'help', 'remote-control'].includes(f))
296
+ .concat(Object.keys(opts).filter((k) => k !== 'profile'));
200
297
  if (unknown.length) { say(`✗ unknown option --${unknown[0]}`); for (const l of USAGE) say(l); return 2; }
201
298
  const sub = pos[0];
202
299
  if (!sub || flags.has('help') || sub === 'help') { for (const l of USAGE) say(l); return sub ? 0 : 2; }
@@ -206,7 +303,14 @@ function run(argv, { say = console.log, platform = process.platform, home = os.h
206
303
  const dir = pos[1] ? path.resolve(cwd, pos[1]) : cwd;
207
304
  if (!fs.existsSync(dir)) { say(`✗ ${dir} does not exist`); return 1; }
208
305
  const repo = repoRootOf(dir);
209
- const p = plan({ platform, home, env, node, bin, repo, login: !flags.has('no-login') });
306
+ let profile = null;
307
+ if (opts.profile !== undefined) {
308
+ profile = resolveProfile(opts.profile, home);
309
+ if (profile.error) { say(`✗ ${profile.error}`); return 1; }
310
+ }
311
+ const remoteControl = flags.has('remote-control')
312
+ ? { configDir: profile ? profile.configDir : null, name: `${String(hostname).replace(/\.local$/, '')} (${path.basename(repo)})` } : null;
313
+ const p = plan({ platform, home, env, node, bin, repo, login: !flags.has('no-login'), remoteControl });
210
314
  if (p.refused) { say(`✗ ${p.refused}`); return 1; }
211
315
  // Never write over a file of the same name that the launcher did not write.
212
316
  const foreign = p.files.filter((f) => fs.existsSync(f.path) && !marked(f.path));
@@ -216,6 +320,10 @@ function run(argv, { say = console.log, platform = process.platform, home = os.h
216
320
  catch (e) { say(`✗ not written: ${e.message}`); return 1; }
217
321
  }
218
322
  fs.mkdirSync(stateRoot.defaultRoot({ env, platform, home }), { recursive: true });
323
+ // A keeper whose script changes (another profile, another repository) restarts its tmux session below.
324
+ const rcFile = p.files.find((f) => f.role === 'app' && f.path.endsWith('pmos-remote-control'));
325
+ let rcChanged = false;
326
+ if (rcFile) { try { rcChanged = readSource(rcFile.path) !== rcFile.content; } catch { rcChanged = false; } }
219
327
  for (const f of p.files) {
220
328
  fs.mkdirSync(path.dirname(f.path), { recursive: true });
221
329
  // WSH requires a UTF-16 BOM for paths containing non-ASCII characters.
@@ -231,9 +339,27 @@ function run(argv, { say = console.log, platform = process.platform, home = os.h
231
339
  say(` ${p.app}`);
232
340
  say(platform === 'darwin' ? ' Open it from Spotlight or Launchpad, or drag it to the Dock.' : platform === 'win32' ? ' Open Start and choose PMOS.' : ' Open it from the app menu.');
233
341
  if (p.login) {
234
- say('✓ login item: the workspace server starts when you log in, without a browser window');
342
+ say('✓ login item: the workspace server starts when you log in, and starts again within a minute if it stops');
235
343
  say(` ${p.login}`);
236
344
  } else say(' no login item (--no-login): the server starts when you open the app');
345
+ if (profile) {
346
+ if (preferProfile(stateRoot.defaultRoot({ env, platform, home }), profile.id)) say(`✓ Claude profile: the workspace's Claude work now runs as ${profile.id}`);
347
+ else say(`✓ Claude profile: ${profile.id} (already chosen)`);
348
+ if (profile.skipped.length) say(` only CLAUDE_CONFIG_DIR is used here; ${profile.skipped.join(', ')} from the profile is not written to any file`);
349
+ }
350
+ if (p.remoteControl) {
351
+ say(`✓ Remote Control: \`claude remote-control\`${profile ? ` as ${profile.id}` : ''} runs in tmux session ${RC_SESSION}, and starts again within a minute if it stops`);
352
+ say(` ${p.remoteControl}`);
353
+ say(` To see it: tmux attach -t ${RC_SESSION} (leave it with Ctrl-b d)`);
354
+ }
355
+ if (platform === 'darwin') {
356
+ for (const [label, file] of p.agents) {
357
+ if (!fs.existsSync(file) || !p.files.some((f) => f.path === file)) continue;
358
+ if (label === RC_LABEL && rcChanged) launchctl(label, file, 'unload');
359
+ const r = launchctl(label, file, 'load');
360
+ if (!r.ok) say(`· ${label} starts at the next login (launchctl: ${r.error})`);
361
+ }
362
+ }
237
363
  say(' The app opens the browser on the running workspace and starts the server when none runs.');
238
364
  say(' If you move or upgrade node, run `pmos launcher on` again.');
239
365
  return 0;
@@ -244,6 +370,7 @@ function run(argv, { say = console.log, platform = process.platform, home = os.h
244
370
 
245
371
  if (sub === 'off') {
246
372
  let removed = 0;
373
+ if (platform === 'darwin' && p.agents) for (const [label, file] of p.agents) if (fs.existsSync(file) && marked(file)) launchctl(label, file, 'unload');
247
374
  if (p.shortcut && fs.existsSync(p.shortcut.path)) {
248
375
  try { manageShortcut(p.shortcut, 'remove'); say(`✓ removed ${p.shortcut.path}`); removed++; }
249
376
  catch (e) { say(`· left ${p.shortcut.path}: ${e.message}`); }
@@ -276,7 +403,14 @@ function run(argv, { say = console.log, platform = process.platform, home = os.h
276
403
  say(` node: ${t.node}${fs.existsSync(t.node) ? '' : ' ✗ not found — run `pmos launcher on` again'}`);
277
404
  say(` pmos: ${t.bin}${fs.existsSync(t.bin) ? '' : ' ✗ not found — run `pmos launcher on` again'}`);
278
405
  say(login ? `✓ login item — ${loginPath}` : '○ no login item: the server starts when you open the app');
279
- return [t.repo, t.node, t.bin].every((x) => fs.existsSync(x)) ? 0 : 1;
406
+ // A macOS login item from before the minute check runs once at login only. Exit 1, so setup writes it again.
407
+ const oldLogin = login && platform === 'darwin' && !readSource(loginPath).includes('<string>--keep</string>');
408
+ if (oldLogin) say('✗ the login item starts the server at login only — run `pmos launcher on` again so it restarts a stopped server');
409
+ if (p.remoteControl === null && p.agents) {
410
+ const rc = p.agents.find(([l]) => l === RC_LABEL)[1];
411
+ if (fs.existsSync(rc) && marked(rc)) say(`✓ Remote Control keeper — ${rc} (tmux attach -t ${RC_SESSION})`);
412
+ }
413
+ return [t.repo, t.node, t.bin].every((x) => fs.existsSync(x)) && !oldLogin ? 0 : 1;
280
414
  }
281
415
 
282
- module.exports = { run, plan, readTarget, COMMANDS, USAGE, MARK };
416
+ module.exports = { run, plan, readTarget, resolveProfile, preferProfile, COMMANDS, USAGE, MARK, RC_SESSION };
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.546.0",
3
+ "version": "0.547.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.546.0",
9
+ "version": "0.547.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@anthropic-ai/sdk": "^1.3.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.546.0",
3
+ "version": "0.547.0",
4
4
  "private": true,
5
5
  "description": "PMOS Terminal Workspace — local companion hosting real PTYs beside the library and gates (D62)",
6
6
  "license": "MIT",