@christang/keel 5.98.0 → 5.99.1
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/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/scripts/session-start.js +48 -1
- package/scripts/validate_plugin.py +97 -10
- package/src/core/chat/notice.js +1 -9
- package/src/core/context.js +9 -0
- package/src/core/shift.js +74 -29
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@christang/keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.99.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@christang/keel",
|
|
9
|
-
"version": "5.
|
|
9
|
+
"version": "5.99.1",
|
|
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.99.1",
|
|
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.99.1",
|
|
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",
|
|
@@ -445,6 +445,47 @@ function fallback(reason) {
|
|
|
445
445
|
);
|
|
446
446
|
}
|
|
447
447
|
|
|
448
|
+
// The git common directory of `cwd`, read from `.git` without spawning git.
|
|
449
|
+
function gitCommonDir(cwd) {
|
|
450
|
+
for (let dir = cwd; dir && dir !== path.dirname(dir); dir = path.dirname(dir)) {
|
|
451
|
+
const dotGit = path.join(dir, ".git");
|
|
452
|
+
let stat;
|
|
453
|
+
try {
|
|
454
|
+
stat = fs.statSync(dotGit);
|
|
455
|
+
} catch {
|
|
456
|
+
continue;
|
|
457
|
+
}
|
|
458
|
+
if (stat.isDirectory()) return dotGit;
|
|
459
|
+
const match = fs.readFileSync(dotGit, "utf8").match(/^gitdir:\s*(.+)$/m);
|
|
460
|
+
if (!match) return null;
|
|
461
|
+
const gitdir = path.resolve(dir, match[1].trim());
|
|
462
|
+
return /[\\/]worktrees[\\/][^\\/]+$/.test(gitdir) ? path.dirname(path.dirname(gitdir)) : gitdir;
|
|
463
|
+
}
|
|
464
|
+
return null;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// A repository without OpenSpec gets no projection, except a note from the
|
|
468
|
+
// previous shift (shift-without-role D3): checked on disk first, so the
|
|
469
|
+
// common case spawns nothing.
|
|
470
|
+
function shiftOnly(cwd) {
|
|
471
|
+
const common = gitCommonDir(cwd);
|
|
472
|
+
if (!common || !fs.existsSync(path.join(common, "keel-chat", "shift"))) return 0;
|
|
473
|
+
const result = runKeel(cwd, ["context", "--json"], keelCommand().command);
|
|
474
|
+
let context = null;
|
|
475
|
+
try {
|
|
476
|
+
context = JSON.parse(result.stdout);
|
|
477
|
+
} catch {
|
|
478
|
+
return 0;
|
|
479
|
+
}
|
|
480
|
+
if (!context || !context.shift || !context.shift.since) return 0;
|
|
481
|
+
const shift = `shift: your previous shift left a note (${context.shift.since}); run \`keel shift resume\` before anything else.`;
|
|
482
|
+
emit(
|
|
483
|
+
`Keel: ${shift} It authorizes nothing.`,
|
|
484
|
+
panel([`Keel: ${shift[0].toUpperCase()}${shift.slice(1)}`, DISPOSABLE])
|
|
485
|
+
);
|
|
486
|
+
return 0;
|
|
487
|
+
}
|
|
488
|
+
|
|
448
489
|
function main() {
|
|
449
490
|
const input = readStdin();
|
|
450
491
|
const handed = handOff(__filename, input, 12000);
|
|
@@ -459,7 +500,7 @@ function main() {
|
|
|
459
500
|
typeof event.cwd === "string" && event.cwd ? event.cwd : process.cwd();
|
|
460
501
|
|
|
461
502
|
if (!fs.existsSync(path.join(cwd, "openspec"))) {
|
|
462
|
-
return
|
|
503
|
+
return shiftOnly(cwd);
|
|
463
504
|
}
|
|
464
505
|
|
|
465
506
|
const cli = keelCommand();
|
|
@@ -571,6 +612,12 @@ function main() {
|
|
|
571
612
|
}
|
|
572
613
|
const pointer = precedentPointer(cwd);
|
|
573
614
|
if (pointer) lines.push(`- ${pointer}`);
|
|
615
|
+
// A note from the previous shift (shift-without-role D3), on every host.
|
|
616
|
+
if (context.shift && context.shift.since) {
|
|
617
|
+
const shift = `shift: your previous shift left a note (${context.shift.since}); run \`keel shift resume\` before anything else.`;
|
|
618
|
+
lines.push(`- ${shift}`);
|
|
619
|
+
human.splice(human.length - 1, 0, shift[0].toUpperCase() + shift.slice(1));
|
|
620
|
+
}
|
|
574
621
|
lines.push(`- report this state ${DISCLOSURE}; it authorizes nothing.`);
|
|
575
622
|
emit(lines.join("\n"), panel(human));
|
|
576
623
|
return 0;
|
|
@@ -47,8 +47,8 @@ REQUIRED_SCRIPTS = [
|
|
|
47
47
|
"scripts/validate_plugin.py",
|
|
48
48
|
]
|
|
49
49
|
|
|
50
|
-
PACKAGE_VERSION = "5.
|
|
51
|
-
PROTOCOL_VERSION = "5.
|
|
50
|
+
PACKAGE_VERSION = "5.99.1"
|
|
51
|
+
PROTOCOL_VERSION = "5.99.1"
|
|
52
52
|
LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
|
|
53
53
|
OPENSPEC_SCHEMA_NAME = "keel-spec-driven"
|
|
54
54
|
# Mirrors KEEL_PACKAGE_NAME in scripts/install_to_repo.py, one of the two
|
|
@@ -4481,13 +4481,12 @@ def validate_shift_change_scenario() -> int:
|
|
|
4481
4481
|
return run_keel(cwd, "shift", *args, env=env)
|
|
4482
4482
|
|
|
4483
4483
|
def notice() -> str:
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
input=json.dumps({"hook_event_name": "SessionStart", "cwd": str(verify)}),
|
|
4484
|
+
# The SessionStart projection, which every host runs (shift-without-role D3).
|
|
4485
|
+
session = run_session_start_hook(
|
|
4486
|
+
verify, {"hook_event_name": "SessionStart", "source": "startup", "cwd": str(verify)},
|
|
4487
|
+
keel_cli=f'node "{ROOT / "bin" / "keel.js"}"', extra_env={k: v for k, v in env.items() if k.startswith("KEEL_")},
|
|
4489
4488
|
)
|
|
4490
|
-
return
|
|
4489
|
+
return session_start_context(session) or ""
|
|
4491
4490
|
|
|
4492
4491
|
size = signal.stat().st_size if signal.exists() else 0
|
|
4493
4492
|
requested = shift(rtl, "request", "verify")
|
|
@@ -4517,10 +4516,19 @@ def validate_shift_change_scenario() -> int:
|
|
|
4517
4516
|
subprocess.run(["git", "add", "pushed-not.txt"], cwd=verify, check=True)
|
|
4518
4517
|
subprocess.run(["git", "commit", "-q", "-m", "local only"], cwd=verify, check=True)
|
|
4519
4518
|
write_text(verify / "keel" / "guard.json", "{}\n")
|
|
4520
|
-
|
|
4519
|
+
# A Claude scratchpad of a session started in verify, and one of a
|
|
4520
|
+
# session started elsewhere (shift-temp-owner D1).
|
|
4521
|
+
scratch = Path(tempfile.gettempdir()) / f"claude-{os.getuid()}"
|
|
4522
|
+
slug = re.sub(r"[^A-Za-z0-9]", "-", str(verify.resolve()))
|
|
4523
|
+
temp_tree = scratch / slug / f"keel-test-{os.getpid()}" / "scratchpad" / "own-tmp-tree"
|
|
4524
|
+
other_tree = scratch / "-some-other-dir" / f"keel-test-{os.getpid()}" / "scratchpad" / "other-tmp-tree"
|
|
4525
|
+
for tree in (temp_tree, other_tree):
|
|
4526
|
+
tree.parent.mkdir(parents=True, exist_ok=True)
|
|
4521
4527
|
subprocess.run(["git", "worktree", "add", "-q", "--detach", str(temp_tree)], cwd=verify, check=True, capture_output=True)
|
|
4522
4528
|
run_keel(rtl, "chat", "todo", "soc", "--assignee", "verify", "Rerun the regression", env=env)
|
|
4523
|
-
|
|
4529
|
+
# Its own session, as a job a session leaves behind would be: the check
|
|
4530
|
+
# skips its own command line's process group.
|
|
4531
|
+
sleeper = subprocess.Popen(["sleep", "60"], cwd=verify, start_new_session=True)
|
|
4524
4532
|
try:
|
|
4525
4533
|
checked = shift(verify, "check", "--json")
|
|
4526
4534
|
if checked.returncode != 1:
|
|
@@ -4557,6 +4565,19 @@ def validate_shift_change_scenario() -> int:
|
|
|
4557
4565
|
if clean.returncode != 0:
|
|
4558
4566
|
report(f"{label} keel shift check is not ready on a clean worktree: {clean.stdout.strip()} {clean.stderr.strip()}")
|
|
4559
4567
|
return 1
|
|
4568
|
+
subprocess.run(["git", "worktree", "add", "-q", "--detach", str(other_tree)], cwd=verify, check=True, capture_output=True)
|
|
4569
|
+
try:
|
|
4570
|
+
foreign = shift(verify, "check")
|
|
4571
|
+
if foreign.returncode != 0:
|
|
4572
|
+
report(f"{label} another session's temporary worktree blocked the check: {foreign.stdout.strip()}")
|
|
4573
|
+
return 1
|
|
4574
|
+
if "other-tmp-tree" not in foreign.stdout:
|
|
4575
|
+
report(f"{label} another session's temporary worktree is not listed as a note: {foreign.stdout.strip()}")
|
|
4576
|
+
return 1
|
|
4577
|
+
finally:
|
|
4578
|
+
subprocess.run(["git", "worktree", "remove", "--force", str(other_tree)], cwd=verify, check=False, capture_output=True)
|
|
4579
|
+
shutil.rmtree(scratch / slug / f"keel-test-{os.getpid()}", ignore_errors=True)
|
|
4580
|
+
shutil.rmtree(scratch / "-some-other-dir" / f"keel-test-{os.getpid()}", ignore_errors=True)
|
|
4560
4581
|
|
|
4561
4582
|
ready = shift(verify, "ready", "next: rerun R007 on 1b64e8c")
|
|
4562
4583
|
if ready.returncode != 0:
|
|
@@ -4640,6 +4661,71 @@ def validate_shift_change_scenario() -> int:
|
|
|
4640
4661
|
return 0
|
|
4641
4662
|
|
|
4642
4663
|
|
|
4664
|
+
def validate_shift_without_role_scenario() -> int:
|
|
4665
|
+
"""Owner's remark of 2026-10-05: a shift change needs no chat role.
|
|
4666
|
+
|
|
4667
|
+
In a worktree with no `keel chat` role, `ready` keeps the note per
|
|
4668
|
+
worktree, `keel context` and the SessionStart projection point to it
|
|
4669
|
+
without changing the context's status, and `resume` consumes it.
|
|
4670
|
+
"""
|
|
4671
|
+
label = "shift-without-role:"
|
|
4672
|
+
with tempfile.TemporaryDirectory(prefix="keel-shift-norole-") as raw:
|
|
4673
|
+
base = Path(raw)
|
|
4674
|
+
repo = mailbox_repository(base / "solo")
|
|
4675
|
+
env = chat_environment()
|
|
4676
|
+
common = mailbox_common_dir(repo) / "keel-chat"
|
|
4677
|
+
|
|
4678
|
+
def context() -> dict:
|
|
4679
|
+
return chat_json(run_keel(repo, "context", "--json", env=env))
|
|
4680
|
+
|
|
4681
|
+
before = context().get("status")
|
|
4682
|
+
ready = run_keel(repo, "shift", "ready", "next: rerun R007", env=env)
|
|
4683
|
+
if ready.returncode != 0:
|
|
4684
|
+
report(f"{label} keel shift ready refused in a worktree without a chat role: {ready.stderr.strip()}")
|
|
4685
|
+
return 1
|
|
4686
|
+
notes = list((common / "shift" / "worktree").glob("*.md"))
|
|
4687
|
+
if len(notes) != 1:
|
|
4688
|
+
report(f"{label} ready kept {len(notes)} worktree notes under keel-chat/shift/worktree/, not one.")
|
|
4689
|
+
return 1
|
|
4690
|
+
text = run_keel(repo, "context", env=env).stdout
|
|
4691
|
+
if "keel shift resume" not in text:
|
|
4692
|
+
report(f"{label} keel context does not point to the waiting note: {text.strip()}")
|
|
4693
|
+
return 1
|
|
4694
|
+
if context().get("status") != before:
|
|
4695
|
+
report(f"{label} the waiting note changed the context status from {before!r} to {context().get('status')!r}.")
|
|
4696
|
+
return 1
|
|
4697
|
+
session = run_session_start_hook(
|
|
4698
|
+
repo, {"hook_event_name": "SessionStart", "source": "startup", "cwd": str(repo)},
|
|
4699
|
+
keel_cli=f'node "{ROOT / "bin" / "keel.js"}"',
|
|
4700
|
+
)
|
|
4701
|
+
if "keel shift resume" not in (session_start_context(session) or ""):
|
|
4702
|
+
report(f"{label} the SessionStart projection does not point to the waiting note.")
|
|
4703
|
+
return 1
|
|
4704
|
+
resumed = run_keel(repo, "shift", "resume", env=env)
|
|
4705
|
+
if "rerun R007" not in resumed.stdout:
|
|
4706
|
+
report(f"{label} keel shift resume did not print the note: {resumed.stdout.strip()} {resumed.stderr.strip()}")
|
|
4707
|
+
return 1
|
|
4708
|
+
if notes[0].exists():
|
|
4709
|
+
report(f"{label} resume left the worktree note waiting.")
|
|
4710
|
+
return 1
|
|
4711
|
+
if not list((common / "shift" / "history").glob("*.md")):
|
|
4712
|
+
report(f"{label} resume did not keep the note in history.")
|
|
4713
|
+
return 1
|
|
4714
|
+
if "keel shift resume" in run_keel(repo, "context", env=env).stdout:
|
|
4715
|
+
report(f"{label} keel context still points to a note already resumed.")
|
|
4716
|
+
return 1
|
|
4717
|
+
|
|
4718
|
+
for relative, needle in (("docs/shift-change.md", "no chat role"), ("docs/shift-change.zh-CN.md", "不绑定聊天角色")):
|
|
4719
|
+
if needle not in (ROOT / relative).read_text(encoding="utf-8"):
|
|
4720
|
+
report(f"{label} {relative} does not say a chat role is optional ({needle!r}).")
|
|
4721
|
+
return 1
|
|
4722
|
+
if "shift-without-role" not in {name for name, _ in SCENARIOS}:
|
|
4723
|
+
report(f"{label} scenario is not registered.")
|
|
4724
|
+
return 1
|
|
4725
|
+
report("shift-without-role scenario passed.")
|
|
4726
|
+
return 0
|
|
4727
|
+
|
|
4728
|
+
|
|
4643
4729
|
def validate_chat_archive_scenario() -> int:
|
|
4644
4730
|
"""Issue #187: chat history is archived to an orphan branch, never exposed.
|
|
4645
4731
|
|
|
@@ -37107,6 +37193,7 @@ SCENARIOS: tuple = (
|
|
|
37107
37193
|
("context-names-the-protocol-refresh", validate_context_names_the_protocol_refresh_scenario),
|
|
37108
37194
|
("collected-feedback-is-recorded", validate_collected_feedback_is_recorded_scenario),
|
|
37109
37195
|
("shift-change", validate_shift_change_scenario),
|
|
37196
|
+
("shift-without-role", validate_shift_without_role_scenario),
|
|
37110
37197
|
("init-never-downgrades-openspec", validate_init_never_downgrades_openspec_scenario),
|
|
37111
37198
|
("native-plugin-marketplaces", validate_native_plugin_marketplaces_scenario),
|
|
37112
37199
|
("native-plugin-install-matrix", validate_native_plugin_install_matrix_scenario),
|
package/src/core/chat/notice.js
CHANGED
|
@@ -151,14 +151,6 @@ const OWNER_RULE = "Slack notifies the owner only for messages that write `@owne
|
|
|
151
151
|
+ "needs to see or decide on, and leave it out of routine discussion. Send a risk or decision as its own message "
|
|
152
152
|
+ "with `@owner` rather than inside a status update.";
|
|
153
153
|
|
|
154
|
-
// A shift note waiting for this role (shift-change D7): the new shift reads it
|
|
155
|
-
// before anything else.
|
|
156
|
-
function shiftLine(where, role) {
|
|
157
|
-
const since = require("../shift").pendingNote(where, role);
|
|
158
|
-
if (!since) return null;
|
|
159
|
-
return `keel shift: your previous shift left a note (${since}); run \`keel context\`, then \`keel shift resume\`, before anything else.`;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
154
|
const HOST_EVENTS = {
|
|
163
155
|
"session-start": "SessionStart",
|
|
164
156
|
"user-prompt-submit": "UserPromptSubmit",
|
|
@@ -206,7 +198,7 @@ function hook(event, input, { mail = false } = {}) {
|
|
|
206
198
|
const output = {
|
|
207
199
|
hookSpecificOutput: { hookEventName: "SessionStart", watchPaths: [ensureSignal(where, role), ensureWorktreeSignal(where)] },
|
|
208
200
|
};
|
|
209
|
-
const context = [bridgeLine(where),
|
|
201
|
+
const context = [bridgeLine(where), text].filter(Boolean).join("\n");
|
|
210
202
|
if (context) output.hookSpecificOutput.additionalContext = context;
|
|
211
203
|
return { code: 0, stdout: `${JSON.stringify(output)}\n` };
|
|
212
204
|
}
|
package/src/core/context.js
CHANGED
|
@@ -715,6 +715,10 @@ function resolveContext(repo, options) {
|
|
|
715
715
|
|
|
716
716
|
const protocol = protocolRefresh(repo, keelVersion(), authorization);
|
|
717
717
|
if (protocol) context.protocol = protocol;
|
|
718
|
+
// A note from this worktree's previous shift (shift-without-role D3): a
|
|
719
|
+
// pointer for the new session, which changes no status or selection.
|
|
720
|
+
const shift = require("./shift").waitingFor(repo);
|
|
721
|
+
if (shift) context.shift = shift;
|
|
718
722
|
|
|
719
723
|
// Set here rather than by the caller, so every consumer of the projection —
|
|
720
724
|
// text, JSON, and any host reading it — carries the version without having
|
|
@@ -783,6 +787,10 @@ function protocolRefresh(repo, running, authorization) {
|
|
|
783
787
|
};
|
|
784
788
|
}
|
|
785
789
|
|
|
790
|
+
function shiftLine(shift) {
|
|
791
|
+
return `Shift: your previous shift left a note (${shift.since}); run \`keel shift resume\` before anything else`;
|
|
792
|
+
}
|
|
793
|
+
|
|
786
794
|
function renderProtocol(protocol) {
|
|
787
795
|
const head = `Protocol: ${protocol.file} is stamped ${protocol.stamped}, older than `
|
|
788
796
|
+ `Keel ${protocol.keel}; refresh with \`${protocol.command}\``;
|
|
@@ -859,6 +867,7 @@ function renderContext(result) {
|
|
|
859
867
|
);
|
|
860
868
|
}
|
|
861
869
|
if (result.protocol) lines.push(renderProtocol(result.protocol));
|
|
870
|
+
if (result.shift) lines.push(shiftLine(result.shift));
|
|
862
871
|
for (const reason of result.reasons) lines.push(`Reason: ${reason}`);
|
|
863
872
|
for (const warning of result.warnings) lines.push(`Warning: ${warning}`);
|
|
864
873
|
return `${lines.join("\n")}\n`;
|
package/src/core/shift.js
CHANGED
|
@@ -56,6 +56,26 @@ function notePath(where, role) {
|
|
|
56
56
|
return path.join(shiftDir(where), `${role}.md`);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
// A worktree with no chat role keeps its note per worktree (shift-without-role
|
|
60
|
+
// D1): its directory name for a reader, a hash of its path for uniqueness.
|
|
61
|
+
function worktreeNotePath(where) {
|
|
62
|
+
const id = require("crypto").createHash("sha256").update(where.worktree).digest("hex").slice(0, 8);
|
|
63
|
+
return path.join(shiftDir(where), "worktree", `${path.basename(where.worktree)}-${id}.md`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Where this worktree's note is written: the role's when it has one.
|
|
67
|
+
function ownNotePath(where, role) {
|
|
68
|
+
return role ? notePath(where, role) : worktreeNotePath(where);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// The note waiting for this worktree: its role's first, then its own.
|
|
72
|
+
function waitingNote(where, role) {
|
|
73
|
+
for (const file of [role ? notePath(where, role) : null, worktreeNotePath(where)]) {
|
|
74
|
+
if (file && fs.existsSync(file)) return file;
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
|
|
59
79
|
function writeFileAtomic(file, content) {
|
|
60
80
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
61
81
|
const temp = `${file}.${process.pid}.tmp`;
|
|
@@ -71,11 +91,11 @@ function isShift(record) {
|
|
|
71
91
|
|
|
72
92
|
// Every process: pid, parent, elapsed time, command.
|
|
73
93
|
function processTable() {
|
|
74
|
-
const result = spawnSync("ps", ["-axo", "pid=,ppid=,etime=,command="], { encoding: "utf8" });
|
|
94
|
+
const result = spawnSync("ps", ["-axo", "pid=,ppid=,pgid=,etime=,command="], { encoding: "utf8" });
|
|
75
95
|
const table = new Map();
|
|
76
96
|
for (const line of String(result.stdout || "").split("\n")) {
|
|
77
|
-
const match = line.match(/^\s*(\d+)\s+(\d+)\s+(\S+)\s+(.*)$/);
|
|
78
|
-
if (match) table.set(Number(match[1]), { pid: Number(match[1]), ppid: Number(match[2]),
|
|
97
|
+
const match = line.match(/^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(.*)$/);
|
|
98
|
+
if (match) table.set(Number(match[1]), { pid: Number(match[1]), ppid: Number(match[2]), pgid: Number(match[3]), elapsed: match[4], command: match[5] });
|
|
79
99
|
}
|
|
80
100
|
return table;
|
|
81
101
|
}
|
|
@@ -110,14 +130,16 @@ const IDLE_SHELL = /^-?(?:\S*\/)?(?:zsh|bash|sh|dash|fish)(?:\s+-[il]+)*\s*$/;
|
|
|
110
130
|
|
|
111
131
|
function liveProcesses(worktree) {
|
|
112
132
|
const table = processTable();
|
|
113
|
-
// The checking process and its ancestors are the session doing the check
|
|
133
|
+
// The checking process and its ancestors are the session doing the check,
|
|
134
|
+
// and its process group is the command line it runs in (`… | head`).
|
|
114
135
|
const own = new Set();
|
|
115
136
|
for (let pid = process.pid; pid && !own.has(pid); pid = (table.get(pid) || {}).ppid) own.add(pid);
|
|
137
|
+
const group = (table.get(process.pid) || {}).pgid;
|
|
116
138
|
const found = [];
|
|
117
139
|
for (const [pid, cwd] of processDirectories()) {
|
|
118
140
|
if (own.has(pid) || !inside(realpath(cwd), worktree)) continue;
|
|
119
141
|
const row = table.get(pid);
|
|
120
|
-
if (!row || IDLE_SHELL.test(row.command)) continue;
|
|
142
|
+
if (!row || row.pgid === group || IDLE_SHELL.test(row.command)) continue;
|
|
121
143
|
found.push(row);
|
|
122
144
|
}
|
|
123
145
|
return found.sort((a, b) => a.pid - b.pid);
|
|
@@ -127,13 +149,24 @@ function temporaryRoots() {
|
|
|
127
149
|
return [...new Set([os.tmpdir(), "/tmp", "/private/tmp", "/var/folders", "/private/var/folders"].map(realpath))];
|
|
128
150
|
}
|
|
129
151
|
|
|
152
|
+
// Linked worktrees under a temporary directory, split by owner
|
|
153
|
+
// (shift-temp-owner D1): one in a Claude scratchpad of a session started in
|
|
154
|
+
// this worktree is this worktree's; any other is someone else's, or unknown.
|
|
130
155
|
function temporaryWorktrees(where) {
|
|
131
156
|
const listed = git(where.worktree, ["worktree", "list", "--porcelain"]);
|
|
132
|
-
if (!listed.ok) return [];
|
|
157
|
+
if (!listed.ok) return { own: [], other: [] };
|
|
133
158
|
const trees = listed.out.split("\n").filter((line) => line.startsWith("worktree ")).map((line) => realpath(line.slice(9)));
|
|
134
159
|
const main = trees[0];
|
|
135
160
|
const roots = temporaryRoots();
|
|
136
|
-
|
|
161
|
+
const slug = where.worktree.replace(/[^A-Za-z0-9]/g, "-");
|
|
162
|
+
const own = [];
|
|
163
|
+
const other = [];
|
|
164
|
+
for (const tree of trees) {
|
|
165
|
+
if (tree === main || tree === where.worktree || !roots.some((root) => inside(tree, root))) continue;
|
|
166
|
+
const scratch = tree.match(/[\\/]claude-\d+[\\/]([^\\/]+)[\\/][^\\/]+[\\/]scratchpad(?:[\\/]|$)/);
|
|
167
|
+
(scratch && scratch[1] === slug ? own : other).push(tree);
|
|
168
|
+
}
|
|
169
|
+
return { own, other };
|
|
137
170
|
}
|
|
138
171
|
|
|
139
172
|
function check(where, role) {
|
|
@@ -158,7 +191,9 @@ function check(where, role) {
|
|
|
158
191
|
items.push({ kind: "process", detail: `PID ${row.pid}, running ${row.elapsed}: ${row.command}` });
|
|
159
192
|
}
|
|
160
193
|
|
|
161
|
-
|
|
194
|
+
const temporary = temporaryWorktrees(where);
|
|
195
|
+
for (const tree of temporary.own) items.push({ kind: "temporary-worktree", detail: tree });
|
|
196
|
+
for (const tree of temporary.other) notes.push(`temporary worktree of another session, or of unknown owner, not counted: ${tree}`);
|
|
162
197
|
|
|
163
198
|
if (role) {
|
|
164
199
|
for (const todo of store.openTodos(where, { assignee: role })) {
|
|
@@ -246,7 +281,7 @@ function readNoteText(options) {
|
|
|
246
281
|
}
|
|
247
282
|
|
|
248
283
|
function ready(where, options) {
|
|
249
|
-
const role =
|
|
284
|
+
const role = store.currentRole(where);
|
|
250
285
|
const result = check(where, role);
|
|
251
286
|
if (!result.ready && !options.forceReason) {
|
|
252
287
|
throw new ShiftError(`${renderCheck(result)}\nResolve these, or give --force-reason "<why they may stay>".`);
|
|
@@ -255,14 +290,16 @@ function ready(where, options) {
|
|
|
255
290
|
if (!text.trim()) throw new ShiftError("keel shift ready needs the shift note: give it as text, with --file, or on stdin.");
|
|
256
291
|
const stamp = store.isoLocal(new Date());
|
|
257
292
|
const head = [
|
|
258
|
-
`# Shift note: ${role}`,
|
|
293
|
+
`# Shift note: ${role || path.basename(where.worktree)}`,
|
|
259
294
|
"",
|
|
260
295
|
`Written ${stamp} in ${result.worktree}.`,
|
|
261
296
|
options.forceReason ? `\nLeft as is (${options.forceReason}):\n${result.items.map((item) => `- ${item.kind}: ${item.detail}`).join("\n")}` : "",
|
|
262
297
|
"",
|
|
263
298
|
].join("\n");
|
|
264
|
-
|
|
265
|
-
|
|
299
|
+
const note = ownNotePath(where, role);
|
|
300
|
+
writeFileAtomic(note, `${head}\n${text}\n`);
|
|
301
|
+
// Requests are chat records; without a role there is none to close (D2).
|
|
302
|
+
const open = role ? shiftRequests(where, role).filter((r) => r.open) : [];
|
|
266
303
|
for (const todo of open) {
|
|
267
304
|
store.post(where, {
|
|
268
305
|
group: todo.group,
|
|
@@ -271,7 +308,7 @@ function ready(where, options) {
|
|
|
271
308
|
text: `done — ${role} is ready for the shift change; the note waits for \`keel shift resume\`.${options.forceReason ? ` Left as is: ${options.forceReason}.` : ""}`,
|
|
272
309
|
});
|
|
273
310
|
}
|
|
274
|
-
return { role
|
|
311
|
+
return { role: role || null, note, closed: open.map((todo) => todo.id) };
|
|
275
312
|
}
|
|
276
313
|
|
|
277
314
|
function start(where, role, text) {
|
|
@@ -289,14 +326,15 @@ function start(where, role, text) {
|
|
|
289
326
|
}
|
|
290
327
|
|
|
291
328
|
function resume(where) {
|
|
292
|
-
const role =
|
|
293
|
-
const note =
|
|
294
|
-
if (!
|
|
329
|
+
const role = store.currentRole(where);
|
|
330
|
+
const note = waitingNote(where, role);
|
|
331
|
+
if (!note) return { role: role || null, note: null, text: null };
|
|
295
332
|
const text = fs.readFileSync(note, "utf8");
|
|
296
333
|
const stamp = store.isoLocal(new Date()).replace(/[:+]/g, "");
|
|
297
|
-
const history = path.join(shiftDir(where), "history", `${role}-${stamp}.md`);
|
|
334
|
+
const history = path.join(shiftDir(where), "history", `${role || path.basename(note, ".md")}-${stamp}.md`);
|
|
298
335
|
fs.mkdirSync(path.dirname(history), { recursive: true });
|
|
299
336
|
fs.renameSync(note, history);
|
|
337
|
+
if (!role) return { role: null, note: history, text, told: null };
|
|
300
338
|
// The cold-start message has done its work once the note is read.
|
|
301
339
|
for (const record of store.unread(where, role)) {
|
|
302
340
|
if (isShift(record)) store.advanceCursor(where, role, record.group, record.id);
|
|
@@ -320,10 +358,12 @@ function status(where) {
|
|
|
320
358
|
entry(todo.assignee).request = { id: todo.id, from: todo.from, created: todo.created, open: todo.open };
|
|
321
359
|
}
|
|
322
360
|
const dir = shiftDir(where);
|
|
323
|
-
for (const
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
361
|
+
for (const [folder, prefix] of [[dir, ""], [path.join(dir, "worktree"), "worktree "]]) {
|
|
362
|
+
for (const file of safeList(folder)) {
|
|
363
|
+
if (!file.endsWith(".md")) continue;
|
|
364
|
+
const stat = fs.statSync(path.join(folder, file));
|
|
365
|
+
entry(`${prefix}${file.slice(0, -3)}`).note = store.isoLocal(stat.mtime);
|
|
366
|
+
}
|
|
327
367
|
}
|
|
328
368
|
for (const file of safeList(path.join(dir, "history"))) {
|
|
329
369
|
const match = file.match(/^(.+)-(\d{4}-\d{2}-\d{2}T\d+)\.md$/);
|
|
@@ -356,7 +396,7 @@ const CLEAR_HINT = [
|
|
|
356
396
|
"- Claude desktop app: call `clear_session(\"self\")` (the owner approves it), or type /clear;",
|
|
357
397
|
"- Claude Code CLI: /clear;",
|
|
358
398
|
"- Codex: start a new session in this worktree.",
|
|
359
|
-
"The coordinator's `keel shift start` then wakes the new shift
|
|
399
|
+
"The coordinator's `keel shift start` then wakes the new shift; without chat roles, tell the new session to run `keel shift resume`.",
|
|
360
400
|
].join("\n");
|
|
361
401
|
|
|
362
402
|
function runShift(argv) {
|
|
@@ -390,7 +430,8 @@ function runShift(argv) {
|
|
|
390
430
|
}
|
|
391
431
|
case "ready": {
|
|
392
432
|
const result = ready(where, { ...options, text: rest.join(" ") });
|
|
393
|
-
|
|
433
|
+
const whose = result.role || "this worktree (no chat role, so no request to close)";
|
|
434
|
+
out({ ...result, clear: CLEAR_HINT }, `Stored the shift note for ${whose} at ${result.note}${result.closed.length ? ` and closed ${result.closed.join(", ")}` : ""}.\n${CLEAR_HINT}`);
|
|
394
435
|
return 0;
|
|
395
436
|
}
|
|
396
437
|
case "start": {
|
|
@@ -402,7 +443,7 @@ function runShift(argv) {
|
|
|
402
443
|
case "resume": {
|
|
403
444
|
const result = resume(where);
|
|
404
445
|
if (!result.note) {
|
|
405
|
-
out(result, `No shift note waits for ${result.role}.`);
|
|
446
|
+
out(result, `No shift note waits for ${result.role || "this worktree"}.`);
|
|
406
447
|
return 0;
|
|
407
448
|
}
|
|
408
449
|
out(result, `${result.text.replace(/\s+$/, "")}\n\n(The note moved to ${result.note}.)`);
|
|
@@ -426,10 +467,14 @@ function runShift(argv) {
|
|
|
426
467
|
}
|
|
427
468
|
}
|
|
428
469
|
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
470
|
+
// The waiting note for a repository path, for `keel context` (D3); null when
|
|
471
|
+
// none waits or the path is not a repository.
|
|
472
|
+
function waitingFor(repo) {
|
|
473
|
+
const where = store.locate(repo);
|
|
474
|
+
if (!where) return null;
|
|
475
|
+
const note = waitingNote(where, store.currentRole(where));
|
|
476
|
+
if (!note) return null;
|
|
477
|
+
return { note, since: store.isoLocal(fs.statSync(note).mtime) };
|
|
433
478
|
}
|
|
434
479
|
|
|
435
|
-
module.exports = { check,
|
|
480
|
+
module.exports = { check, runShift, waitingFor };
|