Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"name": "unic-spec-review",
"source": "./",
"tags": ["productivity", "quality"],
"version": "0.1.1"
"version": "0.1.2"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"keywords": ["spec-review", "confluence", "figma", "adversarial-review", "six-hats", "unic"],
"license": "LGPL-3.0-or-later",
"name": "unic-spec-review",
"version": "0.1.1"
"version": "0.1.2"
}
19 changes: 18 additions & 1 deletion apps/claude-code/unic-spec-review/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Breaking
- (none)

### Added
- (none)

### Fixed
- (none)

## [0.1.2] — 2026-06-05

### Breaking
- (none)

### Added
- Cover two previously untested paths flagged in PR #210 review: `loadAtlassianCreds` preferring env vars over a present credentials file, and `fetchConfluencePage` capping the stripped excerpt at 800 characters.
- Add `/setup-confluence` command: interactive credential wizard writing `~/.unic-confluence.json`, vendored by copying from `unic-pr-review` (ADR-0001 self-containment, no cross-import).
- Add `/spec-doctor` command: preflight checks for Confluence credentials and connectivity, Figma Dev Mode MCP, and Playwright MCP; absent MCPs are reported as explicit loud failures with remediation, never a silent skip.
- Add `parseArgs` to the `args` module (CLI parser shared by the setup wizard) alongside the existing `parseReviewSpecArgs`.
- Unit tests for the vendored `setup-confluence` wizard (`writeConfluenceCreds`, `isEnvConfigured`) and the Confluence preflight logic (`checkConfluence`, `runSpecDoctorCredentials`, `mapPingError`, `realPing`) with injected `homedir`/`platform`/`fetch`/`loadCreds`; no live services.
- Cover two more pure-logic branches flagged in PR #211 review: `isEnvConfigured` rejecting an env var that is present but empty, and `checkConfluence` falling back to the raw url string when the configured url is unparseable.

### Fixed
- Reject non-http(s) URLs in arg parsing, link classification, and validate `pageTitle`/`pageUrl` in the report-renderer CLI entry, so ftp/file/mailto inputs no longer slip through and missing report fields no longer render as literal `undefined`.
- Make `/review-spec` orchestration portable: write the scratch report JSON into the gitignored `.spec-review/` directory instead of the POSIX-only `/tmp` path (broke on Windows CI), and surface the structured `errors[].kind`/`errors[].message` from the fetch script so the real failure cause is shown.

### Documentation
- Correct stale cross-plugin references in code comments (drop the `render-summary.mjs`, `doctor.mjs`, and inaccurate `ADR-0001` citations), reword the `CONTEXT.md` status line so it no longer promises an unused `(S1)` per-term marking convention, and replace em dashes with hyphens in authored comments and messages per the org typography rule.
- Correct stale cross-plugin references in code comments (drop the `render-summary.mjs`, `doctor.mjs`, and inaccurate `ADR-0001` citations), reword the `CONTEXT.md` status line so it no longer promises an unused `(S1)` per-term marking convention, and replace em dashes with hyphens in authored comments, command docs, user-facing script output, and test descriptions, per this slice's acceptance criterion (no em dash in authored text except the mandated CHANGELOG version header).
- Reword the `writeConfluenceCreds` JSDoc to drop a stale `:setup-jira` reference (a command that exists in `unic-pr-review` but not in this plugin); the `jiraUrl` preservation behavior is unchanged.

## [0.1.1] — 2026-06-05

Expand Down
52 changes: 48 additions & 4 deletions apps/claude-code/unic-spec-review/commands/setup-confluence.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,53 @@
---
description: Interactive setup wizard that writes Confluence credentials to ~/.unic-confluence.json for unic-spec-review.
allowed-tools: Bash(node *), Bash(test *), Bash(echo *)
argument-hint: (no arguments)
description: Interactive setup wizard - writes ~/.unic-confluence.json with Confluence credentials
---

# Setup Confluence
# unic-spec-review:setup-confluence

