@bridge_gpt/mcp-server 0.2.71 → 0.2.73
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/README.md +55 -17
- package/build/agent-launchers/claude-executor-adapter.js +22 -3
- package/build/agent-notes.js +171 -95
- package/build/agents.generated.js +7 -7
- package/build/bridge-permissions.js +31 -0
- package/build/bridge-worktree-inspection.js +237 -0
- package/build/check-evidence.js +6 -0
- package/build/ci-system-detection.js +50 -0
- package/build/ci-trigger-adapters.js +631 -0
- package/build/ci-trigger-install.js +106 -0
- package/build/claude-review-workflow.js +1 -1
- package/build/cli-help.js +6 -0
- package/build/codex-auto-recovery.js +126 -0
- package/build/codex-launcher-pin.js +33 -2
- package/build/codex-skill-adapter.js +5 -1
- package/build/command-host.js +33 -0
- package/build/commands.generated.js +7 -6
- package/build/conductor/bridge-api-client.js +1352 -50
- package/build/conductor/bring-up-facts.js +18 -5
- package/build/conductor/command-drift-production.js +42 -17
- package/build/conductor/command-drift.js +47 -0
- package/build/conductor/declare-blocked.js +554 -0
- package/build/conductor/doctor.js +187 -28
- package/build/conductor/driver-commands.js +141 -0
- package/build/conductor/driver-guard.js +277 -0
- package/build/conductor/driver-lapse.js +321 -0
- package/build/conductor/driver-register.js +176 -0
- package/build/conductor/driver-release.js +174 -0
- package/build/conductor/driver-session-state.js +315 -0
- package/build/conductor/epic-branch-ci-inspection.js +222 -29
- package/build/conductor/epic-implementer-cli.js +213 -13
- package/build/conductor/epic-server-database.js +162 -0
- package/build/conductor/epic-server-guidance.js +278 -0
- package/build/conductor/epic-server-journal.js +239 -0
- package/build/conductor/epic-server-processes.js +324 -0
- package/build/conductor/epic-server-recipe.js +397 -0
- package/build/conductor/epic-server-runtime.js +1207 -0
- package/build/conductor/epic-server-sfcc.js +107 -0
- package/build/conductor/epic-server-state.js +427 -0
- package/build/conductor/epic-server.js +594 -0
- package/build/conductor/gate-discovery.js +281 -10
- package/build/conductor/gate-settings-review.js +525 -5
- package/build/conductor/git-hooks-uninstall.js +112 -0
- package/build/conductor/git-hooks.js +81 -15
- package/build/conductor/guided-repair.js +10 -1
- package/build/conductor/install-doctor.js +2 -4
- package/build/conductor/launch-need-probes.js +6 -53
- package/build/conductor/launch-plan.js +318 -121
- package/build/conductor/local-merge.js +12 -1
- package/build/conductor/merge-execution-contract.js +1 -1
- package/build/conductor/merged-child-check.js +2 -1
- package/build/conductor/prerequisite-inputs.js +1213 -0
- package/build/conductor/readiness-assessment.js +93 -0
- package/build/conductor/readiness-cli.js +30 -9
- package/build/conductor/readiness-prerequisites.js +77 -5
- package/build/conductor/readiness-sections.js +146 -126
- package/build/conductor/readiness.js +21 -3
- package/build/conductor/recovery-cli.js +236 -15
- package/build/conductor/recovery-operations.js +34 -4
- package/build/conductor/repair-contract.js +33 -0
- package/build/conductor/tools.js +36 -4
- package/build/conductor/wait-run-attention.js +115 -0
- package/build/conductor/wait-run-cli.js +300 -21
- package/build/conductor/worker-database-doctor-inspector.js +34 -2
- package/build/conductor/worker-setup-tally.js +27 -0
- package/build/credential-store.js +96 -21
- package/build/dependency-install-declarations.js +212 -0
- package/build/docs.generated.js +4 -4
- package/build/doctor.js +91 -8
- package/build/drive-epic-help.js +23 -4
- package/build/drive-epic.js +1841 -340
- package/build/engine-paths.js +20 -0
- package/build/epic-branch-ci-summary.js +140 -0
- package/build/epic-capability-statement.js +107 -0
- package/build/epic-ci-workflow-drift.js +30 -15
- package/build/epic-ci-workflow-install.js +110 -42
- package/build/epic-ci-workflow-v2.js +274 -0
- package/build/epic-ci-workflow.js +38 -12
- package/build/epic-implementer-bin.js +2184 -52
- package/build/epic-launch-context.js +607 -0
- package/build/epic-launch-profile.js +1 -1
- package/build/epic-server-record.js +273 -0
- package/build/epic-shared/bridge-client.js +11 -3
- package/build/escalation-reachability.js +43 -0
- package/build/executor/ci-fix-test-runs.js +334 -0
- package/build/executor/cli.js +2 -0
- package/build/executor/completion-contract.js +24 -1
- package/build/executor/credentials.js +1 -1
- package/build/executor/delivery-observations.js +113 -0
- package/build/executor/delivery-outcome.js +30 -0
- package/build/executor/dependency-refresh-runner.js +132 -0
- package/build/executor/dependency-refresh.js +530 -0
- package/build/executor/deps.js +4 -0
- package/build/executor/env.js +119 -17
- package/build/executor/epic-server-context.js +141 -0
- package/build/executor/gate-qualification-job.js +127 -26
- package/build/executor/harness-coverage.js +19 -0
- package/build/executor/http-client.js +87 -6
- package/build/executor/index.js +2 -1
- package/build/executor/install-preflight.js +1 -1
- package/build/executor/job-runner.js +659 -87
- package/build/executor/likely-tests.js +94 -97
- package/build/executor/observation.js +8 -0
- package/build/executor/pre-pr-checks.js +363 -0
- package/build/executor/prompt-spec.js +127 -5
- package/build/executor/reconcile-overlap-job.js +5 -3
- package/build/executor/required-verification.js +28 -0
- package/build/executor/required-work-diagnostics.js +32 -0
- package/build/executor/required-work-ledger.js +955 -39
- package/build/executor/results.js +100 -0
- package/build/executor/service-discovery.js +42 -0
- package/build/executor/service-lifecycle.js +109 -2
- package/build/executor/service-uninstall.js +205 -0
- package/build/executor/service-unit.js +5 -3
- package/build/executor/terminal-mutation.js +8 -0
- package/build/executor/test-clock.js +3 -0
- package/build/executor/verification-hints.js +179 -0
- package/build/executor/worker-command.js +126 -5
- package/build/executor/worker-database-config.js +281 -0
- package/build/executor/worker-database-target.js +16 -12
- package/build/executor/worker-database.js +575 -116
- package/build/executor/worker-finalization.js +71 -10
- package/build/executor/worker-guard-hook.js +10 -2
- package/build/executor/worker-resources.js +25 -3
- package/build/executor/worker-verification-guidance.js +55 -5
- package/build/executor/worktree-inspection.js +42 -0
- package/build/executor/worktree.js +20 -1
- package/build/executor-launch.js +54 -2
- package/build/generated-assets-catalog.js +2 -2
- package/build/github-sign-in.js +1 -1
- package/build/index.js +1111 -381
- package/build/init.js +29 -14
- package/build/install-bridge-conductor-answers.js +465 -0
- package/build/install-bridge-conductor-apply.js +259 -0
- package/build/install-bridge-conductor-assessment.js +895 -0
- package/build/install-bridge-conductor-compact.js +161 -0
- package/build/install-bridge-conductor-contracts.js +63 -0
- package/build/install-bridge-conductor-gate.js +1383 -188
- package/build/install-bridge-conductor-setup.js +637 -92
- package/build/install-bridge-conductor.js +3163 -740
- package/build/install-bridge.js +601 -128
- package/build/install-maintenance.js +127 -0
- package/build/install-reexec.js +1 -1
- package/build/launcher-config-inspection.js +162 -1
- package/build/local-cleanup.js +59 -0
- package/build/mcp-grant-candidates.js +767 -0
- package/build/mcp-grant-doctor.js +63 -0
- package/build/mcp-grant.js +288 -0
- package/build/mcp-host-targets.js +8 -0
- package/build/mcp-identity.js +23 -0
- package/build/mcp-install-state.js +68 -2
- package/build/mcp-invoke.js +126 -13
- package/build/mcp-presets.js +107 -0
- package/build/mcp-provisioning.js +134 -2
- package/build/mcp-registration-doctor.js +31 -2
- package/build/mcp-server-invocation.js +6 -1
- package/build/merge-workflow-install.js +236 -111
- package/build/package-script-semantics.js +10 -0
- package/build/pipeline-utils.js +1 -1
- package/build/pipelines.generated.js +6 -6
- package/build/plan-discovery.js +97 -4
- package/build/plan-execution-ledger.js +248 -9
- package/build/plan-generation-io.js +262 -0
- package/build/plan-generation.js +424 -0
- package/build/plane/build-freshness.js +6 -1
- package/build/plane/cli.js +75 -9
- package/build/plane/plane-freshness.js +23 -7
- package/build/plane/preflight.js +50 -10
- package/build/plane/shutdown.js +19 -0
- package/build/plane/terminal-run-cleanup.js +23 -5
- package/build/plane/terminal-run-status.js +4 -0
- package/build/printed-remedy-commands.js +229 -15
- package/build/readiness-check.js +1 -1
- package/build/readiness-prerequisites.generated.js +311 -4
- package/build/readme.generated.js +1 -1
- package/build/repository-state-paths.js +38 -0
- package/build/repository-toolchains.js +50 -8
- package/build/run-unit-tests-launcher.js +8 -1
- package/build/setup-change-policy.js +32 -0
- package/build/setup-epic.js +1192 -198
- package/build/setup-progress.js +44 -0
- package/build/setup-question.js +180 -0
- package/build/start-tickets.js +4 -0
- package/build/test-command-detection.js +32 -88
- package/build/test-support/notes-fs.js +40 -0
- package/build/third-party-mcp-targets.js +30 -0
- package/build/ticket-delivery-enrollment.js +30 -8
- package/build/ticket-delivery-run-scope.js +128 -0
- package/build/upgrade-cli.js +85 -2
- package/build/v2-readiness-requirements.js +28 -1
- package/build/version.generated.js +3 -3
- package/build/worker-guard-hook-bin.js +2 -2
- package/build/worktrees.js +105 -0
- package/docs/EPIC-IMPLEMENTER-INSTALL.md +9 -1
- package/docs/EPIC-IMPLEMENTER.md +5 -0
- package/docs/epic-implementer/getting-started.md +42 -15
- package/docs/epic-implementer/self-hosting.md +14 -1
- package/package.json +2 -2
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BAPI-1638 — the shared apply of `install epic-implementer`.
|
|
3
|
+
*
|
|
4
|
+
* One function performs every write, for both the interactive CLI and
|
|
5
|
+
* `--answers`. It takes the approved operations as injected adapters over the
|
|
6
|
+
* existing `fix*` writers (it never imports the CLI), refuses the whole apply
|
|
7
|
+
* before any write when preflight failed, runs the operations in their fixed
|
|
8
|
+
* order, and returns each write's own result with its read-back.
|
|
9
|
+
*
|
|
10
|
+
* - A refusal refuses this apply, before any write, and names the fix. It adds
|
|
11
|
+
* no new way to stop a run.
|
|
12
|
+
* - An operation that fails, is refused on fresh evidence, or ends uncertain
|
|
13
|
+
* keeps its own status. Operations that depend on it are reported
|
|
14
|
+
* `unattempted`; independent ones still run. Nothing is rolled back.
|
|
15
|
+
* - The setup record is written here and nowhere else, only after approval.
|
|
16
|
+
*/
|
|
17
|
+
import { SETUP_RECORD_RELATIVE_PATH, } from "./install-bridge-conductor-contracts.js";
|
|
18
|
+
const NOT_COMPLETED = new Set(["failed", "refused", "uncertain", "unattempted"]);
|
|
19
|
+
const COMPLETE = new Set(["written", "unchanged", "declined"]);
|
|
20
|
+
function unexpectedFailure(key, target) {
|
|
21
|
+
return {
|
|
22
|
+
key,
|
|
23
|
+
status: "failed",
|
|
24
|
+
target,
|
|
25
|
+
reason: "the write stopped unexpectedly",
|
|
26
|
+
fix: "Rerun setup; finished writes report unchanged and only this one is tried again.",
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Apply the approved operations once, in order. A refusal returns before any
|
|
31
|
+
* operation runs. Each operation's adapter reads its current state first and
|
|
32
|
+
* reports `unchanged` when it already matches.
|
|
33
|
+
*/
|
|
34
|
+
export async function applyInstallProposal(input, deps) {
|
|
35
|
+
if (input.refusal !== null)
|
|
36
|
+
return { kind: "refused", refusal: input.refusal };
|
|
37
|
+
const results = [...(input.prior?.results ?? [])];
|
|
38
|
+
const completed = new Map(results.map((r) => [r.key, r]));
|
|
39
|
+
for (const operation of deps.operations) {
|
|
40
|
+
const blocker = (operation.dependsOn ?? []).find((key) => {
|
|
41
|
+
const r = completed.get(key);
|
|
42
|
+
return r !== undefined && NOT_COMPLETED.has(r.status);
|
|
43
|
+
});
|
|
44
|
+
if (blocker !== undefined) {
|
|
45
|
+
const r = {
|
|
46
|
+
key: operation.key,
|
|
47
|
+
status: "unattempted",
|
|
48
|
+
target: operation.key,
|
|
49
|
+
reason: `it depends on ${blocker}, which did not complete`,
|
|
50
|
+
fix: `Resolve ${blocker} first, then rerun setup with the same answers.`,
|
|
51
|
+
};
|
|
52
|
+
results.push(r);
|
|
53
|
+
completed.set(r.key, r);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
let produced;
|
|
57
|
+
try {
|
|
58
|
+
produced = await operation.run(completed);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
produced = unexpectedFailure(operation.key, operation.key);
|
|
62
|
+
}
|
|
63
|
+
for (const r of produced === null ? [] : Array.isArray(produced) ? produced : [produced]) {
|
|
64
|
+
const at = results.findIndex((existing) => existing.key === r.key);
|
|
65
|
+
if (at === -1)
|
|
66
|
+
results.push(r);
|
|
67
|
+
else
|
|
68
|
+
results[at] = r;
|
|
69
|
+
completed.set(r.key, r);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (deps.setupRecord) {
|
|
73
|
+
const record = await writeSetupRecord(input, results, deps.setupRecord);
|
|
74
|
+
if (record !== null)
|
|
75
|
+
results.push(record);
|
|
76
|
+
}
|
|
77
|
+
return { kind: "applied", result: { complete: results.every((r) => COMPLETE.has(r.status)), results } };
|
|
78
|
+
}
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
// The setup record
|
|
81
|
+
// ---------------------------------------------------------------------------
|
|
82
|
+
/** True when at least one approved write is in the proposal (or, without one, in the results). */
|
|
83
|
+
function hasApprovedWork(proposal, results) {
|
|
84
|
+
if (proposal !== null)
|
|
85
|
+
return proposal.actions.some((a) => a.intent === "write");
|
|
86
|
+
// Interactive: each write was approved at its own question, so only a write that happened counts.
|
|
87
|
+
return results.some((r) => r.status === "written");
|
|
88
|
+
}
|
|
89
|
+
/** Secret-free record text. Deterministic: no timestamps, so an identical record is never rewritten. */
|
|
90
|
+
export function renderSetupRecord(proposal, digest, results) {
|
|
91
|
+
const lines = [
|
|
92
|
+
"# Epic Implementer setup record",
|
|
93
|
+
"",
|
|
94
|
+
"Written by `install epic-implementer` after approval. It holds the approved proposal and what each",
|
|
95
|
+
"write read back. It never holds a secret: credentials appear only as references.",
|
|
96
|
+
"",
|
|
97
|
+
"## Approved proposal",
|
|
98
|
+
"",
|
|
99
|
+
];
|
|
100
|
+
if (proposal === null) {
|
|
101
|
+
lines.push("Interactive setup: each consequential write was approved at its own question. The answers", "below are those responses in the same answers shape `--answers` takes (no digest: they were", "not shown as one proposal).", "", "```json", JSON.stringify(interactiveAnswers(results), null, 2), "```", "");
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
lines.push(`- Repository: ${proposal.identity.repo_name}`);
|
|
105
|
+
if (proposal.identity.provider_repository !== null)
|
|
106
|
+
lines.push(`- Provider repository: ${proposal.identity.provider_repository}`);
|
|
107
|
+
lines.push(`- Bridge destination: ${proposal.identity.destination}`);
|
|
108
|
+
lines.push(`- Credential binding: ${proposal.identity.credential_binding}`);
|
|
109
|
+
if (digest !== null)
|
|
110
|
+
lines.push(`- proposal_digest: \`${digest}\``);
|
|
111
|
+
// The approved effect is recorded structurally (action, target, condition). Shown sentences
|
|
112
|
+
// change once a write is settled, and the record must not be rewritten for wording alone.
|
|
113
|
+
lines.push("", "| Answer key | Decision | Approved effect |", "|---|---|---|");
|
|
114
|
+
for (const action of proposal.actions) {
|
|
115
|
+
const decision = proposal.decisions.find((d) => d.key === action.key)?.decision;
|
|
116
|
+
const effect = action.effect === null ? "none" : `${action.effect.action} → ${action.effect.target}${action.effect.condition !== undefined ? ` (${action.effect.condition})` : ""}`;
|
|
117
|
+
lines.push(`| ${action.key} | ${describeDecision(decision)} | ${effect.replace(/\|/g, "\\|")} |`);
|
|
118
|
+
}
|
|
119
|
+
lines.push("");
|
|
120
|
+
}
|
|
121
|
+
lines.push("## Read-back", "", "| Write | Status | Target | Detail |", "|---|---|---|---|");
|
|
122
|
+
for (const r of results) {
|
|
123
|
+
if (r.key === "setup_record")
|
|
124
|
+
continue;
|
|
125
|
+
const detail = [r.reason, r.progress !== undefined ? `progress ${r.progress}` : undefined, r.phase !== undefined ? `phase ${r.phase ?? "unknown"}` : undefined]
|
|
126
|
+
.filter((p) => p !== undefined)
|
|
127
|
+
.join("; ");
|
|
128
|
+
// `written` and `unchanged` both mean the approved state is in place. Such a row shows one
|
|
129
|
+
// word, the approved target, and no run-specific detail, so a replay does not rewrite the record.
|
|
130
|
+
// BAPI-1659: an opened or reused CI pull request is `proposed`, not coverage. This is rendering
|
|
131
|
+
// only: the machine status stays `written` or `unchanged`, and the pull request stays named.
|
|
132
|
+
if (r.key === "epic_ci_change" && (r.status === "written" || r.status === "unchanged") && r.read_back?.state === "proposed") {
|
|
133
|
+
const pr = typeof r.read_back.pull_request === "string" ? `pull request ${r.read_back.pull_request}; ` : "";
|
|
134
|
+
lines.push(`| ${r.key} | proposed | ${r.target} | ${`${pr}not merged yet; checks start once you merge it`.replace(/\|/g, "\\|")} |`);
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
const inPlace = r.status === "written" || r.status === "unchanged";
|
|
138
|
+
const shown = inPlace ? "in place" : r.status;
|
|
139
|
+
const target = inPlace ? proposal?.actions.find((a) => a.key === r.key)?.effect?.target ?? r.target : r.target;
|
|
140
|
+
const shownDetail = inPlace ? "" : detail;
|
|
141
|
+
lines.push(`| ${r.key} | ${shown} | ${target} | ${shownDetail.replace(/\|/g, "\\|")} |`);
|
|
142
|
+
}
|
|
143
|
+
lines.push("");
|
|
144
|
+
return lines.join("\n");
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* The interactive responses as an answers object: an approved write that ran is
|
|
148
|
+
* `approve`, a declined one `decline`. Only keys whose question was asked appear.
|
|
149
|
+
* Selections and references are not reconstructed: their values stay with the
|
|
150
|
+
* writer that received them.
|
|
151
|
+
*/
|
|
152
|
+
export function interactiveAnswers(results) {
|
|
153
|
+
const answers = {};
|
|
154
|
+
for (const r of results) {
|
|
155
|
+
if (r.key === "setup_record")
|
|
156
|
+
continue;
|
|
157
|
+
if (r.status === "written")
|
|
158
|
+
answers[r.key] = r.key === "epic_branch_ci" ? String(r.read_back?.decision ?? "include") : "approve";
|
|
159
|
+
else if (r.status === "declined")
|
|
160
|
+
answers[r.key] = "decline";
|
|
161
|
+
}
|
|
162
|
+
return answers;
|
|
163
|
+
}
|
|
164
|
+
function describeDecision(decision) {
|
|
165
|
+
if (decision === undefined)
|
|
166
|
+
return "-";
|
|
167
|
+
switch (decision.kind) {
|
|
168
|
+
case "option": return decision.option;
|
|
169
|
+
case "decline": return "decline";
|
|
170
|
+
case "selection": return decision.ids.length === 0 ? "none selected" : `${decision.ids.length} selected`;
|
|
171
|
+
case "reference": return decision.reference.kind === "env" ? `reference env:${decision.reference.name}` : `reference credential_store:${decision.reference.target}`;
|
|
172
|
+
case "command": return "owner command";
|
|
173
|
+
case "epic_server_sfcc": return "sfcc_shared_active";
|
|
174
|
+
case "profile": return `profile ${decision.name}`;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
async function writeSetupRecord(input, results, writer) {
|
|
178
|
+
// Declining everything writes nothing.
|
|
179
|
+
if (!hasApprovedWork(input.proposal, results))
|
|
180
|
+
return null;
|
|
181
|
+
const text = renderSetupRecord(input.proposal, input.digest, results);
|
|
182
|
+
try {
|
|
183
|
+
const current = await writer.read();
|
|
184
|
+
if (current === text)
|
|
185
|
+
return { key: "setup_record", status: "unchanged", target: writer.path };
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
// An unreadable record is simply rewritten below.
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
await writer.write(text);
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
return {
|
|
195
|
+
key: "setup_record",
|
|
196
|
+
status: "failed",
|
|
197
|
+
target: writer.path,
|
|
198
|
+
reason: "the setup record could not be written; the configuration writes above are kept",
|
|
199
|
+
fix: "Check the docs directory is writable, then rerun setup with the same answers to write the record.",
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
if ((await writer.read()) !== text) {
|
|
204
|
+
return { key: "setup_record", status: "uncertain", target: writer.path, reason: "the record did not read back as written", fix: "Check the file, then rerun setup." };
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
return { key: "setup_record", status: "uncertain", target: writer.path, reason: "the record could not be read back", fix: "Check the file, then rerun setup." };
|
|
209
|
+
}
|
|
210
|
+
return { key: "setup_record", status: "written", target: writer.path };
|
|
211
|
+
}
|
|
212
|
+
/** The fixed record path under `docs_dir`. */
|
|
213
|
+
export function setupRecordPath(docsDir, join) {
|
|
214
|
+
return join(docsDir, SETUP_RECORD_RELATIVE_PATH);
|
|
215
|
+
}
|
|
216
|
+
function isMissing(error) {
|
|
217
|
+
return error?.code === "ENOENT";
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* The record writer under `<docs_dir>/bridge-setup/`. It refuses to follow a
|
|
221
|
+
* link: the record directory and file must be real, and are created only inside
|
|
222
|
+
* `docs_dir`. The text is written to a sibling and renamed into place.
|
|
223
|
+
*/
|
|
224
|
+
export function createSetupRecordWriter(docsDir, fs, pathOps) {
|
|
225
|
+
const file = setupRecordPath(docsDir, pathOps.join);
|
|
226
|
+
const dir = pathOps.dirname(file);
|
|
227
|
+
const assertNotLink = async (p, kind) => {
|
|
228
|
+
try {
|
|
229
|
+
const st = await fs.lstat(p);
|
|
230
|
+
if (st.isSymbolicLink() || (kind === "file" ? !st.isFile() : !st.isDirectory())) {
|
|
231
|
+
throw new Error("setup record path is not a plain " + kind);
|
|
232
|
+
}
|
|
233
|
+
return true;
|
|
234
|
+
}
|
|
235
|
+
catch (error) {
|
|
236
|
+
if (isMissing(error))
|
|
237
|
+
return false;
|
|
238
|
+
throw error;
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
return {
|
|
242
|
+
path: file,
|
|
243
|
+
read: async () => {
|
|
244
|
+
if (!(await assertNotLink(file, "file")))
|
|
245
|
+
return null;
|
|
246
|
+
return fs.readFile(file, "utf-8");
|
|
247
|
+
},
|
|
248
|
+
write: async (text) => {
|
|
249
|
+
if (!(await assertNotLink(dir, "directory"))) {
|
|
250
|
+
await fs.mkdir(dir, { recursive: true });
|
|
251
|
+
await assertNotLink(dir, "directory");
|
|
252
|
+
}
|
|
253
|
+
await assertNotLink(file, "file");
|
|
254
|
+
const temp = `${file}.tmp-${process.pid}`;
|
|
255
|
+
await fs.writeFile(temp, text, { encoding: "utf-8", mode: 0o644 });
|
|
256
|
+
await fs.rename(temp, file);
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
}
|