@softdesignbrasil/productdock-cli 0.8.0 → 0.9.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/README.md CHANGED
@@ -92,6 +92,13 @@ Under `--json` the CLI:
92
92
  `error.code` is the process exit code, so an agent can branch either on the
93
93
  document or on the exit status.
94
94
 
95
+ **One documented exception: `productdock watch`.** It does not end on its own,
96
+ so under `--json` it writes **one JSON event per line** (NDJSON) as things
97
+ happen, and the closing document above is its last line. A round asks nothing,
98
+ so it runs without a terminal; the two things that do ask — the model on the
99
+ first run and `--confirm` — still prompt with `--json` on, on `stderr`, and
100
+ need a terminal. See [`productdock watch`](#productdock-watch).
101
+
95
102
  Without `--json`, `stdout` still carries nothing but what a shell expects to find
96
103
  there — `--help` and `--version`. Prose, spinners and error messages always go to
97
104
  `stderr`, which keeps `stdout` free for machine-readable output.
@@ -155,7 +162,7 @@ productdock init
155
162
 
156
163
  ### `productdock login`
157
164
 
158
- Authenticates with Azure AD using OAuth 2.1 + PKCE. Opens a browser window and saves credentials to `~/.productdock/credentials.json`.
165
+ Authenticates with Azure AD using OAuth 2.1 + PKCE. Opens a browser window and saves credentials to `~/.productdock/credentials.json` — or to the directory in `PRODUCTDOCK_CONFIG_DIR`, which `login`, the silent refresh and `logout` all honour.
159
166
 
160
167
  ```bash
161
168
  productdock login
@@ -1343,6 +1350,148 @@ The general table above holds; this is how each condition maps to it:
1343
1350
  | `1` | Missing `<ref>`/`--ref`/`--type`; body file unreadable; body that is not a JSON object; file **and** `--content` together; directory not linked and no `--project-id`; **`flow_change` refused (`400`) — wrong type, or outside the `backlog`/`prd`/`specification` window**; **body the server could not interpret (`400`) — the message carries the schema of the `--type`, and nothing was written**; unknown `update_type` (`400`); no permission for the write (`403`); no access to the work item (`404` — the same answer as "does not exist", on purpose); any other API failure |
1344
1351
  | `2` | The API rejected the token (`401`) — run `productdock login` again |
1345
1352
 
1353
+ ### `productdock watch`
1354
+
1355
+ The runner of the **PRD Tech Review**. Run it in the directory of a linked
1356
+ project and the terminal serves that project's Tech Review requests on its own:
1357
+ it takes a request, runs the two stages of the review with Claude Code in a
1358
+ disposable copy of the code, **without asking you anything**, and the request
1359
+ ends closed. The purely technical questions are left pending for the Spec, in
1360
+ the body of the review and in the work item's state. One request at a time.
1361
+
1362
+ ```bash
1363
+ # Serve the project linked to this directory
1364
+ productdock watch
1365
+
1366
+ # Only work items assigned to you, asking before each run
1367
+ productdock watch --mine --confirm
1368
+
1369
+ # Another project, polling every 30 s, machine-readable events
1370
+ productdock watch --project-id <uuid> --interval 30 --json
1371
+
1372
+ # Follow what Claude is doing in each stage, live
1373
+ productdock watch --follow
1374
+ ```
1375
+
1376
+ **One project per terminal.** The project is the one in `productdock.json`
1377
+ (looked up the way every command does) or `--project-id`. To serve two projects,
1378
+ open two terminals.
1379
+
1380
+ **It needs a terminal only for what asks.** A round asks nothing, so with the
1381
+ model already stored and without `--confirm` it runs with no TTY — `--json`
1382
+ included. Without a TTY it exits `1` at start-up in two cases: no model stored
1383
+ yet (run it once in a terminal to choose one, or write it to
1384
+ `~/.productdock/config.json`), and `--confirm` (it asks before each run). It
1385
+ also checks, before taking any request: that the directory is inside a Git
1386
+ repository, that `claude` (Claude Code) is on the `PATH`, that the
1387
+ `pd-workflow` skill is installed, and that there is a CLI session.
1388
+
1389
+ **What a round does.**
1390
+
1391
+ 1. **Claim** the oldest queued request of the project (`/cli/prd-review-jobs/claim`).
1392
+ The server decides what you may take — member of the project with permission
1393
+ to edit work items — and two runners never take the same request.
1394
+ 2. **Disposable copy** — `git worktree add --detach` of `HEAD` in the temp
1395
+ directory, with submodules initialised, and the installed `pd-workflow` skill
1396
+ copied into it (the repository's `.claude/skills/pd-workflow`, else the user's
1397
+ `~/.claude/skills/pd-workflow`). Your working tree is not touched; the copy is
1398
+ removed at the end of the round, failure included. A copy left behind by a
1399
+ runner that died — still on disk, still registered in your repository — is
1400
+ cleared when the same request is taken again, and every such leftover is
1401
+ cleared when `watch` starts; a copy that belongs to a runner still alive in
1402
+ another terminal is kept (the runner locks its copy with its process id).
1403
+ 3. **Stage A** — `claude -p` analyses the PRD against the code, following the
1404
+ skill's autonomous-mode reference. It submits nothing.
1405
+ 4. **Version check** — if the PRD changed during the round, or the request was
1406
+ cancelled, the round is **discarded**: no Stage B, nothing submitted.
1407
+ 5. **Stage B** — `claude --resume` submits the review **once**, right after the
1408
+ version check, with no pause. Submitting closes the request on the server.
1409
+
1410
+ A `runner-handoff.json` in the round's folder comes from an outdated
1411
+ (pre-release) skill: it is **ignored**, never asked, and a one-line warning says so
1412
+ ("skill desatualizada — atualize a pd-workflow"). Stage B still runs, and with
1413
+ that skill it fails the round for lack of answers — the warning is the cause.
1414
+
1415
+ While a round runs the runner sends a heartbeat every minute — the lease is 15
1416
+ minutes — and the request stays `running` throughout. A failed heartbeat or a
1417
+ network blip does not end the round. A round that fails ends the request as
1418
+ `failed`, with the cause; its files are kept and the path is printed.
1419
+
1420
+ **How Claude Code runs.** With your account and the model you chose, but with the
1421
+ project's configuration only: `--setting-sources project`,
1422
+ `--strict-mcp-config`, no web access, notebooks denied. Writing is granted **only
1423
+ in the round's folder** (passed with `--add-dir`), by an `Edit(<folder>/**)`
1424
+ rule — in Claude Code 2.1.x path rules for writing are `Edit` rules and cover
1425
+ every tool that writes a file, while a `Write(<path>)` rule never matches —
1426
+ and writing in the disposable copy of the code is denied by name, so a project
1427
+ setting cannot reopen it. Stage A may read, search, delegate to a subagent,
1428
+ write in the round's folder and run `productdock wi prd`, `wi spec-context`, `prd-review get`,
1429
+ `code search` and `code map`; Stage B adds `prd-review submit` and
1430
+ `state update`. There is no spending cap: the run uses your Claude Code quota,
1431
+ like any request made in the IDE. The `productdock` calls Claude makes reuse your
1432
+ session through `PRODUCTDOCK_CONFIG_DIR`, set by the runner — your `HOME` is not
1433
+ changed.
1434
+
1435
+ **The model.** On the first run the command asks which Claude Code model to use,
1436
+ suggesting the default of the installed Claude Code when it can read one
1437
+ (`ANTHROPIC_MODEL`, or `model` in the Claude Code `settings.json` under
1438
+ `CLAUDE_CONFIG_DIR` or `~/.claude`), and stores the answer in
1439
+ `~/.productdock/config.json` (`{ "watch": { "model": "…" } }`). Edit or delete
1440
+ that file to change it.
1441
+
1442
+ **Following a round (`--follow`).** By default Claude Code runs headless
1443
+ (`claude -p --output-format json`) and the terminal only shows the request, the
1444
+ stages and the outcome — the review is not a chat, there and in production alike.
1445
+ With `--follow` each stage runs with `--output-format stream-json --verbose` and
1446
+ the runner prints one line per action as it happens: the file read (`📄`, relative
1447
+ to the disposable copy), the search (`🔎`), the `productdock` command (`▸`), the
1448
+ subagent (`🤖`), the file written in the round's folder (`✍`) and the first line of
1449
+ what the model says (`💬`). Only the target of each tool is shown, never its
1450
+ content. The round itself — tools, permissions, files, outcome — does not change.
1451
+
1452
+ **Ctrl+C.** The first one finishes the current round and exits. The second one
1453
+ gives the request back to the queue (`release`) and exits — both with `0`.
1454
+
1455
+ #### Parameters
1456
+
1457
+ | Flag | Description |
1458
+ | ---------------------- | ---------------------------------------------------------------------------------------------------------------------- |
1459
+ | `--project-id <uuid>` | Project to serve — overrides `project.id` of `productdock.json` |
1460
+ | `--mine` | Only work items assigned to you. Filtered by the server, in the claim |
1461
+ | `--confirm` | Ask before each run — needs a terminal. Declining gives the request back to the queue, and this session does not receive it again |
1462
+ | `--interval <seconds>` | Seconds between queue polls while idle — a positive integer, `10` by default. A non-numeric value is refused (exit `1`) |
1463
+ | `--follow` | Print what Claude does in each stage, live — one line per tool call (file read, search, command, subagent, file written) |
1464
+ | `--json` | One JSON event per line on `stdout` (NDJSON); prose and the questions of the first run and `--confirm` on `stderr` |
1465
+
1466
+ #### Response format
1467
+
1468
+ Without `--json`, `stdout` stays empty and each round is reported on `stderr`:
1469
+ the request in progress, the outcome and its duration (and turns). Under
1470
+ `--json`, one event per line:
1471
+
1472
+ | `event` | When |
1473
+ | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
1474
+ | `watch_started` | The runner is up — `project_id`, `runner_label`, `model`, `only_assigned`, `confirm`, `follow`, `skill_version` |
1475
+ | `job_started` | A request was taken — `job_id`, `work_item_ref`, `brief_version`, `title`, `skill_version` (the `SKILL.md` version copied into the round) |
1476
+ | `job_released` | A request declined under `--confirm` went back to the queue |
1477
+ | `job_finished` | The round ended — `outcome` (`completed`, `failed`, `discarded`, `released`), `duration_ms`, `turns`, and the verdict counts (`tech_pending`, or the `tech_decisions` of a 2.3.0 skill) or the `error` |
1478
+ | `activity` | Only with `--follow` — one action of Claude: `job_id`, `stage` (`A`/`B`), `kind` (`tool`/`text`), `tool`, `detail` |
1479
+ | `warning` | Something that did not end the round — a failed heartbeat, an unreachable queue |
1480
+ | `stopping` | The first Ctrl+C |
1481
+
1482
+ The last line is the closing document — `{ "ok": true, "event": "watch_stopped", "rounds": n }`,
1483
+ or the error document.
1484
+
1485
+ #### Exit codes
1486
+
1487
+ The general table above holds; this is how each condition maps to it:
1488
+
1489
+ | Code | When |
1490
+ | ---- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1491
+ | `0` | The runner was stopped with Ctrl+C — once or twice |
1492
+ | `1` | Directory not linked and no `--project-id` (no network call is made); no terminal (`--json` included) with no model stored yet, or with `--confirm`; not inside a Git repository; `claude` not on the `PATH`; `pd-workflow` not installed; non-numeric `--interval`; the queue refused the call for good — no permission on the project (`403`), bad request (`400`) |
1493
+ | `2` | No CLI session, or the API rejected the token (`401`) — run `productdock login` again |
1494
+
1346
1495
  ### `productdock doctor`
1347
1496
 
1348
1497
  Runs a full diagnostic and reports any configuration issues with suggested fixes.
@@ -1450,7 +1599,7 @@ The branch is passed to the registry as a `?branch=` query parameter, and every
1450
1599
 
1451
1600
  ## How authentication works
1452
1601
 
1453
- There is **one** OAuth 2.1 + PKCE flow and it lives at `/oauth/*` on the ProductDock API — not under `/mcp`. Two channels ride on it: the CLI, which authenticates on its own and calls the project endpoints directly, and the IDEs, which keep talking to the MCP server. Both end up with credentials in `~/.productdock/credentials.json` (mode `0600`), refreshed silently as they expire.
1602
+ There is **one** OAuth 2.1 + PKCE flow and it lives at `/oauth/*` on the ProductDock API — not under `/mcp`. Two channels ride on it: the CLI, which authenticates on its own and calls the project endpoints directly, and the IDEs, which keep talking to the MCP server. Both end up with credentials in `~/.productdock/credentials.json` (mode `0600`, written atomically), refreshed silently as they expire. The credentials are deleted only when the server rejects the session (`invalid_grant` or `401`); a `5xx` or a network failure during the refresh keeps them and exits `1`. Before giving up, the CLI rereads the file: another process (the `productdock` calls of a `watch` round, for instance) may have renewed the session in the meantime.
1454
1603
 
1455
1604
  ```
1456
1605
  productdock login IDE (Claude Code / Cursor / VS Code)
@@ -1478,6 +1627,7 @@ All optional — defaults point at production.
1478
1627
  | `PRODUCTDOCK_MCP_URL` | `<PRODUCTDOCK_API_URL>/mcp` | MCP server URL, written into each IDE config by `mcp setup`. Legacy: when it is set and `PRODUCTDOCK_API_URL` is not, this value minus the `/mcp` suffix becomes the API base |
1479
1628
  | `PRODUCTDOCK_REGISTRY_URL` | `https://productdock-core-api.softdesign.com.br` | Skill and agent registry URL |
1480
1629
  | `AI_TOOLS_BRANCH` | _(registry default branch, `main`)_ | Resolve skills and agents from this `ai-tools` branch. Setting it to `main` is the same as not setting it |
1630
+ | `PRODUCTDOCK_CONFIG_DIR` | `~/.productdock` | Directory of `credentials.json` and of the user's `config.json`. `login`, the token refresh and `logout` honour it; `productdock watch` sets it for the `productdock` calls Claude makes, so they share your session without changing `HOME` |
1481
1631
 
1482
1632
  When running from source, these are also read from a `.env` file in the repository root — see `.env.example`.
1483
1633
 
@@ -1515,10 +1665,10 @@ bun test test/output.test.ts
1515
1665
  | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1516
1666
  | `bin/productdock.ts` | Commander program — command definitions and dispatch |
1517
1667
  | `lib/constants.ts` | Version, base URLs and environment overrides — the `/oauth/*` and `/cli/*` root, the MCP server URL, the registry, `AI_TOOLS_BRANCH`; loads `.env` when running from source |
1518
- | `lib/auth.ts` | OAuth 2.1 + PKCE flow, credential store, token refresh |
1668
+ | `lib/auth.ts` | OAuth 2.1 + PKCE flow, credential store (`PRODUCTDOCK_CONFIG_DIR`), token refresh |
1519
1669
  | `lib/config.ts` | `productdock.json` read/write/migrate, `init` and `link` |
1520
1670
  | `lib/api.ts` | Project and repository lookup behind `link` — `/cli/projects` and `/cli/projects/{id}/repositories` |
1521
- | `lib/git.ts` | `origin` remote detection and Azure DevOps URL parsing (SSH, HTTPS, legacy) |
1671
+ | `lib/git.ts` | `origin` remote detection, Azure DevOps URL parsing (SSH, HTTPS, legacy), and the worktree helpers of `watch` |
1522
1672
  | `lib/ide.ts` | IDE detection and MCP config writing |
1523
1673
  | `lib/registry.ts` | Registry HTTP client — one code path for skills and agents, `?branch=` |
1524
1674
  | `lib/http.ts` | HTTP client for the `/cli/*` endpoints — file bodies, `multipart`, HTTP status kept in the error |
@@ -1533,6 +1683,9 @@ bun test test/output.test.ts
1533
1683
  | `lib/prd-review.ts` | The `prd-review` command group — `get` (mandatory read-back) and `submit` over `/cli/prd-review` |
1534
1684
  | `lib/evaluations.ts` | The `eval` command group — `submit` over `/cli/evaluations`, envelope from a file, project-level |
1535
1685
  | `lib/sdlc-state.ts` | The `state` command group — `phase` over `/cli/state/phase` and `update` over `/cli/state`, the read/write pair over the same state |
1686
+ | `lib/prd-review-jobs.ts` | Tech Review queue client — `claim`, `heartbeat`, `release` and `finish` over `/cli/prd-review-jobs/*` |
1687
+ | `lib/watch.ts` | The `watch` command — the PRD Tech Review runner: disposable worktree, the two Claude Code stages, heartbeat — no question during the round |
1688
+ | `lib/user-config.ts` | The user's `config.json` in the configuration directory, and the private atomic writer shared with the credentials |
1536
1689
  | `lib/doctor.ts` | Diagnostics |
1537
1690
  | `lib/exit.ts` | Exit code taxonomy — `CliError` and the error → code mapping |
1538
1691
  | `lib/output.ts` | Output layer — JSON on `stdout`, prose on `stderr`, credential redaction |