@bigmistqke/workpad 0.18.1 → 0.19.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 (55) hide show
  1. package/bin/workpad.ts +225 -21
  2. package/dist/bin/workpad.js +181 -15
  3. package/dist/plugins/badge/README.md +59 -10
  4. package/dist/plugins/badge/index.js +130 -8
  5. package/dist/plugins/badge/public/style.css +132 -12
  6. package/dist/plugins/chat/index.js +7 -1
  7. package/dist/plugins/claude/README.md +13 -5
  8. package/dist/plugins/claude/channel.js +25 -2
  9. package/dist/plugins/claude/doctor.js +43 -47
  10. package/dist/plugins/claude/index.js +24 -8
  11. package/dist/plugins/claude/session.js +46 -1
  12. package/dist/plugins/opencode/channel.js +42 -7
  13. package/dist/plugins/opencode/index.js +2 -0
  14. package/dist/src/agents.js +6 -1
  15. package/dist/src/events.js +6 -5
  16. package/dist/src/help.js +16 -4
  17. package/dist/src/hub.js +55 -2
  18. package/dist/src/listen.js +36 -4
  19. package/dist/src/listeners.js +14 -4
  20. package/dist/src/pages/board.js +9 -4
  21. package/dist/src/pages/index.js +2 -4
  22. package/dist/src/pages/markdown.js +47 -16
  23. package/dist/src/pages/render.js +1 -1
  24. package/dist/src/server.js +69 -6
  25. package/dist/src/state.js +2 -1
  26. package/dist/src/status.js +11 -2
  27. package/dist/src/turns.js +41 -0
  28. package/package.json +6 -1
  29. package/plugins/badge/README.md +59 -10
  30. package/plugins/badge/index.ts +141 -8
  31. package/plugins/badge/public/style.css +132 -12
  32. package/plugins/chat/index.ts +9 -1
  33. package/plugins/claude/README.md +13 -5
  34. package/plugins/claude/channel.ts +26 -2
  35. package/plugins/claude/doctor.ts +58 -39
  36. package/plugins/claude/index.ts +30 -8
  37. package/plugins/claude/session.ts +32 -0
  38. package/plugins/opencode/channel.ts +42 -7
  39. package/plugins/opencode/index.ts +4 -0
  40. package/skills/workpad/SKILL.md +23 -3
  41. package/src/agents.ts +7 -0
  42. package/src/define.ts +28 -1
  43. package/src/events.ts +23 -2
  44. package/src/help.ts +16 -4
  45. package/src/hub.ts +71 -2
  46. package/src/listen.ts +47 -4
  47. package/src/listeners.ts +22 -1
  48. package/src/pages/board.ts +10 -3
  49. package/src/pages/index.ts +8 -10
  50. package/src/pages/markdown.ts +55 -8
  51. package/src/pages/render.ts +1 -1
  52. package/src/server.ts +84 -6
  53. package/src/state.ts +3 -0
  54. package/src/status.ts +15 -1
  55. package/src/turns.ts +56 -0
@@ -1,7 +1,6 @@
1
- A status as a coloured dot and a word, inline wherever text goes: in a
2
- heading, a table cell, a list item, a sentence. `done ok yes good` are
3
- green, `active new info` blue, `open todo maybe warning` amber,
4
- `blocked no bad error` red; any other word is grey.
1
+ A status as a word, small and inline wherever text goes: in a heading, a
2
+ table cell, a list item, a sentence. A grey dot before it, unless it says
3
+ otherwise.
5
4
 
6
5
  ```markdown
7
6
  ### Parser :badge[done]
@@ -15,12 +14,6 @@ green, `active new info` blue, `open todo maybe warning` amber,
15
14
  The release is :badge[blocked] on review.
16
15
  ```
17
16
 
18
- A badge that ends a heading sits at its right edge: a page's heading, a grid
19
- card's, a timeline step's. A block of your own can have the same for a title
20
- that isn't a heading, with a `data-wp-title` attribute on it. A badge is not
21
- in a heading's anchor, nor in an item's: `### Parser :badge[done]` is
22
- `#parser`, so a link to it holds while the badge changes.
23
-
24
17
  ### Parser :badge[done]
25
18
 
26
19
  | step | state |
@@ -30,3 +23,59 @@ in a heading's anchor, nor in an item's: `### Parser :badge[done]` is
30
23
  | docs | :badge[todo] |
31
24
 
32
25
  The release is :badge[blocked] on review.
