@mmerterden/multi-agent-pipeline 23.3.0 → 23.4.0

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 (224) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/README.md +25 -6
  3. package/README.tr.md +26 -7
  4. package/docs/adr/0008-installer-modularization-and-secret-leak-defense.md +1 -1
  5. package/docs/adr/0010-own-code-graph.md +299 -8
  6. package/docs/architecture.md +3 -3
  7. package/docs/ecosystem.md +10 -10
  8. package/docs/engineering.md +4 -4
  9. package/docs/facts.json +8 -8
  10. package/docs/features.md +5 -5
  11. package/docs/performance.md +17 -17
  12. package/install/_dev-only-files.mjs +9 -0
  13. package/install/claude.mjs +28 -2
  14. package/install/templates/claude-hooks.json +32 -1
  15. package/manifest.json +223 -155
  16. package/package.json +11 -3
  17. package/pipeline/commands/multi-agent/SKILL.md +1 -1
  18. package/pipeline/commands/multi-agent/design-check/SKILL.md +2 -2
  19. package/pipeline/commands/multi-agent/diff-explain/SKILL.md +3 -3
  20. package/pipeline/commands/multi-agent/graph/SKILL.md +57 -24
  21. package/pipeline/commands/multi-agent/pair/SKILL.md +92 -0
  22. package/pipeline/commands/multi-agent/prune-prompts/SKILL.md +1 -1
  23. package/pipeline/commands/multi-agent/search/SKILL.md +7 -1
  24. package/pipeline/commands/multi-agent/status/SKILL.md +4 -0
  25. package/pipeline/commands/multi-agent/sync/SKILL.md +3 -3
  26. package/pipeline/contract/CHANGELOG.md +49 -0
  27. package/pipeline/contract/build.mjs +13 -1
  28. package/pipeline/contract/fixtures/error-invalid-request.json +1 -1
  29. package/pipeline/contract/fixtures/error-unauthorized.json +1 -1
  30. package/pipeline/contract/fixtures/runs-awaiting-question.json +4 -1
  31. package/pipeline/contract/fixtures/runs-empty.json +1 -1
  32. package/pipeline/contract/fixtures/runs-failed.json +4 -1
  33. package/pipeline/contract/fixtures/runs-old-schema.json +3 -0
  34. package/pipeline/contract/fixtures/runs-pr-opened-redacted.json +4 -1
  35. package/pipeline/contract/fixtures/runs-pr-opened.json +4 -1
  36. package/pipeline/contract/fixtures/runs-running.json +4 -1
  37. package/pipeline/contract/manifest.json +28 -15
  38. package/pipeline/contract/types/index.d.ts +55 -3
  39. package/pipeline/lib/detach-self.mjs +95 -0
  40. package/pipeline/lib/public-mcp-servers.mjs +33 -0
  41. package/pipeline/lib/rotated-log.mjs +93 -0
  42. package/pipeline/lib/tls-trust.mjs +29 -0
  43. package/pipeline/lib/usage-lifecycle.mjs +9 -11
  44. package/pipeline/lib/usage-names.generated.mjs +614 -0
  45. package/pipeline/lib/usage-run-key.mjs +235 -0
  46. package/pipeline/lib/usage-vocab.mjs +210 -0
  47. package/pipeline/multi-agent-refs/analysis/intake.md +2 -2
  48. package/pipeline/multi-agent-refs/analysis/render.md +1 -1
  49. package/pipeline/multi-agent-refs/channels/generator.md +4 -5
  50. package/pipeline/multi-agent-refs/cross-cli-contract.md +3 -3
  51. package/pipeline/multi-agent-refs/design-check/scope-and-ledger.md +1 -1
  52. package/pipeline/multi-agent-refs/features/code-graph.md +146 -11
  53. package/pipeline/multi-agent-refs/features/code-intelligence.md +16 -14
  54. package/pipeline/multi-agent-refs/features/dev-critic.md +7 -7
  55. package/pipeline/multi-agent-refs/features/model-fallback.md +6 -4
  56. package/pipeline/multi-agent-refs/features/remote-control.md +252 -0
  57. package/pipeline/multi-agent-refs/features/review-delta.md +1 -1
  58. package/pipeline/multi-agent-refs/features/review-file-set.md +3 -3
  59. package/pipeline/multi-agent-refs/features/review-multi-repo.md +1 -1
  60. package/pipeline/multi-agent-refs/features/session-brief.md +42 -0
  61. package/pipeline/multi-agent-refs/features/skill-conformance.md +3 -3
  62. package/pipeline/multi-agent-refs/features/usage-reporting.md +252 -24
  63. package/pipeline/multi-agent-refs/help/en.md +3 -2
  64. package/pipeline/multi-agent-refs/help/tr.md +3 -2
  65. package/pipeline/multi-agent-refs/knowledge.md +1 -1
  66. package/pipeline/multi-agent-refs/orchestrator/dispatcher.md +1 -1
  67. package/pipeline/multi-agent-refs/phases/operations.md +2 -2
  68. package/pipeline/multi-agent-refs/phases/phase-0-init.md +13 -12
  69. package/pipeline/multi-agent-refs/phases/phase-1-plan.md +4 -4
  70. package/pipeline/multi-agent-refs/phases/phase-3-review.md +2 -0
  71. package/pipeline/multi-agent-refs/phases/phase-5-report.md +1 -1
  72. package/pipeline/multi-agent-refs/platform-parity.md +2 -2
  73. package/pipeline/multi-agent-refs/wiki-capture.md +3 -17
  74. package/pipeline/office/index.html +1207 -233
  75. package/pipeline/office/toolkit.json +1 -1
  76. package/pipeline/rules/outside-the-pipeline.md +1 -1
  77. package/pipeline/schemas/activity.schema.json +23 -0
  78. package/pipeline/schemas/agent-state.schema.json +6 -1
  79. package/pipeline/schemas/code-graph-calls.schema.json +254 -0
  80. package/pipeline/schemas/code-graph-docs.schema.json +223 -0
  81. package/pipeline/schemas/code-graph-infra.schema.json +227 -0
  82. package/pipeline/schemas/code-graph.schema.json +2 -2
  83. package/pipeline/schemas/examples/design-check-config.json +27 -0
  84. package/pipeline/schemas/learning-curve.schema.json +67 -0
  85. package/pipeline/schemas/office-jobs.json +69 -2
  86. package/pipeline/schemas/office-jobs.schema.json +8 -1
  87. package/pipeline/schemas/phases.json +5 -0
  88. package/pipeline/schemas/phases.schema.json +8 -0
  89. package/pipeline/schemas/prefs.schema.json +46 -12
  90. package/pipeline/schemas/runs-index.schema.json +17 -0
  91. package/pipeline/schemas/toolkit-path-params.json +84 -8
  92. package/pipeline/scripts/README.md +1 -0
  93. package/pipeline/scripts/_code-graph.mjs +184 -103
  94. package/pipeline/scripts/_contract-core.mjs +1 -1
  95. package/pipeline/scripts/_contract-routes-office.mjs +21 -0
  96. package/pipeline/scripts/_diff-impact.mjs +21 -2
  97. package/pipeline/scripts/_graph-sidecars.mjs +372 -0
  98. package/pipeline/scripts/_http-post.mjs +103 -115
  99. package/pipeline/scripts/_safe-read.mjs +57 -0
  100. package/pipeline/scripts/_skill-practices.mjs +26 -0
  101. package/pipeline/scripts/_strip-code.mjs +380 -0
  102. package/pipeline/scripts/activity-snapshot.mjs +13 -1
  103. package/pipeline/scripts/aggregate-metrics.mjs +3 -5
  104. package/pipeline/scripts/call-graph/index.mjs +78 -0
  105. package/pipeline/scripts/call-graph/lang/cpp.mjs +308 -0
  106. package/pipeline/scripts/call-graph/lang/csharp.mjs +130 -0
  107. package/pipeline/scripts/call-graph/lang/go.mjs +303 -0
  108. package/pipeline/scripts/call-graph/lang/java.mjs +370 -0
  109. package/pipeline/scripts/call-graph/lang/kotlin.mjs +397 -0
  110. package/pipeline/scripts/call-graph/lang/python.mjs +399 -0
  111. package/pipeline/scripts/call-graph/lang/rust.mjs +345 -0
  112. package/pipeline/scripts/call-graph/lang/shared.mjs +230 -0
  113. package/pipeline/scripts/call-graph/lang/swift.mjs +432 -0
  114. package/pipeline/scripts/call-graph/lang/typescript.mjs +692 -0
  115. package/pipeline/scripts/call-graph/lex.mjs +396 -0
  116. package/pipeline/scripts/call-graph/platform.mjs +86 -0
  117. package/pipeline/scripts/call-graph/profiles.mjs +89 -0
  118. package/pipeline/scripts/call-graph/resolve.mjs +1125 -0
  119. package/pipeline/scripts/call-graph/scan.mjs +267 -0
  120. package/pipeline/scripts/code-graph-rules/android.json +7 -2
  121. package/pipeline/scripts/code-graph-rules/cpp.json +99 -0
  122. package/pipeline/scripts/code-graph-rules/csharp.json +102 -0
  123. package/pipeline/scripts/code-graph-rules/go.json +2 -1
  124. package/pipeline/scripts/code-graph-rules/ios.json +3 -1
  125. package/pipeline/scripts/code-graph-rules/java.json +76 -0
  126. package/pipeline/scripts/code-graph-rules/node.json +7 -2
  127. package/pipeline/scripts/code-graph-rules/python.json +6 -2
  128. package/pipeline/scripts/code-graph-rules/rust.json +105 -0
  129. package/pipeline/scripts/contract-server.mjs +1 -0
  130. package/pipeline/scripts/feedback-send.mjs +26 -26
  131. package/pipeline/scripts/gate-ledger.mjs +2 -1
  132. package/pipeline/scripts/gen-usage-names.mjs +124 -0
  133. package/pipeline/scripts/graph-affected.mjs +109 -20
  134. package/pipeline/scripts/graph-build.mjs +95 -15
  135. package/pipeline/scripts/graph-export.mjs +272 -0
  136. package/pipeline/scripts/graph-hint.mjs +15 -2
  137. package/pipeline/scripts/graph-query.mjs +305 -26
  138. package/pipeline/scripts/graph-report.mjs +187 -1
  139. package/pipeline/scripts/health-report.mjs +3 -4
  140. package/pipeline/scripts/infra/docs.mjs +317 -0
  141. package/pipeline/scripts/infra/extract.mjs +998 -0
  142. package/pipeline/scripts/infra/graph.mjs +245 -0
  143. package/pipeline/scripts/infra/yaml-lite.mjs +311 -0
  144. package/pipeline/scripts/job-launch.mjs +67 -2
  145. package/pipeline/scripts/learning-curve.mjs +288 -178
  146. package/pipeline/scripts/log-metric.sh +10 -1
  147. package/pipeline/scripts/note-agent-event.mjs +3 -4
  148. package/pipeline/scripts/note-command-use.mjs +333 -0
  149. package/pipeline/scripts/note-command-use.sh +126 -0
  150. package/pipeline/scripts/note-mcp-call.sh +89 -0
  151. package/pipeline/scripts/note-mcp-failure.mjs +272 -1
  152. package/pipeline/scripts/note-session.sh +62 -3
  153. package/pipeline/scripts/note-skill-use.mjs +58 -2
  154. package/pipeline/scripts/office-build.mjs +115 -1
  155. package/pipeline/scripts/office-memory.mjs +14 -5
  156. package/pipeline/scripts/pair.mjs +333 -0
  157. package/pipeline/scripts/pre-push-check.sh +1 -1
  158. package/pipeline/scripts/remote/cbor.mjs +128 -0
  159. package/pipeline/scripts/remote/contract.mjs +98 -0
  160. package/pipeline/scripts/remote/handler.mjs +317 -0
  161. package/pipeline/scripts/remote/handles.mjs +57 -0
  162. package/pipeline/scripts/remote/lifecycle.mjs +186 -0
  163. package/pipeline/scripts/remote/listener.mjs +204 -0
  164. package/pipeline/scripts/remote/lockout.mjs +103 -0
  165. package/pipeline/scripts/remote/nonces.mjs +61 -0
  166. package/pipeline/scripts/remote/pairing.mjs +519 -0
  167. package/pipeline/scripts/remote/qr-encode.mjs +459 -0
  168. package/pipeline/scripts/remote/store.mjs +188 -0
  169. package/pipeline/scripts/remote/transport.mjs +211 -0
  170. package/pipeline/scripts/remote/verbs.json +70 -0
  171. package/pipeline/scripts/remote/verbs.mjs +217 -0
  172. package/pipeline/scripts/remote/webauthn.mjs +169 -0
  173. package/pipeline/scripts/remote/wire.mjs +364 -0
  174. package/pipeline/scripts/remote-listener.mjs +83 -0
  175. package/pipeline/scripts/route-learn.mjs +4 -4
  176. package/pipeline/scripts/run-kill.mjs +1 -1
  177. package/pipeline/scripts/run-write.mjs +13 -2
  178. package/pipeline/scripts/runs-index.mjs +30 -3
  179. package/pipeline/scripts/search-logs.sh +9 -0
  180. package/pipeline/scripts/session-brief.mjs +458 -0
  181. package/pipeline/scripts/session-brief.sh +130 -0
  182. package/pipeline/scripts/test-gap-rules/cpp.json +25 -0
  183. package/pipeline/scripts/test-gap-rules/csharp.json +20 -0
  184. package/pipeline/scripts/test-gap-rules/java.json +20 -0
  185. package/pipeline/scripts/test-gap-rules/rust.json +14 -0
  186. package/pipeline/scripts/token-budget-report.mjs +3 -2
  187. package/pipeline/scripts/uninstall.mjs +29 -0
  188. package/pipeline/scripts/usage-access.mjs +16 -31
  189. package/pipeline/scripts/usage-health.mjs +31 -62
  190. package/pipeline/scripts/usage-register-beacon.mjs +11 -22
  191. package/pipeline/scripts/usage-register.mjs +39 -29
  192. package/pipeline/scripts/usage-report.mjs +579 -178
  193. package/pipeline/scripts/validate-code-graph.mjs +361 -111
  194. package/pipeline/scripts/write-state.mjs +39 -0
  195. package/pipeline/skills/.skill-manifest.json +21 -17
  196. package/pipeline/skills/.skills-index.json +13 -2
  197. package/pipeline/skills/shared/README.md +5 -4
  198. package/pipeline/skills/shared/core/multi-agent-design-check/SKILL.md +1 -1
  199. package/pipeline/skills/shared/core/multi-agent-diff-explain/SKILL.md +3 -3
  200. package/pipeline/skills/shared/core/multi-agent-graph/SKILL.md +55 -21
  201. package/pipeline/skills/shared/core/multi-agent-pair/SKILL.md +41 -0
  202. package/pipeline/skills/shared/core/multi-agent-prune-prompts/SKILL.md +1 -1
  203. package/pipeline/skills/shared/core/multi-agent-sync/SKILL.md +3 -3
  204. package/pipeline/skills/shared/external/app-store-optimization/SKILL.md +2 -3
  205. package/pipeline/skills/shared/external/app-store-optimization/references/keyword-research-methodology.md +2 -2
  206. package/pipeline/skills/shared/external/app-store-optimization/references/product-page-variants.md +2 -2
  207. package/pipeline/skills/shared/external/app-store-review/SKILL.md +11 -4
  208. package/pipeline/skills/shared/external/build-settings-audit/SKILL.md +1 -1
  209. package/pipeline/skills/shared/external/build-time-benchmark/SKILL.md +5 -5
  210. package/pipeline/skills/shared/external/build-time-fixes/SKILL.md +5 -5
  211. package/pipeline/skills/shared/external/build-time-optimizer/SKILL.md +6 -6
  212. package/pipeline/skills/shared/external/free-llm-apis/references/providers.md +1 -0
  213. package/pipeline/skills/shared/external/ios-coding-standard/references/STANDARD.md +2 -2
  214. package/pipeline/skills/shared/external/ios-haptics/references/core-haptics.md +1 -1
  215. package/pipeline/skills/shared/external/localization-reuse-map/references/publish-and-snapshot.md +1 -1
  216. package/pipeline/skills/shared/external/package-build-audit/SKILL.md +3 -3
  217. package/pipeline/skills/shared/external/reverse-engineer-own-app/SKILL.md +2 -3
  218. package/pipeline/skills/shared/external/swift-compile-hotspots/SKILL.md +2 -2
  219. package/pipeline/skills/shared/external/weatherkit/SKILL.md +5 -6
  220. package/pipeline/skills/skills-index.md +3 -2
  221. package/docs/FIGMA_PIPELINE.md +0 -137
  222. package/pipeline/lib/identifier-scan.mjs +0 -156
  223. package/pipeline/scripts/publish-staged.mjs +0 -324
  224. package/pipeline/skills/shared/external/ios-coding-standard/scripts/check_structure.py +0 -765
