create-pmos 0.463.0 → 0.464.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 +14 -14
- 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/scripts/anchor-resolve.js +3 -0
- package/payload/state/discoveries.md +1 -1
- package/workspace/changelog.json +13 -0
- package/workspace/guide/layout.md +1 -0
- package/workspace/lib/auto-sync.js +24 -4
- package/workspace/lib/engine/anchor-resolve.js +3 -0
- package/workspace/lib/folder-attention.js +22 -0
- package/workspace/lib/folder-needs.js +32 -0
- package/workspace/lib/needs-providers.js +1 -0
- package/workspace/lib/routes-programs.js +5 -0
- package/workspace/lib/start-policy.js +12 -1
- package/workspace/lib/vendor/scripts/anchor-resolve.js +3 -0
- package/workspace/lib/worktree-gc.js +86 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/server.js +7 -2
- package/workspace/test-files.json +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-pmos",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.464.0",
|
|
4
4
|
"description": "Scaffold the PMOS portable kit — run the PMOS product-management workflow (initiative → lane-fit spec → contract → build → three gates, with work-type lanes for features, research, maintenance, incidents, and content) entirely inside your own repo, with all state as git-versioned files. Includes `workflow-sweep`, which audits the state every board derives from and separates real defects from work you simply have not done. `create-pmos workspace` also installs + launches the local Terminal Workspace GUI. No database, no network, no telemetry.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -32,6 +32,19 @@
|
|
|
32
32
|
"audit"
|
|
33
33
|
],
|
|
34
34
|
"pmosChanges": [
|
|
35
|
+
{
|
|
36
|
+
"v": "0.464.0",
|
|
37
|
+
"at": "2026-10-31T02:53:30.027Z",
|
|
38
|
+
"f": 3,
|
|
39
|
+
"prs": [
|
|
40
|
+
{
|
|
41
|
+
"n": 1116,
|
|
42
|
+
"t": "No folder per initiative in a document repository, finished worktrees clean up, one plain notice (D102)",
|
|
43
|
+
"s": "No folder per initiative in a document repository, finished worktrees clean up, one plain notice",
|
|
44
|
+
"k": "new"
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
},
|
|
35
48
|
{
|
|
36
49
|
"v": "0.463.0",
|
|
37
50
|
"at": "2026-10-31T02:36:24.736Z",
|
|
@@ -284,19 +297,6 @@
|
|
|
284
297
|
"k": "new"
|
|
285
298
|
}
|
|
286
299
|
]
|
|
287
|
-
},
|
|
288
|
-
{
|
|
289
|
-
"v": "0.444.0",
|
|
290
|
-
"at": "2026-10-28T16:30:50.265Z",
|
|
291
|
-
"f": 3,
|
|
292
|
-
"prs": [
|
|
293
|
-
{
|
|
294
|
-
"n": 1088,
|
|
295
|
-
"t": "Arrange panels, manage tasks in the stage card, goals dashboard (batch 18 items 15, 16, 11 gap)",
|
|
296
|
-
"s": "Arrange panels, manage tasks in the stage card, goals dashboard (batch 18 items 15, 16, 11 gap)",
|
|
297
|
-
"k": "new"
|
|
298
|
-
}
|
|
299
|
-
]
|
|
300
300
|
}
|
|
301
301
|
]
|
|
302
302
|
}
|
package/payload/KIT-VERSION
CHANGED
|
@@ -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-31T02:
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-10-31T02:53:26Z"}
|
|
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-31T02:
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-10-31T02:53:26Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -95,6 +95,9 @@ function krBullet(line) {
|
|
|
95
95
|
const m = RE_KR_BULLET.exec(line);
|
|
96
96
|
if (!m) return null;
|
|
97
97
|
let rest = m[3];
|
|
98
|
+
// a bullet that lists KRs in a sentence ("KR-A2, KR-B1 and KR-C3 have no initiative.") declares none of them: a KR is declared by an id
|
|
99
|
+
// followed by its name, so a comma or "and" after the id is prose
|
|
100
|
+
if (/^\s*(\*\*)?\s*(,|;|&|(and|or)\b)/i.test(rest)) return null;
|
|
98
101
|
const sep = /^\s*[—–:.-]?\s*/;
|
|
99
102
|
let name;
|
|
100
103
|
if (m[1] && /^\s*\*\*/.test(rest)) name = rest.replace(/^\s*\*\*/, '').replace(sep, ''); // **KR1.2** — name
|
|
@@ -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-31T02:
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-10-31T02:53:26Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
package/workspace/changelog.json
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"v": "0.464.0",
|
|
4
|
+
"at": "2026-10-31T02:53:30.027Z",
|
|
5
|
+
"f": 3,
|
|
6
|
+
"prs": [
|
|
7
|
+
{
|
|
8
|
+
"n": 1116,
|
|
9
|
+
"t": "No folder per initiative in a document repository, finished worktrees clean up, one plain notice (D102)",
|
|
10
|
+
"s": "No folder per initiative in a document repository, finished worktrees clean up, one plain notice",
|
|
11
|
+
"k": "new"
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
},
|
|
2
15
|
{
|
|
3
16
|
"v": "0.463.0",
|
|
4
17
|
"at": "2026-10-31T02:36:24.736Z",
|
|
@@ -23,6 +23,7 @@ The top bar has these parts, from left to right:
|
|
|
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
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
|
+
- **Old work folders clean up on their own.** When a piece of work has been merged and its extra folder has been untouched for 14 days, with nothing unsaved in it and no session using it, the workspace removes the folder. The work itself is kept. To turn this off, start the workspace with `PMOS_AUTO_CLEAN=0`.
|
|
26
27
|
- **Settings** opens the settings of the workspace.
|
|
27
28
|
|
|
28
29
|
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."
|
|
@@ -17,12 +17,15 @@
|
|
|
17
17
|
*/
|
|
18
18
|
const syncLib = require('./sync');
|
|
19
19
|
const folderRepair = require('./folder-repair');
|
|
20
|
+
const attention = require('./folder-attention');
|
|
21
|
+
const worktreeGc = require('./worktree-gc');
|
|
20
22
|
|
|
21
23
|
const BRANCH_WHY = /not the default branch|cannot tell the default branch/;
|
|
22
24
|
const QUIET_MS = 5 * 60 * 1000;
|
|
23
25
|
const RETRY_MS = 30 * 60 * 1000;
|
|
24
26
|
const ASK_AGAIN_MS = 30 * 60 * 1000; // a repair that needs the PM is not tried again for this long
|
|
25
27
|
const WAIT_AGAIN_MS = 10 * 60 * 1000; // one that only waited (no network, a refused push) is tried again sooner
|
|
28
|
+
const GC_EVERY_MS = 6 * 60 * 60 * 1000; // finished worktrees are looked for this often per repository (lib/worktree-gc.js)
|
|
26
29
|
|
|
27
30
|
// On for a real server start. A server given its own state directory (every suite does, through test-run.js) is a
|
|
28
31
|
// scratch server and does not auto-sync unless asked. PMOS_AUTO_SYNC=0 turns it off; =1 turns it on.
|
|
@@ -63,10 +66,12 @@ async function blocker(root, moment, { now = Date.now(), lastFail = 0 } = {}) {
|
|
|
63
66
|
* roots() the repository roots the server holds
|
|
64
67
|
* busy a Set of roots with a sync running (shared with the press route)
|
|
65
68
|
* onDone(root, result) called after each auto-sync that ran (to refresh caches) */
|
|
66
|
-
function createAutoSync({ roots, busy, onDone = () => {}, env = process.env, label = 'auto-sync', repair = folderRepair.repair } = {}) {
|
|
69
|
+
function createAutoSync({ roots, busy, onDone = () => {}, env = process.env, label = 'auto-sync', repair = folderRepair.repair, gc = worktreeGc.collect, gcHooks = {} } = {}) {
|
|
67
70
|
const last = new Map(); // root -> { at, moment, ok, message, skipped?, blocked?, needs?, repaired? }
|
|
68
71
|
const tried = new Map(); // root -> { at, result } the last repair attempt
|
|
69
72
|
const repairOn = String(env.PMOS_AUTO_REPAIR || '').trim() !== '0';
|
|
73
|
+
const cleanOn = String(env.PMOS_AUTO_CLEAN || '').trim() !== '0';
|
|
74
|
+
const gcAt = new Map(); // root -> when finished worktrees were last looked for
|
|
70
75
|
|
|
71
76
|
// A document repository whose folder is off its default branch is put back by itself (lib/folder-repair.js). It is tried again
|
|
72
77
|
// after a pause, so a state that needs the PM does not run git on every tick.
|
|
@@ -92,6 +97,7 @@ function createAutoSync({ roots, busy, onDone = () => {}, env = process.env, lab
|
|
|
92
97
|
const opts = () => ({ lastFail: prev && prev.ok === false ? prev.at : 0 });
|
|
93
98
|
let why = await blocker(root, moment, opts());
|
|
94
99
|
let repaired = null;
|
|
100
|
+
if (!why || !BRANCH_WHY.test(why)) attention.clear(root); // the folder is right (or is not a document folder): nothing to tell
|
|
95
101
|
if (why && BRANCH_WHY.test(why)) {
|
|
96
102
|
// 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
103
|
if (syncLib.profileOf(root) !== 'pm-artifacts') return null;
|
|
@@ -99,8 +105,10 @@ function createAutoSync({ roots, busy, onDone = () => {}, env = process.env, lab
|
|
|
99
105
|
if (r && r.action === 'repaired') { repaired = { from: r.from, to: r.to, at: Date.now() }; why = await blocker(root, moment, opts()); }
|
|
100
106
|
else {
|
|
101
107
|
// the technical reason stays in `detail`; `message` is the plain sentence, and only when the PM has to decide something
|
|
102
|
-
|
|
103
|
-
|
|
108
|
+
const ask = r && r.action === 'ask';
|
|
109
|
+
last.set(root, { at: Date.now(), moment, ok: null, skipped: true, blocked: 'branch', needs: ask ? 'choice' : 'wait',
|
|
110
|
+
message: ask ? folderRepair.plain(r) : '', detail: why, files: (r && r.files) || [] });
|
|
111
|
+
if (ask) attention.set(root, { message: folderRepair.plain(r), files: (r && r.files) || [] }); else attention.clear(root);
|
|
104
112
|
return null;
|
|
105
113
|
}
|
|
106
114
|
}
|
|
@@ -118,9 +126,21 @@ function createAutoSync({ roots, busy, onDone = () => {}, env = process.env, lab
|
|
|
118
126
|
return out;
|
|
119
127
|
} finally { busy.delete(root); }
|
|
120
128
|
}
|
|
129
|
+
// The folders of finished work are removed by lib/worktree-gc.js, which keeps every one a person could miss. Rarely, and never while a
|
|
130
|
+
// sync or repair holds the repository.
|
|
131
|
+
async function cleanFor(root) {
|
|
132
|
+
if (!cleanOn || !enabledFor(env) || busy.has(root)) return;
|
|
133
|
+
if (Date.now() - (gcAt.get(root) || 0) < GC_EVERY_MS) return;
|
|
134
|
+
gcAt.set(root, Date.now());
|
|
135
|
+
busy.add(root);
|
|
136
|
+
try { await gc(root, gcHooks); } catch { /* the next round tries again */ } finally { busy.delete(root); }
|
|
137
|
+
}
|
|
121
138
|
async function each(moment) {
|
|
122
139
|
const out = [];
|
|
123
|
-
for (const r of roots()) {
|
|
140
|
+
for (const r of roots()) {
|
|
141
|
+
try { out.push(await runFor(r, moment)); } catch { /* one repository never stops the others */ }
|
|
142
|
+
try { await cleanFor(r); } catch { /* nor does a cleanup */ }
|
|
143
|
+
}
|
|
124
144
|
return out;
|
|
125
145
|
}
|
|
126
146
|
return { startup: () => each('startup'), tick: () => each('idle'), lastOf: (root) => last.get(root) || null };
|
|
@@ -95,6 +95,9 @@ function krBullet(line) {
|
|
|
95
95
|
const m = RE_KR_BULLET.exec(line);
|
|
96
96
|
if (!m) return null;
|
|
97
97
|
let rest = m[3];
|
|
98
|
+
// a bullet that lists KRs in a sentence ("KR-A2, KR-B1 and KR-C3 have no initiative.") declares none of them: a KR is declared by an id
|
|
99
|
+
// followed by its name, so a comma or "and" after the id is prose
|
|
100
|
+
if (/^\s*(\*\*)?\s*(,|;|&|(and|or)\b)/i.test(rest)) return null;
|
|
98
101
|
const sep = /^\s*[—–:.-]?\s*/;
|
|
99
102
|
let name;
|
|
100
103
|
if (m[1] && /^\s*\*\*/.test(rest)) name = rest.replace(/^\s*\*\*/, '').replace(sep, ''); // **KR1.2** — name
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* lib/folder-attention.js — what the PM has to be told about a repository's folder, as one small registry in the server process.
|
|
3
|
+
*
|
|
4
|
+
* set(root, { message, files }) a folder PMOS could not put right alone (lib/auto-sync.js)
|
|
5
|
+
* clear(root) it is right again, or was never wrong
|
|
6
|
+
* get(root) → { message, files } | null
|
|
7
|
+
*
|
|
8
|
+
* lib/folder-needs.js reads it and makes the one needs row the Briefing, My work and the phone already show. `message` is one plain
|
|
9
|
+
* sentence with no git words (lib/folder-repair.js plain()). Nothing here writes a file: the registry is rebuilt by the next sync tick. */
|
|
10
|
+
const path = require('path');
|
|
11
|
+
|
|
12
|
+
const held = new Map(); // resolved root -> { message, files, at }
|
|
13
|
+
const key = (root) => path.resolve(String(root || ''));
|
|
14
|
+
|
|
15
|
+
function set(root, { message, files } = {}) {
|
|
16
|
+
if (!root || !message) return;
|
|
17
|
+
held.set(key(root), { message: String(message), files: Array.isArray(files) ? files.slice(0, 8).map(String) : [], at: Date.now() });
|
|
18
|
+
}
|
|
19
|
+
function clear(root) { if (root) held.delete(key(root)); }
|
|
20
|
+
function get(root) { return root ? held.get(key(root)) || null : null; }
|
|
21
|
+
|
|
22
|
+
module.exports = { set, clear, get };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* folder-needs.js — the needs provider of the folder repair (D70 as amended 2026-10-31). lib/needs-providers.js folds these rows into
|
|
3
|
+
* server.js deriveNeeds, and from there into /api/needs, the Briefing and My work.
|
|
4
|
+
*
|
|
5
|
+
* kinds: folder-attention
|
|
6
|
+
* rowsFor(w, { lead }) → rows · sig(w) → string
|
|
7
|
+
*
|
|
8
|
+
* folder-attention one row for a repository whose folder PMOS could not put back on its default branch alone: two saved versions of
|
|
9
|
+
* one page that do not match, or another copy of the folder that holds work not yet saved. The question is one plain
|
|
10
|
+
* sentence with no git words. Kind 8 (needs repair). The row goes when the next sync tick finds the folder right.
|
|
11
|
+
*
|
|
12
|
+
* The row is repository-wide, so a tree that is not the lead returns []. Nothing here writes. */
|
|
13
|
+
const attention = require('./folder-attention.js');
|
|
14
|
+
|
|
15
|
+
const NAME = 'folder-needs';
|
|
16
|
+
|
|
17
|
+
function rowsFor(w, { lead } = {}) {
|
|
18
|
+
if (!lead || !w || !w.root) return [];
|
|
19
|
+
const a = attention.get(w.root);
|
|
20
|
+
if (!a) return [];
|
|
21
|
+
const evidence = a.files.length ? a.files.join(', ') : '';
|
|
22
|
+
return [{
|
|
23
|
+
run_id: `${NAME}:${w.id}`, kind: 'folder-attention', initiative_id: null, question: a.message, doc: null, ws: w.id,
|
|
24
|
+
today: { kind: 8, source: NAME, cause: a.message, evidence, act: { label: 'Ask Claude to sort it out', cli: null } },
|
|
25
|
+
}];
|
|
26
|
+
}
|
|
27
|
+
function sig(w) {
|
|
28
|
+
const a = w && w.root ? attention.get(w.root) : null;
|
|
29
|
+
return a ? `${a.at}:${a.message}:${a.files.join(',')}` : '';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = { kinds: ['folder-attention'], rowsFor, sig };
|
|
@@ -36,6 +36,7 @@ const PROVIDERS = Object.freeze([
|
|
|
36
36
|
'driver-needs', // initiative-driver: drafts the agent filed (kind 7), a target the PM is blocking (kind 7)
|
|
37
37
|
'core-docs-needs', // core-documents: one row per scope with core document drafts waiting for the PM (kind 1)
|
|
38
38
|
'report-structure-needs', // report-structure: a Chrome or computer source that failed its check while a draft waits for it (kind 8)
|
|
39
|
+
'folder-needs', // folder repair: a folder PMOS could not put back on its default branch alone, in one plain sentence (kind 8)
|
|
39
40
|
]);
|
|
40
41
|
/** Kinds that already mean something in the needs queue. A provider may not reuse one. */
|
|
41
42
|
const RESERVED_KINDS = Object.freeze(['question', 'accept', 'outcome', 'keep', 'evidence', 'plan-flag', 'provider-error']);
|
|
@@ -34,6 +34,7 @@ const pmItems = require('./pm-items.js');
|
|
|
34
34
|
const P = require('./programs.js');
|
|
35
35
|
const MS = require('./milestone-suggest.js');
|
|
36
36
|
const gitInfo = require('./git-info.js');
|
|
37
|
+
const deletedIds = require('./ini-deleted.js');
|
|
37
38
|
|
|
38
39
|
const str = (v, n) => String(v == null ? '' : v).replace(/[\u0000-\u001f]+/g, ' ').trim().slice(0, n);
|
|
39
40
|
const DAY_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
@@ -78,6 +79,10 @@ function all(ctx, now = Date.now()) {
|
|
|
78
79
|
const of = (w) => foldedInto(list, w);
|
|
79
80
|
const perWs = list.map((w) => ({ ws: (of(w) || w).id, lines: read(fileOf(ctx, w, false)), tree: of(w) ? 0 : 1 })).sort((a, b) => a.tree - b.tree);
|
|
80
81
|
const progs = P.merge(perWs);
|
|
82
|
+
// an initiative the PM deleted on the board (lib/ini-deleted.js) is no longer a member: the ledger line stays, so a restore brings it back,
|
|
83
|
+
// and the program does not keep naming what no list shows (Project Ascent kept `decommission` after it was deleted)
|
|
84
|
+
const rootOf = new Map(list.map((w) => [w.id, w.root]));
|
|
85
|
+
for (const p of progs) p.members = (p.members || []).filter((m) => { const r = rootOf.get(m.ws); return !(r && deletedIds.ids(r).has(m.initiative)); });
|
|
81
86
|
const R = new Map();
|
|
82
87
|
for (const p of progs) {
|
|
83
88
|
if (!R.has(p.home)) { const w = list.find((x) => x.id === p.home), d = w ? stateDir(ctx, w, false) : null; R.set(p.home, MS.fold(read(d ? MS.fileOf(d) : null))); }
|
|
@@ -64,6 +64,7 @@ function mainTreeOf(trees) {
|
|
|
64
64
|
/* Resolve one "start work here" request to a plan.
|
|
65
65
|
*
|
|
66
66
|
* trees — the registered workspaces of ONE repository: { id, root, repo_key, branch }
|
|
67
|
+
* profile — the repository's profile: 'pm-artifacts' (documents only, D68) or 'product-code' (the default)
|
|
67
68
|
* initiative — an initiative id, or null/'' for "just give me a terminal"
|
|
68
69
|
* branches — branch names known to the repo (branchInfo().branches), or null when unread
|
|
69
70
|
*
|
|
@@ -71,7 +72,7 @@ function mainTreeOf(trees) {
|
|
|
71
72
|
* there is nothing to act on. `wsId` is the workspace the session is spawned against; `branch`
|
|
72
73
|
* non-null means a git operation is required first, and `isolate` says which kind.
|
|
73
74
|
*/
|
|
74
|
-
function resolveStart({ initiative, trees, branches } = {}) {
|
|
75
|
+
function resolveStart({ initiative, trees, branches, profile } = {}) {
|
|
75
76
|
const list = (trees || []).filter(Boolean);
|
|
76
77
|
if (!list.length) return { ok: false, error: 'no working tree is registered for this repository' };
|
|
77
78
|
const main = mainTreeOf(list);
|
|
@@ -103,6 +104,16 @@ function resolveStart({ initiative, trees, branches } = {}) {
|
|
|
103
104
|
why: `this repository is already on ${branch} — the session runs here, and no second folder is made`,
|
|
104
105
|
};
|
|
105
106
|
}
|
|
107
|
+
// A DOCUMENT repository (profile pm-artifacts) holds only the PM's documents and every file is a record. There is no code to keep
|
|
108
|
+
// from a parallel session, and a branch and a folder per initiative is how a product folder was once left off its default branch with
|
|
109
|
+
// its records on the wrong one (D70 as amended 2026-10-31, D102). The session runs in the repository's own folder, with no git
|
|
110
|
+
// operation. A folder an earlier version already made for the initiative is still reused above.
|
|
111
|
+
if (profile === 'pm-artifacts') {
|
|
112
|
+
return {
|
|
113
|
+
ok: true, plan: 'main-tree', wsId: main.id, branch: null, createBranch: false, isolate: false,
|
|
114
|
+
why: `runs in ${main.name || 'the main working tree'} — this repository holds documents only, so no second folder is made`,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
106
117
|
// Otherwise: a new worktree, off the main tree, which stays exactly where it is.
|
|
107
118
|
// `create` is DERIVED. A null `branches` means the branch list was never read — assuming the
|
|
108
119
|
// branch is new would make `git worktree add -b` fail on every existing branch, so the honest
|
|
@@ -95,6 +95,9 @@ function krBullet(line) {
|
|
|
95
95
|
const m = RE_KR_BULLET.exec(line);
|
|
96
96
|
if (!m) return null;
|
|
97
97
|
let rest = m[3];
|
|
98
|
+
// a bullet that lists KRs in a sentence ("KR-A2, KR-B1 and KR-C3 have no initiative.") declares none of them: a KR is declared by an id
|
|
99
|
+
// followed by its name, so a comma or "and" after the id is prose
|
|
100
|
+
if (/^\s*(\*\*)?\s*(,|;|&|(and|or)\b)/i.test(rest)) return null;
|
|
98
101
|
const sep = /^\s*[—–:.-]?\s*/;
|
|
99
102
|
let name;
|
|
100
103
|
if (m[1] && /^\s*\*\*/.test(rest)) name = rest.replace(/^\s*\*\*/, '').replace(sep, ''); // **KR1.2** — name
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* lib/worktree-gc.js — remove the folders of finished work, so they do not pile up (D102; the PM: "a worktree should be invisible").
|
|
3
|
+
*
|
|
4
|
+
* A linked worktree is an extra folder of a repository. IDPF had six under pmos-idpf-worktrees/ and three under pmos-microsites-worktrees/,
|
|
5
|
+
* each left behind after its branch was merged. collect(root) removes a worktree only when ALL of these hold, so nothing a person
|
|
6
|
+
* could miss is ever removed:
|
|
7
|
+
* - root is the repository's own folder, and the worktree is another one on a named branch that is not the default branch;
|
|
8
|
+
* - its branch is fully merged: a commit of the default branch (the remote's when there is a remote) contains the branch tip;
|
|
9
|
+
* - the folder holds nothing unsaved: no modified, staged or untracked file;
|
|
10
|
+
* - it has been idle for IDLE_MS: neither its HEAD nor its index has changed in that time (a fresh branch with no commit is "merged"
|
|
11
|
+
* too, and must never be removed the minute it is made);
|
|
12
|
+
* - it is not locked, and inUse(dir) says no session or registered workspace uses it.
|
|
13
|
+
* It runs `git worktree remove` WITHOUT --force, so git itself refuses a dirty folder as a last check. The branch is never deleted. A
|
|
14
|
+
* worktree whose folder is already gone is pruned. Nothing is pushed or merged here.
|
|
15
|
+
*
|
|
16
|
+
* collect(root, { inUse, onRemoved, now, idleMs }) → { removed: [{ dir, branch }], kept: [{ dir, branch, why }] } */
|
|
17
|
+
const fs = require('fs');
|
|
18
|
+
const path = require('path');
|
|
19
|
+
const syncLib = require('./sync');
|
|
20
|
+
const repairLib = require('./folder-repair');
|
|
21
|
+
|
|
22
|
+
const { run } = syncLib;
|
|
23
|
+
const IDLE_MS = 14 * 24 * 60 * 60 * 1000;
|
|
24
|
+
const same = (a, b) => path.resolve(String(a)) === path.resolve(String(b));
|
|
25
|
+
|
|
26
|
+
/** `git worktree list --porcelain` with the flags the plain list drops: [{ dir, branch|null, locked, prunable }]. */
|
|
27
|
+
async function list(root) {
|
|
28
|
+
const r = await run(root, ['worktree', 'list', '--porcelain']);
|
|
29
|
+
if (!r.ok || !r.out) return [];
|
|
30
|
+
const out = []; let cur = null;
|
|
31
|
+
for (const line of r.out.split('\n')) {
|
|
32
|
+
if (line.startsWith('worktree ')) { cur = { dir: line.slice(9).trim(), branch: null, locked: false, prunable: false }; out.push(cur); }
|
|
33
|
+
else if (!cur) continue;
|
|
34
|
+
else if (line.startsWith('branch ')) cur.branch = line.slice(7).trim().replace(/^refs\/heads\//, '');
|
|
35
|
+
else if (line === 'locked' || line.startsWith('locked ')) cur.locked = true;
|
|
36
|
+
else if (line === 'prunable' || line.startsWith('prunable ')) cur.prunable = true;
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** When a worktree was last used: the newest change of its HEAD or index file, in ms; null when it cannot be read. */
|
|
42
|
+
async function lastUsed(dir) {
|
|
43
|
+
const g = await run(dir, ['rev-parse', '--path-format=absolute', '--git-dir']);
|
|
44
|
+
if (!g.ok || !g.out) return null;
|
|
45
|
+
let newest = null;
|
|
46
|
+
for (const f of ['HEAD', 'index']) { try { const t = fs.statSync(path.join(g.out, f)).mtimeMs; if (newest == null || t > newest) newest = t; } catch { /* a missing file says nothing */ } }
|
|
47
|
+
return newest;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function collect(root, { inUse = () => false, onRemoved = () => {}, now = Date.now(), idleMs = IDLE_MS } = {}) {
|
|
51
|
+
const res = { removed: [], kept: [] };
|
|
52
|
+
if (!(await repairLib.isMainTree(root))) return res;
|
|
53
|
+
const s = await syncLib.status(root);
|
|
54
|
+
const remote = s.ok && s.upstream ? s.upstream.split('/')[0] : 'origin';
|
|
55
|
+
const hasRemote = (await run(root, ['remote', 'get-url', remote])).ok;
|
|
56
|
+
const def = hasRemote ? await syncLib.defaultBranchOf(root, remote) : null;
|
|
57
|
+
if (!def) return res;
|
|
58
|
+
|
|
59
|
+
// a worktree whose folder is gone is only a record in the repository: pruning it removes no file
|
|
60
|
+
const trees = await list(root);
|
|
61
|
+
if (trees.some((t) => t.prunable)) await run(root, ['worktree', 'prune']);
|
|
62
|
+
|
|
63
|
+
const mergedInto = (await run(root, ['rev-parse', '--verify', '--quiet', `refs/remotes/${remote}/${def}`])).ok ? `refs/remotes/${remote}/${def}` : `refs/heads/${def}`;
|
|
64
|
+
for (const t of trees) {
|
|
65
|
+
if (same(t.dir, root) || t.prunable) continue;
|
|
66
|
+
const keep = (why) => res.kept.push({ dir: t.dir, branch: t.branch, why });
|
|
67
|
+
if (!t.branch) { keep('no branch'); continue; }
|
|
68
|
+
if (t.branch === def) { keep('the default branch'); continue; }
|
|
69
|
+
if (t.locked) { keep('locked'); continue; }
|
|
70
|
+
if ((await run(root, ['merge-base', '--is-ancestor', `refs/heads/${t.branch}`, mergedInto])).ok !== true) { keep('not merged'); continue; }
|
|
71
|
+
// read the idle time first, and look at the folder without taking an index lock: a status that refreshed the index would reset the clock
|
|
72
|
+
const used = await lastUsed(t.dir);
|
|
73
|
+
const st = await run(t.dir, ['--no-optional-locks', 'status', '--porcelain', '--untracked-files=all']);
|
|
74
|
+
if (!st.ok) { keep('unreadable'); continue; }
|
|
75
|
+
if (st.out) { keep('holds unsaved files'); continue; }
|
|
76
|
+
if (used == null || now - used < idleMs) { keep('used recently'); continue; }
|
|
77
|
+
let busy = false; try { busy = !!inUse(t.dir); } catch { busy = true; }
|
|
78
|
+
if (busy) { keep('in use'); continue; }
|
|
79
|
+
if (!(await run(root, ['worktree', 'remove', t.dir])).ok) { keep('git refused'); continue; }
|
|
80
|
+
res.removed.push({ dir: t.dir, branch: t.branch });
|
|
81
|
+
try { onRemoved(t.dir); } catch { /* the caller's tidy-up is not the removal's business */ }
|
|
82
|
+
}
|
|
83
|
+
return res;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
module.exports = { collect, list, IDLE_MS };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.464.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pmos-workspace",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.464.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@anthropic-ai/sdk": "^1.3.0",
|
package/workspace/package.json
CHANGED
package/workspace/server.js
CHANGED
|
@@ -2073,6 +2073,11 @@ const autoSync = require('./lib/auto-sync').createAutoSync({
|
|
|
2073
2073
|
busy: syncing,
|
|
2074
2074
|
onDone: (root, out) => { boardCache.invalidate(root); try { if (refreshRun) refreshRun.codeRun('sync', { trigger: 'change', result: out && out.ok ? 'done' : 'failed', got: out && out.ok ? (out.message || 'synced') : null, error: out && !out.ok ? out.message || 'the sync failed' : null }); } catch { /* the log is not the sync's business */ } },
|
|
2075
2075
|
label: `${os.hostname()} (auto-sync)`,
|
|
2076
|
+
// finished worktrees are removed (lib/worktree-gc.js) only when no registered workspace owns sessions there; a registered one is forgotten with its folder
|
|
2077
|
+
gcHooks: {
|
|
2078
|
+
inUse: (dir) => { const w = [...workspaces.values()].find((x) => path.resolve(x.root) === path.resolve(dir)); return !!w && !!forgetBlocker(w.id); },
|
|
2079
|
+
onRemoved: (dir) => { const w = [...workspaces.values()].find((x) => path.resolve(x.root) === path.resolve(dir)); if (w) forgetWorkspace(w.id); },
|
|
2080
|
+
},
|
|
2076
2081
|
});
|
|
2077
2082
|
// workspace-data-freshness (R2 to R4): the facts cache is kept in the runtime state folder, and ONE change detector per
|
|
2078
2083
|
// workspace starts the board and facts rebuilds when the repository changes, so nothing is re-read on a clock. The board
|
|
@@ -4835,7 +4840,7 @@ function startPreview({ initiative, repoKey, ws }) {
|
|
|
4835
4840
|
if (initiative && main) {
|
|
4836
4841
|
try { const bi = gitInfo.branchInfo(main.root); if (bi.ok) branches = bi.branches; } catch {}
|
|
4837
4842
|
}
|
|
4838
|
-
const plan = startPolicy.resolveStart({ initiative, trees, branches });
|
|
4843
|
+
const plan = startPolicy.resolveStart({ initiative, trees, branches, profile: main ? syncLib.profileOf(main.root) : undefined });
|
|
4839
4844
|
if (!plan.ok) return plan;
|
|
4840
4845
|
// The literal directory, so the sentence in the UI is checkable rather than a promise.
|
|
4841
4846
|
let dir = null;
|
|
@@ -4855,7 +4860,7 @@ function startWork({ initiative, repoKey, ws, agent, name, profile, origin, init
|
|
|
4855
4860
|
if (initiative && main) {
|
|
4856
4861
|
try { const bi = gitInfo.branchInfo(main.root); if (bi.ok) branches = bi.branches; } catch {}
|
|
4857
4862
|
}
|
|
4858
|
-
const plan = startPolicy.resolveStart({ initiative, trees, branches });
|
|
4863
|
+
const plan = startPolicy.resolveStart({ initiative, trees, branches, profile: main ? syncLib.profileOf(main.root) : undefined });
|
|
4859
4864
|
if (!plan.ok) return plan;
|
|
4860
4865
|
const r = spawnWithBranch({
|
|
4861
4866
|
name: name || initiative || agent || 'shell',
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"modules": [
|
|
11
11
|
"find-browser.test.js",
|
|
12
12
|
"program-worktree.test.js",
|
|
13
|
+
"program-deleted.test.js",
|
|
13
14
|
"own-profile.test.js",
|
|
14
15
|
"stage-tools.test.js",
|
|
15
16
|
"report-template-cadence.test.js",
|
|
@@ -80,6 +81,8 @@
|
|
|
80
81
|
"sync.test.js",
|
|
81
82
|
"auto-sync.test.js",
|
|
82
83
|
"folder-repair.test.js",
|
|
84
|
+
"folder-needs.test.js",
|
|
85
|
+
"worktree-gc.test.js",
|
|
83
86
|
"schedule-cli.test.js",
|
|
84
87
|
"initiative-surface.test.js",
|
|
85
88
|
"guide.test.js",
|
|
@@ -193,6 +196,9 @@
|
|
|
193
196
|
"sync.test.js": 4,
|
|
194
197
|
"auto-sync.test.js": 4,
|
|
195
198
|
"folder-repair.test.js": 4,
|
|
199
|
+
"folder-needs.test.js": 1,
|
|
200
|
+
"worktree-gc.test.js": 3,
|
|
201
|
+
"program-deleted.test.js": 1,
|
|
196
202
|
"schedule-cli.test.js": 3,
|
|
197
203
|
"initiative-surface.test.js": 3,
|
|
198
204
|
"guide.test.js": 1,
|