create-pmos 0.783.0 → 0.785.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.
Files changed (77) hide show
  1. package/package.json +70 -78
  2. package/payload/AGENTS.md +160 -0
  3. package/payload/KIT-VERSION +1 -1
  4. package/payload/design-system/ui/components/Badge/README.md +2 -2
  5. package/payload/design-system/ui/components/Glyph/README.md +28 -0
  6. package/payload/design-system/ui/components/bundle.css +3 -0
  7. package/payload/planning/evals/eval-calibration.md +1 -1
  8. package/payload/planning/okrs/health-budgets.md +1 -1
  9. package/payload/state/discoveries.md +1 -1
  10. package/workspace/bin/card-catalog-gen.js +22 -0
  11. package/workspace/board-columns-test.js +2 -2
  12. package/workspace/briefing-premium-insights-test.js +5 -4
  13. package/workspace/calm-timeline-test.js +4 -3
  14. package/workspace/changelog.json +69 -10
  15. package/workspace/design-system/ui/components/Badge/README.md +2 -2
  16. package/workspace/design-system/ui/components/Glyph/README.md +28 -0
  17. package/workspace/design-system/ui/components/bundle.css +3 -0
  18. package/workspace/guide/claude-proposes.md +1 -0
  19. package/workspace/guide/cli.md +8 -0
  20. package/workspace/guide/home.md +4 -3
  21. package/workspace/guide/index.md +2 -2
  22. package/workspace/guide/layout.md +16 -2
  23. package/workspace/lib/briefing-premium-agent.js +3 -0
  24. package/workspace/lib/card-catalog-gen.js +123 -0
  25. package/workspace/lib/cos-chat.js +1 -0
  26. package/workspace/lib/declined-asks.js +177 -0
  27. package/workspace/lib/declined-cli.js +87 -0
  28. package/workspace/lib/goal-chat.js +1 -0
  29. package/workspace/lib/initiative-chat.js +1 -0
  30. package/workspace/lib/jira-status.js +11 -2
  31. package/workspace/lib/live-events.js +99 -0
  32. package/workspace/lib/pmos-verbs.js +3 -0
  33. package/workspace/lib/program-chat.js +1 -0
  34. package/workspace/lib/proposals.js +13 -2
  35. package/workspace/lib/report-chat.js +1 -0
  36. package/workspace/lib/route-modules.js +1 -0
  37. package/workspace/lib/routes-live-rows.js +30 -0
  38. package/workspace/lib/routes-proposals.js +31 -3
  39. package/workspace/lib/routes-slash.js +142 -2
  40. package/workspace/lib/routes-task-links.js +1 -1
  41. package/workspace/lib/scope-cuts.js +138 -0
  42. package/workspace/lib/task-cli.js +5 -3
  43. package/workspace/lib/workflow-chat.js +1 -0
  44. package/workspace/okr-goals-ui-test.js +3 -2
  45. package/workspace/package-lock.json +2 -2
  46. package/workspace/package.json +1 -1
  47. package/workspace/public/pm/bd-cols.js +3 -1
  48. package/workspace/public/pm/bd-span.js +13 -7
  49. package/workspace/public/pm/bd-views.js +6 -3
  50. package/workspace/public/pm/bd-work-ds.css +1 -0
  51. package/workspace/public/pm/bd-work.js +15 -2
  52. package/workspace/public/pm/cozy-board.css +3 -0
  53. package/workspace/public/pm/cozy-insights.css +3 -4
  54. package/workspace/public/pm/ds-bridge.css +12 -0
  55. package/workspace/public/pm/goal-forecast.js +7 -4
  56. package/workspace/public/pm/home-app.js +5 -3
  57. package/workspace/public/pm/ini-props.js +4 -3
  58. package/workspace/public/pm/komorebi.css +1 -0
  59. package/workspace/public/pm/live-edit.js +34 -3
  60. package/workspace/public/pm/live-feed.js +42 -0
  61. package/workspace/public/pm/okr-list.js +5 -2
  62. package/workspace/public/pm/premium-board.js +2 -0
  63. package/workspace/public/pm/premium-insights.js +10 -4
  64. package/workspace/public/pm/premium-vw-doc.css +5 -0
  65. package/workspace/public/pm/premium-vw-doc.js +11 -31
  66. package/workspace/public/pm/premium-vw-file.js +13 -8
  67. package/workspace/public/pm/premium-vw-guide.css +9 -0
  68. package/workspace/public/pm/premium-vw-guide.js +20 -17
  69. package/workspace/public/pm/reading-view.js +44 -0
  70. package/workspace/public/pm/state-glyph.js +135 -0
  71. package/workspace/skills/jira-sync.skill +4 -3
  72. package/workspace/task-milestones-test.js +2 -2
  73. package/workspace/test-lists/a2ui-chat-rules.json +9 -0
  74. package/workspace/test-lists/a2ui-live-rows.json +9 -0
  75. package/workspace/test-lists/declined-asks.json +9 -0
  76. package/workspace/test-lists/scope-cuts-save-date.json +5 -0
  77. package/workspace/test-lists/state-glyph.json +5 -0
