@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.
- package/bin/workpad.ts +225 -21
- package/dist/bin/workpad.js +181 -15
- package/dist/plugins/badge/README.md +59 -10
- package/dist/plugins/badge/index.js +130 -8
- package/dist/plugins/badge/public/style.css +132 -12
- package/dist/plugins/chat/index.js +7 -1
- package/dist/plugins/claude/README.md +13 -5
- package/dist/plugins/claude/channel.js +25 -2
- package/dist/plugins/claude/doctor.js +43 -47
- package/dist/plugins/claude/index.js +24 -8
- package/dist/plugins/claude/session.js +46 -1
- package/dist/plugins/opencode/channel.js +42 -7
- package/dist/plugins/opencode/index.js +2 -0
- package/dist/src/agents.js +6 -1
- package/dist/src/events.js +6 -5
- package/dist/src/help.js +16 -4
- package/dist/src/hub.js +55 -2
- package/dist/src/listen.js +36 -4
- package/dist/src/listeners.js +14 -4
- package/dist/src/pages/board.js +9 -4
- package/dist/src/pages/index.js +2 -4
- package/dist/src/pages/markdown.js +47 -16
- package/dist/src/pages/render.js +1 -1
- package/dist/src/server.js +69 -6
- package/dist/src/state.js +2 -1
- package/dist/src/status.js +11 -2
- package/dist/src/turns.js +41 -0
- package/package.json +6 -1
- package/plugins/badge/README.md +59 -10
- package/plugins/badge/index.ts +141 -8
- package/plugins/badge/public/style.css +132 -12
- package/plugins/chat/index.ts +9 -1
- package/plugins/claude/README.md +13 -5
- package/plugins/claude/channel.ts +26 -2
- package/plugins/claude/doctor.ts +58 -39
- package/plugins/claude/index.ts +30 -8
- package/plugins/claude/session.ts +32 -0
- package/plugins/opencode/channel.ts +42 -7
- package/plugins/opencode/index.ts +4 -0
- package/skills/workpad/SKILL.md +23 -3
- package/src/agents.ts +7 -0
- package/src/define.ts +28 -1
- package/src/events.ts +23 -2
- package/src/help.ts +16 -4
- package/src/hub.ts +71 -2
- package/src/listen.ts +47 -4
- package/src/listeners.ts +22 -1
- package/src/pages/board.ts +10 -3
- package/src/pages/index.ts +8 -10
- package/src/pages/markdown.ts +55 -8
- package/src/pages/render.ts +1 -1
- package/src/server.ts +84 -6
- package/src/state.ts +3 -0
- package/src/status.ts +15 -1
- package/src/turns.ts +56 -0
|
@@ -1,30 +1,150 @@
|
|
|
1
|
-
/* a
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
20
|
-
--
|
|
130
|
+
.wp-badge[data-border='grey'] {
|
|
131
|
+
--wp-badge-line: var(--wp-badge-grey);
|
|
21
132
|
}
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
26
|
-
|
|
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
|
-
|
|
29
|
-
|
|
146
|
+
@media (prefers-reduced-motion: reduce) {
|
|
147
|
+
.wp-badge[data-live]::before {
|
|
148
|
+
animation: none;
|
|
149
|
+
}
|
|
30
150
|
}
|
package/plugins/chat/index.ts
CHANGED
|
@@ -69,6 +69,14 @@ const chat: Block = {
|
|
|
69
69
|
/** The chat at the bottom of every page (see `end`): for what is about none of its questions. */
|
|
70
70
|
export const PAGE_CHAT = 'page'
|
|
71
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Whether a page's text could name a chat (or a form, whose chat it is) `name`: a `name=` or `id=`
|
|
74
|
+
* of it, or `#name`. Without one it names none, and the page needs no parse to say so: most pages,
|
|
75
|
+
* whose status asks this for every page.
|
|
76
|
+
*/
|
|
77
|
+
const mayName = (body: string, name: string) =>
|
|
78
|
+
new RegExp(`(?:\\bname|\\bid)\\s*=\\s*["']?${name}(?![\\w-])|#${name}(?![\\w-])`).test(body)
|
|
79
|
+
|
|
72
80
|
/** `page: false`: no chat at the bottom of every page. */
|
|
73
81
|
export interface ChatOptions {
|
|
74
82
|
page?: boolean
|
|
@@ -83,7 +91,7 @@ export default function chatPlugin({ page: pageChat = true }: ChatOptions = {}):
|
|
|
83
91
|
end(page) {
|
|
84
92
|
if (!pageChat || page.id.startsWith('-/')) return null
|
|
85
93
|
const own = (page.frontmatter.plugins as Record<string, unknown> | undefined)?.chat
|
|
86
|
-
if (own === false || chatNames(page.body).includes(PAGE_CHAT)) return null
|
|
94
|
+
if (own === false || (mayName(page.body, PAGE_CHAT) && chatNames(page.body).includes(PAGE_CHAT))) return null
|
|
87
95
|
return `:::chat{name=${PAGE_CHAT}}\nQuestions or remarks about this page:\n:::`
|
|
88
96
|
},
|
|
89
97
|
public: builtinPublic('chat'),
|
package/plugins/claude/README.md
CHANGED
|
@@ -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
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
|
|
@@ -23,8 +23,8 @@ import fs from 'node:fs'
|
|
|
23
23
|
import path from 'node:path'
|
|
24
24
|
import readline from 'node:readline'
|
|
25
25
|
import type { CommandContext, WpEvent } from '../../src/define.ts'
|
|
26
|
-
import { ANSWERS_NOTE, answerLine, identity, pong } from '../../src/agents.ts'
|
|
27
|
-
import { channelSince, read } from '../../src/events.ts'
|
|
26
|
+
import { ANSWERS_NOTE, answerLine, identity, pong, unfollowedLine } from '../../src/agents.ts'
|
|
27
|
+
import { channelSince, read, takesUnfollowed } from '../../src/events.ts'
|
|
28
28
|
import { claudeProcess, recordedSession } from './session.ts'
|
|
29
29
|
|
|
30
30
|
const INSTRUCTIONS = [
|
|
@@ -82,10 +82,34 @@ export async function channel(ctx: CommandContext) {
|
|
|
82
82
|
|
|
83
83
|
// Each page followed on its own, so another session's answers are never handed out here.
|
|
84
84
|
const followed = new Set<string>()
|
|
85
|
+
// the pages no one follows, when the session took them on (`workpad listen --unfollowed --channel`)
|
|
86
|
+
let unfollowed: { session: string; stop: AbortController } | null = null
|
|
87
|
+
const takeUnfollowed = (session: string) => {
|
|
88
|
+
const wanted = takesUnfollowed(read(ctx.eventsFile).events, session)
|
|
89
|
+
if (unfollowed && (!wanted || unfollowed.session !== session)) {
|
|
90
|
+
unfollowed.stop.abort()
|
|
91
|
+
unfollowed = null
|
|
92
|
+
}
|
|
93
|
+
if (!wanted || unfollowed) return
|
|
94
|
+
unfollowed = { session, stop: new AbortController() }
|
|
95
|
+
void ctx
|
|
96
|
+
.unfollowed(
|
|
97
|
+
(e, again, from) =>
|
|
98
|
+
notify(unfollowedLine(e, again, from), {
|
|
99
|
+
page: e.page,
|
|
100
|
+
id: e.id,
|
|
101
|
+
type: e.type,
|
|
102
|
+
...(from && { project: from.project }),
|
|
103
|
+
}),
|
|
104
|
+
{ agent: session, signal: unfollowed.stop.signal },
|
|
105
|
+
)
|
|
106
|
+
.catch(err => problem('taking the unfollowed pages failed', String(err)))
|
|
107
|
+
}
|
|
85
108
|
const follow = async () => {
|
|
86
109
|
const session = current()
|
|
87
110
|
hold(session)
|
|
88
111
|
if (!confirmed || !session) return
|
|
112
|
+
takeUnfollowed(session)
|
|
89
113
|
const pages = (await ctx.status()).filter(p => p.subscribers.includes(session)).map(p => p.page)
|
|
90
114
|
for (const page of pages) {
|
|
91
115
|
if (followed.has(page)) continue
|
package/plugins/claude/doctor.ts
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
// `workpad claude doctor`: everything the channel needs to push the reader's answers into this
|
|
2
2
|
// session, checked one by one, with what to do about each that fails. Each of these broke a channel
|
|
3
3
|
// without a word once: Claude Code drops a server's messages when the session wasn't started with the
|
|
4
|
-
// channels flag, a session
|
|
5
|
-
//
|
|
6
|
-
//
|
|
4
|
+
// channels flag, a session reads .mcp.json from the folder it runs in only, and an Esc on "New MCP
|
|
5
|
+
// server found" disables the server in a settings file `/mcp` then doesn't list at all (in a git
|
|
6
|
+
// worktree without its own settings.local.json, in the main checkout's).
|
|
7
|
+
//
|
|
8
|
+
// The folder Claude Code runs in is not always the pages' project: a wrapper can hand a session in
|
|
9
|
+
// one folder (a git worktree) the pages of another (a job's folder). .mcp.json and the approval are
|
|
10
|
+
// read from Claude's folder (claudeFolder), and both are named when they differ.
|
|
7
11
|
//
|
|
8
12
|
// It reads, and changes nothing: the files, the claude process it runs under (its command line and
|
|
9
13
|
// folder, with ps and lsof), and what the project's server says (never started for it). The
|
|
10
|
-
// channel's command is started once, asked to initialize, and stopped.
|
|
14
|
+
// channel's command is started once, in Claude's folder, asked to initialize, and stopped.
|
|
11
15
|
import fs from 'node:fs'
|
|
12
16
|
import os from 'node:os'
|
|
13
17
|
import path from 'node:path'
|
|
14
18
|
import { spawn, spawnSync } from 'node:child_process'
|
|
15
19
|
import type { CommandContext } from '../../src/define.ts'
|
|
16
|
-
import { claudePid, claudeProcess, recordedSession } from './session.ts'
|
|
20
|
+
import { claudeFolder, claudePid, claudeProcess, real, recordedSession } from './session.ts'
|
|
17
21
|
|
|
18
22
|
const SERVER = 'workpad'
|
|
19
23
|
const FLAG = '--dangerously-load-development-channels'
|
|
@@ -136,62 +140,85 @@ export function approvals(dir: string, home = os.homedir()): Line[] {
|
|
|
136
140
|
return lines
|
|
137
141
|
}
|
|
138
142
|
|
|
139
|
-
/** The claude process's command line
|
|
140
|
-
function
|
|
143
|
+
/** The claude process's command line. */
|
|
144
|
+
function claudeArgs(pid: number): string | null {
|
|
141
145
|
const ps = spawnSync('ps', ['-o', 'args=', '-p', String(pid)], { encoding: 'utf8' })
|
|
142
|
-
|
|
143
|
-
const cwd = lsof.status === 0 ? (lsof.stdout.split('\n').find(l => l.startsWith('n'))?.slice(1) ?? null) : null
|
|
144
|
-
return { args: ps.status === 0 ? ps.stdout.trim() : null, cwd }
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/** The workpad version a project pins (its package.json), and the one installed there, when it has them. */
|
|
148
|
-
function pinned(dir: string): { pin: string | null; installed: string | null } {
|
|
149
|
-
const pkg = readJson(path.join(dir, 'package.json'))?.value
|
|
150
|
-
const pin = pkg?.dependencies?.['@bigmistqke/workpad'] ?? pkg?.devDependencies?.['@bigmistqke/workpad'] ?? null
|
|
151
|
-
const installed = readJson(path.join(dir, 'node_modules', '@bigmistqke', 'workpad', 'package.json'))?.value?.version ?? null
|
|
152
|
-
return { pin, installed }
|
|
146
|
+
return ps.status === 0 ? ps.stdout.trim() : null
|
|
153
147
|
}
|
|
154
148
|
|
|
155
|
-
|
|
156
|
-
|
|
149
|
+
/**
|
|
150
|
+
* The checks of what Claude Code reads where it runs (`claude`, see claudeFolder): which folder
|
|
151
|
+
* that is, beside the pages' project (`pages`), when the two differ; the channel in its .mcp.json,
|
|
152
|
+
* and that its command answers, started there as Claude Code starts it; and the server approved and
|
|
153
|
+
* disabled nowhere in its settings. Each fix points at the folder it is for.
|
|
154
|
+
*/
|
|
155
|
+
export async function channelChecks(
|
|
156
|
+
pages: string,
|
|
157
|
+
claude: { dir: string; from: string | null },
|
|
158
|
+
home = os.homedir(),
|
|
159
|
+
): Promise<Line[]> {
|
|
160
|
+
const dir = claude.dir
|
|
161
|
+
const apart = real(pages) !== dir
|
|
157
162
|
const lines: Line[] = []
|
|
163
|
+
if (apart)
|
|
164
|
+
lines.push({
|
|
165
|
+
mark: 'skip',
|
|
166
|
+
text: `pages: ${pages}; Claude's project: ${dir} (${claude.from ?? 'no Claude Code session found'}). The channel and its approval are read from Claude's`,
|
|
167
|
+
})
|
|
168
|
+
else if (claude.from)
|
|
169
|
+
lines.push({ mark: 'ok', text: `Claude Code runs in the project's folder (${dir})` })
|
|
170
|
+
const install = apart ? `workpad claude install --claude-dir ${dir}` : 'workpad claude install'
|
|
158
171
|
|
|
159
|
-
//
|
|
172
|
+
// the channel in .mcp.json, and its command starts
|
|
160
173
|
const mcpFile = path.join(dir, '.mcp.json')
|
|
161
174
|
const mcp = readJson(mcpFile)
|
|
162
175
|
const entry = mcp?.value?.mcpServers?.[SERVER]
|
|
163
|
-
if (!mcp) lines.push({ mark: 'fail', text: `no ${mcpFile}`, fix:
|
|
176
|
+
if (!mcp) lines.push({ mark: 'fail', text: `no ${mcpFile}`, fix: install })
|
|
164
177
|
else if (mcp.value === undefined) lines.push({ mark: 'fail', text: `${mcpFile}: ${mcp.why}`, fix: 'fix the file' })
|
|
165
|
-
else if (!entry?.command)
|
|
166
|
-
lines.push({ mark: 'fail', text: `${mcpFile} has no "${SERVER}" server`, fix: 'workpad claude install' })
|
|
178
|
+
else if (!entry?.command) lines.push({ mark: 'fail', text: `${mcpFile} has no "${SERVER}" server`, fix: install })
|
|
167
179
|
else {
|
|
168
|
-
const env = { ...process.env, CLAUDE_PROJECT_DIR:
|
|
180
|
+
const env = { ...process.env, CLAUDE_PROJECT_DIR: dir, ...(entry.env ?? {}) }
|
|
169
181
|
const command = expand(entry.command, env)
|
|
170
182
|
const args = ((entry.args ?? []) as string[]).map(a => expand(a, env))
|
|
171
183
|
const why = await probe(command, args, dir, env)
|
|
172
184
|
const shown = [entry.command, ...(entry.args ?? [])].join(' ')
|
|
173
185
|
lines.push(
|
|
174
186
|
why
|
|
175
|
-
? { mark: 'fail', text: `the channel's command in ${mcpFile} doesn't answer: ${why}`, fix: `run it by hand to see why: ${shown}` }
|
|
187
|
+
? { mark: 'fail', text: `the channel's command in ${mcpFile} doesn't answer: ${why}`, fix: `run it by hand in ${dir} to see why: ${shown}` }
|
|
176
188
|
: { mark: 'ok', text: `${mcpFile} has the channel, and its command answers (${shown})` },
|
|
177
189
|
)
|
|
178
190
|
}
|
|
179
191
|
|
|
180
|
-
//
|
|
181
|
-
lines.push(...approvals(dir))
|
|
192
|
+
// enabled, and disabled in no settings scope
|
|
193
|
+
lines.push(...approvals(dir, home))
|
|
194
|
+
return lines
|
|
195
|
+
}
|
|
182
196
|
|
|
183
|
-
|
|
197
|
+
/** The workpad version a project pins (its package.json), and the one installed there, when it has them. */
|
|
198
|
+
function pinned(dir: string): { pin: string | null; installed: string | null } {
|
|
199
|
+
const pkg = readJson(path.join(dir, 'package.json'))?.value
|
|
200
|
+
const pin = pkg?.dependencies?.['@bigmistqke/workpad'] ?? pkg?.devDependencies?.['@bigmistqke/workpad'] ?? null
|
|
201
|
+
const installed = readJson(path.join(dir, 'node_modules', '@bigmistqke', 'workpad', 'package.json'))?.value?.version ?? null
|
|
202
|
+
return { pin, installed }
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export async function doctor(ctx: CommandContext) {
|
|
206
|
+
const dir = ctx.project.dir
|
|
207
|
+
// 1. where Claude Code runs; the channel in its .mcp.json; 2. approved, and disabled in no settings scope
|
|
208
|
+
const lines = await channelChecks(dir, claudeFolder(dir))
|
|
209
|
+
|
|
210
|
+
// 3. the session: started with the flag
|
|
184
211
|
const pid = claudePid()
|
|
185
212
|
const envSession = process.env.CLAUDE_CODE_SESSION_ID || null
|
|
186
213
|
if (!pid)
|
|
187
214
|
lines.push({
|
|
188
215
|
mark: 'skip',
|
|
189
216
|
text: envSession
|
|
190
|
-
? "couldn't find the claude process (is ps permitted here?): its launch flag
|
|
217
|
+
? "couldn't find the claude process (is ps permitted here?): its launch flag is not checked"
|
|
191
218
|
: 'not run from a Claude Code session: its launch and channel are not checked',
|
|
192
219
|
})
|
|
193
220
|
else {
|
|
194
|
-
const
|
|
221
|
+
const args = claudeArgs(pid)
|
|
195
222
|
if (args == null) lines.push({ mark: 'skip', text: `couldn't read the command line of claude (pid ${pid})` })
|
|
196
223
|
else if (new RegExp(`${FLAG}(=|\\s+)\\S*server:${SERVER}\\b`).test(args))
|
|
197
224
|
lines.push({ mark: 'ok', text: `the session was started with ${FLAG} server:${SERVER}` })
|
|
@@ -201,14 +228,6 @@ export async function doctor(ctx: CommandContext) {
|
|
|
201
228
|
text: `the session was started without ${FLAG} server:${SERVER}: Claude Code drops what the channel sends`,
|
|
202
229
|
fix: `restart it with: claude ${FLAG} server:${SERVER} (a resume or a restore keeps no flag it wasn't given)`,
|
|
203
230
|
})
|
|
204
|
-
if (cwd == null) lines.push({ mark: 'skip', text: `couldn't read the folder claude (pid ${pid}) runs in` })
|
|
205
|
-
else if (path.resolve(cwd) === dir) lines.push({ mark: 'ok', text: `the session runs in the project's folder` })
|
|
206
|
-
else
|
|
207
|
-
lines.push({
|
|
208
|
-
mark: 'fail',
|
|
209
|
-
text: `the session runs in ${cwd}, not the project's folder: it doesn't see ${mcpFile}`,
|
|
210
|
-
fix: `start claude in ${dir}`,
|
|
211
|
-
})
|
|
212
231
|
}
|
|
213
232
|
|
|
214
233
|
// 4. the server, its version, and a channel for this session; 5. its ping confirmed
|
package/plugins/claude/index.ts
CHANGED
|
@@ -28,6 +28,7 @@ import { read, receivedBy } from '../../src/events.ts'
|
|
|
28
28
|
import { channel } from './channel.ts'
|
|
29
29
|
import { doctor } from './doctor.ts'
|
|
30
30
|
import { recordSession } from './session.ts'
|
|
31
|
+
import { recordTurn } from '../../src/turns.ts'
|
|
31
32
|
|
|
32
33
|
type Mode = 'session' | 'stop'
|
|
33
34
|
|
|
@@ -71,27 +72,44 @@ export default function claude(): Plugin {
|
|
|
71
72
|
},
|
|
72
73
|
doctor: {
|
|
73
74
|
description:
|
|
74
|
-
"check what the channel needs, a line each with what to do: the .mcp.json entry and its command, the server approved and disabled in no settings file, the session started with the channels flag
|
|
75
|
+
"check what the channel needs, a line each with what to do: the .mcp.json entry and its command, the server approved and disabled in no settings file (both where Claude Code runs, named beside the pages' project when it is another folder), the session started with the channels flag, the server up at the project's version, a channel for this session, its ping confirmed",
|
|
75
76
|
run: doctor,
|
|
76
77
|
},
|
|
77
78
|
install: {
|
|
78
|
-
description:
|
|
79
|
+
description:
|
|
80
|
+
"add the channel to the .mcp.json and its hooks to the .claude/settings.json of the folder Claude Code runs in: this project's, or --claude-dir",
|
|
81
|
+
options: { 'claude-dir': CLAUDE_DIR },
|
|
79
82
|
run: ctx => {
|
|
80
|
-
|
|
81
|
-
|
|
83
|
+
const dir = claudeDir(ctx)
|
|
84
|
+
installChannel(dir)
|
|
85
|
+
installHooks(dir)
|
|
82
86
|
},
|
|
83
87
|
},
|
|
84
88
|
uninstall: {
|
|
85
|
-
description:
|
|
89
|
+
description:
|
|
90
|
+
"take the channel and its hooks out of the settings again (this project's, or --claude-dir's); other hooks, servers and settings stay",
|
|
91
|
+
options: { 'claude-dir': CLAUDE_DIR },
|
|
86
92
|
run: ctx => {
|
|
87
|
-
|
|
88
|
-
|
|
93
|
+
const dir = claudeDir(ctx)
|
|
94
|
+
uninstallChannel(dir)
|
|
95
|
+
uninstallHooks(dir)
|
|
89
96
|
},
|
|
90
97
|
},
|
|
91
98
|
},
|
|
92
99
|
}
|
|
93
100
|
}
|
|
94
101
|
|
|
102
|
+
/**
|
|
103
|
+
* The folder Claude Code runs in, when it isn't the pages' project: a session a wrapper hands
|
|
104
|
+
* another folder's pages reads .mcp.json and its settings from its own folder.
|
|
105
|
+
*/
|
|
106
|
+
const CLAUDE_DIR = {
|
|
107
|
+
type: 'string?',
|
|
108
|
+
value: 'folder',
|
|
109
|
+
description: "the folder Claude Code runs in, when not this project's (`workpad claude doctor` names it)",
|
|
110
|
+
} as const
|
|
111
|
+
const claudeDir = (ctx: CommandContext) => path.resolve((ctx.options['claude-dir'] as string | undefined) ?? ctx.project.dir)
|
|
112
|
+
|
|
95
113
|
/** The JSON Claude Code passes a hook on its standard input, or nothing. */
|
|
96
114
|
function hookInput(): { session_id?: string; stop_hook_active?: boolean; transcript_path?: string } {
|
|
97
115
|
if (process.stdin.isTTY) return {}
|
|
@@ -106,12 +124,16 @@ async function hook(ctx: CommandContext, mode: Mode) {
|
|
|
106
124
|
const input = hookInput()
|
|
107
125
|
// the channel's environment can hold an id the conversation left (a resume): tell it the current one
|
|
108
126
|
if (input.session_id) recordSession(ctx.dataDir, input.session_id)
|
|
109
|
-
|
|
127
|
+
// `workpad agent ping --wait` counts from a turn's end (turns.ts): from here on they are recorded
|
|
128
|
+
if (mode === 'session')
|
|
129
|
+
return recordTurn(ctx.project.wp, identity(input.session_id ?? process.env.CLAUDE_CODE_SESSION_ID ?? null), false)
|
|
110
130
|
// A turn ends with something on the session's pages left: its turn goes on once, with that as the
|
|
111
131
|
// reason; Claude Code marks a turn a hook continued (stop_hook_active), and that one ends, with
|
|
112
132
|
// what is open shown to the reader instead.
|
|
113
133
|
const agent = identity(input.session_id ?? process.env.CLAUDE_CODE_SESSION_ID ?? null)
|
|
114
134
|
const left = await stopReminder(ctx, agent, inFlight(ctx, agent, input.transcript_path))
|
|
135
|
+
// the turn ends, unless the reminder below sends it on: then its next end is the one (turns.ts)
|
|
136
|
+
if (!left || input.stop_hook_active) recordTurn(ctx.project.wp, agent, true)
|
|
115
137
|
if (!left) return
|
|
116
138
|
if (input.stop_hook_active) return void console.log(JSON.stringify({ systemMessage: left.shown }))
|
|
117
139
|
// As context for the turn, not a block: the turn goes on all the same (with the same guard,
|
|
@@ -37,6 +37,38 @@ export function claudeProcess(): string {
|
|
|
37
37
|
return Number.isNaN(at) ? String(pid) : `${pid}-${at / 1000}`
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
/** The folder a process runs in (with lsof), or null when it can't be read. */
|
|
41
|
+
function processCwd(pid: number): string | null {
|
|
42
|
+
const lsof = spawnSync('lsof', ['-a', '-p', String(pid), '-d', 'cwd', '-Fn'], { encoding: 'utf8' })
|
|
43
|
+
if (lsof.status !== 0) return null
|
|
44
|
+
return lsof.stdout.split('\n').find(l => l.startsWith('n'))?.slice(1) || null
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** A folder as the file system names it, symbolic links resolved (as given when it isn't there). */
|
|
48
|
+
export function real(dir: string): string {
|
|
49
|
+
try {
|
|
50
|
+
return fs.realpathSync(dir)
|
|
51
|
+
} catch {
|
|
52
|
+
return path.resolve(dir)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The folder Claude Code runs in, where it reads .mcp.json and its project settings: not always the
|
|
58
|
+
* pages' project (a wrapper can hand a session another folder's pages). CLAUDE_PROJECT_DIR when set
|
|
59
|
+
* (Claude Code gives it to hooks and MCP servers, not to an agent's commands); else the folder of
|
|
60
|
+
* the claude process this one runs under (found with ps, else by the CLAUDE_PID Claude Code gives an
|
|
61
|
+
* agent's commands); else, outside a session, `fallback`. With how it was found, for the doctor
|
|
62
|
+
* (null: no session was found, and it is `fallback`).
|
|
63
|
+
*/
|
|
64
|
+
export function claudeFolder(fallback: string, env: NodeJS.ProcessEnv = process.env): { dir: string; from: string | null } {
|
|
65
|
+
if (env.CLAUDE_PROJECT_DIR) return { dir: real(env.CLAUDE_PROJECT_DIR), from: 'CLAUDE_PROJECT_DIR' }
|
|
66
|
+
const pid = claudePid() ?? (Number(env.CLAUDE_PID) || null)
|
|
67
|
+
const cwd = pid ? processCwd(pid) : null
|
|
68
|
+
if (cwd) return { dir: real(cwd), from: `the folder claude (pid ${pid}) runs in` }
|
|
69
|
+
return { dir: real(fallback), from: null }
|
|
70
|
+
}
|
|
71
|
+
|
|
40
72
|
const sessionsDir = (dataDir: string) => path.join(dataDir, 'sessions')
|
|
41
73
|
|
|
42
74
|
/** The conversation a hook says this claude process is on; records of processes that ended go. */
|
|
@@ -23,8 +23,10 @@ import fs from 'node:fs'
|
|
|
23
23
|
import path from 'node:path'
|
|
24
24
|
import readline from 'node:readline'
|
|
25
25
|
import type { CommandContext, WpEvent } from '../../src/define.ts'
|
|
26
|
-
import { channelSince, read, receive, receivedBy } from '../../src/events.ts'
|
|
27
|
-
import { answerLine, identity, pong } from '../../src/agents.ts'
|
|
26
|
+
import { channelSince, read, receive, receivedBy, takesUnfollowed } from '../../src/events.ts'
|
|
27
|
+
import { answerLine, identity, pong, unfollowedLine } from '../../src/agents.ts'
|
|
28
|
+
import { project as projectAt } from '../../src/config.ts'
|
|
29
|
+
import { recordTurn } from '../../src/turns.ts'
|
|
28
30
|
|
|
29
31
|
export async function channel(ctx: CommandContext) {
|
|
30
32
|
const problem = (what: string, data?: unknown) => {
|
|
@@ -40,6 +42,8 @@ export async function channel(ctx: CommandContext) {
|
|
|
40
42
|
const sessions = new Map<string, boolean>()
|
|
41
43
|
const hold = (session: string) => {
|
|
42
44
|
sessions.set(session, false)
|
|
45
|
+
// its turn ends are recorded from now on (`hook stop`), for `workpad agent ping --wait` (turns.ts)
|
|
46
|
+
recordTurn(ctx.project.wp, identity(session), false)
|
|
43
47
|
ctx.channel(identity(session)!, {
|
|
44
48
|
onPing: code => say({ session, pong: true, text: pong(code) }),
|
|
45
49
|
onConfirmed: () => {
|
|
@@ -50,11 +54,37 @@ export async function channel(ctx: CommandContext) {
|
|
|
50
54
|
}
|
|
51
55
|
// each page followed on its own, so another session's answers are never handed out here
|
|
52
56
|
const followed = new Set<string>()
|
|
57
|
+
// the sessions that took the pages no one follows on (`workpad listen --unfollowed --channel`),
|
|
58
|
+
// and the log each answer they were given from another project is in, to mark it received there
|
|
59
|
+
const unfollowed = new Map<string, AbortController>()
|
|
60
|
+
const logOf = new Map<string, string>()
|
|
61
|
+
const takeUnfollowed = (agent: string, session: string) => {
|
|
62
|
+
const wanted = takesUnfollowed(read(ctx.eventsFile).events, agent)
|
|
63
|
+
if (!wanted) {
|
|
64
|
+
unfollowed.get(session)?.abort()
|
|
65
|
+
unfollowed.delete(session)
|
|
66
|
+
return
|
|
67
|
+
}
|
|
68
|
+
if (unfollowed.has(session)) return
|
|
69
|
+
const stop = new AbortController()
|
|
70
|
+
unfollowed.set(session, stop)
|
|
71
|
+
void ctx
|
|
72
|
+
.unfollowed(
|
|
73
|
+
(e, again, from) => {
|
|
74
|
+
const log = from ? projectAt(from.project)?.eventsFile : null
|
|
75
|
+
if (log) logOf.set(e.id, log)
|
|
76
|
+
say({ session, id: e.id, page: e.page, type: e.type, text: unfollowedLine(e, again, from) })
|
|
77
|
+
},
|
|
78
|
+
{ agent, mark: false, signal: stop.signal },
|
|
79
|
+
)
|
|
80
|
+
.catch(err => problem('taking the unfollowed pages failed', String(err)))
|
|
81
|
+
}
|
|
53
82
|
const follow = async () => {
|
|
54
83
|
// who each confirmed session is on the boards, and the session to bring its pages' answers to
|
|
55
84
|
const who = new Map<string, string>()
|
|
56
85
|
for (const [session, confirmed] of sessions) if (confirmed) who.set(identity(session)!, session)
|
|
57
86
|
if (!who.size) return
|
|
87
|
+
for (const [agent, session] of who) takeUnfollowed(agent, session)
|
|
58
88
|
for (const p of await ctx.status()) {
|
|
59
89
|
const agent = p.subscribers.find(s => who.has(s))
|
|
60
90
|
if (!agent || followed.has(p.page)) continue
|
|
@@ -81,11 +111,16 @@ export async function channel(ctx: CommandContext) {
|
|
|
81
111
|
/** The plugin brought these answers into their session. */
|
|
82
112
|
const received = (ids: string[], session: string) => {
|
|
83
113
|
const agent = identity(session)
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
114
|
+
// by log: this project's, or another's an unfollowed page is in
|
|
115
|
+
for (const log of new Set(ids.map(id => logOf.get(id) ?? ctx.eventsFile))) {
|
|
116
|
+
const { events } = read(log)
|
|
117
|
+
const had = receivedBy(events, agent)
|
|
118
|
+
for (const id of ids) {
|
|
119
|
+
if ((logOf.get(id) ?? ctx.eventsFile) !== log) continue
|
|
120
|
+
const e = events.find(x => x.id === id)
|
|
121
|
+
if (e && !had.has(id)) receive(log, e, agent)
|
|
122
|
+
logOf.delete(id)
|
|
123
|
+
}
|
|
89
124
|
}
|
|
90
125
|
}
|
|
91
126
|
|
|
@@ -19,6 +19,7 @@ import fs from 'node:fs'
|
|
|
19
19
|
import path from 'node:path'
|
|
20
20
|
import type { Plugin } from '../../src/define.ts'
|
|
21
21
|
import { identity, stopReminder, workpadCommand } from '../../src/agents.ts'
|
|
22
|
+
import { recordTurn } from '../../src/turns.ts'
|
|
22
23
|
import { channel } from './channel.ts'
|
|
23
24
|
import { shimSource } from './shim.ts'
|
|
24
25
|
|
|
@@ -37,6 +38,9 @@ export default function opencode(): Plugin {
|
|
|
37
38
|
if (ctx.positionals[0] !== 'stop') throw new Error('usage: workpad opencode hook stop')
|
|
38
39
|
// a hook that fails must not get in the way of the session it runs in: say why, and exit cleanly
|
|
39
40
|
try {
|
|
41
|
+
// the turn ended, for `workpad agent ping --wait` (turns.ts); one the plugin then sends on
|
|
42
|
+
// with what is left counts as ended a little early, since this can't tell
|
|
43
|
+
recordTurn(ctx.project.wp, identity(session()), true)
|
|
40
44
|
const left = await stopReminder(ctx, identity(session()))
|
|
41
45
|
if (left) console.log(JSON.stringify(left))
|
|
42
46
|
} catch (err) {
|