> ⚠️ Scaffold stub: not yet implemented. Behaviour is specified in the [PRD](../docs/issues/unic-spec-review/PRD.md) (#200); the command body lands with its implementation slice.
Guides you through creating `~/.unic-confluence.json` so the plugin can reach Confluence.

This plugin ships its own Confluence credential wizard so it is fully self-contained: it never depends on another plugin being installed or set up. It writes to the shared `~/.unic-confluence.json` convention (also honouring `CONFLUENCE_*` env vars), so a user with `unic-pr-review` already configured does not configure Confluence twice. See `AGENTS.md` for the locked design.
## Step 1 - Check for existing env-var configuration

If `CONFLUENCE_URL`, `CONFLUENCE_USER`, and `CONFLUENCE_TOKEN` are all set, the file is not required.
Tell the user and offer to exit without writing. If they want to write the file anyway, continue.

## Step 2 - Check for an existing credential file

```sh
test -f ~/.unic-confluence.json && echo "exists"
```

If the file exists, show the current values (redact the token - print only `****`):

```sh
node -e "
const c = JSON.parse(require('fs').readFileSync(require('os').homedir() + '/.unic-confluence.json', 'utf8'));
console.log(JSON.stringify({ url: c.url, username: c.username, token: '****', jiraUrl: c.jiraUrl ?? null }, null, 2));
"
```

Ask whether to overwrite. If the user chooses not to overwrite, stop.

## Step 3 - Collect credentials

Ask the user for:

1. **Confluence base URL** - e.g. `https://your-org.atlassian.net`
2. **Username** - typically the Atlassian account email address
3. **API token** - generate one at <https://id.atlassian.com/manage-profile/security/api-tokens>

## Step 4 - Write the credential file

```sh
node "${CLAUDE_PLUGIN_ROOT}/scripts/setup-confluence.mjs" --url "<url>" --username "<username>" --token "<token>"
```

## Step 5 - Confirm

Tell the user:

- `~/.unic-confluence.json` has been written with access restricted to the owner (chmod 600) on macOS/Linux
- On Windows: file permissions must be restricted manually (the wizard printed a reminder)
- They can run `/unic-spec-review:spec-doctor` to verify the full setup
78 changes: 75 additions & 3 deletions apps/claude-code/unic-spec-review/commands/spec-doctor.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,81 @@
---
allowed-tools: Bash(node *)
argument-hint: (no arguments)
description: Verify unic-spec-review prerequisites (Confluence credentials, Figma Dev Mode MCP, and Playwright MCP).
---

# Spec Doctor
# unic-spec-review:spec-doctor

> ⚠️ Scaffold stub: not yet implemented. Behaviour is specified in the [PRD](../docs/issues/unic-spec-review/PRD.md) (#200); the command body lands with its implementation slice.
Runs a preflight check for all unic-spec-review prerequisites so you can diagnose setup issues before running a review.

This preflight command will check that Confluence credentials (`~/.unic-confluence.json`), the Figma Dev Mode MCP, and the Playwright MCP are present and reachable before a review. See `AGENTS.md` for the locked design.
Checks performed:

1. Atlassian credentials are present (`~/.unic-confluence.json` or `CONFLUENCE_*` env vars)
2. Confluence is reachable via HTTP (Basic auth)
3. Figma Dev Mode MCP is connected
4. Playwright MCP is connected

## Step 1 - Print the spec-doctor header

Print:

```
unic-spec-review spec-doctor
─────────────────────────────────
```

## Step 2 - Run the Confluence credential and connectivity check

```sh
node "${CLAUDE_PLUGIN_ROOT}/scripts/spec-doctor.mjs"
```

Show the script output verbatim (one ✓/✗ line per check).

Record whether the script exited 0 (all credential/connectivity checks passed) or 1 (failed).

## Step 3 - Check for Figma Dev Mode MCP

Determine whether a Figma Dev Mode MCP tool is available in the current Claude Code session
by checking the active tool set for tools whose names match `mcp__figma*` or any tool clearly
from a Figma Dev Mode MCP server.

- If the Figma Dev Mode MCP is **available**: print `✓ Figma Dev Mode MCP - connected`
- If the Figma Dev Mode MCP is **NOT available**: print the following explicit failure (not a silent skip):
```
✗ Figma Dev Mode MCP - not connected
Remediation: Enable the Figma Dev Mode MCP in your Claude Code MCP settings.
See https://help.figma.com/hc/en-us/articles/32132100888087 for setup instructions.
```
Record whether this check passed or failed.

## Step 4 - Check for Playwright MCP

Determine whether a Playwright MCP tool is available in the current Claude Code session
by checking the active tool set for tools whose names match `mcp__playwright*` or any tool
clearly from a Playwright MCP server.

- If the Playwright MCP is **available**: print `✓ Playwright MCP - connected`
- If the Playwright MCP is **NOT available**: print the following explicit failure (not a silent skip):
```
✗ Playwright MCP - not connected
Remediation: Enable the Playwright MCP in your Claude Code MCP settings.
Example config: https://github.com/microsoft/playwright-mcp
```
Record whether this check passed or failed.

## Step 5 - Print overall result

Print:

```
─────────────────────────────────
```

Then:

- If **all checks passed**: print `All checks passed.`
- If **any check failed**: print `One or more checks failed - see lines marked ✗ above.`

Missing MCPs are hard failures. Do not summarise them as warnings or caveats;
they must appear as ✗ lines.
2 changes: 1 addition & 1 deletion apps/claude-code/unic-spec-review/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "unic-spec-review",
"version": "0.1.1",
"version": "0.1.2",
"private": true,
"license": "LGPL-3.0-or-later",
"type": "module",
Expand Down
51 changes: 47 additions & 4 deletions apps/claude-code/unic-spec-review/scripts/lib/args.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
// Copyright © 2026 Unic

/**
* args.mjs - parse /review-spec command arguments.
* args.mjs - CLI argument parsers for unic-spec-review.
*
* Accepts a raw argument string or a pre-split argv array.
* Tokens that parse as valid URLs go into `urls`; `--post` sets `post: true`;
* other flags and unrecognised tokens are silently ignored.
* - `parseReviewSpecArgs`: accepts a raw string or argv array; extracts http(s)
* URLs and the `--post` flag (for the /review-spec command).
* - `parseArgs`: key=value / key value flag parser for setup scripts;
* throws on a flag with no value rather than silently dropping it.
*/

/**
Expand Down Expand Up @@ -38,3 +39,45 @@ export function parseReviewSpecArgs(input) {
}
return { urls, post }
}

/**
* Shared CLI argument parser for setup scripts.
*
* Accepts both `--key=value` and `--key value` forms. Bare positional args
* are ignored. A `--flag` with no following value (last arg, or followed by
* another `--flag`) throws - the previous silent-drop behaviour produced
* misleading "X is required" errors when the user actually did pass the flag.
*
* Boolean flags (presence-only, no value) must be declared in `options.booleanFlags`.
* They are recorded as `''` (empty string) when present so callers can use `'key' in result`.
*
* @param {string[]} args
* @param {{ booleanFlags?: Set<string> }} [options]
* @returns {Record<string, string>}
*/
export function parseArgs(args, options = {}) {
const booleans = options.booleanFlags ?? new Set()
/** @type {Record<string, string>} */
const result = {}
for (let i = 0; i < args.length; i++) {
const m = args[i].match(/^--([^=]+)=(.*)$/)
if (m) {
result[m[1]] = m[2]
continue
}
if (args[i].startsWith('--')) {
const key = args[i].slice(2)
if (booleans.has(key)) {
result[key] = ''
continue
}
const next = args[i + 1]
if (next === undefined || next.startsWith('--')) {
throw new Error(`${args[i]} requires a value`)
}
result[key] = next
i++
}
}
return result
}
119 changes: 119 additions & 0 deletions apps/claude-code/unic-spec-review/scripts/setup-confluence.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/usr/bin/env node
// SPDX-License-Identifier: LGPL-3.0-or-later
// @ts-check
// Copyright © 2026 Unic

/**
* setup-confluence.mjs - write ~/.unic-confluence.json with the user's
* Confluence credentials. Pure file-writer: values arrive as CLI args; the
* conversational prompting happens in commands/setup-confluence.md.
*/

import {
chmodSync as realChmod,
existsSync as realExistsSync,
readFileSync as realReadFile,
renameSync as realRename,
writeFileSync as realWriteFile,
} from 'node:fs'
import os from 'node:os'
import { join } from 'node:path'
import { pathToFileURL } from 'node:url'
import { parseArgs } from './lib/args.mjs'

/**
* @typedef {Object} WriteDeps
* @property {string} [homedir]
* @property {string} [platform]
* @property {(path: string) => boolean} [exists]
* @property {(path: string, encoding: BufferEncoding) => string} [readFile]
* @property {(path: string, data: string, encoding: BufferEncoding) => void} [writeFile]
* @property {(oldPath: string, newPath: string) => void} [rename]
* @property {(path: string, mode: number) => void} [chmod]
* @property {(message: string) => void} [warn]
*/

/**
* Write ~/.unic-confluence.json with the given credentials. Preserves any
* existing fields (such as a `jiraUrl` written by another tool that shares
* ~/.unic-confluence.json) so re-running to rotate a token does not silently
* drop data. If the existing file is unparseable
* the writer warns and overwrites; non-syntax read errors (EACCES, etc.)
* propagate so callers can surface them rather than silently losing data.
*
* @param {string} url
* @param {string} username
* @param {string} token
* @param {WriteDeps} [deps]
* @returns {{ path: string }}
*/
export function writeConfluenceCreds(url, username, token, deps = {}) {
const home = deps.homedir ?? os.homedir()
if (!home) throw new Error('could not determine home directory (HOME / USERPROFILE unset)')
const platform = deps.platform ?? process.platform
const exists = deps.exists ?? realExistsSync
const read = deps.readFile ?? realReadFile
const write = deps.writeFile ?? realWriteFile
const rename = deps.rename ?? realRename
const chmod = deps.chmod ?? realChmod
const warn = deps.warn ?? ((m) => process.stderr.write(`${m}\n`))

const path = join(home, '.unic-confluence.json')
let preserved = {}
if (exists(path)) {
const raw = read(path, 'utf8')
try {
const existing = JSON.parse(raw)
if (existing && typeof existing === 'object') preserved = existing
} catch (err) {
if (!(err instanceof SyntaxError)) throw err
warn(`${path} contains invalid JSON - overwriting (any prior jiraUrl will be lost).`)
}
Comment thread
orioltf marked this conversation as resolved.
}
const payload = { ...preserved, url, username, token }
const tmp = `${path}.tmp`
write(tmp, JSON.stringify(payload, null, 2), 'utf8')
if (platform === 'win32') {
warn(
`Windows detected - skipping chmod 600 on ${path}. Restrict file access manually, e.g.:\n icacls "${path}" /inheritance:r /grant:r "%USERNAME%:F"`
)
} else {
Comment thread
orioltf marked this conversation as resolved.
chmod(tmp, 0o600)
}
rename(tmp, path)
return { path }
}

/**
* True when CONFLUENCE_URL, CONFLUENCE_USER and CONFLUENCE_TOKEN are all set.
*
* @param {Record<string, string | undefined>} env
* @returns {boolean}
*/
export function isEnvConfigured(env) {
return Boolean(env.CONFLUENCE_URL && env.CONFLUENCE_USER && env.CONFLUENCE_TOKEN)
}

async function main() {
let args
try {
args = parseArgs(process.argv.slice(2))
} catch (err) {
process.stderr.write(`setup-confluence: ${err instanceof Error ? err.message : String(err)}\n`)
process.exit(1)
}
const { url, username, token } = args
if (!url || !username || !token) {
process.stderr.write('setup-confluence: --url, --username and --token are all required\n')
process.exit(1)
}
const { path } = writeConfluenceCreds(url, username, token)
process.stdout.write(`Written: ${path}\n`)
}

if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
main().catch((err) => {
process.stderr.write(`setup-confluence: unexpected error: ${err?.stack ?? err?.message ?? String(err)}\n`)
process.exit(1)
})
}
Loading
Loading