@mmerterden/multi-agent-pipeline 23.3.0 → 23.5.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 (239) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/README.md +27 -8
  3. package/README.tr.md +28 -9
  4. package/SECURITY.md +16 -0
  5. package/docs/adr/0008-installer-modularization-and-secret-leak-defense.md +1 -1
  6. package/docs/adr/0010-own-code-graph.md +299 -8
  7. package/docs/architecture.md +3 -3
  8. package/docs/ecosystem.md +10 -10
  9. package/docs/engineering.md +4 -4
  10. package/docs/facts.json +8 -8
  11. package/docs/features.md +5 -5
  12. package/docs/performance.md +17 -17
  13. package/install/_dev-only-files.mjs +9 -0
  14. package/install/_platform-filter.mjs +2 -55
  15. package/install/claude.mjs +28 -2
  16. package/install/codex.mjs +1 -3
  17. package/install/copilot.mjs +4 -8
  18. package/install/templates/claude-hooks.json +32 -1
  19. package/manifest.json +236 -167
  20. package/package.json +11 -3
  21. package/pipeline/commands/multi-agent/SKILL.md +1 -1
  22. package/pipeline/commands/multi-agent/design-check/SKILL.md +3 -2
  23. package/pipeline/commands/multi-agent/diff-explain/SKILL.md +3 -3
  24. package/pipeline/commands/multi-agent/graph/SKILL.md +57 -24
  25. package/pipeline/commands/multi-agent/pair/SKILL.md +92 -0
  26. package/pipeline/commands/multi-agent/prune-prompts/SKILL.md +1 -1
  27. package/pipeline/commands/multi-agent/search/SKILL.md +7 -1
  28. package/pipeline/commands/multi-agent/status/SKILL.md +4 -0
  29. package/pipeline/commands/multi-agent/sync/SKILL.md +3 -3
  30. package/pipeline/contract/CHANGELOG.md +63 -0
  31. package/pipeline/contract/README.md +1 -0
  32. package/pipeline/contract/build.mjs +13 -1
  33. package/pipeline/contract/fixtures/error-invalid-request.json +1 -1
  34. package/pipeline/contract/fixtures/error-unauthorized.json +1 -1
  35. package/pipeline/contract/fixtures/runs-awaiting-question.json +4 -1
  36. package/pipeline/contract/fixtures/runs-empty.json +1 -1
  37. package/pipeline/contract/fixtures/runs-failed.json +4 -1
  38. package/pipeline/contract/fixtures/runs-old-schema.json +3 -0
  39. package/pipeline/contract/fixtures/runs-pr-opened-redacted.json +4 -1
  40. package/pipeline/contract/fixtures/runs-pr-opened.json +4 -1
  41. package/pipeline/contract/fixtures/runs-running.json +4 -1
  42. package/pipeline/contract/manifest.json +41 -15
  43. package/pipeline/contract/types/index.d.ts +81 -3
  44. package/pipeline/lib/detach-self.mjs +95 -0
  45. package/pipeline/lib/public-mcp-servers.mjs +33 -0
  46. package/pipeline/lib/rotated-log.mjs +93 -0
  47. package/pipeline/lib/stack-detect.sh +1 -1
  48. package/pipeline/lib/tls-trust.mjs +29 -0
  49. package/pipeline/lib/usage-lifecycle.mjs +9 -11
  50. package/pipeline/lib/usage-names.generated.mjs +613 -0
  51. package/pipeline/lib/usage-run-key.mjs +235 -0
  52. package/pipeline/lib/usage-vocab.mjs +210 -0
  53. package/pipeline/multi-agent-refs/analysis/intake.md +2 -2
  54. package/pipeline/multi-agent-refs/analysis/render.md +1 -1
  55. package/pipeline/multi-agent-refs/channels/generator.md +4 -5
  56. package/pipeline/multi-agent-refs/cross-cli-contract.md +3 -3
  57. package/pipeline/multi-agent-refs/design-check/init-inventory.md +11 -1
  58. package/pipeline/multi-agent-refs/design-check/scope-and-ledger.md +1 -1
  59. package/pipeline/multi-agent-refs/features/code-graph.md +146 -11
  60. package/pipeline/multi-agent-refs/features/code-intelligence.md +16 -14
  61. package/pipeline/multi-agent-refs/features/dev-critic.md +7 -7
  62. package/pipeline/multi-agent-refs/features/model-fallback.md +6 -4
  63. package/pipeline/multi-agent-refs/features/remote-control.md +253 -0
  64. package/pipeline/multi-agent-refs/features/review-delta.md +1 -1
  65. package/pipeline/multi-agent-refs/features/review-file-set.md +3 -3
  66. package/pipeline/multi-agent-refs/features/review-multi-repo.md +1 -1
  67. package/pipeline/multi-agent-refs/features/session-brief.md +42 -0
  68. package/pipeline/multi-agent-refs/features/skill-conformance.md +3 -3
  69. package/pipeline/multi-agent-refs/features/usage-reporting.md +255 -27
  70. package/pipeline/multi-agent-refs/help/en.md +3 -2
  71. package/pipeline/multi-agent-refs/help/tr.md +3 -2
  72. package/pipeline/multi-agent-refs/knowledge.md +1 -1
  73. package/pipeline/multi-agent-refs/orchestrator/dispatcher.md +2 -2
  74. package/pipeline/multi-agent-refs/phases/operations.md +2 -2
  75. package/pipeline/multi-agent-refs/phases/phase-0-init.md +13 -12
  76. package/pipeline/multi-agent-refs/phases/phase-1-plan.md +4 -4
  77. package/pipeline/multi-agent-refs/phases/phase-3-review.md +2 -0
  78. package/pipeline/multi-agent-refs/phases/phase-5-report.md +1 -1
  79. package/pipeline/multi-agent-refs/platform-parity.md +2 -2
  80. package/pipeline/multi-agent-refs/wiki-capture.md +3 -17
  81. package/pipeline/office/index.html +1309 -236
  82. package/pipeline/office/toolkit.json +1 -1
  83. package/pipeline/rules/outside-the-pipeline.md +1 -1
  84. package/pipeline/schemas/activity.schema.json +23 -0
  85. package/pipeline/schemas/agent-state.schema.json +6 -1
  86. package/pipeline/schemas/code-graph-calls.schema.json +254 -0
  87. package/pipeline/schemas/code-graph-docs.schema.json +223 -0
  88. package/pipeline/schemas/code-graph-infra.schema.json +227 -0
  89. package/pipeline/schemas/code-graph.schema.json +2 -2
  90. package/pipeline/schemas/examples/design-check-config.json +27 -0
  91. package/pipeline/schemas/learning-curve.schema.json +67 -0
  92. package/pipeline/schemas/mcp-health.schema.json +96 -0
  93. package/pipeline/schemas/office-jobs.json +69 -2
  94. package/pipeline/schemas/office-jobs.schema.json +8 -1
  95. package/pipeline/schemas/phases.json +5 -0
  96. package/pipeline/schemas/phases.schema.json +8 -0
  97. package/pipeline/schemas/prefs.schema.json +46 -12
  98. package/pipeline/schemas/runs-index.schema.json +17 -0
  99. package/pipeline/schemas/toolkit-path-params.json +78 -8
  100. package/pipeline/scripts/README.md +1 -0
  101. package/pipeline/scripts/_code-graph.mjs +184 -103
  102. package/pipeline/scripts/_contract-core.mjs +1 -1
  103. package/pipeline/scripts/_contract-routes-office.mjs +33 -0
  104. package/pipeline/scripts/_diff-impact.mjs +21 -2
  105. package/pipeline/scripts/_graph-sidecars.mjs +372 -0
  106. package/pipeline/scripts/_http-post.mjs +103 -115
  107. package/pipeline/scripts/_safe-read.mjs +57 -0
  108. package/pipeline/scripts/_skill-practices.mjs +26 -0
  109. package/pipeline/scripts/_strip-code.mjs +380 -0
  110. package/pipeline/scripts/activity-snapshot.mjs +13 -1
  111. package/pipeline/scripts/aggregate-metrics.mjs +3 -5
  112. package/pipeline/scripts/build-stack-plugins.mjs +1 -47
  113. package/pipeline/scripts/call-graph/index.mjs +78 -0
  114. package/pipeline/scripts/call-graph/lang/cpp.mjs +308 -0
  115. package/pipeline/scripts/call-graph/lang/csharp.mjs +130 -0
  116. package/pipeline/scripts/call-graph/lang/go.mjs +303 -0
  117. package/pipeline/scripts/call-graph/lang/java.mjs +370 -0
  118. package/pipeline/scripts/call-graph/lang/kotlin.mjs +397 -0
  119. package/pipeline/scripts/call-graph/lang/python.mjs +399 -0
  120. package/pipeline/scripts/call-graph/lang/rust.mjs +345 -0
  121. package/pipeline/scripts/call-graph/lang/shared.mjs +230 -0
  122. package/pipeline/scripts/call-graph/lang/swift.mjs +432 -0
  123. package/pipeline/scripts/call-graph/lang/typescript.mjs +692 -0
  124. package/pipeline/scripts/call-graph/lex.mjs +396 -0
  125. package/pipeline/scripts/call-graph/platform.mjs +86 -0
  126. package/pipeline/scripts/call-graph/profiles.mjs +89 -0
  127. package/pipeline/scripts/call-graph/resolve.mjs +1125 -0
  128. package/pipeline/scripts/call-graph/scan.mjs +267 -0
  129. package/pipeline/scripts/code-graph-rules/android.json +7 -2
  130. package/pipeline/scripts/code-graph-rules/cpp.json +99 -0
  131. package/pipeline/scripts/code-graph-rules/csharp.json +102 -0
  132. package/pipeline/scripts/code-graph-rules/go.json +2 -1
  133. package/pipeline/scripts/code-graph-rules/ios.json +3 -1
  134. package/pipeline/scripts/code-graph-rules/java.json +76 -0
  135. package/pipeline/scripts/code-graph-rules/node.json +7 -2
  136. package/pipeline/scripts/code-graph-rules/python.json +6 -2
  137. package/pipeline/scripts/code-graph-rules/rust.json +105 -0
  138. package/pipeline/scripts/contract-server.mjs +3 -0
  139. package/pipeline/scripts/design-check-config.mjs +205 -0
  140. package/pipeline/scripts/feedback-send.mjs +26 -26
  141. package/pipeline/scripts/gate-ledger.mjs +2 -1
  142. package/pipeline/scripts/gen-facts.mjs +1 -2
  143. package/pipeline/scripts/gen-usage-names.mjs +124 -0
  144. package/pipeline/scripts/graph-affected.mjs +109 -20
  145. package/pipeline/scripts/graph-build.mjs +95 -15
  146. package/pipeline/scripts/graph-export.mjs +272 -0
  147. package/pipeline/scripts/graph-hint.mjs +15 -2
  148. package/pipeline/scripts/graph-query.mjs +305 -26
  149. package/pipeline/scripts/graph-report.mjs +187 -1
  150. package/pipeline/scripts/health-report.mjs +3 -4
  151. package/pipeline/scripts/infra/docs.mjs +317 -0
  152. package/pipeline/scripts/infra/extract.mjs +998 -0
  153. package/pipeline/scripts/infra/graph.mjs +245 -0
  154. package/pipeline/scripts/infra/yaml-lite.mjs +311 -0
  155. package/pipeline/scripts/job-launch.mjs +67 -2
  156. package/pipeline/scripts/learning-curve.mjs +288 -178
  157. package/pipeline/scripts/log-metric.sh +10 -1
  158. package/pipeline/scripts/mcp-health.mjs +309 -0
  159. package/pipeline/scripts/note-agent-event.mjs +3 -4
  160. package/pipeline/scripts/note-command-use.mjs +333 -0
  161. package/pipeline/scripts/note-command-use.sh +126 -0
  162. package/pipeline/scripts/note-mcp-call.sh +89 -0
  163. package/pipeline/scripts/note-mcp-failure.mjs +272 -1
  164. package/pipeline/scripts/note-session.sh +62 -3
  165. package/pipeline/scripts/note-skill-use.mjs +58 -2
  166. package/pipeline/scripts/office-build.mjs +115 -1
  167. package/pipeline/scripts/office-memory.mjs +14 -5
  168. package/pipeline/scripts/pair.mjs +333 -0
  169. package/pipeline/scripts/pre-push-check.sh +1 -1
  170. package/pipeline/scripts/remote/cbor.mjs +128 -0
  171. package/pipeline/scripts/remote/contract.mjs +98 -0
  172. package/pipeline/scripts/remote/handler.mjs +330 -0
  173. package/pipeline/scripts/remote/handles.mjs +57 -0
  174. package/pipeline/scripts/remote/lifecycle.mjs +186 -0
  175. package/pipeline/scripts/remote/listener.mjs +204 -0
  176. package/pipeline/scripts/remote/lockout.mjs +103 -0
  177. package/pipeline/scripts/remote/nonces.mjs +61 -0
  178. package/pipeline/scripts/remote/pairing.mjs +519 -0
  179. package/pipeline/scripts/remote/qr-encode.mjs +459 -0
  180. package/pipeline/scripts/remote/store.mjs +191 -0
  181. package/pipeline/scripts/remote/transport.mjs +211 -0
  182. package/pipeline/scripts/remote/verbs.json +70 -0
  183. package/pipeline/scripts/remote/verbs.mjs +217 -0
  184. package/pipeline/scripts/remote/webauthn.mjs +169 -0
  185. package/pipeline/scripts/remote/wire.mjs +364 -0
  186. package/pipeline/scripts/remote-listener.mjs +83 -0
  187. package/pipeline/scripts/route-learn.mjs +4 -4
  188. package/pipeline/scripts/run-kill.mjs +1 -1
  189. package/pipeline/scripts/run-write.mjs +13 -2
  190. package/pipeline/scripts/runs-index.mjs +30 -3
  191. package/pipeline/scripts/search-logs.sh +9 -0
  192. package/pipeline/scripts/session-brief.mjs +458 -0
  193. package/pipeline/scripts/session-brief.sh +130 -0
  194. package/pipeline/scripts/skill-usage.mjs +16 -5
  195. package/pipeline/scripts/test-gap-rules/cpp.json +25 -0
  196. package/pipeline/scripts/test-gap-rules/csharp.json +20 -0
  197. package/pipeline/scripts/test-gap-rules/java.json +20 -0
  198. package/pipeline/scripts/test-gap-rules/rust.json +14 -0
  199. package/pipeline/scripts/token-budget-report.mjs +3 -2
  200. package/pipeline/scripts/uninstall.mjs +29 -0
  201. package/pipeline/scripts/usage-access.mjs +16 -31
  202. package/pipeline/scripts/usage-health.mjs +31 -62
  203. package/pipeline/scripts/usage-register-beacon.mjs +11 -22
  204. package/pipeline/scripts/usage-register.mjs +39 -29
  205. package/pipeline/scripts/usage-report.mjs +579 -178
  206. package/pipeline/scripts/validate-code-graph.mjs +361 -111
  207. package/pipeline/scripts/write-state.mjs +39 -0
  208. package/pipeline/skills/.skill-manifest.json +21 -17
  209. package/pipeline/skills/.skills-index.json +13 -2
  210. package/pipeline/skills/shared/README.md +5 -4
  211. package/pipeline/skills/shared/core/multi-agent-design-check/SKILL.md +1 -1
  212. package/pipeline/skills/shared/core/multi-agent-diff-explain/SKILL.md +3 -3
  213. package/pipeline/skills/shared/core/multi-agent-graph/SKILL.md +55 -21
  214. package/pipeline/skills/shared/core/multi-agent-pair/SKILL.md +41 -0
  215. package/pipeline/skills/shared/core/multi-agent-prune-prompts/SKILL.md +1 -1
  216. package/pipeline/skills/shared/core/multi-agent-sync/SKILL.md +3 -3
  217. package/pipeline/skills/shared/external/app-store-optimization/SKILL.md +2 -3
  218. package/pipeline/skills/shared/external/app-store-optimization/references/keyword-research-methodology.md +2 -2
  219. package/pipeline/skills/shared/external/app-store-optimization/references/product-page-variants.md +2 -2
  220. package/pipeline/skills/shared/external/app-store-review/SKILL.md +11 -4
  221. package/pipeline/skills/shared/external/build-settings-audit/SKILL.md +1 -1
  222. package/pipeline/skills/shared/external/build-time-benchmark/SKILL.md +5 -5
  223. package/pipeline/skills/shared/external/build-time-fixes/SKILL.md +5 -5
  224. package/pipeline/skills/shared/external/build-time-optimizer/SKILL.md +6 -6
  225. package/pipeline/skills/shared/external/free-llm-apis/references/providers.md +1 -0
  226. package/pipeline/skills/shared/external/ios-coding-standard/references/STANDARD.md +2 -2
  227. package/pipeline/skills/shared/external/ios-haptics/references/core-haptics.md +1 -1
  228. package/pipeline/skills/shared/external/localization-reuse-map/references/publish-and-snapshot.md +1 -1
  229. package/pipeline/skills/shared/external/package-build-audit/SKILL.md +3 -3
  230. package/pipeline/skills/shared/external/reverse-engineer-own-app/SKILL.md +2 -3
  231. package/pipeline/skills/shared/external/swift-compile-hotspots/SKILL.md +2 -2
  232. package/pipeline/skills/shared/external/weatherkit/SKILL.md +5 -6
  233. package/pipeline/skills/skills-index.md +3 -2
  234. package/docs/FIGMA_PIPELINE.md +0 -137
  235. package/pipeline/lib/identifier-scan.mjs +0 -156
  236. package/pipeline/scripts/_renamed-skills.mjs +0 -164
  237. package/pipeline/scripts/publish-staged.mjs +0 -324
  238. package/pipeline/skills/renamed.json +0 -30
  239. package/pipeline/skills/shared/external/ios-coding-standard/scripts/check_structure.py +0 -765
