create-pmos 0.474.0 → 0.476.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 -33
- 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/claude-proposes.md +5 -1
- package/workspace/guide/index.md +2 -2
- package/workspace/guide/launcher.md +14 -32
- package/workspace/guide/layout.md +1 -1
- package/workspace/guide/settings.md +12 -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/proposals.js +4 -3
- package/workspace/lib/route-modules.js +3 -0
- package/workspace/lib/routes-grill.js +70 -0
- package/workspace/lib/routes-onboard.js +188 -0
- package/workspace/lib/routes-onboarding.js +5 -4
- package/workspace/lib/routes-proposals.js +8 -6
- 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-ev.css +6 -0
- package/workspace/public/pm/cozy-insights.css +2 -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 +35 -5
- package/workspace/public/pm/cozy-today.css +3 -0
- package/workspace/public/pm/grill-words.js +53 -0
- package/workspace/public/pm/home-app.js +41 -1
- package/workspace/public/pm/home-today.js +3 -1
- package/workspace/public/pm/ini-props.js +41 -8
- package/workspace/public/pm/ini-view.css +62 -37
- package/workspace/public/pm/premium-first.js +1 -1
- package/workspace/public/pm/premium-insights.js +43 -5
- 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/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
|
@@ -1,38 +1,81 @@
|
|
|
1
1
|
---
|
|
2
2
|
type: Guide
|
|
3
|
-
title: "
|
|
4
|
-
timestamp: 2026-
|
|
3
|
+
title: "First run: set up a project in Home"
|
|
4
|
+
timestamp: 2026-11-01
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
#
|
|
7
|
+
# First run
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Setup is a conversation in Home. It replaces the chat on the right while it runs, and the list of your work stays on the left. There is no separate setup page.
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Home starts setup when PMOS has no project yet. `pmos` also starts it on a first run. To start it again, open `/premium.html?onboard=1`. The old addresses `/welcome` and `/premium-welcome.html` open the same conversation.
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Setup saves its progress on this computer, outside any project folder. A reload continues from the same step.
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
## What you need
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
The desktop installers set up Node.js, Git, Claude Code and the PMOS launcher. PMOS needs a writable folder for the project, a writable local settings folder, and a current browser. The local server must run while you use the app.
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
Setup needs a Claude Code login on this computer. Signing in on the Claude website alone does not sign in Claude Code. Jira, Slack, Google Drive and other tools need their own connections under that same login.
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
## 1. Connect Claude and test the login
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
Choose **Set up a separate PMOS login**, or select an existing Claude setup. A profile name does not prove that the account is signed in.
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
2. **Your sources.** The page shows the folder and its path. Choose **Add another folder** to open the system folder chooser and add a second folder. Under **Tools**, tick the tools PMOS can read: Calendar (your meetings today and for the next 14 days), Jira (the issues assigned to you), Inbox (the threads waiting on you, by subject and sender only) and Slack (messages that mention you and your direct messages, as short summaries). None is ticked at first. Choose **Scan** to start. With tools ticked, the button reads, for example, **Scan the folder and read 2 tools**. Calendar and Jira each start their read-only skill as an agent session. Inbox and Slack are turned on for your daily brief, and the day is prepared now; if the morning brief was not scheduled, it is scheduled for 06:45 each day. A spinner shows while the scan runs. A large folder can take a minute or two, and the rest of PMOS keeps working.
|
|
27
|
-
3. **First look.** One sentence gives the counts: initiatives, documents, deadlines, stale documents, duplicates, people and risks. Up to ten findings follow. Each finding shows the file and line it comes from. Choose **Continue**.
|
|
28
|
-
4. **Your portfolio.** PMOS proposes one board for each product folder (`products/<name>/`). If there is no product folder, it proposes one board for the whole folder. Each board lists its initiatives. Each row has a checkbox, a title you can edit, a lane, an anchor, a stage and a document count. Choose the document count to see the documents. Use the board list on a row to move it to another board. Each board shows how many documents PMOS could not place. High and medium confidence rows start checked. The button reads **Import N initiatives into M boards**. The numbers change as you check, uncheck and move rows.
|
|
29
|
-
5. **Questions.** This step appears only when the scan could not decide something. There are three questions at most. Each question shows its default already chosen. Choose **Import** to accept what is chosen. Choose **Skip** to leave a question open: for the anchor question, the proposed anchors then stay marked for you to confirm later.
|
|
30
|
-
6. **First Briefing.** After the import, the page lists up to five things that need you first. An item that belongs to an imported initiative names the initiative and its board. Under **Your tools**, each tool you ticked says it is being read; its items join your Briefing in PMOS when the agent session finishes. Choose **Open PMOS** to go to the console. Choose **Undo this import** to take the import back and return to your portfolio.
|
|
25
|
+
Complete Claude's sign-in in the terminal that opens. Type `/login` there if needed. PMOS does not copy your password or credentials.
|
|
31
26
|
|
|
32
|
-
|
|
27
|
+
Choose **Test this login**. The test makes one small Claude request and may use your account allowance. It runs with no tools, no hooks and no connectors, and it does not read your files.
|
|
33
28
|
|
|
34
|
-
|
|
29
|
+
A failed test shows the reason: not signed in, Claude Code missing or too old, no network, or no account usage. A failed test does not switch to a different account, and setup does not continue until a test passes.
|
|
35
30
|
|
|
36
|
-
|
|
31
|
+
If you change the login after a passing test, setup asks you to test again. Results from the earlier login are dropped.
|
|
37
32
|
|
|
38
|
-
|
|
33
|
+
## 2. Describe the project
|
|
34
|
+
|
|
35
|
+
Type the project name and a few words about it. For example: "Checkout redesign, payments team. Jira key PAY." To use a folder you already have, include its path.
|
|
36
|
+
|
|
37
|
+
## 3. Choose the folder
|
|
38
|
+
|
|
39
|
+
Setup proposes a new folder under `PMOS` in your home folder, named after the project. Nothing is created until you confirm. Setup never proposes a folder that already holds files. If the name is taken, it adds a number.
|
|
40
|
+
|
|
41
|
+
To use a folder you already have, choose **Choose an existing folder…**, or type its path. Setup then shows what is already there: a Git repository, a README, or an existing PMOS install. In an existing folder, setup adds only what is missing; your files and history stay as they are. **Put the new folder somewhere else…** changes where the new folder goes.
|
|
42
|
+
|
|
43
|
+
The search step can also read the folder's README and Git history.
|
|
44
|
+
|
|
45
|
+
## 4. Search your connected tools
|
|
46
|
+
|
|
47
|
+
Choose **Show what I can read**. Setup lists the connectors of the tested login. This step makes no Claude request. A connector that needs sign-in is shown but cannot be selected; sign in to it in Claude first.
|
|
48
|
+
|
|
49
|
+
Select the sources, then choose **Search, read-only**. Searching uses some of your account usage. The search can only use tools whose names say they read, search, list or get. Every other tool is refused before it runs. Setup asks for no permission and sends no message.
|
|
50
|
+
|
|
51
|
+
Each source shows one result: what it found, nothing found, or why it could not read. A source that could not be read adds nothing to the review.
|
|
52
|
+
|
|
53
|
+
To skip the search, choose **Skip, use my description**.
|
|
54
|
+
|
|
55
|
+
## 5. Review what was found
|
|
56
|
+
|
|
57
|
+
Each proposed field names the source it came from, with a link. A field is empty when no source supports it. Setup does not invent an owner, a goal or a Jira project.
|
|
58
|
+
|
|
59
|
+
Edit any field, and clear the findings you do not want. If more than one Jira project matched, choose one before you continue. Treat what a connector returns as information to check, not as instructions.
|
|
60
|
+
|
|
61
|
+
## 6. Set up PMOS
|
|
62
|
+
|
|
63
|
+
Choose **Set up PMOS in** the folder. Setup creates the folder if it is new, sets up Git in a new folder, installs PMOS, adds one line to `CLAUDE.md`, and saves the project context to `pmos/planning/project-context.md`.
|
|
64
|
+
|
|
65
|
+
If the folder already has PMOS, setup reuses it as it is and does not reinstall it. The button then says **Open PMOS in**. If a different project context file is already there, setup saves a second one beside it.
|
|
66
|
+
|
|
67
|
+
Each step is recorded. If setup stops part of the way, run it again and it continues from the step that did not finish.
|
|
68
|
+
|
|
69
|
+
## 7. Open the project
|
|
70
|
+
|
|
71
|
+
The project opens in My Work. The last turn lists what setup did and offers next steps, such as checking the project context or showing what is open in Jira. An agent does not start automatically.
|
|
72
|
+
|
|
73
|
+
## Repair the login later
|
|
74
|
+
|
|
75
|
+
Home shows a **Claude needs attention** card only when the saved login has failed: signed out, removed, unreachable or refused. A login that was not tested since a restart shows nothing. **Test the login again** reopens setup at the login test, for the same profile. PMOS never switches accounts itself.
|
|
76
|
+
|
|
77
|
+
Settings › Claude has the same sign-in and test controls.
|
|
78
|
+
|
|
79
|
+
## What this was tested with
|
|
80
|
+
|
|
81
|
+
The automated tests use a stand-in Claude program, not a real account or real connectors. They check the flags of every Claude call, the refused tools, the folder rules and the PMOS install. A live sign-in and a live connector search were not part of those tests.
|
|
@@ -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 };
|