pluidr 0.7.0 → 0.7.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.
Files changed (48) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +365 -365
  3. package/bin/pluidr.js +3 -3
  4. package/package.json +45 -45
  5. package/src/cli/commands/doctor.js +101 -101
  6. package/src/cli/commands/init.js +43 -43
  7. package/src/cli/commands/launch.js +46 -44
  8. package/src/cli/commands/uninstall.js +63 -63
  9. package/src/cli/commands/update.js +6 -6
  10. package/src/cli/index.js +57 -57
  11. package/src/cli/wizard/selectModelTier.js +40 -40
  12. package/src/core/agentPromptWriter.js +32 -32
  13. package/src/core/agentPromptWriter.test.js +56 -56
  14. package/src/core/backup.js +40 -40
  15. package/src/core/configBuilder.js +32 -32
  16. package/src/core/configBuilder.test.js +93 -93
  17. package/src/core/configWriter.js +10 -10
  18. package/src/core/identityHeader.js +8 -8
  19. package/src/core/paths.js +9 -9
  20. package/src/core/paths.test.js +21 -21
  21. package/src/core/pluginWriter.js +29 -29
  22. package/src/core/squeezeInstaller.js +161 -161
  23. package/src/core/squeezeInstaller.test.js +75 -75
  24. package/src/core/version.js +8 -8
  25. package/src/core/versionCheck.js +44 -35
  26. package/src/core/versionCheck.test.js +12 -2
  27. package/src/plugins/README.md +68 -68
  28. package/src/plugins/pluidr-squeeze.js +77 -77
  29. package/src/templates/agent-prompts/auditor.txt +20 -20
  30. package/src/templates/agent-prompts/coder.txt +87 -87
  31. package/src/templates/agent-prompts/compose-reporter.txt +55 -55
  32. package/src/templates/agent-prompts/composer.txt +430 -430
  33. package/src/templates/agent-prompts/debug-reporter.txt +65 -65
  34. package/src/templates/agent-prompts/debugger.txt +151 -151
  35. package/src/templates/agent-prompts/fixer.txt +66 -66
  36. package/src/templates/agent-prompts/hierarchy.txt +96 -96
  37. package/src/templates/agent-prompts/inspector.txt +79 -79
  38. package/src/templates/agent-prompts/patcher.txt +20 -20
  39. package/src/templates/agent-prompts/plan-checker.txt +45 -45
  40. package/src/templates/agent-prompts/plan-writer.txt +57 -57
  41. package/src/templates/agent-prompts/probe-reporter.txt +62 -62
  42. package/src/templates/agent-prompts/prober.txt +90 -90
  43. package/src/templates/agent-prompts/researcher.txt +48 -48
  44. package/src/templates/agent-prompts/reviewer.txt +57 -57
  45. package/src/templates/agent-prompts/tester.txt +66 -66
  46. package/src/templates/agent-prompts/tracer.txt +33 -33
  47. package/src/templates/model-defaults.json +73 -73
  48. package/src/templates/opencode.config.json +481 -481