@@ -1,141 +1,129 @@
1
- // _http-post.mjs - POST a JSON body, falling back to curl when Node's fetch
2
- // cannot reach the host at all.
1
+ // _http-post.mjs - POST a JSON body through node:https, with certificate
2
+ // verification that the environment cannot weaken.
3
3
  //
4
- // Node's built-in fetch ignores HTTPS_PROXY and trusts only its bundled CA
5
- // list, so behind a corporate proxy or a TLS-inspecting gateway it fails with
6
- // ECONNREFUSED, ENOTFOUND or SELF_SIGNED_CERT_IN_CHAIN while gh, git and curl on
7
- // the same machine work. curl honours the proxy variables and the system trust
8
- // store, so a transport failure (never an HTTP status) is retried through it.
4
+ // Every usage send (the run record, the lifecycle record, registration, the
5
+ // access check, the failure beacon and feedback) carries a bearer token or a
6
+ // login, so the transport is fixed rather than negotiated:
9
7
  //
10
- // Secret headers never reach argv: curl reads them from a 0600 file that is
11
- // removed before this returns. Redirects are never followed by either path.
8
+ // - node:https with an explicit `rejectUnauthorized: true` on the request and
9
+ // on a dedicated agent. NODE_TLS_REJECT_UNAUTHORIZED=0 does not apply to an
10
+ // option that is set explicitly.
11
+ // - The dedicated agent is not the global one, so an environment proxy
12
+ // (HTTPS_PROXY, NODE_USE_ENV_PROXY) is not used.
13
+ // - No second client. A transport or certificate failure is reported as it
14
+ // is; it is never retried through curl or anything else, which is how a
15
+ // CURL_CA_BUNDLE or SSL_CERT_FILE pointing at an attacker's certificate
16
+ // would otherwise get the token delivered.
17
+ // - The trust store (lib/tls-trust.mjs, shared with the remote transport) is
18
+ // Node's bundled roots plus the file NODE_EXTRA_CA_CERTS names, passed to
19
+ // the agent as `ca`. NODE_EXTRA_CA_CERTS is the documented
20
+ // way to trust a corporate TLS-inspecting CA; SSL_CERT_FILE, SSL_CERT_DIR
21
+ // and the other ways of adding trust are not applied to these requests.
22
+ //
23
+ // node:https is part of every supported Node (engines >= 20.11), so there is
24
+ // nothing to fall back to. Redirects are never followed. Plain http is allowed
25
+ // for a loopback address only.
26
+
27
+ import http from "node:http";
28
+ import https from "node:https";
29
+ import { trustedRoots } from "../lib/tls-trust.mjs";
30
+
31
+ const MAX_BODY = 1024 * 1024;
32
+ const LOOPBACK = new Set(["127.0.0.1", "localhost", "[::1]", "::1"]);
12
33
 