26
+
27
+ Its look, each attribute off unless set, each colour a name from the
28
+ palette `red orange yellow green blue violet pink grey` (tuned per theme, so
29
+ the text reads on the page and on a fill):
30
+
31
+ - `color`: the dot and the text.
32
+ - `background`: a fill behind them; the text takes the palette's readable
33
+ shade for it, so `{background=red}` alone is a red pill.
34
+ - `border`: an outline.
35
+ - `live`: the dot pulses (still for a reader who asks for less motion).
36
+
37
+ A fill or an outline stands without the dot, unless it is `live`.
38
+
39
+ ```markdown
40
+ :badge[busy]{color=green live} :badge[you]{background=red} :badge[on hold]{color=orange border=orange}
41
+ ```
42
+
43
+ :badge[busy]{color=green live} :badge[you]{background=red} :badge[on hold]{color=orange border=orange}
44
+
45
+ **Presets** name looks, in the config: a badge whose word is the name takes
46
+ its preset (`:badge[you]`, the word as its text lowercased, other characters
47
+ a `-`), and so does one that names it (`:badge[Jonathan]{preset=person}`). A
48
+ preset sets any of the badge's own attributes, and nothing else.
49
+
50
+ ```ts
51
+ // .workpad/config.ts
52
+ import badge from '@bigmistqke/workpad/badge'
53
+
54
+ export default defineConfig({
55
+ plugins: [
56
+ badge({
57
+ presets: {
58
+ you: { background: 'red' },
59
+ 'on hold': { color: 'orange', border: 'orange' },
60
+ busy: { color: 'green', live: true },
61
+ person: { color: 'violet' },
62
+ },
63
+ }),
64
+ ],
65
+ })
66
+ ```
67
+
68
+ The built-in words are presets too: `done ok yes good` green,
69
+ `active new info` blue, `open todo maybe warning` orange,
70
+ `blocked no bad error` red. A project's preset of the same word replaces one.
71
+
72
+ Most specific wins, attribute by attribute: the badge's own attributes, then
73
+ its `preset=`, then its word's preset. An unknown colour, preset or attribute
74
+ is listed by `workpad check` and shown above the page; a bad preset stops the
75
+ config from loading, saying which.
76
+
77
+ A badge that ends a heading sits at its right edge: a page's heading, a grid
78
+ card's, a timeline step's. A block of your own can have the same for a title
79
+ that isn't a heading, with a `data-wp-title` attribute on it. A badge is not
80
+ in a heading's anchor, nor in an item's: `### Parser :badge[done]` is
81
+ `#parser`, so a link to it holds while the badge changes.
@@ -2,15 +2,126 @@ import { builtinPublic } from "../../src/package.js";
2
2
  import fs from "node:fs";
3
3
  import { definePlugin, html, raw } from "@bigmistqke/workpad";
4
4
  // plugins/badge/index.ts
5
- /** The word a badge's colour is chosen by: its text, lowercased, runs of other characters a `-`. */
5
+ /** The colours a badge takes, by name; each tuned per theme for readable text (style.css). */
6
+ const PALETTE = [
7
+ "red",
8
+ "orange",
9
+ "yellow",
10
+ "green",
11
+ "blue",
12
+ "violet",
13
+ "pink",
14
+ "grey"
15
+ ];
16
+ const COLOURED = [
17
+ "color",
18
+ "background",
19
+ "border"
20
+ ];
21
+ const KEYS = [...COLOURED, "live"];
22
+ const palette = PALETTE.join(", ");
23
+ /** The built-in words: default presets, which a project's presets replace word by word. */
24
+ const BUILTIN_PRESETS = Object.fromEntries([
25
+ ...[
26
+ "done",
27
+ "ok",
28
+ "yes",
29
+ "good"
30
+ ].map((w) => [w, { color: "green" }]),
31
+ ...[
32
+ "active",
33
+ "new",
34
+ "info"
35
+ ].map((w) => [w, { color: "blue" }]),
36
+ ...[
37
+ "open",
38
+ "todo",
39
+ "maybe",
40
+ "warning"
41
+ ].map((w) => [w, { color: "orange" }]),
42
+ ...[
43
+ "blocked",
44
+ "no",
45
+ "bad",
46
+ "error"
47
+ ].map((w) => [w, { color: "red" }])
48
+ ]);
49
+ /** The word a badge's preset is found by: its text, lowercased, runs of other characters a `-`. */
6
50
  const tone = (s) => s.toLowerCase().trim().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
