@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.
- package/CHANGELOG.md +73 -0
- package/README.md +27 -8
- package/README.tr.md +28 -9
- package/SECURITY.md +16 -0
- package/docs/adr/0008-installer-modularization-and-secret-leak-defense.md +1 -1
- package/docs/adr/0010-own-code-graph.md +299 -8
- package/docs/architecture.md +3 -3
- package/docs/ecosystem.md +10 -10
- package/docs/engineering.md +4 -4
- package/docs/facts.json +8 -8
- package/docs/features.md +5 -5
- package/docs/performance.md +17 -17
- package/install/_dev-only-files.mjs +9 -0
- package/install/_platform-filter.mjs +2 -55
- package/install/claude.mjs +28 -2
- package/install/codex.mjs +1 -3
- package/install/copilot.mjs +4 -8
- package/install/templates/claude-hooks.json +32 -1
- package/manifest.json +236 -167
- package/package.json +11 -3
- package/pipeline/commands/multi-agent/SKILL.md +1 -1
- package/pipeline/commands/multi-agent/design-check/SKILL.md +3 -2
- package/pipeline/commands/multi-agent/diff-explain/SKILL.md +3 -3
- package/pipeline/commands/multi-agent/graph/SKILL.md +57 -24
- package/pipeline/commands/multi-agent/pair/SKILL.md +92 -0
- package/pipeline/commands/multi-agent/prune-prompts/SKILL.md +1 -1
- package/pipeline/commands/multi-agent/search/SKILL.md +7 -1
- package/pipeline/commands/multi-agent/status/SKILL.md +4 -0
- package/pipeline/commands/multi-agent/sync/SKILL.md +3 -3
- package/pipeline/contract/CHANGELOG.md +63 -0
- package/pipeline/contract/README.md +1 -0
- package/pipeline/contract/build.mjs +13 -1
- package/pipeline/contract/fixtures/error-invalid-request.json +1 -1
- package/pipeline/contract/fixtures/error-unauthorized.json +1 -1
- package/pipeline/contract/fixtures/runs-awaiting-question.json +4 -1
- package/pipeline/contract/fixtures/runs-empty.json +1 -1
- package/pipeline/contract/fixtures/runs-failed.json +4 -1
- package/pipeline/contract/fixtures/runs-old-schema.json +3 -0
- package/pipeline/contract/fixtures/runs-pr-opened-redacted.json +4 -1
- package/pipeline/contract/fixtures/runs-pr-opened.json +4 -1
- package/pipeline/contract/fixtures/runs-running.json +4 -1
- package/pipeline/contract/manifest.json +41 -15
- package/pipeline/contract/types/index.d.ts +81 -3
- package/pipeline/lib/detach-self.mjs +95 -0
- package/pipeline/lib/public-mcp-servers.mjs +33 -0
- package/pipeline/lib/rotated-log.mjs +93 -0
- package/pipeline/lib/stack-detect.sh +1 -1
- package/pipeline/lib/tls-trust.mjs +29 -0
- package/pipeline/lib/usage-lifecycle.mjs +9 -11
- package/pipeline/lib/usage-names.generated.mjs +613 -0
- package/pipeline/lib/usage-run-key.mjs +235 -0
- package/pipeline/lib/usage-vocab.mjs +210 -0
- package/pipeline/multi-agent-refs/analysis/intake.md +2 -2
- package/pipeline/multi-agent-refs/analysis/render.md +1 -1
- package/pipeline/multi-agent-refs/channels/generator.md +4 -5
- package/pipeline/multi-agent-refs/cross-cli-contract.md +3 -3
- package/pipeline/multi-agent-refs/design-check/init-inventory.md +11 -1
- package/pipeline/multi-agent-refs/design-check/scope-and-ledger.md +1 -1
- package/pipeline/multi-agent-refs/features/code-graph.md +146 -11
- package/pipeline/multi-agent-refs/features/code-intelligence.md +16 -14
- package/pipeline/multi-agent-refs/features/dev-critic.md +7 -7
- package/pipeline/multi-agent-refs/features/model-fallback.md +6 -4
- package/pipeline/multi-agent-refs/features/remote-control.md +253 -0
- package/pipeline/multi-agent-refs/features/review-delta.md +1 -1
- package/pipeline/multi-agent-refs/features/review-file-set.md +3 -3
- package/pipeline/multi-agent-refs/features/review-multi-repo.md +1 -1
- package/pipeline/multi-agent-refs/features/session-brief.md +42 -0
- package/pipeline/multi-agent-refs/features/skill-conformance.md +3 -3
- package/pipeline/multi-agent-refs/features/usage-reporting.md +255 -27
- package/pipeline/multi-agent-refs/help/en.md +3 -2
- package/pipeline/multi-agent-refs/help/tr.md +3 -2
- package/pipeline/multi-agent-refs/knowledge.md +1 -1
- package/pipeline/multi-agent-refs/orchestrator/dispatcher.md +2 -2
- package/pipeline/multi-agent-refs/phases/operations.md +2 -2
- package/pipeline/multi-agent-refs/phases/phase-0-init.md +13 -12
- package/pipeline/multi-agent-refs/phases/phase-1-plan.md +4 -4
- package/pipeline/multi-agent-refs/phases/phase-3-review.md +2 -0
- package/pipeline/multi-agent-refs/phases/phase-5-report.md +1 -1
- package/pipeline/multi-agent-refs/platform-parity.md +2 -2
- package/pipeline/multi-agent-refs/wiki-capture.md +3 -17
- package/pipeline/office/index.html +1309 -236
- package/pipeline/office/toolkit.json +1 -1
- package/pipeline/rules/outside-the-pipeline.md +1 -1
- package/pipeline/schemas/activity.schema.json +23 -0
- package/pipeline/schemas/agent-state.schema.json +6 -1
- package/pipeline/schemas/code-graph-calls.schema.json +254 -0
- package/pipeline/schemas/code-graph-docs.schema.json +223 -0
- package/pipeline/schemas/code-graph-infra.schema.json +227 -0
- package/pipeline/schemas/code-graph.schema.json +2 -2
- package/pipeline/schemas/examples/design-check-config.json +27 -0
- package/pipeline/schemas/learning-curve.schema.json +67 -0
- package/pipeline/schemas/mcp-health.schema.json +96 -0
- package/pipeline/schemas/office-jobs.json +69 -2
- package/pipeline/schemas/office-jobs.schema.json +8 -1
- package/pipeline/schemas/phases.json +5 -0
- package/pipeline/schemas/phases.schema.json +8 -0
- package/pipeline/schemas/prefs.schema.json +46 -12
- package/pipeline/schemas/runs-index.schema.json +17 -0
- package/pipeline/schemas/toolkit-path-params.json +78 -8
- package/pipeline/scripts/README.md +1 -0
- package/pipeline/scripts/_code-graph.mjs +184 -103
- package/pipeline/scripts/_contract-core.mjs +1 -1
- package/pipeline/scripts/_contract-routes-office.mjs +33 -0
- package/pipeline/scripts/_diff-impact.mjs +21 -2
- package/pipeline/scripts/_graph-sidecars.mjs +372 -0
- package/pipeline/scripts/_http-post.mjs +103 -115
- package/pipeline/scripts/_safe-read.mjs +57 -0
- package/pipeline/scripts/_skill-practices.mjs +26 -0
- package/pipeline/scripts/_strip-code.mjs +380 -0
- package/pipeline/scripts/activity-snapshot.mjs +13 -1
- package/pipeline/scripts/aggregate-metrics.mjs +3 -5
- package/pipeline/scripts/build-stack-plugins.mjs +1 -47
- package/pipeline/scripts/call-graph/index.mjs +78 -0
- package/pipeline/scripts/call-graph/lang/cpp.mjs +308 -0
- package/pipeline/scripts/call-graph/lang/csharp.mjs +130 -0
- package/pipeline/scripts/call-graph/lang/go.mjs +303 -0
- package/pipeline/scripts/call-graph/lang/java.mjs +370 -0
- package/pipeline/scripts/call-graph/lang/kotlin.mjs +397 -0
- package/pipeline/scripts/call-graph/lang/python.mjs +399 -0
- package/pipeline/scripts/call-graph/lang/rust.mjs +345 -0
- package/pipeline/scripts/call-graph/lang/shared.mjs +230 -0
- package/pipeline/scripts/call-graph/lang/swift.mjs +432 -0
- package/pipeline/scripts/call-graph/lang/typescript.mjs +692 -0
- package/pipeline/scripts/call-graph/lex.mjs +396 -0
- package/pipeline/scripts/call-graph/platform.mjs +86 -0
- package/pipeline/scripts/call-graph/profiles.mjs +89 -0
- package/pipeline/scripts/call-graph/resolve.mjs +1125 -0
- package/pipeline/scripts/call-graph/scan.mjs +267 -0
- package/pipeline/scripts/code-graph-rules/android.json +7 -2
- package/pipeline/scripts/code-graph-rules/cpp.json +99 -0
- package/pipeline/scripts/code-graph-rules/csharp.json +102 -0
- package/pipeline/scripts/code-graph-rules/go.json +2 -1
- package/pipeline/scripts/code-graph-rules/ios.json +3 -1
- package/pipeline/scripts/code-graph-rules/java.json +76 -0
- package/pipeline/scripts/code-graph-rules/node.json +7 -2
- package/pipeline/scripts/code-graph-rules/python.json +6 -2
- package/pipeline/scripts/code-graph-rules/rust.json +105 -0
- package/pipeline/scripts/contract-server.mjs +3 -0
- package/pipeline/scripts/design-check-config.mjs +205 -0
- package/pipeline/scripts/feedback-send.mjs +26 -26
- package/pipeline/scripts/gate-ledger.mjs +2 -1
- package/pipeline/scripts/gen-facts.mjs +1 -2
- package/pipeline/scripts/gen-usage-names.mjs +124 -0
- package/pipeline/scripts/graph-affected.mjs +109 -20
- package/pipeline/scripts/graph-build.mjs +95 -15
- package/pipeline/scripts/graph-export.mjs +272 -0
- package/pipeline/scripts/graph-hint.mjs +15 -2
- package/pipeline/scripts/graph-query.mjs +305 -26
- package/pipeline/scripts/graph-report.mjs +187 -1
- package/pipeline/scripts/health-report.mjs +3 -4
- package/pipeline/scripts/infra/docs.mjs +317 -0
- package/pipeline/scripts/infra/extract.mjs +998 -0
- package/pipeline/scripts/infra/graph.mjs +245 -0
- package/pipeline/scripts/infra/yaml-lite.mjs +311 -0
- package/pipeline/scripts/job-launch.mjs +67 -2
- package/pipeline/scripts/learning-curve.mjs +288 -178
- package/pipeline/scripts/log-metric.sh +10 -1
- package/pipeline/scripts/mcp-health.mjs +309 -0
- package/pipeline/scripts/note-agent-event.mjs +3 -4
- package/pipeline/scripts/note-command-use.mjs +333 -0
- package/pipeline/scripts/note-command-use.sh +126 -0
- package/pipeline/scripts/note-mcp-call.sh +89 -0
- package/pipeline/scripts/note-mcp-failure.mjs +272 -1
- package/pipeline/scripts/note-session.sh +62 -3
- package/pipeline/scripts/note-skill-use.mjs +58 -2
- package/pipeline/scripts/office-build.mjs +115 -1
- package/pipeline/scripts/office-memory.mjs +14 -5
- package/pipeline/scripts/pair.mjs +333 -0
- package/pipeline/scripts/pre-push-check.sh +1 -1
- package/pipeline/scripts/remote/cbor.mjs +128 -0
- package/pipeline/scripts/remote/contract.mjs +98 -0
- package/pipeline/scripts/remote/handler.mjs +330 -0
- package/pipeline/scripts/remote/handles.mjs +57 -0
- package/pipeline/scripts/remote/lifecycle.mjs +186 -0
- package/pipeline/scripts/remote/listener.mjs +204 -0
- package/pipeline/scripts/remote/lockout.mjs +103 -0
- package/pipeline/scripts/remote/nonces.mjs +61 -0
- package/pipeline/scripts/remote/pairing.mjs +519 -0
- package/pipeline/scripts/remote/qr-encode.mjs +459 -0
- package/pipeline/scripts/remote/store.mjs +191 -0
- package/pipeline/scripts/remote/transport.mjs +211 -0
- package/pipeline/scripts/remote/verbs.json +70 -0
- package/pipeline/scripts/remote/verbs.mjs +217 -0
- package/pipeline/scripts/remote/webauthn.mjs +169 -0
- package/pipeline/scripts/remote/wire.mjs +364 -0
- package/pipeline/scripts/remote-listener.mjs +83 -0
- package/pipeline/scripts/route-learn.mjs +4 -4
- package/pipeline/scripts/run-kill.mjs +1 -1
- package/pipeline/scripts/run-write.mjs +13 -2
- package/pipeline/scripts/runs-index.mjs +30 -3
- package/pipeline/scripts/search-logs.sh +9 -0
- package/pipeline/scripts/session-brief.mjs +458 -0
- package/pipeline/scripts/session-brief.sh +130 -0
- package/pipeline/scripts/skill-usage.mjs +16 -5
- package/pipeline/scripts/test-gap-rules/cpp.json +25 -0
- package/pipeline/scripts/test-gap-rules/csharp.json +20 -0
- package/pipeline/scripts/test-gap-rules/java.json +20 -0
- package/pipeline/scripts/test-gap-rules/rust.json +14 -0
- package/pipeline/scripts/token-budget-report.mjs +3 -2
- package/pipeline/scripts/uninstall.mjs +29 -0
- package/pipeline/scripts/usage-access.mjs +16 -31
- package/pipeline/scripts/usage-health.mjs +31 -62
- package/pipeline/scripts/usage-register-beacon.mjs +11 -22
- package/pipeline/scripts/usage-register.mjs +39 -29
- package/pipeline/scripts/usage-report.mjs +579 -178
- package/pipeline/scripts/validate-code-graph.mjs +361 -111
- package/pipeline/scripts/write-state.mjs +39 -0
- package/pipeline/skills/.skill-manifest.json +21 -17
- package/pipeline/skills/.skills-index.json +13 -2
- package/pipeline/skills/shared/README.md +5 -4
- package/pipeline/skills/shared/core/multi-agent-design-check/SKILL.md +1 -1
- package/pipeline/skills/shared/core/multi-agent-diff-explain/SKILL.md +3 -3
- package/pipeline/skills/shared/core/multi-agent-graph/SKILL.md +55 -21
- package/pipeline/skills/shared/core/multi-agent-pair/SKILL.md +41 -0
- package/pipeline/skills/shared/core/multi-agent-prune-prompts/SKILL.md +1 -1
- package/pipeline/skills/shared/core/multi-agent-sync/SKILL.md +3 -3
- package/pipeline/skills/shared/external/app-store-optimization/SKILL.md +2 -3
- package/pipeline/skills/shared/external/app-store-optimization/references/keyword-research-methodology.md +2 -2
- package/pipeline/skills/shared/external/app-store-optimization/references/product-page-variants.md +2 -2
- package/pipeline/skills/shared/external/app-store-review/SKILL.md +11 -4
- package/pipeline/skills/shared/external/build-settings-audit/SKILL.md +1 -1
- package/pipeline/skills/shared/external/build-time-benchmark/SKILL.md +5 -5
- package/pipeline/skills/shared/external/build-time-fixes/SKILL.md +5 -5
- package/pipeline/skills/shared/external/build-time-optimizer/SKILL.md +6 -6
- package/pipeline/skills/shared/external/free-llm-apis/references/providers.md +1 -0
- package/pipeline/skills/shared/external/ios-coding-standard/references/STANDARD.md +2 -2
- package/pipeline/skills/shared/external/ios-haptics/references/core-haptics.md +1 -1
- package/pipeline/skills/shared/external/localization-reuse-map/references/publish-and-snapshot.md +1 -1
- package/pipeline/skills/shared/external/package-build-audit/SKILL.md +3 -3
- package/pipeline/skills/shared/external/reverse-engineer-own-app/SKILL.md +2 -3
- package/pipeline/skills/shared/external/swift-compile-hotspots/SKILL.md +2 -2
- package/pipeline/skills/shared/external/weatherkit/SKILL.md +5 -6
- package/pipeline/skills/skills-index.md +3 -2
- package/docs/FIGMA_PIPELINE.md +0 -137
- package/pipeline/lib/identifier-scan.mjs +0 -156
- package/pipeline/scripts/_renamed-skills.mjs +0 -164
- package/pipeline/scripts/publish-staged.mjs +0 -324
- package/pipeline/skills/renamed.json +0 -30
- 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
|
|
2
|
-
//
|
|
1
|
+
// _http-post.mjs - POST a JSON body through node:https, with certificate
|
|
2
|
+
// verification that the environment cannot weaken.
|
|
3
3
|
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
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
|
-
//
|
|
11
|
-
//
|
|
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
|
-
|
|
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
|
|
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
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
|
50
|
-
*
|
|
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
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
93
|
-
|
|
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
|
-
*
|
|
99
|
-
*
|
|
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
|
|
115
|
-
|
|
119
|
+
const r = await send({
|
|
120
|
+
url,
|
|
116
121
|
headers: { "Content-Type": "application/json", ...headers },
|
|
117
122
|
body,
|
|
118
|
-
|
|
119
|
-
signal: ctrl.signal,
|
|
123
|
+
timeoutMs,
|
|
120
124
|
});
|
|
121
|
-
|
|
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
|
-
|
|
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);
|