@aviaratech/ai-delivery 0.3.35 → 0.3.37
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/CONTRIBUTING.md +12 -206
- package/README.md +56 -554
- package/dist/agent.d.ts +1 -3
- package/dist/agent.js +74 -16
- package/dist/agent.js.map +7 -1
- package/dist/agentReadiness.test.js +73 -67
- package/dist/agentReadiness.test.js.map +7 -1
- package/dist/boardReconcile.test.js +1651 -1590
- package/dist/boardReconcile.test.js.map +7 -1
- package/dist/build.test.js +130 -0
- package/dist/build.test.js.map +7 -0
- package/dist/callerErrors.test.js +91 -0
- package/dist/callerErrors.test.js.map +7 -0
- package/dist/cli.js +389 -517
- package/dist/cli.js.map +7 -1
- package/dist/cliResult.d.ts +2 -2
- package/dist/cliResult.js +42 -45
- package/dist/cliResult.js.map +7 -1
- package/dist/cliResult.test.js +424 -369
- package/dist/cliResult.test.js.map +7 -1
- package/dist/config/deliveryConfig.d.ts +288 -14
- package/dist/config/deliveryConfig.js +472 -390
- package/dist/config/deliveryConfig.js.map +7 -1
- package/dist/config/deliveryConfig.test.js +773 -649
- package/dist/config/deliveryConfig.test.js.map +7 -1
- package/dist/contributorChecks.test.js +1694 -916
- package/dist/contributorChecks.test.js.map +7 -1
- package/dist/currentConsumer.test.js +819 -737
- package/dist/currentConsumer.test.js.map +7 -1
- package/dist/currentTrackingScenario.test.js +499 -479
- package/dist/currentTrackingScenario.test.js.map +7 -1
- package/dist/delivery/common.js +160 -172
- package/dist/delivery/common.js.map +7 -1
- package/dist/delivery/delivery.test.js +509 -431
- package/dist/delivery/delivery.test.js.map +7 -1
- package/dist/delivery/evidence.d.ts +2 -2
- package/dist/delivery/evidence.js +133 -120
- package/dist/delivery/evidence.js.map +7 -1
- package/dist/delivery/index.js +7 -2
- package/dist/delivery/index.js.map +7 -1
- package/dist/delivery/legacy.js +65 -5
- package/dist/delivery/legacy.js.map +7 -1
- package/dist/delivery/policy.d.ts +10 -10
- package/dist/delivery/policy.js +211 -238
- package/dist/delivery/policy.js.map +7 -1
- package/dist/delivery/stage.d.ts +18 -18
- package/dist/delivery/stage.js +220 -235
- package/dist/delivery/stage.js.map +7 -1
- package/dist/deliveryBoard.d.ts +74 -0
- package/dist/deliveryBoard.js +644 -0
- package/dist/deliveryBoard.js.map +7 -0
- package/dist/deliveryBoard.test.js +649 -0
- package/dist/deliveryBoard.test.js.map +7 -0
- package/dist/deliveryHealth.test.js +179 -155
- package/dist/deliveryHealth.test.js.map +7 -1
- package/dist/dependencyCompatibility.test.js +154 -140
- package/dist/dependencyCompatibility.test.js.map +7 -1
- package/dist/directoryIndependent.test.js +417 -383
- package/dist/directoryIndependent.test.js.map +7 -1
- package/dist/dispatch.d.ts +16 -11
- package/dist/dispatch.js +316 -354
- package/dist/dispatch.js.map +7 -1
- package/dist/errors.d.ts +3 -3
- package/dist/errors.js +103 -96
- package/dist/errors.js.map +7 -1
- package/dist/fixtures/deliveryBoardReplay.d.ts +56 -0
- package/dist/fixtures/deliveryBoardReplay.js +617 -0
- package/dist/fixtures/deliveryBoardReplay.js.map +7 -0
- package/dist/fixtures/discovery.d.ts +63 -23
- package/dist/fixtures/discovery.js +96 -90
- package/dist/fixtures/discovery.js.map +7 -1
- package/dist/fixtures/inertEntrypointChild.js +57 -56
- package/dist/fixtures/inertEntrypointChild.js.map +7 -1
- package/dist/fixtures/inertEntrypoints.d.ts +1 -1
- package/dist/fixtures/inertEntrypoints.js +321 -276
- package/dist/fixtures/inertEntrypoints.js.map +7 -1
- package/dist/fixtures/inertTarget.d.ts +78 -7
- package/dist/fixtures/inertTarget.js +769 -691
- package/dist/fixtures/inertTarget.js.map +7 -1
- package/dist/fixtures/issue63.d.ts +4 -3
- package/dist/fixtures/issue63.js +260 -274
- package/dist/fixtures/issue63.js.map +7 -1
- package/dist/fixtures/issueProjectItems.d.ts +20 -0
- package/dist/fixtures/issueProjectItems.js +15 -0
- package/dist/fixtures/issueProjectItems.js.map +7 -0
- package/dist/fixtures/readView.d.ts +120 -0
- package/dist/fixtures/readView.js +172 -0
- package/dist/fixtures/readView.js.map +7 -0
- package/dist/fixtures/recordedGitHubFlows.d.ts +120 -0
- package/dist/fixtures/recordedGitHubFlows.js +109 -0
- package/dist/fixtures/recordedGitHubFlows.js.map +7 -0
- package/dist/genericCompatibility.test.js +64 -55
- package/dist/genericCompatibility.test.js.map +7 -1
- package/dist/git.d.ts +0 -3
- package/dist/git.js +59 -76
- package/dist/git.js.map +7 -1
- package/dist/gitProcess.d.ts +1 -1
- package/dist/gitProcess.js +58 -53
- package/dist/gitProcess.js.map +7 -1
- package/dist/github/client.d.ts +2 -2
- package/dist/github/client.js +484 -379
- package/dist/github/client.js.map +7 -1
- package/dist/github/commandIdentityPolicy.js +42 -52
- package/dist/github/commandIdentityPolicy.js.map +7 -1
- package/dist/github/discovery.d.ts +1 -0
- package/dist/github/discovery.js +197 -215
- package/dist/github/discovery.js.map +7 -1
- package/dist/github/discovery.test.js +223 -177
- package/dist/github/discovery.test.js.map +7 -1
- package/dist/github/issueHistory.d.ts +2 -2
- package/dist/github/issueHistory.js +117 -125
- package/dist/github/issueHistory.js.map +7 -1
- package/dist/github/machineAuth.d.ts +1 -1
- package/dist/github/machineAuth.js +126 -117
- package/dist/github/machineAuth.js.map +7 -1
- package/dist/github/machineAuth.test.js +755 -639
- package/dist/github/machineAuth.test.js.map +7 -1
- package/dist/github/nativeIssueMetadata.js +286 -273
- package/dist/github/nativeIssueMetadata.js.map +7 -1
- package/dist/github/projectDelivery.d.ts +18 -2
- package/dist/github/projectDelivery.js +615 -557
- package/dist/github/projectDelivery.js.map +7 -1
- package/dist/github/relationships.js +433 -389
- package/dist/github/relationships.js.map +7 -1
- package/dist/github/repo.d.ts +1 -0
- package/dist/github/repo.js +123 -96
- package/dist/github/repo.js.map +7 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +7 -1
- package/dist/issue.d.ts +40 -9
- package/dist/issue.js +2102 -1742
- package/dist/issue.js.map +7 -1
- package/dist/issue63History.test.js +40 -42
- package/dist/issue63History.test.js.map +7 -1
- package/dist/issue63Routes.test.js +154 -143
- package/dist/issue63Routes.test.js.map +7 -1
- package/dist/issueBatchUpdate.test.js +989 -885
- package/dist/issueBatchUpdate.test.js.map +7 -1
- package/dist/issueBlockerGuard.test.js +262 -226
- package/dist/issueBlockerGuard.test.js.map +7 -1
- package/dist/issueContract.d.ts +23 -4
- package/dist/issueContract.js +416 -395
- package/dist/issueContract.js.map +7 -1
- package/dist/issueContract.test.d.ts +4 -3
- package/dist/issueContract.test.js +358 -321
- package/dist/issueContract.test.js.map +7 -1
- package/dist/issueDates.test.js +235 -233
- package/dist/issueDates.test.js.map +7 -1
- package/dist/issueInfoReadback.test.js +304 -190
- package/dist/issueInfoReadback.test.js.map +7 -1
- package/dist/issueIntake.test.js +1938 -1732
- package/dist/issueIntake.test.js.map +7 -1
- package/dist/issueJournal.d.ts +40 -19
- package/dist/issueJournal.js +229 -138
- package/dist/issueJournal.js.map +7 -1
- package/dist/issueJournal.test.js +605 -422
- package/dist/issueJournal.test.js.map +7 -1
- package/dist/issueRollup.test.d.ts +1 -0
- package/dist/issueRollup.test.js +476 -0
- package/dist/issueRollup.test.js.map +7 -0
- package/dist/issueTracking.test.js +1059 -989
- package/dist/issueTracking.test.js.map +7 -1
- package/dist/issueWriteRecovery.test.d.ts +1 -0
- package/dist/issueWriteRecovery.test.js +260 -0
- package/dist/issueWriteRecovery.test.js.map +7 -0
- package/dist/lifecycle.test.js +112 -441
- package/dist/lifecycle.test.js.map +7 -1
- package/dist/logger.js +80 -74
- package/dist/logger.js.map +7 -1
- package/dist/mcp/index.js +116 -94
- package/dist/mcp/index.js.map +7 -1
- package/dist/mcp/tools.d.ts +252 -310
- package/dist/mcp/tools.js +235 -342
- package/dist/mcp/tools.js.map +7 -1
- package/dist/pluginAuthProbe.js +63 -52
- package/dist/pluginAuthProbe.js.map +7 -1
- package/dist/pluginAuthProbe.test.js +85 -62
- package/dist/pluginAuthProbe.test.js.map +7 -1
- package/dist/pluginCredentials.test.js +282 -259
- package/dist/pluginCredentials.test.js.map +7 -1
- package/dist/pluginDoctor.test.js +653 -588
- package/dist/pluginDoctor.test.js.map +7 -1
- package/dist/pluginInstaller.d.ts +7 -5
- package/dist/pluginInstaller.js +1173 -1229
- package/dist/pluginInstaller.js.map +7 -1
- package/dist/pluginInstaller.test.js +1842 -1423
- package/dist/pluginInstaller.test.js.map +7 -1
- package/dist/pluginPackaging.test.js +417 -413
- package/dist/pluginPackaging.test.js.map +7 -1
- package/dist/pr.d.ts +114 -131
- package/dist/pr.js +1314 -1327
- package/dist/pr.js.map +7 -1
- package/dist/pr.test.js +967 -653
- package/dist/pr.test.js.map +7 -1
- package/dist/prAssociation.test.js +2419 -1788
- package/dist/prAssociation.test.js.map +7 -1
- package/dist/prDispatch.test.js +123 -89
- package/dist/prDispatch.test.js.map +7 -1
- package/dist/readView.d.ts +184 -0
- package/dist/readView.js +218 -0
- package/dist/readView.js.map +7 -0
- package/dist/readView.test.d.ts +1 -0
- package/dist/readView.test.js +146 -0
- package/dist/readView.test.js.map +7 -0
- package/dist/releaseReconciliation.test.js +267 -288
- package/dist/releaseReconciliation.test.js.map +7 -1
- package/dist/releaseWorkflow.test.js +2493 -422
- package/dist/releaseWorkflow.test.js.map +7 -1
- package/dist/review.d.ts +738 -2
- package/dist/review.js +601 -348
- package/dist/review.js.map +7 -1
- package/dist/review.test.js +1218 -812
- package/dist/review.test.js.map +7 -1
- package/dist/reviewSubmit.test.d.ts +1 -0
- package/dist/reviewSubmit.test.js +747 -0
- package/dist/reviewSubmit.test.js.map +7 -0
- package/dist/services/agentReadinessService.js +42 -37
- package/dist/services/agentReadinessService.js.map +7 -1
- package/dist/services/blockerGuardService.js +188 -188
- package/dist/services/blockerGuardService.js.map +7 -1
- package/dist/services/boardReconcileService.d.ts +125 -125
- package/dist/services/boardReconcileService.js +1295 -1421
- package/dist/services/boardReconcileService.js.map +7 -1
- package/dist/services/deliveryHealthService.js +197 -199
- package/dist/services/deliveryHealthService.js.map +7 -1
- package/dist/services/legacyIssueMigration.js +263 -277
- package/dist/services/legacyIssueMigration.js.map +7 -1
- package/dist/stagedChecks.test.js +396 -194
- package/dist/stagedChecks.test.js.map +7 -1
- package/dist/start.test.js +99 -95
- package/dist/start.test.js.map +7 -1
- package/dist/stdoutRegression.test.js +321 -358
- package/dist/stdoutRegression.test.js.map +7 -1
- package/dist/targetPolicyDiscovery.test.js +141 -143
- package/dist/targetPolicyDiscovery.test.js.map +7 -1
- package/dist/targetPolicyEntrypoints.test.js +308 -269
- package/dist/targetPolicyEntrypoints.test.js.map +7 -1
- package/dist/targetPolicyLocal.test.js +580 -1051
- package/dist/targetPolicyLocal.test.js.map +7 -1
- package/dist/targetPolicyRoutes.test.js +274 -281
- package/dist/targetPolicyRoutes.test.js.map +7 -1
- package/dist/targetRepositoryExecution.test.d.ts +1 -0
- package/dist/targetRepositoryExecution.test.js +451 -0
- package/dist/targetRepositoryExecution.test.js.map +7 -0
- package/dist/terminalMessages.js +41 -35
- package/dist/terminalMessages.js.map +7 -1
- package/dist/toolOutput.d.ts +2 -0
- package/dist/toolOutput.js +36 -0
- package/dist/toolOutput.js.map +7 -0
- package/dist/toolOutput.test.d.ts +1 -0
- package/dist/toolOutput.test.js +240 -0
- package/dist/toolOutput.test.js.map +7 -0
- package/dist/utils/atomicJson.d.ts +0 -2
- package/dist/utils/atomicJson.js +81 -77
- package/dist/utils/atomicJson.js.map +7 -1
- package/dist/utils/filesystem.d.ts +0 -8
- package/dist/utils/filesystem.js +5 -19
- package/dist/utils/filesystem.js.map +7 -1
- package/dist/utils/lockfile.js +68 -71
- package/dist/utils/lockfile.js.map +7 -1
- package/dist/verification.d.ts +1 -54
- package/dist/verification.js +976 -1941
- package/dist/verification.js.map +7 -1
- package/dist/verificationGate.test.js +127 -117
- package/dist/verificationGate.test.js.map +7 -1
- package/dist/version.js +45 -24
- package/dist/version.js.map +7 -1
- package/package.json +9 -8
- package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
- package/plugins/ai-delivery/README.md +47 -156
- package/plugins/ai-delivery/plugin.json +1 -1
- package/plugins/ai-delivery/runtime/dist/THIRD-PARTY-NOTICES.md +238 -44
- package/plugins/ai-delivery/runtime/dist/cli.js +351 -115
- package/plugins/ai-delivery/runtime/package.json +1 -1
- package/plugins/ai-delivery/skills/intake-create/SKILL.md +14 -78
- package/plugins/ai-delivery/skills/pr-handoff/SKILL.md +35 -36
- package/plugins/ai-delivery/skills/worktree-lifecycle/SKILL.md +14 -15
- package/dist/investigationCompletion.test.js +0 -728
- package/dist/investigationCompletion.test.js.map +0 -1
- package/dist/services/deliveryAdmission.d.ts +0 -49
- package/dist/services/deliveryAdmission.js +0 -165
- package/dist/services/deliveryAdmission.js.map +0 -1
- package/dist/services/worktreeRegistry.d.ts +0 -434
- package/dist/services/worktreeRegistry.js +0 -1248
- package/dist/services/worktreeRegistry.js.map +0 -1
- package/dist/setup.d.ts +0 -60
- package/dist/setup.js +0 -585
- package/dist/setup.js.map +0 -1
- package/dist/setup.test.js +0 -3329
- package/dist/setup.test.js.map +0 -1
- package/dist/worktree.d.ts +0 -28
- package/dist/worktree.js +0 -188
- package/dist/worktree.js.map +0 -1
- package/dist/worktreeTransition.d.ts +0 -211
- package/dist/worktreeTransition.js +0 -1037
- package/dist/worktreeTransition.js.map +0 -1
- package/dist/worktreeTransition.test.js +0 -1191
- package/dist/worktreeTransition.test.js.map +0 -1
- /package/dist/{investigationCompletion.test.d.ts → build.test.d.ts} +0 -0
- /package/dist/{setup.test.d.ts → callerErrors.test.d.ts} +0 -0
- /package/dist/{worktreeTransition.test.d.ts → deliveryBoard.test.d.ts} +0 -0
package/dist/utils/lockfile.js
CHANGED
|
@@ -1,82 +1,79 @@
|
|
|
1
|
-
import { resolve } from
|
|
2
|
-
import * as lockfile from
|
|
3
|
-
import { logDebug, logWarn } from
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import * as lockfile from "proper-lockfile";
|
|
3
|
+
import { logDebug, logWarn } from "../logger.js";
|
|
4
4
|
const LOCK_OPTIONS = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
realpath: false,
|
|
6
|
+
retries: 0,
|
|
7
|
+
stale: 1e4
|
|
8
|
+
// 10 seconds - auto-release stale locks
|
|
8
9
|
};
|
|
9
10
|
const LOCK_RETRY_DELAY_MS = 200;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
if (!isLockError(error)) {
|
|
43
|
-
throw error;
|
|
44
|
-
}
|
|
45
|
-
if (!warned) {
|
|
46
|
-
logWarn(`Unable to acquire lock on ${lockPath} - another agent is modifying it. Retrying...`);
|
|
47
|
-
warned = true;
|
|
48
|
-
}
|
|
49
|
-
if (nextTimeoutAt !== null && timeoutInterval !== null && Date.now() >= nextTimeoutAt) {
|
|
50
|
-
onTimeout?.();
|
|
51
|
-
nextTimeoutAt = Date.now() + timeoutInterval;
|
|
52
|
-
}
|
|
53
|
-
await delay(LOCK_RETRY_DELAY_MS);
|
|
54
|
-
}
|
|
11
|
+
async function withLock(filePath, { onCompromised, onReleaseError, onTimeout, operation, projectRoot, timeout }) {
|
|
12
|
+
const root = projectRoot ?? process.cwd();
|
|
13
|
+
const lockPath = resolve(root, filePath);
|
|
14
|
+
let release = null;
|
|
15
|
+
const timeoutInterval = typeof timeout === "number" && timeout > 0 ? timeout : null;
|
|
16
|
+
const maxAttempts = timeoutInterval !== null ? Math.ceil(timeoutInterval / LOCK_RETRY_DELAY_MS) : null;
|
|
17
|
+
let attempts = 0;
|
|
18
|
+
let nextTimeoutAt = timeoutInterval === null ? null : Date.now() + timeoutInterval;
|
|
19
|
+
let warned = false;
|
|
20
|
+
try {
|
|
21
|
+
for (; ; ) {
|
|
22
|
+
if (maxAttempts !== null && attempts >= maxAttempts) {
|
|
23
|
+
const timeoutLabel = timeoutInterval === null ? "unknown" : String(timeoutInterval);
|
|
24
|
+
throw new Error(
|
|
25
|
+
`Lock acquisition timeout after ${timeoutLabel}ms on ${lockPath}. Another process may be holding the lock.`
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
attempts += 1;
|
|
29
|
+
const attemptLabel = maxAttempts !== null ? `${String(attempts)}/${String(maxAttempts)}` : String(attempts);
|
|
30
|
+
logDebug(`Acquiring lock on ${lockPath}... (attempt ${attemptLabel})`);
|
|
31
|
+
try {
|
|
32
|
+
release = await lockfile.lock(lockPath, {
|
|
33
|
+
...LOCK_OPTIONS,
|
|
34
|
+
...onCompromised === void 0 ? {} : { onCompromised }
|
|
35
|
+
});
|
|
36
|
+
logDebug(`Lock acquired on ${lockPath}`);
|
|
37
|
+
break;
|
|
38
|
+
} catch (error) {
|
|
39
|
+
if (!isLockError(error)) {
|
|
40
|
+
throw error;
|
|
55
41
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
catch (error) {
|
|
65
|
-
onReleaseError?.(error);
|
|
66
|
-
// Lock release failure is non-fatal - stale lock will auto-expire
|
|
67
|
-
logDebug(`Failed to release lock on ${lockPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
68
|
-
}
|
|
42
|
+
if (!warned) {
|
|
43
|
+
logWarn(`Unable to acquire lock on ${lockPath} - another agent is modifying it. Retrying...`);
|
|
44
|
+
warned = true;
|
|
45
|
+
}
|
|
46
|
+
if (nextTimeoutAt !== null && timeoutInterval !== null && Date.now() >= nextTimeoutAt) {
|
|
47
|
+
onTimeout?.();
|
|
48
|
+
nextTimeoutAt = Date.now() + timeoutInterval;
|
|
69
49
|
}
|
|
50
|
+
await delay(LOCK_RETRY_DELAY_MS);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return await operation();
|
|
54
|
+
} finally {
|
|
55
|
+
if (release !== null) {
|
|
56
|
+
try {
|
|
57
|
+
await release();
|
|
58
|
+
logDebug(`Lock released on ${lockPath}`);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
onReleaseError?.(error);
|
|
61
|
+
logDebug(`Failed to release lock on ${lockPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
62
|
+
}
|
|
70
63
|
}
|
|
64
|
+
}
|
|
71
65
|
}
|
|
72
66
|
function delay(ms) {
|
|
73
|
-
|
|
67
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
74
68
|
}
|
|
75
69
|
function isLockError(error) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
70
|
+
if (typeof error !== "object" || error === null) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
const code = error.code;
|
|
74
|
+
return code === "ELOCKED";
|
|
81
75
|
}
|
|
82
|
-
|
|
76
|
+
export {
|
|
77
|
+
withLock
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=lockfile.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/lockfile.ts"],
|
|
4
|
+
"sourcesContent": ["import { resolve } from 'node:path';\nimport * as lockfile from 'proper-lockfile';\n\nimport { logDebug, logWarn } from '../logger.js';\n\nconst LOCK_OPTIONS = {\n realpath: false,\n retries: 0,\n stale: 10000, // 10 seconds - auto-release stale locks\n};\n\nconst LOCK_RETRY_DELAY_MS = 200;\n\ninterface WithLockOptions<T> {\n onCompromised?: (error: Error) => void;\n onReleaseError?: (error: unknown) => void;\n onTimeout?: () => void;\n operation: () => Promise<T> | T;\n projectRoot?: string;\n timeout?: number;\n}\n\n/**\n * Execute a function with exclusive file lock\n * Prevents concurrent modifications to the worktree registry\n */\nexport async function withLock<T>(\n filePath: string,\n { onCompromised, onReleaseError, onTimeout, operation, projectRoot, timeout }: WithLockOptions<T>,\n): Promise<T> {\n const root = projectRoot ?? process.cwd();\n const lockPath = resolve(root, filePath);\n\n let release: (() => Promise<void>) | null = null;\n const timeoutInterval = typeof timeout === 'number' && timeout > 0 ? timeout : null;\n const maxAttempts = timeoutInterval !== null ? Math.ceil(timeoutInterval / LOCK_RETRY_DELAY_MS) : null;\n let attempts = 0;\n let nextTimeoutAt = timeoutInterval === null ? null : Date.now() + timeoutInterval;\n let warned = false;\n\n try {\n for (;;) {\n // Enforce hard timeout by breaking after max attempts\n if (maxAttempts !== null && attempts >= maxAttempts) {\n const timeoutLabel = timeoutInterval === null ? 'unknown' : String(timeoutInterval);\n throw new Error(\n `Lock acquisition timeout after ${timeoutLabel}ms on ${lockPath}. Another process may be holding the lock.`,\n );\n }\n\n attempts += 1;\n const attemptLabel = maxAttempts !== null ? `${String(attempts)}/${String(maxAttempts)}` : String(attempts);\n logDebug(`Acquiring lock on ${lockPath}... (attempt ${attemptLabel})`);\n\n try {\n release = await lockfile.lock(lockPath, {\n ...LOCK_OPTIONS,\n ...(onCompromised === undefined ? {} : { onCompromised }),\n });\n logDebug(`Lock acquired on ${lockPath}`);\n break;\n } catch (error: unknown) {\n if (!isLockError(error)) {\n throw error;\n }\n\n if (!warned) {\n logWarn(`Unable to acquire lock on ${lockPath} - another agent is modifying it. Retrying...`);\n warned = true;\n }\n\n if (nextTimeoutAt !== null && timeoutInterval !== null && Date.now() >= nextTimeoutAt) {\n onTimeout?.();\n nextTimeoutAt = Date.now() + timeoutInterval;\n }\n\n await delay(LOCK_RETRY_DELAY_MS);\n }\n }\n\n return await operation();\n } finally {\n if (release !== null) {\n try {\n await release();\n logDebug(`Lock released on ${lockPath}`);\n } catch (error: unknown) {\n onReleaseError?.(error);\n // Lock release failure is non-fatal - stale lock will auto-expire\n logDebug(`Failed to release lock on ${lockPath}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n }\n}\n\nfunction delay(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nfunction isLockError(error: unknown): boolean {\n if (typeof error !== 'object' || error === null) {\n return false;\n }\n\n const code = (error as { code?: unknown }).code;\n return code === 'ELOCKED';\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,eAAe;AACxB,YAAY,cAAc;AAE1B,SAAS,UAAU,eAAe;AAElC,MAAM,eAAe;AAAA,EACnB,UAAU;AAAA,EACV,SAAS;AAAA,EACT,OAAO;AAAA;AACT;AAEA,MAAM,sBAAsB;AAe5B,eAAsB,SACpB,UACA,EAAE,eAAe,gBAAgB,WAAW,WAAW,aAAa,QAAQ,GAChE;AACZ,QAAM,OAAO,eAAe,QAAQ,IAAI;AACxC,QAAM,WAAW,QAAQ,MAAM,QAAQ;AAEvC,MAAI,UAAwC;AAC5C,QAAM,kBAAkB,OAAO,YAAY,YAAY,UAAU,IAAI,UAAU;AAC/E,QAAM,cAAc,oBAAoB,OAAO,KAAK,KAAK,kBAAkB,mBAAmB,IAAI;AAClG,MAAI,WAAW;AACf,MAAI,gBAAgB,oBAAoB,OAAO,OAAO,KAAK,IAAI,IAAI;AACnE,MAAI,SAAS;AAEb,MAAI;AACF,eAAS;AAEP,UAAI,gBAAgB,QAAQ,YAAY,aAAa;AACnD,cAAM,eAAe,oBAAoB,OAAO,YAAY,OAAO,eAAe;AAClF,cAAM,IAAI;AAAA,UACR,kCAAkC,YAAY,SAAS,QAAQ;AAAA,QACjE;AAAA,MACF;AAEA,kBAAY;AACZ,YAAM,eAAe,gBAAgB,OAAO,GAAG,OAAO,QAAQ,CAAC,IAAI,OAAO,WAAW,CAAC,KAAK,OAAO,QAAQ;AAC1G,eAAS,qBAAqB,QAAQ,gBAAgB,YAAY,GAAG;AAErE,UAAI;AACF,kBAAU,MAAM,SAAS,KAAK,UAAU;AAAA,UACtC,GAAG;AAAA,UACH,GAAI,kBAAkB,SAAY,CAAC,IAAI,EAAE,cAAc;AAAA,QACzD,CAAC;AACD,iBAAS,oBAAoB,QAAQ,EAAE;AACvC;AAAA,MACF,SAAS,OAAgB;AACvB,YAAI,CAAC,YAAY,KAAK,GAAG;AACvB,gBAAM;AAAA,QACR;AAEA,YAAI,CAAC,QAAQ;AACX,kBAAQ,6BAA6B,QAAQ,+CAA+C;AAC5F,mBAAS;AAAA,QACX;AAEA,YAAI,kBAAkB,QAAQ,oBAAoB,QAAQ,KAAK,IAAI,KAAK,eAAe;AACrF,sBAAY;AACZ,0BAAgB,KAAK,IAAI,IAAI;AAAA,QAC/B;AAEA,cAAM,MAAM,mBAAmB;AAAA,MACjC;AAAA,IACF;AAEA,WAAO,MAAM,UAAU;AAAA,EACzB,UAAE;AACA,QAAI,YAAY,MAAM;AACpB,UAAI;AACF,cAAM,QAAQ;AACd,iBAAS,oBAAoB,QAAQ,EAAE;AAAA,MACzC,SAAS,OAAgB;AACvB,yBAAiB,KAAK;AAEtB,iBAAS,6BAA6B,QAAQ,KAAK,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,EAAE;AAAA,MAC7G;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,MAAM,IAA2B;AACxC,SAAO,IAAI,QAAQ,CAACA,aAAY,WAAWA,UAAS,EAAE,CAAC;AACzD;AAEA,SAAS,YAAY,OAAyB;AAC5C,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WAAO;AAAA,EACT;AAEA,QAAM,OAAQ,MAA6B;AAC3C,SAAO,SAAS;AAClB;",
|
|
6
|
+
"names": ["resolve"]
|
|
7
|
+
}
|
package/dist/verification.d.ts
CHANGED
|
@@ -1,18 +1,4 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { type RepositoryClassificationReceipt, type RepositoryStageAggregate, type RepositoryStageReceipt } from './delivery/legacy.js';
|
|
3
|
-
export interface VerificationRun {
|
|
4
|
-
aggregate: RepositoryStageAggregate;
|
|
5
|
-
classification: RepositoryClassificationReceipt;
|
|
6
|
-
completedAt: string;
|
|
7
|
-
manifestId: string;
|
|
8
|
-
resources?: VerificationResourceSummary;
|
|
9
|
-
schemaVersion: 'ai-delivery.run@1' | 'ai-delivery.run@2' | 'ai-delivery.run@3';
|
|
10
|
-
writer?: {
|
|
11
|
-
worktreeDigest: string;
|
|
12
|
-
producerDigest: string;
|
|
13
|
-
};
|
|
14
|
-
stageReceipts: RepositoryStageReceipt[];
|
|
15
|
-
}
|
|
16
2
|
export interface VerificationResourceBounds {
|
|
17
3
|
maxAggregateRssBytes: number;
|
|
18
4
|
maxNewOutputBytes?: number;
|
|
@@ -87,31 +73,6 @@ interface VerificationWriter {
|
|
|
87
73
|
idle(): void;
|
|
88
74
|
assertQuiescent(): void;
|
|
89
75
|
}
|
|
90
|
-
/** @internal Durable transition evidence must precede changes to the existing writer slot. */
|
|
91
|
-
export interface WorktreeTransitionWriterLeaseInput {
|
|
92
|
-
repoRoot: string;
|
|
93
|
-
worktreePath?: string;
|
|
94
|
-
writerId: string;
|
|
95
|
-
beforeClaim(input: {
|
|
96
|
-
previousBytes: Buffer | undefined;
|
|
97
|
-
owner: {
|
|
98
|
-
pid: number;
|
|
99
|
-
identity: string;
|
|
100
|
-
};
|
|
101
|
-
}): void | Promise<void>;
|
|
102
|
-
recordClaim(bytes: Buffer): void | Promise<void>;
|
|
103
|
-
afterClaim?(bytes: Buffer): void | Promise<void>;
|
|
104
|
-
recordRelease(bytes: Buffer): void | Promise<void>;
|
|
105
|
-
afterRelease?(): void | Promise<void>;
|
|
106
|
-
onLockReleaseError?: (error: unknown) => void;
|
|
107
|
-
onLockCompromised?: (error: Error) => void;
|
|
108
|
-
}
|
|
109
|
-
/** @internal Read-only closure check shared by inspection and the locked transition lease. */
|
|
110
|
-
export declare function assertWorktreeTransitionWriterQuiescent(worktreePath: string, bytes: Buffer | undefined): void;
|
|
111
|
-
/** @internal Hold the existing writer lock while reading a sealed transition; never claim or recover its slot. */
|
|
112
|
-
export declare function withWorktreeTransitionWriterAbsent<T>(repoRoot: string, worktreePath: string, operation: () => Promise<T>): Promise<T>;
|
|
113
|
-
/** @internal Check-only lease for the explicit transition owner; never recovers or signals old commands. */
|
|
114
|
-
export declare function withWorktreeTransitionWriterLease<T>(input: WorktreeTransitionWriterLeaseInput, operation: () => Promise<T>): Promise<T>;
|
|
115
76
|
/** @internal Retained public code is hashed as data; it is never imported or executed. */
|
|
116
77
|
export declare function retainedWorktreeTransitionProducerDigest(distDirectory: string): string;
|
|
117
78
|
/** @internal Preserve the same dependency manifests that participate in the existing producer digest. */
|
|
@@ -119,8 +80,6 @@ export declare function retainedWorktreeTransitionDependencyManifests(distDirect
|
|
|
119
80
|
source: string;
|
|
120
81
|
digest: string;
|
|
121
82
|
}[];
|
|
122
|
-
/** @internal Original manifests validate as history and cannot authorize current verification. */
|
|
123
|
-
export declare function readWorktreeTransitionRun(bytes: Buffer): VerificationRun;
|
|
124
83
|
export declare function runStageCommand(repoRoot: string, argv: readonly string[], abortSignal?: AbortSignal, onRunning?: (capturedOutputBytes: number, resource?: ResourceSample, reason?: string) => void, resourceBounds?: VerificationResourceBounds, baseline?: OutputBaseline, onResourceSample?: (sample: ResourceSample) => void, writer?: VerificationWriter, execution?: {
|
|
125
84
|
environment: NodeJS.ProcessEnv;
|
|
126
85
|
cwd?: string;
|
|
@@ -260,22 +219,10 @@ declare const IssueSourcePhaseReceiptSchema: z.ZodObject<{
|
|
|
260
219
|
outputDigest: z.ZodNullable<z.ZodString>;
|
|
261
220
|
outputBytes: z.ZodNumber;
|
|
262
221
|
status: z.ZodEnum<{
|
|
263
|
-
failed: "failed";
|
|
264
222
|
complete: "complete";
|
|
223
|
+
failed: "failed";
|
|
265
224
|
}>;
|
|
266
225
|
}, z.core.$strict>>;
|
|
267
226
|
}, z.core.$strict>;
|
|
268
227
|
export type IssueSourcePhaseReceipt = z.infer<typeof IssueSourcePhaseReceiptSchema>;
|
|
269
|
-
/** @internal Runtime setup shares the existing writer, ownership handshake and bounded command runner. */
|
|
270
|
-
export declare function withRuntimeSetupWriter<T>(root: string, operation: (runner: {
|
|
271
|
-
assertQuiescent(): void;
|
|
272
|
-
bindCapturedOutput(stageId: string): void;
|
|
273
|
-
checkResources: () => Promise<void>;
|
|
274
|
-
signal: AbortSignal;
|
|
275
|
-
run(argv: readonly string[], bounds: VerificationResourceBounds, signal?: AbortSignal, environment?: NodeJS.ProcessEnv, cwd?: string): Promise<Buffer>;
|
|
276
|
-
}) => Promise<T>, scope?: {
|
|
277
|
-
bounds: VerificationResourceBounds;
|
|
278
|
-
maxCapturedOutputBytes: number;
|
|
279
|
-
signal?: AbortSignal;
|
|
280
|
-
}): Promise<T>;
|
|
281
228
|
export {};
|