7
- /** `:badge[done]`: a coloured dot and a word, inline wherever text goes. */
8
- function render(ctx) {
51
+ const isColour = (v) => typeof v === "string" && PALETTE.includes(v);
52
+ /**
53
+ * A config's presets, checked, by their words (tone()), over the built-in words: what is wrong
54
+ * throws, so the config fails to load and says why.
55
+ */
56
+ function presetsOf(given = {}) {
57
+ if (typeof given !== "object" || given === null || Array.isArray(given)) throw new Error("badge: `presets` is an object of looks by name: `{ you: { background: \"red\" } }`");
58
+ const own = {};
59
+ const named = {};
60
+ for (const [name, look] of Object.entries(given)) {
61
+ const word = tone(name);
62
+ const where = `badge: preset "${name}"`;
63
+ if (!word) throw new Error(`${where} has no letter or digit: a badge's word couldn't reach it`);
64
+ if (word in named) throw new Error(`${where} is the same word as "${named[word]}" (${word})`);
65
+ named[word] = name;
66
+ if (typeof look !== "object" || look === null || Array.isArray(look)) throw new Error(`${where} is a look: an object such as \`{ color: 'green' }\``);
67
+ for (const [k, v] of Object.entries(look)) {
68
+ if (!KEYS.includes(k)) throw new Error(`${where} sets \`${k}\`, which a badge hasn't: a preset sets ${KEYS.join(", ")}`);
69
+ if (k === "live" ? typeof v !== "boolean" : !isColour(v)) throw new Error(k === "live" ? `${where} has \`live: ${JSON.stringify(v)}\`: it is true or false` : `${where} has no colour ${JSON.stringify(v)} for \`${k}\`: the palette is ${palette}`);
70
+ }
71
+ own[word] = { ...look };
72
+ }
73
+ return {
74
+ ...BUILTIN_PRESETS,
75
+ ...own
76
+ };
77
+ }
78
+ /**
79
+ * The look of a badge of `text` with `attrs`, attribute by attribute the most specific: its own
80
+ * attributes, then the preset it names (`preset=`), then its word's preset (the built-in words
81
+ * among them). A value it doesn't know is reported, and the next one down holds.
82
+ */
83
+ function lookOf(text, attrs, presets, report = () => {}) {
84
+ const written = `\`:badge[${text}]\``;
85
+ const own = {};
86
+ for (const k of COLOURED) {
87
+ const v = attrs[k];
88
+ if (v === void 0) continue;
89
+ if (isColour(v)) own[k] = v;
90
+ else report(`${written} has no colour \`${v}\` for \`${k}\`: the palette is ${palette}`);
91
+ }
92
+ if (attrs.live !== void 0) {
93
+ if (attrs.live === "" || attrs.live === "true") own.live = true;
94
+ else if (attrs.live === "false") own.live = false;
95
+ else report(`${written} has \`live=${attrs.live}\`: it is \`{live}\` or \`{live=false}\``);
96
+ }
97
+ let named = {};
98
+ if (attrs.preset !== void 0) {
99
+ const found = presets[tone(attrs.preset)];
100
+ if (found) named = found;
101
+ else report(`${written} names no preset \`${attrs.preset}\`: there are ${Object.keys(presets).map((p) => `\`${p}\``).join(", ")}`);
102
+ }
103
+ const look = {};
104
+ for (const layer of [
105
+ presets[tone(text)] ?? {},
106
+ named,
107
+ own
108
+ ]) for (const [k, v] of Object.entries(layer)) if (v !== void 0) look[k] = v;
109
+ return look;
110
+ }
111
+ /** `:badge[done]`: a word, with a coloured dot, a fill or an outline, inline wherever text goes. */
112
+ function render(ctx, presets = BUILTIN_PRESETS) {
9
113
  const text = ctx.labelText?.trim();
10
114
  if (!text) return html``;
11
- return html`<span class="wp-badge" data-badge="${tone(text)}">${raw(ctx.label ?? "")}</span>`;
115
+ const look = lookOf(text, ctx.attrs, presets, (p) => ctx.problem(p));
116
+ const word = tone(text);
117
+ const builtin = presets[word] !== void 0 && presets[word] === BUILTIN_PRESETS[word] && ctx.attrs.color === void 0 && (ctx.attrs.preset === void 0 || presets[tone(ctx.attrs.preset)]?.color === void 0);
118
+ const shows = html`${COLOURED.map((k) => look[k] && html` data-${k}="${look[k]}"`)}${look.live && html` data-live`}${builtin && look.color && html` data-dot`}`;
119
+ const label = raw(ctx.label ?? "");
120
+ return html`<span class="wp-badge" data-badge="${tone(text)}"${shows}>${label}</span>`;
12
121
  }
13
- function badge() {
122
+ function badge(options = {}) {
123
+ const presets = presetsOf(options.presets);
124
+ const own = Object.keys(options.presets ?? {});
14
125
  return definePlugin({
15
126
  name: "badge",
16
127
  public: builtinPublic("badge"),
@@ -19,10 +130,21 @@ function badge() {
19
130
  group: "mark",
20
131
  summary: "a status in a word: done, todo, waiting"
21
132
  },
22
- html: render,
133
+ attrs: [
134
+ "color",
135
+ "background",
136
+ "border",
137
+ "live",
138
+ "preset"
139
+ ],
140
+ html: (ctx) => render(ctx, presets),
23
141
  style: "style.css"
24
142
  } },
25
- docs: () => fs.readFileSync(new URL("./README.md", import.meta.url), "utf8")
143
+ docs: () => {
144
+ const readme = fs.readFileSync(new URL("./README.md", import.meta.url), "utf8");
145
+ if (!own.length) return readme;
146
+ return `${readme}\nThis project's presets:\n\n${own.map((name) => `- \`${name}\`: ${JSON.stringify(options.presets[name])}`).join("\n")}\n`;
147
+ }
26
148
  });
