@unbrained/pm-web 2026.5.29 → 2026.6.2-1
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/CHANGELOG.md +37 -0
- package/README.md +65 -1
- package/dist/board.js +41 -0
- package/dist/board.js.map +1 -0
- package/dist/db.js +40 -6
- package/dist/db.js.map +1 -1
- package/dist/index.js +351 -6
- package/dist/index.js.map +1 -1
- package/dist/routes/pm.js +40 -0
- package/dist/routes/pm.js.map +1 -1
- package/dist/server.js +25 -32
- package/dist/server.js.map +1 -1
- package/manifest.json +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2026.6.2-1 - 2026-06-02
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Do NOT add the 'services' extension capability to pm-web ([pm-web-vyfp](https://github.com/unbraind/pm-web/blob/main/.agents/pm/decisions/pm-web-vyfp.toon))
|
|
8
|
+
- Deepen pm-web extension command surface \(status/stop/doctor\) + services-capability evaluation ([pm-web-7pxa](https://github.com/unbraind/pm-web/blob/main/.agents/pm/features/pm-web-7pxa.toon))
|
|
9
|
+
- Add /healthz version + unit tests + README docs ([pm-web-edyj](https://github.com/unbraind/pm-web/blob/main/.agents/pm/tasks/pm-web-edyj.toon))
|
|
10
|
+
- Introduce CommandError \(numeric exitCode\) for new handlers ([pm-web-9ycn](https://github.com/unbraind/pm-web/blob/main/.agents/pm/tasks/pm-web-9ycn.toon))
|
|
11
|
+
|
|
12
|
+
### Other
|
|
13
|
+
|
|
14
|
+
- Implement 'pm web doctor' command ([pm-web-vyqb](https://github.com/unbraind/pm-web/blob/main/.agents/pm/tasks/pm-web-vyqb.toon))
|
|
15
|
+
- Implement 'pm web stop' command + pidfile-on-detach ([pm-web-odwq](https://github.com/unbraind/pm-web/blob/main/.agents/pm/tasks/pm-web-odwq.toon))
|
|
16
|
+
- Implement 'pm web status' command ([pm-web-8eqs](https://github.com/unbraind/pm-web/blob/main/.agents/pm/tasks/pm-web-8eqs.toon))
|
|
17
|
+
|
|
18
|
+
## 2026.05.30 - 2026-05-30
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- Daily Release fails at changelog:check — version-format mismatch \(padded tag vs npm version\) ([pm-web-ysd5](https://github.com/unbraind/pm-web/blob/main/.agents/pm/issues/pm-web-ysd5.toon))
|
|
23
|
+
|
|
24
|
+
### Other
|
|
25
|
+
|
|
26
|
+
- Keep pm-web published scoped as @unbrained/pm-web \(not unscoped pm-web\) ([pm-web-1qq4](https://github.com/unbraind/pm-web/blob/main/.agents/pm/decisions/pm-web-1qq4.toon))
|
|
27
|
+
- Production-readiness audit 2026-05-28 ([pm-web-8u17](https://github.com/unbraind/pm-web/blob/main/.agents/pm/tasks/pm-web-8u17.toon))
|
|
28
|
+
|
|
29
|
+
## 2026.05.29-1 - 2026-05-29
|
|
30
|
+
|
|
31
|
+
### Added
|
|
32
|
+
|
|
33
|
+
- Hands-on functional test pass 2026-05-29 \(real data + Postgres\) ([pm-web-ul0n](https://github.com/unbraind/pm-web/blob/main/.agents/pm/features/pm-web-ul0n.toon))
|
|
34
|
+
|
|
35
|
+
### Fixed
|
|
36
|
+
|
|
37
|
+
- Catalog npm link points to unpublished unscoped pm-web \(404\) ([pm-web-2wrz](https://github.com/unbraind/pm-web/blob/main/.agents/pm/issues/pm-web-2wrz.toon))
|
|
38
|
+
- Server hangs/cryptic error when DATABASE\_URL is unset ([pm-web-onv4](https://github.com/unbraind/pm-web/blob/main/.agents/pm/issues/pm-web-onv4.toon))
|
|
39
|
+
|
|
3
40
|
## 2026.05.29 - 2026-05-29
|
|
4
41
|
|
|
5
42
|
### Fixed
|
package/README.md
CHANGED
|
@@ -52,8 +52,55 @@ The package repository is at **github.com/unbraind/pm-web**.
|
|
|
52
52
|
|
|
53
53
|
| Command | Description |
|
|
54
54
|
|---|---|
|
|
55
|
-
| `pm web` | Start the pm-web server |
|
|
55
|
+
| `pm web` | Start the pm-web server (foreground) |
|
|
56
56
|
| `pm web --port 8080` | Start on a custom port |
|
|
57
|
+
| `pm web --detach` | Start the server in the background (tracked via a pidfile) |
|
|
58
|
+
| `pm web status` | Report whether a server is reachable (probes `/healthz`); `--json` supported |
|
|
59
|
+
| `pm web stop` | Stop a server previously started with `--detach`; `--json` supported |
|
|
60
|
+
| `pm web doctor` | Preflight diagnostics (Node, runtime deps, port, pm, workspace); `--json` supported |
|
|
61
|
+
|
|
62
|
+
#### `pm web status`
|
|
63
|
+
|
|
64
|
+
Probes `http://localhost:<port>/healthz` and reports `up`/`down`, the responding
|
|
65
|
+
port, and the server version. Never errors when the server is down — it returns a
|
|
66
|
+
structured `down` result. The port is resolved from `--port`, then `PORT`, then
|
|
67
|
+
the default `4000`.
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pm web status # human-readable
|
|
71
|
+
pm web status --port 8080 --json
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
#### `pm web stop`
|
|
75
|
+
|
|
76
|
+
Stops a server started with `pm web --detach`. The detached PID is recorded in a
|
|
77
|
+
pidfile (under `PM_WEB_STATE_DIR` if set, otherwise the OS temp dir, keyed by
|
|
78
|
+
port). `pm web stop` reads the pidfile, sends `SIGTERM`, and clears the pidfile.
|
|
79
|
+
If nothing is running it reports `not_running` gracefully and cleans up any stale
|
|
80
|
+
pidfile.
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
pm web stop # stops the server on the default port
|
|
84
|
+
pm web stop --port 8080 --json
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
#### `pm web doctor`
|
|
88
|
+
|
|
89
|
+
Runs preflight checks before starting the server: Node version (>= 20), whether
|
|
90
|
+
runtime dependencies (express, etc.) are installed, whether the target port is
|
|
91
|
+
free, whether `pm` is on `PATH`, and whether the workspace is initialized.
|
|
92
|
+
Returns an overall `ok` boolean. The `port_available` check is informational (a
|
|
93
|
+
busy port may just be a server you already started) and does not gate `ok`.
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
pm web doctor
|
|
97
|
+
pm web doctor --json
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
> Note: the `services` extension capability is intentionally **not** declared.
|
|
101
|
+
> The pm SDK's `registerService` only overrides one of eight fixed core services
|
|
102
|
+
> (e.g. `output_format`), which would alter core output for unrelated commands;
|
|
103
|
+
> the server lifecycle is exposed safely through the commands above instead.
|
|
57
104
|
|
|
58
105
|
### Environment Variables
|
|
59
106
|
|
|
@@ -64,6 +111,7 @@ The package repository is at **github.com/unbraind/pm-web**.
|
|
|
64
111
|
| `PM_WEB_SECRET_KEY` | Recommended | At-rest encryption key for saved GitHub PATs. Falls back to `JWT_SECRET`; use at least 32 characters |
|
|
65
112
|
| `PM_WEB_BOOTSTRAP_ADMIN_EMAIL` | Recommended | Email of the user account to auto-promote to admin on schema init. Leave unset to skip auto-promotion (manage admins via the admin UI). |
|
|
66
113
|
| `PORT` | No | Server port (default: 4000) |
|
|
114
|
+
| `PM_WEB_STATE_DIR` | No | Directory for the `--detach` pidfile used by `pm web stop` (default: OS temp dir) |
|
|
67
115
|
| `NODE_ENV` | No | `production` enables caching |
|
|
68
116
|
| `OLLAMA_BASE_URL` / `OLLAMA_HOST` | No | Local Ollama endpoint for semantic pm search |
|
|
69
117
|
| `PM_OLLAMA_MODEL` | No | Embedding model for new projects, default `qwen3-embedding:0.6b` |
|
|
@@ -105,3 +153,19 @@ MIT
|
|
|
105
153
|
## Release Automation
|
|
106
154
|
|
|
107
155
|
This package is release-ready for GitHub, npm, and Bun-compatible installs. CI runs type checking, build, production dependency audit, package packing, Bun install verification, and pm-changelog validation. The daily release workflow publishes only when commits exist after the latest release tag and uses pm-changelog to generate CHANGELOG.md and GitHub release notes.
|
|
156
|
+
|
|
157
|
+
## New data endpoints (kanban board & search)
|
|
158
|
+
|
|
159
|
+
The pm data API now exposes board and search views, both driven by the
|
|
160
|
+
workspace's live `pm contracts` schema (so they reflect the installed pm CLI +
|
|
161
|
+
extensions):
|
|
162
|
+
|
|
163
|
+
- `GET /api/projects/:projectId/pm/board` — items grouped into kanban columns by
|
|
164
|
+
the workspace's runtime statuses (unlisted statuses fall into `(other)`).
|
|
165
|
+
- `GET /api/projects/:projectId/pm/search?q=<text>` — case-insensitive full-text
|
|
166
|
+
search over id, title, tags and body.
|
|
167
|
+
- `GET /api/projects/:projectId/pm/schema` — runtime types/statuses (existing).
|
|
168
|
+
- `GET /api/projects/:projectId/pm/graph` — dependency graph (existing).
|
|
169
|
+
|
|
170
|
+
The pure grouping/search helpers live in `src/board.ts` and are unit-tested
|
|
171
|
+
independently of the database.
|
package/dist/board.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Pure, dependency-free helpers for the kanban board and search endpoints.
|
|
2
|
+
// Kept in their own module (no db/neo4j imports) so they are unit-testable
|
|
3
|
+
// without booting the server or a database.
|
|
4
|
+
// Group items into board columns keyed by the workspace's actual statuses
|
|
5
|
+
// (from `pm contracts`), so the kanban board reflects whatever statuses the
|
|
6
|
+
// installed pm CLI + extensions define. Items with an unlisted status fall into
|
|
7
|
+
// a trailing "(other)" column so nothing is silently dropped.
|
|
8
|
+
export function boardColumns(items, statuses) {
|
|
9
|
+
const known = statuses.length > 0 ? statuses : ["open", "in_progress", "blocked", "closed"];
|
|
10
|
+
const columns = new Map();
|
|
11
|
+
for (const s of known)
|
|
12
|
+
columns.set(s, []);
|
|
13
|
+
const OTHER = "(other)";
|
|
14
|
+
for (const item of items) {
|
|
15
|
+
const s = item.status ?? "open";
|
|
16
|
+
if (columns.has(s))
|
|
17
|
+
columns.get(s).push(item);
|
|
18
|
+
else {
|
|
19
|
+
if (!columns.has(OTHER))
|
|
20
|
+
columns.set(OTHER, []);
|
|
21
|
+
columns.get(OTHER).push(item);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return [...columns.entries()].map(([status, list]) => ({ status, items: list }));
|
|
25
|
+
}
|
|
26
|
+
// Case-insensitive full-text filter over id, title, tags and body.
|
|
27
|
+
export function filterItemsByQuery(items, query) {
|
|
28
|
+
const q = query.trim().toLowerCase();
|
|
29
|
+
if (!q)
|
|
30
|
+
return items;
|
|
31
|
+
return items.filter((item) => {
|
|
32
|
+
const hay = [
|
|
33
|
+
item.id,
|
|
34
|
+
item.title ?? "",
|
|
35
|
+
(item.tags ?? []).join(" "),
|
|
36
|
+
item.body ?? "",
|
|
37
|
+
].join(" ").toLowerCase();
|
|
38
|
+
return hay.includes(q);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=board.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"board.js","sourceRoot":"","sources":["../src/board.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,2EAA2E;AAC3E,4CAA4C;AAU5C,0EAA0E;AAC1E,4EAA4E;AAC5E,gFAAgF;AAChF,8DAA8D;AAC9D,MAAM,UAAU,YAAY,CAC1B,KAAU,EACV,QAAkB;IAElB,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;IAC5F,MAAM,OAAO,GAAG,IAAI,GAAG,EAAe,CAAC;IACvC,KAAK,MAAM,CAAC,IAAI,KAAK;QAAE,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC1C,MAAM,KAAK,GAAG,SAAS,CAAC;IACxB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC;QAChC,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;YAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAE,CAAC,IAAI,CAAC,IAA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ve the PostgreSQL connection config from the environment.
|
|
5
|
+
*
|
|
6
|
+
* pm-web requires a PostgreSQL database. Rather than silently falling back to
|
|
7
|
+
* an opaque default host (which produces a cryptic `getaddrinfo` DNS error
|
|
8
|
+
* several seconds after start), we validate up front and throw a clear,
|
|
9
|
+
* actionable error when no database is configured.
|
|
10
|
+
*/
|
|
11
|
+
function resolvePoolConfig() {
|
|
12
|
+
if (process.env.DATABASE_URL) {
|
|
13
|
+
return { connectionString: process.env.DATABASE_URL };
|
|
14
|
+
}
|
|
15
|
+
// Allow discrete POSTGRES_* vars as an alternative to DATABASE_URL.
|
|
16
|
+
if (process.env.POSTGRES_HOST && process.env.POSTGRES_DB) {
|
|
17
|
+
return {
|
|
18
|
+
host: process.env.POSTGRES_HOST,
|
|
8
19
|
port: parseInt(process.env.POSTGRES_PORT || "5432", 10),
|
|
9
20
|
user: process.env.POSTGRES_USER,
|
|
10
21
|
password: process.env.POSTGRES_PASSWORD,
|
|
11
22
|
database: process.env.POSTGRES_DB,
|
|
12
|
-
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Throw a clear, actionable error when no database is configured.
|
|
29
|
+
*
|
|
30
|
+
* pm-web requires a PostgreSQL database. Without this guard, an unset
|
|
31
|
+
* DATABASE_URL produced a cryptic `getaddrinfo` DNS error several seconds
|
|
32
|
+
* after start (or a silent hang). Call this before using the pool so the
|
|
33
|
+
* server fails fast with guidance instead.
|
|
34
|
+
*/
|
|
35
|
+
export function assertDbConfigured() {
|
|
36
|
+
const configured = Boolean(process.env.DATABASE_URL) ||
|
|
37
|
+
Boolean(process.env.POSTGRES_HOST && process.env.POSTGRES_DB);
|
|
38
|
+
if (configured)
|
|
39
|
+
return;
|
|
40
|
+
throw new Error("DATABASE_URL is not set. pm-web requires a PostgreSQL database.\n" +
|
|
41
|
+
" Set it before starting, e.g.:\n" +
|
|
42
|
+
" export DATABASE_URL=postgres://user:pass@localhost:5432/pmweb\n" +
|
|
43
|
+
" (or provide POSTGRES_HOST + POSTGRES_DB and related POSTGRES_* vars).");
|
|
44
|
+
}
|
|
45
|
+
export const pool = new Pool({
|
|
46
|
+
...resolvePoolConfig(),
|
|
13
47
|
max: 10,
|
|
14
48
|
idleTimeoutMillis: 30_000,
|
|
15
49
|
connectionTimeoutMillis: 5_000,
|
package/dist/db.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db.js","sourceRoot":"","sources":["../src/db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;AAEpB,
|
|
1
|
+
{"version":3,"file":"db.js","sourceRoot":"","sources":["../src/db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;AAEpB;;;;;;;GAOG;AACH,SAAS,iBAAiB;IACxB,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,CAAC;QAC7B,OAAO,EAAE,gBAAgB,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,CAAC;IACxD,CAAC;IAED,oEAAoE;IACpE,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;QACzD,OAAO;YACL,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa;YAC/B,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,MAAM,EAAE,EAAE,CAAC;YACvD,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa;YAC/B,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB;YACvC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW;SAClC,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,CAAC;AACZ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ACtB,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,16 +2,81 @@
|
|
|
2
2
|
// This file registers the web server as a pm extension command.
|
|
3
3
|
import { spawn, spawnSync } from "node:child_process";
|
|
4
4
|
import fs from "node:fs";
|
|
5
|
+
import net from "node:net";
|
|
6
|
+
import os from "node:os";
|
|
5
7
|
import path from "node:path";
|
|
6
8
|
import { fileURLToPath } from "node:url";
|
|
7
9
|
// Inline defineExtension helper (avoids runtime dependency on @unbrained/pm-cli/sdk)
|
|
8
10
|
function defineExtension(m) { return m; }
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
// Error contract
|
|
13
|
+
// CommandError carries a numeric exitCode so the pm runtime surfaces a clean
|
|
14
|
+
// failure instead of double-invoking the handler on a plain thrown Error.
|
|
15
|
+
// 1 = generic, 2 = usage, 3 = not-found
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
class CommandError extends Error {
|
|
18
|
+
exitCode;
|
|
19
|
+
constructor(message, exitCode = 1) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.name = "CommandError";
|
|
22
|
+
this.exitCode = exitCode;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
9
25
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
10
26
|
const packageRoot = path.resolve(__dirname, "..");
|
|
11
27
|
let serverProcess = null;
|
|
12
|
-
|
|
28
|
+
const DEFAULT_PORT = "4000";
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
// Pure helpers (unit-tested in test/)
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
/** Resolve the port from flag → PORT env → default 4000. */
|
|
33
|
+
export function resolvePort(options, env = process.env) {
|
|
34
|
+
const flag = options["port"];
|
|
35
|
+
if (flag !== undefined && flag !== null && String(flag).length > 0) {
|
|
36
|
+
return String(flag);
|
|
37
|
+
}
|
|
38
|
+
if (env["PORT"] && String(env["PORT"]).length > 0) {
|
|
39
|
+
return String(env["PORT"]);
|
|
40
|
+
}
|
|
41
|
+
return DEFAULT_PORT;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Resolve the pidfile path used to track a detached server.
|
|
45
|
+
* Uses PM_WEB_STATE_DIR when set, else the OS temp dir, keyed by port so
|
|
46
|
+
* multiple detached servers don't clobber each other's pidfile.
|
|
47
|
+
*/
|
|
48
|
+
export function pidfilePath(port, env = process.env, tmpDir = os.tmpdir()) {
|
|
49
|
+
const baseDir = env["PM_WEB_STATE_DIR"] && String(env["PM_WEB_STATE_DIR"]).length > 0
|
|
50
|
+
? String(env["PM_WEB_STATE_DIR"])
|
|
51
|
+
: tmpDir;
|
|
52
|
+
return path.join(baseDir, `pm-web-${String(port)}.pid`);
|
|
53
|
+
}
|
|
54
|
+
/** Shape a /healthz probe outcome into a stable status result object. */
|
|
55
|
+
export function shapeStatusResult(input) {
|
|
56
|
+
const portNum = Number(input.port);
|
|
57
|
+
const body = (input.body ?? null);
|
|
58
|
+
const version = body && typeof body["version"] === "string" ? body["version"] : null;
|
|
59
|
+
const result = {
|
|
60
|
+
status: input.reachable ? "up" : "down",
|
|
61
|
+
port: portNum,
|
|
62
|
+
reachable: input.reachable,
|
|
63
|
+
url: `http://localhost:${portNum}/healthz`,
|
|
64
|
+
version,
|
|
65
|
+
healthz: input.body ?? null,
|
|
66
|
+
};
|
|
67
|
+
if (input.error)
|
|
68
|
+
result.error = input.error;
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
// ---------------------------------------------------------------------------
|
|
72
|
+
// Runtime helpers
|
|
73
|
+
// ---------------------------------------------------------------------------
|
|
74
|
+
function runtimeDependenciesInstalled() {
|
|
13
75
|
const expressPackage = path.join(packageRoot, "node_modules", "express", "package.json");
|
|
14
|
-
|
|
76
|
+
return fs.existsSync(expressPackage);
|
|
77
|
+
}
|
|
78
|
+
function ensureRuntimeDependencies() {
|
|
79
|
+
if (runtimeDependenciesInstalled())
|
|
15
80
|
return;
|
|
16
81
|
console.error("Installing pm-web runtime dependencies...");
|
|
17
82
|
const install = spawnSync("npm", ["install", "--omit=dev"], {
|
|
@@ -22,7 +87,77 @@ function ensureRuntimeDependencies() {
|
|
|
22
87
|
if (install.error)
|
|
23
88
|
throw install.error;
|
|
24
89
|
if (install.status !== 0) {
|
|
25
|
-
throw new
|
|
90
|
+
throw new CommandError(`npm install --omit=dev failed with exit code ${install.status ?? "unknown"}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/** HTTP GET /healthz with a short timeout. Never throws; returns a probe result. */
|
|
94
|
+
async function probeHealthz(port) {
|
|
95
|
+
const url = `http://localhost:${port}/healthz`;
|
|
96
|
+
const controller = new AbortController();
|
|
97
|
+
const timer = setTimeout(() => controller.abort(), 1500);
|
|
98
|
+
try {
|
|
99
|
+
const res = await fetch(url, { signal: controller.signal });
|
|
100
|
+
let body = null;
|
|
101
|
+
try {
|
|
102
|
+
body = await res.json();
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
body = null;
|
|
106
|
+
}
|
|
107
|
+
return { reachable: res.ok, body };
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
return { reachable: false, error: err instanceof Error ? err.message : String(err) };
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
clearTimeout(timer);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/** Check whether a TCP port is free to bind locally. Never throws. */
|
|
117
|
+
function isPortFree(port) {
|
|
118
|
+
return new Promise((resolve) => {
|
|
119
|
+
const tester = net
|
|
120
|
+
.createServer()
|
|
121
|
+
.once("error", () => resolve(false))
|
|
122
|
+
.once("listening", () => {
|
|
123
|
+
tester.close(() => resolve(true));
|
|
124
|
+
})
|
|
125
|
+
.listen(port, "127.0.0.1");
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
function pmOnPath() {
|
|
129
|
+
const probe = spawnSync("pm", ["--version"], { stdio: "ignore" });
|
|
130
|
+
return !probe.error && probe.status === 0;
|
|
131
|
+
}
|
|
132
|
+
function workspaceInitialized(pmRoot) {
|
|
133
|
+
if (!pmRoot)
|
|
134
|
+
return false;
|
|
135
|
+
// A pm workspace has a settings.json plus item-type directories under the
|
|
136
|
+
// pm root (e.g. tasks/, features/). Match on the settings file or a known
|
|
137
|
+
// item-type dir so detection is robust across pm versions.
|
|
138
|
+
if (!fs.existsSync(pmRoot))
|
|
139
|
+
return false;
|
|
140
|
+
return (fs.existsSync(path.join(pmRoot, "settings.json")) ||
|
|
141
|
+
fs.existsSync(path.join(pmRoot, "schema")) ||
|
|
142
|
+
fs.existsSync(path.join(pmRoot, "tasks")));
|
|
143
|
+
}
|
|
144
|
+
function readPackageVersion() {
|
|
145
|
+
try {
|
|
146
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(packageRoot, "package.json"), "utf8"));
|
|
147
|
+
return pkg.version ?? "unknown";
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
return "unknown";
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function processAlive(pid) {
|
|
154
|
+
try {
|
|
155
|
+
process.kill(pid, 0);
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
catch (err) {
|
|
159
|
+
// ESRCH = no such process; EPERM = exists but not ours (treat as alive)
|
|
160
|
+
return err.code === "EPERM";
|
|
26
161
|
}
|
|
27
162
|
}
|
|
28
163
|
export default defineExtension({
|
|
@@ -30,7 +165,7 @@ export default defineExtension({
|
|
|
30
165
|
version: "1.0.0",
|
|
31
166
|
activate(api) {
|
|
32
167
|
// -----------------------------------------------------------------------
|
|
33
|
-
// Command: pm web [--port <port>]
|
|
168
|
+
// Command: pm web [--port <port>] [--detach]
|
|
34
169
|
// -----------------------------------------------------------------------
|
|
35
170
|
api.registerCommand({
|
|
36
171
|
name: "web",
|
|
@@ -39,13 +174,14 @@ export default defineExtension({
|
|
|
39
174
|
examples: [
|
|
40
175
|
"pm web",
|
|
41
176
|
"pm web --port 8080",
|
|
177
|
+
"pm web --detach",
|
|
42
178
|
],
|
|
43
179
|
flags: [
|
|
44
180
|
{ long: "--port", value_name: "port", description: "Port to listen on (default: 4000 or PORT env var)" },
|
|
45
181
|
{ long: "--detach", description: "Run the server in the background" },
|
|
46
182
|
],
|
|
47
183
|
async run(ctx) {
|
|
48
|
-
const port = ctx.options
|
|
184
|
+
const port = resolvePort(ctx.options);
|
|
49
185
|
const detach = Boolean(ctx.options["detach"]);
|
|
50
186
|
const serverPath = path.resolve(__dirname, "server.js");
|
|
51
187
|
ensureRuntimeDependencies();
|
|
@@ -60,6 +196,15 @@ export default defineExtension({
|
|
|
60
196
|
stdio: "ignore",
|
|
61
197
|
});
|
|
62
198
|
serverProcess.unref();
|
|
199
|
+
// Track the detached PID so `pm web stop` can terminate it.
|
|
200
|
+
if (serverProcess.pid) {
|
|
201
|
+
try {
|
|
202
|
+
fs.writeFileSync(pidfilePath(port), String(serverProcess.pid), "utf8");
|
|
203
|
+
}
|
|
204
|
+
catch (err) {
|
|
205
|
+
console.error(`Warning: could not write pidfile: ${err instanceof Error ? err.message : String(err)}`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
63
208
|
console.error(`pm-web started on port ${port} (PID ${serverProcess.pid})`);
|
|
64
209
|
return { status: "started", port: Number(port), pid: serverProcess.pid };
|
|
65
210
|
}
|
|
@@ -77,12 +222,212 @@ export default defineExtension({
|
|
|
77
222
|
resolve();
|
|
78
223
|
return;
|
|
79
224
|
}
|
|
80
|
-
reject(new
|
|
225
|
+
reject(new CommandError(`pm-web exited with code ${code ?? `signal ${signal}`}`));
|
|
81
226
|
});
|
|
82
227
|
});
|
|
83
228
|
return { status: "stopped", port: Number(port) };
|
|
84
229
|
},
|
|
85
230
|
});
|
|
231
|
+
// -----------------------------------------------------------------------
|
|
232
|
+
// Command: pm web status [--port <port>] [--json]
|
|
233
|
+
// -----------------------------------------------------------------------
|
|
234
|
+
api.registerCommand({
|
|
235
|
+
name: "web status",
|
|
236
|
+
description: "Report whether a pm-web server is reachable on the configured port.",
|
|
237
|
+
intent: "check pm-web server status",
|
|
238
|
+
examples: ["pm web status", "pm web status --port 8080 --json"],
|
|
239
|
+
flags: [
|
|
240
|
+
{ long: "--port", value_name: "port", description: "Port to probe (default: 4000 or PORT env var)" },
|
|
241
|
+
{ long: "--json", description: "Emit machine-readable JSON" },
|
|
242
|
+
],
|
|
243
|
+
async run(ctx) {
|
|
244
|
+
const port = resolvePort(ctx.options);
|
|
245
|
+
const json = Boolean(ctx.options["json"]);
|
|
246
|
+
const probe = await probeHealthz(port);
|
|
247
|
+
const result = shapeStatusResult({
|
|
248
|
+
port,
|
|
249
|
+
reachable: probe.reachable,
|
|
250
|
+
body: probe.body,
|
|
251
|
+
error: probe.error,
|
|
252
|
+
});
|
|
253
|
+
if (json) {
|
|
254
|
+
console.log(JSON.stringify(result, null, 2));
|
|
255
|
+
}
|
|
256
|
+
else if (result.status === "up") {
|
|
257
|
+
console.log(`pm-web is UP on port ${result.port}` +
|
|
258
|
+
(result.version ? ` (version ${result.version})` : ""));
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
console.log(`pm-web is DOWN on port ${result.port}`);
|
|
262
|
+
}
|
|
263
|
+
return result;
|
|
264
|
+
},
|
|
265
|
+
});
|
|
266
|
+
// -----------------------------------------------------------------------
|
|
267
|
+
// Command: pm web stop [--port <port>] [--json]
|
|
268
|
+
// -----------------------------------------------------------------------
|
|
269
|
+
api.registerCommand({
|
|
270
|
+
name: "web stop",
|
|
271
|
+
description: "Stop a pm-web server previously started with --detach.",
|
|
272
|
+
intent: "stop a detached pm-web server",
|
|
273
|
+
examples: ["pm web stop", "pm web stop --port 8080"],
|
|
274
|
+
flags: [
|
|
275
|
+
{ long: "--port", value_name: "port", description: "Port of the detached server (default: 4000 or PORT env var)" },
|
|
276
|
+
{ long: "--json", description: "Emit machine-readable JSON" },
|
|
277
|
+
],
|
|
278
|
+
async run(ctx) {
|
|
279
|
+
const port = resolvePort(ctx.options);
|
|
280
|
+
const json = Boolean(ctx.options["json"]);
|
|
281
|
+
const pidfile = pidfilePath(port);
|
|
282
|
+
const emit = (result) => {
|
|
283
|
+
if (json) {
|
|
284
|
+
console.log(JSON.stringify(result, null, 2));
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
console.log(String(result["message"]));
|
|
288
|
+
}
|
|
289
|
+
return result;
|
|
290
|
+
};
|
|
291
|
+
// Prefer the in-process handle if we started it this session.
|
|
292
|
+
let pid = null;
|
|
293
|
+
if (serverProcess?.pid) {
|
|
294
|
+
pid = serverProcess.pid;
|
|
295
|
+
}
|
|
296
|
+
else if (fs.existsSync(pidfile)) {
|
|
297
|
+
const raw = fs.readFileSync(pidfile, "utf8").trim();
|
|
298
|
+
const parsed = Number.parseInt(raw, 10);
|
|
299
|
+
if (Number.isInteger(parsed) && parsed > 0)
|
|
300
|
+
pid = parsed;
|
|
301
|
+
}
|
|
302
|
+
if (pid === null) {
|
|
303
|
+
return emit({
|
|
304
|
+
status: "not_running",
|
|
305
|
+
port: Number(port),
|
|
306
|
+
message: `pm-web is not running (no pidfile for port ${port}).`,
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
if (!processAlive(pid)) {
|
|
310
|
+
// Stale pidfile — clean it up and report gracefully.
|
|
311
|
+
if (fs.existsSync(pidfile))
|
|
312
|
+
fs.rmSync(pidfile, { force: true });
|
|
313
|
+
return emit({
|
|
314
|
+
status: "not_running",
|
|
315
|
+
port: Number(port),
|
|
316
|
+
pid,
|
|
317
|
+
message: `pm-web process (PID ${pid}) is not running; cleared stale pidfile.`,
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
try {
|
|
321
|
+
process.kill(pid, "SIGTERM");
|
|
322
|
+
}
|
|
323
|
+
catch (err) {
|
|
324
|
+
throw new CommandError(`Failed to stop pm-web (PID ${pid}): ${err instanceof Error ? err.message : String(err)}`);
|
|
325
|
+
}
|
|
326
|
+
if (fs.existsSync(pidfile))
|
|
327
|
+
fs.rmSync(pidfile, { force: true });
|
|
328
|
+
if (serverProcess?.pid === pid)
|
|
329
|
+
serverProcess = null;
|
|
330
|
+
return emit({
|
|
331
|
+
status: "stopped",
|
|
332
|
+
port: Number(port),
|
|
333
|
+
pid,
|
|
334
|
+
message: `Stopped pm-web (PID ${pid}) on port ${port}.`,
|
|
335
|
+
});
|
|
336
|
+
},
|
|
337
|
+
});
|
|
338
|
+
// -----------------------------------------------------------------------
|
|
339
|
+
// Command: pm web doctor [--port <port>] [--json]
|
|
340
|
+
// -----------------------------------------------------------------------
|
|
341
|
+
api.registerCommand({
|
|
342
|
+
name: "web doctor",
|
|
343
|
+
description: "Preflight diagnostics for running pm-web (Node, deps, port, pm, workspace).",
|
|
344
|
+
intent: "diagnose pm-web preflight readiness",
|
|
345
|
+
examples: ["pm web doctor", "pm web doctor --json"],
|
|
346
|
+
flags: [
|
|
347
|
+
{ long: "--port", value_name: "port", description: "Port to check availability for (default: 4000 or PORT env var)" },
|
|
348
|
+
{ long: "--json", description: "Emit machine-readable JSON" },
|
|
349
|
+
],
|
|
350
|
+
async run(ctx) {
|
|
351
|
+
const port = resolvePort(ctx.options);
|
|
352
|
+
const json = Boolean(ctx.options["json"]);
|
|
353
|
+
const nodeMajor = Number.parseInt(process.versions.node.split(".")[0] ?? "0", 10);
|
|
354
|
+
const depsInstalled = runtimeDependenciesInstalled();
|
|
355
|
+
const portFree = await isPortFree(Number(port));
|
|
356
|
+
const pmAvailable = pmOnPath();
|
|
357
|
+
const wsInit = workspaceInitialized(ctx.pm_root);
|
|
358
|
+
const checks = [
|
|
359
|
+
{
|
|
360
|
+
name: "node_version",
|
|
361
|
+
ok: nodeMajor >= 20,
|
|
362
|
+
detail: `Node ${process.versions.node} (requires >= 20)`,
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
name: "runtime_dependencies",
|
|
366
|
+
ok: depsInstalled,
|
|
367
|
+
detail: depsInstalled
|
|
368
|
+
? "express and runtime deps installed"
|
|
369
|
+
: "runtime deps missing (will auto-install on `pm web`)",
|
|
370
|
+
},
|
|
371
|
+
{
|
|
372
|
+
name: "port_available",
|
|
373
|
+
ok: portFree,
|
|
374
|
+
detail: portFree
|
|
375
|
+
? `port ${port} is free`
|
|
376
|
+
: `port ${port} is in use (a server may already be running)`,
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
name: "pm_on_path",
|
|
380
|
+
ok: pmAvailable,
|
|
381
|
+
detail: pmAvailable ? "pm CLI is on PATH" : "pm CLI not found on PATH",
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
name: "workspace_initialized",
|
|
385
|
+
ok: wsInit,
|
|
386
|
+
detail: wsInit
|
|
387
|
+
? `pm workspace found at ${ctx.pm_root}`
|
|
388
|
+
: `no pm workspace at ${ctx.pm_root || "(unset)"} — run \`pm init\``,
|
|
389
|
+
},
|
|
390
|
+
];
|
|
391
|
+
// port_available is informational (in-use can be a healthy running server),
|
|
392
|
+
// so it does not gate overall readiness.
|
|
393
|
+
const ok = checks
|
|
394
|
+
.filter((c) => c.name !== "port_available")
|
|
395
|
+
.every((c) => c.ok);
|
|
396
|
+
const result = {
|
|
397
|
+
ok,
|
|
398
|
+
version: readPackageVersion(),
|
|
399
|
+
node: process.versions.node,
|
|
400
|
+
port: Number(port),
|
|
401
|
+
checks,
|
|
402
|
+
};
|
|
403
|
+
if (json) {
|
|
404
|
+
console.log(JSON.stringify(result, null, 2));
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
console.log(`pm-web doctor — overall: ${ok ? "OK" : "ISSUES"}`);
|
|
408
|
+
for (const c of checks) {
|
|
409
|
+
console.log(` [${c.ok ? "ok" : "!!"}] ${c.name}: ${c.detail}`);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return result;
|
|
413
|
+
},
|
|
414
|
+
});
|
|
415
|
+
// -----------------------------------------------------------------------
|
|
416
|
+
// services capability — intentionally NOT registered.
|
|
417
|
+
//
|
|
418
|
+
// The SDK's `registerService(name, override)` only accepts one of the eight
|
|
419
|
+
// fixed CORE service names (output_format, error_format, help_format,
|
|
420
|
+
// lock_acquire, lock_release, history_append, item_store_write,
|
|
421
|
+
// item_store_delete) and OVERRIDES that core service on every pm command.
|
|
422
|
+
// There is no API to register a new "pm-web lifecycle" service, and
|
|
423
|
+
// overriding a core service would alter/replace core output for unrelated
|
|
424
|
+
// commands. The pm-web server lifecycle is surfaced safely via the
|
|
425
|
+
// web/status/stop/doctor commands instead. The guarded block below
|
|
426
|
+
// documents the deliberate no-op; the "services" capability is therefore
|
|
427
|
+
// NOT declared in manifest.json.
|
|
428
|
+
if (typeof api.registerService === "function") {
|
|
429
|
+
// Deliberately register no service overrides — see comment above.
|
|
430
|
+
}
|
|
86
431
|
},
|
|
87
432
|
});
|
|
88
433
|
//# sourceMappingURL=index.js.map
|