@christang/keel 5.113.0 → 5.114.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/README.md +3 -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/scripts/validate_plugin.py +139 -2
- package/src/core/chat/notice.js +9 -2
- package/src/core/shift.js +122 -10
package/README.md
CHANGED
|
@@ -356,7 +356,9 @@ material choice, every gate still runs, and the write guard still binds. In part
|
|
|
356
356
|
explicitly.
|
|
357
357
|
|
|
358
358
|
**Keel schedules nothing.** `/loop`, cron, and CI triggers are your runtime's; Keel's part is making
|
|
359
|
-
each step decidable with authority.
|
|
359
|
+
each step decidable with authority. The one exception is `keel shift ready --wake`: a one-shot waiter
|
|
360
|
+
that writes a single wake record once that role's next session has started, then exits — a session
|
|
361
|
+
changing its own shift has nobody else to start it. And a run that stops at a real decision has ended the way it was
|
|
360
362
|
designed to — resist widening the policy until it stops happening.
|
|
361
363
|
|
|
362
364
|
### Who merges
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@christang/keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.114.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.114.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.114.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.114.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",
|
|
@@ -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.114.0"
|
|
51
|
+
PROTOCOL_VERSION = "5.114.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
|
|
@@ -5512,6 +5512,141 @@ def validate_shift_role_elsewhere_scenario() -> int:
|
|
|
5512
5512
|
return 0
|
|
5513
5513
|
|
|
5514
5514
|
|
|
5515
|
+
def validate_shift_self_scenario() -> int:
|
|
5516
|
+
"""Issue #293: a role with no coordinator changes its own shift.
|
|
5517
|
+
|
|
5518
|
+
It cannot start itself, `ready` says nobody will start the new session,
|
|
5519
|
+
status says its own next session resumes the note, and a new session in
|
|
5520
|
+
an unbound worktree resumes it with `--role`.
|
|
5521
|
+
"""
|
|
5522
|
+
label = "shift-self:"
|
|
5523
|
+
with tempfile.TemporaryDirectory(prefix="keel-shift-self-") as raw:
|
|
5524
|
+
base = Path(raw)
|
|
5525
|
+
rtl, _verify, env, _ = shift_scratch(base)
|
|
5526
|
+
pm = chat_worktree(rtl, base / "pm")
|
|
5527
|
+
other = chat_worktree(rtl, base / "other")
|
|
5528
|
+
for tree in (pm, other):
|
|
5529
|
+
subprocess.run(["git", "push", "-q", "-u", "origin", "HEAD"], cwd=tree, check=True, capture_output=True)
|
|
5530
|
+
run_keel(pm, "chat", "role", "--set", "pm", env=env)
|
|
5531
|
+
|
|
5532
|
+
def shift(cwd: Path, *args: str) -> subprocess.CompletedProcess[str]:
|
|
5533
|
+
return run_keel(cwd, "shift", *args, env=env)
|
|
5534
|
+
|
|
5535
|
+
readied = shift(pm, "ready", "pm note: next is R009")
|
|
5536
|
+
if readied.returncode != 0:
|
|
5537
|
+
report(f"{label} pm's ready failed: {readied.stderr}")
|
|
5538
|
+
return 1
|
|
5539
|
+
if "nobody" not in readied.stdout:
|
|
5540
|
+
report(f"{label} ready does not say nobody is set to start the new session: {readied.stdout!r}")
|
|
5541
|
+
return 1
|
|
5542
|
+
if "--wake" not in readied.stdout:
|
|
5543
|
+
report(f"{label} ready does not name --wake: {readied.stdout!r}")
|
|
5544
|
+
return 1
|
|
5545
|
+
if "The coordinator's `keel shift start` then wakes" in readied.stdout:
|
|
5546
|
+
report(f"{label} ready still promises a coordinator's start to a role nobody asked: {readied.stdout!r}")
|
|
5547
|
+
return 1
|
|
5548
|
+
itself = shift(pm, "start", "pm")
|
|
5549
|
+
if itself.returncode == 0:
|
|
5550
|
+
report(f"{label} keel shift start pm by pm was accepted.")
|
|
5551
|
+
return 1
|
|
5552
|
+
if "ready --wake" not in itself.stderr:
|
|
5553
|
+
report(f"{label} the refusal does not name ready --wake: {itself.stderr}")
|
|
5554
|
+
return 1
|
|
5555
|
+
if chat_log(rtl, "dm-pm--pm").exists():
|
|
5556
|
+
report(f"{label} a refused self-start still created dm-pm--pm.")
|
|
5557
|
+
return 1
|
|
5558
|
+
status = shift(rtl, "status").stdout
|
|
5559
|
+
line = next((l for l in status.splitlines() if l.startswith("pm:")), "")
|
|
5560
|
+
if "own next session" not in line:
|
|
5561
|
+
report(f"{label} status does not say pm's own next session resumes its note: {line!r}")
|
|
5562
|
+
return 1
|
|
5563
|
+
misbound = shift(rtl, "resume", "--role", "pm")
|
|
5564
|
+
if misbound.returncode == 0:
|
|
5565
|
+
report(f"{label} resume --role pm in rtl's worktree was accepted.")
|
|
5566
|
+
return 1
|
|
5567
|
+
resumed = shift(other, "resume", "--role", "pm")
|
|
5568
|
+
if resumed.returncode != 0:
|
|
5569
|
+
report(f"{label} resume --role pm in an unbound worktree failed: {resumed.stderr}")
|
|
5570
|
+
return 1
|
|
5571
|
+
if "next is R009" not in resumed.stdout:
|
|
5572
|
+
report(f"{label} resume --role pm did not print pm's note: {resumed.stdout!r}")
|
|
5573
|
+
return 1
|
|
5574
|
+
if (mailbox_common_dir(rtl) / "keel-chat" / "shift" / "pm.md").exists():
|
|
5575
|
+
report(f"{label} pm's note still waits after resume --role pm.")
|
|
5576
|
+
return 1
|
|
5577
|
+
report("shift-self scenario passed.")
|
|
5578
|
+
return 0
|
|
5579
|
+
|
|
5580
|
+
|
|
5581
|
+
def validate_shift_self_wake_scenario() -> int:
|
|
5582
|
+
"""Issue #293: `ready --wake` wakes the role's next session, once.
|
|
5583
|
+
|
|
5584
|
+
A `compact` start does not trigger the waiter; a `clear` start does, and
|
|
5585
|
+
the role then has exactly one waking record from `keel-shift`. Without a
|
|
5586
|
+
chat role, `--wake` is refused.
|
|
5587
|
+
"""
|
|
5588
|
+
label = "shift-self-wake:"
|
|
5589
|
+
protocol = (ROOT / "AGENTS.md").read_text(encoding="utf-8")
|
|
5590
|
+
line = next((l for l in protocol.splitlines() if l.startswith("- Keel schedules nothing")), "")
|
|
5591
|
+
if "keel shift ready --wake" not in line:
|
|
5592
|
+
report(f"{label} the protocol's scheduling line does not name the keel shift ready --wake exception: {line!r}")
|
|
5593
|
+
return 1
|
|
5594
|
+
with tempfile.TemporaryDirectory(prefix="keel-shift-wake-") as raw:
|
|
5595
|
+
base = Path(raw)
|
|
5596
|
+
rtl, verify, env, _ = shift_scratch(base)
|
|
5597
|
+
env = {**env, "KEEL_SHIFT_WAKE_POLL_MS": "100", "KEEL_SHIFT_WAKE_TIMEOUT_MS": "20000"}
|
|
5598
|
+
loose = chat_worktree(rtl, base / "loose")
|
|
5599
|
+
subprocess.run(["git", "push", "-q", "-u", "origin", "HEAD"], cwd=loose, check=True, capture_output=True)
|
|
5600
|
+
|
|
5601
|
+
def shift(cwd: Path, *args: str) -> subprocess.CompletedProcess[str]:
|
|
5602
|
+
return run_keel(cwd, "shift", *args, env=env)
|
|
5603
|
+
|
|
5604
|
+
def session_start(source: str) -> None:
|
|
5605
|
+
subprocess.run(
|
|
5606
|
+
["node", str(ROOT / "bin" / "keel.js"), "chat", "hook", "session-start"],
|
|
5607
|
+
cwd=verify, env=env, text=True, capture_output=True, check=False,
|
|
5608
|
+
input=json.dumps({"cwd": str(verify), "source": source, "hook_event_name": "SessionStart"}),
|
|
5609
|
+
)
|
|
5610
|
+
|
|
5611
|
+
def wakes() -> list[str]:
|
|
5612
|
+
return chat_records_with(rtl, "dm-keel-shift--verify", "keel shift resume")
|
|
5613
|
+
|
|
5614
|
+
unbound = shift(loose, "ready", "--wake", "loose note")
|
|
5615
|
+
if unbound.returncode == 0:
|
|
5616
|
+
report(f"{label} ready --wake in an unbound worktree with no --role was accepted.")
|
|
5617
|
+
return 1
|
|
5618
|
+
armed = shift(verify, "ready", "--wake", "verify note: next is R010")
|
|
5619
|
+
if armed.returncode != 0:
|
|
5620
|
+
report(f"{label} ready --wake failed: {armed.stderr}")
|
|
5621
|
+
return 1
|
|
5622
|
+
session_start("compact")
|
|
5623
|
+
time.sleep(1)
|
|
5624
|
+
if wakes():
|
|
5625
|
+
report(f"{label} a compact start triggered the wake.")
|
|
5626
|
+
return 1
|
|
5627
|
+
session_start("clear")
|
|
5628
|
+
deadline = time.time() + 5
|
|
5629
|
+
while time.time() < deadline and not wakes():
|
|
5630
|
+
time.sleep(0.1)
|
|
5631
|
+
found = wakes()
|
|
5632
|
+
if len(found) != 1:
|
|
5633
|
+
report(f"{label} expected exactly one wake record from keel-shift after the clear start, found {len(found)}.")
|
|
5634
|
+
return 1
|
|
5635
|
+
if "from: keel-shift" not in found[0]:
|
|
5636
|
+
report(f"{label} the wake record is not from keel-shift: {found[0]!r}")
|
|
5637
|
+
return 1
|
|
5638
|
+
time.sleep(0.5)
|
|
5639
|
+
if len(wakes()) != 1:
|
|
5640
|
+
report(f"{label} the waiter wrote more than one wake record.")
|
|
5641
|
+
return 1
|
|
5642
|
+
checked = run_keel(verify, "chat", "notice", "--check", env=env)
|
|
5643
|
+
if checked.returncode != 0:
|
|
5644
|
+
report(f"{label} keel chat notice --check for verify does not see the wake (exit {checked.returncode}).")
|
|
5645
|
+
return 1
|
|
5646
|
+
report("shift-self-wake scenario passed.")
|
|
5647
|
+
return 0
|
|
5648
|
+
|
|
5649
|
+
|
|
5515
5650
|
def validate_shift_coordinator_last_scenario() -> int:
|
|
5516
5651
|
"""Issue #289: the coordinator starts the others before its own shift ends.
|
|
5517
5652
|
|
|
@@ -39185,6 +39320,8 @@ SCENARIOS: tuple = (
|
|
|
39185
39320
|
("shift-change", validate_shift_change_scenario),
|
|
39186
39321
|
("shift-role-elsewhere", validate_shift_role_elsewhere_scenario),
|
|
39187
39322
|
("shift-coordinator-last", validate_shift_coordinator_last_scenario),
|
|
39323
|
+
("shift-self", validate_shift_self_scenario),
|
|
39324
|
+
("shift-self-wake", validate_shift_self_wake_scenario),
|
|
39188
39325
|
("shift-without-role", validate_shift_without_role_scenario),
|
|
39189
39326
|
("resource-lock", validate_resource_lock_scenario),
|
|
39190
39327
|
("chat-supersedes", validate_chat_supersedes_scenario),
|
package/src/core/chat/notice.js
CHANGED
|
@@ -80,12 +80,17 @@ function presenceFile(where, role) {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
// Presence is written only by its own role, so it never conflicts (D1).
|
|
83
|
-
function touchPresence(where, role, state = "online", host = null) {
|
|
83
|
+
function touchPresence(where, role, state = "online", host = null, started = null) {
|
|
84
84
|
const previous = store.readJsonFile(presenceFile(where, role));
|
|
85
85
|
const record = {
|
|
86
86
|
state,
|
|
87
87
|
last_active: store.isoLocal(new Date()),
|
|
88
88
|
host: host || previous.host || null,
|
|
89
|
+
// When and how the role's current session started, for the one-shot
|
|
90
|
+
// waiter `keel shift ready --wake` leaves (#293 D1); millisecond UTC so a
|
|
91
|
+
// start in the same second as the `ready` still orders after it.
|
|
92
|
+
session_started: started ? new Date().toISOString() : previous.session_started || null,
|
|
93
|
+
session_source: started ? started.source : previous.session_source || null,
|
|
89
94
|
};
|
|
90
95
|
try {
|
|
91
96
|
store.writeJsonAtomic(where, presenceFile(where, role), record);
|
|
@@ -193,7 +198,8 @@ function hook(event, input, { mail = false } = {}) {
|
|
|
193
198
|
touchPresence(where, role, "offline");
|
|
194
199
|
return { code: 0 };
|
|
195
200
|
}
|
|
196
|
-
|
|
201
|
+
const started = event === "session-start" ? { source: typeof payload.source === "string" ? payload.source : null } : null;
|
|
202
|
+
touchPresence(where, role, "online", mail ? null : "claude-code", started);
|
|
197
203
|
const chatText = noticeText(where, role);
|
|
198
204
|
const text = chatText && mail ? `${chatText}\n${MAIL_POINTER}` : chatText;
|
|
199
205
|
if (event === "session-start") {
|
|
@@ -237,6 +243,7 @@ module.exports = {
|
|
|
237
243
|
bridgeLine,
|
|
238
244
|
hook,
|
|
239
245
|
noticeText,
|
|
246
|
+
presenceFile,
|
|
240
247
|
presenceOf,
|
|
241
248
|
signalPath,
|
|
242
249
|
touchPresence,
|
package/src/core/shift.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
const fs = require("fs");
|
|
15
15
|
const os = require("os");
|
|
16
16
|
const path = require("path");
|
|
17
|
-
const { spawnSync } = require("child_process");
|
|
17
|
+
const { spawn, spawnSync } = require("child_process");
|
|
18
18
|
const store = require("./chat/store");
|
|
19
19
|
const locks = require("./lock");
|
|
20
20
|
|
|
@@ -25,8 +25,9 @@ const USAGE = [
|
|
|
25
25
|
"keel shift ready [text | --file f] store the shift note, close the request (refused while loose)",
|
|
26
26
|
" [--role r] ...under role r, from a worktree bound to no role (#290)",
|
|
27
27
|
" [--force-reason r] ...or state why the loose ends may stay",
|
|
28
|
+
" [--wake] ...and wake the role's next session once it starts (#293)",
|
|
28
29
|
"keel shift start <role> [text] wake the cleared role to resume (once its note waits)",
|
|
29
|
-
"keel shift resume [--json]
|
|
30
|
+
"keel shift resume [--role r] [--json] print and consume this role's note (--role: from an unbound worktree)",
|
|
30
31
|
"keel shift status [--json] each role's shift state",
|
|
31
32
|
"Options: --repo <path>. See docs/shift-change.md.",
|
|
32
33
|
].join("\n");
|
|
@@ -363,6 +364,10 @@ function readyRole(where, options) {
|
|
|
363
364
|
|
|
364
365
|
function ready(where, options) {
|
|
365
366
|
const role = readyRole(where, options);
|
|
367
|
+
if (options.wake && !role) {
|
|
368
|
+
throw new ShiftError("--wake wakes a chat role, and this worktree has none: bind one with `keel chat role --set <name>`, or name it with --role.");
|
|
369
|
+
}
|
|
370
|
+
const since = Date.now();
|
|
366
371
|
const result = check(where, role);
|
|
367
372
|
if (!result.ready && !options.forceReason) {
|
|
368
373
|
throw new ShiftError(`${renderCheck(result)}\nResolve these, or give --force-reason "<why they may stay>".`);
|
|
@@ -392,12 +397,77 @@ function ready(where, options) {
|
|
|
392
397
|
store.writeRecord(where, { group: todo.group, kind: "done", from: role, target: todo.id });
|
|
393
398
|
}
|
|
394
399
|
}
|
|
395
|
-
|
|
400
|
+
const waiter = options.wake ? armWake(where, role, since) : null;
|
|
401
|
+
return { role: role || null, note, closed: open.map((todo) => todo.id), waiter };
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// --- the one-shot wake (#293) -------------------------------------------------------
|
|
405
|
+
//
|
|
406
|
+
// The one exception to "Keel schedules nothing" (D7): `ready --wake` leaves a
|
|
407
|
+
// detached waiter that writes a single wake record once the role's next
|
|
408
|
+
// session has started, then exits. Its working directory is `/`, so `check`
|
|
409
|
+
// never counts it as this worktree's process.
|
|
410
|
+
|
|
411
|
+
const WAKE_SENDER = "keel-shift";
|
|
412
|
+
const WAKE_SOURCES = new Set(["clear", "startup"]);
|
|
413
|
+
|
|
414
|
+
function envMs(name, fallback) {
|
|
415
|
+
const value = Number(process.env[name]);
|
|
416
|
+
return Number.isFinite(value) && value > 0 ? value : fallback;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
function armWake(where, role, since) {
|
|
420
|
+
const keel = path.resolve(__dirname, "..", "..", "bin", "keel.js");
|
|
421
|
+
const child = spawn(
|
|
422
|
+
process.execPath,
|
|
423
|
+
[keel, "shift", "wake-wait", "--role", role, "--since", String(since), "--repo", where.worktree],
|
|
424
|
+
{ detached: true, stdio: "ignore", cwd: path.parse(where.worktree).root },
|
|
425
|
+
);
|
|
426
|
+
child.unref();
|
|
427
|
+
return child.pid;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// The role's current session started after `since`, from a clear or a fresh start.
|
|
431
|
+
function startedSince(where, role, since) {
|
|
432
|
+
const { presenceFile } = require("./chat/notice");
|
|
433
|
+
const presence = store.readJsonFile(presenceFile(where, role));
|
|
434
|
+
const started = Date.parse(presence.session_started || "");
|
|
435
|
+
return !Number.isNaN(started) && started >= since && WAKE_SOURCES.has(presence.session_source);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
function writeWake(where, role) {
|
|
439
|
+
const group = directGroup(where, WAKE_SENDER, role);
|
|
440
|
+
return store.writeRecord(where, {
|
|
441
|
+
group,
|
|
442
|
+
kind: "message",
|
|
443
|
+
from: WAKE_SENDER,
|
|
444
|
+
refs: [REF],
|
|
445
|
+
text: `${role}: your new shift starts now (woken by the \`keel shift ready --wake\` you ran). First run \`keel context\`, then \`keel shift resume\`.`,
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
function waitForWake(where, role, since) {
|
|
450
|
+
const poll = envMs("KEEL_SHIFT_WAKE_POLL_MS", 5000);
|
|
451
|
+
const deadline = Date.now() + envMs("KEEL_SHIFT_WAKE_TIMEOUT_MS", 2 * 60 * 60 * 1000);
|
|
452
|
+
const tick = () => {
|
|
453
|
+
// A note resumed by hand needs no wake; give up after the time limit.
|
|
454
|
+
if (!fs.existsSync(notePath(where, role)) || Date.now() > deadline) return;
|
|
455
|
+
if (startedSince(where, role, since)) {
|
|
456
|
+
writeWake(where, role);
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
setTimeout(tick, poll);
|
|
460
|
+
};
|
|
461
|
+
tick();
|
|
396
462
|
}
|
|
397
463
|
|
|
398
464
|
function start(where, role, text) {
|
|
399
465
|
const from = requireRole(where);
|
|
400
466
|
store.checkName(role, "Role");
|
|
467
|
+
// A role's own start would address itself and wake nothing (#293 D4).
|
|
468
|
+
if (role === from) {
|
|
469
|
+
throw new ShiftError("A role does not start its own new shift; use `keel shift ready --wake`, which wakes it once the new session starts.");
|
|
470
|
+
}
|
|
401
471
|
if (!fs.existsSync(notePath(where, role))) {
|
|
402
472
|
throw new ShiftError(`No shift note waits for ${role}: it has not run \`keel shift ready\`, or already resumed.`);
|
|
403
473
|
}
|
|
@@ -409,8 +479,19 @@ function start(where, role, text) {
|
|
|
409
479
|
return store.post(where, { group, text: body, refs: [REF] });
|
|
410
480
|
}
|
|
411
481
|
|
|
412
|
-
|
|
413
|
-
|
|
482
|
+
// `--role` reads a role's note from a worktree bound to no other role (#293 D5).
|
|
483
|
+
function resumeRole(where, named) {
|
|
484
|
+
const bound = store.currentRole(where);
|
|
485
|
+
if (!named) return bound;
|
|
486
|
+
store.checkName(named, "Role");
|
|
487
|
+
if (bound && bound !== named) {
|
|
488
|
+
throw new ShiftError(`This worktree is bound to role ${bound}; --role ${named} names another role.`);
|
|
489
|
+
}
|
|
490
|
+
return named;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
function resume(where, named = null) {
|
|
494
|
+
const role = resumeRole(where, named);
|
|
414
495
|
const note = waitingNote(where, role);
|
|
415
496
|
if (!note) return { role: role || null, note: null, text: null };
|
|
416
497
|
const text = fs.readFileSync(note, "utf8");
|
|
@@ -427,7 +508,10 @@ function resume(where) {
|
|
|
427
508
|
let told = null;
|
|
428
509
|
if (latest && latest.from !== role) {
|
|
429
510
|
const group = directGroup(where, role, latest.from);
|
|
430
|
-
|
|
511
|
+
const text = `${role} is on shift, resumed from its shift note.`;
|
|
512
|
+
told = (store.currentRole(where) === role
|
|
513
|
+
? store.post(where, { group, text, refs: [REF] })
|
|
514
|
+
: store.writeRecord(where, { group, kind: "message", from: role, refs: [REF], text })).id;
|
|
431
515
|
}
|
|
432
516
|
return { role, note: history, text, told, waiting: role ? unstarted(where, role) : [] };
|
|
433
517
|
}
|
|
@@ -485,7 +569,11 @@ function describe(row) {
|
|
|
485
569
|
if (row.note && row.role.startsWith("worktree ")) {
|
|
486
570
|
return `${row.role}: note waiting since ${row.note}; no chat role there, so tell the session in ${row.path || "that worktree"} to run \`keel shift resume\``;
|
|
487
571
|
}
|
|
488
|
-
|
|
572
|
+
// A note no request asked for is its own role's to resume (#293 D6).
|
|
573
|
+
if (row.note && !row.request) {
|
|
574
|
+
return `${row.role}: note waiting since ${row.note}; its own next session resumes it — woken by \`keel shift ready --wake\`, or by typing into it`;
|
|
575
|
+
}
|
|
576
|
+
if (row.note) return `${row.role}: note waiting since ${row.note}; another role's \`keel shift start ${row.role}\` wakes it to resume`;
|
|
489
577
|
if (row.request && row.request.open) {
|
|
490
578
|
const elsewhere = row.worktreeNotesSince
|
|
491
579
|
? `; a worktree note was written since (${row.worktreeNotesSince.join(", ")}) — if it is ${row.role}'s, file it with \`keel shift ready --role ${row.role}\``
|
|
@@ -504,9 +592,23 @@ const CLEAR_HINT = [
|
|
|
504
592
|
"- Claude desktop app: call `clear_session(\"self\")` (the owner approves it), or type /clear;",
|
|
505
593
|
"- Claude Code CLI: /clear;",
|
|
506
594
|
"- Codex: start a new session in this worktree.",
|
|
507
|
-
"The coordinator's `keel shift start` then wakes the new shift; without chat roles, tell the new session to run `keel shift resume`.",
|
|
508
595
|
].join("\n");
|
|
509
596
|
|
|
597
|
+
// Who starts the new session (#293 D3): the coordinator that asked, nobody,
|
|
598
|
+
// or — without a chat role — the person who opens it.
|
|
599
|
+
function clearHint(result) {
|
|
600
|
+
let last;
|
|
601
|
+
if (!result.role) last = "Without a chat role, tell the new session to run `keel shift resume`.";
|
|
602
|
+
else if (result.waiter) {
|
|
603
|
+
last = `The wake is armed: once ${result.role}'s next session starts (after a clear or a fresh start), it gets one message to run \`keel shift resume\`. The waiter gives up after two hours.`;
|
|
604
|
+
} else if (result.closed.length) last = "The coordinator's `keel shift start` then wakes the new shift.";
|
|
605
|
+
else {
|
|
606
|
+
last = `No request named ${result.role}, so nobody is set to start the new session: type into it, `
|
|
607
|
+
+ "or run `keel shift ready --wake` again with this note, which wakes it once it starts.";
|
|
608
|
+
}
|
|
609
|
+
return `${CLEAR_HINT}\n${last}`;
|
|
610
|
+
}
|
|
611
|
+
|
|
510
612
|
function runShift(argv) {
|
|
511
613
|
const options = { json: false, repo: process.cwd(), positionals: [], file: null, forceReason: null, role: null };
|
|
512
614
|
for (let index = 0; index < argv.length; index += 1) {
|
|
@@ -516,6 +618,8 @@ function runShift(argv) {
|
|
|
516
618
|
else if (arg === "--file") options.file = argv[++index] || "";
|
|
517
619
|
else if (arg === "--force-reason") options.forceReason = argv[++index] || "";
|
|
518
620
|
else if (arg === "--role") options.role = argv[++index] || "";
|
|
621
|
+
else if (arg === "--since") options.since = Number(argv[++index]);
|
|
622
|
+
else if (arg === "--wake") options.wake = true;
|
|
519
623
|
else if (arg === "--help" || arg === "-h") {
|
|
520
624
|
process.stdout.write(`${USAGE}\n`);
|
|
521
625
|
return 0;
|
|
@@ -540,7 +644,15 @@ function runShift(argv) {
|
|
|
540
644
|
case "ready": {
|
|
541
645
|
const result = ready(where, { ...options, text: rest.join(" ") });
|
|
542
646
|
const whose = result.role || "this worktree (no chat role, so no request to close)";
|
|
543
|
-
|
|
647
|
+
const hint = clearHint(result);
|
|
648
|
+
out({ ...result, clear: hint }, `Stored the shift note for ${whose} at ${result.note}${result.closed.length ? ` and closed ${result.closed.join(", ")}` : ""}.\n${hint}`);
|
|
649
|
+
return 0;
|
|
650
|
+
}
|
|
651
|
+
case "wake-wait": {
|
|
652
|
+
// Internal: the detached waiter `ready --wake` spawns.
|
|
653
|
+
if (!options.role || !Number.isFinite(options.since)) throw new ShiftError("keel shift wake-wait needs --role and --since.");
|
|
654
|
+
store.checkName(options.role, "Role");
|
|
655
|
+
waitForWake(where, options.role, options.since);
|
|
544
656
|
return 0;
|
|
545
657
|
}
|
|
546
658
|
case "start": {
|
|
@@ -550,7 +662,7 @@ function runShift(argv) {
|
|
|
550
662
|
return 0;
|
|
551
663
|
}
|
|
552
664
|
case "resume": {
|
|
553
|
-
const result = resume(where);
|
|
665
|
+
const result = resume(where, options.role);
|
|
554
666
|
if (!result.note) {
|
|
555
667
|
out(result, `No shift note waits for ${result.role || "this worktree"}.`);
|
|
556
668
|
return 0;
|