@@ -1,324 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * publish-staged.mjs - publish an npm package so that `latest` only ever
4
- * names a version the registry has been seen to serve and that installs.
5
- *
6
- * 1. pack `npm pack`, and the tarball's sha512 computed here; the two
7
- * must agree
8
- * 2. publish `npm publish <tarball> --tag candidate`. A version the
9
- * registry already holds with these bytes is a resumed
10
- * release and is not published again; with other bytes it
11
- * is refused
12
- * 3. visible poll the registry's packument until the version carries
13
- * the local integrity and the candidate tag names it. Read
14
- * over HTTP, never with `npm view`, whose cache answers
15
- * before the registry does. A different integrity fails at
16
- * once: waiting cannot fix it
17
- * 4. tarball download the tarball the registry serves; its sha512 must
18
- * be the local one
19
- * 5. install `npm install <that tarball>` into an empty temp project,
20
- * scripts off, and check the installed version and its bins
21
- * 6. smoke `--smoke "<cmd>"`, run in that project, when given
22
- * 7. promote `npm dist-tag add <name>@<version> latest`
23
- * 8. latest poll until the registry's `latest` names the version
24
- *
25
- * A failure before step 2 publishes nothing (exit 1). A failure after it
26
- * leaves the version on the candidate tag and `latest` where it was (exit 3);
27
- * running the same command again resumes from step 3.
28
- *
29
- * Usage:
30
- * publish-staged.mjs [--dir <package dir>] [--registry <url>] [--tag <dist-tag>]
31
- * [--npm <npm bin>] [--userconfig <npmrc>] [--smoke "<cmd>"]
32
- * [--timeout-s N] [--interval-ms N] [--dry-run] [--json]
33
- *
34
- * --tag never names `latest`: publishing there moves latest before any of the
35
- * checks run, so it is refused (exit 2) in any letter case.
36
- *
37
- * --registry defaults to https://registry.npmjs.org, --tag to candidate,
38
- * --timeout-s to 300 per poll and --interval-ms to 5000. --userconfig is
39
- * passed to every npm call, so a token kept in a temporary npmrc never
40
- * reaches argv. --dry-run stops after the pack.
41
- *
42
- * Exit: 0 promoted (or dry run packed); 1 nothing published; 2 usage error;
43
- * 3 published to the candidate tag, not promoted.
44
- */
45
-
46
- import { spawnSync } from "node:child_process";
47
- import { createHash } from "node:crypto";
48
- import { mkdirSync, mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
49
- import { tmpdir } from "node:os";
50
- import { join, resolve } from "node:path";
51
-
52
- import { ArgsError, parseArgs } from "../lib/args.mjs";
53
- import { exitOnHelp } from "../lib/cli-help.mjs";
54
- import { invokedDirectly } from "../lib/invoked-directly.mjs";
55
-
56
- exitOnHelp(import.meta.url);
57
-
58
- const DEFAULT_REGISTRY = "https://registry.npmjs.org";
59
-
60
- /** The packument URL of a package; a scope's slash is encoded. */
61
- export function packumentUrl(registry, name) {
62
- return `${String(registry).replace(/\/+$/, "")}/${String(name).replace("/", "%2f")}`;
63
- }
64
-
65
- /** Why a staging tag cannot be used, or null: `latest` is the tag only promote may move. */
66
- export function stagingTagRefusal(tag) {
67
- const t = String(tag ?? "").trim();
68
- if (!t) return "--tag needs a dist-tag name";
69
- if (t.toLowerCase() === "latest")
70
- return "--tag latest would move latest before the release is verified; stage on another tag";
71
- return null;
72
- }
73
-
74
- export const integrityOf = (buf) => `sha512-${createHash("sha512").update(buf).digest("base64")}`;
75
-
76
- const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
77
-
78
- function npmRunner(bin, userconfig) {
79
- const viaNode = /\.(mjs|cjs|js)$/.test(bin);
80
- return (args, cwd) => {
81
- const argv = [...args, ...(userconfig ? ["--userconfig", userconfig] : [])];
82
- const r = spawnSync(viaNode ? process.execPath : bin, viaNode ? [bin, ...argv] : argv, {
83
- cwd,
84
- encoding: "utf8",
85
- env: process.env,
86
- stdio: ["ignore", "pipe", "pipe"],
87
- timeout: 10 * 60 * 1000,
88
- });
89
- return {
90
- ok: r.status === 0,
91
- stdout: r.stdout || "",
92
- stderr: String(r.stderr || r.error?.message || "").trim(),
93
- };
94
- };
95
- }
96
-
97
- async function packument(registry, name) {
98
- const res = await fetch(packumentUrl(registry, name), {
99
- headers: { accept: "application/json" },
100
- });
101
- if (res.status === 404) return null;
102
- if (!res.ok) throw new Error(`registry answered ${res.status}`);
103
- return res.json();
104
- }
105
-
106
- async function poll(check, { timeoutMs, intervalMs }) {
107
- const end = Date.now() + timeoutMs;
108
- let last;
109
- for (;;) {
110
- try {
111
- last = await check();
112
- if (last.done) return last;
113
- } catch (e) {
114
- if (e.fatal) throw e;
115
- last = { done: false, detail: e.message };
116
- }
117
- if (Date.now() >= end) return { ...last, done: false, timedOut: true };
118
- await sleep(intervalMs);
119
- }
120
- }
121
-
122
- /**
123
- * The staged release. `steps` collects one {step, ok, detail} per step run.
124
- *
125
- * @returns {Promise<{code: number, report: object}>}
126
- */
127
- export async function publishStaged(opts) {
128
- const refusal = stagingTagRefusal(opts.tag);
129
- if (refusal) throw new ArgsError(refusal, { kind: "unexpected", token: "--tag" });
130
- const dir = resolve(opts.dir);
131
- const pkg = JSON.parse(readFileSync(join(dir, "package.json"), "utf8"));
132
- const npm = npmRunner(opts.npm, opts.userconfig);
133
- const steps = [];
134
- const report = {
135
- name: pkg.name,
136
- version: pkg.version,
137
- tag: opts.tag,
138
- registry: opts.registry,
139
- integrity: null,
140
- promoted: false,
141
- steps,
142
- };
143
- const work = mkdtempSync(join(tmpdir(), "publish-staged-"));
144
- const done = (code) => {
145
- rmSync(work, { recursive: true, force: true });
146
- return { code, report };
147
- };
148
- const step = (name, ok, detail) => {
149
- steps.push({ step: name, ok, detail });
150
- return ok;
151
- };
152
- const timing = { timeoutMs: opts.timeoutS * 1000, intervalMs: opts.intervalMs };
153
-
154
- const packed = npm(["pack", "--json", "--pack-destination", work], dir);
155
- let tarball;
156
- try {
157
- const entry = JSON.parse(packed.stdout)[0];
158
- tarball = join(work, entry.filename);
159
- const local = integrityOf(readFileSync(tarball));
160
- report.integrity = local;
161
- if (entry.integrity && entry.integrity !== local) {
162
- step("pack", false, `npm reported ${entry.integrity}, the tarball hashes to ${local}`);
163
- return done(1);
164
- }
165
- step("pack", true, `${entry.filename} ${statSync(tarball).size} bytes`);
166
- } catch (e) {
167
- step("pack", false, packed.ok ? `unreadable pack output: ${e.message}` : packed.stderr);
168
- return done(1);
169
- }
170
- if (opts.dryRun) return done(0);
171
-
172
- let existing;
173
- try {
174
- existing = (await packument(opts.registry, pkg.name))?.versions?.[pkg.version];
175
- } catch (e) {
176
- step("publish", false, `the registry could not be read before publishing: ${e.message}`);
177
- return done(1);
178
- }
179
- if (existing) {
180
- if (existing.dist?.integrity !== report.integrity) {
181
- step("publish", false, `${pkg.version} is already on the registry with other bytes`);
182
- return done(1);
183
- }
184
- step("publish", true, "already on the registry with these bytes");
185
- } else {
186
- const pub = npm(["publish", tarball, "--tag", opts.tag, "--registry", opts.registry], dir);
187
- if (!step("publish", pub.ok, pub.ok ? `tag ${opts.tag}` : pub.stderr)) return done(1);
188
- }
189
-
190
- const visible = await poll(async () => {
191
- const doc = await packument(opts.registry, pkg.name);
192
- const v = doc?.versions?.[pkg.version];
193
- if (v && v.dist?.integrity && v.dist.integrity !== report.integrity) {
194
- throw Object.assign(new Error(`the registry serves ${v.dist.integrity}`), { fatal: true });
195
- }
196
- const tagged = doc?.["dist-tags"]?.[opts.tag] === pkg.version;
197
- return {
198
- done: Boolean(v) && tagged,
199
- url: v?.dist?.tarball,
200
- detail: v ? "tag not yet moved" : "version not yet listed",
201
- };
202
- }, timing).catch((e) => ({ done: false, detail: e.message }));
203
- if (!visible.done) {
204
- step("visible", false, visible.timedOut ? `timed out: ${visible.detail}` : visible.detail);
205
- return done(3);
206
- }
207
- step("visible", true, `${opts.tag} -> ${pkg.version}`);
208
-
209
- const served = join(work, "served.tgz");
210
- try {
211
- const res = await fetch(visible.url);
212
- if (!res.ok) throw new Error(`tarball answered ${res.status}`);
213
- writeFileSync(served, Buffer.from(await res.arrayBuffer()));
214
- } catch (e) {
215
- step("tarball", false, e.message);
216
- return done(3);
217
- }
218
- const servedIntegrity = integrityOf(readFileSync(served));
219
- if (!step("tarball", servedIntegrity === report.integrity, servedIntegrity)) return done(3);
220
-
221
- const project = join(work, "install");
222
- mkdirSync(project, { recursive: true });
223
- writeFileSync(join(project, "package.json"), JSON.stringify({ private: true }));
224
- const inst = npm(
225
- ["install", served, "--ignore-scripts", "--no-audit", "--no-fund", "--no-package-lock"],
226
- project,
227
- );
228
- if (!inst.ok) {
229
- step("install", false, inst.stderr);
230
- return done(3);
231
- }
232
- try {
233
- const installed = join(project, "node_modules", pkg.name);
234
- const got = JSON.parse(readFileSync(join(installed, "package.json"), "utf8"));
235
- if (got.version !== pkg.version) throw new Error(`installed ${got.version}`);
236
- const bins = typeof got.bin === "string" ? [got.bin] : Object.values(got.bin || {});
237
- for (const b of bins) statSync(join(installed, b));
238
- step("install", true, `${pkg.version}, ${bins.length} bin(s) present`);
239
- } catch (e) {
240
- step("install", false, e.message);
241
- return done(3);
242
- }
243
-
244
- if (opts.smoke) {
245
- const r = spawnSync("/bin/sh", ["-c", opts.smoke], {
246
- cwd: project,
247
- encoding: "utf8",
248
- timeout: 5 * 60 * 1000,
249
- });
250
- const detail = `${opts.smoke}: exit ${r.status}${r.stderr ? ` ${r.stderr.trim().slice(0, 200)}` : ""}`;
251
- if (!step("smoke", r.status === 0, detail)) return done(3);
252
- }
253
-
254
- const tagged = npm(
255
- ["dist-tag", "add", `${pkg.name}@${pkg.version}`, "latest", "--registry", opts.registry],
256
- dir,
257
- );
258
- if (!step("promote", tagged.ok, tagged.ok ? "latest" : tagged.stderr)) return done(3);
259
- const latest = await poll(async () => {
260
- const doc = await packument(opts.registry, pkg.name);
261
- return { done: doc?.["dist-tags"]?.latest === pkg.version, detail: "latest not yet moved" };
262
- }, timing);
263
- if (!step("latest", latest.done, latest.done ? pkg.version : latest.detail)) return done(3);
264
- report.promoted = true;
265
- return done(0);
266
- }
267
-
268
- async function main() {
269
- let flags;
270
- try {
271
- ({ flags } = parseArgs(process.argv.slice(2), {
272
- unknown: "error",
273
- positionals: false,
274
- booleans: ["dry-run", "json"],
275
- strings: ["dir", "registry", "tag", "npm", "userconfig", "smoke", "timeout-s", "interval-ms"],
276
- }));
277
- } catch (e) {
278
- if (!(e instanceof ArgsError)) throw e;
279
- process.stderr.write(`publish-staged: ${e.message}\n`);
280
- process.exitCode = 2;
281
- return;
282
- }
283
- const timeoutS = Number(flags["timeout-s"] ?? 300);
284
- const intervalMs = Number(flags["interval-ms"] ?? 5000);
285
- const refusal = stagingTagRefusal(flags.tag ?? "candidate");
286
- if (refusal) {
287
- process.stderr.write(`publish-staged: ${refusal}\n`);
288
- process.exitCode = 2;
289
- return;
290
- }
291
- if (!(timeoutS > 0) || !(intervalMs > 0)) {
292
- process.stderr.write("publish-staged: --timeout-s and --interval-ms take positive numbers\n");
293
- process.exitCode = 2;
294
- return;
295
- }
296
- const { code, report } = await publishStaged({
297
- dir: flags.dir ?? process.cwd(),
298
- registry: flags.registry ?? DEFAULT_REGISTRY,
299
- tag: flags.tag ?? "candidate",
300
- npm: flags.npm ?? "npm",
301
- userconfig: flags.userconfig ?? null,
302
- smoke: flags.smoke ?? null,
303
- timeoutS,
304
- intervalMs,
305
- dryRun: flags["dry-run"] === true,
306
- });
307
- if (flags.json) {
308
- process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
309
- } else {
310
- for (const s of report.steps) {
311
- process.stdout.write(`${s.ok ? "ok " : "FAIL"} ${s.step.padEnd(8)} ${s.detail ?? ""}\n`);
312
- }
313
- process.stdout.write(
314
- report.promoted
315
- ? `${report.name}@${report.version} is latest\n`
316
- : code === 3
317
- ? `${report.name}@${report.version} stays on ${report.tag}; latest is unchanged\n`
318
- : "",
319
- );
320
- }
321
- process.exitCode = code;
322
- }
323
-
324
- if (invokedDirectly(import.meta.url)) await main();