@@ -1,161 +1,161 @@
1
- import { execFileSync } from "node:child_process"
2
- import { chmodSync, mkdirSync, existsSync, writeFileSync, unlinkSync, readFileSync, renameSync } from "node:fs"
3
- import { extname, join, resolve, dirname } from "node:path"
4
- import { fileURLToPath } from "node:url"
5
- import { createHash } from "node:crypto"
6
- import { getConfigDir } from "./paths.js"
7
-
8
- const __dirname = dirname(fileURLToPath(import.meta.url))
9
-
10
- // Local binary name — friendlier than the upstream "rtk" name
11
- const BIN_NAME = process.platform === "win32" ? "squeeze.exe" : "squeeze"
12
- // Name of the binary inside the downloaded archive (upstream uses "rtk")
13
- const RTK_BIN_NAME = process.platform === "win32" ? "rtk.exe" : "rtk"
14
- export const ASSETS = {
15
- "darwin-arm64": "rtk-aarch64-apple-darwin.tar.gz",
16
- "darwin-x64": "rtk-x86_64-apple-darwin.tar.gz",
17
- "linux-x64": "rtk-x86_64-unknown-linux-musl.tar.gz",
18
- "linux-arm64": "rtk-aarch64-unknown-linux-gnu.tar.gz",
19
- "win32-x64": "rtk-x86_64-pc-windows-msvc.zip",
20
- }
21
- const RTK_RELEASE_BASE = "https://github.com/rtk-ai/rtk/releases/latest/download"
22
-
23
- export function platformAsset() {
24
- const key = `${process.platform}-${process.arch}`
25
- return ASSETS[key] ?? null
26
- }
27
-
28
- export function validatePath(path) {
29
- if (!/^[a-zA-Z0-9_\-\.\:\/\\]+$/.test(path)) {
30
- throw new Error(`Invalid path: "${path}" contains unsafe characters`)
31
- }
32
- }
33
-
34
- export function findSqueezePath() {
35
- try {
36
- const [cmd, ...args] =
37
- process.platform === "win32" ? ["where", "squeeze"] : ["which", "squeeze"]
38
- return execFileSync(cmd, args, { stdio: "pipe" })
39
- .toString()
40
- .trim()
41
- .split(/\r?\n/)[0]
42
- } catch {
43
- return null
44
- }
45
- }
46
-
47
- function extract(archivePath, destDir) {
48
- validatePath(archivePath)
49
- validatePath(destDir)
50
- const isZip = extname(archivePath) === ".zip"
51
-
52
- if (isZip && process.platform === "win32") {
53
- execFileSync("powershell", [
54
- "-NoProfile",
55
- "-Command",
56
- "Expand-Archive",
57
- "-LiteralPath", archivePath,
58
- "-DestinationPath", destDir,
59
- "-Force"
60
- ], { stdio: "ignore" })
61
- } else {
62
- execFileSync("tar", ["-xzf", archivePath, "-C", destDir], { stdio: "ignore" })
63
- }
64
- }
65
-
66
- function verifyChecksum(buffer, assetName) {
67
- const checksumsPath = resolve(__dirname, "../templates/rtk-checksums.json")
68
- let checksums
69
- try {
70
- checksums = JSON.parse(readFileSync(checksumsPath, "utf-8"))
71
- } catch {
72
- // No checksums file — skip verification
73
- return
74
- }
75
-
76
- const expectedHash = checksums[assetName]
77
- if (expectedHash === null || expectedHash === undefined) {
78
- // Hash not yet populated for this platform — silently skip
79
- return
80
- }
81
-
82
- const computed = createHash("sha256").update(buffer).digest("hex")
83
- if (computed !== expectedHash) {
84
- throw new Error(
85
- `SHA256 mismatch for ${assetName}\n expected: ${expectedHash}\n computed: ${computed}`
86
- )
87
- }
88
- }
89
-
90
- export async function installSqueeze() {
91
- let rtkPath = findSqueezePath()
92
-
93
- if (!rtkPath) {
94
- // Not on PATH — download it to the managed location
95
- const asset = platformAsset()
96
- if (!asset) {
97
- console.warn("⚠ Squeeze: unsupported platform — squeeze binary unavailable")
98
- return
99
- }
100
-
101
- const binDir = join(getConfigDir(), "bin")
102
- mkdirSync(binDir, { recursive: true })
103
-
104
- const url = `${RTK_RELEASE_BASE}/${asset}`
105
- const archivePath = join(binDir, asset)
106
-
107
- try {
108
- let response
109
- for (let attempt = 1; attempt <= 3; attempt++) {
110
- try {
111
- response = await fetch(url)
112
- if (!response.ok) throw new Error(`HTTP ${response.status}`)
113
- break
114
- } catch (err) {
115
- if (attempt < 3) {
116
- // Retry on any error (network, HTTP, etc.) with exponential backoff
117
- const delay = Math.pow(2, attempt - 1) * 1000
118
- await new Promise(r => setTimeout(r, delay))
119
- continue
120
- }
121
- throw err
122
- }
123
- }
124
-
125
- const buffer = Buffer.from(await response.arrayBuffer())
126
- verifyChecksum(buffer, asset)
127
- writeFileSync(archivePath, buffer)
128
-
129
- extract(archivePath, binDir)
130
-
131
- try { unlinkSync(archivePath) } catch {}
132
-
133
- // Archive contains "rtk"/"rtk.exe" — rename to local BIN_NAME ("squeeze")
134
- const extracted = join(binDir, RTK_BIN_NAME)
135
- rtkPath = join(binDir, BIN_NAME)
136
- if (existsSync(extracted) && extracted !== rtkPath) {
137
- renameSync(extracted, rtkPath)
138
- }
139
-
140
- if (process.platform !== "win32" && existsSync(rtkPath)) {
141
- chmodSync(rtkPath, 0o755)
142
- }
143
-
144
- // Verify that the downloaded binary is executable and runs on this platform
145
- try {
146
- execFileSync(rtkPath, ["--help"], { stdio: "ignore" })
147
- } catch (err) {
148
- // If it throws because of execution format or permissions (e.g. ENOEXEC, EACCES, ENOENT)
149
- if (err.code === "ENOEXEC" || err.code === "EACCES" || err.code === "ENOENT") {
150
- try { unlinkSync(rtkPath) } catch {}
151
- throw new Error(`Downloaded binary is not executable on this platform: ${err.message}`)
152
- }
153
- // If it ran but exited with non-zero (like returning exit code 1 for --help), that's fine, it means it is executable!
154
- }
155
- } catch (err) {
156
- try { unlinkSync(archivePath) } catch {}
157
- console.warn(`⚠ Squeeze: installation failed (${err.message}) — squeeze plugin disabled`)
158
- return
159
- }
160
- }
161
- }
1
+ import { execFileSync } from "node:child_process"
2
+ import { chmodSync, mkdirSync, existsSync, writeFileSync, unlinkSync, readFileSync, renameSync } from "node:fs"
3
+ import { extname, join, resolve, dirname } from "node:path"
4
+ import { fileURLToPath } from "node:url"
5
+ import { createHash } from "node:crypto"
6
+ import { getConfigDir } from "./paths.js"
7
+
8
+ const __dirname = dirname(fileURLToPath(import.meta.url))
9
+
10
+ // Local binary name — friendlier than the upstream "rtk" name
11
+ const BIN_NAME = process.platform === "win32" ? "squeeze.exe" : "squeeze"
12
+ // Name of the binary inside the downloaded archive (upstream uses "rtk")
13
+ const RTK_BIN_NAME = process.platform === "win32" ? "rtk.exe" : "rtk"
14
+ export const ASSETS = {
15
+ "darwin-arm64": "rtk-aarch64-apple-darwin.tar.gz",
16
+ "darwin-x64": "rtk-x86_64-apple-darwin.tar.gz",
17
+ "linux-x64": "rtk-x86_64-unknown-linux-musl.tar.gz",
18
+ "linux-arm64": "rtk-aarch64-unknown-linux-gnu.tar.gz",
19
+ "win32-x64": "rtk-x86_64-pc-windows-msvc.zip",
20
+ }
21
+ const RTK_RELEASE_BASE = "https://github.com/rtk-ai/rtk/releases/latest/download"
22
+
23
+ export function platformAsset() {
24
+ const key = `${process.platform}-${process.arch}`
25
+ return ASSETS[key] ?? null
26
+ }
27
+
28
+ export function validatePath(path) {
29
+ if (!/^[a-zA-Z0-9_\-\.\:\/\\]+$/.test(path)) {
30
+ throw new Error(`Invalid path: "${path}" contains unsafe characters`)
31
+ }
32
+ }
33
+
34
+ export function findSqueezePath() {
35
+ try {
36
+ const [cmd, ...args] =
37
+ process.platform === "win32" ? ["where", "squeeze"] : ["which", "squeeze"]
38
+ return execFileSync(cmd, args, { stdio: "pipe" })
39
+ .toString()
40
+ .trim()
41
+ .split(/\r?\n/)[0]
42
+ } catch {
43
+ return null
44
+ }
45
+ }
46
+
47
+ function extract(archivePath, destDir) {
48
+ validatePath(archivePath)
49
+ validatePath(destDir)
50
+ const isZip = extname(archivePath) === ".zip"
51
+
52
+ if (isZip && process.platform === "win32") {
53
+ execFileSync("powershell", [
54
+ "-NoProfile",
55
+ "-Command",
56
+ "Expand-Archive",
57
+ "-LiteralPath", archivePath,
58
+ "-DestinationPath", destDir,
59
+ "-Force"
60
+ ], { stdio: "ignore" })
61
+ } else {
62
+ execFileSync("tar", ["-xzf", archivePath, "-C", destDir], { stdio: "ignore" })
63
+ }
64
+ }
65
+
66
+ function verifyChecksum(buffer, assetName) {
67
+ const checksumsPath = resolve(__dirname, "../templates/rtk-checksums.json")
68
+ let checksums
69
+ try {
70
+ checksums = JSON.parse(readFileSync(checksumsPath, "utf-8"))
71
+ } catch {
72
+ // No checksums file — skip verification
73
+ return
74
+ }
75
+
76
+ const expectedHash = checksums[assetName]
77
+ if (expectedHash === null || expectedHash === undefined) {
78
+ // Hash not yet populated for this platform — silently skip
79
+ return
80
+ }
81
+
82
+ const computed = createHash("sha256").update(buffer).digest("hex")
83
+ if (computed !== expectedHash) {
84
+ throw new Error(
85
+ `SHA256 mismatch for ${assetName}\n expected: ${expectedHash}\n computed: ${computed}`
86
+ )
87
+ }
88
+ }
89
+
90
+ export async function installSqueeze() {
91
+ let rtkPath = findSqueezePath()
92
+
93
+ if (!rtkPath) {
94
+ // Not on PATH — download it to the managed location
95
+ const asset = platformAsset()
96
+ if (!asset) {
97
+ console.warn("⚠ Squeeze: unsupported platform — squeeze binary unavailable")
98
+ return
99
+ }
100
+
101
+ const binDir = join(getConfigDir(), "bin")
102
+ mkdirSync(binDir, { recursive: true })
103
+
104
+ const url = `${RTK_RELEASE_BASE}/${asset}`
105
+ const archivePath = join(binDir, asset)
106
+
107
+ try {
108
+ let response
109
+ for (let attempt = 1; attempt <= 3; attempt++) {
110
+ try {
111
+ response = await fetch(url)
112
+ if (!response.ok) throw new Error(`HTTP ${response.status}`)
113
+ break
114
+ } catch (err) {
115
+ if (attempt < 3) {
116
+ // Retry on any error (network, HTTP, etc.) with exponential backoff
117
+ const delay = Math.pow(2, attempt - 1) * 1000
118
+ await new Promise(r => setTimeout(r, delay))
119
+ continue
120
+ }
121
+ throw err
122
+ }
123
+ }
124
+
125
+ const buffer = Buffer.from(await response.arrayBuffer())
126
+ verifyChecksum(buffer, asset)
127
+ writeFileSync(archivePath, buffer)
128
+
129
+ extract(archivePath, binDir)
130
+
131
+ try { unlinkSync(archivePath) } catch {}
132
+
133
+ // Archive contains "rtk"/"rtk.exe" — rename to local BIN_NAME ("squeeze")
134
+ const extracted = join(binDir, RTK_BIN_NAME)
135
+ rtkPath = join(binDir, BIN_NAME)
136
+ if (existsSync(extracted) && extracted !== rtkPath) {
137
+ renameSync(extracted, rtkPath)
138
+ }
139
+
140
+ if (process.platform !== "win32" && existsSync(rtkPath)) {
141
+ chmodSync(rtkPath, 0o755)
142
+ }
143
+
144
+ // Verify that the downloaded binary is executable and runs on this platform
145
+ try {
146
+ execFileSync(rtkPath, ["--help"], { stdio: "ignore" })
147
+ } catch (err) {
148
+ // If it throws because of execution format or permissions (e.g. ENOEXEC, EACCES, ENOENT)
149
+ if (err.code === "ENOEXEC" || err.code === "EACCES" || err.code === "ENOENT") {
150
+ try { unlinkSync(rtkPath) } catch {}
151
+ throw new Error(`Downloaded binary is not executable on this platform: ${err.message}`)
152
+ }
153
+ // If it ran but exited with non-zero (like returning exit code 1 for --help), that's fine, it means it is executable!
154
+ }
155
+ } catch (err) {
156
+ try { unlinkSync(archivePath) } catch {}
157
+ console.warn(`⚠ Squeeze: installation failed (${err.message}) — squeeze plugin disabled`)
158
+ return
159
+ }
160
+ }
161
+ }
@@ -1,75 +1,75 @@
1
- import { describe, it } from "node:test"
2
- import assert from "node:assert"
3
- import { platformAsset, validatePath, findSqueezePath, ASSETS } from "./squeezeInstaller.js"
4
-
5
- describe("platformAsset", () => {
6
- it("returns a string or null for current platform", () => {
7
- const result = platformAsset()
8
- // On a supported platform: string; on unsupported: null
9
- assert.ok(result === null || typeof result === "string")
10
- })
11
-
12
- it("returns known asset names for mapped platforms", () => {
13
- // Verify the ASSETS map has entries for all known platform combos
14
- const knownCombos = [
15
- { plat: "darwin", arch: "arm64" },
16
- { plat: "darwin", arch: "x64" },
17
- { plat: "linux", arch: "x64" },
18
- { plat: "linux", arch: "arm64" },
19
- { plat: "win32", arch: "x64" },
20
- ]
21
- for (const { plat, arch } of knownCombos) {
22
- const key = `${plat}-${arch}`
23
- const asset = ASSETS[key]
24
- assert.ok(asset, `ASSETS map should have entry for ${key}`)
25
- assert.ok(asset.endsWith(".tar.gz") || asset.endsWith(".zip"),
26
- `Asset "${asset}" should end with .tar.gz or .zip`)
27
- }
28
- })
29
- })
30
-
31
- describe("validatePath", () => {
32
- it("accepts simple relative paths", () => {
33
- assert.doesNotThrow(() => validatePath("foo/bar"))
34
- })
35
-
36
- it("accepts absolute POSIX paths", () => {
37
- assert.doesNotThrow(() => validatePath("/home/user/.config"))
38
- })
39
-
40
- it("accepts absolute Windows paths", () => {
41
- assert.doesNotThrow(() => validatePath("C:\\Users\\test"))
42
- })
43
-
44
- it("accepts paths with dots and dashes", () => {
45
- assert.doesNotThrow(() => validatePath("./dir/file-name.ext"))
46
- })
47
-
48
- it("allows .. in paths (shell metacharacter check only, not path traversal)", () => {
49
- assert.doesNotThrow(() => validatePath("../evil"))
50
- })
51
-
52
- it("rejects paths with semicolons", () => {
53
- assert.throws(() => validatePath("foo;rm -rf /"), /unsafe characters/)
54
- })
55
-
56
- it("rejects paths with backticks", () => {
57
- assert.throws(() => validatePath("foo`id`"), /unsafe characters/)
58
- })
59
-
60
- it("rejects paths with dollar signs", () => {
61
- assert.throws(() => validatePath("foo$PATH"), /unsafe characters/)
62
- })
63
-
64
- it("rejects paths with pipe characters", () => {
65
- assert.throws(() => validatePath("foo|bar"), /unsafe characters/)
66
- })
67
- })
68
-
69
- describe("findSqueezePath", () => {
70
- it("returns null when squeeze is not available on PATH", () => {
71
- const result = findSqueezePath()
72
- // Either null (not on PATH) or a non-empty string (found)
73
- assert.ok(result === null || typeof result === "string")
74
- })
75
- })
1
+ import { describe, it } from "node:test"
2
+ import assert from "node:assert"
3
+ import { platformAsset, validatePath, findSqueezePath, ASSETS } from "./squeezeInstaller.js"
4
+
5
+ describe("platformAsset", () => {
6
+ it("returns a string or null for current platform", () => {
7
+ const result = platformAsset()
8
+ // On a supported platform: string; on unsupported: null
9
+ assert.ok(result === null || typeof result === "string")
10
+ })
11
+
12
+ it("returns known asset names for mapped platforms", () => {
13
+ // Verify the ASSETS map has entries for all known platform combos
14
+ const knownCombos = [
15
+ { plat: "darwin", arch: "arm64" },
16
+ { plat: "darwin", arch: "x64" },
17
+ { plat: "linux", arch: "x64" },
18
+ { plat: "linux", arch: "arm64" },
19
+ { plat: "win32", arch: "x64" },
20
+ ]
21
+ for (const { plat, arch } of knownCombos) {
22
+ const key = `${plat}-${arch}`
23
+ const asset = ASSETS[key]
24
+ assert.ok(asset, `ASSETS map should have entry for ${key}`)
25
+ assert.ok(asset.endsWith(".tar.gz") || asset.endsWith(".zip"),
26
+ `Asset "${asset}" should end with .tar.gz or .zip`)
27
+ }
28
+ })
29
+ })
30
+
31
+ describe("validatePath", () => {
32
+ it("accepts simple relative paths", () => {
33
+ assert.doesNotThrow(() => validatePath("foo/bar"))
34
+ })
35
+
36
+ it("accepts absolute POSIX paths", () => {
37
+ assert.doesNotThrow(() => validatePath("/home/user/.config"))
38
+ })
39
+
40
+ it("accepts absolute Windows paths", () => {
41
+ assert.doesNotThrow(() => validatePath("C:\\Users\\test"))
42
+ })
43
+
44
+ it("accepts paths with dots and dashes", () => {
45
+ assert.doesNotThrow(() => validatePath("./dir/file-name.ext"))
46
+ })
47
+
48
+ it("allows .. in paths (shell metacharacter check only, not path traversal)", () => {
49
+ assert.doesNotThrow(() => validatePath("../evil"))
50
+ })
51
+
52
+ it("rejects paths with semicolons", () => {
53
+ assert.throws(() => validatePath("foo;rm -rf /"), /unsafe characters/)
54
+ })
55
+
56
+ it("rejects paths with backticks", () => {
57
+ assert.throws(() => validatePath("foo`id`"), /unsafe characters/)
58
+ })
59
+
60
+ it("rejects paths with dollar signs", () => {
61
+ assert.throws(() => validatePath("foo$PATH"), /unsafe characters/)
62
+ })
63
+
64
+ it("rejects paths with pipe characters", () => {
65
+ assert.throws(() => validatePath("foo|bar"), /unsafe characters/)
66
+ })
67
+ })
68
+
69
+ describe("findSqueezePath", () => {
70
+ it("returns null when squeeze is not available on PATH", () => {
71
+ const result = findSqueezePath()
72
+ // Either null (not on PATH) or a non-empty string (found)
73
+ assert.ok(result === null || typeof result === "string")
74
+ })
75
+ })
@@ -1,8 +1,8 @@
1
- import { readFileSync } from "node:fs"
2
- import { resolve, dirname } from "node:path"
3
- import { fileURLToPath } from "node:url"
4
-
5
- const __dirname = dirname(fileURLToPath(import.meta.url))
6
- export const version = JSON.parse(
7
- readFileSync(resolve(__dirname, "../../package.json"), "utf-8")
8
- ).version
1
+ import { readFileSync } from "node:fs"
2
+ import { resolve, dirname } from "node:path"
3
+ import { fileURLToPath } from "node:url"
4
+
5
+ const __dirname = dirname(fileURLToPath(import.meta.url))
6
+ export const version = JSON.parse(
7
+ readFileSync(resolve(__dirname, "../../package.json"), "utf-8")
8
+ ).version
@@ -1,35 +1,44 @@
1
- import { execFileSync } from "node:child_process"
2
- import { confirm, isCancel } from "@clack/prompts"
3
-
4
- export function fetchLatestVersion() {
5
- try {
6
- return execFileSync("npm", ["view", "pluidr", "version"], { stdio: "pipe" })
7
- .toString()
8
- .trim()
9
- } catch {
10
- return null
11
- }
12
- }
13
-
14
- export async function checkAndPromptUpdate(currentVersion) {
15
- process.stdout.write("Checking for updates... ")
16
-
17
- const latest = fetchLatestVersion()
18
- if (!latest) {
19
- console.log("⚠ Could not reach npm registry — skipping")
20
- return false
21
- }
22
-
23
- if (latest === currentVersion) {
24
- console.log(`✓ Up to date (${currentVersion})`)
25
- return false
26
- }
27
-
28
- console.log(`⚠ pluidr ${latest} available (you have ${currentVersion})`)
29
-
30
- const answer = await confirm({ message: "Update now?", initialValue: true })
31
- if (isCancel(answer) || !answer) return false
32
-
33
- execFileSync("npm", ["install", "-g", "pluidr"], { stdio: "inherit" })
34
- return true
35
- }
1
+ import { execFileSync, execSync } from "node:child_process"
2
+ import { confirm, isCancel } from "@clack/prompts"
3
+
4
+ export function fetchLatestVersion() {
5
+ try {
6
+ if (process.platform === "win32") {
7
+ return execSync("npm view pluidr version", { stdio: "pipe" })
8
+ .toString()
9
+ .trim()
10
+ }
11
+ return execFileSync("npm", ["view", "pluidr", "version"], { stdio: "pipe" })
12
+ .toString()
13
+ .trim()
14
+ } catch {
15
+ return null
16
+ }
17
+ }
18
+
19
+ export async function checkAndPromptUpdate(currentVersion) {
20
+ process.stdout.write("Checking for updates... ")
21
+
22
+ const latest = fetchLatestVersion()
23
+ if (!latest) {
24
+ console.log("⚠ Could not reach npm registry — skipping")
25
+ return false
26
+ }
27
+
28
+ if (latest === currentVersion) {
29
+ console.log(`✓ Up to date (${currentVersion})`)
30
+ return false
31
+ }
32
+
33
+ console.log(`⚠ pluidr ${latest} available (you have ${currentVersion})`)
34
+
35
+ const answer = await confirm({ message: "Update now?", initialValue: true })
36
+ if (isCancel(answer) || !answer) return false
37
+
38
+ if (process.platform === "win32") {
39
+ execSync("npm install -g pluidr", { stdio: "inherit" })
40
+ } else {
41
+ execFileSync("npm", ["install", "-g", "pluidr"], { stdio: "inherit" })
42
+ }
43
+ return true
44
+ }
@@ -1,6 +1,6 @@
1
1
  import { describe, it } from "node:test"
