@christang/keel 5.194.0 → 5.196.0
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/.claude-plugin/plugin.json +1 -1
- package/assets/bootstrap/AGENTS.md +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/plugins/keel/.claude-plugin/plugin.json +1 -1
- package/plugins/keel/.codex-plugin/plugin.json +1 -1
- package/plugins/keel/commands/shift.md +2 -2
- package/plugins/keel/scripts/session-start.js +18 -1
- package/scripts/validation/common.py +2 -2
- package/scripts/validation/hosts.py +42 -0
- package/scripts/validation/registry.py +3 -0
- package/scripts/validation/shift.py +107 -0
- package/src/core/shift.js +29 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.196.0",
|
|
4
4
|
"description": "Keel OpenSpec execution discipline: stateless continuity, task capsules, deterministic gates, and expectation alignment for Codex and Claude Code.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "TanglmChris",
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@christang/keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.196.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@christang/keel",
|
|
9
|
-
"version": "5.
|
|
9
|
+
"version": "5.196.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@fission-ai/openspec": "^1.4.1"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.196.0",
|
|
4
4
|
"description": "Keel OpenSpec execution discipline: stateless continuity, task capsules, deterministic gates, and expectation alignment for Codex and Claude Code.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "TanglmChris",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.196.0",
|
|
4
4
|
"description": "Keel OpenSpec execution discipline: stateless continuity, task capsules, deterministic gates, and expectation alignment for Codex and Claude Code.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "TanglmChris",
|
|
@@ -13,7 +13,7 @@ keel shift check
|
|
|
13
13
|
Exit 0 means ready. Exit 1 lists items. Deal with each before going on, or stop and ask the owner when one is not yours to settle:
|
|
14
14
|
|
|
15
15
|
- Uncommitted changes, unpushed commits, a write guard, a lock lease, a linked worktree: commit and push, run `keel guard clear`, release the lease, or remove the worktree you made. Do not discard work to make the list empty.
|
|
16
|
-
- A process:
|
|
16
|
+
- A process: the check already leaves out the keep-awake the host runs under this session, such as `caffeinate -i -t 300`. A server, watcher or job you started is yours: stop it, or ask the owner before leaving it running.
|
|
17
17
|
|
|
18
18
|
Then act on the `memory:` note: recheck what this session wrote to memory, and remove what this shift made untrue or what the repository can answer. It never blocks the shift.
|
|
19
19
|
|
|
@@ -32,7 +32,7 @@ Name commits and branches by id; `keel shift resume` checks them against the rem
|
|
|
32
32
|
|
|
33
33
|
## 3. Hand over
|
|
34
34
|
|
|
35
|
-
Use a quoted heredoc, so backticks in the note are not run. When
|
|
35
|
+
Use a quoted heredoc, so backticks in the note are not run. When the owner let a listed process stay, add `--force-reason "<which process, and that the owner let it stay>"`.
|
|
36
36
|
|
|
37
37
|
```bash
|
|
38
38
|
keel shift ready --wake --file - <<'EOF'
|
|
@@ -227,6 +227,18 @@ function installedTarget(cwd) {
|
|
|
227
227
|
return "codex";
|
|
228
228
|
}
|
|
229
229
|
|
|
230
|
+
// Keel's own source repository, by the test `isKeelSourceRepo` makes
|
|
231
|
+
// (src/core/capabilities.js), inlined because these scripts load nothing from
|
|
232
|
+
// src/core. There the managed block is the checked-out branch's own version.
|
|
233
|
+
function keelSourceRepo(cwd) {
|
|
234
|
+
try {
|
|
235
|
+
if (JSON.parse(fs.readFileSync(path.join(cwd, "package.json"), "utf8")).name !== "@christang/keel") return false;
|
|
236
|
+
} catch {
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
return fs.existsSync(path.join(cwd, "plugins", "keel"));
|
|
240
|
+
}
|
|
241
|
+
|
|
230
242
|
// Three versions are comparable in any repository: the plugin executing this
|
|
231
243
|
// hook, the CLI it just invoked, and the protocol version the repository
|
|
232
244
|
// stamped into its managed block. Keel reports the disagreement and stops
|
|
@@ -288,7 +300,12 @@ function versionReport(cwd, cli, pathCli = null) {
|
|
|
288
300
|
const parts = [];
|
|
289
301
|
if (pending) parts.push(`The host has already installed plugin ${pending}, so nothing needs updating.`);
|
|
290
302
|
else if (runtimeBehind || !protocolBehind) parts.push(`Updating is ${plugin.remedy}, which Keel names and does not run.`);
|
|
291
|
-
if (protocolBehind) {
|
|
303
|
+
if (protocolBehind && keelSourceRepo(cwd)) {
|
|
304
|
+
// #446 D2: a refresh is not the remedy here, and `keel context` prints no
|
|
305
|
+
// Protocol: line in this repository.
|
|
306
|
+
parts.push("This is Keel's source repository, whose protocol block is the checked-out branch's own version: "
|
|
307
|
+
+ "an older one means the branch is behind its default branch, so start from that branch rather than refreshing.");
|
|
308
|
+
} else if (protocolBehind) {
|
|
292
309
|
parts.push(`The repository's protocol block is behind: refresh it with \`keel --install --target ${installedTarget(cwd)}\`, `
|
|
293
310
|
+ "the command `keel context` names on its Protocol: line.");
|
|
294
311
|
}
|
|
@@ -35,10 +35,10 @@ os.environ["KEEL_UPDATE_CLAUDE"] = str(Path(tempfile.gettempdir()) / "keel-suite
|
|
|
35
35
|
os.environ["KEEL_UPDATE_CODEX"] = str(Path(tempfile.gettempdir()) / "keel-suite-has-no-codex")
|
|
36
36
|
|
|
37
37
|
|
|
38
|
-
PACKAGE_VERSION = "5.
|
|
38
|
+
PACKAGE_VERSION = "5.196.0"
|
|
39
39
|
|
|
40
40
|
|
|
41
|
-
PROTOCOL_VERSION = "5.
|
|
41
|
+
PROTOCOL_VERSION = "5.196.0"
|
|
42
42
|
|
|
43
43
|
|
|
44
44
|
LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
|
|
@@ -1638,6 +1638,48 @@ def plant_spawn_recorder(path: Path) -> str:
|
|
|
1638
1638
|
return f"--require {path}"
|
|
1639
1639
|
|
|
1640
1640
|
|
|
1641
|
+
def validate_session_start_source_repo_protocol_scenario() -> int:
|
|
1642
|
+
"""Issue #446 D2: in Keel's source repository a lagging protocol is a lagging branch.
|
|
1643
|
+
|
|
1644
|
+
There the managed block is the checked-out branch's own version, and
|
|
1645
|
+
`keel context` prints no Protocol: line, so naming the refresh sends the
|
|
1646
|
+
maintainer to the wrong command. Elsewhere the refresh is still named.
|
|
1647
|
+
"""
|
|
1648
|
+
label = "session-start-source-repo-protocol:"
|
|
1649
|
+
event = {"hook_event_name": "SessionStart", "source": "startup"}
|
|
1650
|
+
with tempfile.TemporaryDirectory(prefix="keel-446-hook-") as raw:
|
|
1651
|
+
tmp = Path(raw)
|
|
1652
|
+
plugin = plant_session_start_plugin(tmp / "plugin", "5.9.0")
|
|
1653
|
+
cli = fake_keel_cli(tmp / "cli.js", "5.9.0")
|
|
1654
|
+
lagging = "<!-- keel:start version=5.2.0 -->\n## Session Start\n<!-- keel:end -->\n"
|
|
1655
|
+
source = tmp / "keel-source"
|
|
1656
|
+
write_text(source / "openspec/changes/demo/tasks.md", task_contract_fixture())
|
|
1657
|
+
write_text(source / "CLAUDE.md", lagging)
|
|
1658
|
+
write_text(source / "package.json", json.dumps({"name": "@christang/keel", "version": "5.2.0"}) + "\n")
|
|
1659
|
+
write_text(source / "plugins/keel/.keep", "")
|
|
1660
|
+
text = session_start_context(run_session_start_hook(source, event, keel_cli=cli, plugin_root=plugin)) or ""
|
|
1661
|
+
if VERSION_DRIFT_STATEMENT not in text:
|
|
1662
|
+
report(f"{label} the source repository's lagging protocol is not reported at all: {text!r}")
|
|
1663
|
+
return 1
|
|
1664
|
+
for forbidden in ("keel --install", "Protocol: line"):
|
|
1665
|
+
if forbidden in text:
|
|
1666
|
+
report(f"{label} the source repository's report still names {forbidden!r}: {text!r}")
|
|
1667
|
+
return 1
|
|
1668
|
+
if "checked-out branch" not in text:
|
|
1669
|
+
report(f"{label} the source repository's report does not say the block is the checked-out branch's: {text!r}")
|
|
1670
|
+
return 1
|
|
1671
|
+
other = tmp / "user-repo"
|
|
1672
|
+
write_text(other / "openspec/changes/demo/tasks.md", task_contract_fixture())
|
|
1673
|
+
write_text(other / "CLAUDE.md", lagging)
|
|
1674
|
+
write_text(other / "package.json", json.dumps({"name": "user-app"}) + "\n")
|
|
1675
|
+
elsewhere = session_start_context(run_session_start_hook(other, event, keel_cli=cli, plugin_root=plugin)) or ""
|
|
1676
|
+
if "keel --install --target claude" not in elsewhere:
|
|
1677
|
+
report(f"{label} a user repository's lagging protocol no longer names the refresh: {elsewhere!r}")
|
|
1678
|
+
return 1
|
|
1679
|
+
report("session-start-source-repo-protocol scenario passed.")
|
|
1680
|
+
return 0
|
|
1681
|
+
|
|
1682
|
+
|
|
1641
1683
|
def validate_runtime_version_drift_scenario() -> int:
|
|
1642
1684
|
codex_event = {"hook_event_name": "SessionStart", "source": "startup"}
|
|
1643
1685
|
|
|
@@ -386,6 +386,7 @@ SCENARIOS: tuple = (
|
|
|
386
386
|
("native-plugin-manifests", hosts.validate_native_plugin_manifests_scenario),
|
|
387
387
|
("native-plugin-session-start", hosts.validate_native_plugin_session_start_scenario),
|
|
388
388
|
("runtime-version-drift", hosts.validate_runtime_version_drift_scenario),
|
|
389
|
+
("session-start-source-repo-protocol", hosts.validate_session_start_source_repo_protocol_scenario),
|
|
389
390
|
("plugin-runs-its-own-cli", hosts.validate_plugin_runs_its_own_cli_scenario),
|
|
390
391
|
("drift-names-a-pending-reload", hosts.validate_drift_names_a_pending_reload_scenario),
|
|
391
392
|
("hook-hands-off-to-installed-update", hosts.validate_hook_hands_off_to_installed_update_scenario),
|
|
@@ -426,6 +427,7 @@ SCENARIOS: tuple = (
|
|
|
426
427
|
("shift-history-show", shift.validate_shift_history_show_scenario),
|
|
427
428
|
("shift-resume-checks-commits", shift.validate_shift_resume_checks_commits_scenario),
|
|
428
429
|
("shift-resume-skips-session-ids", shift.validate_shift_resume_skips_session_ids_scenario),
|
|
430
|
+
("shift-resume-names-merged-branch", shift.validate_shift_resume_names_merged_branch_scenario),
|
|
429
431
|
("shift-keeps-transcripts", shift.validate_shift_keeps_transcripts_scenario),
|
|
430
432
|
("shift-keeps-found-transcripts", shift.validate_shift_keeps_found_transcripts_scenario),
|
|
431
433
|
("role-drift", shift.validate_role_drift_scenario),
|
|
@@ -459,6 +461,7 @@ SCENARIOS: tuple = (
|
|
|
459
461
|
("tick-runs-each-patrol", shift.validate_tick_runs_each_patrol_scenario),
|
|
460
462
|
("launchd-stable-node", shift.validate_launchd_stable_node_scenario),
|
|
461
463
|
("shift-slash-command", shift.validate_shift_slash_command_scenario),
|
|
464
|
+
("shift-check-skips-host-keep-awake", shift.validate_shift_check_skips_host_keep_awake_scenario),
|
|
462
465
|
("patrol-exit-says-who-acts", shift.validate_patrol_exit_says_who_acts_scenario),
|
|
463
466
|
("patrol-nudge", shift.validate_patrol_nudge_scenario),
|
|
464
467
|
("patrol-escalate", shift.validate_patrol_escalate_scenario),
|
|
@@ -710,6 +710,65 @@ def validate_launchd_stable_node_scenario() -> int:
|
|
|
710
710
|
return 0
|
|
711
711
|
|
|
712
712
|
|
|
713
|
+
def validate_shift_check_skips_host_keep_awake_scenario() -> int:
|
|
714
|
+
"""Issue #447: the host's own keep-awake is not a loose end of the shift.
|
|
715
|
+
|
|
716
|
+
Claude Code runs `caffeinate` as a child of the session's host process,
|
|
717
|
+
an ancestor of the check. That one is left out; a `caffeinate` with any
|
|
718
|
+
other parent, and any other program, are still named.
|
|
719
|
+
"""
|
|
720
|
+
label = "shift-check-skips-host-keep-awake:"
|
|
721
|
+
with tempfile.TemporaryDirectory(prefix="keel-shift-447-") as raw:
|
|
722
|
+
base = Path(raw)
|
|
723
|
+
_rtl, verify, env, _ = shift_scratch(base)
|
|
724
|
+
# A stand-in named `caffeinate` by its argv[0]: macOS kills a copied
|
|
725
|
+
# system binary, and `ps` shows the name a process was exec'd under.
|
|
726
|
+
# This process is an ancestor of the `keel shift check` it runs, as the
|
|
727
|
+
# session's claude process is of the shell that runs the check.
|
|
728
|
+
host = subprocess.Popen(["bash", "-c", "exec -a caffeinate sleep 90"], cwd=verify, start_new_session=True)
|
|
729
|
+
# Orphaned in a process group of its own, as a keep-awake another
|
|
730
|
+
# session or a script left behind would be.
|
|
731
|
+
subprocess.run(["bash", "-c", "bash -c 'exec -a caffeinate sleep 91' >/dev/null 2>&1 &"], cwd=verify, check=True,
|
|
732
|
+
start_new_session=True)
|
|
733
|
+
found: list[str] = []
|
|
734
|
+
for _ in range(50):
|
|
735
|
+
found = subprocess.run(["pgrep", "-f", "^caffeinate 91"], capture_output=True, text=True).stdout.split()
|
|
736
|
+
if found:
|
|
737
|
+
break
|
|
738
|
+
time.sleep(0.1)
|
|
739
|
+
if not found:
|
|
740
|
+
report(f"{label} the orphaned stand-in caffeinate did not start.")
|
|
741
|
+
host.kill()
|
|
742
|
+
return 1
|
|
743
|
+
orphan = int(found[0])
|
|
744
|
+
sleeper = subprocess.Popen(["sleep", "92"], cwd=verify, start_new_session=True)
|
|
745
|
+
try:
|
|
746
|
+
listed = run_keel(verify, "shift", "check", env=env)
|
|
747
|
+
if f"PID {host.pid}," in listed.stdout:
|
|
748
|
+
report(f"{label} keel shift check names the host's own keep-awake: {listed.stdout.strip()}")
|
|
749
|
+
return 1
|
|
750
|
+
for name, pid in (("an orphaned caffeinate", orphan), ("a sleep", sleeper.pid)):
|
|
751
|
+
if f"PID {pid}," not in listed.stdout:
|
|
752
|
+
report(f"{label} keel shift check does not name {name} (PID {pid}): {listed.stdout.strip()}")
|
|
753
|
+
return 1
|
|
754
|
+
os.kill(orphan, signal.SIGKILL)
|
|
755
|
+
sleeper.kill()
|
|
756
|
+
sleeper.wait()
|
|
757
|
+
time.sleep(0.3)
|
|
758
|
+
clean = run_keel(verify, "shift", "check", env=env)
|
|
759
|
+
if clean.returncode != 0:
|
|
760
|
+
report(f"{label} with only the host's keep-awake running, keel shift check exited {clean.returncode}: {clean.stdout.strip()}")
|
|
761
|
+
return 1
|
|
762
|
+
finally:
|
|
763
|
+
for proc in (host, sleeper):
|
|
764
|
+
proc.kill()
|
|
765
|
+
proc.wait()
|
|
766
|
+
with contextlib.suppress(ProcessLookupError):
|
|
767
|
+
os.kill(orphan, signal.SIGKILL)
|
|
768
|
+
report("shift-check-skips-host-keep-awake scenario passed.")
|
|
769
|
+
return 0
|
|
770
|
+
|
|
771
|
+
|
|
713
772
|
def validate_shift_slash_command_scenario() -> int:
|
|
714
773
|
"""Issue #386: a session changes its own shift with one slash command.
|
|
715
774
|
|
|
@@ -1580,6 +1639,54 @@ def validate_shift_resume_skips_session_ids_scenario() -> int:
|
|
|
1580
1639
|
return 0
|
|
1581
1640
|
|
|
1582
1641
|
|
|
1642
|
+
def validate_shift_resume_names_merged_branch_scenario() -> int:
|
|
1643
|
+
"""Issue #446: resume says when the worktree is on a branch already merged.
|
|
1644
|
+
|
|
1645
|
+
A new shift starts on the branch the last one left, which `land` has
|
|
1646
|
+
usually merged; resume names it and says to start from the default
|
|
1647
|
+
branch. A branch with commits of its own gets no such line.
|
|
1648
|
+
"""
|
|
1649
|
+
label = "shift-resume-names-merged-branch:"
|
|
1650
|
+
with tempfile.TemporaryDirectory(prefix="keel-shift-446-") as raw:
|
|
1651
|
+
base = Path(raw)
|
|
1652
|
+
rtl, verify, env, _ = shift_scratch(base)
|
|
1653
|
+
default = subprocess.run(["git", "rev-parse", "--abbrev-ref", "HEAD"], cwd=rtl, text=True,
|
|
1654
|
+
capture_output=True, check=True).stdout.strip()
|
|
1655
|
+
|
|
1656
|
+
def git(*args: str) -> str:
|
|
1657
|
+
return subprocess.run(["git", *args], cwd=verify, text=True, capture_output=True, check=True).stdout.strip()
|
|
1658
|
+
|
|
1659
|
+
git("fetch", "-q", "origin")
|
|
1660
|
+
git("switch", "-q", "-c", "feat", f"origin/{default}")
|
|
1661
|
+
git("commit", "-q", "--allow-empty", "-m", "feat work")
|
|
1662
|
+
git("push", "-q", "origin", f"feat:{default}")
|
|
1663
|
+
after = git("commit-tree", git("rev-parse", "HEAD^{tree}"), "-p", "HEAD", "-m", "next shift's work")
|
|
1664
|
+
git("push", "-q", "origin", f"{after}:refs/heads/{default}")
|
|
1665
|
+
git("fetch", "-q", "origin")
|
|
1666
|
+
|
|
1667
|
+
def resumed(note: str) -> str:
|
|
1668
|
+
ready = run_keel(verify, "shift", "ready", note, env=env)
|
|
1669
|
+
if ready.returncode != 0:
|
|
1670
|
+
return f"ready failed: {ready.stdout} {ready.stderr}"
|
|
1671
|
+
return run_keel(verify, "shift", "resume", env=env).stdout
|
|
1672
|
+
|
|
1673
|
+
merged = resumed("next: pick the next issue")
|
|
1674
|
+
notice = next((line for line in merged.splitlines() if f"already in origin/{default}" in line and "feat" in line), "")
|
|
1675
|
+
if not notice:
|
|
1676
|
+
report(f"{label} resume on merged branch feat does not say so: {merged!r}")
|
|
1677
|
+
return 1
|
|
1678
|
+
if "1 commit behind" not in notice:
|
|
1679
|
+
report(f"{label} the merged-branch line does not say 1 commit behind: {notice!r}")
|
|
1680
|
+
return 1
|
|
1681
|
+
git("commit", "-q", "--allow-empty", "-m", "unpushed work")
|
|
1682
|
+
own = resumed("next: push feat")
|
|
1683
|
+
if any("feat" in line and f"already in origin/{default}" in line for line in own.splitlines()):
|
|
1684
|
+
report(f"{label} a branch with an unpushed commit is reported as merged: {own!r}")
|
|
1685
|
+
return 1
|
|
1686
|
+
report("shift-resume-names-merged-branch scenario passed.")
|
|
1687
|
+
return 0
|
|
1688
|
+
|
|
1689
|
+
|
|
1583
1690
|
def validate_shift_resume_checks_commits_scenario() -> int:
|
|
1584
1691
|
"""Issue #347: a shift note's commit ids go stale before the next shift reads it.
|
|
1585
1692
|
|
package/src/core/shift.js
CHANGED
|
@@ -133,6 +133,8 @@ function processDirectories() {
|
|
|
133
133
|
|
|
134
134
|
// An interactive shell open in the worktree, such as a terminal tab, is not
|
|
135
135
|
// work in progress; what it runs is, and is listed by its own entry.
|
|
136
|
+
const HOST_KEEP_AWAKE = /^(?:\S*\/)?caffeinate(?:\s|$)/;
|
|
137
|
+
|
|
136
138
|
const IDLE_SHELL = /^-?(?:\S*\/)?(?:zsh|bash|sh|dash|fish)(?:\s+-[il]+)*\s*$/;
|
|
137
139
|
|
|
138
140
|
function liveProcesses(worktree) {
|
|
@@ -147,6 +149,10 @@ function liveProcesses(worktree) {
|
|
|
147
149
|
if (own.has(pid) || !inside(realpath(cwd), worktree)) continue;
|
|
148
150
|
const row = table.get(pid);
|
|
149
151
|
if (!row || row.pgid === group || IDLE_SHELL.test(row.command)) continue;
|
|
152
|
+
// The keep-awake the session's host runs under it (#447 D1): its parent is
|
|
153
|
+
// one of the checker's ancestors, the host process itself. Not init, which
|
|
154
|
+
// every orphan has for a parent and every process for an ancestor.
|
|
155
|
+
if (row.ppid > 1 && own.has(row.ppid) && HOST_KEEP_AWAKE.test(row.command)) continue;
|
|
150
156
|
found.push(row);
|
|
151
157
|
}
|
|
152
158
|
return found.sort((a, b) => a.pid - b.pid);
|
|
@@ -1033,6 +1039,21 @@ function noteCommits(cwd, text, sessions = []) {
|
|
|
1033
1039
|
return commits;
|
|
1034
1040
|
}
|
|
1035
1041
|
|
|
1042
|
+
// A new shift starts on the branch the last one left, which `land` has
|
|
1043
|
+
// usually merged (#446 D1): named when HEAD is behind the remote default branch
|
|
1044
|
+
// and contained in it. Nothing is fetched.
|
|
1045
|
+
function mergedBranch(cwd) {
|
|
1046
|
+
const base = remoteDefault(cwd);
|
|
1047
|
+
if (!base) return null;
|
|
1048
|
+
const head = git(cwd, ["rev-parse", "--verify", "--quiet", "HEAD"]);
|
|
1049
|
+
const tip = git(cwd, ["rev-parse", "--verify", "--quiet", `refs/remotes/${base}`]);
|
|
1050
|
+
if (!head.ok || !tip.ok || head.out === tip.out) return null;
|
|
1051
|
+
if (!git(cwd, ["merge-base", "--is-ancestor", head.out, tip.out]).ok) return null;
|
|
1052
|
+
const branch = git(cwd, ["symbolic-ref", "--quiet", "--short", "HEAD"]);
|
|
1053
|
+
const behind = Number(git(cwd, ["rev-list", "--count", `${head.out}..${tip.out}`]).out) || 0;
|
|
1054
|
+
return { branch: branch.ok ? branch.out : null, base, behind };
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1036
1057
|
function lastFetch(cwd) {
|
|
1037
1058
|
const file = git(cwd, ["rev-parse", "--git-path", "FETCH_HEAD"]);
|
|
1038
1059
|
if (!file.ok) return null;
|
|
@@ -1052,7 +1073,7 @@ function resume(where, named = null) {
|
|
|
1052
1073
|
const history = path.join(shiftDir(where), "history", `${role || path.basename(note, ".md")}-${stamp}.md`);
|
|
1053
1074
|
fs.mkdirSync(path.dirname(history), { recursive: true });
|
|
1054
1075
|
fs.renameSync(note, history);
|
|
1055
|
-
if (!role) return { role: null, note: history, text, told: null, commits: noteCommits(where.worktree, text, knownSessionIds(where)), fetched: lastFetch(where.worktree) };
|
|
1076
|
+
if (!role) return { role: null, note: history, text, told: null, commits: noteCommits(where.worktree, text, knownSessionIds(where)), merged_branch: mergedBranch(where.worktree), fetched: lastFetch(where.worktree) };
|
|
1056
1077
|
// The cold-start message has done its work once the note is read.
|
|
1057
1078
|
for (const record of store.unread(where, role)) {
|
|
1058
1079
|
if (isShift(record)) store.advanceCursor(where, role, record.group, record.id);
|
|
@@ -1066,7 +1087,7 @@ function resume(where, named = null) {
|
|
|
1066
1087
|
? store.post(where, { group, text, refs: [REF] })
|
|
1067
1088
|
: store.writeRecord(where, { group, kind: "message", from: role, refs: [REF], text })).id;
|
|
1068
1089
|
}
|
|
1069
|
-
return { role, note: history, text, told, waiting: role ? unstarted(where, role) : [], commits: noteCommits(where.worktree, text, knownSessionIds(where)), fetched: lastFetch(where.worktree) };
|
|
1090
|
+
return { role, note: history, text, told, waiting: role ? unstarted(where, role) : [], commits: noteCommits(where.worktree, text, knownSessionIds(where)), merged_branch: mergedBranch(where.worktree), fetched: lastFetch(where.worktree) };
|
|
1070
1091
|
}
|
|
1071
1092
|
|
|
1072
1093
|
function status(where) {
|
|
@@ -1531,7 +1552,12 @@ function runShift(argv) {
|
|
|
1531
1552
|
? `\n\nCommits the note names, against the remote-tracking refs (not fetched; last fetch ${result.fetched || "never"}):\n`
|
|
1532
1553
|
+ result.commits.map((c) => `- ${c.token}: ${c.marks.join("; ")}`).join("\n")
|
|
1533
1554
|
: "";
|
|
1534
|
-
|
|
1555
|
+
const merged = result.merged_branch;
|
|
1556
|
+
const stale = merged
|
|
1557
|
+
? `\n\nThis worktree is on ${merged.branch ? `\`${merged.branch}\`` : "a detached HEAD"}, already in ${merged.base} and `
|
|
1558
|
+
+ `${merged.behind} commit${merged.behind === 1 ? "" : "s"} behind it: start new work from ${merged.base}.`
|
|
1559
|
+
: "";
|
|
1560
|
+
out(result, `${result.text.replace(/\s+$/, "")}${commits}${stale}\n\n(The note moved to ${result.note}.)${still}${remind ? `\n\n${patrolReminder(patrol)}` : ""}${remote}`);
|
|
1535
1561
|
return 0;
|
|
1536
1562
|
}
|
|
1537
1563
|
case "history": {
|