27
149
  }
28
- export { badge as default, render, tone };
150
+ export { BUILTIN_PRESETS, PALETTE, badge as default, lookOf, presetsOf, render, tone };
@@ -1,30 +1,150 @@
1
- /* a coloured dot and a word, not a pill */
1
+ /* A word, small, with a dot before it; a colour, a fill, an outline and a pulse when it says so
2
+ (data-color, data-background, data-border, data-live, from its attributes and presets).
3
+
4
+ The palette, per theme: each colour (--wp-badge-<name>) as text and dot at least 4.5:1 on the
5
+ page and the surfaces a badge sits on (cards, tables, code), and as a fill under its readable
6
+ text (--wp-badge-ink) at least 4.5:1 (test/browser/badge.test.ts measures both). A project can
7
+ retune one in its own stylesheet, both themes at once: `--wp-badge-orange: light-dark(#9a4a06, #ffa462)`. */
8
+ :root {
9
+ --wp-badge-red: light-dark(#c4352b, #ff6f66);
10
+ --wp-badge-orange: light-dark(#a84d08, #ff9a4d);
11
+ --wp-badge-yellow: light-dark(#8a6500, #e8c547);
12
+ --wp-badge-green: light-dark(#1a7a49, #57c48c);
13
+ --wp-badge-blue: light-dark(#1d5bbf, #82aaff);
14
+ --wp-badge-violet: light-dark(#6b4fc0, #b4a0ff);
15
+ --wp-badge-pink: light-dark(#be185d, #f78fc0);
16
+ --wp-badge-grey: light-dark(#696e76, #979ca5);
17
+ /* a fill is the colour itself; the text on it this: white on the light theme's dark shades,
18
+ near-black on the dark theme's light ones */
19
+ --wp-badge-ink: light-dark(#ffffff, #131417);
20
+ }
21
+
2
22
  .wp-badge {
3
- --c: var(--muted);
4
23
  display: inline-flex;
5
24
  align-items: center;
6
25
  gap: var(--space-sm);
7
26
  font: 500 var(--ui-tiny)/1 var(--sans);
8
- color: var(--muted);
27
+ /* on a fill, its ink; else the colour; else as text beside the page's */
28
+ color: var(--wp-badge-on, var(--wp-badge-c, var(--muted)));
29
+ background: var(--wp-badge-fill, none);
9
30
  white-space: nowrap;
10
31
  vertical-align: 0.1em;
11
32
  }
12
33
  .wp-badge::before {
13
34
  content: '';
35
+ flex: none;
14
36
  width: 7px;
15
37
  height: 7px;
16
38
  border-radius: 50%;
17
- background: var(--c);
39
+ --wp-badge-dot: var(--wp-badge-c, var(--wp-badge-on, var(--muted)));
40
+ background: var(--wp-badge-dot);
41
+ }
42
+ /* a built-in word (done, todo, …): the colour is its dot's, the text stays grey */
43
+ .wp-badge[data-dot]:not([data-background]) {
44
+ color: var(--muted);
45
+ }
46
+ /* a fill or an outline makes it a pill, which stands without a dot, unless the dot is live */
47
+ .wp-badge:is([data-background], [data-border]) {
48
+ padding: 2px 7px;
49
+ border: var(--hairline) solid var(--wp-badge-line, transparent);
50
+ border-radius: var(--radius-pill);
51
+ }
52
+ .wp-badge:is([data-background], [data-border]):not([data-live])::before {
53
+ display: none;
54
+ }
55
+
56
+ .wp-badge[data-color='red'] {
57
+ --wp-badge-c: var(--wp-badge-red);
58
+ }
59
+ .wp-badge[data-color='orange'] {
60
+ --wp-badge-c: var(--wp-badge-orange);
61
+ }
62
+ .wp-badge[data-color='yellow'] {
63
+ --wp-badge-c: var(--wp-badge-yellow);
64
+ }
65
+ .wp-badge[data-color='green'] {
66
+ --wp-badge-c: var(--wp-badge-green);
67
+ }
68
+ .wp-badge[data-color='blue'] {
69
+ --wp-badge-c: var(--wp-badge-blue);
70
+ }
71
+ .wp-badge[data-color='violet'] {
72
+ --wp-badge-c: var(--wp-badge-violet);
73
+ }
74
+ .wp-badge[data-color='pink'] {
75
+ --wp-badge-c: var(--wp-badge-pink);
76
+ }
77
+ .wp-badge[data-color='grey'] {
78
+ --wp-badge-c: var(--wp-badge-grey);
79
+ }
80
+
81
+ .wp-badge[data-background] {
82
+ --wp-badge-on: var(--wp-badge-ink);
83
+ }
84
+ .wp-badge[data-background='red'] {
85
+ --wp-badge-fill: var(--wp-badge-red);
86
+ }
87
+ .wp-badge[data-background='orange'] {
88
+ --wp-badge-fill: var(--wp-badge-orange);
89
+ }
90
+ .wp-badge[data-background='yellow'] {
91
+ --wp-badge-fill: var(--wp-badge-yellow);
92
+ }
93
+ .wp-badge[data-background='green'] {
94
+ --wp-badge-fill: var(--wp-badge-green);
95
+ }
96
+ .wp-badge[data-background='blue'] {
97
+ --wp-badge-fill: var(--wp-badge-blue);
98
+ }
99
+ .wp-badge[data-background='violet'] {
100
+ --wp-badge-fill: var(--wp-badge-violet);
101
+ }
102
+ .wp-badge[data-background='pink'] {
103
+ --wp-badge-fill: var(--wp-badge-pink);
104
+ }
105
+ .wp-badge[data-background='grey'] {
106
+ --wp-badge-fill: var(--wp-badge-grey);
107
+ }
108
+
109
+ .wp-badge[data-border='red'] {
110
+ --wp-badge-line: var(--wp-badge-red);
111
+ }
112
+ .wp-badge[data-border='orange'] {
113
+ --wp-badge-line: var(--wp-badge-orange);
114
+ }
115
+ .wp-badge[data-border='yellow'] {
116
+ --wp-badge-line: var(--wp-badge-yellow);
117
+ }
118
+ .wp-badge[data-border='green'] {
119
+ --wp-badge-line: var(--wp-badge-green);
120
+ }
121
+ .wp-badge[data-border='blue'] {
122
+ --wp-badge-line: var(--wp-badge-blue);
123
+ }
124
+ .wp-badge[data-border='violet'] {
125
+ --wp-badge-line: var(--wp-badge-violet);
126
+ }
127
+ .wp-badge[data-border='pink'] {
128
+ --wp-badge-line: var(--wp-badge-pink);
18
129
  }
19
- .wp-badge:is([data-badge='done'], [data-badge='ok'], [data-badge='yes'], [data-badge='good']) {
20
- --c: var(--ok);
130
+ .wp-badge[data-border='grey'] {
131
+ --wp-badge-line: var(--wp-badge-grey);
21
132
  }
22
- .wp-badge:is([data-badge='active'], [data-badge='new'], [data-badge='info']) {
23
- --c: var(--info);
133
+
134
+ /* live: the dot pulses, a ring growing out of it and fading; still under reduced motion */
135
+ .wp-badge[data-live]::before {
136
+ animation: wp-badge-pulse 1.6s ease-out infinite;
24
137
  }
25
- .wp-badge:is([data-badge='open'], [data-badge='todo'], [data-badge='maybe'], [data-badge='warning']) {
26
- --c: var(--warn);
138
+ @keyframes wp-badge-pulse {
139
+ 0% {
140
+ box-shadow: 0 0 0 0 color-mix(in srgb, var(--wp-badge-dot) 55%, transparent);
141
+ }
142
+ 100% {
143
+ box-shadow: 0 0 0 5px transparent;
144
+ }
27
145
  }
28
- .wp-badge:is([data-badge='blocked'], [data-badge='no'], [data-badge='bad'], [data-badge='error']) {
29
- --c: var(--bad);
146
+ @media (prefers-reduced-motion: reduce) {
147
+ .wp-badge[data-live]::before {
148
+ animation: none;
149
+ }
30
150
  }
@@ -40,12 +40,18 @@ const chat = {
40
40
  };
41
41
  /** The chat at the bottom of every page (see `end`): for what is about none of its questions. */
42
42
  const PAGE_CHAT = "page";
43
+ /**
44
+ * Whether a page's text could name a chat (or a form, whose chat it is) `name`: a `name=` or `id=`
45
+ * of it, or `#name`. Without one it names none, and the page needs no parse to say so: most pages,
46
+ * whose status asks this for every page.
47
+ */
48
+ const mayName = (body, name) => new RegExp(`(?:\\bname|\\bid)\\s*=\\s*["']?${name}(?![\\w-])|#${name}(?![\\w-])`).test(body);
43
49
  function chatPlugin({ page: pageChat = true } = {}) {
44
50
  return definePlugin({
45
51
  name: "chat",
46
52
  end(page) {
47
53
  if (!pageChat || page.id.startsWith("-/")) return null;
48
- if (page.frontmatter.plugins?.chat === false || chatNames(page.body).includes("page")) return null;
54
+ if (page.frontmatter.plugins?.chat === false || mayName(page.body, "page") && chatNames(page.body).includes("page")) return null;
49
55
  return `:::chat{name=${PAGE_CHAT}}\nQuestions or remarks about this page:\n:::`;
50
56
  },
51
57
  public: builtinPublic("chat"),
@@ -97,11 +97,19 @@ command answers; the server approved and disabled in no settings file
97
97
  (`.claude/settings.json`, `settings.local.json`, `~/.claude/settings.json`,
98
98
  the project in `~/.claude.json`, and in a git worktree without its own
99
99
  `settings.local.json`, the main checkout's, where Claude Code writes an Esc
100
- on "New MCP server found"); the session started with the flag above, in
101
- the project's folder; the server up at the project's version; a channel
102
- for this session; and its ping confirmed. `/mcp` doesn't list a disabled
103
- server at all, so this is where to look. It changes nothing, and exits 1
104
- when something is to fix.
100
+ on "New MCP server found"); the session started with the flag above; the
101
+ server up at the project's version; a channel for this session; and its
102
+ ping confirmed. `/mcp` doesn't list a disabled server at all, so this is
103
+ where to look. It changes nothing, and exits 1 when something is to fix.
104
+
105
+ `.mcp.json` and the settings are read where Claude Code runs, which need
106
+ not be the pages' project: a wrapper can start a session in one folder (a
107
+ git worktree) with the pages of another. That folder is
108
+ `CLAUDE_PROJECT_DIR` when set, else the one the session's claude process
109
+ runs in, else the project's. When it differs, the doctor names both
110
+ (`pages: …; Claude's project: …`), and its fixes point at Claude's:
111
+ `workpad claude install --claude-dir <folder>` writes `.mcp.json` and the
112
+ hooks there.
105
113
 
106
114
  ## The turn-end check
107
115
 
@@ -1,5 +1,5 @@
1
- import { channelSince } from "../../src/status.js";
2
- import { ANSWERS_NOTE, answerLine, identity, pong } from "../../src/agents.js";
1
+ import { channelSince, takesUnfollowed } from "../../src/status.js";
2
+ import { ANSWERS_NOTE, answerLine, identity, pong, unfollowedLine } from "../../src/agents.js";
3
3
  import { read } from "../../src/events.js";
4
4
  import { claudeProcess, recordedSession } from "./session.js";
5
5
  import fs from "node:fs";
@@ -59,10 +59,33 @@ async function channel(ctx) {
59
59
  });
60
60
  };
61
61
  const followed = /* @__PURE__ */ new Set();
62
+ let unfollowed = null;
63
+ const takeUnfollowed = (session) => {
64
+ const wanted = takesUnfollowed(read(ctx.eventsFile).events, session);
65
+ if (unfollowed && (!wanted || unfollowed.session !== session)) {
66
+ unfollowed.stop.abort();
67
+ unfollowed = null;
68
+ }
69
+ if (!wanted || unfollowed) return;
70
+ unfollowed = {
71
+ session,
72
+ stop: new AbortController()
73
+ };
74
+ ctx.unfollowed((e, again, from) => notify(unfollowedLine(e, again, from), {
75
+ page: e.page,
76
+ id: e.id,
77
+ type: e.type,
78
+ ...from && { project: from.project }
79
+ }), {
80
+ agent: session,
81
+ signal: unfollowed.stop.signal
82
+ }).catch((err) => problem("taking the unfollowed pages failed", String(err)));
83
+ };
62
84
  const follow = async () => {
63
85
  const session = current();
64
86
  hold(session);
65
87
  if (!confirmed || !session) return;
88
+ takeUnfollowed(session);
66
89
  const pages = (await ctx.status()).filter((p) => p.subscribers.includes(session)).map((p) => p.page);
67
90
  for (const page of pages) {
68
91
  if (followed.has(page)) continue;
@@ -1,4 +1,4 @@
1
- import { claudePid, claudeProcess, recordedSession } from "./session.js";
1
+ import { claudeFolder, claudePid, claudeProcess, real, recordedSession } from "./session.js";
2
2
  import fs from "node:fs";
3
3
  import path from "node:path";
4
4
  import os from "node:os";
@@ -134,46 +134,42 @@ function approvals(dir, home = os.homedir()) {
134
134
  });
135
135
  return lines;
136
136
  }
137
- /** The claude process's command line and folder. */
138
- function claudeLaunch(pid) {
137
+ /** The claude process's command line. */
138
+ function claudeArgs(pid) {
139
139
  const ps = spawnSync("ps", [
140
140
  "-o",
141
141
  "args=",
142
142
  "-p",
143
143
  String(pid)
144
144
  ], { encoding: "utf8" });
145
- const lsof = spawnSync("lsof", [
146
- "-a",
147
- "-p",
148
- String(pid),
149
- "-d",
150
- "cwd",
151
- "-Fn"
152
- ], { encoding: "utf8" });
153
- const cwd = lsof.status === 0 ? lsof.stdout.split("\n").find((l) => l.startsWith("n"))?.slice(1) ?? null : null;
154
- return {
155
- args: ps.status === 0 ? ps.stdout.trim() : null,
156
- cwd
157
- };
145
+ return ps.status === 0 ? ps.stdout.trim() : null;
158
146
  }
159
- /** The workpad version a project pins (its package.json), and the one installed there, when it has them. */
160
- function pinned(dir) {
161
- const pkg = readJson(path.join(dir, "package.json"))?.value;
162
- return {
163
- pin: pkg?.dependencies?.["@bigmistqke/workpad"] ?? pkg?.devDependencies?.["@bigmistqke/workpad"] ?? null,
164
- installed: readJson(path.join(dir, "node_modules", "@bigmistqke", "workpad", "package.json"))?.value?.version ?? null
165
- };
166
- }
167
- async function doctor(ctx) {
168
- const dir = ctx.project.dir;
147
+ /**
148
+ * The checks of what Claude Code reads where it runs (`claude`, see claudeFolder): which folder
149
+ * that is, beside the pages' project (`pages`), when the two differ; the channel in its .mcp.json,
150
+ * and that its command answers, started there as Claude Code starts it; and the server approved and
151
+ * disabled nowhere in its settings. Each fix points at the folder it is for.
152
+ */
153
+ async function channelChecks(pages, claude, home = os.homedir()) {
154
+ const dir = claude.dir;
155
+ const apart = real(pages) !== dir;
169
156
  const lines = [];
157
+ if (apart) lines.push({
158
+ mark: "skip",
159
+ text: `pages: ${pages}; Claude's project: ${dir} (${claude.from ?? "no Claude Code session found"}). The channel and its approval are read from Claude's`
160
+ });
161
+ else if (claude.from) lines.push({
162
+ mark: "ok",
163
+ text: `Claude Code runs in the project's folder (${dir})`
164
+ });
165
+ const install = apart ? `workpad claude install --claude-dir ${dir}` : "workpad claude install";
170
166
  const mcpFile = path.join(dir, ".mcp.json");
171
167
  const mcp = readJson(mcpFile);
172
168
  const entry = mcp?.value?.mcpServers?.[SERVER];
173
169
  if (!mcp) lines.push({
174
170
  mark: "fail",
175
171
  text: `no ${mcpFile}`,
176
- fix: "workpad claude install"
172
+ fix: install
177
173
  });
178
174
  else if (mcp.value === void 0) lines.push({
179
175
  mark: "fail",
@@ -183,12 +179,12 @@ async function doctor(ctx) {
183
179
  else if (!entry?.command) lines.push({
184
180
  mark: "fail",
185
181
  text: `${mcpFile} has no "${SERVER}" server`,
186
- fix: "workpad claude install"
182
+ fix: install
187
183
  });
188
184
  else {
189
185
  const env = {
190
186
  ...process.env,
191
- CLAUDE_PROJECT_DIR: process.env.CLAUDE_PROJECT_DIR ?? dir,
187
+ CLAUDE_PROJECT_DIR: dir,
192
188
  ...entry.env ?? {}
193
189
  };
194
190
  const why = await probe(expand(entry.command, env), (entry.args ?? []).map((a) => expand(a, env)), dir, env);
@@ -196,21 +192,34 @@ async function doctor(ctx) {
196
192
  lines.push(why ? {
197
193
  mark: "fail",
198
194
  text: `the channel's command in ${mcpFile} doesn't answer: ${why}`,
199
- fix: `run it by hand to see why: ${shown}`
195
+ fix: `run it by hand in ${dir} to see why: ${shown}`
200
196
  } : {
201
197
  mark: "ok",
202
198
  text: `${mcpFile} has the channel, and its command answers (${shown})`
203
199
  });
204
200
  }
205
- lines.push(...approvals(dir));
201
+ lines.push(...approvals(dir, home));
202
+ return lines;
203
+ }
204
+ /** The workpad version a project pins (its package.json), and the one installed there, when it has them. */
205
+ function pinned(dir) {
206
+ const pkg = readJson(path.join(dir, "package.json"))?.value;
207
+ return {
208
+ pin: pkg?.dependencies?.["@bigmistqke/workpad"] ?? pkg?.devDependencies?.["@bigmistqke/workpad"] ?? null,
209
+ installed: readJson(path.join(dir, "node_modules", "@bigmistqke", "workpad", "package.json"))?.value?.version ?? null
210
+ };
211
+ }
212
+ async function doctor(ctx) {
213
+ const dir = ctx.project.dir;
214
+ const lines = await channelChecks(dir, claudeFolder(dir));
206
215
  const pid = claudePid();
207
216
  const envSession = process.env.CLAUDE_CODE_SESSION_ID || null;
208
217
  if (!pid) lines.push({
209
218
  mark: "skip",
210
- text: envSession ? "couldn't find the claude process (is ps permitted here?): its launch flag and folder are not checked" : "not run from a Claude Code session: its launch and channel are not checked"
219
+ text: envSession ? "couldn't find the claude process (is ps permitted here?): its launch flag is not checked" : "not run from a Claude Code session: its launch and channel are not checked"
211
220
  });
212
221
  else {
213
- const { args, cwd } = claudeLaunch(pid);
222
+ const args = claudeArgs(pid);
214
223
  if (args == null) lines.push({
215
224
  mark: "skip",
216
225
  text: `couldn't read the command line of claude (pid ${pid})`
@@ -224,19 +233,6 @@ async function doctor(ctx) {
224
233
  text: `the session was started without ${FLAG} server:${SERVER}: Claude Code drops what the channel sends`,
225
234
  fix: `restart it with: claude ${FLAG} server:${SERVER} (a resume or a restore keeps no flag it wasn't given)`
226
235
  });
227
- if (cwd == null) lines.push({
228
- mark: "skip",
229
- text: `couldn't read the folder claude (pid ${pid}) runs in`
230
- });
231
- else if (path.resolve(cwd) === dir) lines.push({
232
- mark: "ok",
233
- text: `the session runs in the project's folder`
234
- });
235
- else lines.push({
236
- mark: "fail",
237
- text: `the session runs in ${cwd}, not the project's folder: it doesn't see ${mcpFile}`,
238
- fix: `start claude in ${dir}`
239
- });
240
236
  }
241
237
  let stuckWhy = null;
242
238
  const server = await ctx.running().catch((err) => (stuckWhy = err.message, null));
@@ -313,4 +309,4 @@ async function doctor(ctx) {
313
309
  console.log(failed ? `\n${failed} to fix.` : "\nThe channel has what it needs.");
314
310
  if (failed) process.exitCode = 1;
315
311
  }
316
- export { approvals, doctor, expand, mainCheckout };
312
+ export { approvals, channelChecks, doctor, expand, mainCheckout };