@@ -1,23 +1,82 @@
1
1
  [
2
2
  {
3
- "v": "0.783.0",
4
- "at": "2026-11-24T16:37:58.744Z",
3
+ "v": "0.785.0",
4
+ "at": "2026-11-24T17:13:04.909Z",
5
5
  "f": 4,
6
6
  "prs": [
7
7
  {
8
- "n": 1778,
9
- "t": "Name the catalog and draft routes outside routes-*, so d86-seams check 7 passes",
10
- "s": "Name the catalog and draft routes outside routes-*, so d86-seams check 7 passes",
11
- "k": "fix",
8
+ "n": 1758,
9
+ "t": "A chat write moves the row on every open page at once (a2ui-live-rows, job #1750)",
10
+ "s": "A chat write moves the row on every open page at once (a2ui-live-rows, job #1750)",
11
+ "k": "new"
12
+ },
13
+ {
14
+ "n": 1753,
15
+ "t": "Chat rules, AGENTS.md commands and the / menu generated from the card catalog",
16
+ "s": "Chat rules, AGENTS.md commands and the / menu generated from the card catalog",
17
+ "k": "new"
18
+ },
19
+ {
20
+ "n": 1782,
21
+ "t": "Declined asks get a kind reply draft and an out-of-scope record",
22
+ "s": "Declined asks get a kind reply draft and an out-of-scope record",
23
+ "k": "new",
24
+ "h": "Declined asks get a kind reply draft and an out-of-scope record",
25
+ "try": {
26
+ "steps": [
27
+ "Open Today and ask PMOS in the chat: which asks did I decline lately?",
28
+ "Ask PMOS to record one of them with its reason"
29
+ ],
30
+ "see": "The chat lists the Jira tickets closed as Won't Do, Declined, Duplicate or similar in the last 90 days, each with a short kind reply to the person who asked. Recording one adds it to the product's…"
31
+ }
32
+ },
33
+ {
34
+ "n": 1755,
35
+ "t": "States are shapes, not words (state-glyphs, job #1675)",
36
+ "s": "States are shapes, not words (state-glyphs, job #1675)",
37
+ "k": "new"
38
+ },
39
+ {
40
+ "n": 1785,
41
+ "t": "Guide pages and markdown files read in the Reading layout (A334)",
42
+ "s": "Guide pages and markdown files read in the Reading layout (A334)",
43
+ "k": "new"
44
+ }
45
+ ]
46
+ },
47
+ {
48
+ "v": "0.784.0",
49
+ "at": "2026-11-24T16:59:38.052Z",
50
+ "f": 4,
51
+ "prs": [
52
+ {
53
+ "n": 1777,
54
+ "t": "PMOS proposes the scope cuts that save a date",
55
+ "s": "PMOS proposes the scope cuts that save a date",
56
+ "k": "new",
57
+ "h": "PMOS proposes the scope cuts that save a date",
12
58
  "try": {
13
59
  "steps": [
14
- "On Work, open an initiative whose Overview says Goal: Not written yet, and press ✓ on its ✦",
15
- "Wait for the line to say PMOS is drafting it, then read the goal it saved",
16
- "Press Undo on the toast"
60
+ "Open Work and open an initiative whose end date is still ahead but whose tasks run past it",
61
+ "Press its ✦ and find Cut to keep the date",
62
+ "Keep it, then press Undo"
17
63
  ],
18
- "see": "The goal line fills in by itself with no chat opening, and Undo puts it back to Not written yet",
64
+ "see": "The ✦ lists the tasks that finish after the date, each with its forecast and the new dates after the date; Keep moves them and adds a note, and Undo puts them back",
19
65
  "open": "/premium-board.html"
20
66
  }
67
+ }
68
+ ]
69
+ },
70
+ {
71
+ "v": "0.783.0",
72
+ "at": "2026-11-24T16:37:58.744Z",
73
+ "f": 4,
74
+ "prs": [
75
+ {
76
+ "n": 1778,
77
+ "t": "Name the catalog and draft routes outside routes-*, so d86-seams check 7 passes",
78
+ "s": "Name the catalog and draft routes outside routes-*, so d86-seams check 7 passes",
79
+ "k": "fix"
21
80
  },
22
81
  {
23
82
  "n": 1780,
@@ -1,11 +1,11 @@
1
1
  ---
2
2
  type: Reference
3
3
  title: "PMOS design system: Badge"
4
- description: "Small labels: `pm-badge` (state), `pm-count` (a number on the rail), `pm-chip` (a name or tag), `pm-kbd` (a key)."
4
+ description: "Small labels: `pm-badge` (a fact; a state is a Glyph), `pm-count` (a number on the rail), `pm-chip` (a name or tag), `pm-kbd` (a key)."
5
5
  timestamp: 2026-11-19
6
6
  ---
7
7
 
8
- Small labels: `pm-badge` (state), `pm-count` (a number on the rail), `pm-chip` (a name or tag), `pm-kbd` (a key).
8
+ Small labels: `pm-badge` (a fact such as "Due 29 Oct"; a state is a [Glyph](../Glyph/README.md)), `pm-count` (a number on the rail), `pm-chip` (a name or tag), `pm-kbd` (a key).
9
9
 
10
10
  - `alert` badge only for late, at risk or blocked. On track gets no badge (zero is silence).
11
11
  - Never show a count of 0.
@@ -0,0 +1,28 @@
1
+ ---
2
+ type: Reference
3
+ title: "PMOS design system: Glyph"
4
+ description: "A state is a shape, not a word: `pm-glyph` from `stateGlyph(state, { progress, size, why })` in pm/state-glyph.js."
5
+ timestamp: 2026-11-24
6
+ ---
7
+
8
+ A state is a shape, not a word. Every state on every page comes from `stateGlyph(state, { progress, size, why })` in `pm/state-glyph.js`. It gives a `pm-glyph` span with `role="img"`, an `aria-label` and a `title`.
9
+
10
+ | State | Shape | Token |
11
+ |---|---|---|
12
+ | On track | a ring that fills with progress | `--state-on` |
13
+ | At risk | a half-filled circle | `--state-risk` |
14
+ | Late | a triangle with ! | `--state-late` |
15
+ | Needs you | a blue dot on a tint | `--state-you` |
16
+ | Waiting on others | a clock | `--state-wait` |
17
+ | No signal | a dashed ring | `--state-none` |
18
+ | Done | a filled check | `--state-done` |
19
+
20
+ - The seven `--state-*` tokens are set once in `components/bundle.css` from `--leaf`, `--alert`, `--blue` and `--muted`. The glyph names only these tokens. Change one token and every glyph changes. The glyph's own rules (its pulse and the phone sheet) sit in `public/pm/ds-bridge.css`, which every page loads, so the design system sent to a prototype run stays under its 32k cap.
21
+ - Put the glyph before the title on Work, Goals and phone rows, at the end of the row in Library, and at the end of the bar in Timeline.
22
+ - Facts stay as text: "29 days late", "Commerce has it", "last update 2 Nov". Only the state word goes.
23
+
24
+ ## Interaction
25
+
26
+ - Hover shows the word and why as a tooltip. A screen reader reads the same words from the `aria-label`.
27
+ - On a phone, press and hold a glyph to open a small sheet with the word and one line of why (`pressHold(root)`). A quick tap opens the row as before.
28
+ - Only Needs you moves: one soft pulse when it first shows. With `prefers-reduced-motion` there is no pulse.
@@ -208,3 +208,6 @@ a{color:var(--blue)}
208
208
  .pm-table tr.sel td{background:var(--leaf-tint)}
209
209
  .pm-li.gone{opacity:0;transform:translateX(12px);transition:opacity var(--duration-enter) var(--ease-out),transform var(--duration-enter) var(--ease-out)}
210
210
  @media (prefers-reduced-motion:reduce){.pm-chart path.line,.pm-li.gone,.pm-tip{transition:none}}
211
+ /* State glyph (initiative state-glyphs, boards StatesDS and StatesPhone): a state is a shape, not a word. The seven state tokens are set
212
+ here, once, from the brand colours; the glyph (pm/state-glyph.js) names only these, so a change to one reaches every glyph. */
213
+ :root{--state-on:var(--leaf);--state-risk:var(--alert);--state-late:var(--alert);--state-you:var(--blue);--state-wait:var(--muted);--state-none:var(--muted);--state-done:var(--leaf)}
@@ -19,6 +19,7 @@ Press the ✦ to open "PMOS proposes N" in the Viewer. On a desk the chat stays
19
19
  - **Check these.** A maybe match, with its reason, and an item that is already in another initiative. A duplicate is linked, never copied. These need their own ✓.
20
20
  - **Not placed.** What PMOS could not fit. It is kept under Linked.
21
21
  - **Dates.** Each morning, and whenever a date passes, PMOS proposes new dates for tasks that are late or at risk (due within 3 days and not started), one proposal per stage. Each line names the task and its two days: "Move <task> from 24 Nov to 27 Nov". The reason is one line with its source. When PMOS finds no reason, it says "No reason found" and offers to ask the owner. When a new date reaches a task that waits on it, the proposal shows the link: keep it (the waiting task moves too) or ignore it (it stays and the two overlap). PMOS marks the one it recommends with a small ✦.
22
+ - **Cut to keep the date.** When an initiative's open tasks will finish after its date, and that date is still ahead, PMOS proposes "Cut 3 tasks to keep 12 Dec". It lists the tasks that finish after the date, and any task that waits on one of them. Each line shows when the task would end, where it moves to, and what the cut costs: "the PRD names it" (listed last) or a Jira ticket (PMOS drafts a comment and does not change the ticket). A ◇ milestone is never cut. Keep moves each task to the first working day after the date, with the same length, and adds a note that says why. Undo puts the dates and the notes back. This proposal is never in Keep all, and PMOS never applies it by itself. Remove a task you want to keep with its ✕. The date is the initiative's committed end, or else the latest due date of its tasks. Count the cuts you kept with `node lib/scope-cuts.js count`.
22
23
  - **Status.** "Looks done" when the evidence says the work happened, such as an email that was sent.
23
24
  - **Names.** Tidy names: the WBS number kept, verb first, about 7 words, no "+" and no brackets. The detail that is cut goes to the task's notes.
24
25
  - **Links.** The links between tasks that PMOS proposes.
@@ -408,6 +408,14 @@ The same five lines as the Strategy card on Work ([The strategy in five lines](i
408
408
  - `pmos strategy set --line <key> --text "<line>"` writes your own line. `--text ""` blanks it.
409
409
  - `pmos strategy undo` takes back every line PMOS drafted. `--line <key>` takes back one.
410
410
 
411
+ ### pmos declined: asks you said no to, with a kind reply
412
+
413
+ PMOS lists the asks in the product's Jira readings that were closed without being done: Won't Do, Declined, Duplicate, Not a bug and the like. Each one gets a short reply draft to the person who asked: thanks for the ask, the decision and its reason, and what would bring it back. PMOS never sends the reply. Copy it and send it yourself. Run the commands in the product's repository, or pass `--root <dir>`.
414
+
415
+ - `pmos declined list` lists the asks closed in the last 90 days, newest first, each with its reply draft. `--days <n>` changes the window. A recorded ask shows ✓.
416
+ - `pmos declined draft <KEY>` shows the reply draft for one ask. `--reason "<why>"` gives your own reason instead of the one PMOS reads from the ticket.
417
+ - `pmos declined record <KEY>` records the ask in `planning/out-of-scope/<key>.md` and in `declined-asks.jsonl` in the product's records folder. `--reason "<why>"` gives your reason. When a later idea repeats the ask, "You decided this before" raises it. Once you edit the file, PMOS does not write over it.
418
+
411
419
  ### pmos sprint: the retro of a closed sprint and one tracked change
412
420
 
413
421
  The same block as One change in a past sprint on Work › Backlog. PMOS writes the retro from its own close numbers for every sprint it saw open and then closed: done of total, and why work was carried (never started, started, in review, carried two sprints in a row, added after the start). It tracks one change for the next sprint: the biggest reason with 2 or more tickets. At the next sprint's close, the retro says whether that change helped, with the number before and after. Run the commands in the product's repository, or pass `--root <dir>`. Your overrides are in `_sprint-retro.jsonl` beside the kept sprint history. Nothing is sent and Jira is not written.
@@ -2,7 +2,7 @@
2
2
  type: Guide
3
3
  title: "Today: your list, the chat, the Viewer, My work, documents and people"
4
4
  description: "Today's list, Mentions, Your day, the chat and the Viewer; My work; documents and their copies; People; and the suggested next prompt."
5
- timestamp: 2026-11-24
5
+ timestamp: 2026-11-25
6
6
  ---
7
7
 
8
8
  # Today
@@ -159,6 +159,7 @@ Press the name in the Viewer's header. The name becomes a field.
159
159
 
160
160
  - Type the new name. Press Enter or the check to save it. Press Esc to stop without a change. An empty name is not saved.
161
161
  - The new name shows at once in the list, the chat header, the Viewer, Work and the Timeline. The message **Renamed** has **Undo**.
162
+ - **A change from the chat shows at once.** When you ask the chat to add, move, close or delete a task, the row changes on Today, Work and an open task popup within a second, without the page reading its lists again. A change you make in one tab of the workspace shows in its other open tabs as soon as it is saved. A change that is not saved does not show in the other tabs.
162
163
  - An initiative of another product renames in that product's own repository, the same as on Work.
163
164
  - Only the name changes. The id, the record file, the links and the history stay the same.
164
165
  - An initiative with a Jira epic shows **Rename the Jira epic too**. It is off by default. When you select it, Today opens the initiative's chat with the request typed. Send it to let your agent rename the epic in Jira. PMOS does not change Jira itself.
@@ -200,7 +201,7 @@ Press the round button at the bottom of the page (bottom left on a desktop, bott
200
201
  - **Search** (⌘K) has **Ask PMOS: …** as its first row once you type two letters. On Work and in Intelligence, the page's own matches come first, then **Ask PMOS**. Press it to put your words in the chat.
201
202
  - PMOS reads with the `pmos` commands and ends each answer with where it read from and how fresh it is, for example "Work · read now". A change inside PMOS comes back as a ✦ that you keep with ✓. Anything that leaves PMOS is a draft in the outbox. The chat never accepts a run, anchors or disposes an initiative, approves a contract or merges: it says where each one waits.
202
203
 
203
- - **Guide** opens this guide's start page in the Viewer of the page you are on. A link to another guide page opens it in the same place; ← goes back. The guide opens wide: every page in a list on the left, by group, with Find a page; a chip for each section above the page. On a phone the list icon beside the title shows the list. The address `/premium-viewer.html?open=guide&page=<name>` opens one page on its own.
204
+ - **Guide** opens this guide's start page in the Viewer of the page you are on. A link to another guide page opens it in the same place; ← goes back. The guide opens wide and reads like every document: Contents at the left lists the page's sections and follows the scroll, and each section folds. The list icon at the top shows every page, by group, with Find a page. Where Contents is hidden (a narrow Viewer or a phone), a chip for each section sits above the page. The address `/premium-viewer.html?open=guide&page=<name>` opens one page on its own.
204
205
 
205
206
  - The button has one dot. It is amber when a source is old, else blue when a call is yours in Your move. The dot shows on every page. When the menu is open, the blue dot is on **Today** and the amber dot is on **Settings**.
206
207
  - When a source is old, **Settings** opens at **Connectors**, with the old source first.
@@ -233,7 +234,7 @@ There is no My work page. The list on Today is your list:
233
234
  - A conversation opens at its latest message.
234
235
  - A file that you send shows as a chip in your message, with a small picture for a photo. Press the chip to open the file beside the conversation.
235
236
  - Your message shows as you typed it. Markdown that you paste (headings, lists, bold, code, tables) shows formatted.
236
- - Type `/` to see every command: `/goal`, the commands built into Claude Code, and the commands and skills in the workspace's `.claude` folder and in your own `~/.claude` folder.
237
+ - Type `/` to see every command: `/goal`, then one `/pmos:` command for each button a PMOS card has (`/pmos:task-set` moves a task's dates; the list comes from the card catalog), the commands built into Claude Code, and the commands and skills in the workspace's `.claude` folder and in your own `~/.claude` folder.
237
238
  - The mic types what you say into the box. **Stop** keeps the words, and **Discard** puts the box back. Both end listening at once.
238
239
  - When Claude Code asks whether to trust the folder of a new chat, the chat shows the ask as a card: **Trust this folder** or **No, end the session**. Your first message waits until you answer, for up to 15 minutes, and is then sent. It is never typed into the question.
239
240
 
@@ -1,14 +1,14 @@
1
1
  ---
2
2
  type: Guide
3
3
  title: "Guide: start here"
4
- timestamp: 2026-11-08
4
+ timestamp: 2026-11-25
5
5
  ---
6
6
 
7
7
  # Guide: start here
8
8
 
9
9
  This guide describes the PMOS workspace as it works today. It ships with the app. When a change alters how the workspace looks or behaves, the same change updates this guide.
10
10
 
11
- To open the guide from any page, press the round menu button at the bottom of the page, then the **?** icon (Guide). The guide opens wide in the Viewer and uses its full width. Every page is in the list on the left, by group, with **Find a page** on top; a group folds and stays folded. Above each page, one chip for each of its sections takes you there. A link to another guide page opens that page in the same place. Press ← to go back. On a phone, or when the Viewer is narrow, the list icon beside the title shows the list.
11
+ To open the guide from any page, press the round menu button at the bottom of the page, then the **?** icon (Guide). The guide opens wide in the Viewer and uses its full width. Each page reads like every document in PMOS: **Contents** at the left lists its sections and marks the one you are reading, and each section folds (the page keeps what you folded). The list icon at the top shows every page, by group, with **Find a page** on top; a group folds and stays folded. When the Viewer is narrow, or on a phone, one chip for each section sits above the page instead of Contents. A link to another guide page opens that page in the same place. Press ← to go back.
12
12
 
13
13
  ## The screen
14
14
 
@@ -2,7 +2,7 @@
2
2
  type: Guide
3
3
  title: "Layout and first run: the places, the navigation, the Viewer, the launcher and Adler"
4
4
  description: "The places, the navigation at the left, the Viewer, the keys and the phone; the first run; when features appear; the PMOS app; and Adler."
5
- timestamp: 2026-11-24
5
+ timestamp: 2026-11-25
6
6
  ---
7
7
 
8
8
  # Layout and first run
@@ -142,7 +142,7 @@ A document opened in the Viewer (a doc, spec, brief, report, weekly update, meet
142
142
  - **Contents** at the left lists the sections and marks the one you are reading as you scroll. Press one to go to it. Below 1100 px wide, and on a phone, there is no Contents.
143
143
  - Edit, Markdown, Health, Links, Copies, the report's Present, Print and Download, the Edit log and Proposals are where they were. An agent's edit still opens with **Keep** and **Undo all**.
144
144
 
145
- Other kinds move to this view one at a time. Slides, PDFs and prototypes keep the stage, and a task, ticket or event keeps the task detail.
145
+ This guide's pages and a Markdown file opened from a chat read the same way; a file keeps **Download** and **Share** at the top. Other kinds move to this view one at a time. Slides, PDFs and prototypes keep the stage, and a task, ticket or event keeps the task detail.
146
146
 
147
147
  ### What you type is kept
148
148
 
@@ -454,6 +454,20 @@ When a place opens, Today's own chat shows one ✦ for it, with a link to its pa
454
454
 
455
455
  PMOS shows at most one of these a day. Your impact and What you might have missed come first, so Today's chat shows one ✦ at a time.
456
456
 
457
+ ### States are shapes
458
+
459
+ PMOS shows the state of a piece of work as a small shape, not as a word. Each state has its own shape, so you can tell them apart without colour:
460
+
461
+ - **On track**: a ring that fills as the work gets done.
462
+ - **At risk**: a half-filled circle.
463
+ - **Late**: a triangle with !.
464
+ - **Needs you**: a blue dot on a light circle. It pulses once when it first shows, and not at all when your system asks for less motion.
465
+ - **Waiting on others**: a clock.
466
+ - **No signal**: a dashed ring. PMOS has read nothing for this work yet.
467
+ - **Done**: a filled circle with a check.
468
+
469
+ The shape is before the title on Work, Goals and the phone rows, in the Status column of the Timeline, and at the end of a bar on the Timeline. The facts stay as words beside it, for example "29 days late" or "Commerce has it". Hold the pointer on a shape to see its word and why. A screen reader reads the same words. On a phone, press and hold a shape to open a small sheet with its word and one line of why.
470
+
457
471
  ### The dot on the menu
458
472
 
459
473
  The first time a place opens, its row in the menu gets one soft blue dot, and so does the menu button. The dot goes away when you open that place. The reports dot is on the Intelligence row, because reports are in Intelligence under **⋯**.
@@ -15,6 +15,7 @@ const path = require('path');
15
15
  const crypto = require('crypto');
16
16
  const headless = require('./headless.js');
17
17
  const Goal = require('./goal-chat.js');
18
+ const { pmosAsk } = require('./routes-slash.js');
18
19
  const ReportChat = require('./report-chat.js');
19
20
  const REPORT_KEYS = new Set(); // chats that carried the report rule: their later messages carry the short reminder (item 9, batch 27)
20
21
  const ProgramChat = require('./program-chat.js');
@@ -234,6 +235,8 @@ function chat({ runtimeDir, key, text, model, context, sessions, wsId, iniInfo,
234
235
  let msg = q, goal = null;
235
236
  const cmd = Goal.parseCommand(q);
236
237
  if (cmd) { const b = Goal.begin({ runtimeDir, key, text: cmd.text, now }); if (b.error) return fail(400, b.error); msg = b.prompt; goal = b.id; }
238
+ // A455: a pick from the / menu's PMOS group ("/pmos task set …") reaches the session as words; Claude Code has no /pmos command
239
+ else if (pmosAsk(q)) msg = pmosAsk(q);
237
240
  // D99: the New workflow chat (Settings › Workflows) carries the workflow rule on every message (lib/workflow-chat.js)
238
241
  else if (WorkflowChat.isKey(key) && !q.startsWith('/')) msg = WorkflowChat.wrap(q);
239
242
  // ask-the-past: "why did we drop X?" in any chat carries the past rule: answer from `pmos past ask`, cite every line, "No record found" when none
@@ -0,0 +1,123 @@
1
+ 'use strict';
2
+ /* card-catalog-gen.js — the command text that the card catalog (lib/card-catalog.json) writes into three places (A455, job #1749):
3
+ * 1. kit/AGENTS.md, between <!-- card-catalog:begin --> and <!-- card-catalog:end -->: every pmos command a card button runs
4
+ * 2. the chat rules lib/<scope>-chat.js, between the card-catalog:begin and card-catalog:end comments: the commands of the cards that
5
+ * chat speaks about, as one rule line
6
+ * 3. the PMOS group of the / menu (lib/routes-slash.js), between the same comments: one entry per command
7
+ * The catalog is the one source. Edit lib/card-catalog.json, then run `node bin/card-catalog-gen.js`; card-catalog-gen.test.js fails
8
+ * while a generated block differs from what the catalog writes, and when a catalog command has no handler in `pmos`.
9
+ *
10
+ * usage(cmd) → 'pmos task set <id> [--due <date>] [--start <date>] …' (the positional words of its first run, every flag of every run)
11
+ * scopeLine(scope) → the one rule line of a chat scope (SCOPES)
12
+ * agentsBlock() → the markdown of the AGENTS.md block
13
+ * slashEntries() → [{ cmd, name, say }] for the / menu
14
+ * targets(root) → [{ file, begin, end, text }] the blocks and where they go (root = the repository root)
15
+ * apply(src, t) → src with the block between t.begin and t.end replaced by t.text; throws when a marker is missing
16
+ * handlerMissing(verbs?) → ['pmos <verb> <sub>' …] the catalog commands no `pmos` handler takes
17
+ * Pure apart from reading the catalog and, in handlerMissing, the verb modules' COMMANDS. */
18
+ const path = require('path');
19
+ const fs = require('fs');
20
+ const CC = require('./card-catalog');
21
+
22
+ /* Which cards each chat speaks about. cos is the chief over every unit, so it gets every group, by command name only. */
23
+ const SCOPES = Object.freeze({
24
+ initiative: { file: 'initiative-chat.js', kinds: ['task', 'subtask', 'milestone', 'dependency', 'workitem', 'initiative', 'proposal-ini', 'parked', 'launch', 'ready', 'signoff', 'artefact', 'rehearsal'] },
25
+ program: { file: 'program-chat.js', kinds: ['program', 'program-task', 'unit'] },
26
+ goal: { file: 'goal-chat.js', kinds: ['goal', 'measure', 'outcome', 'forecast'] },
27
+ report: { file: 'report-chat.js', kinds: ['report', 'schedule', 'press-release'] },
28
+ workflow: { file: 'workflow-chat.js', kinds: ['workflow', 'grill', 'build-item', 'prototype'] },
29
+ cos: { file: 'cos-chat.js', kinds: null },
30
+ });
31
+ const WHO = { you: 'one press with Undo', agent: 'PMOS starts a run', waits: 'only after the PM says yes' };
32
+
33
+ const cmdKey = (c) => c.verb + ' ' + c.sub;
34
+ /** Every catalog command, each with all its runs. */
35
+ function allCommands() {
36
+ const by = new Map();
37
+ for (const k of CC.kinds()) for (const a of k.actions) {
38
+ const p = CC.parseRun(a.run); if (!p) continue;
39
+ const key = p.verb + ' ' + p.sub;
40
+ if (!by.has(key)) by.set(key, { verb: p.verb, sub: p.sub, pos: p.pos, flags: {}, need: new Set(Object.keys(p.flags)), uses: [] });
41
+ const c = by.get(key);
42
+ for (const [f, v] of Object.entries(p.flags)) if (!(f in c.flags)) c.flags[f] = v;
43
+ c.uses.push({ kind: k.id, group: k.group, label: a.label, who: a.who || 'you' });
44
+ }
45
+ return [...by.values()];
46
+ }
47
+ function usage(c) {
48
+ // the first run's flags are its usual form; a flag only another button adds is shown optional
49
+ const fl = Object.entries(c.flags).map(([f, v]) => { const w = '--' + f + (v === true ? '' : ' ' + v); return c.need.has(f) ? w : '[' + w + ']'; });
50
+ return ['pmos', c.verb, c.sub, ...c.pos, ...fl].filter(Boolean).join(' ');
51
+ }
52
+ const uniq = (a) => [...new Set(a)];
53
+ const whoOf = (c) => uniq(c.uses.map((u) => u.who)).sort().join('/');
54
+ const labels = (c, kinds) => uniq(c.uses.filter((u) => !kinds || kinds.includes(u.kind)).map((u) => u.label));
55
+
56
+ function scopeLine(scope) {
57
+ const S = SCOPES[scope]; if (!S) throw new Error('no chat scope ' + scope);
58
+ const head = 'The card buttons run these pmos commands (the card catalog; who acts: you = ' + WHO.you + ', agent = ' + WHO.agent + ', waits = ' + WHO.waits + '). Run the one that fits the PM\'s ask, and tell the PM the Undo line it prints: ';
59
+ if (!S.kinds) {
60
+ const groups = (CC.load().groups || []).map((g) => {
61
+ const ks = g.kinds.map((k) => k.id), cs = allCommands().filter((c) => c.uses.some((u) => ks.includes(u.kind)));
62
+ return g.name + ': ' + uniq(cs.map((c) => 'pmos ' + cmdKey(c))).join(', ');
63
+ });
64
+ return head + groups.join('; ') + '. Each command\'s own help gives its flags.';
65
+ }
66
+ const cs = allCommands().filter((c) => c.uses.some((u) => S.kinds.includes(u.kind)));
67
+ return head + cs.map((c) => usage(c) + ' (' + labels(c, S.kinds).join(', ') + '; ' + whoOf(c) + ')').join('; ') + '.';
68
+ }
69
+
70
+ function agentsBlock() {
71
+ const out = ['## Card commands (generated from the card catalog)', '',
72
+ 'Every button on a PMOS card runs one `pmos` command. This list is generated from `workspace/lib/card-catalog.json` by `node workspace/bin/card-catalog-gen.js`; do not edit it by hand. Who acts: **you** is ' + WHO.you + ', **agent** is ' + WHO.agent + ', **waits** is ' + WHO.waits + '. Run the command the PM\'s ask names, and tell the PM the Undo line it prints.', ''];
73
+ for (const g of CC.load().groups || []) {
74
+ const ks = g.kinds.map((k) => k.id), cs = allCommands().filter((c) => c.uses.some((u) => ks.includes(u.kind)));
75
+ if (!cs.length) continue;
76
+ out.push('**' + g.name + '.**', '');
77
+ for (const c of cs) out.push('- `' + usage(c) + '`: ' + labels(c, ks).join(', ') + ' (' + whoOf(c) + ')');
78
+ out.push('');
79
+ }
80
+ return out.join('\n').trimEnd();
81
+ }
82
+
83
+ function slashEntries() {
84
+ // one entry per sub ("up|down" gives two); a / command is one word, so "/pmos:task-set" (the menu filters as you type)
85
+ const out = [];
86
+ for (const c of allCommands()) for (const sub of String(c.sub).split('|')) {
87
+ const l = labels(c);
88
+ out.push({ cmd: '/pmos:' + c.verb + (sub ? '-' + sub : ''), run: ('pmos ' + c.verb + ' ' + sub).trim(), name: l[0] + (l.length > 1 ? ' and ' + (l.length - 1) + ' more' : ''), say: usage({ ...c, sub }) });
89
+ }
90
+ return out;
91
+ }
92
+
93
+ const JS_BEGIN = '/* card-catalog:begin, generated by bin/card-catalog-gen.js: edit lib/card-catalog.json, not this block */';
94
+ const JS_END = '/* card-catalog:end */';
95
+ function targets(root) {
96
+ const ws = path.join(root, 'workspace');
97
+ const t = [{ file: path.join(root, 'kit', 'AGENTS.md'), begin: '<!-- card-catalog:begin -->', end: '<!-- card-catalog:end -->', text: '\n\n' + agentsBlock() + '\n\n' }];
98
+ for (const s of Object.keys(SCOPES)) t.push({ file: path.join(ws, 'lib', SCOPES[s].file), begin: JS_BEGIN, end: JS_END, text: JSON.stringify(scopeLine(s)) });
99
+ t.push({ file: path.join(ws, 'lib', 'routes-slash.js'), begin: JS_BEGIN, end: JS_END, text: '\n' + slashEntries().map((e) => ' ' + JSON.stringify(e) + ',').join('\n') + '\n' });
100
+ return t;
101
+ }
102
+ function apply(src, t) {
103
+ const i = src.indexOf(t.begin), j = src.indexOf(t.end, i + 1);
104
+ if (i < 0 || j < 0) throw new Error('the card-catalog markers are missing in ' + t.file);
105
+ return src.slice(0, i + t.begin.length) + t.text + src.slice(j);
106
+ }
107
+
108
+ /* The verbs bin/pmos.js handles itself, before lib/pmos-verbs.js: verb → its module. */
109
+ const BIN_VERBS = { schedule: 'schedule-cli.js', skill: 'schedule-cli.js', proactive: 'proactive-cli.js', item: 'item-cli.js', kg: 'kg-cli.js' };
110
+ function handlerMissing() {
111
+ const V = require('./pmos-verbs');
112
+ const miss = [];
113
+ for (const c of allCommands()) {
114
+ const mod = BIN_VERBS[c.verb] || (V.VERBS[c.verb] && V.VERBS[c.verb].module);
115
+ const f = mod && path.join(__dirname, mod);
116
+ if (!f || !fs.existsSync(f)) { miss.push('pmos ' + cmdKey(c)); continue; }
117
+ const subs = ((require(f).COMMANDS || {})[c.verb]) || [];
118
+ for (const s of String(c.sub).split('|')) if (s && !subs.includes(s)) miss.push('pmos ' + c.verb + ' ' + s);
119
+ }
120
+ return miss;
121
+ }
122
+
123
+ module.exports = { SCOPES, JS_BEGIN, JS_END, allCommands, usage, scopeLine, agentsBlock, slashEntries, targets, apply, handlerMissing };
@@ -59,6 +59,7 @@ const RULE = [
59
59
  'You are the chief: the one live session over every Program, Product and Project. Each unit has one owner, a record with a daily brief, never a session; an initiative in a program is the program\'s, else its product\'s. Never ask another session; read the records. `pmos units` lists the units and their briefs. You may run these yourself: `pmos owner brief [<unit>]` (a fresh brief now), `pmos team dispatch --unit <unit>` (the roles for the unit\'s first open initiative), `pmos team pause|resume --unit <unit>` (stop or restart the role runs on a unit). When the same lesson shows in two units, file it with `pmos propose` as a workspace rule the PM keeps or drops.',
60
60
  'Answer in plain sentences, the answer first. Never start with "I can help with".',
61
61
  'Speak to the PM as "you", in the first person ("I archived them"). Never write "The PM says" or speak of the PM in the third person.',
62
+ /* card-catalog:begin, generated by bin/card-catalog-gen.js: edit lib/card-catalog.json, not this block */"The card buttons run these pmos commands (the card catalog; who acts: you = one press with Undo, agent = PMOS starts a run, waits = only after the PM says yes). Run the one that fits the PM's ask, and tell the PM the Undo line it prints: Work items: pmos task set, pmos task state, pmos task comment, pmos task describe, pmos task remove, pmos task add, pmos rehearse move, pmos task link, pmos task unlink, pmos item move, pmos item set, pmos item withdraw, pmos my-work show; Initiatives and programs: pmos task add, pmos initiative up|down, pmos initiative top|bottom, pmos initiative after, pmos initiative check-by, pmos initiative kind, pmos workflow switch, pmos workflow move, pmos initiative describe, pmos parked hold, pmos initiative export, pmos initiative adopt, pmos initiative drop, pmos parked back, pmos program check, pmos program milestone, pmos program join, pmos program leave, pmos program charter, pmos program capacity, pmos program decide, pmos program order, pmos program archive, pmos program task, pmos program task-done, pmos units show, pmos launch check, pmos launch tier, pmos ready check; Strategy, goals and evidence: pmos strategy set, pmos strategy draft, pmos strategy undo, pmos positioning keep, pmos positioning drop, pmos principles keep, pmos principles drop, pmos principles undo, pmos principles add, pmos artefacts set, pmos artefacts undo, pmos proactive goals, pmos measure add, pmos outcomes declare, pmos outcomes test, pmos outcomes record, pmos decisions add, pmos decisions check, pmos decisions undo, pmos glossary set, pmos glossary remove, pmos signal add, pmos signal remove, pmos forecast baseline, pmos forecast baseline-off; People and conversations: pmos people record, pmos mention draft, pmos mention answered, pmos mention watch, pmos mention stands, pmos signoff ask, pmos signoff answer, pmos signoff drop, pmos jira answer; What PMOS proposes and does: pmos driver keep, pmos driver return, pmos driver drop, pmos driver undo, pmos driver pause, pmos proactive feedback, pmos rules edit, pmos rules retire, pmos rules restore, pmos autonomy restore, pmos autonomy check, pmos ai off, pmos ai on, pmos team pause|resume, pmos team dispatch, pmos scan match, pmos critic label; Tracker, documents and sources: pmos task set, pmos jira pin, pmos jira approve, pmos jira criteria-propose, pmos jira epic, pmos docs link, pmos docs unlink, pmos docs sync-start, pmos refresh since, pmos calendar import; Reports, routines and rehearsals: pmos rehearse move, pmos report draft, pmos report check, pmos report rule, pmos report issue, pmos schedule run, pmos schedule disable|enable, pmos schedule edit, pmos schedule rm, pmos rehearse end, pmos rehearse cut, pmos press-release , pmos skill copy, pmos skill edit; Factory (Full ADLC): pmos workflow switch, pmos build rollout, pmos build rollback, pmos build review, pmos loop stop, pmos loop resume, pmos lab delete, pmos lab undo, pmos grill mode, pmos grill cap. Each command's own help gives its flags."/* card-catalog:end */,
62
63
  ].join('\n');
63
64
 
64
65
  /** The message as typed into a live session. page: the "You are on …" chip's words, or '' when the PM dropped it. */
@@ -0,0 +1,177 @@
1
+ 'use strict';
2
+ /* declined-asks.js — saying no, kindly and on record (initiative declined-asks-reply, bet A326). A PM closes many asks without doing them
3
+ * (Won't Do, Declined, Duplicate…). PMOS lists them from the product's stored Jira readings, drafts a short, kind reply to the person who
4
+ * asked, and, when the PM records one, writes it to the product's out-of-scope list, where lib/past.js (and the "You decided this before"
5
+ * check, lib/past-repeat.js) finds a later repeat of the same ask.
6
+ *
7
+ * PMOS NEVER SENDS THE REPLY. It is a draft the PM copies and sends where they talk to that person. No model, no network, no Jira write.
8
+ *
9
+ * declinedOf(readings, { now, days }) → [ask] PURE: the asks closed without being done in the window, newest first
10
+ * reasonOf(ask) → string PURE: the default reason, from the status or the resolution
11
+ * replyFor(ask, { reason }) → string PURE: the reply draft, at most 3 sentences
12
+ * collect(root, { now, days }) → [ask] every stored Jira reading of the product (lib/jira-status.js)
13
+ * record(root, key, { reason, now, asks }) → { ok, ask, reply, file } | { ok: false, error }
14
+ * recorded(root) → [line] the recorded asks, last line per key
15
+ * CLI: node declined-asks.js recorded → the count on its last line (the experiment's health read)
16
+ *
17
+ * AN ASK is { key, summary, status, resolution, reporter, resolved, url }. The reading carries the reporter's display name only, never an
18
+ * email (lib/jira-status.js askedClosed).
19
+ *
20
+ * THE RECORD. One line per record in `declined-asks.jsonl` in the product's records folder, { at, key, summary, reporter, reason, reason_by:
21
+ * 'pm' | 'pmos', reply, file }, and `planning/out-of-scope/<key>.md` (type Reference, decision: declined). A later record of the same key
22
+ * replaces the file only while it is still the one PMOS wrote (its text matches the last line's hash); a file the PM changed is kept.
23
+ */
24
+ const fs = require('fs');
25
+ const path = require('path');
26
+ const crypto = require('crypto');
27
+
28
+ const FILE = 'declined-asks.jsonl';
29
+ const DAYS = 90;
30
+ const DAY_MS = 86400000;
31
+ const KEY_RE = /^[A-Z][A-Z0-9_]*-\d+$/;
32
+ // Closed without being done, by the status's or the resolution's name (lib/task-jira.js CLOSED_NOT_DONE, the same words).
33
+ const CLOSED_NOT_DONE = /invalid|not an issue|won'?t|cancel|duplicate|reject|obsolete|not (?:needed|required|a bug|reproducible)|cannot reproduce|declined|abandon/i;
34
+ const DONE_WORD = /\b(done|closed|resolved|released|complete|shipped|deployed)\b/i;
35
+ const log = (s) => { try { console.log('[declined-asks] ' + s); } catch { /* no console */ } };
36
+
37
+ const one = (v, n = 200) => { const s = String(v == null ? '' : v).replace(/\s+/g, ' ').trim(); return s.length > n ? s.slice(0, n - 1).trimEnd() + '…' : s; };
38
+ const hash = (s) => crypto.createHash('sha1').update(String(s)).digest('hex').slice(0, 12);
39
+ const dayOf = (v) => { const m = /^(\d{4}-\d{2}-\d{2})/.exec(String(v || '')); return m ? m[1] : null; };
40
+
41
+ /** True when the reading was closed without being done: its status or its resolution says so. */
42
+ function isDeclined(r) {
43
+ if (!r) return false;
44
+ const st = String(r.status || ''), res = String(r.resolution || '');
45
+ if (CLOSED_NOT_DONE.test(st)) return true;
46
+ const closed = String(r.category || '').toLowerCase() === 'done' || DONE_WORD.test(st) || !!r.resolved;
47
+ return closed && !!res && CLOSED_NOT_DONE.test(res);
48
+ }
49
+
50
+ /** PURE. The asks closed without being done, resolved in the last `days` days (a ticket with no resolution day counts by its last
51
+ * update), newest first, one per key. */
52
+ function declinedOf(readings, { now = Date.now(), days = DAYS } = {}) {
53
+ const since = new Date(now - days * DAY_MS).toISOString().slice(0, 10);
54
+ const by = new Map();
55
+ for (const r of readings || []) {
56
+ if (!r || !KEY_RE.test(String(r.key || '')) || !isDeclined(r)) continue;
57
+ const day = dayOf(r.resolved) || dayOf(r.updated);
58
+ if (!day || day < since) continue;
59
+ const a = { key: r.key, summary: one(r.summary, 250), status: one(r.status, 60), resolution: r.resolution ? one(r.resolution, 60) : null,
60
+ reporter: r.reporter ? one(r.reporter, 80) : null, resolved: day, url: r.url || null };
61
+ const old = by.get(a.key);
62
+ if (!old || a.resolved > old.resolved) by.set(a.key, a);
63
+ }
64
+ return [...by.values()].sort((x, y) => (x.resolved < y.resolved ? 1 : x.resolved > y.resolved ? -1 : x.key < y.key ? -1 : 1));
65
+ }
66
+
67
+ /** PURE. The reason a reply gives when the PM gave none, from the words the ticket was closed with. */
68
+ function reasonOf(ask) {
69
+ const w = `${(ask && ask.resolution) || ''} ${(ask && ask.status) || ''}`;
70
+ if (/duplicate/i.test(w)) return 'it is already covered by another ticket, so the work happens there';
71
+ if (/not a bug|not an issue|cannot reproduce|not reproducible|invalid/i.test(w)) return 'we could not find a problem to fix as it was described';
72
+ if (/obsolete|not (?:needed|required)/i.test(w)) return 'it is no longer needed after other changes';
73
+ if (/cancel|abandon/i.test(w)) return 'the work it belonged to was stopped';
74
+ return 'it does not fit what we are working on now';
75
+ }
76
+
77
+ /** PURE. The kind reply draft: thanks for the ask, the decision and its reason, what would bring it back. 3 sentences at most. */
78
+ function replyFor(ask, { reason } = {}) {
79
+ const first = ask && ask.reporter ? one(ask.reporter, 80).split(/\s+/)[0] : '';
80
+ const what = one((ask && ask.summary) || 'this', 120).replace(/[.!?…]+$/, '');
81
+ const why = one(reason || reasonOf(ask), 220).replace(/[.!?…]+$/, '');
82
+ const greet = first ? `Hi ${first}, thank you` : 'Thank you';
83
+ return `${greet} for asking for "${what}" (${ask.key}). We decided not to take it on for now, because ${why.charAt(0).toLowerCase() + why.slice(1)}. If something changes, for example more people need it, we will look at it again.`;
84
+ }
85
+
86
+ // ── the readings ────────────────────────────────────────────────────────────────────────────────────
87
+ function jiraDirOf(root) { try { return require('./jira-tickets.js').jiraDir(root); } catch { return null; } }
88
+ function readingsOf(root) {
89
+ const dir = jiraDirOf(root);
90
+ if (!dir) return [];
91
+ let names;
92
+ try { names = fs.readdirSync(dir); } catch { return []; }
93
+ const JS = require('./jira-status.js');
94
+ const out = [];
95
+ for (const n of names.sort()) {
96
+ if (!n.endsWith('.md') || n.endsWith('-tickets.md') || n === '_sprint-notes.md') continue;
97
+ const snap = JS.readSnapshot(root, n.slice(0, -3));
98
+ if (snap) for (const r of snap.tickets.values()) out.push(r);
99
+ }
100
+ return out;
101
+ }
102
+ /** Every declined ask in the product's stored Jira readings. */
103
+ function collect(root, opts = {}) { return declinedOf(readingsOf(root), opts); }
104
+
105
+ // ── the record ──────────────────────────────────────────────────────────────────────────────────────
106
+ function recordsDirOf(root) {
107
+ try { const { repoScript } = require('./repo-script.js'); return require(repoScript('signals/layout-paths.js')).pathsFor(root).recordsDir; } catch { return path.join(root, 'planning', 'records'); }
108
+ }
109
+ const ledgerOf = (root) => path.join(recordsDirOf(root), FILE);
110
+ const outOfScopeRel = (key) => `planning/out-of-scope/${String(key).toLowerCase()}.md`;
111
+
112
+ function readLedger(root) {
113
+ let text;
114
+ try { text = fs.readFileSync(ledgerOf(root), 'utf8'); } catch { return []; }
115
+ const out = [];
116
+ for (const l of text.split('\n')) { if (!l.trim()) continue; try { const o = JSON.parse(l); if (o && KEY_RE.test(String(o.key || ''))) out.push(o); } catch { /* a torn line is skipped */ } }
117
+ return out;
118
+ }
119
+ /** The recorded asks, the last line for each key wins, newest first. */
120
+ function recorded(root) {
121
+ const by = new Map();
122
+ for (const o of readLedger(root)) by.set(o.key, o);
123
+ return [...by.values()].sort((a, b) => (a.at < b.at ? 1 : -1));
124
+ }
125
+
126
+ const yq = (s) => '"' + String(s).replace(/\\/g, '\\\\').replace(/"/g, '\\"') + '"';
127
+ function fileText(ask, { reason, reply, day }) {
128
+ return [
129
+ '---', 'type: Reference', `title: ${yq(one(ask.summary, 150))}`, `timestamp: ${day}`, `ticket: ${ask.key}`, 'decision: declined', '---', '',
130
+ `# ${one(ask.summary, 150)}`, '',
131
+ '- decision: declined', `- date: ${ask.resolved || day}`, `- ticket: ${ask.key}${ask.url ? ' (' + ask.url + ')' : ''}`,
132
+ ...(ask.reporter ? [`- asked by: ${ask.reporter}`] : []), `- closed as: ${ask.resolution || ask.status}`, '',
133
+ '## Reasoning', '', `Declined because ${reason}.`, '',
134
+ '## Reply draft', '', 'PMOS drafted this reply. It was not sent.', '', '> ' + reply, '',
135
+ `Recorded by \`pmos declined record ${ask.key}\`. Edit this file freely: PMOS does not write over it once you change it.`, '',
136
+ ].join('\n');
137
+ }
138
+
139
+ /** Record one declined ask: a ledger line and the out-of-scope file. `asks` (optional) is the list to find the key in (default: collect). */
140
+ function record(root, key, { reason, now = Date.now(), asks } = {}) {
141
+ const k = String(key || '').trim().toUpperCase();
142
+ if (!KEY_RE.test(k)) return { ok: false, error: `"${key}" is not a ticket key such as ABC-123` };
143
+ const list = asks || collect(root, { now, days: 3650 });
144
+ const ask = list.find((a) => a.key === k);
145
+ if (!ask) return { ok: false, error: `${k} is not a declined ask in this product's Jira readings (pmos declined lists them)` };
146
+ const own = one(reason || '', 220).replace(/[.!?…]+$/, '');
147
+ const why = own || reasonOf(ask);
148
+ const reply = replyFor(ask, { reason: why });
149
+ const day = new Date(now).toISOString().slice(0, 10);
150
+ const rel = outOfScopeRel(k);
151
+ const abs = path.join(root, rel);
152
+ const text = fileText(ask, { reason: why.charAt(0).toLowerCase() + why.slice(1), reply, day });
153
+ const last = recorded(root).find((o) => o.key === k);
154
+ let kept = false;
155
+ if (fs.existsSync(abs)) {
156
+ let cur = '';
157
+ try { cur = fs.readFileSync(abs, 'utf8'); } catch { /* unreadable: keep it */ }
158
+ if (!last || hash(cur) !== last.file_hash) kept = true; // the PM wrote or changed it
159
+ }
160
+ if (!kept) { fs.mkdirSync(path.dirname(abs), { recursive: true }); fs.writeFileSync(abs, text); }
161
+ const lineObj = { at: new Date(now).toISOString(), key: k, summary: ask.summary, reporter: ask.reporter, reason: why, reason_by: own ? 'pm' : 'pmos', reply,
162
+ file: rel, file_hash: kept ? (last ? last.file_hash : null) : hash(text), kept_pm_file: kept || undefined };
163
+ fs.mkdirSync(path.dirname(ledgerOf(root)), { recursive: true });
164
+ fs.appendFileSync(ledgerOf(root), JSON.stringify(lineObj) + '\n');
165
+ log(`recorded ${k} (${lineObj.reason_by} reason)${kept ? '; kept the out-of-scope file the PM changed' : ''}`);
166
+ return { ok: true, ask, reply, reason: why, file: rel, kept };
167
+ }
168
+
169
+ module.exports = { FILE, DAYS, isDeclined, declinedOf, reasonOf, replyFor, collect, record, recorded, outOfScopeRel };
170
+
171
+ if (require.main === module) {
172
+ const [cmd, root] = process.argv.slice(2);
173
+ if (cmd === 'recorded') {
174
+ const r = path.resolve(root || process.cwd());
175
+ process.stdout.write(String(recorded(r).length) + '\n');
176
+ } else { process.stdout.write('usage: node declined-asks.js recorded [<product root>]\n'); process.exitCode = 2; }
177
+ }