create-pmos 0.473.0 → 0.475.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/README.md +5 -3
- package/bin/create-pmos.js +23 -1
- package/install.ps1 +2 -1
- package/install.sh +6 -1
- package/package.json +27 -27
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/workspace/README.md +1 -1
- package/workspace/bin/pmos.js +1 -1
- package/workspace/changelog.json +26 -0
- package/workspace/fixtures/fake-claude-onboard.js +48 -0
- package/workspace/guide/briefing-premium.md +2 -7
- package/workspace/guide/index.md +2 -2
- package/workspace/guide/launcher.md +14 -32
- package/workspace/guide/layout.md +1 -1
- package/workspace/guide/published-board.md +1 -1
- package/workspace/guide/settings.md +3 -3
- package/workspace/guide/welcome.md +64 -21
- package/workspace/lib/claude-readiness.js +143 -0
- package/workspace/lib/engine/calendar-import.js +5 -0
- package/workspace/lib/freshness.js +5 -3
- package/workspace/lib/launcher-cli.js +83 -8
- package/workspace/lib/onboarding-progress.js +36 -0
- package/workspace/lib/project-onboard.js +363 -0
- package/workspace/lib/route-modules.js +2 -0
- package/workspace/lib/routes-onboard.js +188 -0
- package/workspace/lib/routes-onboarding.js +5 -4
- package/workspace/lib/routes-setup.js +88 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/project-onboard-flow-test.js +135 -0
- package/workspace/public/pm/cozy-claude-setup.js +90 -0
- package/workspace/public/pm/cozy-onboard.css +60 -0
- package/workspace/public/pm/cozy-onboard.js +226 -0
- package/workspace/public/pm/cozy-settings.js +8 -2
- package/workspace/public/pm/home-app.js +10 -0
- package/workspace/public/pm/premium-first.js +1 -1
- package/workspace/public/pm/premium-welcome-model.js +1 -1
- package/workspace/public/pm/premium-welcome.js +107 -62
- package/workspace/public/pm/premium.css +16 -0
- package/workspace/public/pm/readonly.js +1 -1
- package/workspace/public/pm/setup-checklist.js +22 -0
- package/workspace/public/premium.html +1 -0
- package/workspace/server.js +28 -6
- package/workspace/skills/calendar-sync.skill +1 -1
- package/workspace/test-files.json +6 -3
- package/workspace/test-lists/briefing-premium.json +1 -3
- package/workspace/test-lists/claude-onboarding-build.json +9 -0
- package/workspace/premium-welcome-test.js +0 -219
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Explicit Claude verification. No credentials or CLI output are returned or persisted.
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
const crypto = require('crypto');
|
|
7
|
+
const cp = require('child_process');
|
|
8
|
+
const win = require('./win-command');
|
|
9
|
+
const DEFAULT = '__default__';
|
|
10
|
+
const PROMPT = 'Reply with exactly PMOS_READY. Do not use tools.';
|
|
11
|
+
const FLAGS = ['--safe-mode', '--tools', '--strict-mcp-config', '--mcp-config', '--disable-slash-commands', '--no-session-persistence', '--output-format'];
|
|
12
|
+
const MESSAGES = {
|
|
13
|
+
unchecked: 'Claude access has not been checked.', ready: 'Claude is ready.',
|
|
14
|
+
signed_out: 'Sign in to this Claude setup, then check again.',
|
|
15
|
+
network: 'Could not reach Claude. Check your connection and try again.',
|
|
16
|
+
account: 'Claude could not accept the request. Review account access or usage, then try again.',
|
|
17
|
+
missing_cli: 'Claude Code was not found. Repair its installation, then try again.',
|
|
18
|
+
unsupported: 'This Claude installation cannot run an isolated check. Update Claude Code, then try again.',
|
|
19
|
+
unknown: 'Claude access could not be verified. Open this profile’s sign-in session and try again.',
|
|
20
|
+
profile_missing: 'The selected Claude profile is unavailable. Choose a profile explicitly.',
|
|
21
|
+
changed: 'The Claude setup changed during the check. Check again before using it.',
|
|
22
|
+
save_failed: 'Claude works, but PMOS could not save this choice. Check and use it again.',
|
|
23
|
+
};
|
|
24
|
+
function classify(error, output = '') {
|
|
25
|
+
const s = String(output);
|
|
26
|
+
if (error && error.code === 'ENOENT') return 'missing_cli';
|
|
27
|
+
if (/oauth.*expired|not logged in|please.*\/login|authentication_error|failed to authenticate|invalid.*(?:api key|token)|401/i.test(s)) return 'signed_out';
|
|
28
|
+
if (/credit|billing|usage limit|rate.limit|quota|overloaded|429|403/i.test(s)) return 'account';
|
|
29
|
+
if ((error && (error.killed || /ETIMEDOUT|ENET|ECONN/.test(String(error.code)))) || /ENOTFOUND|fetch failed|network|connection.*(?:failed|refused)|timed out|unreachable/i.test(s)) return 'network';
|
|
30
|
+
return 'unknown';
|
|
31
|
+
}
|
|
32
|
+
function exec(file, args, opts) {
|
|
33
|
+
return new Promise((resolve) => cp.execFile(file, args, { ...opts, encoding: 'utf8', windowsHide: true, maxBuffer: 128 * 1024 }, (error, stdout, stderr) => resolve({ error, stdout: stdout || '', stderr: stderr || '' })));
|
|
34
|
+
}
|
|
35
|
+
function executable(env) {
|
|
36
|
+
if (process.platform === 'win32') return win.resolve('claude', { env });
|
|
37
|
+
const file = String(env.PATH || '').split(path.delimiter).map(d => path.join(d, 'claude')).find(f => { try { fs.accessSync(f, fs.constants.X_OK); return fs.statSync(f).isFile(); } catch { return false; } });
|
|
38
|
+
return { file: file || 'claude', prefix: [] };
|
|
39
|
+
}
|
|
40
|
+
function stamp(f) { try { const s = fs.statSync(f); return [s.mtimeMs, s.size]; } catch { return null; } }
|
|
41
|
+
function atomic(file, value) {
|
|
42
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
43
|
+
if (fs.existsSync(file) && fs.lstatSync(file).isSymbolicLink()) throw new Error('symlink');
|
|
44
|
+
const temp = file + '.' + crypto.randomBytes(6).toString('hex') + '.tmp';
|
|
45
|
+
try { fs.writeFileSync(temp, JSON.stringify(value) + '\n', { mode: 0o600, flag: 'wx' }); fs.renameSync(temp, file); }
|
|
46
|
+
finally { try { fs.unlinkSync(temp); } catch {} }
|
|
47
|
+
}
|
|
48
|
+
function create({ stateDir, home = os.homedir(), readProfiles, readPrefs, savePreference, envFor, run = exec, resolveExecutable = executable, now = Date.now }) {
|
|
49
|
+
const file = path.join(stateDir, 'claude-readiness.json');
|
|
50
|
+
const boot = crypto.randomBytes(12).toString('hex');
|
|
51
|
+
let running = null;
|
|
52
|
+
const records = () => { try { return JSON.parse(fs.readFileSync(file, 'utf8')); } catch { return {}; } };
|
|
53
|
+
const selected = () => readPrefs().claude || DEFAULT;
|
|
54
|
+
function candidate(id = selected()) {
|
|
55
|
+
if (typeof id !== 'string' || !/^[a-zA-Z0-9_.-]{1,80}$/.test(id)) return null;
|
|
56
|
+
if (id === DEFAULT) return { id, label: 'My usual Claude login', env: { CLAUDE_CONFIG_DIR: path.resolve(envFor(null).CLAUDE_CONFIG_DIR || path.join(home, '.claude')) } };
|
|
57
|
+
return (readProfiles().profiles || []).find(p => p.id === id) || null;
|
|
58
|
+
}
|
|
59
|
+
function binding(p) {
|
|
60
|
+
const env = envFor(p);
|
|
61
|
+
const command = resolveExecutable(env);
|
|
62
|
+
const dir = path.resolve(env.CLAUDE_CONFIG_DIR || path.join(home, '.claude'));
|
|
63
|
+
const authNames = ['ANTHROPIC_API_KEY', 'ANTHROPIC_AUTH_TOKEN', 'ANTHROPIC_BASE_URL', 'CLAUDE_CODE_USE_BEDROCK', 'CLAUDE_CODE_USE_VERTEX', 'CLAUDE_CODE_USE_FOUNDRY'];
|
|
64
|
+
const input = { command, executable: stamp(command.file), env: Object.entries(p.env || {}).sort(), dir,
|
|
65
|
+
auth: authNames.map(k => [k, env[k] || '']), config: ['settings.json', '.claude.json', '.credentials.json'].map(n => stamp(path.join(dir, n))) };
|
|
66
|
+
return { env, command, fingerprint: crypto.createHash('sha256').update(JSON.stringify(input)).digest('hex') };
|
|
67
|
+
}
|
|
68
|
+
function status(id = selected()) {
|
|
69
|
+
const p = candidate(id);
|
|
70
|
+
if (!p) return { state: 'profile_missing', message: MESSAGES.profile_missing, profile: id, ready: false };
|
|
71
|
+
const r = records()[id];
|
|
72
|
+
const current = binding(p).fingerprint;
|
|
73
|
+
const valid = r && r.boot === boot && r.fingerprint === current && now() - Date.parse(r.checked_at) < 15 * 60 * 1000;
|
|
74
|
+
const state = valid ? r.state : 'unchecked';
|
|
75
|
+
return { state, message: MESSAGES[state] || MESSAGES.unknown, profile: id, label: p.label || id, checked_at: r && r.checked_at || null, ready: state === 'ready' && selected() === id };
|
|
76
|
+
}
|
|
77
|
+
function list() {
|
|
78
|
+
const read = readProfiles();
|
|
79
|
+
return { ok: true, selected: selected(), status: status(), profiles: [candidate(DEFAULT), ...(read.profiles || [])].map(p => ({ id: p.id, label: p.label || p.id })), broken: (read.broken || []).map(b => ({ file: b.file })), discovery_failed: read.ok === false };
|
|
80
|
+
}
|
|
81
|
+
function pinDefault(p) {
|
|
82
|
+
if (p.id !== DEFAULT) return p.id;
|
|
83
|
+
const id = 'pmos-usual';
|
|
84
|
+
const target = path.join(home, '.claude', 'profiles', id + '.json');
|
|
85
|
+
const exists = candidate(id);
|
|
86
|
+
if (exists) {
|
|
87
|
+
if (binding(exists).fingerprint !== binding({ ...p, id }).fingerprint) throw new Error('profile name in use');
|
|
88
|
+
return id;
|
|
89
|
+
}
|
|
90
|
+
fs.mkdirSync(path.dirname(target), { recursive: true, mode: 0o700 });
|
|
91
|
+
fs.writeFileSync(target, JSON.stringify({ id, label: p.label, env: p.env }) + '\n', { flag: 'wx', mode: 0o600 });
|
|
92
|
+
return id;
|
|
93
|
+
}
|
|
94
|
+
async function perform(id) {
|
|
95
|
+
const p = candidate(id);
|
|
96
|
+
if (!p) return { ok: false, ...status(id) };
|
|
97
|
+
const before = binding(p), preference = selected();
|
|
98
|
+
let state = 'unknown', scratch;
|
|
99
|
+
try {
|
|
100
|
+
// Arbitrary .cmd wrappers need a shell; refuse them rather than weakening argument isolation.
|
|
101
|
+
if (before.command.prefix.includes('/c')) state = 'unsupported';
|
|
102
|
+
else {
|
|
103
|
+
scratch = fs.mkdtempSync(path.join(os.tmpdir(), 'pmos-claude-check-'));
|
|
104
|
+
const opts = { env: before.env, cwd: scratch, timeout: 10000 };
|
|
105
|
+
const help = await run(before.command.file, [...before.command.prefix, '--help'], opts);
|
|
106
|
+
if (help.error) state = classify(help.error, help.stderr);
|
|
107
|
+
else if (!FLAGS.every(f => help.stdout.includes(f))) state = 'unsupported';
|
|
108
|
+
else {
|
|
109
|
+
const r = await run(before.command.file, [...before.command.prefix, '-p', PROMPT, '--safe-mode', '--tools', '', '--strict-mcp-config', '--mcp-config', '{"mcpServers":{}}', '--disable-slash-commands', '--no-session-persistence', '--output-format', 'json'], { ...opts, timeout: 45000 });
|
|
110
|
+
let result; try { result = JSON.parse(r.stdout); } catch {}
|
|
111
|
+
state = !r.error && result && !result.is_error && String(result.result || '').trim() === 'PMOS_READY' ? 'ready' : classify(r.error, r.stdout + r.stderr);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (!candidate(id) || binding(candidate(id)).fingerprint !== before.fingerprint || selected() !== preference) state = 'changed';
|
|
115
|
+
let savedId = id;
|
|
116
|
+
if (state === 'ready') {
|
|
117
|
+
try { savedId = pinDefault(p); const e = savePreference(savedId); if (e) throw new Error('preference'); }
|
|
118
|
+
catch { state = 'save_failed'; }
|
|
119
|
+
}
|
|
120
|
+
const record = { state, checked_at: new Date(now()).toISOString(), fingerprint: before.fingerprint, boot };
|
|
121
|
+
try { atomic(file, { ...records(), [savedId]: record }); } catch { state = 'save_failed'; }
|
|
122
|
+
return { ok: state === 'ready', state, message: MESSAGES[state], profile: savedId, checked_at: record.checked_at, ready: state === 'ready' };
|
|
123
|
+
} finally { if (scratch) fs.rmSync(scratch, { recursive: true, force: true }); }
|
|
124
|
+
}
|
|
125
|
+
function check(id) {
|
|
126
|
+
if (running) return running.id === id ? running.promise : Promise.resolve({ ok: false, state: 'busy', message: 'Another profile check is running.' });
|
|
127
|
+
const promise = perform(id).finally(() => { running = null; });
|
|
128
|
+
running = { id, promise }; return promise;
|
|
129
|
+
}
|
|
130
|
+
function invalidate(id) {
|
|
131
|
+
id = id || selected(); const r = records();
|
|
132
|
+
if (r[id]) { r[id].state = 'signed_out'; try { atomic(file, r); } catch {} }
|
|
133
|
+
}
|
|
134
|
+
/** The verified binding of a profile: env and executable, only while its last check is valid and ready. Nothing else may run Claude for onboarding. */
|
|
135
|
+
function bound(id = selected()) {
|
|
136
|
+
const st = status(id);
|
|
137
|
+
if (st.state !== 'ready') return null;
|
|
138
|
+
const b = binding(candidate(id));
|
|
139
|
+
return { id, env: b.env, command: b.command, fingerprint: b.fingerprint };
|
|
140
|
+
}
|
|
141
|
+
return { list, status, selected, candidate, check, pinDefault, invalidate, bound };
|
|
142
|
+
}
|
|
143
|
+
module.exports = { create, classify, DEFAULT, FLAGS, MESSAGES };
|
|
@@ -91,6 +91,11 @@ function appendImport(file, events, actor, now, opts = {}) {
|
|
|
91
91
|
const at = now || new Date().toISOString();
|
|
92
92
|
const lines = events.map((event) => L.append(file, { id: L.newId(), kind: 'calendar_event', why: 'calendar import (reported, untrusted)', at, event }, actor));
|
|
93
93
|
for (const event_id of gone) lines.push(L.append(file, { id: L.newId(), kind: 'calendar_event_removed', why: 'not in the import for its days (rescheduled, declined or cancelled)', at, event_id }, actor));
|
|
94
|
+
// Record successful empty reads too, without retracting previously saved meetings.
|
|
95
|
+
const receipt = path.join(path.dirname(file), 'read.json');
|
|
96
|
+
const temp = receipt + '.' + require('crypto').randomBytes(6).toString('hex') + '.tmp';
|
|
97
|
+
try { fs.writeFileSync(temp, JSON.stringify({ fetched_at: at, count: events.length, by: actor && actor.by }) + '\n', { mode: 0o600, flag: 'wx' }); fs.renameSync(temp, receipt); }
|
|
98
|
+
finally { try { fs.unlinkSync(temp); } catch {} }
|
|
94
99
|
return lines;
|
|
95
100
|
}
|
|
96
101
|
|
|
@@ -53,14 +53,16 @@ const readJson = (f, dflt) => { try { return JSON.parse(fs.readFileSync(f, 'utf8
|
|
|
53
53
|
// ledger is megabytes.
|
|
54
54
|
const calSeen = new Map(); // file -> { sig, best }
|
|
55
55
|
function calendarAsOf(stateDir) {
|
|
56
|
+
const receipt = readJson(path.join(stateDir, 'calendar-import', 'read.json'), null);
|
|
57
|
+
const readAt = receipt && Date.parse(receipt.fetched_at) || 0;
|
|
56
58
|
const f = path.join(stateDir, 'calendar-import', 'events.jsonl');
|
|
57
|
-
let st; try { st = fs.statSync(f); } catch { calSeen.delete(f); return
|
|
59
|
+
let st; try { st = fs.statSync(f); } catch { calSeen.delete(f); return readAt; }
|
|
58
60
|
const sig = st.size + ':' + st.mtimeMs + ':' + st.ino;
|
|
59
61
|
const hit = calSeen.get(f);
|
|
60
|
-
if (hit && hit.sig === sig) return hit.best;
|
|
62
|
+
if (hit && hit.sig === sig) return Math.max(hit.best, readAt);
|
|
61
63
|
const best = calendarAsOfText(f);
|
|
62
64
|
calSeen.set(f, { sig, best });
|
|
63
|
-
return best;
|
|
65
|
+
return Math.max(best, readAt);
|
|
64
66
|
}
|
|
65
67
|
function calendarAsOfText(f) {
|
|
66
68
|
let text = '';
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* A file started by the desktop has no shell profile, so the PATH of the terminal that ran `on` is written into the
|
|
17
17
|
* script; that is how `claude`, `git` and `tmux` resolve. It never starts remote (tailnet) mode and writes no token.
|
|
18
18
|
* `off` deletes a file only when it carries MARK, so a file of the same name that the PM wrote is left alone.
|
|
19
|
-
* Windows
|
|
19
|
+
* Windows uses a Start-menu shortcut and hidden Windows Script Host launchers, including a Startup entry.
|
|
20
20
|
*
|
|
21
21
|
* plan() is pure: every input is injected, so each platform's files are assertable from any machine.
|
|
22
22
|
*/
|
|
@@ -81,7 +81,34 @@ function desktop(entries) {
|
|
|
81
81
|
* `login: false` leaves the login item out.
|
|
82
82
|
*/
|
|
83
83
|
function plan({ platform, home, env = {}, node, bin, repo, login = true }) {
|
|
84
|
-
if (platform === 'win32')
|
|
84
|
+
if (platform === 'win32') {
|
|
85
|
+
const wp = path.win32;
|
|
86
|
+
const appData = env.APPDATA || wp.join(home, 'AppData', 'Roaming');
|
|
87
|
+
const local = env.LOCALAPPDATA || wp.join(home, 'AppData', 'Local');
|
|
88
|
+
const programs = wp.join(appData, 'Microsoft', 'Windows', 'Start Menu', 'Programs');
|
|
89
|
+
const exe = wp.join(local, 'PMOS', 'launcher', 'pmos-launch.vbs');
|
|
90
|
+
const auto = wp.join(programs, 'Startup', 'PMOS.vbs');
|
|
91
|
+
const app = wp.join(programs, 'PMOS.lnk');
|
|
92
|
+
const vbs = (s) => '"' + String(s).replace(/"/g, '""') + '"';
|
|
93
|
+
// Quote Windows argv before quoting the resulting command as a VBScript string.
|
|
94
|
+
const arg = (s) => '"' + String(s).replace(/(\\*)"/g, '$1$1\\"').replace(/(\\+)$/g, '$1$1') + '"';
|
|
95
|
+
const body = (noOpen) => [
|
|
96
|
+
`' ${MARK}`,
|
|
97
|
+
`' pmos-target: ${JSON.stringify({ node, bin, repo })}`,
|
|
98
|
+
'Option Explicit',
|
|
99
|
+
'Dim shell',
|
|
100
|
+
'Set shell = CreateObject("WScript.Shell")',
|
|
101
|
+
`shell.Environment("PROCESS")("PATH") = ${vbs(env.PATH || env.Path || '')}`,
|
|
102
|
+
// Portable Git's bash location is needed when launched outside the setup shell.
|
|
103
|
+
...(env.CLAUDE_CODE_GIT_BASH_PATH ? [`shell.Environment("PROCESS")("CLAUDE_CODE_GIT_BASH_PATH") = ${vbs(env.CLAUDE_CODE_GIT_BASH_PATH)}`] : []),
|
|
104
|
+
`shell.Run ${vbs([node, bin, 'up', repo, ...(noOpen ? ['--no-open'] : [])].map(arg).join(' '))}, 0, False`,
|
|
105
|
+
'',
|
|
106
|
+
].join('\r\n');
|
|
107
|
+
const files = [{ role: 'app', path: exe, content: body(false), mode: 0o755 }];
|
|
108
|
+
if (login) files.push({ role: 'login', path: auto, content: body(true), mode: 0o644 });
|
|
109
|
+
return { files, app, login: login ? auto : null, removable: [exe, auto], shortcut: { path: app, script: exe,
|
|
110
|
+
host: wp.join(env.SystemRoot || 'C:\\Windows', 'System32', 'wscript.exe') } };
|
|
111
|
+
}
|
|
85
112
|
if (platform !== 'darwin' && platform !== 'linux') return { refused: `no launcher is made for ${platform}. Start the workspace with \`pmos\`.` };
|
|
86
113
|
const log = path.join(stateRoot.defaultRoot({ env, platform, home }), 'launcher.log');
|
|
87
114
|
const body = script({ node, bin, repo, pathEnv: env.PATH || '/usr/bin:/bin', log });
|
|
@@ -119,7 +146,11 @@ function plan({ platform, home, env = {}, node, bin, repo, login = true }) {
|
|
|
119
146
|
return { files, app, login: login ? auto : null, removable: [exe, app, auto] };
|
|
120
147
|
}
|
|
121
148
|
|
|
122
|
-
const
|
|
149
|
+
const readSource = (f) => {
|
|
150
|
+
const bytes = fs.readFileSync(f);
|
|
151
|
+
return bytes[0] === 0xff && bytes[1] === 0xfe ? bytes.subarray(2).toString('utf16le') : bytes.toString('utf8');
|
|
152
|
+
};
|
|
153
|
+
const marked = (f) => { try { return readSource(f).includes(MARK); } catch { return false; } };
|
|
123
154
|
// The file under a removable path that carries the mark: the bundle's script for a .app, else the path itself.
|
|
124
155
|
const markFile = (p) => p.endsWith('.app') ? path.join(p, 'Contents', 'MacOS', 'pmos-launch') : p;
|
|
125
156
|
|
|
@@ -131,15 +162,38 @@ function repoRootOf(dir) {
|
|
|
131
162
|
// What the installed script points at: the repository and whether node and pmos.js still exist.
|
|
132
163
|
function readTarget(exe) {
|
|
133
164
|
let src = '';
|
|
134
|
-
try { src =
|
|
165
|
+
try { src = readSource(exe); } catch { return null; }
|
|
166
|
+
const target = src.match(/^' pmos-target: (.+)$/m);
|
|
167
|
+
if (target) {
|
|
168
|
+
try { const t = JSON.parse(target[1]); return ['node', 'bin', 'repo'].every((k) => typeof t[k] === 'string') ? t : null; }
|
|
169
|
+
catch { return null; }
|
|
170
|
+
}
|
|
135
171
|
const m = src.match(/^exec '((?:[^']|'\\'')*)' '((?:[^']|'\\'')*)' up '((?:[^']|'\\'')*)'/m);
|
|
136
172
|
if (!m) return null;
|
|
137
173
|
const un = (s) => s.replace(/'\\''/g, "'");
|
|
138
174
|
return { node: un(m[1]), bin: un(m[2]), repo: un(m[3]) };
|
|
139
175
|
}
|
|
140
176
|
|
|
177
|
+
// Inspect shortcuts before replacing/removing them. A shortcut is ours only when its target and arguments match.
|
|
178
|
+
function shortcutAction(shortcut, action) {
|
|
179
|
+
const psq = (s) => "'" + String(s).replace(/'/g, "''") + "'";
|
|
180
|
+
const code = [
|
|
181
|
+
'$ErrorActionPreference = "Stop"',
|
|
182
|
+
`$file = ${psq(shortcut.path)}`,
|
|
183
|
+
'$shell = New-Object -ComObject WScript.Shell',
|
|
184
|
+
'$link = $shell.CreateShortcut($file)',
|
|
185
|
+
`$target = ${psq(shortcut.host)}`,
|
|
186
|
+
`$arguments = ${psq('"' + shortcut.script + '"')}`,
|
|
187
|
+
'if ((Test-Path -LiteralPath $file) -and (($link.TargetPath -ine $target) -or ($link.Arguments -cne $arguments))) { throw "PMOS shortcut belongs to another application" }',
|
|
188
|
+
...(action === 'write' ? ['$link.TargetPath = $target', '$link.Arguments = $arguments', '$link.WindowStyle = 7', '$link.Description = "Open PMOS"', '$link.Save()']
|
|
189
|
+
: action === 'remove' ? ['if (Test-Path -LiteralPath $file) { Remove-Item -LiteralPath $file }'] : []),
|
|
190
|
+
].join('\n');
|
|
191
|
+
const r = spawnSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-EncodedCommand', Buffer.from(code, 'utf16le').toString('base64')], { encoding: 'utf8', windowsHide: true });
|
|
192
|
+
if (r.error || r.status !== 0) throw new Error(String(r.stderr || r.error || 'Could not manage PMOS shortcut').trim());
|
|
193
|
+
}
|
|
194
|
+
|
|
141
195
|
function run(argv, { say = console.log, platform = process.platform, home = os.homedir(), env = process.env,
|
|
142
|
-
node = process.execPath, bin = path.join(__dirname, '..', 'bin', 'pmos.js'), cwd = process.cwd() } = {}) {
|
|
196
|
+
manageShortcut = shortcutAction, node = process.execPath, bin = path.join(__dirname, '..', 'bin', 'pmos.js'), cwd = process.cwd() } = {}) {
|
|
143
197
|
const pos = argv.slice(1).filter((a) => !a.startsWith('--'));
|
|
144
198
|
const flags = new Set(argv.slice(1).filter((a) => a.startsWith('--')).map((a) => a.slice(2)));
|
|
145
199
|
const unknown = [...flags].filter((f) => f !== 'no-login' && f !== 'help');
|
|
@@ -157,14 +211,25 @@ function run(argv, { say = console.log, platform = process.platform, home = os.h
|
|
|
157
211
|
// Never write over a file of the same name that the launcher did not write.
|
|
158
212
|
const foreign = p.files.filter((f) => fs.existsSync(f.path) && !marked(f.path));
|
|
159
213
|
if (foreign.length) { say(`✗ not written: ${foreign.map((f) => f.path).join(', ')} exists and was not written by pmos launcher`); return 1; }
|
|
214
|
+
if (p.shortcut) {
|
|
215
|
+
try { manageShortcut(p.shortcut, 'check'); }
|
|
216
|
+
catch (e) { say(`✗ not written: ${e.message}`); return 1; }
|
|
217
|
+
}
|
|
218
|
+
fs.mkdirSync(stateRoot.defaultRoot({ env, platform, home }), { recursive: true });
|
|
160
219
|
for (const f of p.files) {
|
|
161
220
|
fs.mkdirSync(path.dirname(f.path), { recursive: true });
|
|
162
|
-
|
|
221
|
+
// WSH requires a UTF-16 BOM for paths containing non-ASCII characters.
|
|
222
|
+
const content = f.path.endsWith('.vbs') ? Buffer.from('\ufeff' + f.content, 'utf16le') : f.content;
|
|
223
|
+
fs.writeFileSync(f.path, content, { mode: f.mode });
|
|
163
224
|
fs.chmodSync(f.path, f.mode);
|
|
164
225
|
}
|
|
226
|
+
if (p.shortcut) {
|
|
227
|
+
try { fs.mkdirSync(path.dirname(p.shortcut.path), { recursive: true }); manageShortcut(p.shortcut, 'write'); }
|
|
228
|
+
catch (e) { say(`✗ launcher shortcut failed: ${e.message}`); return 1; }
|
|
229
|
+
}
|
|
165
230
|
say(`✓ PMOS app for ${repo}`);
|
|
166
231
|
say(` ${p.app}`);
|
|
167
|
-
say(platform === 'darwin' ? ' Open it from Spotlight or Launchpad, or drag it to the Dock.' : ' Open it from the app menu.');
|
|
232
|
+
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.');
|
|
168
233
|
if (p.login) {
|
|
169
234
|
say('✓ login item: the workspace server starts when you log in, without a browser window');
|
|
170
235
|
say(` ${p.login}`);
|
|
@@ -179,6 +244,10 @@ function run(argv, { say = console.log, platform = process.platform, home = os.h
|
|
|
179
244
|
|
|
180
245
|
if (sub === 'off') {
|
|
181
246
|
let removed = 0;
|
|
247
|
+
if (p.shortcut && fs.existsSync(p.shortcut.path)) {
|
|
248
|
+
try { manageShortcut(p.shortcut, 'remove'); say(`✓ removed ${p.shortcut.path}`); removed++; }
|
|
249
|
+
catch (e) { say(`· left ${p.shortcut.path}: ${e.message}`); }
|
|
250
|
+
}
|
|
182
251
|
for (const r of p.removable) {
|
|
183
252
|
if (!fs.existsSync(r)) continue;
|
|
184
253
|
if (!marked(markFile(r))) { say(`· left ${r}: it was not written by pmos launcher`); continue; }
|
|
@@ -193,9 +262,15 @@ function run(argv, { say = console.log, platform = process.platform, home = os.h
|
|
|
193
262
|
// status
|
|
194
263
|
const exe = p.files.find((f) => f.role === 'app' && f.mode === 0o755).path;
|
|
195
264
|
const t = marked(exe) ? readTarget(exe) : null;
|
|
196
|
-
const loginPath = p.
|
|
265
|
+
const loginPath = p.login;
|
|
197
266
|
const login = fs.existsSync(loginPath) && marked(loginPath);
|
|
198
267
|
if (!t) { say('○ no PMOS app is installed (pmos launcher on)'); if (login) say(`· a login item is installed without the app: ${loginPath}`); return 1; }
|
|
268
|
+
if (p.shortcut) {
|
|
269
|
+
try {
|
|
270
|
+
if (!fs.existsSync(p.shortcut.path)) throw new Error('Start menu shortcut is missing');
|
|
271
|
+
manageShortcut(p.shortcut, 'check');
|
|
272
|
+
} catch (e) { say(`✗ ${e.message} — run \`pmos launcher on\` again`); return 1; }
|
|
273
|
+
}
|
|
199
274
|
say(`✓ PMOS app — ${p.app}`);
|
|
200
275
|
say(` repository: ${t.repo}${fs.existsSync(t.repo) ? '' : ' ✗ not found'}`);
|
|
201
276
|
say(` node: ${t.node}${fs.existsSync(t.node) ? '' : ' ✗ not found — run `pmos launcher on` again'}`);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const crypto = require('crypto');
|
|
5
|
+
const pmItems = require('./pm-items.js');
|
|
6
|
+
const itemRoutes = require('./routes-pm-items.js');
|
|
7
|
+
const STEPS = ['claude', 'sources', 'found'];
|
|
8
|
+
function file(root, id) { return path.join(root, 'onboarding', crypto.createHash('sha256').update(id).digest('hex') + '.json'); }
|
|
9
|
+
function read(root, id) { try { const v = JSON.parse(fs.readFileSync(file(root, id), 'utf8')); if (!v || typeof v !== 'object') throw new Error('state'); return v; } catch { return { step: 'claude', started: false, completed: false, sources: {} }; } }
|
|
10
|
+
function save(root, id, patch) {
|
|
11
|
+
const f = file(root, id); fs.mkdirSync(path.dirname(f), { recursive: true });
|
|
12
|
+
const next = { ...read(root, id), ...patch, started: true, updated_at: new Date().toISOString() };
|
|
13
|
+
const tmp = f + '.' + crypto.randomBytes(6).toString('hex') + '.tmp';
|
|
14
|
+
try { fs.writeFileSync(tmp, JSON.stringify(next) + '\n', { mode: 0o600, flag: 'wx' }); fs.renameSync(tmp, f); }
|
|
15
|
+
finally { try { fs.unlinkSync(tmp); } catch {} }
|
|
16
|
+
return next;
|
|
17
|
+
}
|
|
18
|
+
function hasWork(ctx, w) {
|
|
19
|
+
const dirs = [path.join(w.root, 'planning', 'initiatives')];
|
|
20
|
+
try { const state = ctx.stateDirFor && ctx.stateDirFor(w); if (state) dirs.push(path.join(state, 'initiatives')); } catch {}
|
|
21
|
+
return dirs.some(d => { try { return fs.readdirSync(d).some(n => n.endsWith('.md') && !/^README|template/i.test(n)); } catch { return false; } });
|
|
22
|
+
}
|
|
23
|
+
function task(ctx, w, body) {
|
|
24
|
+
if (typeof body.request_id !== 'string' || !/^[a-zA-Z0-9-]{8,80}$/.test(body.request_id)) throw new Error('A task request id is required.');
|
|
25
|
+
if (typeof body.title !== 'string' || !body.title.trim() || body.title.length > 500) throw new Error('Enter a task title, up to 500 characters.');
|
|
26
|
+
const due = body.due || null;
|
|
27
|
+
if (due && (!/^\d{4}-\d{2}-\d{2}$/.test(due) || !Number.isFinite(Date.parse(due)) || new Date(due).toISOString().slice(0, 10) !== due)) throw new Error('Choose a valid due date.');
|
|
28
|
+
const id = 'item-' + crypto.createHash('sha256').update(w.id + ':' + body.request_id).digest('hex').slice(0, 12);
|
|
29
|
+
const existing = itemRoutes.itemOf(ctx, id);
|
|
30
|
+
if (existing) return existing;
|
|
31
|
+
const r = itemRoutes.addItem(body.title.trim(), new Date());
|
|
32
|
+
const ev = r.events[0]; ev.id = id; ev.fields.title = body.title.trim(); ev.fields.due = due; ev.fields.flagged = !due;
|
|
33
|
+
pmItems.appendEvent(path.join(ctx.runtimeDir, 'pm-items', 'items.jsonl'), ev, new Date());
|
|
34
|
+
return { ...r.body.item, id, title: body.title.trim(), due, flagged: !due };
|
|
35
|
+
}
|
|
36
|
+
module.exports = { read, save, hasWork, task, STEPS };
|