create-pmos 0.538.0 → 0.540.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 +39 -39
- 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/changelog.json +38 -0
- package/workspace/guide/agent-capabilities.md +9 -5
- package/workspace/guide/agents-act.md +68 -0
- package/workspace/guide/index.md +2 -1
- package/workspace/guide/initiative-driver.md +16 -7
- package/workspace/guide/settings.md +1 -1
- package/workspace/guide/today.md +8 -4
- package/workspace/guide/workflows.md +14 -12
- package/workspace/ini-workflow-test.js +1 -1
- package/workspace/lib/agent-inbox.js +2 -2
- package/workspace/lib/ai-cli.js +12 -1
- package/workspace/lib/ai-guard.js +16 -6
- package/workspace/lib/auto-keep.js +33 -0
- package/workspace/lib/autonomy-cli.js +53 -0
- package/workspace/lib/autonomy.js +234 -0
- package/workspace/lib/bg-queue.js +2 -1
- package/workspace/lib/driver-cli.js +26 -10
- package/workspace/lib/driver-decide.js +76 -8
- package/workspace/lib/driver.js +15 -4
- package/workspace/lib/goal-loop.js +221 -0
- package/workspace/lib/headless.js +75 -1
- package/workspace/lib/job-graph.js +5 -0
- package/workspace/lib/loop-cli.js +84 -0
- package/workspace/lib/pm-lines-needs.js +3 -0
- package/workspace/lib/pmos-verbs.js +6 -1
- package/workspace/lib/route-modules.js +1 -0
- package/workspace/lib/routes-autonomy.js +95 -0
- package/workspace/lib/routes-proposals.js +101 -46
- package/workspace/lib/run-tokens.js +70 -0
- package/workspace/lib/stage-tools.js +11 -1
- package/workspace/lib/today-cli.js +57 -4
- package/workspace/lib/today.js +2 -8
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/cozy-news.js +1 -1
- package/workspace/public/pm/cozy-onboard.js +2 -2
- package/workspace/public/pm/cozy-settings.js +42 -11
- package/workspace/public/pm/home-app.js +10 -1
- package/workspace/public/pm/home-around.js +2 -2
- package/workspace/public/pm/ini-wf.js +3 -3
- package/workspace/public/pm/wf-page.css +26 -15
- package/workspace/public/pm/wf-page.js +96 -72
- package/workspace/public/premium-workflows.html +8 -23
- package/workspace/replaced-tests.json +17 -0
- package/workspace/server.js +33 -16
- package/workspace/test-lists/full-autonomy.json +11 -0
- package/workspace/test-run.js +3 -0
- package/workspace/workflows-setup-test.js +50 -50
|
@@ -68,6 +68,101 @@ const W = {
|
|
|
68
68
|
return RB.taskEdit(ctx, body, g);
|
|
69
69
|
},
|
|
70
70
|
};
|
|
71
|
+
/** Keep these proposals: their writes, then one `keep` line. extra: D106 { auto: true, group } for a change an agent applied by itself. */
|
|
72
|
+
function keepCore(ctx, p, g, f, ini, want, choices = {}, extra = {}) {
|
|
73
|
+
const dir = dirOf(ctx, p.w), wrote = [], keptIds = [], outbox = [];
|
|
74
|
+
let plans = 0;
|
|
75
|
+
for (const x of want) {
|
|
76
|
+
if (x.group === 'links') {
|
|
77
|
+
const r = TLR.acceptFor ? TLR.acceptFor(ctx, p, g, ini, [x.link.id]) : null;
|
|
78
|
+
if (r && r.linked) for (const l of r.linked) wrote.push({ op: 'link', from: l.from, to: l.to, why: x.why });
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const w = applyOne(ctx, p, g, f, ini, x, choices, outbox);
|
|
82
|
+
wrote.push(...w);
|
|
83
|
+
if (x.group === 'dates' && x.plan && w.some((y) => y.op === 'dates')) plans++;
|
|
84
|
+
keptIds.push(x.group === 'dates' ? x.id + ':' + x.sig : x.id);
|
|
85
|
+
}
|
|
86
|
+
for (const a of outbox) { const id = toOutbox(ctx, a); if (id) wrote.push({ op: 'outbox', task: a.task, entry: id, why: a.text }); }
|
|
87
|
+
const batch = PR.newBatch();
|
|
88
|
+
PR.append(dir, g.actor, { kind: 'keep', ini, board: p.board.id, batch, ids: keptIds, wrote, ...extra });
|
|
89
|
+
return { batch, wrote, plans, keptIds };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Undo one kept batch. → { ok, back, kept } | { ok: false, status, error }. A task changed since keeps its change. */
|
|
93
|
+
function undoCore(ctx, p, g, id) {
|
|
94
|
+
const dir = dirOf(ctx, p.w), F = PR.read(dir);
|
|
95
|
+
const k = F.kept.find((x) => x.batch === id);
|
|
96
|
+
if (!k || F.undone.has(id)) return { ok: false, status: 409, error: 'Nothing to undo' };
|
|
97
|
+
const f = TLR.frame(ctx, p.w, p.board);
|
|
98
|
+
if (!f) return { ok: false, status: 202, error: 'The board is still being read. Try again in a moment.' };
|
|
99
|
+
let back = 0, kept = 0;
|
|
100
|
+
for (const w of k.wrote.slice().reverse()) {
|
|
101
|
+
const xi = w.task ? f.byUid.get(w.task) : null, t = w.task ? f.T.get(w.task) : null;
|
|
102
|
+
let r = null;
|
|
103
|
+
if (w.op === 'add') { if (xi && (xi.status || 'To do') === 'To do') r = RB.taskDelete(ctx, { ws: p.w.id, board: p.board.id, task: w.task, why: 'Undo: Claude ✦ added it' }, g); }
|
|
104
|
+
// a task changed since keeps its change: Undo never overwrites a later edit
|
|
105
|
+
else if (w.op === 'dates') { if (xi && (xi.end || '') === (w.to.due || xi.end || '')) r = W.dates(ctx, p, g, w.task, xi, { start: w.from.start, due: w.from.due }); }
|
|
106
|
+
else if (w.op === 'state') { if (t && t.status === w.to) r = RB.taskState(ctx, { ws: p.w.id, board: p.board.id, task: w.task, state: w.from || 'To do', why: 'Undo' }, g); }
|
|
107
|
+
else if (w.op === 'rename') { if (t && t.title === w.to) r = RB.writeAs(ctx, '/api/boards/tasks/rename', { ws: p.w.id, board: p.board.id, task: w.task, title: w.from }, g); }
|
|
108
|
+
else if (w.op === 'notes') { if (xi && (xi.notes || '') === w.to) r = RB.taskEdit(ctx, { ws: p.w.id, board: p.board.id, task: w.task, notes: w.from || '' }, g); }
|
|
109
|
+
else if (w.op === 'stage') { const row = rowOf(f, k.ini); if (row && row.stage === w.to && w.from) r = RB.move(ctx, { ws: p.w.id, board: p.board.id, id: k.ini, to: w.from, why: 'Undo: Claude ✦ moved it' }, g); }
|
|
110
|
+
else if (w.op === 'epics') r = RB.writeAs(ctx, '/api/boards/ini-epics', { ws: p.w.id, board: p.board.id, id: k.ini, epics: w.from }, g);
|
|
111
|
+
else if (w.op === 'unlink') { TL.append(dir, g.actor, { kind: 'link', board: p.board.id, ini: k.ini, from: w.from, to: w.to, type: w.link.type, lag: w.link.lag, source: w.link.source }); back++; continue; }
|
|
112
|
+
else if (w.op === 'link') { TL.append(dir, g.actor, { kind: 'unlink', from: w.from, to: w.to }); back++; continue; }
|
|
113
|
+
else if (w.op === 'prd') { try { const file = path.resolve(p.w.root, w.file), text = fs.readFileSync(file, 'utf8'); if (text.includes(w.to)) { fs.writeFileSync(file, text.split(w.to).join(w.from)); back++; } else kept++; } catch { kept++; } continue; }
|
|
114
|
+
else if (w.op === 'doc' || w.op === 'linked' || w.op === 'ran') { back++; continue; } // the fold leaves an undone batch out
|
|
115
|
+
else if (w.op === 'outbox') { kept++; continue; } // a drafted comment waits in the outbox, where the PM drops it
|
|
116
|
+
else if (w.op === 'description') { const r2 = require('./initiative-writer.js').restoreDescription(p.w.root, k.ini, w.from || '', w.to || '', { actor: g.actor }); if (r2.ok && !r2.kept) back++; else kept++; continue; } // a record edited since keeps its edit
|
|
117
|
+
else if (w.op === 'outcome') { const r2 = require('./initiative-writer.js').restoreOutcome(p.w.root, k.ini, w.from || {}, w.to || {}, { actor: g.actor }); if (r2.ok && !r2.kept) back++; else kept++; continue; } // a record edited since keeps its edit
|
|
118
|
+
if (r && r.body && r.body.ok) back++; else kept++;
|
|
119
|
+
}
|
|
120
|
+
PR.append(dir, g.actor, { kind: 'undo', batch: id });
|
|
121
|
+
// D106: the Undo of a change an agent applied by itself is a setback of its job (lib/autonomy.js), which may demote the job
|
|
122
|
+
const line = PR.readLines(PR.ledgerFile(dir)).find((l) => l.kind === 'keep' && l.batch === id);
|
|
123
|
+
let demoted = null;
|
|
124
|
+
if (line && line.auto === true && line.group) {
|
|
125
|
+
const A = require('./autonomy.js');
|
|
126
|
+
demoted = A.recordSetback(dir, { job: `propose:${line.group}`, product: p.w.id, ref: id, kind: 'undo' }).demoted;
|
|
127
|
+
try { fs.mkdirSync(ctx.runtimeDir || dir, { recursive: true }); fs.appendFileSync(path.join(ctx.runtimeDir || dir, 'corrections.jsonl'), JSON.stringify({ type: 'correction', kind: 'reject', reason: 'propose:undo', run: null, counted: true, at: new Date().toISOString(), record: { kind: 'correction', reason: 'propose:undo', by: g.actor && g.actor.by } }) + '\n'); } catch { /* the ledger holds the undo */ }
|
|
128
|
+
}
|
|
129
|
+
return { ok: true, back, kept, demoted };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** D106: apply by itself every open class A or B proposal on one board of a workspace, one batch per proposal, each with Undo.
|
|
133
|
+
* Class C (a stage found elsewhere, a maybe, a duplicate, the state of a Jira ticket), a job that is demoted and a board whose Driver
|
|
134
|
+
* mode is not auto stay for the PM. → { applied: [{ ini, batch, group, title }], held: n } */
|
|
135
|
+
function autoKeep(ctx, w, { modeOf = () => 'auto', now } = {}) {
|
|
136
|
+
const A = require('./autonomy.js');
|
|
137
|
+
const dir = dirOf(ctx, w);
|
|
138
|
+
const out = { applied: [], held: 0 };
|
|
139
|
+
if (!dir) return out;
|
|
140
|
+
const g = { ok: true, actor: { by: 'agent:auto' } };
|
|
141
|
+
const fr = RB.frameFor(ctx, w);
|
|
142
|
+
for (const board of fr.boards || []) {
|
|
143
|
+
const p = { w, fr, board, file: null };
|
|
144
|
+
const f = TLR.frame(ctx, w, board, { derive: true });
|
|
145
|
+
if (!f) continue;
|
|
146
|
+
for (const row of f.rows || []) {
|
|
147
|
+
const ini = row.id;
|
|
148
|
+
if (!ini) continue;
|
|
149
|
+
const v = view(ctx, p, ini, f, { grillAll: true });
|
|
150
|
+
if (!v) continue;
|
|
151
|
+
for (const x of v.groups.flatMap((gr) => gr.props)) {
|
|
152
|
+
const cls = A.classOfProposal(x);
|
|
153
|
+
const d = A.decide({ stateDir: dir, job: `propose:${x.group}`, product: w.id, cls, mode: modeOf(board.id), undoable: true, now, settingsDir: ctx.runtimeDir || null });
|
|
154
|
+
if (!d.apply) { out.held++; continue; }
|
|
155
|
+
try {
|
|
156
|
+
const r = keepCore(ctx, p, g, f, ini, [x], {}, { auto: true, group: x.group });
|
|
157
|
+
A.recordApplied(dir, { job: `propose:${x.group}`, product: w.id, ref: r.batch, title: x.title || x.why || x.group, cls }, { now });
|
|
158
|
+
out.applied.push({ ini, batch: r.batch, group: x.group, title: x.title || x.why || '' });
|
|
159
|
+
} catch { out.held++; }
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return out;
|
|
164
|
+
}
|
|
165
|
+
|
|
71
166
|
/** The writes of one proposal. → [write] (each { op, ... } that landed). sk: the item ids the PM left out (✕ on one item). */
|
|
72
167
|
function applyOne(ctx, p, g, f, ini, x, choices, outbox) {
|
|
73
168
|
const wrote = [], why = x.why, source = srcText(x);
|
|
@@ -254,23 +349,8 @@ const WRITES = {
|
|
|
254
349
|
// ✓ in the header keeps all Claude is sure of: Check these, Not placed and Jira-only proposals wait for their own ✓
|
|
255
350
|
const want = body.all === true ? all.filter((x) => x.section === 'sure') : all.filter((x) => ids.includes(x.id));
|
|
256
351
|
if (!want.length) return fail(ctx, res, 409, 'Those proposals are no longer open');
|
|
257
|
-
const dir = dirOf(ctx, p.w)
|
|
258
|
-
|
|
259
|
-
const choices = isObj(body.choices) ? body.choices : {};
|
|
260
|
-
for (const x of want) {
|
|
261
|
-
if (x.group === 'links') {
|
|
262
|
-
const r = TLR.acceptFor ? TLR.acceptFor(ctx, p, g, ini, [x.link.id]) : null;
|
|
263
|
-
if (r && r.linked) for (const l of r.linked) wrote.push({ op: 'link', from: l.from, to: l.to, why: x.why });
|
|
264
|
-
continue;
|
|
265
|
-
}
|
|
266
|
-
const w = applyOne(ctx, p, g, f, ini, x, choices, outbox);
|
|
267
|
-
wrote.push(...w);
|
|
268
|
-
if (x.group === 'dates' && x.plan && w.some((y) => y.op === 'dates')) plans++;
|
|
269
|
-
keptIds.push(x.group === 'dates' ? x.id + ':' + x.sig : x.id);
|
|
270
|
-
}
|
|
271
|
-
for (const a of outbox) { const id = toOutbox(ctx, a); if (id) wrote.push({ op: 'outbox', task: a.task, entry: id, why: a.text }); }
|
|
272
|
-
const batch = PR.newBatch();
|
|
273
|
-
PR.append(dir, g.actor, { kind: 'keep', ini, board: p.board.id, batch, ids: keptIds, wrote });
|
|
352
|
+
const dir = dirOf(ctx, p.w);
|
|
353
|
+
const { batch, wrote, plans } = keepCore(ctx, p, g, f, ini, want, isObj(body.choices) ? body.choices : {});
|
|
274
354
|
const v2 = view(ctx, p, ini);
|
|
275
355
|
const left = v2 ? v2.groups.flatMap((x) => x.props).filter((x) => x.section === 'check').length : 0;
|
|
276
356
|
ctx.json(res, { ok: true, batch, said: saidOf(wrote, plans, body.all === true ? left : 0), counts: { wrote: wrote.length }, props: v2, found: PR.foundOf(PR.read(dir), ini) });
|
|
@@ -298,34 +378,9 @@ const WRITES = {
|
|
|
298
378
|
ctx.json(res, { ok: true });
|
|
299
379
|
},
|
|
300
380
|
'/api/proposals/undo': (ctx, res, body, g, p) => {
|
|
301
|
-
const
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
const f = TLR.frame(ctx, p.w, p.board);
|
|
305
|
-
if (!f) return fail(ctx, res, 202, 'The board is still being read. Try again in a moment.');
|
|
306
|
-
let back = 0, kept = 0;
|
|
307
|
-
for (const w of k.wrote.slice().reverse()) {
|
|
308
|
-
const xi = w.task ? f.byUid.get(w.task) : null, t = w.task ? f.T.get(w.task) : null;
|
|
309
|
-
let r = null;
|
|
310
|
-
if (w.op === 'add') { if (xi && (xi.status || 'To do') === 'To do') r = RB.taskDelete(ctx, { ws: p.w.id, board: p.board.id, task: w.task, why: 'Undo: Claude ✦ added it' }, g); }
|
|
311
|
-
// a task changed since keeps its change: Undo never overwrites a later edit
|
|
312
|
-
else if (w.op === 'dates') { if (xi && (xi.end || '') === (w.to.due || xi.end || '')) r = W.dates(ctx, p, g, w.task, xi, { start: w.from.start, due: w.from.due }); }
|
|
313
|
-
else if (w.op === 'state') { if (t && t.status === w.to) r = RB.taskState(ctx, { ws: p.w.id, board: p.board.id, task: w.task, state: w.from || 'To do', why: 'Undo' }, g); }
|
|
314
|
-
else if (w.op === 'rename') { if (t && t.title === w.to) r = RB.writeAs(ctx, '/api/boards/tasks/rename', { ws: p.w.id, board: p.board.id, task: w.task, title: w.from }, g); }
|
|
315
|
-
else if (w.op === 'notes') { if (xi && (xi.notes || '') === w.to) r = RB.taskEdit(ctx, { ws: p.w.id, board: p.board.id, task: w.task, notes: w.from || '' }, g); }
|
|
316
|
-
else if (w.op === 'stage') { const row = rowOf(f, k.ini); if (row && row.stage === w.to && w.from) r = RB.move(ctx, { ws: p.w.id, board: p.board.id, id: k.ini, to: w.from, why: 'Undo: Claude ✦ moved it' }, g); }
|
|
317
|
-
else if (w.op === 'epics') r = RB.writeAs(ctx, '/api/boards/ini-epics', { ws: p.w.id, board: p.board.id, id: k.ini, epics: w.from }, g);
|
|
318
|
-
else if (w.op === 'unlink') { TL.append(dir, g.actor, { kind: 'link', board: p.board.id, ini: k.ini, from: w.from, to: w.to, type: w.link.type, lag: w.link.lag, source: w.link.source }); back++; continue; }
|
|
319
|
-
else if (w.op === 'link') { TL.append(dir, g.actor, { kind: 'unlink', from: w.from, to: w.to }); back++; continue; }
|
|
320
|
-
else if (w.op === 'prd') { try { const file = path.resolve(p.w.root, w.file), text = fs.readFileSync(file, 'utf8'); if (text.includes(w.to)) { fs.writeFileSync(file, text.split(w.to).join(w.from)); back++; } else kept++; } catch { kept++; } continue; }
|
|
321
|
-
else if (w.op === 'doc' || w.op === 'linked' || w.op === 'ran') { back++; continue; } // the fold leaves an undone batch out
|
|
322
|
-
else if (w.op === 'outbox') { kept++; continue; } // a drafted comment waits in the outbox, where the PM drops it
|
|
323
|
-
else if (w.op === 'description') { const r2 = require('./initiative-writer.js').restoreDescription(p.w.root, k.ini, w.from || '', w.to || '', { actor: g.actor }); if (r2.ok && !r2.kept) back++; else kept++; continue; } // a record edited since keeps its edit
|
|
324
|
-
else if (w.op === 'outcome') { const r2 = require('./initiative-writer.js').restoreOutcome(p.w.root, k.ini, w.from || {}, w.to || {}, { actor: g.actor }); if (r2.ok && !r2.kept) back++; else kept++; continue; } // a record edited since keeps its edit
|
|
325
|
-
if (r && r.body && r.body.ok) back++; else kept++;
|
|
326
|
-
}
|
|
327
|
-
PR.append(dir, g.actor, { kind: 'undo', batch: id });
|
|
328
|
-
ctx.json(res, { ok: true, back, kept });
|
|
381
|
+
const r = undoCore(ctx, p, g, String(body.batch || ''));
|
|
382
|
+
if (!r.ok) return fail(ctx, res, r.status, r.error);
|
|
383
|
+
ctx.json(res, { ok: true, back: r.back, kept: r.kept, ...(r.demoted ? { demoted: r.demoted } : {}) });
|
|
329
384
|
},
|
|
330
385
|
'/api/proposals/stop': (ctx, res, body, g, p) => {
|
|
331
386
|
const ini = String(body.initiative || '');
|
|
@@ -348,7 +403,7 @@ const WRITES = {
|
|
|
348
403
|
|
|
349
404
|
module.exports = {
|
|
350
405
|
prefixes: ['/api/proposals'],
|
|
351
|
-
viewFor, saidOf, prdRename,
|
|
406
|
+
viewFor, saidOf, prdRename, keepCore, undoCore, autoKeep,
|
|
352
407
|
handle: async (req, res, url, ctx) => {
|
|
353
408
|
const p0 = url.pathname;
|
|
354
409
|
if (req.method === 'GET') {
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* run-tokens.js — the token log of background runs (token efficiency build, Wawan 2026-11-08).
|
|
3
|
+
*
|
|
4
|
+
* PMOS did not keep what a background run cost: lib/headless.js parseResult read the cost and dropped the token counts. Each finished
|
|
5
|
+
* headless run now writes one line to <state>/run-tokens.jsonl:
|
|
6
|
+
* { at, kind, origin, model, lean, turns, input, cacheCreate, cacheRead, output, costUsd, ok }
|
|
7
|
+
* origin is the part of the session origin before its first ':' (`propose`, `grill`, `schedule`), never an id or a prompt. No line holds
|
|
8
|
+
* a prompt, an answer or a key.
|
|
9
|
+
*
|
|
10
|
+
* record(stateDir, { kind, origin, lean, result, ok }) → the line written, or null (no tokens in the result: nothing is written)
|
|
11
|
+
* read(stateDir, { sinceMs?, limit? }) → [line]
|
|
12
|
+
* summary(stateDir, { now?, days? }) → { days, runs, rows: [{ kind, lean, runs, turns, context, output, costUsd, perRun }] }
|
|
13
|
+
* context = input + cacheCreate + cacheRead, the tokens the runs read; perRun = context / runs, rounded. One row per kind and launch
|
|
14
|
+
* (lean or full), so the before and after of the lean launch sit side by side. `pmos ai status` shows it.
|
|
15
|
+
*
|
|
16
|
+
* The log never stops a run: a failed append is lost, never thrown. */
|
|
17
|
+
const fs = require('fs');
|
|
18
|
+
const path = require('path');
|
|
19
|
+
|
|
20
|
+
const FILE = 'run-tokens.jsonl';
|
|
21
|
+
const DAY = 86400000;
|
|
22
|
+
const num = (v) => (Number.isFinite(v) && v >= 0 ? v : 0);
|
|
23
|
+
|
|
24
|
+
function record(stateDir, { kind, origin, lean = false, result, ok = null } = {}) {
|
|
25
|
+
const t = result && result.tokens;
|
|
26
|
+
if (!stateDir || !t) return null;
|
|
27
|
+
const line = {
|
|
28
|
+
at: new Date().toISOString(),
|
|
29
|
+
kind: String(kind || ''),
|
|
30
|
+
origin: String(origin || '').split(':')[0].slice(0, 40) || null,
|
|
31
|
+
model: result.model || null,
|
|
32
|
+
lean: !!lean,
|
|
33
|
+
turns: Number.isFinite(result.turns) ? result.turns : null,
|
|
34
|
+
input: num(t.input), cacheCreate: num(t.cacheCreate), cacheRead: num(t.cacheRead), output: num(t.output),
|
|
35
|
+
costUsd: Number.isFinite(result.costUsd) ? Math.round(result.costUsd * 10000) / 10000 : null,
|
|
36
|
+
ok: ok == null ? null : !!ok,
|
|
37
|
+
};
|
|
38
|
+
try {
|
|
39
|
+
fs.mkdirSync(stateDir, { recursive: true });
|
|
40
|
+
fs.appendFileSync(path.join(stateDir, FILE), JSON.stringify(line) + '\n', { mode: 0o600 });
|
|
41
|
+
} catch { return null; }
|
|
42
|
+
return line;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function read(stateDir, { sinceMs = 0, limit = 5000 } = {}) {
|
|
46
|
+
let text = '';
|
|
47
|
+
try { text = fs.readFileSync(path.join(stateDir, FILE), 'utf8'); } catch { return []; }
|
|
48
|
+
const out = [];
|
|
49
|
+
for (const s of text.split('\n')) {
|
|
50
|
+
if (!s.trim()) continue;
|
|
51
|
+
try { const o = JSON.parse(s); if (o && (!sinceMs || Date.parse(o.at) >= sinceMs)) out.push(o); } catch { /* a torn line */ }
|
|
52
|
+
}
|
|
53
|
+
return out.slice(-limit);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function summary(stateDir, { now = Date.now(), days = 7 } = {}) {
|
|
57
|
+
const lines = read(stateDir, { sinceMs: now - days * DAY });
|
|
58
|
+
const by = new Map();
|
|
59
|
+
for (const l of lines) {
|
|
60
|
+
const k = `${l.kind}\u0000${l.lean ? 1 : 0}`;
|
|
61
|
+
const r = by.get(k) || { kind: l.kind, lean: !!l.lean, runs: 0, turns: 0, context: 0, output: 0, costUsd: 0 };
|
|
62
|
+
r.runs++; r.turns += num(l.turns); r.context += num(l.input) + num(l.cacheCreate) + num(l.cacheRead); r.output += num(l.output); r.costUsd += num(l.costUsd);
|
|
63
|
+
by.set(k, r);
|
|
64
|
+
}
|
|
65
|
+
const rows = [...by.values()].map((r) => ({ ...r, costUsd: Math.round(r.costUsd * 100) / 100, perRun: Math.round(r.context / r.runs) }))
|
|
66
|
+
.sort((a, b) => b.context - a.context || a.kind.localeCompare(b.kind) || Number(a.lean) - Number(b.lean));
|
|
67
|
+
return { days, runs: lines.length, rows };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
module.exports = { FILE, record, read, summary };
|
|
@@ -80,6 +80,8 @@ function readLedger(file) {
|
|
|
80
80
|
if (!raw.trim()) continue;
|
|
81
81
|
let e;
|
|
82
82
|
try { e = JSON.parse(raw); } catch { continue; }
|
|
83
|
+
// D106: a `clear` line takes a tool's record away again (the Undo of a record an agent wrote where there was none before)
|
|
84
|
+
if (isObj(e) && e.ev === 'clear' && typeof e.initiative === 'string' && out.has(e.initiative)) { out.get(e.initiative).delete(e.tool); continue; }
|
|
83
85
|
if (!isObj(e) || e.ev !== 'tool' || typeof e.initiative !== 'string' || !e.initiative) continue;
|
|
84
86
|
const c = checkData(e.tool, e.data);
|
|
85
87
|
if (!c.ok) continue;
|
|
@@ -89,6 +91,14 @@ function readLedger(file) {
|
|
|
89
91
|
return out;
|
|
90
92
|
}
|
|
91
93
|
|
|
94
|
+
/** D106: take a tool's record away (the Undo of an agent's first record of it). One `clear` line; the fold drops the record. */
|
|
95
|
+
function clearTool(file, { initiative, tool }, actor, { now } = {}) {
|
|
96
|
+
const line = { v: 1, at: new Date(now == null ? Date.now() : now).toISOString(), by: (actor && actor.by) || 'pm:unknown', ev: 'clear', initiative, tool };
|
|
97
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
98
|
+
fs.appendFileSync(file, JSON.stringify(line) + '\n');
|
|
99
|
+
return line;
|
|
100
|
+
}
|
|
101
|
+
|
|
92
102
|
function riceScore(d) {
|
|
93
103
|
if (!d || !num(d.effort) || d.effort <= 0) return null;
|
|
94
104
|
return Math.round((d.reach * d.impact * (d.confidence / 100) / d.effort) * 10) / 10;
|
|
@@ -205,4 +215,4 @@ function burndown(tickets, { sprint: name, today } = {}) {
|
|
|
205
215
|
};
|
|
206
216
|
}
|
|
207
217
|
|
|
208
|
-
module.exports = { LEDGER, TOOLS, IMPACTS, KILL_STATES, LIMITS, checkData, readLedger, recordsOf, appendTool, riceScore, riceRank, buildDeliverOn, burndown, pickSprint };
|
|
218
|
+
module.exports = { LEDGER, TOOLS, IMPACTS, KILL_STATES, LIMITS, checkData, readLedger, recordsOf, appendTool, clearTool, riceScore, riceRank, buildDeliverOn, burndown, pickSprint };
|
|
@@ -19,9 +19,12 @@ const COMMANDS = { today: [] };
|
|
|
19
19
|
const USAGE = [
|
|
20
20
|
'usage: pmos today [--ws <id>] [--json]',
|
|
21
21
|
' pmos today --root <dir> [--json] [--wait]',
|
|
22
|
-
'
|
|
23
|
-
'
|
|
24
|
-
'
|
|
22
|
+
'With a workspace server running, prints Your move: the list Home shows, in the same order (public/pm/move-rank.js rankMove):',
|
|
23
|
+
'an overdue outcome verdict, a grill finding on shipped work, a meeting change, a finding on work ahead, a key result with no',
|
|
24
|
+
'reading, then the rest Claude proposes, one row per initiative. Rows older than 14 days fold under "Older".',
|
|
25
|
+
'Without a server it reads the repository and prints the Today cards, ranked by kind (1 a gate is owed, 2 a session is',
|
|
26
|
+
'waiting, 3 a step was returned to you, 4 work to check, 5 a breakdown to keep, 6 a capture, 7 a cycle review, 8 needs',
|
|
27
|
+
'repair). It does not read sessions then.',
|
|
25
28
|
'Without a server the Cycle review and missing-anchor cards need the initiative records read, which takes time: they show',
|
|
26
29
|
'as pending. Add --wait to read them now (about a quarter of a second per record).',
|
|
27
30
|
];
|
|
@@ -35,6 +38,46 @@ function repoRoot(cwd) {
|
|
|
35
38
|
catch { return cwd; }
|
|
36
39
|
}
|
|
37
40
|
|
|
41
|
+
/* YOUR MOVE (UI grill item 9, "one truth for what needs me"): with a server, `pmos today` ranks with the function Home's Your move uses,
|
|
42
|
+
* on the answers Home reads: the board with its ✦ (GET /api/board-premium), the programs (GET /api/programs) and the product's GET
|
|
43
|
+
* /api/your-move. The board derives in the background (202 "reading"): it asks again for up to WAIT_MS, then falls back to the cards. */
|
|
44
|
+
const WAIT_MS = 8000;
|
|
45
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
46
|
+
async function moveOf(call, ws, { wait = WAIT_MS } = {}) {
|
|
47
|
+
const q = '?ws=' + encodeURIComponent(ws);
|
|
48
|
+
let b = null;
|
|
49
|
+
for (const t0 = Date.now(); ;) {
|
|
50
|
+
b = await call('GET', '/api/board-premium' + q);
|
|
51
|
+
if (!b || b.ok === false || b.state !== 'reading' || Date.now() - t0 >= wait) break;
|
|
52
|
+
await sleep(500);
|
|
53
|
+
}
|
|
54
|
+
if (!b || !b.ok || !b.model) return null;
|
|
55
|
+
const M = b.model, I = M.initiatives || {};
|
|
56
|
+
const rows = (I.list && I.list.rows) || M.rows || [];
|
|
57
|
+
const pg = await call('GET', '/api/programs');
|
|
58
|
+
const ym = await call('GET', '/api/your-move' + q);
|
|
59
|
+
const MR = await import(require('url').pathToFileURL(path.join(__dirname, '..', 'public', 'pm', 'move-rank.js')).href);
|
|
60
|
+
const r = MR.rankMove({
|
|
61
|
+
products: [{ ws, name: M.name || '', board: (M.board && M.board.id) || '', rows }],
|
|
62
|
+
programs: (pg && pg.ok && pg.programs) || [],
|
|
63
|
+
move: ym && ym.ok ? { [ws]: { verdicts: ym.verdicts || [], kr: ym.kr || null } } : {},
|
|
64
|
+
calls: [], now: Date.now(),
|
|
65
|
+
});
|
|
66
|
+
const slim = (x) => ({ key: x.key, rank: x.rank, kind: x.kind, title: x.title, sub: x.sub || '', tag: x.tag || '', age: x.age || '', ini: x.ini || null, yes: x.yes || '', alt: x.alt || '' });
|
|
67
|
+
return { ok: true, ws, source: 'your-move', count: r.rows.length, rows: r.rows.map(slim), older: r.older.map(slim) };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function printMove(say, mv, cards) {
|
|
71
|
+
const waiting = ((cards && cards.cards) || []).filter((c) => c.kind === 2);
|
|
72
|
+
const n = mv.count + waiting.length;
|
|
73
|
+
say(`${n} ${n === 1 ? 'needs' : 'need'} you`);
|
|
74
|
+
for (const r of mv.rows) say(`· ${r.title}${r.sub ? ' — ' + r.sub : ''}${r.age ? ' · ' + r.age : ''}${r.ini ? ' · ' + r.ini : ''}`);
|
|
75
|
+
for (const c of waiting) say(`· ${c.cause}${c.initiative_id ? ' · ' + c.initiative_id : ''}`);
|
|
76
|
+
if (mv.older.length) say(`Older: ${mv.older.length} more, filed more than 14 days ago.`);
|
|
77
|
+
for (const bn of (cards && cards.banner) || []) say(`! ${bn.source}: ${bn.error}`);
|
|
78
|
+
if (!n) say(mv.older.length ? 'Nothing new needs you.' : 'Nothing needs you.');
|
|
79
|
+
}
|
|
80
|
+
|
|
38
81
|
function print(say, out, { sessions }) {
|
|
39
82
|
say(`${out.count} ${out.count === 1 ? 'needs' : 'need'} you`);
|
|
40
83
|
for (const c of out.cards) {
|
|
@@ -91,9 +134,19 @@ async function run(argv, { say, call }) {
|
|
|
91
134
|
} finally { rowsLib.setBackground(was); }
|
|
92
135
|
}
|
|
93
136
|
if (!out.ok) { say('✗ ' + out.error); return 1; }
|
|
137
|
+
if (sessions) {
|
|
138
|
+
let mv = null;
|
|
139
|
+
try { mv = await moveOf(call, out.ws); } catch { mv = null; }
|
|
140
|
+
if (mv) {
|
|
141
|
+
const waiting = (out.cards || []).filter((c) => c.kind === 2);
|
|
142
|
+
if (f.json) say(JSON.stringify({ ...mv, sessions: waiting, banner: out.banner || [] }));
|
|
143
|
+
else printMove(say, mv, out);
|
|
144
|
+
return 0;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
94
147
|
if (f.json) say(JSON.stringify(out));
|
|
95
148
|
else print(say, out, { sessions });
|
|
96
149
|
return 0;
|
|
97
150
|
}
|
|
98
151
|
|
|
99
|
-
module.exports = { run, COMMANDS, USAGE };
|
|
152
|
+
module.exports = { run, COMMANDS, USAGE, moveOf };
|
package/workspace/lib/today.js
CHANGED
|
@@ -262,14 +262,8 @@ function gather(w, { stateDir = stateDirOf(w.root), sessions = [], registered }
|
|
|
262
262
|
const seen = new Set(queue.map((n) => n.run_id));
|
|
263
263
|
for (const n of queue) rows.push(n);
|
|
264
264
|
if (stateDir) {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
for (const e of readLedger(w, stateDir, 'evals.jsonl')) {
|
|
268
|
-
if (!e || !e.run_id || settled.has(e.run_id) || seen.has(e.run_id)) continue;
|
|
269
|
-
rows.push({ run_id: e.run_id, initiative_id: e.initiative_id || null, kind: 'accept', derived: true,
|
|
270
|
-
question: 'Acceptance Gate open', doc: e.rubric_path || e.rubric || null,
|
|
271
|
-
detail: { verdict: e.verdict ? String(e.verdict) : null, score: e.score != null ? e.score : null } });
|
|
272
|
-
}
|
|
265
|
+
// D94 retired the Acceptance Gate as a step before each merge, and D106 lets agents act: an eval with no acceptance is not a card
|
|
266
|
+
// (on 2 Nov 33 of 176 Today items were "Acceptance is owed"). A run the PM RETURNED still shows, below.
|
|
273
267
|
const disposed = new Set();
|
|
274
268
|
for (const c of readLedger(w, stateDir, 'outcome_checks.jsonl')) if (c && c.initiative_id) disposed.add(c.initiative_id);
|
|
275
269
|
const today = new Date().toISOString().slice(0, 10);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.540.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.540.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@anthropic-ai/sdk": "^1.3.0",
|
package/workspace/package.json
CHANGED
|
@@ -251,7 +251,7 @@ function openBridge(it, o = {}) {
|
|
|
251
251
|
return true;
|
|
252
252
|
};
|
|
253
253
|
vwOpen({ id, kind: 'Claude proposes', title: it.title || 'Move to the new workflow', icon: SPARK, sub: ['Claude noticed', it.at ? ago(new Date(it.at).toISOString()) : ''].filter(Boolean).join(' · '), fresh: !!o.fresh,
|
|
254
|
-
more: [{ label: 'Change the bridge in Settings', on: () =>
|
|
254
|
+
more: [{ label: 'Change the bridge in Settings', on: () => import('./cozy-settings.js').then((M) => M.openSettings('workflows', { wf: it.wf.id })) }], // Settings › Workspaces › Workflows, in place (UI grill U1)
|
|
255
255
|
render: (body) => {
|
|
256
256
|
body.classList.add('ev-card-b');
|
|
257
257
|
draw(body);
|
|
@@ -274,9 +274,9 @@ export function mountOnboard(host, { ws = '', done = false } = {}) {
|
|
|
274
274
|
} else if (a.startsWith('f:')) {
|
|
275
275
|
const r = await post('fundamental', { key: a.slice(2) });
|
|
276
276
|
if (!r.ok) S.note = r.error;
|
|
277
|
-
else if (r.follow === 'settings') location.assign('/premium
|
|
277
|
+
else if (r.follow === 'settings') location.assign('/premium.html?settings=workflows&ws=' + encodeURIComponent(p.done.ws)); // Settings › Workspaces › Workflows (UI grill U1)
|
|
278
278
|
else if (r.follow === 'context') { home('Walk me through the project context you saved, and change what I say'); return; }
|
|
279
|
-
} else if (a === 'wf-new') { location.assign('/premium
|
|
279
|
+
} else if (a === 'wf-new') { location.assign('/premium.html?settings=workflows&new=1&ws=' + encodeURIComponent(p.done.ws)); return; } // Home's chat on New workflow
|
|
280
280
|
else if (a === 'first-yes') { go('&first=draft'); return; }
|
|
281
281
|
else if (a === 'first-no') { go('&first=none'); return; } // B2: the reveal with no draft, and nothing written
|
|
282
282
|
} catch (e) { S.note = e.message || 'That did not finish. Try again.'; }
|
|
@@ -22,7 +22,9 @@
|
|
|
22
22
|
* (what PMOS reads on its own, the connectors your sessions have; GET and POST /api/proactive/settings) fold into one row.
|
|
23
23
|
* Workspaces the repositories PMOS works in (GET and POST /api/workspaces, POST /api/workspaces/forget; the folder is never touched),
|
|
24
24
|
* then the row "Workflows ›" (U4; it was a section of its own that linked out): the stages each kind of initiative goes
|
|
25
|
-
* through (pm/wf-page.js, D99). It opens
|
|
25
|
+
* through (pm/wf-page.js, D99). It opens as a sub-panel here, the Settings dialog widened to the window (UI grill U1: the
|
|
26
|
+
* page /premium-workflows.html went; its address redirects to Home with ?settings=workflows). A stage opens in the Viewer,
|
|
27
|
+
* docked inside this dialog while the panel shows; + New workflow starts Home's own chat.
|
|
26
28
|
* Updates the versions and Check now, Update, Restart to update (GET /api/kit/status, POST /api/kit/check | update | upgrade-app); opening it
|
|
27
29
|
* asks for the latest kit. Under it, what's new (design E, UpE): this week's summary lines, the newest kit at version level,
|
|
28
30
|
* then "Earlier this week" as one flat list of Claude's plain-language stories (a blue dot New, an amber dot Fixed, no dot
|
|
@@ -34,7 +36,8 @@
|
|
|
34
36
|
* it with its one action and what Claude tried, and the place menu opens Settings at Connectors. Every write is the PM's press (pmPost carries the launch nonce).
|
|
35
37
|
* PMOS reads the sources and never posts to them.
|
|
36
38
|
* openSettings(section?): general, claude, connectors, workspaces, updates; the old section names still land where their controls are now
|
|
37
|
-
* (checks → Claude, scrolled to Checks; adler and jl → General's sub-panel; dress → Adler › Dress for the day; workflows → Workspaces).
|
|
39
|
+
* (checks → Claude, scrolled to Checks; adler and jl → General's sub-panel; dress → Adler › Dress for the day; workflows → Workspaces › Workflows).
|
|
40
|
+
* openSettings('workflows', { wf, stage }) picks that workflow there and opens that stage once. */
|
|
38
41
|
import { mountClaudeSetup } from './cozy-claude-setup.js';
|
|
39
42
|
import * as JL from './cozy-jl.js';
|
|
40
43
|
import { pmGet, pmPost, pressFetch } from './http.js';
|
|
@@ -50,8 +53,7 @@ async function pmSend(method, path, body) {
|
|
|
50
53
|
catch (e) { return { ok: false, error: 'could not reach the workspace server — ' + ((e && e.message) || String(e)) }; }
|
|
51
54
|
}
|
|
52
55
|
const SECTIONS = [['general', 'General'], ['claude', 'Claude'], ['connectors', 'Connectors'], ['workspaces', 'Workspaces'], ['updates', 'Updates']];
|
|
53
|
-
const SUBS = { adler: 'Adler', jl: 'Jev and Laya' }; // General › Extras: each opens as a sub-panel of
|
|
54
|
-
const WF_HREF = '/premium-workflows.html'; // Workspaces › Workflows: the Workflows panel's address
|
|
56
|
+
const SUBS = { adler: 'Adler', jl: 'Jev and Laya', workflows: 'Workflows' }; // General › Extras and Workspaces › Workflows: each opens as a sub-panel of its section (U4, U1)
|
|
55
57
|
const SRC = { calendar: 'Calendar', wispr: 'Wispr Flow', mail: 'Mail', slack: 'Slack', jira: 'Jira', confluence: 'Confluence', github: 'GitHub', drive: 'Google Drive', figma: 'Figma', website: 'Your websites' };
|
|
56
58
|
const VIEWER_KEY = 'pmos.cz.viewer';
|
|
57
59
|
const T = { el: null, sec: 'general', sub: '', ws: null, st: {}, src: null, con: {}, conn: [], set: null, prods: null, msg: '', busy: false, phase: '', say: '', back: null, fresh: null, reading: '', note: {}, info: false, fold: false, dress: false, more: false, bday: false, dset: {}, wkOpen: new Set(), wkMore: new Set(), arc: false };
|
|
@@ -103,7 +105,7 @@ function general() {
|
|
|
103
105
|
}
|
|
104
106
|
/* General › Extras (U4): the row's › opens the sub-panel; its ‹ comes back to General */
|
|
105
107
|
const subBtn = (k) => `<button type="button" class="ev-ib" data-ev-sub="${k}" aria-label="${esc(SUBS[k])}" title="${esc(SUBS[k])}">${svg(CHEV, 18)}</button>`;
|
|
106
|
-
const subHead = (k) => `<div class="ev-dr-hd"><button type="button" class="ev-ib" data-ev-sub="" aria-label="Back to
|
|
108
|
+
const subHead = (k) => `<div class="ev-dr-hd"><button type="button" class="ev-ib" data-ev-sub="" aria-label="Back to ${esc((SECTIONS.find((x) => x[0] === T.sec) || SECTIONS[0])[1])}" title="Back">${svg(BACK, 18)}</button><h4 class="ev-grow">${esc(SUBS[k])}</h4></div>`;
|
|
107
109
|
/* Your impact (GmP1Switch): on by default; off hides every impact surface and stops Claude's daily read */
|
|
108
110
|
function impactOn() { const x = T.set && Array.isArray(T.set.settings) ? T.set.settings.find((y) => y.key === 'impact.on') : null; return x ? x.value !== false : true; }
|
|
109
111
|
/** One Dress for the day press: POST /api/settings, keep the row, and tell the page (the event adler:dress) so Adler changes at once. */
|
|
@@ -227,11 +229,12 @@ function connectors() {
|
|
|
227
229
|
return info + readsHtml() + fold + (T.fold ? `<div class="ev-con-more" id="evConMore">${all.map((x) => x[1]).join('')}</div>` : '');
|
|
228
230
|
}
|
|
229
231
|
function workspaces() {
|
|
232
|
+
if (T.sub === 'workflows') return subHead('workflows') + '<div class="ev-wfh" data-ev-wfhost></div>'; // pm/wf-page.js draws into it (UI grill U1)
|
|
230
233
|
if (T.ws === null) return '<p class="ev-small ev-mut">Reading the repositories.</p>';
|
|
231
234
|
return '<p class="ev-small ev-mut">A workspace is one repository PMOS works in. Removing one forgets the address only; the folder is not deleted.</p>'
|
|
232
235
|
+ T.ws.filter((x) => !x.linked).map((x) => trow(x.label || x.name || x.id, (x.root || '') + (x.home ? ' · home' : ''), x.home ? '<span class="ev-pill">Home</span>' : `<button type="button" class="ev-btn sm" data-ev-rm="${esc(x.id)}">Remove</button>`)).join('')
|
|
233
236
|
+ '<div class="ev-add"><label class="ev-vh" for="evRoot">Folder path of a repository</label><input id="evRoot" class="ev-inp" placeholder="Folder path of a repository"><button type="button" class="ev-btn pri" data-ev-add>Add</button></div>'
|
|
234
|
-
+ trow('Workflows', 'The stages each kind of initiative goes through',
|
|
237
|
+
+ trow('Workflows', 'The stages each kind of initiative goes through', subBtn('workflows'));
|
|
235
238
|
}
|
|
236
239
|
function updates() {
|
|
237
240
|
const s = home();
|
|
@@ -345,7 +348,7 @@ function checksSec() {
|
|
|
345
348
|
}
|
|
346
349
|
const BODY = { general, claude: claudeSec, connectors, workspaces, updates };
|
|
347
350
|
// the old section names (deep links, other pages' calls): where their controls are now (U4)
|
|
348
|
-
const MOVED = { checks: ['claude', ''], adler: ['general', 'adler'], jl: ['general', 'jl'], dress: ['general', 'adler'], workflows: ['workspaces', ''] };
|
|
351
|
+
const MOVED = { checks: ['claude', ''], adler: ['general', 'adler'], jl: ['general', 'jl'], dress: ['general', 'adler'], workflows: ['workspaces', 'workflows'] };
|
|
349
352
|
let disposeClaudeSetup = null;
|
|
350
353
|
function draw() {
|
|
351
354
|
const el = T.el; if (!el || el.hidden) return;
|
|
@@ -361,21 +364,47 @@ function draw() {
|
|
|
361
364
|
el.querySelector('.ev-st-main').innerHTML = (T.sec === 'connectors' ? '' : staleHtml()) + `<div class="ev-top"><h3 class="ev-h2" id="evStTitle">${esc(label)}</h3>${all}<button type="button" class="ev-ib" data-ev-close aria-label="Close settings" title="Close settings">${svg(ICON.close, 18)}</button></div>`
|
|
362
365
|
+ BODY[T.sec]() + `<p role="status"${T.msg && AD.moodOfText(T.msg) === 'honest' ? ' class="ev-say honest"' : ''}>${T.msg && AD.moodOfText(T.msg) === 'honest' ? AD.adler('honest', 24, { label: false }) : ''}${esc(T.msg)}</p>`;
|
|
363
366
|
if (disposeClaudeSetup) { disposeClaudeSetup(); disposeClaudeSetup = null; }
|
|
367
|
+
wfPanel(el);
|
|
364
368
|
const setup = el.querySelector('[data-claude-setup]');
|
|
365
369
|
if (setup) disposeClaudeSetup = mountClaudeSetup(setup, { ws: wsParam() || (T.ws && T.ws[0] && T.ws[0].id) || '', onReady: () => {} });
|
|
366
370
|
const cur = el.querySelector('.ev-st-nav [aria-current="page"]'); if (cur && cur.scrollIntoView) cur.scrollIntoView({ block: 'nearest', inline: 'nearest' }); // on a phone the section row scrolls: keep the open one in view
|
|
367
371
|
if (had && !ae.isConnected) { const f = (key && el.querySelector(`[${key.name}="${CSS.escape(key.value)}"]`)) || el.querySelector('[aria-current="page"]'); if (f) f.focus(); }
|
|
368
372
|
}
|
|
373
|
+
/** Workspaces › Workflows (UI grill U1): pm/wf-page.js draws into its host, the same node across redraws; leaving it lets it go. */
|
|
374
|
+
let WF = null, wfOpts = {};
|
|
375
|
+
function wfPanel(el) {
|
|
376
|
+
const host = el.querySelector('[data-ev-wfhost]');
|
|
377
|
+
el.classList.toggle('ev-wide', !!host);
|
|
378
|
+
if (!host) { if (WF) WF.release(); return; }
|
|
379
|
+
// the picked workflow and stage wait until a mount uses them: a redraw while the module loads replaces this host
|
|
380
|
+
const go = (M) => { WF = M; if (!host.isConnected) return; const o = { ...wfOpts, close: closeSettings }; wfOpts = {}; M.mount(host, o); };
|
|
381
|
+
if (WF) go(WF); else import('./wf-page.js').then(go).catch(() => { host.textContent = 'The workflows could not open.'; });
|
|
382
|
+
}
|
|
383
|
+
/** Workflows' stage in the Viewer docked in this dialog: Escape closes it first, then Settings. true when it closed it. */
|
|
384
|
+
function vwFirst() {
|
|
385
|
+
const v = WF && T.el.querySelector('#czViewer');
|
|
386
|
+
if (!v || v.hidden) return false;
|
|
387
|
+
import('./cozy-viewer.js').then((V) => V.close());
|
|
388
|
+
return true;
|
|
389
|
+
}
|
|
369
390
|
function mount() {
|
|
370
391
|
if (T.el && T.el.isConnected) return T.el;
|
|
371
392
|
const d = document.createElement('div');
|
|
372
393
|
d.innerHTML = '<div class="ev-st-scrim" id="evStScrim" hidden></div><div class="ev-st" id="evSettings" role="dialog" aria-modal="true" aria-label="Settings" hidden><nav class="ev-st-nav" aria-label="Settings sections"></nav><div class="ev-st-main"></div></div>';
|
|
373
|
-
|
|
394
|
+
// first in the body: while Workflows shows, the Viewer's host inside the dialog is the first data-cz-viewer-host (pm/cozy-viewer.js place)
|
|
395
|
+
document.body.prepend(...d.childNodes);
|
|
374
396
|
T.el = document.getElementById('evSettings');
|
|
375
397
|
document.getElementById('evStScrim').addEventListener('click', closeSettings);
|
|
376
|
-
T.el.addEventListener('keydown', (e) => {
|
|
398
|
+
T.el.addEventListener('keydown', (e) => {
|
|
399
|
+
if (e.target.closest('.cs-term')) return;
|
|
400
|
+
if (e.key !== 'Escape') return;
|
|
401
|
+
e.preventDefault(); e.stopPropagation();
|
|
402
|
+
// inside Workflows, Escape closes the layer it is in first: the stage in the Viewer, a menu or the remove pop, then Settings
|
|
403
|
+
if (e.target.closest('.wf-pop, .cz-vw-ren')) return;
|
|
404
|
+
if (!vwFirst()) closeSettings();
|
|
405
|
+
});
|
|
377
406
|
// the dialog is modal: Escape closes it even when focus is outside it (a click on the scrim's edge, a redraw)
|
|
378
|
-
document.addEventListener('keydown', (e) => { if (e.key === 'Escape' && T.el && !T.el.hidden && !T.el.contains(e.target)) { e.preventDefault(); e.stopPropagation(); closeSettings(); } }, true);
|
|
407
|
+
document.addEventListener('keydown', (e) => { if (e.key === 'Escape' && T.el && !T.el.hidden && !T.el.contains(e.target) && !(e.target.closest && e.target.closest('.wf-menu'))) { e.preventDefault(); e.stopPropagation(); if (!vwFirst()) closeSettings(); } }, true);
|
|
379
408
|
T.el.addEventListener('change', async (e) => {
|
|
380
409
|
const x = e.target;
|
|
381
410
|
if (x.matches('[data-ev-prof]')) {
|
|
@@ -553,8 +582,9 @@ async function load() {
|
|
|
553
582
|
draw();
|
|
554
583
|
openCheck();
|
|
555
584
|
}
|
|
556
|
-
export function openSettings(section) {
|
|
585
|
+
export function openSettings(section, o = {}) {
|
|
557
586
|
const el = mount();
|
|
587
|
+
if (section === 'workflows') wfOpts = { wf: o.wf || null, stage: o.stage || null };
|
|
558
588
|
const m = MOVED[section];
|
|
559
589
|
if (m) { T.sec = m[0]; T.sub = m[1]; T.dress = section === 'dress'; } else if (section && BODY[section]) { T.sec = section; T.sub = ''; T.dress = false; }
|
|
560
590
|
else if (el.hidden) { T.sec = 'general'; T.sub = ''; T.dress = false; } // a fresh open with no section opens on General (R2), not on the section of the last visit
|
|
@@ -569,6 +599,7 @@ export function openSettings(section) {
|
|
|
569
599
|
export function closeSettings() {
|
|
570
600
|
if (!T.el || T.el.hidden) return;
|
|
571
601
|
if (disposeClaudeSetup) { disposeClaudeSetup(); disposeClaudeSetup = null; }
|
|
602
|
+
if (WF) WF.release();
|
|
572
603
|
T.el.hidden = true; document.getElementById('evStScrim').hidden = true; T.el.removeAttribute('data-esc-layer');
|
|
573
604
|
const b = T.back; T.back = null; if (b && b.isConnected) { try { b.focus(); } catch { /* gone */ } }
|
|
574
605
|
}
|
|
@@ -1838,7 +1838,8 @@ function menCtx() {
|
|
|
1838
1838
|
* stays beside it (on a phone the chat takes the page). Another page hands it over through sessionStorage with ?about=<its key>. */
|
|
1839
1839
|
function chatAbout(t) {
|
|
1840
1840
|
S.phoneChat = isPhone(); if (isPhone()) VW.close();
|
|
1841
|
-
|
|
1841
|
+
S.sel = null; // the conversation is about its own item, not the row picked in the list (its header named that row)
|
|
1842
|
+
openTarget({ ...homeTarget(), key: t.key, title: t.title, scope: t.scope && t.scope.text ? { text: String(t.scope.text), icon: t.scope.icon || I.chat } : { text: 'Report · ' + t.title, icon: I.chat }, intro: t.intro ? { role: CLAUDE, text: t.intro } : undefined,
|
|
1842
1843
|
placeholder: t.placeholder || 'Message Claude', context: t.context });
|
|
1843
1844
|
drawList(); chat.focus();
|
|
1844
1845
|
}
|
|
@@ -2238,6 +2239,14 @@ load().then(() => {
|
|
|
2238
2239
|
}
|
|
2239
2240
|
if (say) setTimeout(() => { const ta = $('#hmIn'); if (ta) { ta.value = say; ta.dispatchEvent(new Event('input', { bubbles: true })); ta.focus(); ta.setSelectionRange(say.length, say.length); } }, 0);
|
|
2240
2241
|
if (mt) openMeeting({ note: mt });
|
|
2242
|
+
// ?settings=<section> (UI grill U1: the old /premium-workflows.html lands here with ?settings=workflows, keeping ?wf= and ?stage=):
|
|
2243
|
+
// Settings opens on that section; ?new=1 with it starts the New workflow conversation in this chat instead
|
|
2244
|
+
const sset = P.get('settings');
|
|
2245
|
+
if (sset && /^[a-z]{2,20}$/.test(sset)) {
|
|
2246
|
+
if (sset === 'workflows' && P.get('new') === '1') import('./wf-page.js').then((M) => M.newWorkflowChat()).catch(() => {});
|
|
2247
|
+
else import('./cozy-settings.js').then((M) => M.openSettings(sset, { wf: P.get('wf'), stage: P.get('stage') })).catch(() => {});
|
|
2248
|
+
const u = new URL(location.href); ['settings', 'new', 'wf', 'stage'].forEach((k) => u.searchParams.delete(k)); history.replaceState(history.state, '', u.pathname + u.search + u.hash);
|
|
2249
|
+
}
|
|
2241
2250
|
if (/^(prop|men|pulse|scan|rep|src)$/.test(P.get('around') || '')) MORE.openAround(P.get('around')); // ?around=<row>: that Around you view (home-around.js)
|
|
2242
2251
|
// the Viewer opens now or not at all: the held column goes either way, and the next open holds it only if it opened (SpJ)
|
|
2243
2252
|
setTimeout(() => { if (!isPhone()) store.set(VW_HELD, VW.isOpen() ? '1' : null); LS.holdViewer($('.hm-vw'), false); }, 0);
|
|
@@ -57,7 +57,7 @@ async function readProps(P) {
|
|
|
57
57
|
await Promise.all(P.flatMap((p) => ['initiative', 'work'].map(async (kind) => {
|
|
58
58
|
const r = await getj('/api/driver/open?target_kind=' + kind + (p.ws ? '&' + wq(p.ws) : ''));
|
|
59
59
|
if (!r.ok) { errs.push(r.error); return; }
|
|
60
|
-
if (r.mode !== 'approve') return; // Off and Shadow raise nothing here (the console draws the same)
|
|
60
|
+
if (r.mode !== 'approve' && r.mode !== 'auto') return; // Off and Shadow raise nothing here (the console draws the same). D106: in Auto, what is still open waits for the PM (class C, or a demoted job)
|
|
61
61
|
for (const [tid, list] of Object.entries(r.targets || {})) for (const pr of list) items.push({ id: pr.id, ws: r.ws, pname: P.length > 1 ? p.name : '', kind, tid, p: pr, title: '' });
|
|
62
62
|
})));
|
|
63
63
|
items.sort((a, b) => String(a.p.at).localeCompare(String(b.p.at)) || a.id.localeCompare(b.id));
|
|
@@ -198,7 +198,7 @@ const propSel = (L) => { const w = L.filter((it) => !DEC.has(it.id)); return (w.
|
|
|
198
198
|
function propsHtml() {
|
|
199
199
|
const a = A.prop; if (!a || !a.ok) return `<p class="nodef err" role="alert">Agent proposals ${esc(said(a))}</p>`;
|
|
200
200
|
const L = a.items.concat([...DEC.values()].map((d) => d.item).filter((it) => !a.items.some((o) => o.id === it.id))), sel = propSel(L), it = L.find((x) => x.id === sel);
|
|
201
|
-
const notes = [it ? pKeep(it.p) + ' Drop counts as a correction. Send back starts a new run with your note. None of the three can be undone.' : '', 'The agent mode (Off, Shadow, Approve) stays in Settings. This list shows a kind only when its mode is Approve.', a.errs.length ? 'Not read: ' + a.errs[0] : ''].filter(Boolean);
|
|
201
|
+
const notes = [it ? pKeep(it.p) + ' Drop counts as a correction. Send back starts a new run with your note. None of the three can be undone.' : '', 'The agent mode (Off, Shadow, Approve, Auto) stays in Settings. This list shows a kind only when its mode is Approve or Auto; in Auto it shows what still waits for you.', a.errs.length ? 'Not read: ' + a.errs[0] : ''].filter(Boolean);
|
|
202
202
|
const info = `<div class="pc-info"><button type="button" class="hx-b alt" data-bda="pinfo" aria-expanded="${PINFO}" aria-controls="pcNotes"><i class="pc-i" aria-hidden="true">i</i>Nothing changes a record until you keep it</button><div id="pcNotes"${PINFO ? '' : ' hidden'}>${notes.map((t) => `<p class="bd-why">${esc(t)}</p>`).join('')}</div></div>`;
|
|
203
203
|
const back = it && PBACK.has(it.id), id = it ? esc(it.id) : '';
|
|
204
204
|
const note = back ? `<label class="bd-l" for="bdn-${id}">What should the agent change?</label><textarea id="bdn-${id}" data-bdn="${id}" maxlength="500" rows="2">${esc(PNOTE[it.id] || '')}</textarea>${bdFail(it.id, PERR)}` : '';
|