13
- import { spawn as spawnChild } from "node:child_process";
14
- import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
15
- import { tmpdir } from "node:os";
16
- import { join } from "node:path";
34
+ const agent = new https.Agent({ rejectUnauthorized: true, keepAlive: false, ca: trustedRoots() });
17
35
 
18
- /** The low-level reason a fetch failed, e.g. ECONNREFUSED or SELF_SIGNED_CERT_IN_CHAIN. */
36
+ /** The low-level reason a request failed, e.g. ECONNREFUSED or SELF_SIGNED_CERT_IN_CHAIN. */
19
37
  export function failureCode(err, aborted = false) {
20
38
  if (aborted) return "timeout";
21
39
  return String(err?.cause?.code ?? err?.code ?? err?.name ?? "error").slice(0, 40);
22
40
  }
23
41
 
24
- function run(spawn, cmd, args, input, timeoutMs) {
25
- return new Promise((resolve) => {
26
- let stdout = "";
27
- let child;
28
- try {
29
- child = spawn(cmd, args, { stdio: ["pipe", "pipe", "ignore"] });
30
- } catch (error) {
31
- resolve({ error });
32
- return;
33
- }
34
- const timer = setTimeout(() => child.kill("SIGKILL"), timeoutMs);
35
- child.stdout.on("data", (c) => (stdout += c));
36
- child.on("error", (error) => {
37
- clearTimeout(timer);
38
- resolve({ error });
39
- });
40
- child.on("close", (status) => {
41
- clearTimeout(timer);
42
- resolve({ status, stdout });
43
- });
44
- child.stdin.end(input);
45
- });
42
+ function target(url) {
43
+ let u;
44
+ try {
45
+ u = new URL(url);
46
+ } catch {
47
+ return null;
48
+ }
49
+ if (u.protocol === "https:") return { u, secure: true };
50
+ if (u.protocol === "http:" && LOOPBACK.has(u.hostname)) return { u, secure: false };
51
+ return null;
46
52
  }
47
53
 
48
54
  /**
49
- * One POST through curl. Returns { status, body, location, transport: "curl" }
50
- * or { failure, transport: "curl" } when curl is missing or cannot connect.
55
+ * One POST. Resolves { status, body, location }; rejects with an error whose
56
+ * `code` says why no HTTP answer came (`timeout`, `scheme-not-allowed`,
57
+ * `too-large` for an answer over 1 MB, which also closes the socket, or the
58
+ * socket or certificate error's own code).
51
59
  */
52
- export async function curlPost({ url, headers = {}, body, timeoutMs, spawn = spawnChild }) {
53
- const dir = mkdtempSync(join(tmpdir(), "ma-http-"));
54
- const headerFile = join(dir, "headers");
55
- try {
56
- const lines = Object.entries(headers).map(([k, v]) => `${k}: ${v}`);
57
- writeFileSync(headerFile, lines.join("\n") + "\n", { mode: 0o600 });
58
- const seconds = String(Math.max(1, Math.ceil(timeoutMs / 1000)));
59
- const r = await run(
60
- spawn,
61
- "curl",
62
- [
63
- "-sS",
64
- "--max-time",
65
- seconds,
66
- "-X",
67
- "POST",
68
- "-H",
69
- `@${headerFile}`,
70
- "--data-binary",
71
- "@-",
72
- "-w",
73
- "\n%{http_code} %{redirect_url}",
74
- url,
75
- ],
76
- body,
77
- timeoutMs + 2000,
78
- );
79
- if (r.error) return { failure: failureCode(r.error), transport: "curl" };
80
- if (r.status !== 0) {
81
- return { failure: `curl-exit-${r.status}`, transport: "curl" };
60
+ export function httpsSend({ url, headers = {}, body, timeoutMs }) {
61
+ return new Promise((resolve, reject) => {
62
+ const t = target(url);
63
+ if (!t) {
64
+ reject(Object.assign(new Error("scheme not allowed"), { code: "scheme-not-allowed" }));
65
+ return;
82
66
  }
83
- const out = String(r.stdout ?? "");
84
- const cut = out.lastIndexOf("\n");
85
- const [code, location = ""] = out.slice(cut + 1).split(" ");
86
- return {
87
- status: Number(code) || 0,
88
- body: out.slice(0, cut),
89
- location: location || null,
90
- transport: "curl",
67
+ const payload = Buffer.from(String(body ?? ""), "utf8");
68
+ const options = {
69
+ method: "POST",
70
+ hostname: t.u.hostname.replace(/^\[|\]$/g, ""),
71
+ port: t.u.port || (t.secure ? 443 : 80),
72
+ path: `${t.u.pathname}${t.u.search}`,
73
+ headers: { ...headers, "Content-Length": payload.length },
74
+ ...(t.secure ? { agent, rejectUnauthorized: true } : {}),
91
75
  };
92
- } finally {
93
- rmSync(dir, { recursive: true, force: true });
94
- }
76
+ let settled = false;
77
+ const done = (fn, value) => {
78
+ if (settled) return;
79
+ settled = true;
80
+ clearTimeout(timer);
81
+ fn(value);
82
+ };
83
+ const req = (t.secure ? https : http).request(options, (res) => {
84
+ const chunks = [];
85
+ let size = 0;
86
+ res.on("data", (c) => {
87
+ size += c.length;
88
+ if (size > MAX_BODY) {
89
+ req.destroy();
90
+ done(reject, Object.assign(new Error("response too large"), { code: "too-large" }));
91
+ return;
92
+ }
93
+ chunks.push(c);
94
+ });
95
+ res.on("end", () =>
96
+ done(resolve, {
97
+ status: res.statusCode ?? 0,
98
+ body: Buffer.concat(chunks).toString("utf8"),
99
+ location: res.headers.location ?? null,
100
+ }),
101
+ );
102
+ res.on("error", (e) => done(reject, e));
103
+ });
104
+ const timer = setTimeout(() => {
105
+ req.destroy();
106
+ done(reject, Object.assign(new Error("timeout"), { code: "timeout" }));
107
+ }, timeoutMs);
108
+ req.on("error", (e) => done(reject, e));
109
+ req.end(payload);
110
+ });
95
111
  }
96
112
 
97
113
  /**
98
- * fetch first; on a transport failure, curl. Returns { status, body, location,
99
- * transport } on any HTTP answer, or { failure, fetchFailure, transport } when
100
- * neither path reached the host. `fetchFailure` keeps the original cause.
114
+ * POST a JSON body. Returns { status, body, location, transport: "https" } on
115
+ * any HTTP answer, or { failure, transport: "https" } when none came.
101
116
  */
102
- export async function postJson({
103
- url,
104
- headers = {},
105
- body,
106
- timeoutMs,
107
- fetchImpl = fetch,
108
- curl = curlPost,
109
- }) {
110
- const ctrl = new AbortController();
111
- const timer = setTimeout(() => ctrl.abort(), timeoutMs);
112
- let fetchFailure;
117
+ export async function postJson({ url, headers = {}, body, timeoutMs, send = httpsSend }) {
113
118
  try {
114
- const res = await fetchImpl(url, {
115
- method: "POST",
119
+ const r = await send({
120
+ url,
116
121
  headers: { "Content-Type": "application/json", ...headers },
117
122
  body,
118
- redirect: "manual",
119
- signal: ctrl.signal,
123
+ timeoutMs,
120
124
  });
121
- const text = await res.text().catch(() => "");
122
- return {
123
- status: res.status,
124
- body: text,
125
- location: res.headers.get("location"),
126
- transport: "fetch",
127
- };
125
+ return { status: r.status, body: r.body, location: r.location ?? null, transport: "https" };
128
126
  } catch (err) {
129
- fetchFailure = failureCode(err, ctrl.signal.aborted);
130
- } finally {
131
- clearTimeout(timer);
127
+ return { failure: failureCode(err), transport: "https" };
132
128
  }
133
- const viaCurl = await curl({
134
- url,
135
- headers: { "Content-Type": "application/json", ...headers },
136
- body,
137
- timeoutMs,
138
- });
139
- if (viaCurl.failure) return { failure: viaCurl.failure, fetchFailure, transport: "curl" };
140
- return { ...viaCurl, fetchFailure };
141
129
  }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @file _safe-read.mjs - read a file of an untrusted tree without leaving it.
3
+ *
4
+ * A repository can hold a symbolic link to a file outside itself, a named pipe
5
+ * or a device. Opening those would read something that is not the repository
6
+ * or block forever, so a path is read only when it is a regular file whose real
7
+ * location is inside the root. A link that stays inside the root is followed.
8
+ *
9
+ * @module pipeline/scripts/_safe-read
10
+ */
11
+
12
+ import { lstatSync, readFileSync, realpathSync, statSync } from "node:fs";
13
+ import { dirname, join, sep } from "node:path";
14
+
15
+ /**
16
+ * @param {string} root - absolute repo root
17
+ * @returns {(rel: string, maxBytes?: number) => string|null} reader; null when the
18
+ * path is not a regular file inside root, is too large, or cannot be read
19
+ */
20
+ export function makeSafeReader(root) {
21
+ let realRoot;
22
+ try {
23
+ realRoot = realpathSync(root);
24
+ } catch {
25
+ return () => null;
26
+ }
27
+ const dirOk = new Map();
28
+ const inside = (abs) => abs === realRoot || abs.startsWith(realRoot + sep);
29
+ const parentInside = (abs) => {
30
+ const dir = dirname(abs);
31
+ if (dirOk.has(dir)) return dirOk.get(dir);
32
+ let ok;
33
+ try {
34
+ ok = inside(realpathSync(dir));
35
+ } catch {
36
+ ok = false;
37
+ }
38
+ dirOk.set(dir, ok);
39
+ return ok;
40
+ };
41
+ return (rel, maxBytes = Infinity) => {
42
+ const abs = join(root, rel);
43
+ try {
44
+ if (!parentInside(abs)) return null;
45
+ const link = lstatSync(abs);
46
+ let st = link;
47
+ if (link.isSymbolicLink()) {
48
+ if (!inside(realpathSync(abs))) return null;
49
+ st = statSync(abs);
50
+ }
51
+ if (!st.isFile() || st.size > maxBytes) return null;
52
+ return readFileSync(abs, "utf8");
53
+ } catch {
54
+ return null;
55
+ }
56
+ };
57
+ }
@@ -92,6 +92,32 @@ function targets(text, fromRel) {
92
92
  return out;
93
93
  }
94
94
 
95
+ const ESCAPES = (path) => path === ".." || path.startsWith("../");
96
+
97
+ /**
98
+ * Markdown links (and backticked `../` paths) in SKILL.md or a companion that
99
+ * resolve outside the skill folder. A skill ships and is copied as its folder,
100
+ * so a path that leaves it points at nothing on the machine that installs it.
101
+ *
102
+ * @returns {{from: string, to: string}[]}
103
+ */
104
+ export function escapingLinks(skillDirPath) {
105
+ const out = [];
106
+ for (const rel of ["SKILL.md", ...companionMarkdown(skillDirPath)]) {
107
+ const text = readFileSync(join(skillDirPath, rel), "utf8");
108
+ const base = dirname(rel);
109
+ const raw = [
110
+ ...String(text).matchAll(LINK),
111
+ ...[...String(text).matchAll(TICKED)].filter((m) => m[1].startsWith("../")),
112
+ ];
113
+ for (const m of raw) {
114
+ const resolved = normalize(join(base, m[1])).split(sep).join("/");
115
+ if (ESCAPES(resolved)) out.push({ from: rel, to: m[1] });
116
+ }
117
+ }
118
+ return out;
119
+ }
120
+
95
121
  export function nestedReferences(skillDirPath) {
96
122
  const companions = companionMarkdown(skillDirPath);
97
123
  const known = new Set(companions);