@christang/keel 5.98.0 → 5.99.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/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 +76 -9
- package/src/core/chat/notice.js +1 -9
- package/src/core/context.js +9 -0
- package/src/core/shift.js +58 -26
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@christang/keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.99.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.99.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.99.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.99.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",
|
|
@@ -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.0"
|
|
51
|
+
PROTOCOL_VERSION = "5.99.0"
|
|
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")
|
|
@@ -4520,7 +4519,9 @@ def validate_shift_change_scenario() -> int:
|
|
|
4520
4519
|
temp_tree = Path(tempfile.gettempdir()) / f"keel-shift-tmp-{os.getpid()}"
|
|
4521
4520
|
subprocess.run(["git", "worktree", "add", "-q", "--detach", str(temp_tree)], cwd=verify, check=True, capture_output=True)
|
|
4522
4521
|
run_keel(rtl, "chat", "todo", "soc", "--assignee", "verify", "Rerun the regression", env=env)
|
|
4523
|
-
|
|
4522
|
+
# Its own session, as a job a session leaves behind would be: the check
|
|
4523
|
+
# skips its own command line's process group.
|
|
4524
|
+
sleeper = subprocess.Popen(["sleep", "60"], cwd=verify, start_new_session=True)
|
|
4524
4525
|
try:
|
|
4525
4526
|
checked = shift(verify, "check", "--json")
|
|
4526
4527
|
if checked.returncode != 1:
|
|
@@ -4640,6 +4641,71 @@ def validate_shift_change_scenario() -> int:
|
|
|
4640
4641
|
return 0
|
|
4641
4642
|
|
|
4642
4643
|
|
|
4644
|
+
def validate_shift_without_role_scenario() -> int:
|
|
4645
|
+
"""Owner's remark of 2026-10-05: a shift change needs no chat role.
|
|
4646
|
+
|
|
4647
|
+
In a worktree with no `keel chat` role, `ready` keeps the note per
|
|
4648
|
+
worktree, `keel context` and the SessionStart projection point to it
|
|
4649
|
+
without changing the context's status, and `resume` consumes it.
|
|
4650
|
+
"""
|
|
4651
|
+
label = "shift-without-role:"
|
|
4652
|
+
with tempfile.TemporaryDirectory(prefix="keel-shift-norole-") as raw:
|
|
4653
|
+
base = Path(raw)
|
|
4654
|
+
repo = mailbox_repository(base / "solo")
|
|
4655
|
+
env = chat_environment()
|
|
4656
|
+
common = mailbox_common_dir(repo) / "keel-chat"
|
|
4657
|
+
|
|
4658
|
+
def context() -> dict:
|
|
4659
|
+
return chat_json(run_keel(repo, "context", "--json", env=env))
|
|
4660
|
+
|
|
4661
|
+
before = context().get("status")
|
|
4662
|
+
ready = run_keel(repo, "shift", "ready", "next: rerun R007", env=env)
|
|
4663
|
+
if ready.returncode != 0:
|
|
4664
|
+
report(f"{label} keel shift ready refused in a worktree without a chat role: {ready.stderr.strip()}")
|
|
4665
|
+
return 1
|
|
4666
|
+
notes = list((common / "shift" / "worktree").glob("*.md"))
|
|
4667
|
+
if len(notes) != 1:
|
|
4668
|
+
report(f"{label} ready kept {len(notes)} worktree notes under keel-chat/shift/worktree/, not one.")
|
|
4669
|
+
return 1
|
|
4670
|
+
text = run_keel(repo, "context", env=env).stdout
|
|
4671
|
+
if "keel shift resume" not in text:
|
|
4672
|
+
report(f"{label} keel context does not point to the waiting note: {text.strip()}")
|
|
4673
|
+
return 1
|
|
4674
|
+
if context().get("status") != before:
|
|
4675
|
+
report(f"{label} the waiting note changed the context status from {before!r} to {context().get('status')!r}.")
|
|
4676
|
+
return 1
|
|
4677
|
+
session = run_session_start_hook(
|
|
4678
|
+
repo, {"hook_event_name": "SessionStart", "source": "startup", "cwd": str(repo)},
|
|
4679
|
+
keel_cli=f'node "{ROOT / "bin" / "keel.js"}"',
|
|
4680
|
+
)
|
|
4681
|
+
if "keel shift resume" not in (session_start_context(session) or ""):
|
|
4682
|
+
report(f"{label} the SessionStart projection does not point to the waiting note.")
|
|
4683
|
+
return 1
|
|
4684
|
+
resumed = run_keel(repo, "shift", "resume", env=env)
|
|
4685
|
+
if "rerun R007" not in resumed.stdout:
|
|
4686
|
+
report(f"{label} keel shift resume did not print the note: {resumed.stdout.strip()} {resumed.stderr.strip()}")
|
|
4687
|
+
return 1
|
|
4688
|
+
if notes[0].exists():
|
|
4689
|
+
report(f"{label} resume left the worktree note waiting.")
|
|
4690
|
+
return 1
|
|
4691
|
+
if not list((common / "shift" / "history").glob("*.md")):
|
|
4692
|
+
report(f"{label} resume did not keep the note in history.")
|
|
4693
|
+
return 1
|
|
4694
|
+
if "keel shift resume" in run_keel(repo, "context", env=env).stdout:
|
|
4695
|
+
report(f"{label} keel context still points to a note already resumed.")
|
|
4696
|
+
return 1
|
|
4697
|
+
|
|
4698
|
+
for relative, needle in (("docs/shift-change.md", "no chat role"), ("docs/shift-change.zh-CN.md", "不绑定聊天角色")):
|
|
4699
|
+
if needle not in (ROOT / relative).read_text(encoding="utf-8"):
|
|
4700
|
+
report(f"{label} {relative} does not say a chat role is optional ({needle!r}).")
|
|
4701
|
+
return 1
|
|
4702
|
+
if "shift-without-role" not in {name for name, _ in SCENARIOS}:
|
|
4703
|
+
report(f"{label} scenario is not registered.")
|
|
4704
|
+
return 1
|
|
4705
|
+
report("shift-without-role scenario passed.")
|
|
4706
|
+
return 0
|
|
4707
|
+
|
|
4708
|
+
|
|
4643
4709
|
def validate_chat_archive_scenario() -> int:
|
|
4644
4710
|
"""Issue #187: chat history is archived to an orphan branch, never exposed.
|
|
4645
4711
|
|
|
@@ -37107,6 +37173,7 @@ SCENARIOS: tuple = (
|
|
|
37107
37173
|
("context-names-the-protocol-refresh", validate_context_names_the_protocol_refresh_scenario),
|
|
37108
37174
|
("collected-feedback-is-recorded", validate_collected_feedback_is_recorded_scenario),
|
|
37109
37175
|
("shift-change", validate_shift_change_scenario),
|
|
37176
|
+
("shift-without-role", validate_shift_without_role_scenario),
|
|
37110
37177
|
("init-never-downgrades-openspec", validate_init_never_downgrades_openspec_scenario),
|
|
37111
37178
|
("native-plugin-marketplaces", validate_native_plugin_marketplaces_scenario),
|
|
37112
37179
|
("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);
|
|
@@ -246,7 +268,7 @@ function readNoteText(options) {
|
|
|
246
268
|
}
|
|
247
269
|
|
|
248
270
|
function ready(where, options) {
|
|
249
|
-
const role =
|
|
271
|
+
const role = store.currentRole(where);
|
|
250
272
|
const result = check(where, role);
|
|
251
273
|
if (!result.ready && !options.forceReason) {
|
|
252
274
|
throw new ShiftError(`${renderCheck(result)}\nResolve these, or give --force-reason "<why they may stay>".`);
|
|
@@ -255,14 +277,16 @@ function ready(where, options) {
|
|
|
255
277
|
if (!text.trim()) throw new ShiftError("keel shift ready needs the shift note: give it as text, with --file, or on stdin.");
|
|
256
278
|
const stamp = store.isoLocal(new Date());
|
|
257
279
|
const head = [
|
|
258
|
-
`# Shift note: ${role}`,
|
|
280
|
+
`# Shift note: ${role || path.basename(where.worktree)}`,
|
|
259
281
|
"",
|
|
260
282
|
`Written ${stamp} in ${result.worktree}.`,
|
|
261
283
|
options.forceReason ? `\nLeft as is (${options.forceReason}):\n${result.items.map((item) => `- ${item.kind}: ${item.detail}`).join("\n")}` : "",
|
|
262
284
|
"",
|
|
263
285
|
].join("\n");
|
|
264
|
-
|
|
265
|
-
|
|
286
|
+
const note = ownNotePath(where, role);
|
|
287
|
+
writeFileAtomic(note, `${head}\n${text}\n`);
|
|
288
|
+
// Requests are chat records; without a role there is none to close (D2).
|
|
289
|
+
const open = role ? shiftRequests(where, role).filter((r) => r.open) : [];
|
|
266
290
|
for (const todo of open) {
|
|
267
291
|
store.post(where, {
|
|
268
292
|
group: todo.group,
|
|
@@ -271,7 +295,7 @@ function ready(where, options) {
|
|
|
271
295
|
text: `done — ${role} is ready for the shift change; the note waits for \`keel shift resume\`.${options.forceReason ? ` Left as is: ${options.forceReason}.` : ""}`,
|
|
272
296
|
});
|
|
273
297
|
}
|
|
274
|
-
return { role
|
|
298
|
+
return { role: role || null, note, closed: open.map((todo) => todo.id) };
|
|
275
299
|
}
|
|
276
300
|
|
|
277
301
|
function start(where, role, text) {
|
|
@@ -289,14 +313,15 @@ function start(where, role, text) {
|
|
|
289
313
|
}
|
|
290
314
|
|
|
291
315
|
function resume(where) {
|
|
292
|
-
const role =
|
|
293
|
-
const note =
|
|
294
|
-
if (!
|
|
316
|
+
const role = store.currentRole(where);
|
|
317
|
+
const note = waitingNote(where, role);
|
|
318
|
+
if (!note) return { role: role || null, note: null, text: null };
|
|
295
319
|
const text = fs.readFileSync(note, "utf8");
|
|
296
320
|
const stamp = store.isoLocal(new Date()).replace(/[:+]/g, "");
|
|
297
|
-
const history = path.join(shiftDir(where), "history", `${role}-${stamp}.md`);
|
|
321
|
+
const history = path.join(shiftDir(where), "history", `${role || path.basename(note, ".md")}-${stamp}.md`);
|
|
298
322
|
fs.mkdirSync(path.dirname(history), { recursive: true });
|
|
299
323
|
fs.renameSync(note, history);
|
|
324
|
+
if (!role) return { role: null, note: history, text, told: null };
|
|
300
325
|
// The cold-start message has done its work once the note is read.
|
|
301
326
|
for (const record of store.unread(where, role)) {
|
|
302
327
|
if (isShift(record)) store.advanceCursor(where, role, record.group, record.id);
|
|
@@ -320,10 +345,12 @@ function status(where) {
|
|
|
320
345
|
entry(todo.assignee).request = { id: todo.id, from: todo.from, created: todo.created, open: todo.open };
|
|
321
346
|
}
|
|
322
347
|
const dir = shiftDir(where);
|
|
323
|
-
for (const
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
348
|
+
for (const [folder, prefix] of [[dir, ""], [path.join(dir, "worktree"), "worktree "]]) {
|
|
349
|
+
for (const file of safeList(folder)) {
|
|
350
|
+
if (!file.endsWith(".md")) continue;
|
|
351
|
+
const stat = fs.statSync(path.join(folder, file));
|
|
352
|
+
entry(`${prefix}${file.slice(0, -3)}`).note = store.isoLocal(stat.mtime);
|
|
353
|
+
}
|
|
327
354
|
}
|
|
328
355
|
for (const file of safeList(path.join(dir, "history"))) {
|
|
329
356
|
const match = file.match(/^(.+)-(\d{4}-\d{2}-\d{2}T\d+)\.md$/);
|
|
@@ -356,7 +383,7 @@ const CLEAR_HINT = [
|
|
|
356
383
|
"- Claude desktop app: call `clear_session(\"self\")` (the owner approves it), or type /clear;",
|
|
357
384
|
"- Claude Code CLI: /clear;",
|
|
358
385
|
"- Codex: start a new session in this worktree.",
|
|
359
|
-
"The coordinator's `keel shift start` then wakes the new shift
|
|
386
|
+
"The coordinator's `keel shift start` then wakes the new shift; without chat roles, tell the new session to run `keel shift resume`.",
|
|
360
387
|
].join("\n");
|
|
361
388
|
|
|
362
389
|
function runShift(argv) {
|
|
@@ -390,7 +417,8 @@ function runShift(argv) {
|
|
|
390
417
|
}
|
|
391
418
|
case "ready": {
|
|
392
419
|
const result = ready(where, { ...options, text: rest.join(" ") });
|
|
393
|
-
|
|
420
|
+
const whose = result.role || "this worktree (no chat role, so no request to close)";
|
|
421
|
+
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
422
|
return 0;
|
|
395
423
|
}
|
|
396
424
|
case "start": {
|
|
@@ -402,7 +430,7 @@ function runShift(argv) {
|
|
|
402
430
|
case "resume": {
|
|
403
431
|
const result = resume(where);
|
|
404
432
|
if (!result.note) {
|
|
405
|
-
out(result, `No shift note waits for ${result.role}.`);
|
|
433
|
+
out(result, `No shift note waits for ${result.role || "this worktree"}.`);
|
|
406
434
|
return 0;
|
|
407
435
|
}
|
|
408
436
|
out(result, `${result.text.replace(/\s+$/, "")}\n\n(The note moved to ${result.note}.)`);
|
|
@@ -426,10 +454,14 @@ function runShift(argv) {
|
|
|
426
454
|
}
|
|
427
455
|
}
|
|
428
456
|
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
457
|
+
// The waiting note for a repository path, for `keel context` (D3); null when
|
|
458
|
+
// none waits or the path is not a repository.
|
|
459
|
+
function waitingFor(repo) {
|
|
460
|
+
const where = store.locate(repo);
|
|
461
|
+
if (!where) return null;
|
|
462
|
+
const note = waitingNote(where, store.currentRole(where));
|
|
463
|
+
if (!note) return null;
|
|
464
|
+
return { note, since: store.isoLocal(fs.statSync(note).mtime) };
|
|
433
465
|
}
|
|
434
466
|
|
|
435
|
-
module.exports = { check,
|
|
467
|
+
module.exports = { check, runShift, waitingFor };
|