@ricsam/r5d-worker 0.0.137 → 0.0.139
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 +4 -94
- package/dist/cjs/package.json +1 -1
- package/dist/mjs/main.mjs +46 -7543
- package/dist/mjs/package.json +1 -1
- package/dist/mjs/personal/action-scheduler.mjs +31 -0
- package/dist/mjs/personal/client.mjs +215 -0
- package/dist/mjs/personal/runtime.mjs +359 -0
- package/dist/mjs/personal/tcp.mjs +217 -0
- package/dist/mjs/runtime/adapter.mjs +42 -0
- package/dist/mjs/runtime/client.mjs +95 -0
- package/dist/mjs/runtime/daemon.mjs +131 -0
- package/dist/mjs/runtime/executor.mjs +436 -0
- package/dist/mjs/runtime/index.mjs +15 -0
- package/dist/mjs/runtime/protocol.mjs +139 -0
- package/dist/mjs/runtime/pty-host.mjs +156 -0
- package/dist/mjs/runtime/pty.mjs +127 -0
- package/dist/mjs/runtime/releases/artifacts.mjs +201 -0
- package/dist/mjs/runtime/releases/grants.mjs +93 -0
- package/dist/mjs/runtime/releases/main.mjs +101 -0
- package/dist/mjs/runtime/releases/manager.mjs +541 -0
- package/dist/mjs/runtime/releases/process.mjs +88 -0
- package/dist/mjs/runtime/releases/retirement.mjs +18 -0
- package/dist/mjs/runtime/releases/rpc-client.mjs +184 -0
- package/dist/mjs/runtime/releases/rpc-main.mjs +213 -0
- package/dist/mjs/runtime/releases/rpc-protocol.mjs +103 -0
- package/dist/mjs/runtime/storage.mjs +156 -0
- package/dist/mjs/runtime/workspace/artifacts.mjs +121 -0
- package/dist/mjs/runtime/workspace/authority.mjs +1355 -0
- package/dist/mjs/runtime/workspace/contracts.mjs +60 -0
- package/dist/mjs/runtime/workspace/file-write.mjs +23 -0
- package/dist/mjs/runtime/workspace/files.mjs +308 -0
- package/dist/mjs/runtime/workspace/http-body.mjs +45 -0
- package/dist/mjs/runtime/workspace/storage-client.mjs +59 -0
- package/dist/mjs/runtime/workspace/storage-wire.mjs +53 -0
- package/dist/types/main.d.ts +0 -1167
- package/dist/types/personal/action-scheduler.d.ts +23 -0
- package/dist/types/personal/client.d.ts +14 -0
- package/dist/types/personal/runtime.d.ts +121 -0
- package/dist/types/personal/tcp.d.ts +14 -0
- package/dist/types/runtime/client.d.ts +3 -1
- package/dist/types/runtime/executor.d.ts +6 -1
- package/dist/types/runtime/protocol.d.ts +176 -4
- package/dist/types/runtime/pty.d.ts +1 -0
- package/dist/types/runtime/releases/artifacts.d.ts +51 -0
- package/dist/types/runtime/releases/grants.d.ts +16 -0
- package/dist/types/runtime/releases/manager.d.ts +145 -0
- package/dist/types/runtime/releases/process.d.ts +14 -0
- package/dist/types/runtime/releases/retirement.d.ts +15 -0
- package/dist/types/runtime/releases/rpc-client.d.ts +52 -0
- package/dist/types/runtime/releases/rpc-main.d.ts +10 -0
- package/dist/types/runtime/releases/rpc-protocol.d.ts +1139 -0
- package/dist/types/runtime/workspace/artifacts.d.ts +30 -0
- package/dist/types/runtime/workspace/authority.d.ts +338 -0
- package/dist/types/runtime/workspace/contracts.d.ts +86 -0
- package/dist/types/runtime/workspace/file-write.d.ts +14 -0
- package/dist/types/runtime/workspace/files.d.ts +21 -0
- package/dist/types/runtime/workspace/http-body.d.ts +9 -0
- package/dist/types/runtime/workspace/storage-client.d.ts +23 -0
- package/dist/types/runtime/workspace/storage-wire.d.ts +138 -0
- package/package.json +8 -6
- package/dist/cjs/atomic-rename.cjs +0 -303
- package/dist/cjs/browser-upload.cjs +0 -73
- package/dist/cjs/cli-update.cjs +0 -108
- package/dist/cjs/command-launcher.cjs +0 -423
- package/dist/cjs/control-command-policy.cjs +0 -177
- package/dist/cjs/git-blob-hash.cjs +0 -41
- package/dist/cjs/git-identity.cjs +0 -39
- package/dist/cjs/git-process-environment.cjs +0 -133
- package/dist/cjs/inline-output.cjs +0 -62
- package/dist/cjs/main.cjs +0 -7517
- package/dist/cjs/managed-paths.cjs +0 -215
- package/dist/cjs/plan-lint.cjs +0 -165
- package/dist/cjs/plan-parser.cjs +0 -127
- package/dist/cjs/plan-paths.cjs +0 -53
- package/dist/cjs/port-forward-client.cjs +0 -206
- package/dist/cjs/process-tree.cjs +0 -117
- package/dist/cjs/project-checkout-garbage.cjs +0 -219
- package/dist/cjs/project-mirror-fetch-policy.cjs +0 -82
- package/dist/cjs/project-mirror-refs-token.cjs +0 -85
- package/dist/cjs/project-workspace-state.cjs +0 -972
- package/dist/cjs/project-worktrees.cjs +0 -1713
- package/dist/cjs/pty-output-coalescer.cjs +0 -87
- package/dist/cjs/recovery-journal-protocol.cjs +0 -56
- package/dist/cjs/recovery-journal-runtime.cjs +0 -133
- package/dist/cjs/recovery-journal-thread.cjs +0 -9
- package/dist/cjs/recovery-journal.cjs +0 -742
- package/dist/cjs/recovery-output-window.cjs +0 -77
- package/dist/cjs/recovery-protocol.cjs +0 -31
- package/dist/cjs/recovery-store.cjs +0 -252
- package/dist/cjs/registry-auth.cjs +0 -310
- package/dist/cjs/repository-transition-policy.cjs +0 -49
- package/dist/cjs/runtime-version.cjs +0 -88
- package/dist/cjs/session-file-mutations.cjs +0 -61
- package/dist/cjs/supervisor.cjs +0 -147
- package/dist/cjs/three-way-merge.cjs +0 -346
- package/dist/cjs/working-tree-mirror.cjs +0 -1872
- package/dist/cjs/workspace-automatic-sync-policy.cjs +0 -79
- package/dist/cjs/workspace-branch-incarnation-policy.cjs +0 -37
- package/dist/cjs/workspace-command-sync-policy.cjs +0 -112
- package/dist/cjs/workspace-command-targets.cjs +0 -63
- package/dist/cjs/workspace-filesystem-executor-thread.cjs +0 -36
- package/dist/cjs/workspace-filesystem-executor.cjs +0 -327
- package/dist/cjs/workspace-filesystem-job-types.cjs +0 -144
- package/dist/cjs/workspace-filesystem-jobs.cjs +0 -59
- package/dist/cjs/workspace-git-sync.cjs +0 -3595
- package/dist/cjs/workspace-hydration-ledger.cjs +0 -83
- package/dist/cjs/workspace-hydration-merge.cjs +0 -448
- package/dist/cjs/workspace-hydration-recovery-state.cjs +0 -53
- package/dist/cjs/workspace-incident-state.cjs +0 -37
- package/dist/cjs/workspace-merge-projection.cjs +0 -628
- package/dist/cjs/workspace-mount-boundary.cjs +0 -71
- package/dist/cjs/workspace-mount-hold-fence.cjs +0 -120
- package/dist/cjs/workspace-mutation-gate.cjs +0 -127
- package/dist/cjs/workspace-path-move.cjs +0 -195
- package/dist/cjs/workspace-preserve-only-policy.cjs +0 -36
- package/dist/cjs/workspace-project-config-policy.cjs +0 -53
- package/dist/cjs/workspace-projection-ledger.cjs +0 -81
- package/dist/cjs/workspace-publication-evidence.cjs +0 -46
- package/dist/cjs/workspace-sync-coalescer.cjs +0 -58
- package/dist/mjs/atomic-rename.mjs +0 -261
- package/dist/mjs/browser-upload.mjs +0 -42
- package/dist/mjs/command-launcher.mjs +0 -393
- package/dist/mjs/control-command-policy.mjs +0 -146
- package/dist/mjs/git-blob-hash.mjs +0 -16
- package/dist/mjs/git-identity.mjs +0 -15
- package/dist/mjs/git-process-environment.mjs +0 -105
- package/dist/mjs/inline-output.mjs +0 -37
- package/dist/mjs/managed-paths.mjs +0 -174
- package/dist/mjs/plan-lint.mjs +0 -129
- package/dist/mjs/plan-parser.mjs +0 -94
- package/dist/mjs/plan-paths.mjs +0 -25
- package/dist/mjs/port-forward-client.mjs +0 -172
- package/dist/mjs/project-checkout-garbage.mjs +0 -178
- package/dist/mjs/project-mirror-fetch-policy.mjs +0 -56
- package/dist/mjs/project-mirror-refs-token.mjs +0 -53
- package/dist/mjs/project-workspace-state.mjs +0 -937
- package/dist/mjs/project-worktrees.mjs +0 -1657
- package/dist/mjs/pty-output-coalescer.mjs +0 -61
- package/dist/mjs/recovery-journal-protocol.mjs +0 -30
- package/dist/mjs/recovery-journal-runtime.mjs +0 -112
- package/dist/mjs/recovery-journal-thread.mjs +0 -8
- package/dist/mjs/recovery-journal.mjs +0 -694
- package/dist/mjs/recovery-output-window.mjs +0 -53
- package/dist/mjs/recovery-protocol.mjs +0 -6
- package/dist/mjs/recovery-store.mjs +0 -217
- package/dist/mjs/registry-auth.mjs +0 -269
- package/dist/mjs/repository-transition-policy.mjs +0 -22
- package/dist/mjs/runtime-version.mjs +0 -54
- package/dist/mjs/session-file-mutations.mjs +0 -37
- package/dist/mjs/supervisor.mjs +0 -114
- package/dist/mjs/three-way-merge.mjs +0 -318
- package/dist/mjs/working-tree-mirror.mjs +0 -1817
- package/dist/mjs/workspace-automatic-sync-policy.mjs +0 -48
- package/dist/mjs/workspace-branch-incarnation-policy.mjs +0 -13
- package/dist/mjs/workspace-command-sync-policy.mjs +0 -84
- package/dist/mjs/workspace-command-targets.mjs +0 -37
- package/dist/mjs/workspace-filesystem-executor-thread.mjs +0 -38
- package/dist/mjs/workspace-filesystem-executor.mjs +0 -287
- package/dist/mjs/workspace-filesystem-job-types.mjs +0 -116
- package/dist/mjs/workspace-filesystem-jobs.mjs +0 -55
- package/dist/mjs/workspace-git-sync.mjs +0 -3553
- package/dist/mjs/workspace-hydration-ledger.mjs +0 -58
- package/dist/mjs/workspace-hydration-merge.mjs +0 -414
- package/dist/mjs/workspace-hydration-recovery-state.mjs +0 -29
- package/dist/mjs/workspace-incident-state.mjs +0 -12
- package/dist/mjs/workspace-merge-projection.mjs +0 -594
- package/dist/mjs/workspace-mount-boundary.mjs +0 -37
- package/dist/mjs/workspace-mount-hold-fence.mjs +0 -95
- package/dist/mjs/workspace-mutation-gate.mjs +0 -103
- package/dist/mjs/workspace-path-move.mjs +0 -160
- package/dist/mjs/workspace-preserve-only-policy.mjs +0 -11
- package/dist/mjs/workspace-project-config-policy.mjs +0 -27
- package/dist/mjs/workspace-projection-ledger.mjs +0 -57
- package/dist/mjs/workspace-publication-evidence.mjs +0 -21
- package/dist/mjs/workspace-sync-coalescer.mjs +0 -34
- package/dist/types/atomic-rename.d.ts +0 -78
- package/dist/types/browser-upload.d.ts +0 -7
- package/dist/types/command-launcher.d.ts +0 -104
- package/dist/types/control-command-policy.d.ts +0 -53
- package/dist/types/git-blob-hash.d.ts +0 -10
- package/dist/types/git-identity.d.ts +0 -9
- package/dist/types/git-process-environment.d.ts +0 -9
- package/dist/types/inline-output.d.ts +0 -3
- package/dist/types/managed-paths.d.ts +0 -19
- package/dist/types/plan-lint.d.ts +0 -16
- package/dist/types/plan-parser.d.ts +0 -38
- package/dist/types/plan-paths.d.ts +0 -36
- package/dist/types/port-forward-client.d.ts +0 -8
- package/dist/types/project-checkout-garbage.d.ts +0 -86
- package/dist/types/project-mirror-fetch-policy.d.ts +0 -84
- package/dist/types/project-mirror-refs-token.d.ts +0 -53
- package/dist/types/project-workspace-state.d.ts +0 -188
- package/dist/types/project-worktrees.d.ts +0 -397
- package/dist/types/pty-output-coalescer.d.ts +0 -20
- package/dist/types/recovery-journal-protocol.d.ts +0 -35
- package/dist/types/recovery-journal-runtime.d.ts +0 -12
- package/dist/types/recovery-journal-stall-fixture.d.ts +0 -1
- package/dist/types/recovery-journal-thread.d.ts +0 -1
- package/dist/types/recovery-journal.d.ts +0 -248
- package/dist/types/recovery-output-window.d.ts +0 -19
- package/dist/types/recovery-protocol.d.ts +0 -59
- package/dist/types/recovery-store.d.ts +0 -52
- package/dist/types/registry-auth.d.ts +0 -47
- package/dist/types/repository-transition-policy.d.ts +0 -26
- package/dist/types/runtime-version.d.ts +0 -1
- package/dist/types/session-file-mutations.d.ts +0 -22
- package/dist/types/supervisor-daemonized-fixture.d.ts +0 -1
- package/dist/types/supervisor-launcher-cleanup-fixture.d.ts +0 -1
- package/dist/types/supervisor-signal-fixture.d.ts +0 -1
- package/dist/types/supervisor.d.ts +0 -23
- package/dist/types/three-way-merge.d.ts +0 -77
- package/dist/types/working-tree-mirror.d.ts +0 -424
- package/dist/types/workspace-automatic-sync-policy.d.ts +0 -57
- package/dist/types/workspace-branch-incarnation-policy.d.ts +0 -14
- package/dist/types/workspace-command-sync-policy.d.ts +0 -57
- package/dist/types/workspace-command-targets.d.ts +0 -37
- package/dist/types/workspace-filesystem-executor-thread.d.ts +0 -1
- package/dist/types/workspace-filesystem-executor.d.ts +0 -123
- package/dist/types/workspace-filesystem-job-types.d.ts +0 -302
- package/dist/types/workspace-filesystem-jobs.d.ts +0 -7
- package/dist/types/workspace-git-sync.d.ts +0 -514
- package/dist/types/workspace-hydration-ledger.d.ts +0 -76
- package/dist/types/workspace-hydration-merge.d.ts +0 -103
- package/dist/types/workspace-hydration-recovery-state.d.ts +0 -10
- package/dist/types/workspace-incident-state.d.ts +0 -19
- package/dist/types/workspace-merge-projection.d.ts +0 -69
- package/dist/types/workspace-mount-boundary.d.ts +0 -10
- package/dist/types/workspace-mount-hold-fence.d.ts +0 -42
- package/dist/types/workspace-mutation-gate.d.ts +0 -42
- package/dist/types/workspace-path-move.d.ts +0 -21
- package/dist/types/workspace-preserve-only-policy.d.ts +0 -15
- package/dist/types/workspace-project-config-policy.d.ts +0 -48
- package/dist/types/workspace-projection-ledger.d.ts +0 -59
- package/dist/types/workspace-publication-evidence.d.ts +0 -17
- package/dist/types/workspace-sync-coalescer.d.ts +0 -28
- /package/dist/types/{credential-authority-lock-fixture.d.ts → runtime/releases/main.d.ts} +0 -0
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var repository_transition_policy_exports = {};
|
|
20
|
-
__export(repository_transition_policy_exports, {
|
|
21
|
-
assertRepositoryExecutionEnabled: () => assertRepositoryExecutionEnabled,
|
|
22
|
-
assertRepositoryTransitionState: () => assertRepositoryTransitionState,
|
|
23
|
-
enabledRepositoryTransitionRequiresReseed: () => enabledRepositoryTransitionRequiresReseed,
|
|
24
|
-
repositoryMirrorWritesAllowed: () => repositoryMirrorWritesAllowed
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(repository_transition_policy_exports);
|
|
27
|
-
function assertRepositoryTransitionState(project) {
|
|
28
|
-
if (project.repositoryTransitionId !== null && (typeof project.repositoryTransitionId !== "string" || !/^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/.test(project.repositoryTransitionId)) || typeof project.executionDisabled !== "boolean" || typeof project.mirrorWritesDisabled !== "boolean") {
|
|
29
|
-
throw new Error(`Project ${project.projectId} has invalid repository transition state`);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
function assertRepositoryExecutionEnabled(project) {
|
|
33
|
-
if (project.executionDisabled) {
|
|
34
|
-
throw new Error(`Project ${project.projectId} execution is disabled while its repository connection is transitioning`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
function repositoryMirrorWritesAllowed(project) {
|
|
38
|
-
return project?.executionDisabled !== true && project?.mirrorWritesDisabled !== true;
|
|
39
|
-
}
|
|
40
|
-
function enabledRepositoryTransitionRequiresReseed(input) {
|
|
41
|
-
return !input.project.executionDisabled && (!input.lastEnabled.known || input.lastEnabled.transitionId !== input.project.repositoryTransitionId);
|
|
42
|
-
}
|
|
43
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
-
0 && (module.exports = {
|
|
45
|
-
assertRepositoryExecutionEnabled,
|
|
46
|
-
assertRepositoryTransitionState,
|
|
47
|
-
enabledRepositoryTransitionRequiresReseed,
|
|
48
|
-
repositoryMirrorWritesAllowed
|
|
49
|
-
});
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var runtime_version_exports = {};
|
|
30
|
-
__export(runtime_version_exports, {
|
|
31
|
-
WORKER_RUNTIME_VERSION: () => WORKER_RUNTIME_VERSION
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(runtime_version_exports);
|
|
34
|
-
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
35
|
-
var import_node_path = __toESM(require("node:path"), 1);
|
|
36
|
-
const WORKER_PACKAGE_NAME = "@ricsam/r5d-worker";
|
|
37
|
-
function readVersionFile(filePath) {
|
|
38
|
-
try {
|
|
39
|
-
const version = import_node_fs.default.readFileSync(filePath, "utf8").trim();
|
|
40
|
-
return version || null;
|
|
41
|
-
} catch {
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
function readInstalledPackageVersion(packageJsonPath) {
|
|
46
|
-
try {
|
|
47
|
-
const parsed = JSON.parse(import_node_fs.default.readFileSync(packageJsonPath, "utf8"));
|
|
48
|
-
if (parsed.name === WORKER_PACKAGE_NAME && typeof parsed.version === "string" && parsed.version.trim()) {
|
|
49
|
-
return parsed.version.trim();
|
|
50
|
-
}
|
|
51
|
-
} catch {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
function resolveEntrypointPath(entrypoint) {
|
|
57
|
-
const resolved = import_node_path.default.resolve(entrypoint);
|
|
58
|
-
try {
|
|
59
|
-
return import_node_fs.default.realpathSync.native(resolved);
|
|
60
|
-
} catch {
|
|
61
|
-
return resolved;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
function readWorkerVersion() {
|
|
65
|
-
const entrypoint = process.argv[1] ? resolveEntrypointPath(process.argv[1]) : null;
|
|
66
|
-
let current = entrypoint ? import_node_path.default.dirname(entrypoint) : process.cwd();
|
|
67
|
-
for (let index = 0; index < 12; index += 1) {
|
|
68
|
-
const packageVersion = readInstalledPackageVersion(import_node_path.default.join(current, "package.json"));
|
|
69
|
-
if (packageVersion) {
|
|
70
|
-
return packageVersion;
|
|
71
|
-
}
|
|
72
|
-
const sourceVersion = readVersionFile(import_node_path.default.join(current, "VERSION.txt"));
|
|
73
|
-
if (sourceVersion && import_node_path.default.basename(current) === "packages") {
|
|
74
|
-
return sourceVersion;
|
|
75
|
-
}
|
|
76
|
-
const parent = import_node_path.default.dirname(current);
|
|
77
|
-
if (parent === current) {
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
current = parent;
|
|
81
|
-
}
|
|
82
|
-
return "unknown";
|
|
83
|
-
}
|
|
84
|
-
const WORKER_RUNTIME_VERSION = readWorkerVersion();
|
|
85
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
-
0 && (module.exports = {
|
|
87
|
-
WORKER_RUNTIME_VERSION
|
|
88
|
-
});
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var session_file_mutations_exports = {};
|
|
20
|
-
__export(session_file_mutations_exports, {
|
|
21
|
-
SessionFileMutationTracker: () => SessionFileMutationTracker
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(session_file_mutations_exports);
|
|
24
|
-
class SessionFileMutationTracker {
|
|
25
|
-
inFlight = /* @__PURE__ */ new Map();
|
|
26
|
-
/** Register a started mutation; it is forgotten when it settles, however it settles. */
|
|
27
|
-
track(sessionId, mutation) {
|
|
28
|
-
let mutations = this.inFlight.get(sessionId);
|
|
29
|
-
if (!mutations) {
|
|
30
|
-
mutations = /* @__PURE__ */ new Set();
|
|
31
|
-
this.inFlight.set(sessionId, mutations);
|
|
32
|
-
}
|
|
33
|
-
mutations.add(mutation);
|
|
34
|
-
const forget = () => {
|
|
35
|
-
const current = this.inFlight.get(sessionId);
|
|
36
|
-
if (!current) return;
|
|
37
|
-
current.delete(mutation);
|
|
38
|
-
if (current.size === 0) this.inFlight.delete(sessionId);
|
|
39
|
-
};
|
|
40
|
-
mutation.then(forget, forget);
|
|
41
|
-
return mutation;
|
|
42
|
-
}
|
|
43
|
-
count(sessionId) {
|
|
44
|
-
return this.inFlight.get(sessionId)?.size ?? 0;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Resolves once every mutation tracked for the session at the time of the
|
|
48
|
-
* call has settled. Mutations started later are not joined: the session's
|
|
49
|
-
* cancellation marker, recorded before this is awaited, makes their
|
|
50
|
-
* admission recheck refuse them.
|
|
51
|
-
*/
|
|
52
|
-
settled(sessionId) {
|
|
53
|
-
const pending = [...this.inFlight.get(sessionId) ?? []];
|
|
54
|
-
if (pending.length === 0) return Promise.resolve();
|
|
55
|
-
return Promise.allSettled(pending).then(() => void 0);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
59
|
-
0 && (module.exports = {
|
|
60
|
-
SessionFileMutationTracker
|
|
61
|
-
});
|
package/dist/cjs/supervisor.cjs
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var supervisor_exports = {};
|
|
20
|
-
__export(supervisor_exports, {
|
|
21
|
-
WORKER_CREDENTIAL_RESTART_EXIT_CODE: () => WORKER_CREDENTIAL_RESTART_EXIT_CODE,
|
|
22
|
-
WORKER_RECONNECT_DELAY_MS: () => WORKER_RECONNECT_DELAY_MS,
|
|
23
|
-
WORKER_RECONNECT_EXIT_CODE: () => WORKER_RECONNECT_EXIT_CODE,
|
|
24
|
-
WORKER_RECONNECT_JITTER_MS: () => WORKER_RECONNECT_JITTER_MS,
|
|
25
|
-
WORKER_RECONNECT_MAX_DELAY_MS: () => WORKER_RECONNECT_MAX_DELAY_MS,
|
|
26
|
-
WORKER_RELOAD_EXIT_CODE: () => WORKER_RELOAD_EXIT_CODE,
|
|
27
|
-
WORKER_RUNTIME_ENV: () => WORKER_RUNTIME_ENV,
|
|
28
|
-
isRetryableWorkerServerStatus: () => isRetryableWorkerServerStatus,
|
|
29
|
-
superviseWorkerRuntime: () => superviseWorkerRuntime,
|
|
30
|
-
workerReconnectDelayMs: () => workerReconnectDelayMs
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(supervisor_exports);
|
|
33
|
-
var import_node_os = require("node:os");
|
|
34
|
-
var import_process_tree = require("./process-tree.cjs");
|
|
35
|
-
const WORKER_RUNTIME_ENV = "R5D_WORKER_INTERNAL_RUNTIME";
|
|
36
|
-
const WORKER_RELOAD_EXIT_CODE = 75;
|
|
37
|
-
const WORKER_RECONNECT_EXIT_CODE = 76;
|
|
38
|
-
const WORKER_CREDENTIAL_RESTART_EXIT_CODE = 77;
|
|
39
|
-
const WORKER_RECONNECT_DELAY_MS = 2e3;
|
|
40
|
-
const WORKER_RECONNECT_JITTER_MS = 3e3;
|
|
41
|
-
const WORKER_RECONNECT_MAX_DELAY_MS = 3e4;
|
|
42
|
-
const SUPERVISOR_SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
43
|
-
function defaultRuntimeSpawner(argv, options) {
|
|
44
|
-
return Bun.spawn(argv, options);
|
|
45
|
-
}
|
|
46
|
-
function defaultRuntimeDelay(delayMs) {
|
|
47
|
-
return new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
48
|
-
}
|
|
49
|
-
function workerReconnectDelayMs(random = Math.random, attempt = 0) {
|
|
50
|
-
const sample = Math.max(0, Math.min(1, random()));
|
|
51
|
-
const exponent = Math.min(20, Math.max(0, Math.floor(attempt)));
|
|
52
|
-
const ceiling = Math.min(WORKER_RECONNECT_MAX_DELAY_MS, (WORKER_RECONNECT_DELAY_MS + WORKER_RECONNECT_JITTER_MS) * 2 ** exponent);
|
|
53
|
-
const floor = Math.min(WORKER_RECONNECT_DELAY_MS * 2 ** exponent, ceiling * 0.4);
|
|
54
|
-
return floor + Math.floor(sample * (ceiling - floor));
|
|
55
|
-
}
|
|
56
|
-
async function defaultRuntimeReaper(runtime) {
|
|
57
|
-
await (0, import_process_tree.terminateProcessTree)(runtime, { graceMs: 6e3 });
|
|
58
|
-
}
|
|
59
|
-
function isRetryableWorkerServerStatus(status) {
|
|
60
|
-
return status === 408 || status === 429 || status >= 500;
|
|
61
|
-
}
|
|
62
|
-
function signalExitCode(signal) {
|
|
63
|
-
return 128 + (osSignalNumber(signal) ?? 1);
|
|
64
|
-
}
|
|
65
|
-
function osSignalNumber(signal) {
|
|
66
|
-
return import_node_os.constants.signals[signal];
|
|
67
|
-
}
|
|
68
|
-
async function superviseWorkerRuntime(argv, env = process.env, spawnRuntime = defaultRuntimeSpawner, waitBeforeReconnect = defaultRuntimeDelay, reapCredentialRuntime = defaultRuntimeReaper, reconnectDelay) {
|
|
69
|
-
if (!process.argv[1]) {
|
|
70
|
-
throw new Error("Cannot locate the r5d-worker entrypoint");
|
|
71
|
-
}
|
|
72
|
-
let reconnectAttempt = 0;
|
|
73
|
-
while (true) {
|
|
74
|
-
const runtime = spawnRuntime([process.execPath, process.argv[1], ...argv], {
|
|
75
|
-
stdin: "inherit",
|
|
76
|
-
stdout: "inherit",
|
|
77
|
-
stderr: "inherit",
|
|
78
|
-
detached: true,
|
|
79
|
-
env: {
|
|
80
|
-
...env,
|
|
81
|
-
[WORKER_RUNTIME_ENV]: "1"
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
let receivedSignal;
|
|
85
|
-
let resolveSignal;
|
|
86
|
-
const signalReceived = new Promise((resolve) => {
|
|
87
|
-
resolveSignal = resolve;
|
|
88
|
-
});
|
|
89
|
-
const handlers = SUPERVISOR_SIGNALS.map((signal) => {
|
|
90
|
-
const handler = () => {
|
|
91
|
-
if (receivedSignal) return;
|
|
92
|
-
receivedSignal = signal;
|
|
93
|
-
resolveSignal?.(signal);
|
|
94
|
-
};
|
|
95
|
-
process.on(signal, handler);
|
|
96
|
-
return { signal, handler };
|
|
97
|
-
});
|
|
98
|
-
try {
|
|
99
|
-
const outcome = await Promise.race([
|
|
100
|
-
runtime.exited.then((exitCode2) => ({ type: "exit", exitCode: exitCode2 })),
|
|
101
|
-
signalReceived.then((signal) => ({ type: "signal", signal }))
|
|
102
|
-
]);
|
|
103
|
-
try {
|
|
104
|
-
await reapCredentialRuntime(runtime);
|
|
105
|
-
} catch (error) {
|
|
106
|
-
process.stderr.write(
|
|
107
|
-
`[r5d-worker] runtime restart/exit aborted because process-group reaping failed: ${error instanceof Error ? error.message : String(error)}
|
|
108
|
-
`
|
|
109
|
-
);
|
|
110
|
-
return 1;
|
|
111
|
-
}
|
|
112
|
-
if (outcome.type === "signal" || receivedSignal) {
|
|
113
|
-
return signalExitCode(outcome.type === "signal" ? outcome.signal : receivedSignal);
|
|
114
|
-
}
|
|
115
|
-
const { exitCode } = outcome;
|
|
116
|
-
if (exitCode === WORKER_RELOAD_EXIT_CODE) {
|
|
117
|
-
process.stdout.write("[r5d-worker] activating updated worker runtime\n");
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
if (exitCode === WORKER_RECONNECT_EXIT_CODE) {
|
|
121
|
-
const reconnectDelayMs = reconnectDelay?.() ?? workerReconnectDelayMs(Math.random, reconnectAttempt++);
|
|
122
|
-
process.stderr.write(`[r5d-worker] reconnecting in ${reconnectDelayMs}ms
|
|
123
|
-
`);
|
|
124
|
-
await waitBeforeReconnect(reconnectDelayMs);
|
|
125
|
-
if (receivedSignal) return signalExitCode(receivedSignal);
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
return exitCode;
|
|
129
|
-
} finally {
|
|
130
|
-
const processEvents = process;
|
|
131
|
-
for (const { signal, handler } of handlers) processEvents.off(signal, handler);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
136
|
-
0 && (module.exports = {
|
|
137
|
-
WORKER_CREDENTIAL_RESTART_EXIT_CODE,
|
|
138
|
-
WORKER_RECONNECT_DELAY_MS,
|
|
139
|
-
WORKER_RECONNECT_EXIT_CODE,
|
|
140
|
-
WORKER_RECONNECT_JITTER_MS,
|
|
141
|
-
WORKER_RECONNECT_MAX_DELAY_MS,
|
|
142
|
-
WORKER_RELOAD_EXIT_CODE,
|
|
143
|
-
WORKER_RUNTIME_ENV,
|
|
144
|
-
isRetryableWorkerServerStatus,
|
|
145
|
-
superviseWorkerRuntime,
|
|
146
|
-
workerReconnectDelayMs
|
|
147
|
-
});
|
|
@@ -1,346 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var three_way_merge_exports = {};
|
|
20
|
-
__export(three_way_merge_exports, {
|
|
21
|
-
analyzeAlignment: () => analyzeAlignment,
|
|
22
|
-
diffLines: () => diffLines,
|
|
23
|
-
isBinaryContent: () => isBinaryContent,
|
|
24
|
-
mergeThreeWay: () => mergeThreeWay,
|
|
25
|
-
threeWayMergeTestHarness: () => threeWayMergeTestHarness
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(three_way_merge_exports);
|
|
28
|
-
const BINARY_PROBE_BYTES = 8e3;
|
|
29
|
-
const DEFAULT_MAX_LINES = 1e6;
|
|
30
|
-
const DEFAULT_MAX_EDIT_DISTANCE = 2e4;
|
|
31
|
-
const DEFAULT_MAX_ALIGNMENT_CELLS = 1e8;
|
|
32
|
-
const DEFAULT_MAX_DIFF_WORK = 5e7;
|
|
33
|
-
const NEWLINE = 10;
|
|
34
|
-
const NO_COMMON_LINES = /* @__PURE__ */ Symbol("no-common-lines");
|
|
35
|
-
function isBinaryContent(content) {
|
|
36
|
-
return content.subarray(0, BINARY_PROBE_BYTES).includes(0);
|
|
37
|
-
}
|
|
38
|
-
class LineTable {
|
|
39
|
-
ids = /* @__PURE__ */ new Map();
|
|
40
|
-
lines = [];
|
|
41
|
-
intern(line) {
|
|
42
|
-
const key = line.toString("latin1");
|
|
43
|
-
let id = this.ids.get(key);
|
|
44
|
-
if (id === void 0) {
|
|
45
|
-
id = this.lines.length;
|
|
46
|
-
this.ids.set(key, id);
|
|
47
|
-
this.lines.push(line);
|
|
48
|
-
}
|
|
49
|
-
return id;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
function splitLines(content, table, maxLines) {
|
|
53
|
-
let count = 0;
|
|
54
|
-
for (let offset = 0; offset < content.length; ) {
|
|
55
|
-
const newline = content.indexOf(NEWLINE, offset);
|
|
56
|
-
count += 1;
|
|
57
|
-
if (count > maxLines) return null;
|
|
58
|
-
offset = newline < 0 ? content.length : newline + 1;
|
|
59
|
-
}
|
|
60
|
-
const ids = new Int32Array(count);
|
|
61
|
-
let index = 0;
|
|
62
|
-
for (let offset = 0; offset < content.length; ) {
|
|
63
|
-
const newline = content.indexOf(NEWLINE, offset);
|
|
64
|
-
const end = newline < 0 ? content.length : newline + 1;
|
|
65
|
-
ids[index] = table.intern(content.subarray(offset, end));
|
|
66
|
-
index += 1;
|
|
67
|
-
offset = end;
|
|
68
|
-
}
|
|
69
|
-
return ids;
|
|
70
|
-
}
|
|
71
|
-
function findSplit(a, a0, a1, b, b0, b1, forward, backward, maxEditDistance, budget) {
|
|
72
|
-
const n = a1 - a0;
|
|
73
|
-
const m = b1 - b0;
|
|
74
|
-
const maxD = Math.ceil((n + m) / 2);
|
|
75
|
-
const offset = maxD;
|
|
76
|
-
const length = 2 * maxD + 2;
|
|
77
|
-
forward.fill(-1, 0, length);
|
|
78
|
-
backward.fill(-1, 0, length);
|
|
79
|
-
forward[offset + 1] = 0;
|
|
80
|
-
backward[offset + 1] = 0;
|
|
81
|
-
const delta = n - m;
|
|
82
|
-
const meetOnForward = (delta & 1) !== 0;
|
|
83
|
-
let forwardStart = 0;
|
|
84
|
-
let forwardEnd = 0;
|
|
85
|
-
let backwardStart = 0;
|
|
86
|
-
let backwardEnd = 0;
|
|
87
|
-
for (let d = 0; d < maxD; d += 1) {
|
|
88
|
-
if (2 * d > maxEditDistance) return null;
|
|
89
|
-
budget.remaining -= 2 * (2 * d + 1);
|
|
90
|
-
if (budget.remaining < 0) return null;
|
|
91
|
-
for (let k = -d + forwardStart; k <= d - forwardEnd; k += 2) {
|
|
92
|
-
const kIndex = offset + k;
|
|
93
|
-
let x = k === -d || k !== d && forward[kIndex - 1] < forward[kIndex + 1] ? forward[kIndex + 1] : forward[kIndex - 1] + 1;
|
|
94
|
-
let y = x - k;
|
|
95
|
-
const snakeStart = x;
|
|
96
|
-
while (x < n && y < m && a[a0 + x] === b[b0 + y]) {
|
|
97
|
-
x += 1;
|
|
98
|
-
y += 1;
|
|
99
|
-
}
|
|
100
|
-
budget.remaining -= x - snakeStart;
|
|
101
|
-
forward[kIndex] = x;
|
|
102
|
-
if (x > n) forwardEnd += 2;
|
|
103
|
-
else if (y > m) forwardStart += 2;
|
|
104
|
-
else if (meetOnForward) {
|
|
105
|
-
const reverseIndex = offset + delta - k;
|
|
106
|
-
if (reverseIndex >= 0 && reverseIndex < length && backward[reverseIndex] !== -1 && x >= n - backward[reverseIndex]) {
|
|
107
|
-
return [a0 + x, b0 + y];
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
for (let k = -d + backwardStart; k <= d - backwardEnd; k += 2) {
|
|
112
|
-
const kIndex = offset + k;
|
|
113
|
-
let x = k === -d || k !== d && backward[kIndex - 1] < backward[kIndex + 1] ? backward[kIndex + 1] : backward[kIndex - 1] + 1;
|
|
114
|
-
let y = x - k;
|
|
115
|
-
const snakeStart = x;
|
|
116
|
-
while (x < n && y < m && a[a1 - x - 1] === b[b1 - y - 1]) {
|
|
117
|
-
x += 1;
|
|
118
|
-
y += 1;
|
|
119
|
-
}
|
|
120
|
-
budget.remaining -= x - snakeStart;
|
|
121
|
-
backward[kIndex] = x;
|
|
122
|
-
if (x > n) backwardEnd += 2;
|
|
123
|
-
else if (y > m) backwardStart += 2;
|
|
124
|
-
else if (!meetOnForward) {
|
|
125
|
-
const forwardIndex = offset + delta - k;
|
|
126
|
-
if (forwardIndex >= 0 && forwardIndex < length && forward[forwardIndex] !== -1) {
|
|
127
|
-
const forwardX = forward[forwardIndex];
|
|
128
|
-
if (forwardX >= n - x) return [a0 + forwardX, b0 + forwardX - (forwardIndex - offset)];
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return n + m > maxEditDistance ? null : NO_COMMON_LINES;
|
|
134
|
-
}
|
|
135
|
-
function diffLines(a, b, options = {}) {
|
|
136
|
-
const maxEditDistance = options.maxEditDistance ?? DEFAULT_MAX_EDIT_DISTANCE;
|
|
137
|
-
if (maxEditDistance < 0) return null;
|
|
138
|
-
const budget = { remaining: options.maxWork ?? DEFAULT_MAX_DIFF_WORK };
|
|
139
|
-
const scratchLength = a.length + b.length + 4;
|
|
140
|
-
const forward = new Int32Array(scratchLength);
|
|
141
|
-
const backward = new Int32Array(scratchLength);
|
|
142
|
-
const hunks = [];
|
|
143
|
-
const stack = [0, a.length, 0, b.length];
|
|
144
|
-
let topLevel = true;
|
|
145
|
-
while (stack.length > 0) {
|
|
146
|
-
let b1 = stack.pop();
|
|
147
|
-
let b0 = stack.pop();
|
|
148
|
-
let a1 = stack.pop();
|
|
149
|
-
let a0 = stack.pop();
|
|
150
|
-
while (a0 < a1 && b0 < b1 && a[a0] === b[b0]) {
|
|
151
|
-
a0 += 1;
|
|
152
|
-
b0 += 1;
|
|
153
|
-
}
|
|
154
|
-
while (a0 < a1 && b0 < b1 && a[a1 - 1] === b[b1 - 1]) {
|
|
155
|
-
a1 -= 1;
|
|
156
|
-
b1 -= 1;
|
|
157
|
-
}
|
|
158
|
-
if (a0 === a1 && b0 === b1) continue;
|
|
159
|
-
let noCommonLines = a0 === a1 || b0 === b1;
|
|
160
|
-
if (!noCommonLines && topLevel) {
|
|
161
|
-
const seen = /* @__PURE__ */ new Set();
|
|
162
|
-
for (let index = a0; index < a1; index += 1) seen.add(a[index]);
|
|
163
|
-
noCommonLines = true;
|
|
164
|
-
for (let index = b0; index < b1; index += 1) {
|
|
165
|
-
if (seen.has(b[index])) {
|
|
166
|
-
noCommonLines = false;
|
|
167
|
-
break;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
if (noCommonLines && a1 - a0 + (b1 - b0) > maxEditDistance) return null;
|
|
171
|
-
}
|
|
172
|
-
topLevel = false;
|
|
173
|
-
const split = noCommonLines ? NO_COMMON_LINES : findSplit(a, a0, a1, b, b0, b1, forward, backward, maxEditDistance, budget);
|
|
174
|
-
if (split === null) return null;
|
|
175
|
-
if (split === NO_COMMON_LINES) {
|
|
176
|
-
const previous = hunks[hunks.length - 1];
|
|
177
|
-
if (previous && previous.aEnd === a0 && previous.bEnd === b0) {
|
|
178
|
-
previous.aEnd = a1;
|
|
179
|
-
previous.bEnd = b1;
|
|
180
|
-
} else hunks.push({ aStart: a0, aEnd: a1, bStart: b0, bEnd: b1 });
|
|
181
|
-
continue;
|
|
182
|
-
}
|
|
183
|
-
stack.push(split[0], a1, split[1], b1, a0, split[0], b0, split[1]);
|
|
184
|
-
}
|
|
185
|
-
return hunks;
|
|
186
|
-
}
|
|
187
|
-
function analyzeAlignment(a, b, lcsLength, maxCells) {
|
|
188
|
-
const n = a.length;
|
|
189
|
-
const m = b.length;
|
|
190
|
-
const kMin = lcsLength - m;
|
|
191
|
-
const kMax = n - lcsLength;
|
|
192
|
-
const width = kMax - kMin + 1;
|
|
193
|
-
const certain = new Int32Array(n).fill(-1);
|
|
194
|
-
const ambiguous = new Uint8Array(n);
|
|
195
|
-
if (n === 0) return { certain, ambiguous };
|
|
196
|
-
if ((n + 1) * width > maxCells) return null;
|
|
197
|
-
const computeSuffixRow = (i, next, out) => {
|
|
198
|
-
for (let index = width - 1; index >= 0; index -= 1) {
|
|
199
|
-
const j = i - kMax + index;
|
|
200
|
-
if (j < 0 || j >= m) {
|
|
201
|
-
out[index] = 0;
|
|
202
|
-
continue;
|
|
203
|
-
}
|
|
204
|
-
const down = index > 0 ? next[index - 1] : 0;
|
|
205
|
-
const right = index + 1 < width ? out[index + 1] : 0;
|
|
206
|
-
const diagonal = next[index] + (a[i] === b[j] ? 1 : 0);
|
|
207
|
-
out[index] = down > right ? down > diagonal ? down : diagonal : right > diagonal ? right : diagonal;
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
const computePrefixRow = (i, previous, out) => {
|
|
211
|
-
for (let index = 0; index < width; index += 1) {
|
|
212
|
-
const j = i - kMax + index;
|
|
213
|
-
if (j <= 0 || j > m || i === 0) {
|
|
214
|
-
out[index] = 0;
|
|
215
|
-
continue;
|
|
216
|
-
}
|
|
217
|
-
const up = index + 1 < width ? previous[index + 1] : 0;
|
|
218
|
-
const left = index > 0 ? out[index - 1] : 0;
|
|
219
|
-
const diagonal = previous[index] + (a[i - 1] === b[j - 1] ? 1 : 0);
|
|
220
|
-
out[index] = up > left ? up > diagonal ? up : diagonal : left > diagonal ? left : diagonal;
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
const blockSize = Math.ceil(Math.sqrt(n + 1));
|
|
224
|
-
const checkpoints = /* @__PURE__ */ new Map();
|
|
225
|
-
let suffixNext = new Int32Array(width);
|
|
226
|
-
let suffixCurrent = new Int32Array(width);
|
|
227
|
-
checkpoints.set(n, new Int32Array(width));
|
|
228
|
-
for (let i = n - 1; i >= 0; i -= 1) {
|
|
229
|
-
computeSuffixRow(i, suffixNext, suffixCurrent);
|
|
230
|
-
if (i % blockSize === 0) checkpoints.set(i, suffixCurrent.slice());
|
|
231
|
-
[suffixNext, suffixCurrent] = [suffixCurrent, suffixNext];
|
|
232
|
-
}
|
|
233
|
-
const block = Array.from({ length: blockSize + 1 }, () => new Int32Array(width));
|
|
234
|
-
let prefixPrevious = new Int32Array(width);
|
|
235
|
-
let prefixCurrent = new Int32Array(width);
|
|
236
|
-
for (let blockStart = 0; blockStart < n; blockStart += blockSize) {
|
|
237
|
-
const blockEnd = Math.min(blockStart + blockSize, n);
|
|
238
|
-
block[blockEnd - blockStart] = checkpoints.get(blockEnd);
|
|
239
|
-
for (let i = blockEnd - 1; i > blockStart; i -= 1) computeSuffixRow(i, block[i + 1 - blockStart], block[i - blockStart]);
|
|
240
|
-
for (let i = blockStart; i < blockEnd; i += 1) {
|
|
241
|
-
computePrefixRow(i, prefixPrevious, prefixCurrent);
|
|
242
|
-
const suffix = block[i + 1 - blockStart];
|
|
243
|
-
let bestDeletion = 0;
|
|
244
|
-
let matches = 0;
|
|
245
|
-
let partner = -1;
|
|
246
|
-
for (let index = 0; index < width; index += 1) {
|
|
247
|
-
const j = i - kMax + index;
|
|
248
|
-
if (j < 0 || j > m) continue;
|
|
249
|
-
const prefix = prefixCurrent[index];
|
|
250
|
-
const deleted = prefix + (index > 0 ? suffix[index - 1] : 0);
|
|
251
|
-
if (deleted > bestDeletion) bestDeletion = deleted;
|
|
252
|
-
if (j < m && a[i] === b[j] && prefix + 1 + suffix[index] === lcsLength) {
|
|
253
|
-
matches += 1;
|
|
254
|
-
partner = j;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
if (matches === 1 && bestDeletion < lcsLength) certain[i] = partner;
|
|
258
|
-
else if (matches > 0) ambiguous[i] = 1;
|
|
259
|
-
[prefixPrevious, prefixCurrent] = [prefixCurrent, prefixPrevious];
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
return { certain, ambiguous };
|
|
263
|
-
}
|
|
264
|
-
function rangesEqual(a, aStart, aEnd, b, bStart, bEnd) {
|
|
265
|
-
if (aEnd - aStart !== bEnd - bStart) return false;
|
|
266
|
-
for (let offset = 0; offset < aEnd - aStart; offset += 1) {
|
|
267
|
-
if (a[aStart + offset] !== b[bStart + offset]) return false;
|
|
268
|
-
}
|
|
269
|
-
return true;
|
|
270
|
-
}
|
|
271
|
-
function anyAmbiguous(flags, start, end) {
|
|
272
|
-
for (let index = start; index < end; index += 1) if (flags[index]) return true;
|
|
273
|
-
return false;
|
|
274
|
-
}
|
|
275
|
-
function sideAlignment(base, side, options) {
|
|
276
|
-
const maxEditDistance = Math.min(options.maxEditDistance, Math.floor(options.maxAlignmentCells / (base.length + 1)) - 1);
|
|
277
|
-
const hunks = diffLines(base, side, { maxEditDistance, maxWork: options.maxDiffWork });
|
|
278
|
-
if (!hunks) return null;
|
|
279
|
-
let deleted = 0;
|
|
280
|
-
for (const hunk of hunks) deleted += hunk.aEnd - hunk.aStart;
|
|
281
|
-
return analyzeAlignment(base, side, base.length - deleted, options.maxAlignmentCells);
|
|
282
|
-
}
|
|
283
|
-
function mergeThreeWay(base, ours, theirs, options = {}) {
|
|
284
|
-
if (ours.equals(base)) return { kind: "clean", content: theirs };
|
|
285
|
-
if (theirs.equals(base)) return { kind: "clean", content: ours };
|
|
286
|
-
if (ours.equals(theirs)) return { kind: "clean", content: ours };
|
|
287
|
-
if (isBinaryContent(base) || isBinaryContent(ours) || isBinaryContent(theirs)) return { kind: "conflict", conflicts: 1 };
|
|
288
|
-
const maxLines = options.maxLines ?? DEFAULT_MAX_LINES;
|
|
289
|
-
const bounds = {
|
|
290
|
-
maxEditDistance: options.maxEditDistance ?? DEFAULT_MAX_EDIT_DISTANCE,
|
|
291
|
-
maxAlignmentCells: options.maxAlignmentCells ?? DEFAULT_MAX_ALIGNMENT_CELLS,
|
|
292
|
-
maxDiffWork: options.maxDiffWork ?? DEFAULT_MAX_DIFF_WORK
|
|
293
|
-
};
|
|
294
|
-
const table = new LineTable();
|
|
295
|
-
const baseLines = splitLines(base, table, maxLines);
|
|
296
|
-
const oursLines = splitLines(ours, table, maxLines);
|
|
297
|
-
const theirsLines = splitLines(theirs, table, maxLines);
|
|
298
|
-
if (!baseLines || !oursLines || !theirsLines) return { kind: "conflict", conflicts: 1 };
|
|
299
|
-
const oursAlignment = sideAlignment(baseLines, oursLines, bounds);
|
|
300
|
-
const theirsAlignment = sideAlignment(baseLines, theirsLines, bounds);
|
|
301
|
-
if (!oursAlignment || !theirsAlignment) return { kind: "conflict", conflicts: 1 };
|
|
302
|
-
const oursMatch = oursAlignment.certain;
|
|
303
|
-
const theirsMatch = theirsAlignment.certain;
|
|
304
|
-
const output = [];
|
|
305
|
-
let conflicts = 0;
|
|
306
|
-
let i = 0;
|
|
307
|
-
let o = 0;
|
|
308
|
-
let t = 0;
|
|
309
|
-
for (; ; ) {
|
|
310
|
-
while (i < baseLines.length && oursMatch[i] === o && theirsMatch[i] === t) {
|
|
311
|
-
output.push(table.lines[baseLines[i]]);
|
|
312
|
-
i += 1;
|
|
313
|
-
o += 1;
|
|
314
|
-
t += 1;
|
|
315
|
-
}
|
|
316
|
-
if (i === baseLines.length && o === oursLines.length && t === theirsLines.length) break;
|
|
317
|
-
let j = i;
|
|
318
|
-
while (j < baseLines.length && (oursMatch[j] < 0 || theirsMatch[j] < 0)) j += 1;
|
|
319
|
-
const oursEnd = j < baseLines.length ? oursMatch[j] : oursLines.length;
|
|
320
|
-
const theirsEnd = j < baseLines.length ? theirsMatch[j] : theirsLines.length;
|
|
321
|
-
if (rangesEqual(baseLines, i, j, oursLines, o, oursEnd)) {
|
|
322
|
-
for (let index = t; index < theirsEnd; index += 1) output.push(table.lines[theirsLines[index]]);
|
|
323
|
-
} else if (rangesEqual(baseLines, i, j, theirsLines, t, theirsEnd)) {
|
|
324
|
-
for (let index = o; index < oursEnd; index += 1) output.push(table.lines[oursLines[index]]);
|
|
325
|
-
} else if (rangesEqual(oursLines, o, oursEnd, theirsLines, t, theirsEnd) && // Git compares its hunks, not the region text: the same text reached by
|
|
326
|
-
// differently shaped hunks still conflicts there, so only a region whose
|
|
327
|
-
// alignment is unique on both sides is safely the same change.
|
|
328
|
-
!anyAmbiguous(oursAlignment.ambiguous, i, j) && !anyAmbiguous(theirsAlignment.ambiguous, i, j)) {
|
|
329
|
-
for (let index = o; index < oursEnd; index += 1) output.push(table.lines[oursLines[index]]);
|
|
330
|
-
} else conflicts += 1;
|
|
331
|
-
i = j;
|
|
332
|
-
o = oursEnd;
|
|
333
|
-
t = theirsEnd;
|
|
334
|
-
}
|
|
335
|
-
if (conflicts > 0) return { kind: "conflict", conflicts };
|
|
336
|
-
return { kind: "clean", content: Buffer.concat(output) };
|
|
337
|
-
}
|
|
338
|
-
const threeWayMergeTestHarness = { diffLines, analyzeAlignment };
|
|
339
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
340
|
-
0 && (module.exports = {
|
|
341
|
-
analyzeAlignment,
|
|
342
|
-
diffLines,
|
|
343
|
-
isBinaryContent,
|
|
344
|
-
mergeThreeWay,
|
|
345
|
-
threeWayMergeTestHarness
|
|
346
|
-
});
|