@codyswann/lisa 4.72.2 → 4.72.3
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/all/copy-overwrite/scripts/lisa-hooks/worktree-binding-guard.mjs +225 -33
- package/dist/core/lisa-owned-hash-ledger.d.ts.map +1 -1
- package/dist/core/lisa-owned-hash-ledger.js +6 -0
- package/dist/core/lisa-owned-hash-ledger.js.map +1 -1
- package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
- package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
- package/dist/core/upstream-evidence-manifest.js +5 -2
- package/dist/core/upstream-evidence-manifest.js.map +1 -1
- package/package.json +4 -4
- package/plugins/lisa/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa/hooks/worktree-binding-guard.mjs +225 -33
- package/plugins/lisa-agy/plugin.json +1 -1
- package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-agy/plugin.json +1 -1
- package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/hooks/worktree-binding-guard.mjs +225 -33
- package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cursor/hooks/worktree-binding-guard.mjs +225 -33
- package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-agy/plugin.json +1 -1
- package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-agy/plugin.json +1 -1
- package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-agy/plugin.json +1 -1
- package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-agy/plugin.json +1 -1
- package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-agy/plugin.json +1 -1
- package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-agy/plugin.json +1 -1
- package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-agy/plugin.json +1 -1
- package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/src/base/hooks/worktree-binding-guard.mjs +225 -33
package/package.json
CHANGED
|
@@ -189,7 +189,7 @@
|
|
|
189
189
|
"qs": "^6.16.0"
|
|
190
190
|
},
|
|
191
191
|
"name": "@codyswann/lisa",
|
|
192
|
-
"version": "4.72.
|
|
192
|
+
"version": "4.72.3",
|
|
193
193
|
"description": "Claude Code governance framework that applies guardrails, guidance, and automated enforcement to projects",
|
|
194
194
|
"main": "dist/index.js",
|
|
195
195
|
"exports": {
|
|
@@ -345,7 +345,7 @@
|
|
|
345
345
|
"test": "tests"
|
|
346
346
|
},
|
|
347
347
|
"types": "./dist/index.d.ts",
|
|
348
|
-
"lisaReleaseCommit": "
|
|
349
|
-
"gitHead": "
|
|
350
|
-
"lisaReleaseTag": "v4.72.
|
|
348
|
+
"lisaReleaseCommit": "6aa53989b5ac02e12de038c42a47ada07a57e853",
|
|
349
|
+
"gitHead": "6aa53989b5ac02e12de038c42a47ada07a57e853",
|
|
350
|
+
"lisaReleaseTag": "v4.72.3"
|
|
351
351
|
}
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
* first attempt and lets the retry through is defeated by a blind retry, which
|
|
39
39
|
* is the single most likely next action. So the block stands until the session
|
|
40
40
|
* states, in the acknowledgement, the absolute path it now intends to work in.
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
41
|
+
* An acknowledgement can choose the observed root, return to the initial root,
|
|
42
|
+
* or accept a linked target this session was explicitly offered. A selected
|
|
43
|
+
* target does not prove a move: the next guarded call must actually be there.
|
|
44
44
|
*
|
|
45
45
|
* FAILING OPEN, LOUDLY. Anything this cannot determine — no session id, no
|
|
46
46
|
* cwd, not a git repository, an unreadable state file — exits 0 with a line on
|
|
@@ -71,6 +71,7 @@ const GUARDED_TOOLS = new Set(["Bash", "Write", "Edit", "MultiEdit"]);
|
|
|
71
71
|
* on its own PreToolUse pass — which is exactly where a command string arrives.
|
|
72
72
|
*/
|
|
73
73
|
const ACCEPT_PREFIX = "lisa-worktree-binding: accept";
|
|
74
|
+
const ACK_AND_SEPARATOR = Symbol("acknowledgement AND separator");
|
|
74
75
|
|
|
75
76
|
/**
|
|
76
77
|
* Resolve a path the way git reports one.
|
|
@@ -157,6 +158,46 @@ function mainCheckout(cwd) {
|
|
|
157
158
|
return null;
|
|
158
159
|
}
|
|
159
160
|
|
|
161
|
+
/** Registered roots of the bound repository, with Git path quoting disabled. */
|
|
162
|
+
function linkedWorktreeRoots(bound) {
|
|
163
|
+
const listing = git(["worktree", "list", "--porcelain", "-z"], bound);
|
|
164
|
+
if (listing === null) {
|
|
165
|
+
say(
|
|
166
|
+
"git could not identify linked worktrees; repository identity is NOT enforced"
|
|
167
|
+
);
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
return new Set(
|
|
171
|
+
listing
|
|
172
|
+
.split("\0")
|
|
173
|
+
.filter(record => record.startsWith("worktree "))
|
|
174
|
+
.map(record => realpath(record.slice("worktree ".length)))
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** Canonical common Git directory: stable identity across linked checkouts. */
|
|
179
|
+
function repositoryIdentity(root) {
|
|
180
|
+
if (typeof root !== "string") return null;
|
|
181
|
+
const common = git(["rev-parse", "--git-common-dir"], root);
|
|
182
|
+
if (common === null) {
|
|
183
|
+
say("git could not compare repository identity; identity is NOT enforced");
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
return realpath(resolve(root, common));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** A registration is only authoritative while its live repository agrees. */
|
|
190
|
+
function isLinkedWorktree(
|
|
191
|
+
bound,
|
|
192
|
+
candidate,
|
|
193
|
+
roots = linkedWorktreeRoots(bound)
|
|
194
|
+
) {
|
|
195
|
+
if (!roots?.has(candidate) || worktreeRoot(candidate) !== candidate)
|
|
196
|
+
return false;
|
|
197
|
+
const common = repositoryIdentity(bound);
|
|
198
|
+
return common !== null && common === repositoryIdentity(candidate);
|
|
199
|
+
}
|
|
200
|
+
|
|
160
201
|
/**
|
|
161
202
|
* How much of an executed script this guard will read, in bytes.
|
|
162
203
|
*
|
|
@@ -300,6 +341,7 @@ function executedPath(segment) {
|
|
|
300
341
|
* fooled by exactly that and was caught only by a known-answer control.
|
|
301
342
|
*/
|
|
302
343
|
function foreignTreeIn(text, bound, cwd) {
|
|
344
|
+
let linkedRoots;
|
|
303
345
|
const code = text
|
|
304
346
|
.split("\n")
|
|
305
347
|
.map(line => line.replace(/^\s*#.*$/u, ""))
|
|
@@ -320,7 +362,10 @@ function foreignTreeIn(text, bound, cwd) {
|
|
|
320
362
|
} catch {
|
|
321
363
|
continue;
|
|
322
364
|
}
|
|
323
|
-
if (root && root !== bound)
|
|
365
|
+
if (root && root !== bound) {
|
|
366
|
+
if (linkedRoots === undefined) linkedRoots = linkedWorktreeRoots(bound);
|
|
367
|
+
if (isLinkedWorktree(bound, root, linkedRoots)) return root;
|
|
368
|
+
}
|
|
324
369
|
}
|
|
325
370
|
return null;
|
|
326
371
|
}
|
|
@@ -499,10 +544,10 @@ function reachesOut(script, foreign, bound) {
|
|
|
499
544
|
` script: ${script}`,
|
|
500
545
|
` reaches: ${foreign}`,
|
|
501
546
|
` bound to: ${bound}`,
|
|
502
|
-
"The
|
|
503
|
-
"
|
|
504
|
-
"belongs to, or acknowledge the move:",
|
|
547
|
+
"The access lives inside the file, after this guard measures the session.",
|
|
548
|
+
"Run the work from the tree it belongs to, or acknowledge that target:",
|
|
505
549
|
acceptanceLine(foreign),
|
|
550
|
+
"Then move to the acknowledged tree before further guarded calls.",
|
|
506
551
|
]);
|
|
507
552
|
}
|
|
508
553
|
|
|
@@ -602,9 +647,8 @@ function readState(bindingKeyValue, payload) {
|
|
|
602
647
|
/**
|
|
603
648
|
* Write the session's binding state, MERGING over whatever is already there.
|
|
604
649
|
*
|
|
605
|
-
*
|
|
606
|
-
*
|
|
607
|
-
* What it buys is that a field one writer owns is not silently dropped by
|
|
650
|
+
* Explicit `claimedRoot: null` still clears a claim. Merging means that a
|
|
651
|
+
* field one writer owns is not silently dropped by
|
|
608
652
|
* another writer that had no opinion about it: `runtimeNoticed` is written by
|
|
609
653
|
* {@link noticeRuntimeDrift} and read by nobody else, and a clobbering write
|
|
610
654
|
* would turn its "reported once" into "reported again after the next
|
|
@@ -617,12 +661,24 @@ function readState(bindingKeyValue, payload) {
|
|
|
617
661
|
*/
|
|
618
662
|
function writeState(bindingKeyValue, state, payload) {
|
|
619
663
|
const file = stateFile(bindingKeyValue);
|
|
664
|
+
const previous = readState(bindingKeyValue, payload);
|
|
665
|
+
const originalRoot =
|
|
666
|
+
previous?.originalRoot ?? previous?.boundRoot ?? state.boundRoot;
|
|
667
|
+
const originalCommonDir =
|
|
668
|
+
previous?.originalCommonDir ?? repositoryIdentity(originalRoot);
|
|
620
669
|
try {
|
|
621
670
|
mkdirSync(dirname(file), { recursive: true });
|
|
622
671
|
writeFileSync(
|
|
623
672
|
file,
|
|
624
673
|
`${JSON.stringify(
|
|
625
|
-
{
|
|
674
|
+
{
|
|
675
|
+
...previous,
|
|
676
|
+
...state,
|
|
677
|
+
// Preserve the initial root after intentional rebinds. A legacy
|
|
678
|
+
// state's established root is its only proven recovery anchor.
|
|
679
|
+
originalRoot,
|
|
680
|
+
originalCommonDir,
|
|
681
|
+
},
|
|
626
682
|
null,
|
|
627
683
|
2
|
|
628
684
|
)}\n`
|
|
@@ -749,43 +805,161 @@ function refuse(lines) {
|
|
|
749
805
|
}
|
|
750
806
|
|
|
751
807
|
function acceptanceLine(observed) {
|
|
752
|
-
|
|
808
|
+
const literal = `${ACCEPT_PREFIX} ${observed}`.replaceAll("'", "'\\''");
|
|
809
|
+
return ` echo '${literal}'`;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
/** Read literal shell words and AND separators without evaluating expansions. */
|
|
813
|
+
function acknowledgementWords(text) {
|
|
814
|
+
const words = [];
|
|
815
|
+
let word = "",
|
|
816
|
+
active = false,
|
|
817
|
+
quote = null;
|
|
818
|
+
const emit = () => {
|
|
819
|
+
if (active) words.push(word);
|
|
820
|
+
word = "";
|
|
821
|
+
active = false;
|
|
822
|
+
};
|
|
823
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
824
|
+
const char = text[index];
|
|
825
|
+
if (quote === "'") {
|
|
826
|
+
if (char === "'") quote = null;
|
|
827
|
+
else word += char;
|
|
828
|
+
continue;
|
|
829
|
+
}
|
|
830
|
+
if (char === "\\") {
|
|
831
|
+
const next = text[index + 1];
|
|
832
|
+
if (next === undefined) return null;
|
|
833
|
+
if (quote === '"' && !['"', "\\", "$", "`", "\n"].includes(next)) {
|
|
834
|
+
word += char;
|
|
835
|
+
continue;
|
|
836
|
+
}
|
|
837
|
+
index += 1;
|
|
838
|
+
if (next !== "\n") {
|
|
839
|
+
word += next;
|
|
840
|
+
active = true;
|
|
841
|
+
}
|
|
842
|
+
continue;
|
|
843
|
+
}
|
|
844
|
+
if (quote === '"') {
|
|
845
|
+
if (char === '"') quote = null;
|
|
846
|
+
else if (char === "$" || char === "`") return null;
|
|
847
|
+
else word += char;
|
|
848
|
+
continue;
|
|
849
|
+
}
|
|
850
|
+
if (char === "'" || char === '"') {
|
|
851
|
+
quote = char;
|
|
852
|
+
active = true;
|
|
853
|
+
} else if (char === " " || char === "\t") emit();
|
|
854
|
+
else if (char === "\n") return null;
|
|
855
|
+
else if (char === "&" && text[index + 1] === "&") {
|
|
856
|
+
emit();
|
|
857
|
+
words.push(ACK_AND_SEPARATOR);
|
|
858
|
+
index += 1;
|
|
859
|
+
} else if (/[&;|<>$`*?[\]{}()]/u.test(char)) return null;
|
|
860
|
+
else {
|
|
861
|
+
word += char;
|
|
862
|
+
active = true;
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
if (quote !== null) return null;
|
|
866
|
+
emit();
|
|
867
|
+
return words;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
/** Strip only actual shell edge whitespace in linear time. */
|
|
871
|
+
function acknowledgementText(command) {
|
|
872
|
+
let start = 0,
|
|
873
|
+
end = command.length;
|
|
874
|
+
while (start < end && " \t\n".includes(command[start])) start += 1;
|
|
875
|
+
while (end > start && " \t\n".includes(command[end - 1])) end -= 1;
|
|
876
|
+
return command.slice(start, end);
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
/** A literal echo, optionally preceded by a literal cd to the stated root. */
|
|
880
|
+
function acceptanceRequest(command) {
|
|
881
|
+
const text = acknowledgementText(command);
|
|
882
|
+
const words = acknowledgementWords(text.replace(/;$/u, ""));
|
|
883
|
+
if (!words) return null;
|
|
884
|
+
const direct = words.length === 2 && words[0] === "echo";
|
|
885
|
+
const moving =
|
|
886
|
+
words.length === 5 &&
|
|
887
|
+
words[0] === "cd" &&
|
|
888
|
+
typeof words[1] === "string" &&
|
|
889
|
+
words[2] === ACK_AND_SEPARATOR &&
|
|
890
|
+
words[3] === "echo";
|
|
891
|
+
if (!direct && !moving) return null;
|
|
892
|
+
const message = words.at(-1);
|
|
893
|
+
if (typeof message !== "string" || !message.startsWith(`${ACCEPT_PREFIX} `))
|
|
894
|
+
return null;
|
|
895
|
+
const stated = message.slice(ACCEPT_PREFIX.length + 1);
|
|
896
|
+
// The printed protocol names absolute roots. Empty/relative operands and
|
|
897
|
+
// cd's special ~, -, or -- forms cannot authorize a move.
|
|
898
|
+
if (!isAbsolute(stated)) return null;
|
|
899
|
+
const path = realpath(stated);
|
|
900
|
+
const destination =
|
|
901
|
+
moving && isAbsolute(words[1]) ? realpath(words[1]) : null;
|
|
902
|
+
return {
|
|
903
|
+
path,
|
|
904
|
+
validMove: !moving || (destination !== null && destination === path),
|
|
905
|
+
};
|
|
753
906
|
}
|
|
754
907
|
|
|
755
908
|
/**
|
|
756
|
-
*
|
|
757
|
-
*
|
|
758
|
-
* The path is compared against what the session is measurably in, not against
|
|
759
|
-
* what it says it wants. An acknowledgement naming somewhere else is the case
|
|
760
|
-
* this is for: it means the operator is reasoning about a tree they are not in.
|
|
909
|
+
* Validate the initial recovery root against the identity captured at baseline.
|
|
910
|
+
* The current checkout may have been removed or deliberately rebound elsewhere.
|
|
761
911
|
*/
|
|
912
|
+
function isOriginalRoot(state, path) {
|
|
913
|
+
const original = state?.originalRoot ?? state?.boundRoot;
|
|
914
|
+
if (path !== original || worktreeRoot(path) !== path) return false;
|
|
915
|
+
// Older state can only prove the repository of its established binding.
|
|
916
|
+
const common = state.originalCommonDir ?? repositoryIdentity(state.boundRoot);
|
|
917
|
+
return common !== null && common === repositoryIdentity(path);
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
/** Acknowledgements select intent; the next call must prove actual movement. */
|
|
762
921
|
function handleAcceptance(payload, observed) {
|
|
763
922
|
const command = payload.tool_input?.command;
|
|
764
923
|
if (typeof command !== "string" || !command.includes(ACCEPT_PREFIX))
|
|
765
924
|
return null;
|
|
766
|
-
const
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
const
|
|
770
|
-
const
|
|
771
|
-
|
|
925
|
+
const request = acceptanceRequest(command);
|
|
926
|
+
if (!request) return null;
|
|
927
|
+
const { path, validMove } = request;
|
|
928
|
+
const previous = readState(bindingKey(payload), payload);
|
|
929
|
+
const original = previous?.originalRoot ?? previous?.boundRoot;
|
|
930
|
+
const recovering = isOriginalRoot(previous, path);
|
|
931
|
+
const offered =
|
|
932
|
+
path === previous?.offeredRoot &&
|
|
933
|
+
isLinkedWorktree(previous.boundRoot, path);
|
|
934
|
+
if (!validMove || (path !== observed && !recovering && !offered)) {
|
|
935
|
+
const suggestion = observed ?? original;
|
|
772
936
|
return refuse([
|
|
773
937
|
`worktree-binding-guard: this acknowledgement names ${path ?? "no path"},`,
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
938
|
+
"but it is not a valid move to the observed, original, or offered worktree. Not rebinding.",
|
|
939
|
+
...(suggestion
|
|
940
|
+
? [
|
|
941
|
+
"Acknowledge the measured or original worktree:",
|
|
942
|
+
acceptanceLine(suggestion),
|
|
943
|
+
]
|
|
944
|
+
: []),
|
|
777
945
|
]);
|
|
778
946
|
}
|
|
779
|
-
writeState(
|
|
947
|
+
const written = writeState(
|
|
780
948
|
bindingKey(payload),
|
|
781
949
|
{
|
|
782
|
-
boundRoot:
|
|
950
|
+
boundRoot: path,
|
|
783
951
|
claimedRoot: null,
|
|
952
|
+
offeredRoot: null,
|
|
784
953
|
updatedAt: new Date().toISOString(),
|
|
785
954
|
},
|
|
786
955
|
payload
|
|
787
956
|
);
|
|
788
|
-
|
|
957
|
+
if (written)
|
|
958
|
+
say(
|
|
959
|
+
path === observed
|
|
960
|
+
? `bound to ${path}`
|
|
961
|
+
: `binding set to ${path}; move there before further guarded calls`
|
|
962
|
+
);
|
|
789
963
|
return 0;
|
|
790
964
|
}
|
|
791
965
|
|
|
@@ -985,6 +1159,11 @@ function evaluate(payload) {
|
|
|
985
1159
|
}
|
|
986
1160
|
const binding = bindingKey(payload);
|
|
987
1161
|
const observed = worktreeRoot(cwd);
|
|
1162
|
+
// The initial-root recovery acknowledgement also works outside any repo.
|
|
1163
|
+
if (GUARDED_TOOLS.has(payload.tool_name)) {
|
|
1164
|
+
const accepted = handleAcceptance(payload, observed);
|
|
1165
|
+
if (accepted !== null) return accepted;
|
|
1166
|
+
}
|
|
988
1167
|
if (!observed) return 0;
|
|
989
1168
|
|
|
990
1169
|
if (payload.hook_event_name === "SessionStart") {
|
|
@@ -996,14 +1175,18 @@ function evaluate(payload) {
|
|
|
996
1175
|
return 0;
|
|
997
1176
|
}
|
|
998
1177
|
if (payload.tool_name === "EnterWorktree") {
|
|
1178
|
+
const previous = readState(binding, payload);
|
|
1179
|
+
if (
|
|
1180
|
+
previous?.boundRoot &&
|
|
1181
|
+
previous.boundRoot !== observed &&
|
|
1182
|
+
!isLinkedWorktree(previous.boundRoot, observed)
|
|
1183
|
+
)
|
|
1184
|
+
return 0;
|
|
999
1185
|
recordClaim(payload, observed);
|
|
1000
1186
|
return 0;
|
|
1001
1187
|
}
|
|
1002
1188
|
if (!GUARDED_TOOLS.has(payload.tool_name)) return 0;
|
|
1003
1189
|
|
|
1004
|
-
const accepted = handleAcceptance(payload, observed);
|
|
1005
|
-
if (accepted !== null) return accepted;
|
|
1006
|
-
|
|
1007
1190
|
const state = readState(binding, payload);
|
|
1008
1191
|
if (!state?.boundRoot) {
|
|
1009
1192
|
// No baseline means SessionStart did not run for this session — an older
|
|
@@ -1024,6 +1207,11 @@ function evaluate(payload) {
|
|
|
1024
1207
|
);
|
|
1025
1208
|
return 0;
|
|
1026
1209
|
}
|
|
1210
|
+
if (
|
|
1211
|
+
state.boundRoot !== observed &&
|
|
1212
|
+
!isLinkedWorktree(state.boundRoot, observed)
|
|
1213
|
+
)
|
|
1214
|
+
return 0;
|
|
1027
1215
|
if (state.claimedRoot && state.claimedRoot !== observed) {
|
|
1028
1216
|
return unconfirmedSwitch(state.claimedRoot, observed);
|
|
1029
1217
|
}
|
|
@@ -1033,6 +1221,7 @@ function evaluate(payload) {
|
|
|
1033
1221
|
{
|
|
1034
1222
|
boundRoot: observed,
|
|
1035
1223
|
claimedRoot: null,
|
|
1224
|
+
offeredRoot: null,
|
|
1036
1225
|
updatedAt: new Date().toISOString(),
|
|
1037
1226
|
},
|
|
1038
1227
|
payload
|
|
@@ -1043,7 +1232,10 @@ function evaluate(payload) {
|
|
|
1043
1232
|
// Last, and only once the session is provably where it should be: a script
|
|
1044
1233
|
// that moves somewhere else after this check has already run.
|
|
1045
1234
|
const reach = scriptReachingForeignTree(payload, observed);
|
|
1046
|
-
if (reach)
|
|
1235
|
+
if (reach) {
|
|
1236
|
+
writeState(binding, { offeredRoot: reach.foreign }, payload);
|
|
1237
|
+
return reachesOut(reach.script, reach.foreign, observed);
|
|
1238
|
+
}
|
|
1047
1239
|
return 0;
|
|
1048
1240
|
}
|
|
1049
1241
|
|