create-pmos 0.731.0 → 0.733.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 +57 -27
- package/payload/KIT-VERSION +1 -1
- package/payload/okf/core/concepts/frontmatter-format.md +2 -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/board-columns-test.js +6 -5
- package/workspace/board-deliveries-test.js +8 -7
- package/workspace/board-programs-test.js +6 -12
- package/workspace/briefing-premium-board-test.js +3 -3
- package/workspace/calm-timeline-test.js +5 -10
- package/workspace/changelog.json +56 -0
- package/workspace/guide/agent-capabilities.md +1 -0
- package/workspace/guide/cli.md +10 -1
- package/workspace/guide/index.md +1 -0
- package/workspace/guide/initiatives-and-next-steps.md +17 -1
- package/workspace/guide/layout.md +5 -5
- package/workspace/guide/positioning.md +33 -0
- package/workspace/lib/board-premium.js +10 -0
- package/workspace/lib/customer-signals.js +207 -0
- package/workspace/lib/pmos-verbs.js +3 -0
- package/workspace/lib/positioning-draft.js +225 -0
- package/workspace/lib/press-release-cli.js +108 -0
- package/workspace/lib/press-release.js +186 -0
- package/workspace/lib/routes-boards.js +5 -1
- package/workspace/lib/routes-strategy-card.js +33 -2
- package/workspace/milestone-pins-test.js +4 -7
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/product-lane-test.js +5 -11
- package/workspace/program-leave-test.js +1 -1
- package/workspace/public/pm/bd-deliveries.js +7 -0
- package/workspace/public/pm/bd-phone-line.js +29 -0
- package/workspace/public/pm/bd-positioning.js +91 -0
- package/workspace/public/pm/bd-strategy.js +10 -3
- package/workspace/public/pm/bd-views.js +41 -5
- package/workspace/public/pm/bd-work-ds.css +16 -0
- package/workspace/public/pm/cozy-board.css +14 -0
- package/workspace/public/pm/cozy-goals.css +3 -10
- package/workspace/public/pm/cozy-pop-work.js +1 -1
- package/workspace/public/pm/cozy-popup.js +7 -21
- package/workspace/public/pm/cozy-viewer.js +4 -3
- package/workspace/public/pm/goals-ds.js +1 -1
- package/workspace/public/pm/premium-board.js +4 -3
- package/workspace/public/pm/premium-goals.js +14 -34
- package/workspace/public/premium-goals.html +0 -1
- package/workspace/task-delete-test.js +1 -1
- package/workspace/task-milestones-test.js +4 -8
- package/workspace/test-lists/phone-initiative-lines.json +6 -0
- package/workspace/test-lists/positioning-draft.json +9 -0
- package/workspace/test-lists/press-release.json +9 -0
- package/workspace/test-lists/roadmap-signal-count.json +9 -0
- package/workspace/timeline-holds-test.js +5 -16
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
/* customer-signals.js — the customer signals behind each roadmap item (initiative roadmap-signal-count, bet A157;
|
|
4
|
+
* done test planning/done-tests/roadmap-signal-count.md).
|
|
5
|
+
*
|
|
6
|
+
* A customer signal is one customer asking for, or hurting from, what an initiative does: who, where it was heard, a link
|
|
7
|
+
* and a one-line note. The Board shows how many back each item and a tap lists them (public/pm/bd-views.js).
|
|
8
|
+
*
|
|
9
|
+
* THE LEDGER: customer-signals.jsonl in the repository's runs directory (planning/runs/ for PMOS itself, pmos/state/ in a
|
|
10
|
+
* kit repository; lib/plan-ledgers.js runsDir). Append-only JSON lines:
|
|
11
|
+
* { v: 1, ev: 'added', sid, at, initiative, who, where, link, note, via }
|
|
12
|
+
* { v: 1, ev: 'removed', sid, at, via }
|
|
13
|
+
* sid 'cs_' + 10 hex of sha1(initiative, who in lower case, link or note): the same ask added twice is one signal
|
|
14
|
+
* where ticket | call | email | chat | survey | review | other
|
|
15
|
+
* note at most 140 characters. The customer's own text stays where it was written; the ledger keeps a pointer and a line.
|
|
16
|
+
*
|
|
17
|
+
* The record's `raised_by: "customer: <name>"` (lib/initiative-origin.js) counts as one signal too (where `record`), unless
|
|
18
|
+
* that customer already has one in the ledger.
|
|
19
|
+
*
|
|
20
|
+
* parseAdd(o) → { ok, line } | { ok: false, error } PURE
|
|
21
|
+
* fold(lines) → Map(initiative → [signal], newest first) PURE
|
|
22
|
+
* rowSignals(list, origin) → { n, items } | null PURE (null: zero is silence)
|
|
23
|
+
* ledgerFile(root) · readLines(root) · sigOf(root) · byInitiative(root) · add(root, o) · remove(root, sid) · count(root)
|
|
24
|
+
*
|
|
25
|
+
* CLI (what chat and agents run; nothing else writes the ledger):
|
|
26
|
+
* node workspace/lib/customer-signals.js add <initiative> --who "<customer>" [--where ticket] [--link <url>] [--note "<one line>"] [--root <checkout>]
|
|
27
|
+
* node workspace/lib/customer-signals.js remove <sid> [--root <checkout>]
|
|
28
|
+
* node workspace/lib/customer-signals.js list [<initiative>] [--root <checkout>] [--json]
|
|
29
|
+
* node workspace/lib/customer-signals.js count [<checkout>] last line: the number of initiatives with a signal
|
|
30
|
+
* Every log line carries [signals]. Exit codes: 0 done, 1 refused, 2 usage.
|
|
31
|
+
*/
|
|
32
|
+
const fs = require('fs');
|
|
33
|
+
const path = require('path');
|
|
34
|
+
const crypto = require('crypto');
|
|
35
|
+
|
|
36
|
+
const TAG = '[signals]';
|
|
37
|
+
const FILE = 'customer-signals.jsonl';
|
|
38
|
+
const WHERE = Object.freeze(['ticket', 'call', 'email', 'chat', 'survey', 'review', 'other']);
|
|
39
|
+
const MAX_WHO = 60;
|
|
40
|
+
const MAX_NOTE = 140;
|
|
41
|
+
const MAX_LINK = 500;
|
|
42
|
+
const MAX_ITEMS = 10;
|
|
43
|
+
const ID_RE = /^[a-z0-9][a-z0-9._-]{0,120}$/;
|
|
44
|
+
const SID_RE = /^cs_[0-9a-f]{10}$/;
|
|
45
|
+
const LINE_BREAK = /[\r\n\x00-\x08\x0b-\x1f]/;
|
|
46
|
+
|
|
47
|
+
const str = (v) => (v == null ? '' : String(v)).trim();
|
|
48
|
+
const sidOf = (initiative, who, key) => 'cs_' + crypto.createHash('sha1').update([initiative, who.toLowerCase(), key].join('\0')).digest('hex').slice(0, 10);
|
|
49
|
+
|
|
50
|
+
/** One `added` line from what a caller gives, or the reason it is refused. PURE. */
|
|
51
|
+
function parseAdd(o = {}, now = new Date()) {
|
|
52
|
+
const initiative = str(o.initiative), who = str(o.who), where = str(o.where || 'other').toLowerCase(), link = str(o.link), note = str(o.note);
|
|
53
|
+
if (!ID_RE.test(initiative)) return { ok: false, error: 'name the initiative by its id (lowercase, as on its record)' };
|
|
54
|
+
if (!who) return { ok: false, error: 'say who the customer is: --who "<person or company>"' };
|
|
55
|
+
if (who.length > MAX_WHO || LINE_BREAK.test(who)) return { ok: false, error: `the customer is one line of at most ${MAX_WHO} characters` };
|
|
56
|
+
if (!WHERE.includes(where)) return { ok: false, error: `where is one of: ${WHERE.join(', ')}` };
|
|
57
|
+
if (link.length > MAX_LINK || LINE_BREAK.test(link)) return { ok: false, error: `the link is one line of at most ${MAX_LINK} characters` };
|
|
58
|
+
if (note.length > MAX_NOTE || LINE_BREAK.test(note)) return { ok: false, error: `the note is one line of at most ${MAX_NOTE} characters; the customer's own words stay where they were written` };
|
|
59
|
+
const at = new Date(now).toISOString();
|
|
60
|
+
return { ok: true, line: { v: 1, ev: 'added', sid: sidOf(initiative, who, link || note), at, initiative, who, where, link: link || null, note: note || null, via: o.via || 'cli' } };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Lines (objects) → Map(initiative → [signal], newest first). A line it cannot read is skipped. PURE. */
|
|
64
|
+
function fold(lines) {
|
|
65
|
+
const live = new Map();
|
|
66
|
+
for (const l of lines || []) {
|
|
67
|
+
if (!l || typeof l !== 'object' || !SID_RE.test(String(l.sid || ''))) continue;
|
|
68
|
+
if (l.ev === 'added') {
|
|
69
|
+
if (!ID_RE.test(String(l.initiative || '')) || !str(l.who)) continue;
|
|
70
|
+
if (live.has(l.sid)) continue; // added twice: the first line stands
|
|
71
|
+
live.set(l.sid, { sid: l.sid, initiative: l.initiative, who: str(l.who).slice(0, MAX_WHO), where: WHERE.includes(l.where) ? l.where : 'other',
|
|
72
|
+
link: l.link ? str(l.link).slice(0, MAX_LINK) : null, note: l.note ? str(l.note).slice(0, MAX_NOTE) : null, at: l.at || null });
|
|
73
|
+
} else if (l.ev === 'removed') live.delete(l.sid);
|
|
74
|
+
}
|
|
75
|
+
const out = new Map();
|
|
76
|
+
for (const s of live.values()) {
|
|
77
|
+
if (!out.has(s.initiative)) out.set(s.initiative, []);
|
|
78
|
+
out.get(s.initiative).push(s);
|
|
79
|
+
}
|
|
80
|
+
for (const list of out.values()) list.sort((a, b) => String(b.at || '').localeCompare(String(a.at || '')));
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** One row's signals: the ledger's, plus the record's raised_by customer when no ledger signal names them. null when none. PURE. */
|
|
85
|
+
function rowSignals(list, origin) {
|
|
86
|
+
const items = (list || []).map(({ sid, who, where, link, note, at }) => ({ sid, who, where, link, note, at }));
|
|
87
|
+
if (origin && origin.kind === 'customer' && origin.name && !items.some((s) => s.who.toLowerCase() === String(origin.name).toLowerCase())) {
|
|
88
|
+
items.push({ sid: null, who: String(origin.name), where: 'record', link: null, note: 'raised it', at: null });
|
|
89
|
+
}
|
|
90
|
+
return items.length ? { n: items.length, items: items.slice(0, MAX_ITEMS) } : null;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// ── the ledger on disk ──────────────────────────────────────────────────────────────────────────────
|
|
94
|
+
function ledgerFile(root) { return path.join(require('./plan-ledgers.js').runsDir(root), FILE); }
|
|
95
|
+
function readLines(root) {
|
|
96
|
+
let text = '';
|
|
97
|
+
try { text = fs.readFileSync(ledgerFile(root), 'utf8'); } catch { return []; }
|
|
98
|
+
const out = [];
|
|
99
|
+
for (const raw of text.split('\n')) { if (!raw.trim()) continue; try { out.push(JSON.parse(raw)); } catch { /* a torn line is skipped */ } }
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
/** What a cache keys on: the ledger's size and time, or 'none'. */
|
|
103
|
+
function sigOf(root) {
|
|
104
|
+
try { const st = fs.statSync(ledgerFile(root)); return st.size + ':' + st.mtimeMs; } catch { return 'none'; }
|
|
105
|
+
}
|
|
106
|
+
function byInitiative(root) { return fold(readLines(root)); }
|
|
107
|
+
function append(root, line) {
|
|
108
|
+
const file = ledgerFile(root);
|
|
109
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
110
|
+
fs.appendFileSync(file, JSON.stringify(line) + '\n');
|
|
111
|
+
return file;
|
|
112
|
+
}
|
|
113
|
+
function recordOf(root, id) { try { return require('./plan-tree.js').recordPath(path.resolve(root), id); } catch { return null; } }
|
|
114
|
+
|
|
115
|
+
/** Add one signal. Refused for an initiative with no record. → { ok, sid, dup } | { ok: false, error } */
|
|
116
|
+
function add(root, o, now = new Date()) {
|
|
117
|
+
const p = parseAdd(o, now);
|
|
118
|
+
if (!p.ok) return p;
|
|
119
|
+
if (!recordOf(root, p.line.initiative)) return { ok: false, error: `no initiative "${p.line.initiative}" here: pmos initiative list shows the ids` };
|
|
120
|
+
const cur = byInitiative(root).get(p.line.initiative) || [];
|
|
121
|
+
if (cur.some((s) => s.sid === p.line.sid)) return { ok: true, sid: p.line.sid, dup: true };
|
|
122
|
+
append(root, p.line);
|
|
123
|
+
return { ok: true, sid: p.line.sid, dup: false };
|
|
124
|
+
}
|
|
125
|
+
/** Take one signal out (an append, never an edit). → { ok } | { ok: false, error } */
|
|
126
|
+
function remove(root, sid, now = new Date()) {
|
|
127
|
+
if (!SID_RE.test(str(sid))) return { ok: false, error: 'name the signal by its id (cs_ and 10 characters; list shows them)' };
|
|
128
|
+
const live = [...byInitiative(root).values()].some((l) => l.some((s) => s.sid === sid));
|
|
129
|
+
if (!live) return { ok: false, error: `no signal ${sid} is on the list` };
|
|
130
|
+
append(root, { v: 1, ev: 'removed', sid, at: new Date(now).toISOString(), via: 'cli' });
|
|
131
|
+
return { ok: true };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** The records of a checkout, either layout, with their raised_by line. */
|
|
135
|
+
function records(root) {
|
|
136
|
+
const ORIGIN = require('./initiative-origin.js');
|
|
137
|
+
const out = [];
|
|
138
|
+
for (const rel of ['planning/initiatives', 'pmos/state/initiatives']) {
|
|
139
|
+
let names = [];
|
|
140
|
+
try { names = fs.readdirSync(path.join(root, rel)); } catch { continue; }
|
|
141
|
+
for (const n of names) {
|
|
142
|
+
if (!n.endsWith('.md') || /^(readme|index|log)\.md$/i.test(n)) continue;
|
|
143
|
+
let rb = '';
|
|
144
|
+
try { rb = ORIGIN.raisedByOfText(fs.readFileSync(path.join(root, rel, n), 'utf8')); } catch { rb = ''; }
|
|
145
|
+
out.push({ id: n.slice(0, -3), origin: ORIGIN.originOf({ raised_by: rb }) });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return out;
|
|
149
|
+
}
|
|
150
|
+
/** Every initiative with a record → its signals, and how many have at least one. */
|
|
151
|
+
function count(root) {
|
|
152
|
+
const by = byInitiative(root);
|
|
153
|
+
const rows = {};
|
|
154
|
+
for (const r of records(root)) { const s = rowSignals(by.get(r.id), r.origin); if (s) rows[r.id] = s; }
|
|
155
|
+
return { initiatives: records(root).length, backed: Object.keys(rows).length, rows };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// ── CLI ─────────────────────────────────────────────────────────────────────────────────────────────
|
|
159
|
+
function flag(argv, name) { const i = argv.indexOf('--' + name); return i >= 0 && i + 1 < argv.length ? argv[i + 1] : null; }
|
|
160
|
+
function positional(argv) {
|
|
161
|
+
const out = [];
|
|
162
|
+
for (let i = 0; i < argv.length; i++) { if (argv[i].startsWith('--')) { if (argv[i] !== '--json') i++; continue; } out.push(argv[i]); }
|
|
163
|
+
return out;
|
|
164
|
+
}
|
|
165
|
+
const line = (s) => (s.who + ' · ' + s.where + (s.link ? ' · ' + s.link : '') + (s.note ? ' · ' + s.note : '') + (s.at ? ' · ' + s.at.slice(0, 10) : '') + (s.sid ? ' ' + s.sid : ''));
|
|
166
|
+
|
|
167
|
+
function main(argv, say = console.log) {
|
|
168
|
+
const [cmd, ...rest] = argv;
|
|
169
|
+
const pos = positional(rest);
|
|
170
|
+
const json = rest.includes('--json');
|
|
171
|
+
if (cmd === 'add') {
|
|
172
|
+
const root = path.resolve(flag(rest, 'root') || '.');
|
|
173
|
+
const r = add(root, { initiative: pos[0], who: flag(rest, 'who'), where: flag(rest, 'where'), link: flag(rest, 'link'), note: flag(rest, 'note') });
|
|
174
|
+
if (!r.ok) { say(`${TAG} refused: ${r.error}`); return 1; }
|
|
175
|
+
say(`${TAG} ${r.dup ? 'already on the list' : 'added'}: ${r.sid} on ${pos[0]}`);
|
|
176
|
+
return 0;
|
|
177
|
+
}
|
|
178
|
+
if (cmd === 'remove') {
|
|
179
|
+
const root = path.resolve(flag(rest, 'root') || '.');
|
|
180
|
+
const r = remove(root, pos[0]);
|
|
181
|
+
if (!r.ok) { say(`${TAG} refused: ${r.error}`); return 1; }
|
|
182
|
+
say(`${TAG} removed: ${pos[0]}`);
|
|
183
|
+
return 0;
|
|
184
|
+
}
|
|
185
|
+
if (cmd === 'list') {
|
|
186
|
+
const root = path.resolve(flag(rest, 'root') || '.');
|
|
187
|
+
const c = count(root);
|
|
188
|
+
const rows = pos[0] ? (c.rows[pos[0]] ? { [pos[0]]: c.rows[pos[0]] } : {}) : c.rows;
|
|
189
|
+
if (json) { say(JSON.stringify({ rows }, null, 1)); return 0; }
|
|
190
|
+
if (!Object.keys(rows).length) { say(`${TAG} no customer signals${pos[0] ? ' on ' + pos[0] : ''}`); return 0; }
|
|
191
|
+
for (const [id, s] of Object.entries(rows)) { say(`${id} · ${s.n}`); for (const x of s.items) say(' ' + line(x)); }
|
|
192
|
+
return 0;
|
|
193
|
+
}
|
|
194
|
+
if (cmd === 'count') {
|
|
195
|
+
const root = path.resolve(pos[0] || flag(rest, 'root') || '.');
|
|
196
|
+
const c = count(root);
|
|
197
|
+
say(`${TAG} ${c.backed} of ${c.initiatives} initiatives have a customer signal`);
|
|
198
|
+
say(String(c.backed));
|
|
199
|
+
return 0;
|
|
200
|
+
}
|
|
201
|
+
say('usage: customer-signals.js add <initiative> --who "<customer>" [--where ' + WHERE.join('|') + '] [--link <url>] [--note "<one line>"] | remove <sid> | list [<initiative>] [--json] | count [<checkout>]');
|
|
202
|
+
return 2;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (require.main === module) process.exit(main(process.argv.slice(2)));
|
|
206
|
+
|
|
207
|
+
module.exports = { TAG, FILE, WHERE, MAX_NOTE, MAX_ITEMS, parseAdd, fold, rowSignals, ledgerFile, readLines, sigOf, byInitiative, add, remove, count, main };
|
|
@@ -139,6 +139,9 @@ const VERBS = Object.freeze({
|
|
|
139
139
|
// Not a pm-os-absorb verb (run: null): initiative three-line-why (bet A86) added it through the same table.
|
|
140
140
|
why: Object.freeze({ module: 'why-cli.js', run: null, guide: 'cli.md',
|
|
141
141
|
help: 'pmos why <initiative or task> | coverage — why the work exists in three lines: goal, problem, evidence, read from its records (pmos why help)' }),
|
|
142
|
+
// Not a pm-os-absorb verb (run: null): initiative press-release-faq (bet A362) added it through the same table.
|
|
143
|
+
'press-release': Object.freeze({ module: 'press-release-cli.js', run: null, guide: 'cli.md',
|
|
144
|
+
help: 'pmos press-release <initiative> | count — a one-page press release and FAQ for a bet, drafted from its record, for you to edit (pmos press-release help)' }),
|
|
142
145
|
// Not a pm-os-absorb verb (run: null): initiative outcome-for-every-initiative added it through the same table.
|
|
143
146
|
outcomes: Object.freeze({ module: 'outcomes-cli.js', run: null, guide: 'cli.md',
|
|
144
147
|
help: 'pmos outcomes list|propose|declare|record|live — every initiative\'s expected outcome and check date: Claude\'s cited drafts, the PM\'s yes, the verdict when a check is due, and the version a place runs (pmos outcomes help)' }),
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* positioning-draft.js — the product's positioning statement and key messages, drafted from its five-line strategy (idea A328,
|
|
3
|
+
* initiative positioning-draft; done test planning/done-tests/positioning-draft.md).
|
|
4
|
+
*
|
|
5
|
+
* draft(ctx, card, opts) → { state: 'ready', key, by, lines } | { state: 'pending', key } | { state: 'missing', missing: [field] }
|
|
6
|
+
* opts.again: the PM pressed draft again, so a new run starts even when a draft is kept for this strategy
|
|
7
|
+
* peek(ctx, card) → the kept draft for this strategy, or null (never starts a run)
|
|
8
|
+
* normalize(answer, card) → [line] | null the model's answer made honest
|
|
9
|
+
* template(card) → [line] the lines put together from the strategy word for word (no AI)
|
|
10
|
+
* keep(dir, line, card, now?) → { ok, line } | { ok: false, error } appends { at, ev: 'keep', … } to <dir>/positioning.jsonl
|
|
11
|
+
* drop(dir, id, now?) → { ok } | { ok: false, error } appends { at, ev: 'drop', id }
|
|
12
|
+
* read(dir, card?) → [kept line] folded; a line whose cited strategy line changed since is `stale`
|
|
13
|
+
* count(dirs) → how many of the folders hold one or more kept lines
|
|
14
|
+
*
|
|
15
|
+
* A LINE is { id, kind: 'positioning' | 'message', text, cites: [field], quotes: { field: text } }. `cites` names the strategy lines
|
|
16
|
+
* (lib/strategy-card.js FIELDS) it comes from; `quotes` is the text of each cited line taken from the saved card, never from the model.
|
|
17
|
+
*
|
|
18
|
+
* THE RUN. One short PMOS session of the existing read-only `ask` kind (lib/headless.js, origin briefing-ask:positioning-draft:<key>): it
|
|
19
|
+
* reads only the five lines, uses no tool, writes nothing and sends nothing. Its answer is kept in <runtime>/strategy/positioning-drafts.json
|
|
20
|
+
* by the key of the five lines, so the same strategy is drafted once. When no session can start or the answer cannot be read, the
|
|
21
|
+
* template draft stands in and says so (by: 'template'): the PM always gets a draft, and never one made up.
|
|
22
|
+
*
|
|
23
|
+
* WHERE. `dir` is the product's records folder (lib/records-dir.js): planning/records in the PMOS repo, pmos/state/records in a kit
|
|
24
|
+
* product. positioning.jsonl is append-only; nothing rewrites it. */
|
|
25
|
+
const fs = require('fs');
|
|
26
|
+
const path = require('path');
|
|
27
|
+
const crypto = require('crypto');
|
|
28
|
+
const SC = require('./strategy-card.js');
|
|
29
|
+
|
|
30
|
+
const FILE = 'positioning.jsonl';
|
|
31
|
+
const KINDS = ['positioning', 'message'];
|
|
32
|
+
const MAX_LEN = 200;
|
|
33
|
+
const MAX_MESSAGES = 5;
|
|
34
|
+
const MODEL = 'claude-sonnet-5-5';
|
|
35
|
+
const LEAN = Object.freeze([{ flag: '--strict-mcp-config' }, { flag: '--disable-slash-commands' }, { flag: '--setting-sources', value: 'user' }, { flag: '--tools', value: 'Read' }]);
|
|
36
|
+
const TIMEOUT_MS = 180000;
|
|
37
|
+
const say = (s) => { try { console.log('[positioning-draft] ' + s); } catch { /* no console */ } };
|
|
38
|
+
const clip = (v, n = MAX_LEN) => { const s = String(v == null ? '' : v).replace(/\s+/g, ' ').trim(); return s.length > n ? s.slice(0, n - 1).trimEnd() + '…' : s; };
|
|
39
|
+
const lower1 = (s) => (s && !/^[A-Z]{2}/.test(s) ? s[0].toLowerCase() + s.slice(1) : s);
|
|
40
|
+
const noDot = (s) => String(s || '').replace(/[.\s]+$/, '');
|
|
41
|
+
|
|
42
|
+
/** The strategy lines a draft needs that are not written yet. */
|
|
43
|
+
const missingOf = (card) => SC.FIELDS.filter((k) => !String((card && card[k]) || '').trim());
|
|
44
|
+
const keyOf = (card) => crypto.createHash('sha1').update(SC.FIELDS.map((k) => SC.clean({ [k]: card && card[k] })[k] || '').join('\n')).digest('hex').slice(0, 16);
|
|
45
|
+
const idOf = (kind, text) => crypto.createHash('sha1').update(kind + '\n' + text).digest('hex').slice(0, 10);
|
|
46
|
+
|
|
47
|
+
/** One line made honest: a known kind, one line of text, cites that name written strategy lines, the card's own quotes. */
|
|
48
|
+
function lineOf(raw, card) {
|
|
49
|
+
if (!raw || typeof raw !== 'object') return null;
|
|
50
|
+
const kind = KINDS.includes(raw.kind) ? raw.kind : 'message';
|
|
51
|
+
const text = clip(raw.text);
|
|
52
|
+
if (!text) return null;
|
|
53
|
+
const cites = [...new Set((Array.isArray(raw.cites) ? raw.cites : [raw.cites]).map((c) => String(c || '').trim().toLowerCase()))]
|
|
54
|
+
.filter((c) => SC.FIELDS.includes(c) && String((card && card[c]) || '').trim());
|
|
55
|
+
if (!cites.length) return null;
|
|
56
|
+
const quotes = Object.fromEntries(cites.map((c) => [c, String(card[c]).trim()]));
|
|
57
|
+
return { id: idOf(kind, text), kind, text, cites, quotes };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Order and limit: one positioning statement first, then at most MAX_MESSAGES messages; repeated text once. */
|
|
61
|
+
function shape(lines) {
|
|
62
|
+
const seen = new Set(), pos = [], msg = [];
|
|
63
|
+
for (const l of lines) { if (!l || seen.has(l.text.toLowerCase())) continue; seen.add(l.text.toLowerCase()); (l.kind === 'positioning' ? pos : msg).push(l); }
|
|
64
|
+
if (!pos.length && msg.length) { const first = msg.shift(); pos.push({ ...first, kind: 'positioning', id: idOf('positioning', first.text) }); }
|
|
65
|
+
return [...pos.slice(0, 1), ...msg.slice(0, MAX_MESSAGES)];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function promptOf(card) {
|
|
69
|
+
return [
|
|
70
|
+
'You draft positioning for a product manager. Do not use any tool. Answer with JSON only.',
|
|
71
|
+
"The product's strategy, one line each, with its key:",
|
|
72
|
+
SC.FIELDS.map((k) => `${k} (${SC.LABELS[k]}): ${clip(card[k], 200)}`).join('\n'),
|
|
73
|
+
'Write in plain, short English, in the words of the strategy. Never invent customers, numbers, prices, dates, competitors or features that the strategy does not name.',
|
|
74
|
+
'1. One positioning statement of at most 35 words: who it is for, the problem, what the product does about it, and why it wins.',
|
|
75
|
+
"2. Three to five key messages, each one sentence of at most 20 words, that a team can say outside. None may promise what \"wont\" rules out.",
|
|
76
|
+
'Every line lists in "cites" the keys of the strategy lines it comes from (one or more of: for, problem, bet, win, wont).',
|
|
77
|
+
'Answer: {"lines":[{"kind":"positioning","text":"…","cites":["for","problem","bet"]},{"kind":"message","text":"…","cites":["win"]}]}',
|
|
78
|
+
].join('\n\n');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The model's answer → [line] | null (unreadable, or no line cites a written strategy line). */
|
|
82
|
+
function normalize(text, card) {
|
|
83
|
+
const t = String(text || ''), at = t.indexOf('{'), end = t.lastIndexOf('}');
|
|
84
|
+
if (at < 0 || end < at) return null;
|
|
85
|
+
let o; try { o = JSON.parse(t.slice(at, end + 1)); } catch { return null; }
|
|
86
|
+
if (!o || !Array.isArray(o.lines)) return null;
|
|
87
|
+
const lines = shape(o.lines.slice(0, 20).map((l) => lineOf(l, card)));
|
|
88
|
+
return lines.length ? lines : null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The lines put together from the strategy word for word: honest when no session can run. */
|
|
92
|
+
function template(card) {
|
|
93
|
+
const c = Object.fromEntries(SC.FIELDS.map((k) => [k, noDot(String(card[k] || '').trim())]));
|
|
94
|
+
return shape([
|
|
95
|
+
lineOf({ kind: 'positioning', text: `For ${lower1(c.for)}, who face this: ${lower1(c.problem)}. Our answer: ${lower1(c.bet)}. Why us: ${lower1(c.win)}.`, cites: ['for', 'problem', 'bet', 'win'] }, card),
|
|
96
|
+
lineOf({ kind: 'message', text: c.bet + '.', cites: ['bet'] }, card),
|
|
97
|
+
lineOf({ kind: 'message', text: `Made for ${lower1(c.for)}.`, cites: ['for'] }, card),
|
|
98
|
+
lineOf({ kind: 'message', text: c.win + '.', cites: ['win'] }, card),
|
|
99
|
+
]);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/* ── drafts: one run per strategy, kept in the runtime folder ─────────────────────────────────────────────────── */
|
|
103
|
+
const draftsFile = (ctx) => path.join((ctx && ctx.runtimeDir) || require('os').tmpdir(), 'strategy', 'positioning-drafts.json');
|
|
104
|
+
function readDrafts(ctx) { try { const o = JSON.parse(fs.readFileSync(draftsFile(ctx), 'utf8')); return o && typeof o === 'object' ? o : {}; } catch { return {}; } }
|
|
105
|
+
function keepDraft(ctx, key, value) {
|
|
106
|
+
const all = readDrafts(ctx); all[key] = { at: new Date().toISOString(), ...value };
|
|
107
|
+
const keys = Object.keys(all).sort((a, b) => String(all[b].at).localeCompare(String(all[a].at)));
|
|
108
|
+
for (const k of keys.slice(20)) delete all[k]; // the newest 20 strategies' drafts
|
|
109
|
+
fs.mkdirSync(path.dirname(draftsFile(ctx)), { recursive: true });
|
|
110
|
+
fs.writeFileSync(draftsFile(ctx), JSON.stringify(all));
|
|
111
|
+
}
|
|
112
|
+
const running = new Map(); // key → started at (ms)
|
|
113
|
+
|
|
114
|
+
function viaSession(ctx, prompt, key) {
|
|
115
|
+
if (ctx && typeof ctx.askClaude === 'function') return Promise.resolve(ctx.askClaude(prompt, { job: 'positioning-draft', key })).catch(() => null);
|
|
116
|
+
const headless = require('./headless.js');
|
|
117
|
+
const origin = 'briefing-ask:positioning-draft:' + key;
|
|
118
|
+
if (!ctx || typeof ctx.spawnSession !== 'function' || headless.kindFor({ agent: 'claude', origin }) !== 'ask') return Promise.resolve(null);
|
|
119
|
+
return new Promise((resolve) => {
|
|
120
|
+
let settled = false; const done = (v) => { if (settled) return; settled = true; clearTimeout(tm); resolve(v); };
|
|
121
|
+
const tm = setTimeout(() => done(null), TIMEOUT_MS);
|
|
122
|
+
let s = null;
|
|
123
|
+
try {
|
|
124
|
+
s = ctx.spawnSession({ name: 'positioning: draft from strategy', agent: 'claude', origin, initialInput: prompt,
|
|
125
|
+
modelAsk: { explicit: { model: MODEL, effort: 'low' } }, launchFlags: LEAN.map((f) => ({ ...f })),
|
|
126
|
+
onDone: (d) => { const r = d && d.result; done(r && r.ok && !r.isError ? String(r.text || '') : null); } });
|
|
127
|
+
} catch { s = null; }
|
|
128
|
+
if (!s || s.state === 'exited') done(null);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function peek(ctx, card) {
|
|
133
|
+
if (missingOf(card).length) return null;
|
|
134
|
+
const key = keyOf(card), have = readDrafts(ctx)[key];
|
|
135
|
+
return have && Array.isArray(have.lines) ? { state: 'ready', key, by: have.by, lines: have.lines, at: have.at } : running.has(key) ? { state: 'pending', key } : null;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function draft(ctx, card, opts = {}) {
|
|
139
|
+
const missing = missingOf(card);
|
|
140
|
+
if (missing.length) return { state: 'missing', missing };
|
|
141
|
+
const key = keyOf(card);
|
|
142
|
+
if (running.has(key)) return { state: 'pending', key };
|
|
143
|
+
const have = readDrafts(ctx)[key];
|
|
144
|
+
if (have && Array.isArray(have.lines) && !opts.again) return { state: 'ready', key, by: have.by, lines: have.lines, at: have.at };
|
|
145
|
+
running.set(key, Date.now());
|
|
146
|
+
const p = Promise.resolve(viaSession(ctx, promptOf(card), key)).then((text) => {
|
|
147
|
+
const lines = text == null ? null : normalize(text, card);
|
|
148
|
+
const value = lines ? { by: 'ai', lines } : { by: 'template', lines: template(card), why: text == null ? 'PMOS could not start a session' : 'the answer could not be read' };
|
|
149
|
+
try { keepDraft(ctx, key, value); } catch { /* the next press tries again */ }
|
|
150
|
+
say(`drafted ${value.lines.length} lines (${value.by})`);
|
|
151
|
+
}).catch(() => {}).finally(() => running.delete(key));
|
|
152
|
+
if (opts.wait) return p.then(() => draft(ctx, card));
|
|
153
|
+
return { state: 'pending', key };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/* ── the kept lines ───────────────────────────────────────────────────────────────────────────────────────────── */
|
|
157
|
+
const fileOf = (dir) => (dir ? path.join(dir, FILE) : null);
|
|
158
|
+
function readLines(dir) {
|
|
159
|
+
let text = ''; try { text = fs.readFileSync(fileOf(dir), 'utf8'); } catch { return []; }
|
|
160
|
+
const out = [];
|
|
161
|
+
for (const l of text.split('\n')) { if (!l.trim()) continue; try { const o = JSON.parse(l); if (o && (o.ev === 'keep' || o.ev === 'drop') && o.id) out.push(o); } catch { /* a torn line is skipped */ } }
|
|
162
|
+
return out;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function read(dir, card = null) {
|
|
166
|
+
const by = new Map();
|
|
167
|
+
for (const l of readLines(dir)) {
|
|
168
|
+
if (l.ev === 'drop') { by.delete(l.id); continue; }
|
|
169
|
+
by.delete(l.id); by.set(l.id, { id: l.id, kind: l.kind, text: l.text, cites: l.cites || [], quotes: l.quotes || {}, edited: !!l.edited, at: l.at });
|
|
170
|
+
}
|
|
171
|
+
const out = [...by.values()];
|
|
172
|
+
if (card) for (const l of out) l.stale = l.cites.some((c) => String(card[c] || '').trim() !== String(l.quotes[c] || '').trim());
|
|
173
|
+
return out.sort((a, b) => (a.kind === b.kind ? 0 : a.kind === 'positioning' ? -1 : 1));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function append(dir, obj) { fs.mkdirSync(dir, { recursive: true }); fs.appendFileSync(fileOf(dir), JSON.stringify(obj) + '\n'); }
|
|
177
|
+
|
|
178
|
+
/** Keep one line, as drafted or edited. `line.from` is the drafted text it started as: a different text marks it edited. */
|
|
179
|
+
function keep(dir, line, card, now = Date.now()) {
|
|
180
|
+
if (!dir) return { ok: false, error: 'This product has no records folder.' };
|
|
181
|
+
const l = lineOf(line, card || {});
|
|
182
|
+
if (!l) return { ok: false, error: 'A kept line needs text and one or more written strategy lines it cites: ' + SC.FIELDS.join(', ') + '.' };
|
|
183
|
+
const edited = line.from != null ? clip(line.from) !== l.text : !!line.edited;
|
|
184
|
+
try { append(dir, { at: new Date(now).toISOString(), ev: 'keep', ...l, edited }); } catch (e) { return { ok: false, error: 'could not keep the line: ' + ((e && e.message) || e) }; }
|
|
185
|
+
say(`kept a ${l.kind} line${edited ? ' (edited)' : ''} citing ${l.cites.join(', ')}`);
|
|
186
|
+
return { ok: true, line: { ...l, edited } };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function drop(dir, id, now = Date.now()) {
|
|
190
|
+
if (!dir) return { ok: false, error: 'This product has no records folder.' };
|
|
191
|
+
if (!read(dir).some((l) => l.id === id)) return { ok: false, error: 'No kept line has that id.' };
|
|
192
|
+
try { append(dir, { at: new Date(now).toISOString(), ev: 'drop', id }); } catch (e) { return { ok: false, error: 'could not drop the line: ' + ((e && e.message) || e) }; }
|
|
193
|
+
say('dropped a kept line');
|
|
194
|
+
return { ok: true };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const count = (dirs) => (dirs || []).filter((d) => read(d).length > 0).length;
|
|
198
|
+
|
|
199
|
+
module.exports = { FILE, KINDS, MAX_LEN, MAX_MESSAGES, missingOf, keyOf, promptOf, normalize, template, draft, peek, keep, drop, read, readLines, count };
|
|
200
|
+
|
|
201
|
+
if (require.main === module) {
|
|
202
|
+
const args = process.argv.slice(2), cmd = args[0];
|
|
203
|
+
const flag = (k) => { const i = args.indexOf('--' + k); return i >= 0 ? args[i + 1] : undefined; };
|
|
204
|
+
const pos = args.slice(1).filter((a, i, A) => !a.startsWith('--') && !(i > 0 && A[i - 1].startsWith('--')));
|
|
205
|
+
const root = pos[0] || process.cwd();
|
|
206
|
+
let dir;
|
|
207
|
+
try { const { repoScript } = require('./repo-script.js'); dir = require(repoScript('signals/layout-paths.js')).pathsFor(root).recordsDir; } catch { dir = path.join(root, 'planning', 'records'); }
|
|
208
|
+
const card = SC.read(dir);
|
|
209
|
+
if (cmd === 'count') { console.log(String(count([dir]))); process.exit(0); }
|
|
210
|
+
if (cmd === 'show') {
|
|
211
|
+
const kept = read(dir, card);
|
|
212
|
+
if (!kept.length) console.log('No positioning line kept yet.');
|
|
213
|
+
for (const l of kept) console.log(`${l.kind === 'positioning' ? 'Positioning' : 'Message'}: ${l.text} (from ${l.cites.map((c) => SC.LABELS[c]).join(', ')}${l.stale ? '; the strategy changed since' : ''}) [${l.id}]`);
|
|
214
|
+
process.exit(0);
|
|
215
|
+
}
|
|
216
|
+
if (cmd === 'keep') {
|
|
217
|
+
const r = keep(dir, { kind: flag('kind') || 'message', text: flag('text'), cites: String(flag('cites') || '').split(',') }, card);
|
|
218
|
+
console.log(r.ok ? `kept: ${r.line.text}` : '✗ ' + r.error); process.exit(r.ok ? 0 : 1);
|
|
219
|
+
}
|
|
220
|
+
if (cmd === 'drop') { const r = drop(dir, flag('id')); console.log(r.ok ? 'dropped' : '✗ ' + r.error); process.exit(r.ok ? 0 : 1); }
|
|
221
|
+
console.error('usage: node workspace/lib/positioning-draft.js count|show|keep|drop [<product checkout>]\n'
|
|
222
|
+
+ ' keep --text "<line>" --cites bet,for [--kind positioning|message] keep a positioning line (it must cite written strategy lines)\n'
|
|
223
|
+
+ ' drop --id <id> drop a kept line (ids from show)');
|
|
224
|
+
process.exit(2);
|
|
225
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* press-release-cli.js — `pmos press-release …`: a one-page press release and FAQ for a bet, for the PM to edit
|
|
3
|
+
* (initiative press-release-faq, bet A362).
|
|
4
|
+
*
|
|
5
|
+
* pmos press-release <initiative> [--again] [--no-ai] draft it beside the record and print the path
|
|
6
|
+
* pmos press-release count [--days 7] the drafts written in the window; the last line is the number
|
|
7
|
+
* every command: [--json] [--root <dir>]
|
|
8
|
+
*
|
|
9
|
+
* The draft goes to planning/press-releases/<id>.md (pmos/state/press-releases/<id>.md in kit layout). A file that is there is never
|
|
10
|
+
* written over: --again first keeps it as <id>.prev.md. The model run is one `claude -p` with no tools (lib/press-release.js); when it
|
|
11
|
+
* is off (`pmos ai off press-release`, PMOS_AI=off), fails or answers something unreadable, the draft is the record's own lines.
|
|
12
|
+
* Exit codes: 0 done, 1 refused (no such initiative, a draft is there), 2 usage.
|
|
13
|
+
*/
|
|
14
|
+
const fs = require('fs');
|
|
15
|
+
const path = require('path');
|
|
16
|
+
const { execFileSync } = require('child_process');
|
|
17
|
+
const PR = require('./press-release.js');
|
|
18
|
+
|
|
19
|
+
const TAG = '[press-release]';
|
|
20
|
+
const COMMANDS = { 'press-release': ['count'] };
|
|
21
|
+
const USAGE = [
|
|
22
|
+
'usage: pmos press-release <initiative> | count — a one-page press release and FAQ for a bet, drafted from its record, for you to edit',
|
|
23
|
+
' pmos press-release <id> draft it beside the record and print the path',
|
|
24
|
+
' pmos press-release <id> --again draft it again; the old file is kept as <id>.prev.md',
|
|
25
|
+
' pmos press-release <id> --no-ai draft it from the record only, without a model run',
|
|
26
|
+
' pmos press-release count [--days 7] the drafts written in the last days; the last line is the number',
|
|
27
|
+
' every command: [--json] [--root <dir>]',
|
|
28
|
+
'Where the record does not say a fact, the draft says "(not written yet)". PMOS never writes over your file.',
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
function repoRoot(cwd) {
|
|
32
|
+
try { return execFileSync('git', ['rev-parse', '--show-toplevel'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim() || cwd; }
|
|
33
|
+
catch { return cwd; }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function parse(argv) {
|
|
37
|
+
const pos = []; const flags = {};
|
|
38
|
+
for (let i = 0; i < argv.length; i++) {
|
|
39
|
+
const a = argv[i];
|
|
40
|
+
if (a === '--root' || a === '--days') flags[a.slice(2)] = argv[++i];
|
|
41
|
+
else if (/^--(root|days)=/.test(a)) { const [k, v] = a.slice(2).split('='); flags[k] = v; }
|
|
42
|
+
else if (a.startsWith('--')) flags[a.slice(2)] = true;
|
|
43
|
+
else if (a === '-h') flags.help = true;
|
|
44
|
+
else pos.push(a);
|
|
45
|
+
}
|
|
46
|
+
return { pos, flags };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function aiOff(env) {
|
|
50
|
+
try {
|
|
51
|
+
let dir = null; try { dir = require('./state-root.js').defaultRoot({ env }); } catch { dir = null; }
|
|
52
|
+
return require('./ai-guard.js').off(PR.JOB, { env, settingsDir: dir });
|
|
53
|
+
} catch { return /^(off|0|false|no)$/i.test(String((env || {}).PMOS_AI || '').trim()) ? 'every AI job is off (PMOS_AI)' : null; }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), ask = PR.ask, env = process.env, now = Date.now() } = {}) {
|
|
57
|
+
const { pos, flags } = parse(argv[0] === 'press-release' ? argv.slice(1) : argv.slice());
|
|
58
|
+
if (flags.help || pos[0] === 'help') { for (const l of USAGE) say(l); return 0; }
|
|
59
|
+
const root = path.resolve(flags.root || repoRoot(cwd));
|
|
60
|
+
const json = !!flags.json;
|
|
61
|
+
|
|
62
|
+
if (pos[0] === 'count') {
|
|
63
|
+
const days = Math.max(1, Math.min(365, parseInt(flags.days, 10) || 7));
|
|
64
|
+
const n = PR.count(root, { days, now });
|
|
65
|
+
if (json) { say(JSON.stringify({ ok: true, days, drafts: n })); return 0; }
|
|
66
|
+
say(`${TAG} ${n} press release draft${n === 1 ? '' : 's'} in the last ${days} days.`);
|
|
67
|
+
say(String(n));
|
|
68
|
+
return 0;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const id = pos[0];
|
|
72
|
+
if (!id) { for (const l of USAGE) say(l); return 2; }
|
|
73
|
+
const inputs = PR.inputsOf(root, id);
|
|
74
|
+
if (!inputs) { say(json ? JSON.stringify({ ok: false, error: `no initiative "${id}" in this repository` }) : `✗ no initiative "${id}" in this repository (pmos initiative list shows them)`); return 1; }
|
|
75
|
+
|
|
76
|
+
const recordAbs = path.join(root, inputs.recordPath);
|
|
77
|
+
const dir = PR.dirOf(recordAbs);
|
|
78
|
+
const file = path.join(dir, inputs.id + '.md');
|
|
79
|
+
const rel = path.relative(root, file).split(path.sep).join('/');
|
|
80
|
+
const there = fs.existsSync(file);
|
|
81
|
+
if (there && !flags.again) {
|
|
82
|
+
say(json ? JSON.stringify({ ok: false, error: 'a draft is there', path: rel }) : `✗ ${rel} is already there. Edit it, or run with --again to draft it again (the old file is kept as ${inputs.id}.prev.md).`);
|
|
83
|
+
return 1;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
let draft = null; let why = null;
|
|
87
|
+
const off = flags['no-ai'] ? 'you asked for --no-ai' : aiOff(env);
|
|
88
|
+
if (off) why = off;
|
|
89
|
+
else {
|
|
90
|
+
let r = null;
|
|
91
|
+
try { r = ask(PR.promptOf(inputs), { env }); } catch (e) { r = { ok: false, text: e.message }; }
|
|
92
|
+
if (!r || !r.ok) why = `the model run failed (${(r && r.text) || 'no answer'})`;
|
|
93
|
+
else { draft = PR.parseDraft(r.text); if (!draft) why = 'the model answer could not be read'; }
|
|
94
|
+
}
|
|
95
|
+
const by = draft ? 'model' : 'record';
|
|
96
|
+
if (!draft) draft = PR.fallbackOf(inputs);
|
|
97
|
+
|
|
98
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
99
|
+
if (there) fs.copyFileSync(file, file.replace(/\.md$/, '.prev.md'));
|
|
100
|
+
fs.writeFileSync(file, PR.render(draft, inputs, { now, by }));
|
|
101
|
+
say(`${TAG} drafted ${inputs.id} (${by === 'model' ? 'record and model' : 'record only'}) → ${rel}`);
|
|
102
|
+
if (json) { say(JSON.stringify({ ok: true, path: rel, from: by, why })); return 0; }
|
|
103
|
+
if (why) say(`The draft is from the record only: ${why}.`);
|
|
104
|
+
say(`✓ Press release and FAQ for "${inputs.title}": ${rel}. Edit it as you like; PMOS will not write over it.`);
|
|
105
|
+
return 0;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
module.exports = { run, COMMANDS, USAGE };
|