create-pmos 0.461.0 → 0.463.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.461.0",
3
+ "version": "0.463.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,32 @@
32
32
  "audit"
33
33
  ],
34
34
  "pmosChanges": [
35
+ {
36
+ "v": "0.463.0",
37
+ "at": "2026-10-31T02:36:24.736Z",
38
+ "f": 3,
39
+ "prs": [
40
+ {
41
+ "n": 1114,
42
+ "t": "Records are saved on the default branch only, and a document folder is put back on it by itself (D70)",
43
+ "s": "Records are saved on the default branch only, and a document folder is put back on it by itself",
44
+ "k": "fix"
45
+ }
46
+ ]
47
+ },
48
+ {
49
+ "v": "0.462.0",
50
+ "at": "2026-10-31T02:08:48.803Z",
51
+ "f": 3,
52
+ "prs": [
53
+ {
54
+ "n": 1113,
55
+ "t": "Program initiatives on the board list; a leave in the main tree wins over the worktree copy",
56
+ "s": "Program initiatives on the board list; a leave in the main tree wins over the worktree copy",
57
+ "k": "fix"
58
+ }
59
+ ]
60
+ },
35
61
  {
36
62
  "v": "0.461.0",
37
63
  "at": "2026-10-31T01:34:13.377Z",
@@ -271,32 +297,6 @@
271
297
  "k": "new"
272
298
  }
273
299
  ]
274
- },
275
- {
276
- "v": "0.443.0",
277
- "at": "2026-10-28T14:25:24.275Z",
278
- "f": 3,
279
- "prs": [
280
- {
281
- "n": 1087,
282
- "t": "0.442.0 hotfix, goals made clear, folded list card, task ticket linking (batch 18)",
283
- "s": "0.442.0 hotfix, goals made clear, folded list card, task ticket linking (batch 18)",
284
- "k": "new"
285
- }
286
- ]
287
- },
288
- {
289
- "v": "0.442.0",
290
- "at": "2026-10-28T11:41:20.468Z",
291
- "f": 3,
292
- "prs": [
293
- {
294
- "n": 1086,
295
- "t": "Initiative Viewer on phone and desktop, Adler dressed for the season, clear task marks (feedback batch 18 items 1, 8, 12, 13)",
296
- "s": "Initiative Viewer on phone and desktop, Adler dressed for the season, clear task marks (feedback batch 18 items 1, 8, 12, 13)",
297
- "k": "new"
298
- }
299
- ]
300
300
  }
301
301
  ]
302
302
  }
