@picassohq/cli 0.0.0-stage → 1.0.2

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 (232) hide show
  1. package/agents/browser_agent.yaml +53 -0
  2. package/agents/code_reviewer.yaml +49 -0
  3. package/agents/codebase_investigator.yaml +70 -0
  4. package/agents/design_auditor.yaml +50 -0
  5. package/agents/devex_auditor.yaml +50 -0
  6. package/agents/doc_writer.yaml +54 -0
  7. package/agents/engineering_architect.yaml +51 -0
  8. package/agents/generalist.yaml +55 -0
  9. package/agents/migration_planner.yaml +51 -0
  10. package/agents/product_reviewer.yaml +48 -0
  11. package/agents/qa_operator.yaml +52 -0
  12. package/agents/release_engineer.yaml +50 -0
  13. package/agents/security_auditor.yaml +62 -0
  14. package/agents/test_writer.yaml +52 -0
  15. package/assets/first-light-lockup.png +0 -0
  16. package/assets/first-light-tagline.png +0 -0
  17. package/assets/house/README.md +26 -0
  18. package/assets/house/auraone-banner.png +0 -0
  19. package/assets/house/auraone-logo.png +0 -0
  20. package/assets/house/kiro-prism-banner.png +0 -0
  21. package/assets/house/kiro-prism-logo.png +0 -0
  22. package/assets/house/picasso-banner.png +0 -0
  23. package/assets/house/picasso-logo.png +0 -0
  24. package/assets/wordmark-app.png +0 -0
  25. package/assets/wordmark-tight.png +0 -0
  26. package/assets/wordmark.png +0 -0
  27. package/design/styles.css +1042 -0
  28. package/dist/build-info.json +37 -0
  29. package/dist/index.js +3062 -0
  30. package/goals/cli-hardening.yaml +40 -0
  31. package/goals/repo-maintenance.yaml +40 -0
  32. package/package.json +49 -4
  33. package/runtime/dsh/picasso-ecosystem.community.amendments.yml +24 -0
  34. package/runtime/dsh/picasso-ecosystem.community.json +185 -0
  35. package/runtime/dsh/picasso-ecosystem.community.patch.yml +40 -0
  36. package/runtime/dsh/picasso-ecosystem.cordis.patch.yml +143 -0
  37. package/runtime/dsh/picasso-isolation.patch.yml +25 -0
  38. package/runtime/dsh/picasso-providers.patch.yml +373 -0
  39. package/runtime/dsh/picasso-runtime.cordis.yml +738 -0
  40. package/runtime/dsh/picasso-sdk.patch.yml +204 -0
  41. package/runtime/engine-manifest.json +215 -0
  42. package/runtime/package.json +6 -0
  43. package/runtime/packages/picasso-cache-probe/cordis.patch.yml +5 -0
  44. package/runtime/packages/picasso-cache-probe/index.js +477 -0
  45. package/runtime/packages/picasso-cache-probe/package.json +38 -0
  46. package/runtime/packages/picasso-commands/cordis.patch.yml +4 -0
  47. package/runtime/packages/picasso-commands/fresh-review.js +573 -0
  48. package/runtime/packages/picasso-commands/index.js +497 -0
  49. package/runtime/packages/picasso-commands/package.json +28 -0
  50. package/runtime/packages/picasso-instructions/conflicts.js +115 -0
  51. package/runtime/packages/picasso-instructions/formats.js +145 -0
  52. package/runtime/packages/picasso-instructions/frontmatter.js +175 -0
  53. package/runtime/packages/picasso-instructions/glob.js +114 -0
  54. package/runtime/packages/picasso-instructions/globals.js +90 -0
  55. package/runtime/packages/picasso-instructions/imports.js +123 -0
  56. package/runtime/packages/picasso-instructions/index.js +326 -0
  57. package/runtime/packages/picasso-instructions/modes.js +64 -0
  58. package/runtime/packages/picasso-instructions/package.json +30 -0
  59. package/runtime/packages/picasso-instructions/parse.js +134 -0
  60. package/runtime/packages/picasso-instructions/report.js +161 -0
  61. package/runtime/packages/picasso-instructions/resolve.js +939 -0
  62. package/runtime/packages/picasso-instructions/scan.js +181 -0
  63. package/runtime/packages/picasso-instructions/settings.js +150 -0
  64. package/runtime/packages/picasso-instructions/skills.js +345 -0
  65. package/runtime/packages/picasso-lean-context/cordis.patch.yml +13 -0
  66. package/runtime/packages/picasso-lean-context/index.js +6280 -0
  67. package/runtime/packages/picasso-lean-context/package.json +26 -0
  68. package/runtime/packages/picasso-lean-context/read-image-recovery.js +306 -0
  69. package/runtime/packages/picasso-lean-context/timeline.js +418 -0
  70. package/runtime/packages/picasso-librarian/classify.js +146 -0
  71. package/runtime/packages/picasso-librarian/cordis.patch.yml +10 -0
  72. package/runtime/packages/picasso-librarian/index.js +878 -0
  73. package/runtime/packages/picasso-librarian/notes.js +159 -0
  74. package/runtime/packages/picasso-librarian/package.json +34 -0
  75. package/runtime/packages/picasso-librarian/state.js +478 -0
  76. package/runtime/packages/picasso-memory/index.js +1184 -0
  77. package/runtime/packages/picasso-memory/package.json +21 -0
  78. package/runtime/packages/picasso-model-router/connections.js +912 -0
  79. package/runtime/packages/picasso-model-router/cordis.patch.yml +17 -0
  80. package/runtime/packages/picasso-model-router/index.js +1083 -0
  81. package/runtime/packages/picasso-model-router/package.json +30 -0
  82. package/runtime/packages/picasso-options/cordis.patch.yml +4 -0
  83. package/runtime/packages/picasso-options/index.js +263 -0
  84. package/runtime/packages/picasso-options/package.json +28 -0
  85. package/runtime/packages/picasso-progress-reports/cordis.patch.yml +10 -0
  86. package/runtime/packages/picasso-progress-reports/index.js +267 -0
  87. package/runtime/packages/picasso-progress-reports/package.json +30 -0
  88. package/runtime/packages/picasso-progress-reports/report.js +235 -0
  89. package/runtime/packages/picasso-sdk-server/aside.js +142 -0
  90. package/runtime/packages/picasso-sdk-server/connections.js +38 -0
  91. package/runtime/packages/picasso-sdk-server/context-timeline.js +27 -0
  92. package/runtime/packages/picasso-sdk-server/egress-gate.js +520 -0
  93. package/runtime/packages/picasso-sdk-server/failure-policy.js +246 -0
  94. package/runtime/packages/picasso-sdk-server/file-input.js +169 -0
  95. package/runtime/packages/picasso-sdk-server/goal.js +131 -0
  96. package/runtime/packages/picasso-sdk-server/ignore-file.js +458 -0
  97. package/runtime/packages/picasso-sdk-server/ignore-plugin.js +12 -0
  98. package/runtime/packages/picasso-sdk-server/ignore-sandbox.js +122 -0
  99. package/runtime/packages/picasso-sdk-server/ignore-snapshot.js +131 -0
  100. package/runtime/packages/picasso-sdk-server/image-input.js +44 -0
  101. package/runtime/packages/picasso-sdk-server/index.js +891 -0
  102. package/runtime/packages/picasso-sdk-server/instructions.js +34 -0
  103. package/runtime/packages/picasso-sdk-server/jobs.js +113 -0
  104. package/runtime/packages/picasso-sdk-server/mcp-gate.js +51 -0
  105. package/runtime/packages/picasso-sdk-server/model-selection.js +162 -0
  106. package/runtime/packages/picasso-sdk-server/package.json +50 -0
  107. package/runtime/packages/picasso-sdk-server/picasso-records.js +50 -0
  108. package/runtime/packages/picasso-sdk-server/provider-reload.js +84 -0
  109. package/runtime/packages/picasso-sdk-server/queue.js +322 -0
  110. package/runtime/packages/picasso-sdk-server/requester.js +43 -0
  111. package/runtime/packages/picasso-sdk-server/rewind.js +108 -0
  112. package/runtime/packages/picasso-sdk-server/schedule.js +187 -0
  113. package/runtime/packages/picasso-sdk-server/session-grants.js +35 -0
  114. package/runtime/packages/picasso-sdk-server/session-state.js +118 -0
  115. package/runtime/packages/picasso-sdk-server/shell-paths.js +869 -0
  116. package/runtime/packages/picasso-sdk-server/stream-deltas.js +211 -0
  117. package/runtime/packages/picasso-sdk-server/team-tasks.js +451 -0
  118. package/runtime/packages/picasso-sdk-server/tool-output.js +128 -0
  119. package/runtime/packages/picasso-sdk-server/tools-list.js +51 -0
  120. package/runtime/packages/picasso-sdk-server/wave2-hooks.js +612 -0
  121. package/runtime/packages/picasso-sdk-server/workspace-archive.js +170 -0
  122. package/runtime/packages/picasso-sdk-server/workspace-restore.js +180 -0
  123. package/runtime/packages/picasso-web-search/backends.js +412 -0
  124. package/runtime/packages/picasso-web-search/config.js +121 -0
  125. package/runtime/packages/picasso-web-search/cordis.patch.yml +7 -0
  126. package/runtime/packages/picasso-web-search/failure.js +116 -0
  127. package/runtime/packages/picasso-web-search/format.js +42 -0
  128. package/runtime/packages/picasso-web-search/index.js +71 -0
  129. package/runtime/packages/picasso-web-search/package.json +38 -0
  130. package/runtime/packages/picasso-web-search/router.js +156 -0
  131. package/runtime/packages/picasso-x-reader/circle.js +324 -0
  132. package/runtime/packages/picasso-x-reader/command.js +169 -0
  133. package/runtime/packages/picasso-x-reader/cordis.patch.yml +8 -0
  134. package/runtime/packages/picasso-x-reader/index.js +170 -0
  135. package/runtime/packages/picasso-x-reader/package.json +39 -0
  136. package/runtime/packages/picasso-x-reader/read.js +370 -0
  137. package/runtime/packages/picasso-x-reader/rewrite.js +38 -0
  138. package/runtime/packages/picasso-x-reader/settings.js +131 -0
  139. package/runtime/packages/picasso-x-reader/urls.js +154 -0
  140. package/runtime/packages/picasso-x-reader/xmd.js +512 -0
  141. package/runtime/plugins/picasso-auth-bridge/index.js +380 -0
  142. package/runtime/plugins/picasso-auth-bridge/package.json +28 -0
  143. package/runtime/plugins/picasso-auto-approve/index.js +1003 -0
  144. package/runtime/plugins/picasso-auto-approve/package.json +28 -0
  145. package/runtime/plugins/picasso-browser/index.js +424 -0
  146. package/runtime/plugins/picasso-browser/package.json +28 -0
  147. package/runtime/plugins/picasso-checkpoints/evidence.js +210 -0
  148. package/runtime/plugins/picasso-checkpoints/index.js +885 -0
  149. package/runtime/plugins/picasso-checkpoints/package.json +29 -0
  150. package/runtime/plugins/picasso-commands/fresh-review.js +573 -0
  151. package/runtime/plugins/picasso-commands/index.js +497 -0
  152. package/runtime/plugins/picasso-commands/package.json +28 -0
  153. package/runtime/plugins/picasso-instructions/conflicts.js +115 -0
  154. package/runtime/plugins/picasso-instructions/formats.js +145 -0
  155. package/runtime/plugins/picasso-instructions/frontmatter.js +175 -0
  156. package/runtime/plugins/picasso-instructions/glob.js +114 -0
  157. package/runtime/plugins/picasso-instructions/globals.js +90 -0
  158. package/runtime/plugins/picasso-instructions/imports.js +123 -0
  159. package/runtime/plugins/picasso-instructions/index.js +326 -0
  160. package/runtime/plugins/picasso-instructions/modes.js +64 -0
  161. package/runtime/plugins/picasso-instructions/package.json +30 -0
  162. package/runtime/plugins/picasso-instructions/parse.js +134 -0
  163. package/runtime/plugins/picasso-instructions/report.js +161 -0
  164. package/runtime/plugins/picasso-instructions/resolve.js +939 -0
  165. package/runtime/plugins/picasso-instructions/scan.js +181 -0
  166. package/runtime/plugins/picasso-instructions/settings.js +150 -0
  167. package/runtime/plugins/picasso-instructions/skills.js +345 -0
  168. package/runtime/plugins/picasso-lean-context/index.js +6280 -0
  169. package/runtime/plugins/picasso-lean-context/package.json +26 -0
  170. package/runtime/plugins/picasso-lean-context/read-image-recovery.js +306 -0
  171. package/runtime/plugins/picasso-lean-context/timeline.js +418 -0
  172. package/runtime/plugins/picasso-librarian/classify.js +146 -0
  173. package/runtime/plugins/picasso-librarian/index.js +878 -0
  174. package/runtime/plugins/picasso-librarian/notes.js +159 -0
  175. package/runtime/plugins/picasso-librarian/package.json +34 -0
  176. package/runtime/plugins/picasso-librarian/state.js +478 -0
  177. package/runtime/plugins/picasso-lifecycle-hooks/index.js +186 -0
  178. package/runtime/plugins/picasso-lifecycle-hooks/package.json +25 -0
  179. package/runtime/plugins/picasso-mail/inbox.js +207 -0
  180. package/runtime/plugins/picasso-mail/index.js +293 -0
  181. package/runtime/plugins/picasso-mail/package.json +22 -0
  182. package/runtime/plugins/picasso-memory/index.js +1184 -0
  183. package/runtime/plugins/picasso-memory/package.json +21 -0
  184. package/runtime/plugins/picasso-model-router/connections.js +912 -0
  185. package/runtime/plugins/picasso-model-router/index.js +1083 -0
  186. package/runtime/plugins/picasso-model-router/package.json +30 -0
  187. package/runtime/plugins/picasso-options/index.js +263 -0
  188. package/runtime/plugins/picasso-options/package.json +28 -0
  189. package/runtime/plugins/picasso-progress-reports/index.js +267 -0
  190. package/runtime/plugins/picasso-progress-reports/package.json +30 -0
  191. package/runtime/plugins/picasso-progress-reports/report.js +235 -0
  192. package/runtime/plugins/picasso-provider-models/index.js +436 -0
  193. package/runtime/plugins/picasso-provider-models/package.json +28 -0
  194. package/runtime/plugins/picasso-repo-index/index.js +1850 -0
  195. package/runtime/plugins/picasso-repo-index/package.json +28 -0
  196. package/runtime/plugins/picasso-schedule-pause/index.js +344 -0
  197. package/runtime/plugins/picasso-schedule-pause/package.json +28 -0
  198. package/runtime/plugins/picasso-session-lifecycle/index.js +796 -0
  199. package/runtime/plugins/picasso-session-lifecycle/package.json +28 -0
  200. package/runtime/plugins/picasso-trackers/index.js +895 -0
  201. package/runtime/plugins/picasso-trackers/package.json +28 -0
  202. package/runtime/plugins/picasso-web-search/backends.js +412 -0
  203. package/runtime/plugins/picasso-web-search/config.js +121 -0
  204. package/runtime/plugins/picasso-web-search/failure.js +116 -0
  205. package/runtime/plugins/picasso-web-search/format.js +42 -0
  206. package/runtime/plugins/picasso-web-search/index.js +71 -0
  207. package/runtime/plugins/picasso-web-search/package.json +38 -0
  208. package/runtime/plugins/picasso-web-search/router.js +156 -0
  209. package/runtime/plugins/picasso-x-reader/circle.js +324 -0
  210. package/runtime/plugins/picasso-x-reader/command.js +169 -0
  211. package/runtime/plugins/picasso-x-reader/index.js +170 -0
  212. package/runtime/plugins/picasso-x-reader/package.json +39 -0
  213. package/runtime/plugins/picasso-x-reader/read.js +370 -0
  214. package/runtime/plugins/picasso-x-reader/rewrite.js +38 -0
  215. package/runtime/plugins/picasso-x-reader/settings.js +131 -0
  216. package/runtime/plugins/picasso-x-reader/urls.js +154 -0
  217. package/runtime/plugins/picasso-x-reader/xmd.js +512 -0
  218. package/runtime/relay/attachment-text.mjs +737 -0
  219. package/runtime/relay/companion/companion.css +126 -0
  220. package/runtime/relay/companion/companion.js +648 -0
  221. package/runtime/relay/companion/icon.svg +5 -0
  222. package/runtime/relay/companion/index.html +25 -0
  223. package/runtime/relay/companion/manifest.json +13 -0
  224. package/runtime/relay/companion/sw.js +41 -0
  225. package/runtime/relay/main.mjs +38580 -0
  226. package/runtime/relay/model-listing.mjs +614 -0
  227. package/runtime/relay/versions-routes.mjs +1400 -0
  228. package/runtime/verify-plugins.mjs +205 -0
  229. package/runtime-lock/package-lock.json +10779 -0
  230. package/runtime-lock/package.json +7 -0
  231. package/scripts/install-runtime.mjs +400 -0
  232. package/README.md +0 -3
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "picasso-runtime",
3
+ "private": true,
4
+ "dependencies": {
5
+ "@deepseek-ai/dsh": "0.2.2-rc.3"
6
+ }
7
+ }
@@ -0,0 +1,400 @@
1
+ #!/usr/bin/env node
2
+ // Postinstall for the published @picassohq/cli (AO-038.03, GO-LIVE-PRD Lane 1 D19/D20): make sure the pinned
3
+ // engine (@deepseek-ai/dsh, DSH_PINNED_VERSION below = packages/core contract.ts) is installed in
4
+ // ~/.picasso/dsh from the committed lock: <pkg>/runtime-lock/{package.json,package-lock.json} → `npm ci`.
5
+ // `<prefix>/bin/dsh` links to `../node_modules/.bin/dsh`, the path the CLI resolves first when it is the pin.
6
+ //
7
+ // Guards (install skipped, exit 0):
8
+ // * repo/workspace checkouts (pnpm-workspace.yaml two levels above the package and a workspace manifest);
9
+ // * PICASSO_SKIP_DSH_INSTALL=1;
10
+ // * CI (CI/CONTINUOUS_INTEGRATION) unless PICASSO_INSTALL_DSH=1;
11
+ // * an engine on PATH that already reports the pin (a different version on PATH never blocks the install).
12
+ //
13
+ // Every failure path is NON-FATAL: the CLI still installs and `picasso update runtime --install` retries.
14
+
15
+ import { spawn, spawnSync } from "node:child_process";
16
+ import { copyFileSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, symlinkSync } from "node:fs";
17
+ import { homedir } from "node:os";
18
+ import { basename, delimiter, dirname, join, resolve } from "node:path";
19
+ import { fileURLToPath } from "node:url";
20
+
21
+ export const DSH_PACKAGE = "@deepseek-ai/dsh";
22
+ export const DSH_PINNED_VERSION = "0.2.2-rc.3";
23
+
24
+ const scriptDir = dirname(fileURLToPath(import.meta.url));
25
+ const packageDir = join(scriptDir, "..");
26
+ const say = (msg) => process.stderr.write(`picasso postinstall: ${msg}\n`);
27
+
28
+ /** Default install prefix: `PICASSO_DSH_HOME` or `~/.picasso/dsh`. */
29
+ export function defaultRuntimePrefix(env = process.env) {
30
+ return env.PICASSO_DSH_HOME ?? join(env.HOME ?? homedir(), ".picasso", "dsh");
31
+ }
32
+
33
+ /** Version of the engine package installed under `prefixDir` (lock layout or `npm -g --prefix` layout). */
34
+ export function installedVersion(prefixDir) {
35
+ const candidates = [
36
+ join(prefixDir, "node_modules", ...DSH_PACKAGE.split("/"), "package.json"),
37
+ join(prefixDir, "lib", "node_modules", ...DSH_PACKAGE.split("/"), "package.json"),
38
+ ];
39
+ for (const candidate of candidates) {
40
+ try {
41
+ return JSON.parse(readFileSync(candidate, "utf8")).version ?? null;
42
+ } catch {
43
+ /* keep looking */
44
+ }
45
+ }
46
+ return null;
47
+ }
48
+
49
+ /** Version of the engine a bin path belongs to, read from its package.json (no subprocess). */
50
+ export function binPackageVersion(binPath) {
51
+ let dir;
52
+ try {
53
+ dir = dirname(realpathSync(binPath));
54
+ } catch {
55
+ return null;
56
+ }
57
+ for (let depth = 0; depth < 8; depth += 1) {
58
+ try {
59
+ const pkg = JSON.parse(readFileSync(join(dir, "package.json"), "utf8"));
60
+ if (pkg.name === DSH_PACKAGE) return typeof pkg.version === "string" ? pkg.version : null;
61
+ } catch {
62
+ /* not here */
63
+ }
64
+ const parent = dirname(dir);
65
+ if (parent === dir) break;
66
+ dir = parent;
67
+ }
68
+ return null;
69
+ }
70
+
71
+ /** Every `dsh` on PATH, in PATH order. */
72
+ export function pathCandidates(env = process.env) {
73
+ const names = process.platform === "win32" ? ["dsh.cmd", "dsh.exe", 'dsh'] : ['dsh'];
74
+ const found = [];
75
+ for (const dir of (env.PATH ?? "").split(delimiter)) {
76
+ if (dir.length === 0) continue;
77
+ for (const name of names) {
78
+ const candidate = join(dir, name);
79
+ if (existsSync(candidate) && !found.includes(candidate)) found.push(candidate);
80
+ }
81
+ }
82
+ return found;
83
+ }
84
+
85
+ /** The first PATH engine that reports the pin, if any. */
86
+ export function pinnedOnPath(env = process.env) {
87
+ return pathCandidates(env).find((candidate) => binPackageVersion(candidate) === DSH_PINNED_VERSION);
88
+ }
89
+
90
+ function npmArgv() {
91
+ // Inside a lifecycle script npm_execpath points at the running npm's cli entry; outside, use `npm` on PATH.
92
+ const execPath = process.env.npm_execpath;
93
+ if (execPath && execPath.endsWith(".js") && existsSync(execPath)) {
94
+ return { cmd: process.execPath, prefix: [execPath] };
95
+ }
96
+ return { cmd: process.platform === "win32" ? "npm.cmd" : "npm", prefix: [] };
97
+ }
98
+
99
+ function linkBin(prefixDir) {
100
+ const binDir = join(prefixDir, "bin");
101
+ mkdirSync(binDir, { recursive: true });
102
+ if (process.platform === "win32") {
103
+ for (const name of ["dsh", "dsh.cmd", "dsh.ps1"]) {
104
+ const from = join(prefixDir, "node_modules", ".bin", name);
105
+ if (existsSync(from)) copyFileSync(from, join(binDir, name));
106
+ }
107
+ return;
108
+ }
109
+ const link = join(binDir, "dsh");
110
+ try {
111
+ lstatSync(link);
112
+ rmSync(link, { force: true });
113
+ } catch {
114
+ /* nothing to replace */
115
+ }
116
+ symlinkSync(join("..", "node_modules", ".bin", "dsh"), link);
117
+ }
118
+
119
+ function prepareInstall(prefixDir, options) {
120
+ const lockDir = options.lockDir ?? join(packageDir, "runtime-lock");
121
+ for (const file of ["package.json", "package-lock.json"]) {
122
+ if (!existsSync(join(lockDir, file))) throw new Error(`runtime lock file missing: ${join(lockDir, file)}`);
123
+ }
124
+ mkdirSync(prefixDir, { recursive: true });
125
+ for (const file of ["package.json", "package-lock.json"]) copyFileSync(join(lockDir, file), join(prefixDir, file));
126
+ const { cmd, prefix } = npmArgv();
127
+ // Runs inside the prefix: npm 12 `ci --prefix <dir>` fails with "Missing: <dir>@ from lock file".
128
+ // `--ignore-scripts` matches the Mac engine install (the pin runs on its prebuilt binaries), and npm 12 blocks
129
+ // dependency install scripts in a project without an allowScripts policy anyway. `npm ci` checks every package
130
+ // against the lock's integrity hashes.
131
+ const args = [...prefix, "ci", "--omit=dev", "--ignore-scripts", "--no-audit", "--no-fund", "--loglevel=error", ...(options.npmArgs ?? [])];
132
+ // npm_config_global would turn `npm ci` into a global install when run from `npm i -g`'s lifecycle.
133
+ const env = { ...process.env };
134
+ for (const key of Object.keys(env)) {
135
+ if (/^npm_config_(global|prefix|location|local_prefix)$/iu.test(key)) delete env[key];
136
+ }
137
+ return { cmd, args, env };
138
+ }
139
+
140
+ function finishInstall(prefixDir) {
141
+ linkBin(prefixDir);
142
+ const installed = installedVersion(prefixDir);
143
+ if (installed !== DSH_PINNED_VERSION) {
144
+ throw new Error(`installed version ${installed ?? "unknown"} != pinned ${DSH_PINNED_VERSION}`);
145
+ }
146
+ return installed;
147
+ }
148
+
149
+ /** Sibling dirs an install uses: `<prefix>.staging-<pid>-<n>` (built there) and `<prefix>.old-<pid>-<n>` (swapped out). */
150
+ function siblingDir(prefixDir, kind) {
151
+ return `${prefixDir}.${kind}-${process.pid}-${Date.now().toString(36)}`;
152
+ }
153
+
154
+ function pidAlive(pid) {
155
+ try {
156
+ process.kill(pid, 0);
157
+ return true;
158
+ } catch (error) {
159
+ return error?.code === "EPERM";
160
+ }
161
+ }
162
+
163
+ /** Removes staging/old siblings left by an install that was killed (its process is gone). */
164
+ export function removeAbandonedInstallDirs(prefixDir) {
165
+ const parent = dirname(prefixDir);
166
+ const pattern = new RegExp(`^${basename(prefixDir).replace(/[.*+?^${}()|[\]\\]/gu, "\\$&")}\\.(staging|old)-(\\d+)-`, "u");
167
+ let names = [];
168
+ try {
169
+ names = readdirSync(parent);
170
+ } catch {
171
+ return;
172
+ }
173
+ for (const name of names) {
174
+ const match = pattern.exec(name);
175
+ if (match === null || pidAlive(Number(match[2]))) continue;
176
+ rmSync(join(parent, name), { recursive: true, force: true });
177
+ }
178
+ }
179
+
180
+ /**
181
+ * Moves a finished, verified staging dir into `prefixDir`. The previous runtime is renamed aside first and only
182
+ * removed once the new one is in place; if the swap fails half way the previous one is put back.
183
+ */
184
+ function swapIntoPlace(stagingDir, prefixDir) {
185
+ const old = existsSync(prefixDir) ? siblingDir(prefixDir, "old") : undefined;
186
+ if (old !== undefined) renameSync(prefixDir, old);
187
+ try {
188
+ renameSync(stagingDir, prefixDir);
189
+ } catch (error) {
190
+ if (old !== undefined) renameSync(old, prefixDir);
191
+ throw error;
192
+ }
193
+ if (old !== undefined) rmSync(old, { recursive: true, force: true });
194
+ }
195
+
196
+ /** Builds in a staging sibling, verifies, then swaps; the previous runtime stays untouched until then. */
197
+ function stagedInstall(prefixDir, options, runNpm) {
198
+ mkdirSync(dirname(prefixDir), { recursive: true });
199
+ removeAbandonedInstallDirs(prefixDir);
200
+ const stagingDir = siblingDir(prefixDir, "staging");
201
+ const cleanup = () => rmSync(stagingDir, { recursive: true, force: true });
202
+ let prepared;
203
+ try {
204
+ prepared = prepareInstall(stagingDir, options);
205
+ } catch (error) {
206
+ cleanup();
207
+ return Promise.reject(error);
208
+ }
209
+ const finish = () => {
210
+ finishInstall(stagingDir);
211
+ swapIntoPlace(stagingDir, prefixDir);
212
+ return DSH_PINNED_VERSION;
213
+ };
214
+ return runNpm(prepared, stagingDir, cleanup).then(
215
+ () => {
216
+ try {
217
+ return finish();
218
+ } catch (error) {
219
+ cleanup();
220
+ throw error;
221
+ }
222
+ },
223
+ (error) => {
224
+ cleanup();
225
+ throw error;
226
+ },
227
+ );
228
+ }
229
+
230
+ /**
231
+ * Install the pinned engine into `prefixDir` from the lock in `lockDir` (default `<pkg>/runtime-lock`).
232
+ * Throws on failure; returns the installed version. Used by the postinstall and `picasso update runtime --install`.
233
+ * The install is built in a sibling staging dir and swapped in only after it verifies, so a failed or interrupted
234
+ * install leaves the runtime that was there before untouched.
235
+ */
236
+ export function installPinnedRuntime(prefixDir = defaultRuntimePrefix(), options = {}) {
237
+ mkdirSync(dirname(prefixDir), { recursive: true });
238
+ removeAbandonedInstallDirs(prefixDir);
239
+ const stagingDir = siblingDir(prefixDir, "staging");
240
+ try {
241
+ const { cmd, args, env } = prepareInstall(stagingDir, options);
242
+ const result = spawnSync(cmd, args, { cwd: stagingDir, stdio: ["ignore", "ignore", "inherit"], env });
243
+ if (result.status !== 0) throw new Error(`npm ci exited ${result.status ?? "unknown"}`);
244
+ finishInstall(stagingDir);
245
+ swapIntoPlace(stagingDir, prefixDir);
246
+ return DSH_PINNED_VERSION;
247
+ } finally {
248
+ rmSync(stagingDir, { recursive: true, force: true });
249
+ }
250
+ }
251
+
252
+ /**
253
+ * {@link installPinnedRuntime} without blocking the event loop and without writing to the terminal (the CLI's
254
+ * automatic startup install): npm's own error output is kept and its last line goes into the thrown error.
255
+ * `options.timeoutMs` stops a stuck install; `options.signal` aborts it (Ctrl-C). Either way npm is stopped, the
256
+ * staging dir is removed and the previous runtime is kept.
257
+ */
258
+ export function installPinnedRuntimeQuietly(prefixDir = defaultRuntimePrefix(), options = {}) {
259
+ return stagedInstall(prefixDir, options, (prepared, stagingDir, cleanup) =>
260
+ new Promise((resolvePromise, rejectPromise) => {
261
+ let stderr = "";
262
+ let settled = false;
263
+ const child = spawn(prepared.cmd, prepared.args, { cwd: stagingDir, stdio: ["ignore", "ignore", "pipe"], env: prepared.env });
264
+ const stop = (reason) => {
265
+ if (settled) return;
266
+ settled = true;
267
+ clearTimeout(timer);
268
+ options.signal?.removeEventListener?.("abort", onAbort);
269
+ child.kill("SIGTERM");
270
+ // Synchronous, so a caller that exits right after an abort leaves no staging dir behind.
271
+ cleanup();
272
+ rejectPromise(new Error(reason));
273
+ };
274
+ const onAbort = () => stop("the install was stopped");
275
+ const timer =
276
+ options.timeoutMs === undefined
277
+ ? undefined
278
+ : setTimeout(() => stop(`the install took longer than ${Math.round(options.timeoutMs / 1000)} s`), options.timeoutMs);
279
+ timer?.unref?.();
280
+ if (options.signal?.aborted === true) {
281
+ onAbort();
282
+ return;
283
+ }
284
+ options.signal?.addEventListener?.("abort", onAbort, { once: true });
285
+ child.stderr.setEncoding("utf8");
286
+ child.stderr.on("data", (chunk) => {
287
+ stderr = (stderr + chunk).slice(-4_000);
288
+ });
289
+ child.on("error", (error) => {
290
+ if (settled) return;
291
+ settled = true;
292
+ clearTimeout(timer);
293
+ options.signal?.removeEventListener?.("abort", onAbort);
294
+ rejectPromise(error);
295
+ });
296
+ child.on("close", (code) => {
297
+ if (settled) return;
298
+ settled = true;
299
+ clearTimeout(timer);
300
+ options.signal?.removeEventListener?.("abort", onAbort);
301
+ if (code !== 0) {
302
+ const last = stderr.trim().split("\n").filter((line) => line.trim().length > 0).at(-1);
303
+ rejectPromise(new Error(`npm ci exited ${code ?? "unknown"}${last === undefined ? "" : ` (${last.trim()})`}`));
304
+ return;
305
+ }
306
+ resolvePromise();
307
+ });
308
+ }),
309
+ );
310
+ }
311
+
312
+ // A workspace checkout iff a pnpm-workspace.yaml sits two dirs above the package AND the manifest
313
+ // itself still looks workspace-only (private:true or workspace:* ranges). The published tarball has
314
+ // "private" stripped and no workspace deps, so a consumer whose own project happens to use pnpm
315
+ // workspaces is NOT mistaken for a dev checkout.
316
+ function looksLikeWorkspaceCheckout() {
317
+ const wsMarker = join(packageDir, "..", "..", "pnpm-workspace.yaml");
318
+ if (!existsSync(wsMarker)) return false;
319
+ try {
320
+ const pkg = JSON.parse(readFileSync(join(packageDir, "package.json"), "utf8"));
321
+ if (pkg.private === true) return true;
322
+ return Object.values(pkg.dependencies ?? {}).some((range) => String(range).startsWith("workspace:"));
323
+ } catch {
324
+ return true; // unreadable manifest next to a workspace marker: treat as a checkout, stay out.
325
+ }
326
+ }
327
+
328
+ function checkPublishable() {
329
+ // prepublishOnly gate: refuse publishing the workspace package. The supported publish path is
330
+ // scripts/release/package-npm.sh, which packs the bundled stage — `npm publish <tarball>` never runs this hook.
331
+ const pkg = JSON.parse(readFileSync(join(packageDir, "package.json"), "utf8"));
332
+ const workspaceDeps = Object.entries(pkg.dependencies ?? {}).filter(([, range]) =>
333
+ String(range).startsWith("workspace:"),
334
+ );
335
+ if (pkg.private === true || (looksLikeWorkspaceCheckout() && workspaceDeps.length > 0)) {
336
+ process.stderr.write(
337
+ `refusing to publish the workspace copy of ${pkg.name}: ` +
338
+ `${workspaceDeps.length} dependency range(s) are workspace:* (${workspaceDeps
339
+ .map(([name]) => name)
340
+ .join(", ")}). ` +
341
+ `Publish via scripts/release/package-npm.sh --publish, which packs the bundled release stage.\n`,
342
+ );
343
+ process.exit(1);
344
+ }
345
+ say("publishable check ok (not a workspace manifest)");
346
+ }
347
+
348
+ function main() {
349
+ if (process.argv.includes("--check-publishable")) {
350
+ checkPublishable();
351
+ return;
352
+ }
353
+ if (looksLikeWorkspaceCheckout()) {
354
+ say("workspace checkout detected; skipping runtime install (dev flows manage the runtime themselves)");
355
+ return;
356
+ }
357
+ if (process.env.PICASSO_SKIP_DSH_INSTALL === "1") {
358
+ say("PICASSO_SKIP_DSH_INSTALL=1; skipping pinned runtime install");
359
+ return;
360
+ }
361
+ const inCi = process.env.CI === "true" || process.env.CONTINUOUS_INTEGRATION === "true";
362
+ if (inCi && process.env.PICASSO_INSTALL_DSH !== "1") {
363
+ say("CI detected; skipping runtime install (set PICASSO_INSTALL_DSH=1 to opt in)");
364
+ return;
365
+ }
366
+ const onPath = pinnedOnPath();
367
+ if (onPath !== undefined) {
368
+ say(`pinned runtime ${DSH_PINNED_VERSION} already on PATH (${onPath})`);
369
+ return;
370
+ }
371
+
372
+ const prefixDir = defaultRuntimePrefix();
373
+ if (installedVersion(prefixDir) === DSH_PINNED_VERSION && existsSync(join(prefixDir, "bin"))) {
374
+ say(`pinned runtime ${DSH_PINNED_VERSION} already present at ${prefixDir}`);
375
+ return;
376
+ }
377
+
378
+ try {
379
+ installPinnedRuntime(prefixDir);
380
+ say(`installed pinned runtime ${DSH_PINNED_VERSION} -> ${prefixDir}/bin`);
381
+ } catch (error) {
382
+ say(
383
+ `pinned runtime install failed (${error.message}); the CLI still installs — run ` +
384
+ `\`picasso update runtime --install\` for the pinned version or set PICASSO_DSH_RUNTIME_BIN.`,
385
+ );
386
+ }
387
+ }
388
+
389
+ // Compare real paths: Node resolves symlinks in import.meta.url but not in argv[1] (e.g. /tmp -> /private/tmp), so a
390
+ // plain comparison skips main() and exits 0. Inlined rather than importing scripts/lib/is-main-module.mjs because this
391
+ // file ships alone in the npm package.
392
+ function launchedDirectly() {
393
+ if (!process.argv[1]) return false;
394
+ try {
395
+ return realpathSync(fileURLToPath(import.meta.url)) === realpathSync(resolve(process.argv[1]));
396
+ } catch {
397
+ return false;
398
+ }
399
+ }
400
+ if (launchedDirectly()) main();
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.