@astrosheep/keiyaku 2.9.8 → 2.9.10
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 +50 -182
- package/build/.tsbuildinfo +1 -1
- package/build/agents/harness/control-types.js +18 -1
- package/build/agents/harness/index.js +2 -0
- package/build/agents/harness/outcome-error.js +81 -0
- package/build/agents/harness/projection.js +10 -7
- package/build/agents/harness/router.js +5 -1
- package/build/agents/providers/claude-agent-sdk/adapter.js +18 -4
- package/build/agents/providers/claude-agent-sdk/registration.js +11 -1
- package/build/agents/providers/claude-agent-sdk/session.js +19 -5
- package/build/agents/providers/codex-app-server/adapter.js +11 -6
- package/build/agents/providers/codex-app-server/events.js +67 -6
- package/build/agents/providers/codex-app-server/registration.js +11 -1
- package/build/agents/providers/opencode-sdk/adapter.js +8 -1
- package/build/agents/providers/opencode-sdk/events.js +24 -2
- package/build/agents/providers/opencode-sdk/registration.js +11 -1
- package/build/agents/providers/pi/checkpoint.js +9 -1
- package/build/agents/providers/pi/events.js +2 -0
- package/build/agents/providers/pi/registration.js +14 -1
- package/build/cli/commands/akuma/akuma/handler.js +1 -1
- package/build/cli/commands/akuma/akuma/meta.js +3 -3
- package/build/cli/commands/akuma/catalog.js +2 -2
- package/build/cli/commands/akuma/{view → show}/handler.js +5 -5
- package/build/cli/commands/akuma/{view → show}/meta.js +3 -3
- package/build/cli/commands/akuma.js +1 -1
- package/build/cli/commands/contract/amend/handler.js +5 -4
- package/build/cli/commands/contract/arc/handler.js +5 -4
- package/build/cli/commands/contract/audit/handler.js +2 -2
- package/build/cli/commands/contract/bind/handler.js +12 -3
- package/build/cli/commands/contract/bind/meta.js +45 -15
- package/build/cli/commands/contract/forfeit/handler.js +9 -5
- package/build/cli/commands/contract/log/handler.js +2 -2
- package/build/cli/commands/contract/petition/handler.js +34 -7
- package/build/cli/commands/contract/renew/handler.js +7 -7
- package/build/cli/commands/contract/renew/meta.js +3 -3
- package/build/cli/commands/metadata.js +10 -6
- package/build/cli/commands/projection/call/meta.js +1 -1
- package/build/cli/commands/projection/catalog.js +2 -0
- package/build/cli/commands/projection/history/handler.js +21 -0
- package/build/cli/commands/projection/history/meta.js +9 -0
- package/build/cli/commands/projection/shared.js +3 -4
- package/build/cli/commands/projection/status/handler.js +3 -3
- package/build/cli/commands/projection/wait/handler.js +20 -11
- package/build/cli/commands/task/add/handler.js +14 -5
- package/build/cli/commands/task/add/meta.js +2 -2
- package/build/cli/commands/task/catalog.js +4 -0
- package/build/cli/commands/task/done/handler.js +1 -4
- package/build/cli/commands/task/done/meta.js +1 -1
- package/build/cli/commands/task/drop/meta.js +1 -1
- package/build/cli/commands/task/hold/handler.js +3 -0
- package/build/cli/commands/task/hold/meta.js +8 -0
- package/build/cli/commands/task/log/handler.js +1 -1
- package/build/cli/commands/task/log/meta.js +2 -2
- package/build/cli/commands/task/resume/handler.js +3 -0
- package/build/cli/commands/task/resume/meta.js +8 -0
- package/build/cli/commands/task/shared.js +39 -14
- package/build/cli/commands/task/show/handler.js +1 -1
- package/build/cli/commands/task/show/meta.js +1 -1
- package/build/cli/commands/task/start/meta.js +1 -1
- package/build/cli/commands/task/stop/handler.js +1 -4
- package/build/cli/commands/task/stop/meta.js +1 -1
- package/build/cli/commands/task/update/handler.js +11 -3
- package/build/cli/commands/task/update/meta.js +3 -3
- package/build/cli/completion.js +3 -2
- package/build/cli/flags.js +51 -14
- package/build/cli/help.js +4 -1
- package/build/cli/index.js +40 -25
- package/build/cli/parse-flags.js +40 -7
- package/build/cli/parse-metadata.js +5 -2
- package/build/cli/parse-selectors.js +2 -3
- package/build/cli/parse.js +40 -6
- package/build/cli/projection-address.js +12 -10
- package/build/cli/render/amendment-warning.js +8 -0
- package/build/cli/render/arc.js +6 -2
- package/build/cli/render/audit.js +400 -81
- package/build/cli/render/kanshi.js +242 -79
- package/build/cli/render/lifecycle.js +56 -0
- package/build/cli/render/misc.js +24 -28
- package/build/cli/render/petition.js +5 -0
- package/build/cli/render/projection-activity.js +65 -29
- package/build/cli/render/projection-history.js +64 -0
- package/build/cli/render/shared.js +23 -9
- package/build/cli/render/status.js +13 -35
- package/build/cli/render/task.js +51 -26
- package/build/cli/render/terminal-failure.js +3 -1
- package/build/cli/render/wait.js +45 -69
- package/build/cli/subagent-guard.js +1 -1
- package/build/cli/types.js +1 -1
- package/build/config/env-keys.js +3 -1
- package/build/config/env.js +24 -1
- package/build/config/settings/schema.js +3 -1
- package/build/core/address-carrier.js +89 -0
- package/build/core/addressing.js +255 -196
- package/build/core/amend.js +115 -38
- package/build/core/amendment-criteria.js +17 -0
- package/build/core/amendment-warning.js +10 -0
- package/build/core/arc.js +184 -83
- package/build/core/audit/candidate.js +110 -9
- package/build/core/audit/coordinates.js +120 -65
- package/build/core/audit/evidence.js +19 -23
- package/build/core/audit/facade.js +34 -11
- package/build/core/audit/report.js +5 -5
- package/build/core/bind-reconciliation.js +390 -0
- package/build/core/bind-workspace.js +12 -20
- package/build/core/bind.js +242 -273
- package/build/core/call/call.js +1 -0
- package/build/core/call/context.js +46 -71
- package/build/core/call/prompt.js +6 -3
- package/build/core/context.js +49 -35
- package/build/core/contract-carrier-runtime.js +408 -0
- package/build/core/contract-carrier.js +270 -0
- package/build/core/contract-view.js +33 -27
- package/build/core/contract.js +5 -1
- package/build/core/derived-replay.js +207 -0
- package/build/core/draft.js +125 -57
- package/build/core/forfeit.js +113 -56
- package/build/core/identifier-slug.js +63 -13
- package/build/core/ids.js +4 -4
- package/build/core/lifecycle-history.js +35 -0
- package/build/core/lifecycle-recovery.js +117 -0
- package/build/core/lifecycle-runner.js +377 -0
- package/build/core/log.js +37 -11
- package/build/core/outcome-base.js +181 -0
- package/build/core/process-group.js +139 -0
- package/build/core/projection/generation/database.js +82 -7
- package/build/core/projection/generation/model.js +9 -36
- package/build/core/projection/generation/projection-generation-continuation.js +10 -22
- package/build/core/projection/generation/projection-generation-execution.js +13 -6
- package/build/core/projection/index.js +5 -4
- package/build/core/projection/projection-activity.js +29 -8
- package/build/core/projection/projection-alias.js +23 -10
- package/build/core/projection/projection-core.js +21 -7
- package/build/core/projection/projection-execution-observer.js +91 -39
- package/build/core/projection/projection-history.js +474 -0
- package/build/core/projection/projection-runner-lock.js +12 -0
- package/build/core/projection/projection-status-observation.js +365 -0
- package/build/core/projection/projection-status.js +35 -337
- package/build/core/projection/projection-terminal-failure.js +13 -8
- package/build/core/projection/projection-wait.js +7 -2
- package/build/core/projection/tell/launch-store.js +244 -0
- package/build/core/projection/tell/model.js +3 -3
- package/build/core/projection/tell/store.js +70 -118
- package/build/core/registry.js +22 -87
- package/build/core/renew-build.js +424 -0
- package/build/core/renew-plan.js +239 -0
- package/build/core/renew-rewrite.js +77 -0
- package/build/core/renew.js +295 -520
- package/build/core/repository-ledger/accepted-fold-read.js +19 -0
- package/build/core/repository-ledger/accepted-tail.js +116 -0
- package/build/core/repository-ledger/admission.js +38 -0
- package/build/core/repository-ledger/authoritative-transaction.js +1 -0
- package/build/core/repository-ledger/claim-evidence.js +147 -0
- package/build/core/repository-ledger/codec.js +297 -0
- package/build/core/repository-ledger/current-state-store.js +853 -0
- package/build/core/repository-ledger/fold-repository.js +375 -0
- package/build/core/repository-ledger/fold.js +248 -0
- package/build/core/repository-ledger/git-object-store.js +243 -0
- package/build/core/repository-ledger/history-read.js +15 -0
- package/build/core/repository-ledger/incremental-read.js +153 -0
- package/build/core/repository-ledger/index.js +15 -0
- package/build/core/repository-ledger/inventory-plan.js +75 -0
- package/build/core/repository-ledger/inventory.js +310 -0
- package/build/core/repository-ledger/publication-admission.js +125 -0
- package/build/core/repository-ledger/publication.js +353 -0
- package/build/core/repository-ledger/read-model.js +469 -0
- package/build/core/repository-ledger/transaction-membership.js +78 -0
- package/build/core/repository-ledger/traversal.js +404 -0
- package/build/core/repository-ledger/write-transaction.js +339 -0
- package/build/core/seal.js +168 -161
- package/build/core/settlement/claim-delivery.js +42 -215
- package/build/core/settlement/claim.js +235 -153
- package/build/core/settlement/index.js +4 -4
- package/build/core/settlement/petition-claim-gates.js +52 -33
- package/build/core/settlement/petition-forfeit.js +12 -5
- package/build/core/settlement/petition-head-guard.js +8 -5
- package/build/core/settlement/petition-preview.js +68 -56
- package/build/core/settlement/petition-window.js +50 -0
- package/build/core/settlement/petition.js +252 -131
- package/build/core/settlement/queue-read-model.js +72 -95
- package/build/core/settlement/queue-seat-allocation.js +35 -126
- package/build/core/settlement/queue.js +1 -1
- package/build/core/settlement/settlement.js +172 -80
- package/build/core/settlement/verdict.js +112 -66
- package/build/core/settlement/verification-coordination.js +305 -0
- package/build/core/settlement/verification-supervisor.js +275 -0
- package/build/core/settlement/verification.js +398 -31
- package/build/core/status/board.js +125 -127
- package/build/core/status/lifecycle.js +7 -80
- package/build/core/structured-query.js +23 -0
- package/build/core/target-ref.js +1 -1
- package/build/core/task/board.js +59 -24
- package/build/core/task/commands.js +181 -33
- package/build/core/task/coordinate.js +56 -0
- package/build/core/task/document.js +25 -9
- package/build/core/task/index.js +7 -4
- package/build/core/task/query.js +17 -27
- package/build/core/task/settlement-git.js +164 -179
- package/build/core/task/settlement-policy.js +15 -11
- package/build/core/task/source-board.js +31 -13
- package/build/core/task/task-bind-preparation.js +193 -0
- package/build/core/task/task-contract.js +102 -193
- package/build/core/task/task-file-transaction.js +171 -0
- package/build/core/task/task-git-runtime.js +76 -14
- package/build/core/task/task-git-store.js +68 -169
- package/build/core/task/task-store-repository.js +13 -6
- package/build/core/task/task-worktree.js +6 -33
- package/build/core/task/task.js +1 -1
- package/build/core/task/tree.js +3 -3
- package/build/core/task/validation.js +4 -3
- package/build/core/transcripts.js +93 -1
- package/build/core/worktree-bootstrap.js +44 -36
- package/build/core/worktree-path.js +210 -77
- package/build/flow-error.js +7 -7
- package/build/generated/version.js +2 -2
- package/build/git/core.js +76 -13
- package/build/git/refs.js +168 -46
- package/build/git/streaming-batch.js +73 -13
- package/package.json +1 -1
- package/skills/keiyaku/SKILL.md +1 -1
- package/skills/keiyaku-akuma/SKILL.md +3 -3
- package/skills/keiyaku-task/SKILL.md +4 -2
- package/skills/keiyaku-workflow/SKILL.md +88 -203
- package/build/core/entry.js +0 -305
- package/build/core/ledger-batch.js +0 -194
- package/build/core/ledger.js +0 -84
- package/build/core/projection/leash.js +0 -87
- package/build/core/ref-log.js +0 -119
- package/build/core/renew-session.js +0 -128
- package/build/core/status/ledger-batch.js +0 -1
- package/build/core/status/reconciliation.js +0 -137
|
@@ -1,242 +1,69 @@
|
|
|
1
|
-
import * as fs from "node:fs/promises";
|
|
2
|
-
import * as path from "node:path";
|
|
3
1
|
import { FlowError } from "../../flow-error.js";
|
|
4
|
-
import {
|
|
5
|
-
import { createGit, errorContainsAnyPattern, MISSING_HEAD_PATTERNS, wrapGitError } from "../../git/core.js";
|
|
6
|
-
import { readLedger } from "../ledger.js";
|
|
2
|
+
import { createGit, errorContainsAnyPattern, MISSING_HEAD_PATTERNS, runGitProcess } from "../../git/core.js";
|
|
7
3
|
import { shortCommitHash } from "../../git/commits.js";
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
import { assertHonestClaimEvidence, buildHonestClaimMerge, } from "../repository-ledger/claim-evidence.js";
|
|
5
|
+
async function successfulGit(cwd, args, input) {
|
|
6
|
+
const result = await runGitProcess(cwd, args, input === undefined ? undefined : { input });
|
|
7
|
+
if (result.status !== 0 || result.error) {
|
|
8
|
+
const detail = result.stderr.trim() || result.error?.message || `exit ${String(result.status)}`;
|
|
9
|
+
throw new FlowError(args[0] === "merge-tree" ? "CLOSE_MERGE_CONFLICT" : "INTERNAL_STATE", `git ${args.join(" ")} failed: ${detail}`, { cause: result.error });
|
|
10
|
+
}
|
|
11
|
+
return result.stdout.trim();
|
|
12
|
+
}
|
|
13
|
+
/** Build unreachable claim objects using only the approved frozen coordinates. */
|
|
14
|
+
export async function buildClaimLanding(input) {
|
|
16
15
|
try {
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
const built = await buildHonestClaimMerge(input);
|
|
17
|
+
return { ...input.coordinates, ...built };
|
|
19
18
|
}
|
|
20
19
|
catch (error) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
handle = await fs.open(receiptPath, "a");
|
|
24
|
-
}
|
|
25
|
-
try {
|
|
26
|
-
await handle.writeFile(`${created ? restoreIfMissing : ""}${JSON.stringify(receipt)}\n`, "utf8");
|
|
27
|
-
await handle.sync();
|
|
20
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
21
|
+
throw new FlowError(message.includes("not conflict-free") ? "CLOSE_MERGE_CONFLICT" : "INTERNAL_STATE", message, { cause: error });
|
|
28
22
|
}
|
|
29
|
-
finally {
|
|
30
|
-
await handle.close();
|
|
31
|
-
}
|
|
32
|
-
await syncDirectory(path.dirname(receiptPath));
|
|
33
23
|
}
|
|
34
24
|
export async function resolveCommit(cwd, rev) {
|
|
35
|
-
|
|
36
|
-
try {
|
|
37
|
-
return (await git.raw(["rev-parse", "--verify", `${rev}^{commit}`])).trim();
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
throw wrapGitError(`rev-parse ${rev}`, error, cwd);
|
|
41
|
-
}
|
|
25
|
+
return await successfulGit(cwd, ["rev-parse", "--verify", `${rev}^{commit}`]);
|
|
42
26
|
}
|
|
43
27
|
export async function resolveCommitOrNull(cwd, rev) {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
return
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
28
|
+
const result = await runGitProcess(cwd, ["rev-parse", "--verify", `${rev}^{commit}`]);
|
|
29
|
+
if (result.status === 0 && !result.error)
|
|
30
|
+
return result.stdout.trim();
|
|
31
|
+
if (errorContainsAnyPattern(result.stderr, MISSING_HEAD_PATTERNS))
|
|
32
|
+
return null;
|
|
33
|
+
const detail = result.stderr.trim() || result.error?.message || `exit ${String(result.status)}`;
|
|
34
|
+
throw new FlowError("INTERNAL_STATE", `git rev-parse ${rev} failed: ${detail}`, { cause: result.error });
|
|
35
|
+
}
|
|
36
|
+
/** Prove parent order and tree identity independently of mutable refs. */
|
|
37
|
+
export async function proveClaimLanding(cwd, landing) {
|
|
38
|
+
await assertHonestClaimEvidence(cwd, landing);
|
|
53
39
|
}
|
|
54
40
|
/** Display path for preview cleanup effects; delivery owns path mechanics. */
|
|
55
41
|
export function relativeDisplayPath(from, to) {
|
|
56
|
-
return
|
|
42
|
+
return (to.startsWith(from) ? to.slice(from.length).replace(/^\//, "") : to) || ".";
|
|
57
43
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
* even when claim cwd is a different worktree (real Keiyaku topology).
|
|
62
|
-
*/
|
|
63
|
-
async function findWorktreePathForBranch(cwd, branch) {
|
|
64
|
-
const git = createGit(cwd);
|
|
65
|
-
let output;
|
|
66
|
-
try {
|
|
67
|
-
output = await git.raw(["worktree", "list", "--porcelain", "-z"]);
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
throw wrapGitError("worktree list --porcelain -z", error, cwd);
|
|
71
|
-
}
|
|
72
|
-
const expected = `refs/heads/${branch}`;
|
|
73
|
-
let currentPath;
|
|
44
|
+
async function findWorktreePathForRef(cwd, target) {
|
|
45
|
+
const output = await successfulGit(cwd, ["worktree", "list", "--porcelain", "-z"]);
|
|
46
|
+
let worktree;
|
|
74
47
|
for (const field of output.split("\0")) {
|
|
75
|
-
if (field.startsWith("worktree "))
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (field.startsWith("branch ") && field.slice("branch ".length) === expected) {
|
|
80
|
-
return currentPath;
|
|
81
|
-
}
|
|
48
|
+
if (field.startsWith("worktree "))
|
|
49
|
+
worktree = field.slice("worktree ".length);
|
|
50
|
+
if (field === `branch ${target}`)
|
|
51
|
+
return worktree;
|
|
82
52
|
}
|
|
83
53
|
return undefined;
|
|
84
54
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return output.split("\0").filter((entry) => entry.length > 0);
|
|
90
|
-
}
|
|
91
|
-
catch (error) {
|
|
92
|
-
throw wrapGitError(`diff --name-only -z ${oldHead} ${mergeCommit}`, error, cwd);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Among candidate merge paths, return those that are dirty/untracked in the target worktree.
|
|
97
|
-
* Must run while HEAD/index still share oldHead (pre-CAS). Uses porcelain -z only — never prose.
|
|
98
|
-
*/
|
|
99
|
-
async function listBlockingPaths(worktreePath, candidates) {
|
|
100
|
-
if (candidates.length === 0)
|
|
101
|
-
return [];
|
|
102
|
-
const candidateSet = new Set(candidates);
|
|
103
|
-
const git = createGit(worktreePath);
|
|
104
|
-
let output;
|
|
105
|
-
try {
|
|
106
|
-
output = await git.raw([
|
|
107
|
-
"status",
|
|
108
|
-
"--porcelain",
|
|
109
|
-
"-z",
|
|
110
|
-
"--untracked-files=all",
|
|
111
|
-
"--",
|
|
112
|
-
...candidates,
|
|
113
|
-
]);
|
|
114
|
-
}
|
|
115
|
-
catch (error) {
|
|
116
|
-
throw wrapGitError("status --porcelain -z --untracked-files=all", error, worktreePath);
|
|
117
|
-
}
|
|
118
|
-
const dirty = new Set();
|
|
119
|
-
for (const part of output.split("\0")) {
|
|
120
|
-
if (part.length < 3)
|
|
121
|
-
continue;
|
|
122
|
-
// porcelain -z: "XYpath" (no space) or legacy "XY path"
|
|
123
|
-
const pathEntry = part[2] === " " ? part.slice(3) : part.slice(2);
|
|
124
|
-
if (pathEntry.length > 0 && candidateSet.has(pathEntry)) {
|
|
125
|
-
dirty.add(pathEntry);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return candidates.filter((candidate) => dirty.has(candidate));
|
|
129
|
-
}
|
|
130
|
-
function buildReconcileWarning(input) {
|
|
131
|
-
const blocking = input.blockingPaths.length > 0
|
|
132
|
-
? input.blockingPaths.map((entry) => `- ${entry}`).join("\n")
|
|
133
|
-
: "- (none identified)";
|
|
134
|
-
return [
|
|
135
|
-
`Target worktree ${input.worktreePath} remains behind after claim advanced '${input.targetBranch}' to ${shortCommitHash(input.mergeCommit)}.`,
|
|
136
|
-
"The branch ref advanced while that worktree was not reconciled.",
|
|
137
|
-
"Blocking paths:",
|
|
138
|
-
blocking,
|
|
139
|
-
].join("\n");
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Snapshot real blockers BEFORE CAS while target worktree HEAD/index still match oldHead.
|
|
143
|
-
* Post-CAS porcelain is useless: every merge path looks like ghost dirt.
|
|
144
|
-
*/
|
|
145
|
-
async function snapshotPreCasBlockers(input) {
|
|
146
|
-
const worktreePath = await findWorktreePathForBranch(input.cwd, input.targetBranch);
|
|
147
|
-
if (!worktreePath)
|
|
148
|
-
return undefined;
|
|
149
|
-
// Claim reconciles the common task board itself after CAS. Task paths are
|
|
150
|
-
// therefore never target-worktree blockers and must not enter this snapshot.
|
|
151
|
-
const changedPaths = (await listChangedPaths(input.cwd, input.oldHead, input.mergeCommit))
|
|
152
|
-
.filter((entry) => !entry.startsWith(".keiyaku/tasks/"));
|
|
153
|
-
const blockingPaths = await listBlockingPaths(worktreePath, changedPaths);
|
|
154
|
-
return { worktreePath, blockingPaths };
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* After CAS, attempt two-tree read-tree on the pre-identified target worktree.
|
|
158
|
-
* - No snapshot (target not checked out) → ref-only, no warning.
|
|
159
|
-
* - read-tree success → no warnings.
|
|
160
|
-
* - read-tree reject → soft-fail using pre-CAS blocker snapshot; never throw/reset.
|
|
161
|
-
*/
|
|
162
|
-
async function reconcileAfterCas(input) {
|
|
163
|
-
if (!input.snapshot)
|
|
55
|
+
/** Align a checked-out target after the atomic claim. Failure leaves authority intact. */
|
|
56
|
+
export async function replayClaimTargetWorktree(cwd, landing) {
|
|
57
|
+
const worktree = await findWorktreePathForRef(cwd, landing.target);
|
|
58
|
+
if (!worktree)
|
|
164
59
|
return [];
|
|
165
|
-
const targetGit = createGit(input.snapshot.worktreePath);
|
|
166
60
|
try {
|
|
167
|
-
|
|
168
|
-
// index entries to the accepted merge. Reconcile only the remaining tree.
|
|
169
|
-
await targetGit.raw(["read-tree", "-m", "-u", input.oldHead, input.mergeCommit]);
|
|
61
|
+
await createGit(worktree).raw(["read-tree", "-m", "-u", landing.targetHead, landing.mergeCommit]);
|
|
170
62
|
return [];
|
|
171
63
|
}
|
|
172
64
|
catch {
|
|
173
65
|
return [
|
|
174
|
-
|
|
175
|
-
worktreePath: input.snapshot.worktreePath,
|
|
176
|
-
targetBranch: input.targetBranch,
|
|
177
|
-
mergeCommit: input.mergeCommit,
|
|
178
|
-
blockingPaths: input.snapshot.blockingPaths,
|
|
179
|
-
}),
|
|
66
|
+
`Target worktree ${worktree} remains behind after claim advanced '${landing.target.slice("refs/heads/".length)}' to ${shortCommitHash(landing.mergeCommit)}.`,
|
|
180
67
|
];
|
|
181
68
|
}
|
|
182
69
|
}
|
|
183
|
-
export async function defaultMergeDelivery(input) {
|
|
184
|
-
const ledger = await readLedger(input.cwd, input.contractId);
|
|
185
|
-
if (!ledger) {
|
|
186
|
-
throw new FlowError("INTERNAL_STATE", `cannot claim ${input.contractId}: ledger missing`);
|
|
187
|
-
}
|
|
188
|
-
const commission = commissionTarget(ledger.entries);
|
|
189
|
-
if (!commission) {
|
|
190
|
-
throw new FlowError("INTERNAL_STATE", `cannot claim ${input.contractId}: missing commission target`);
|
|
191
|
-
}
|
|
192
|
-
const targetHead = await resolveCommitOrNull(input.cwd, commission.ref);
|
|
193
|
-
if (!targetHead) {
|
|
194
|
-
throw new FlowError("INTERNAL_STATE", `cannot claim ${input.contractId}: commission target ${commission.ref} does not resolve`);
|
|
195
|
-
}
|
|
196
|
-
const branch = `keiyaku/${input.contractId}`;
|
|
197
|
-
const deliveryHead = await resolveCommit(input.cwd, branch);
|
|
198
|
-
const base = latestBase(ledger.entries);
|
|
199
|
-
if (!base)
|
|
200
|
-
throw new FlowError("INTERNAL_STATE", `cannot claim ${input.contractId}: missing ledger base`);
|
|
201
|
-
let receiptStreamBeforeCas = "";
|
|
202
|
-
if (!input.writeClaimReceipt) {
|
|
203
|
-
const receiptPath = path.join(await stableRepoRoot(input.cwd), ".keiyaku", CLAIM_RECEIPTS_FILE);
|
|
204
|
-
try {
|
|
205
|
-
receiptStreamBeforeCas = await fs.readFile(receiptPath, "utf8");
|
|
206
|
-
}
|
|
207
|
-
catch (error) {
|
|
208
|
-
if (error.code !== "ENOENT")
|
|
209
|
-
throw error;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
let preCasSnapshot;
|
|
213
|
-
const merged = await settleTaskBoardForLanding({
|
|
214
|
-
cwd: input.cwd,
|
|
215
|
-
contractId: input.contractId,
|
|
216
|
-
baseCommit: base,
|
|
217
|
-
targetRef: commission.ref,
|
|
218
|
-
targetBranch: commission.branch,
|
|
219
|
-
targetHead,
|
|
220
|
-
deliveryHead,
|
|
221
|
-
beforeCas: async (mergeCommit, oldHead) => {
|
|
222
|
-
preCasSnapshot = await snapshotPreCasBlockers({ cwd: input.cwd, targetBranch: commission.branch, oldHead, mergeCommit });
|
|
223
|
-
},
|
|
224
|
-
afterCas: async (mergeCommit, oldHead) => reconcileAfterCas({ contractId: input.contractId, targetBranch: commission.branch, oldHead, mergeCommit, snapshot: preCasSnapshot }),
|
|
225
|
-
publishLedger: input.publishClaim,
|
|
226
|
-
});
|
|
227
|
-
const receiptWarnings = [];
|
|
228
|
-
if (merged.oldHead !== undefined) {
|
|
229
|
-
try {
|
|
230
|
-
const receipt = { kind: "receipt", oldHead: merged.oldHead, newHead: merged.mergeCommit, contract: input.contractId };
|
|
231
|
-
if (input.writeClaimReceipt)
|
|
232
|
-
await input.writeClaimReceipt(input.cwd, receipt);
|
|
233
|
-
else
|
|
234
|
-
await appendClaimReceipt(input.cwd, receipt, receiptStreamBeforeCas);
|
|
235
|
-
}
|
|
236
|
-
catch {
|
|
237
|
-
receiptWarnings.push("Claim receipt was not recorded after the target branch update; this movement will appear as an unreceipted FACT until manually recorded.");
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
const warnings = [...receiptWarnings, ...(merged.warnings ?? [])];
|
|
241
|
-
return warnings.length > 0 ? { mergeCommit: merged.mergeCommit, warnings } : { mergeCommit: merged.mergeCommit };
|
|
242
|
-
}
|