@@ -1,3 +1,3 @@
1
- kernel-source: pmos@391ea0f0
1
+ kernel-source: pmos@e3f8c684
2
2
  assembled: 2026-10-31
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-10-31T01:34:09Z"}
5
+ generated: {by: process:create-pmos, at: "2026-10-31T02:36: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-10-31T01:34:09Z"}
5
+ generated: {by: process:create-pmos, at: "2026-10-31T02:36: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-10-31T01:34:09Z"}
5
+ generated: {by: process:create-pmos, at: "2026-10-31T02:36:21Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -1,4 +1,30 @@
1
1
  [
2
+ {
3
+ "v": "0.463.0",
4
+ "at": "2026-10-31T02:36:24.736Z",
5
+ "f": 3,
6
+ "prs": [
7
+ {
8
+ "n": 1114,
9
+ "t": "Records are saved on the default branch only, and a document folder is put back on it by itself (D70)",
10
+ "s": "Records are saved on the default branch only, and a document folder is put back on it by itself",
11
+ "k": "fix"
12
+ }
13
+ ]
14
+ },
15
+ {
16
+ "v": "0.462.0",
17
+ "at": "2026-10-31T02:08:48.803Z",
18
+ "f": 3,
19
+ "prs": [
20
+ {
21
+ "n": 1113,
22
+ "t": "Program initiatives on the board list; a leave in the main tree wins over the worktree copy",
23
+ "s": "Program initiatives on the board list; a leave in the main tree wins over the worktree copy",
24
+ "k": "fix"
25
+ }
26
+ ]
27
+ },
2
28
  {
3
29
  "v": "0.461.0",
4
30
  "at": "2026-10-31T01:34:13.377Z",
@@ -2,7 +2,7 @@
2
2
  type: Guide
3
3
  title: "Guide: layout"
4
4
  description: "The frame: one top bar, the place on screen, the detail and the agent dock; the phone tabs and lists; the keys; and the older layout."
5
- timestamp: 2026-10-23
5
+ timestamp: 2026-10-31
6
6
  ---
7
7
 
8
8
  # Guide: layout
@@ -22,7 +22,7 @@ The top bar has these parts, from left to right:
22
22
  - **Agenda, My work, Initiatives, Board, Reports, Docs and People** are the places. Each has an icon before its name, the same icon as on the phone. Press one to show it. The Agenda count shows how many items need you. Docs shows whether each document is the same as its Google Docs and Confluence copy. People shows the people you work with in the repository ([People](people.md)).
23
23
  - **Search or capture ⌘K** opens the command palette. Type to find an initiative, a repository, an open tab or a command.
24
24
  - **Sync** shows only when the current repository is not in sync with its remote. Press it to fetch, bring in the work of the other machine, record your changes and push. If the repository has not fetched in the last 10 minutes, Sync also shows, because a push from another machine is not visible until a fetch. When the repository fetched recently and is in sync, Sync is not shown. When two machines add lines to the same ledger (a `.jsonl` file under `pmos/` or `planning/`), Sync keeps the lines from both machines. If Sync stops, the message names the step that stopped. If both machines changed the same lines of another file, Sync changes nothing and names the files. Then choose **Push this machine’s version** or **Pull the other machine’s version**. Sync keeps that version of those files, keeps all other changes from both machines, and finishes. It never overwrites the remote history.
25
- - **Sync on its own.** If you forget to press Sync, the workspace syncs for you. It syncs each repository once when the workspace starts. It also syncs a repository that has records not yet pushed when no record changed for 5 minutes. In a document repository it syncs every changed file on any branch. In a code repository it syncs only on the default branch (for example `main`), and only when every commit not yet pushed changes records and no code. If you close the tab while records are not yet pushed, the browser asks you first. To turn automatic sync off, start the workspace with `PMOS_AUTO_SYNC=0`.
25
+ - **Sync on its own.** If you forget to press Sync, the workspace syncs for you. It syncs each repository once when the workspace starts. It also syncs a repository that has records not yet pushed when no record changed for 5 minutes. It syncs only on the default branch (for example `main`). In a document repository it syncs every changed file. In a code repository it also needs every commit not yet pushed to change records and no code. If a document folder has been left on another branch, the workspace puts it back on the default branch for you, with your records saved, when that loses nothing. It tells you only when it cannot do this safely, for example when two saved versions of one page do not match. If you close the tab while records are not yet pushed, the browser asks you first. To turn automatic sync off, start the workspace with `PMOS_AUTO_SYNC=0`.
26
26
  - **Settings** opens the settings of the workspace.
27
27
 
28
28
  Each place is drawn when its run is built. Until then the place says which run brings it, for example "Board arrives in Run 4."
@@ -8,16 +8,21 @@
8
8
  * Before either, a repository must pass every rule below. A rule that cannot be read is a no.
9
9
  * - auto-sync is on for this server (see enabledFor);
10
10
  * - the branch has an upstream;
11
- * - in a CODE repository only (profile product-code, D68): the branch is the remote's default branch, and every commit
12
- * not yet pushed touches record paths only, so a feature branch and code are never auto-pushed. A DOCUMENT
13
- * repository (profile pm-artifacts) holds only the PM's documents: any branch, every file;
11
+ * - the branch is the remote's default branch, in every repository (D70 as amended 2026-10-31: a record committed on a
12
+ * feature branch never reaches the default branch, so the PM's records seemed to vanish from the product they belong to);
13
+ * - in a CODE repository only (profile product-code, D68): every commit not yet pushed touches record paths only, so
14
+ * code is never auto-pushed. A DOCUMENT repository (profile pm-artifacts) holds only the PM's documents: every file;
14
15
  * - no record file changed in the last QUIET_MS: a document being written is left alone;
15
16
  * - no sync is running for the repository, and the last auto-sync did not fail within RETRY_MS.
16
17
  */
17
18
  const syncLib = require('./sync');
19
+ const folderRepair = require('./folder-repair');
18
20
 
21
+ const BRANCH_WHY = /not the default branch|cannot tell the default branch/;
19
22
  const QUIET_MS = 5 * 60 * 1000;
20
23
  const RETRY_MS = 30 * 60 * 1000;
24
+ const ASK_AGAIN_MS = 30 * 60 * 1000; // a repair that needs the PM is not tried again for this long
25
+ const WAIT_AGAIN_MS = 10 * 60 * 1000; // one that only waited (no network, a refused push) is tried again sooner
21
26
 
22
27
  // On for a real server start. A server given its own state directory (every suite does, through test-run.js) is a
23
28
  // scratch server and does not auto-sync unless asked. PMOS_AUTO_SYNC=0 turns it off; =1 turns it on.
@@ -37,8 +42,9 @@ async function blocker(root, moment, { now = Date.now(), lastFail = 0 } = {}) {
37
42
  if (st.state === 'mid-operation') return 'a merge, rebase or cherry-pick is in progress';
38
43
  const docs = syncLib.profileOf(root) === 'pm-artifacts';
39
44
  const remote = st.upstream.split('/')[0];
40
- const def = docs ? null : await syncLib.defaultBranchOf(root, remote);
41
- if (!docs && (!def || st.branch !== def)) return `'${st.branch}' is not the default branch of ${remote}`;
45
+ const def = await syncLib.defaultBranchOf(root, remote);
46
+ if (!def) return `PMOS cannot tell the default branch of ${remote}, so it does not save your records on its own`;
47
+ if (st.branch !== def) return `'${st.branch}' is not the default branch of ${remote}, so PMOS is not saving your records. Switch this folder back to '${def}'`;
42
48
  if (st.ahead && !docs) {
43
49
  const paths = await syncLib.unpushedPaths(root, st.upstream);
44
50
  if (!paths) return 'the unpushed commits cannot be read';
@@ -57,17 +63,57 @@ async function blocker(root, moment, { now = Date.now(), lastFail = 0 } = {}) {
57
63
  * roots() the repository roots the server holds
58
64
  * busy a Set of roots with a sync running (shared with the press route)
59
65
  * onDone(root, result) called after each auto-sync that ran (to refresh caches) */
60
- function createAutoSync({ roots, busy, onDone = () => {}, env = process.env, label = 'auto-sync' } = {}) {
61
- const last = new Map(); // root -> { at, moment, ok, message, skipped? }
66
+ function createAutoSync({ roots, busy, onDone = () => {}, env = process.env, label = 'auto-sync', repair = folderRepair.repair } = {}) {
67
+ const last = new Map(); // root -> { at, moment, ok, message, skipped?, blocked?, needs?, repaired? }
68
+ const tried = new Map(); // root -> { at, result } the last repair attempt
69
+ const repairOn = String(env.PMOS_AUTO_REPAIR || '').trim() !== '0';
70
+
71
+ // A document repository whose folder is off its default branch is put back by itself (lib/folder-repair.js). It is tried again
72
+ // after a pause, so a state that needs the PM does not run git on every tick.
73
+ async function tryRepair(root) {
74
+ const prev = tried.get(root);
75
+ const pause = prev && prev.result && (prev.result.action === 'ask' ? ASK_AGAIN_MS : WAIT_AGAIN_MS);
76
+ if (prev && prev.result && prev.result.action !== 'repaired' && Date.now() - prev.at < pause) return prev.result;
77
+ busy.add(root);
78
+ try {
79
+ const result = await repair(root, { label });
80
+ tried.set(root, { at: Date.now(), result });
81
+ return result;
82
+ } catch (e) {
83
+ const result = { action: 'wait', why: String((e && e.message) || e).slice(0, 160) };
84
+ tried.set(root, { at: Date.now(), result });
85
+ return result;
86
+ } finally { busy.delete(root); }
87
+ }
88
+
62
89
  async function runFor(root, moment) {
63
90
  if (!enabledFor(env) || busy.has(root)) return null;
64
91
  const prev = last.get(root);
65
- const why = await blocker(root, moment, { lastFail: prev && prev.ok === false ? prev.at : 0 });
66
- if (why) return null;
92
+ const opts = () => ({ lastFail: prev && prev.ok === false ? prev.at : 0 });
93
+ let why = await blocker(root, moment, opts());
94
+ let repaired = null;
95
+ if (why && BRANCH_WHY.test(why)) {
96
+ // only a document repository is repaired and only one is the PM's to be told about: a developer on a feature branch is normal
97
+ if (syncLib.profileOf(root) !== 'pm-artifacts') return null;
98
+ const r = repairOn ? await tryRepair(root) : null;
99
+ if (r && r.action === 'repaired') { repaired = { from: r.from, to: r.to, at: Date.now() }; why = await blocker(root, moment, opts()); }
100
+ else {
101
+ // the technical reason stays in `detail`; `message` is the plain sentence, and only when the PM has to decide something
102
+ last.set(root, { at: Date.now(), moment, ok: null, skipped: true, blocked: 'branch', needs: r && r.action === 'ask' ? 'choice' : 'wait',
103
+ message: r && r.action === 'ask' ? folderRepair.plain(r) : '', detail: why, files: (r && r.files) || [] });
104
+ return null;
105
+ }
106
+ }
107
+ if (why) {
108
+ // repaired, and nothing is left to send: the status still says it happened, so the PM's screen can say it once
109
+ if (repaired) last.set(root, { at: Date.now(), moment, ok: true, message: '', repaired });
110
+ else if (prev && prev.blocked === 'branch') last.delete(root);
111
+ return null;
112
+ }
67
113
  busy.add(root);
68
114
  try {
69
115
  const out = await syncLib.sync(root, { label });
70
- last.set(root, { at: Date.now(), moment, ok: !!out.ok, message: out.message, stopped_at: out.stopped_at || null });
116
+ last.set(root, { at: Date.now(), moment, ok: !!out.ok, message: out.message, stopped_at: out.stopped_at || null, ...(repaired ? { repaired } : {}) });
71
117
  try { onDone(root, out); } catch { /* a cache refresh is not the sync's business */ }
72
118
  return out;
73
119
  } finally { busy.delete(root); }
@@ -296,7 +296,10 @@ function build(f) {
296
296
  const rows = (f.rows || []).slice(0, MAX_LIST).map((r) => rowOf(r, wf, todayIso));
297
297
  // the on-hold rows follow the open ones; the cancelled and archived rows sit under the list's fold (initiative premium-board-actions)
298
298
  for (const r of (f.held || [])) if (rows.length < MAX_LIST + 50 && !rows.some((x) => x.id === r.id)) rows.push(rowOf(r, wf, todayIso));
299
- const gone = { cancelled: (f.cancelled || []).slice(0, MAX_LIST).map((r) => rowOf(r, wf, todayIso)), archived: (f.archived || []).slice(0, MAX_LIST).map((r) => rowOf(r, wf, todayIso)) };
299
+ // an initiative a program holds stays on the list whatever its horizon: the list reads the `now` and `risk` views, and a member the
300
+ // program page cannot find here shows as "not read" and its program as "No open initiatives"
301
+ for (const r of (f.members || [])) if (rows.length < MAX_LIST + 100 && !rows.some((x) => x.id === r.id)) rows.push(rowOf(r, wf, todayIso));
302
+ const gone ={ cancelled: (f.cancelled || []).slice(0, MAX_LIST).map((r) => rowOf(r, wf, todayIso)), archived: (f.archived || []).slice(0, MAX_LIST).map((r) => rowOf(r, wf, todayIso)) };
300
303
  // the list reads the board's own rank; "Do this first" only where a record says the first row is late
301
304
  if (rows[0] && rows[0].late) rows[0].first = true;
302
305
  const stages = (f.columns || []).map((c) => ({ stage: c.stage, cat: c.cat, count: Number(c.count) || 0, rows: (c.rows || []).slice(0, STAGE_ROWS).map((r) => rowOf(r, wf, todayIso)), more: Math.max(0, (Number(c.count) || 0) - STAGE_ROWS) }));
@@ -0,0 +1,150 @@
1
+ 'use strict';
2
+ /* lib/folder-repair.js — put a document repository's folder back on its default branch, by itself, when that loses nothing
3
+ * (D70 as amended 2026-10-31). The PM: "if PMOS can fix it, it should just do it".
4
+ *
5
+ * WHY. A product folder left on a feature branch collects every record there, and the product looks empty on its default
6
+ * branch: Project Ascent's program and initiatives could not be found. The PM should not have to know what a branch is.
7
+ *
8
+ * WHAT. In a DOCUMENT repository (profile pm-artifacts: every file is a record) whose own folder is not on the remote's
9
+ * default branch, repair() does, in this order, and stops at the first step that cannot be made safe:
10
+ * 1. fetch;
11
+ * 2. commit the records pending in the folder, on the branch it is on (the same staging Sync uses);
12
+ * 3. check, without touching anything, that the branch merges into the default branch with no conflict;
13
+ * 4. merge the branch into the default branch (in the folder that already holds it, or in this one after switching);
14
+ * 5. push the default branch (no force);
15
+ * 6. free the default branch if another clean folder held it, and switch this folder onto it.
16
+ * The feature branch is never deleted, never rewritten and never force-pushed. A code repository is never touched: a developer
17
+ * on a feature branch is normal there. A linked worktree is never touched: only a repository's own folder is a product.
18
+ *
19
+ * ANSWERS. { action, from, to, why, files? }
20
+ * none nothing to do (already on the default branch, a code repository, a linked worktree)
21
+ * repaired the folder is on the default branch and its records are merged into it
22
+ * ask it cannot be made safe alone: 'conflict' (two versions of one file, `files` names them), 'work' (another copy of the
23
+ * folder holds work that is not saved), 'diverged' (the default branch differs from the remote's)
24
+ * wait try again later: no network, a push the remote refused, a git too old for the check, an operation in progress
25
+ * Every step that fails after a change is undone first (a merge is aborted, the folder is switched back), so `ask` and `wait`
26
+ * leave the folder as it was found, plus the records committed in step 2. Running it again after `repaired` answers `none`. */
27
+ const os = require('os');
28
+ const path = require('path');
29
+ const syncLib = require('./sync');
30
+
31
+ const { run } = syncLib;
32
+ const same = (a, b) => path.resolve(String(a)) === path.resolve(String(b));
33
+
34
+ /** The working trees of the repository: [{ dir, branch|null }], the main one first. */
35
+ async function worktrees(root) {
36
+ const r = await run(root, ['worktree', 'list', '--porcelain']);
37
+ if (!r.ok || !r.out) return [];
38
+ const out = []; let cur = null;
39
+ for (const line of r.out.split('\n')) {
40
+ if (line.startsWith('worktree ')) { cur = { dir: line.slice(9).trim(), branch: null }; out.push(cur); }
41
+ else if (cur && line.startsWith('branch ')) cur.branch = line.slice(7).trim().replace(/^refs\/heads\//, '');
42
+ }
43
+ return out;
44
+ }
45
+
46
+ /** Is `root` a repository's own folder (not a linked worktree)? */
47
+ async function isMainTree(root) {
48
+ const r = await run(root, ['rev-parse', '--path-format=absolute', '--git-dir', '--git-common-dir']);
49
+ if (!r.ok) return false;
50
+ const [dir, common] = r.out.split('\n').map((x) => x.trim());
51
+ return !!dir && !!common && same(dir, common);
52
+ }
53
+
54
+ async function repair(root, { label } = {}) {
55
+ const none = (why) => ({ action: 'none', why });
56
+ if (syncLib.profileOf(root) !== 'pm-artifacts') return none('a code repository');
57
+ if (!(await isMainTree(root))) return none('a linked worktree');
58
+ const s0 = await syncLib.status(root);
59
+ if (!s0.ok || !s0.branch) return none('no branch');
60
+ if (s0.state === 'mid-operation') return { action: 'wait', why: 'a merge, rebase or cherry-pick is in progress here' };
61
+ const remote = s0.upstream ? s0.upstream.split('/')[0] : 'origin';
62
+ if (!(await run(root, ['remote', 'get-url', remote])).ok) return none('no remote');
63
+ const def = await syncLib.defaultBranchOf(root, remote);
64
+ if (!def) return none('the default branch is not known');
65
+ const from = s0.branch;
66
+ if (from === def) return none('already on the default branch');
67
+ const out = (action, why, extra) => ({ action, from, to: def, why, ...(extra || {}) });
68
+
69
+ // 1. fetch
70
+ if (!(await run(root, ['fetch', '--quiet', remote], { net: true })).ok) return out('wait', 'the remote could not be reached');
71
+
72
+ // 2. the records pending in this folder are committed on the branch it is on, so nothing the PM wrote can be lost by what follows
73
+ const added = syncLib.ensureUnionAttribute(root);
74
+ const s1 = await syncLib.status(root);
75
+ if (s1.dirty_records || s1.dirty_other || added) {
76
+ if (!(await run(root, ['add', '-A'])).ok) return out('wait', 'the records could not be staged');
77
+ const staged = await run(root, ['diff', '--cached', '--name-only']);
78
+ if (staged.out) {
79
+ const c = await run(root, ['commit', '-m', `chore(pmos): sync records from ${label || os.hostname()}`, '--no-verify']);
80
+ if (!c.ok) return out('wait', /identity unknown|empty ident/i.test(c.err) ? 'git has no author name or email on this machine' : 'the records could not be committed');
81
+ }
82
+ }
83
+
84
+ // the default branch here must be the remote's, or ahead of it: a local default branch behind it moves up, a diverged one is not ours to fix
85
+ const trees = await worktrees(root);
86
+ const holder = trees.find((t) => t.branch === def && !same(t.dir, root)) || null;
87
+ const haveLocal = (await run(root, ['rev-parse', '--verify', '--quiet', `refs/heads/${def}`])).ok;
88
+ const remoteDef = `refs/remotes/${remote}/${def}`;
89
+ if (!(await run(root, ['rev-parse', '--verify', '--quiet', remoteDef])).ok) return out('wait', 'the remote has no default branch yet');
90
+ if (haveLocal) {
91
+ const behind = (await run(root, ['merge-base', '--is-ancestor', `refs/heads/${def}`, remoteDef])).ok;
92
+ const ahead = (await run(root, ['merge-base', '--is-ancestor', remoteDef, `refs/heads/${def}`])).ok;
93
+ if (!behind && !ahead) return out('ask', 'diverged');
94
+ if (behind && !holder) { if (!(await run(root, ['branch', '-f', def, remoteDef])).ok) return out('wait', 'the default branch could not be updated'); }
95
+ } else if (!(await run(root, ['branch', def, remoteDef])).ok) return out('wait', 'the default branch could not be created');
96
+
97
+ // another folder holds the default branch: it must hold no unsaved work, and is brought up to date
98
+ if (holder) {
99
+ const dirty = await run(holder.dir, ['status', '--porcelain', '--untracked-files=all']);
100
+ if (!dirty.ok || dirty.out) return out('ask', 'work', { where: holder.dir });
101
+ if (haveLocal && !(await run(holder.dir, ['merge', '--ff-only', remoteDef])).ok) {
102
+ const ahead = (await run(root, ['merge-base', '--is-ancestor', remoteDef, `refs/heads/${def}`])).ok;
103
+ if (!ahead) return out('wait', 'the default branch could not be brought up to date');
104
+ }
105
+ }
106
+
107
+ // 3. a merge that conflicts is not made: the dry run touches no file and no branch
108
+ const attrs = syncLib.unionAttributesFor(root);
109
+ const cfg = attrs ? ['-c', `core.attributesFile=${attrs}`] : [];
110
+ const probe = await run(root, [...cfg, 'merge-tree', '--write-tree', '--name-only', def, from]);
111
+ if (!probe.ok) {
112
+ // `--name-only` prints the tree id and the conflicted files, then a blank line, then git's notes about each
113
+ const files = probe.out.split(/\n\s*\n/)[0].split('\n').slice(1).map((l) => l.trim()).filter(Boolean).slice(0, 8);
114
+ if (/conflict/i.test(probe.out) || files.length) return out('ask', 'conflict', { files });
115
+ return out('wait', 'this git cannot check a merge first');
116
+ }
117
+
118
+ // 4. the merge, where the default branch already is, or here after switching onto it
119
+ let cwd = holder ? holder.dir : root;
120
+ let switched = false;
121
+ if (!holder) {
122
+ if (!(await run(root, ['switch', '--quiet', def])).ok) return out('wait', 'the folder could not be switched');
123
+ switched = true;
124
+ }
125
+ const back = async () => { if (switched) await run(root, ['switch', '--quiet', from]); };
126
+ const m = await run(cwd, [...cfg, 'merge', '--no-ff', '-m', `chore(pmos): bring the records from ${from} onto ${def}`, '--no-verify', from]);
127
+ if (!m.ok) { await run(cwd, ['merge', '--abort']); await back(); return out('ask', 'conflict'); }
128
+
129
+ // 5. push, never forced; a refusal keeps the local merge. Folder still on the branch: the next run pushes it. Folder already on the
130
+ // default branch: Sync pushes it, being then an ordinary unpushed record commit
131
+ if (!(await run(cwd, ['push', '--quiet', remote, def], { net: true })).ok) return out('wait', 'the remote did not take the push');
132
+
133
+ // 6. free the default branch and switch this folder onto it
134
+ if (holder) {
135
+ if (!(await run(root, ['worktree', 'remove', holder.dir])).ok) return out('wait', 'the other folder could not be removed');
136
+ if (!(await run(root, ['switch', '--quiet', def])).ok) return out('wait', 'the folder could not be switched');
137
+ }
138
+ return out('repaired', 'the records are merged and the folder is back on the default branch');
139
+ }
140
+
141
+ /** The sentence a person reads when repair cannot be made safe alone. Plain words: no branch, merge or worktree. */
142
+ function plain(r) {
143
+ if (!r) return '';
144
+ if (r.action === 'ask' && r.why === 'conflict') return 'Two saved versions of the same page do not match, and PMOS cannot tell which one is newer.';
145
+ if (r.action === 'ask' && r.why === 'work') return 'Another copy of this folder holds work that is not saved yet, so PMOS has not moved your records.';
146
+ if (r.action === 'ask') return 'Your records are in two versions that do not match, so PMOS has not moved them.';
147
+ return '';
148
+ }
149
+
150
+ module.exports = { repair, plain, worktrees, isMainTree };
@@ -150,6 +150,10 @@ function merge(perWs) {
150
150
  Object.assign(m.checks, p.checks);
151
151
  // the route writes the order line to the charter's workspace; a line elsewhere counts only while the charter's has none
152
152
  if (p.orderSet && (p.charter || !m.orderHome)) { m.order = p.order; if (p.charter) m.orderHome = true; }
153
+ // two ledgers can stand for one workspace (a linked worktree's copy is read as its main tree's, lib/routes-programs.js), the later one
154
+ // read last: what it says of an initiative (a member line or a leave line) replaces what the earlier one said, so a leave in the main
155
+ // tree is not undone by the worktree's older member line
156
+ for (const ini of p.touched) m.members = m.members.filter((x) => !(x.ws === ws && x.initiative === ini));
153
157
  for (const ini of p.members) if (!m.members.some((x) => x.ws === ws && x.initiative === ini)) m.members.push({ ws, initiative: ini });
154
158
  for (const t of p.tasks) m.tasks.push({ ...t, ws });
155
159
  for (const ini of p.touched) m.touched.push({ ws, initiative: ini });
@@ -51,7 +51,15 @@ async function metrics(req, res, url, ctx) {
51
51
  return true;
52
52
  }
53
53
 
54
+ /** The ids of the initiatives of workspace `ws` that a program holds: the rows the premium board keeps on its list whatever their horizon. */
55
+ const programMemberIds = (programs, ws) => {
56
+ const ids = new Set();
57
+ for (const p of programs || []) for (const m of (p && p.members) || []) if (m && m.ws === ws) ids.add(m.initiative);
58
+ return ids;
59
+ };
60
+
54
61
  module.exports = {
62
+ programMemberIds,
55
63
  prefixes: ['/api/board-premium', '/api/board-metrics-premium'],
56
64
  handle: async (req, res, url, ctx) => {
57
65
  if (url.pathname === '/api/board-metrics-premium') return metrics(req, res, url, ctx);
@@ -92,10 +100,22 @@ module.exports = {
92
100
  // the documents the PM added (lib/custom-docs.js): one file read, no route
93
101
  let custom = [];
94
102
  try { const w = ctx.getWs ? ctx.getWs(pick.ws) : null; custom = w ? Custom.list(w.root, 'board:' + pick.id) : []; } catch { custom = []; missing.push('added documents'); }
103
+ // the initiatives of this workspace that a program holds (GET /api/programs): the list above is the `now` and `risk` views, so a member
104
+ // on a later horizon is not in it, and the program page would call it unread. Their rows come from the board's own `all` view.
105
+ const rowsNow = listOf(rk, nw);
106
+ let members = [];
107
+ try {
108
+ const ids = programMemberIds(require('./routes-programs.js').all(ctx), pick.ws);
109
+ const have = new Set(rowsNow.map((r) => r.id));
110
+ if ([...ids].some((id) => !have.has(id))) {
111
+ const every = ok(await via(boards, '/api/boards/backlog' + q + '&view=all&limit=300', req, ctx), 'program initiatives');
112
+ members = ((every && every.rows) || []).filter((r) => ids.has(r.id) && !have.has(r.id));
113
+ }
114
+ } catch { missing.push('program initiatives'); }
95
115
  const model = BoardPremium.build({
96
116
  now: Date.now(), pending: false, missing: missing.filter((m) => m !== 'core documents'), boards: all.map((x) => ({ ws: x.ws, id: x.id, name: x.name })),
97
117
  board: head.body.board, counts: head.body.counts, nextRelease: head.body.nextRelease || null, pastReleases: head.body.pastReleases || [],
98
- rows: listOf(rk, nw), columns: c ? c.columns : [], sprints: s || { source: 'none', sprints: [] }, docs: d, custom,
118
+ rows: rowsNow, members, columns: c ? c.columns : [], sprints: s || { source: 'none', sprints: [] }, docs: d, custom,
99
119
  items: its && its.body && its.body.ok !== false && Array.isArray(its.body.items) ? its.body.items : [], held: hd ? hd.rows : [], cancelled: cn ? cn.rows : [], archived: ar ? ar.rows : [], asks: ak ? ak.asks || [] : null,
100
120
  });
101
121
  // every open initiative's anchor, not only the 100 rows listed (batch 17 item 1): Home's product card counts the goals as the ready-made
@@ -246,5 +246,5 @@ async function defaultBranchOf(root, remote) {
246
246
  return null;
247
247
  }
248
248
 
249
- module.exports = { status, sync, ensureUnionAttribute, unionAttributesFor, RECORD_PATHS, isRecord, REMOTE_FRESH_MS,
249
+ module.exports = { run, status, sync, ensureUnionAttribute, unionAttributesFor, RECORD_PATHS, isRecord, REMOTE_FRESH_MS,
250
250
  unpushedPaths, newestDirtyRecordMs, defaultBranchOf, profileOf };
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.461.0",
3
+ "version": "0.463.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.461.0",
9
+ "version": "0.463.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.461.0",
3
+ "version": "0.463.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",
@@ -79,6 +79,7 @@
79
79
  "state-isolation.test.js",
80
80
  "sync.test.js",
81
81
  "auto-sync.test.js",
82
+ "folder-repair.test.js",
82
83
  "schedule-cli.test.js",
83
84
  "initiative-surface.test.js",
84
85
  "guide.test.js",
@@ -191,6 +192,7 @@
191
192
  "state-isolation.test.js": 4,
192
193
  "sync.test.js": 4,
193
194
  "auto-sync.test.js": 4,
195
+ "folder-repair.test.js": 4,
194
196
  "schedule-cli.test.js": 3,
195
197
  "initiative-surface.test.js": 3,
196
198
  "guide.test.js": 1,