2
2
  import assert from "node:assert"
3
- import { execFileSync } from "node:child_process"
3
+ import { execFileSync, execSync } from "node:child_process"
4
4
  import { fetchLatestVersion } from "./versionCheck.js"
5
5
 
6
6
  describe("fetchLatestVersion", () => {
@@ -14,11 +14,21 @@ describe("fetchLatestVersion", () => {
14
14
  // Verify the try/catch in fetchLatestVersion swallows errors
15
15
  let caught = null
16
16
  try {
17
- execFileSync("npm", ["view", "__nonexistent_pkg_xyz_pluidr__", "version"], { stdio: "pipe" })
17
+ if (process.platform === "win32") {
18
+ execSync("npm view __nonexistent_pkg_xyz_pluidr__ version", { stdio: "pipe" })
19
+ } else {
20
+ execFileSync("npm", ["view", "__nonexistent_pkg_xyz_pluidr__", "version"], { stdio: "pipe" })
21
+ }
18
22
  } catch (err) {
19
23
  caught = err
20
24
  }
21
25
  // npm throws on unknown package — fetchLatestVersion handles this and returns null
22
26
  assert.ok(caught instanceof Error, "npm should throw for unknown package")
23
27
  })
28
+
29
+ it("uses execSync on Windows for npm, plain execFileSync on other platforms", () => {
30
+ // Confirm the platform guard evaluates correctly
31
+ const useSync = process.platform === "win32"
32
+ assert.strictEqual(typeof useSync, "boolean")
33
+ })
24
34
  })