@christang/keel 5.158.0 → 5.159.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/README.md +12 -2
- 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 +105 -2
- package/src/core/chat/cli.js +10 -0
- package/src/core/chat/rename.js +202 -0
- package/src/core/chat/store.js +47 -7
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.159.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/README.md
CHANGED
|
@@ -825,7 +825,7 @@ Without a known default branch, no issue range is inferred.
|
|
|
825
825
|
|
|
826
826
|
## Group chat between sessions
|
|
827
827
|
|
|
828
|
-
Sessions working the same repository — a Claude Code session, a Codex session, an unattended runner, and you — share a work group with `keel chat`. Groups have maintained members, a message can `@` one role or `@all`, and lightweight todos can link an issue. A record can supersede its author's earlier one (`--supersedes <id>`), and the earlier one then leaves everyone's unread; unread lists newest first. A record posted with `--ack` asks the roles it addresses to acknowledge it, by `keel chat ack <id>` or a reply, and `keel chat show <id>` and `keel chat acks` list who has acknowledged, who only read it, and who has not read it. `keel chat summary --since <time>` digests what changed in the groups you can read — per sender, the message count, todos opened with whether they are still open, todos closed, superseded records folded into their successors, and acknowledgements still waiting — without a model and without marking anything read. Each member has its own unread state, and history is kept. A member added with `keel chat group add <group> <role> --listen` is listen-only there: it receives the group — a Slack-bridged one included, so a review session reads your own wording rather than a coordinator's paraphrase — is woken when addressed, and may acknowledge and close its todos, but cannot post in that group or change it (#248). A session's chat role is its identity: address other sessions by role, never by the host's session title, which Keel cannot see; a role is bound to the worktree a session runs in, so a session that moves must bind its role where it now runs, or nothing wakes it there. `keel patrol` and `keel --doctor` report a binding to a removed worktree and a role with something waiting and no session active for two hours, a session starting unbound is told which roles those are, and `keel chat role --prune` drops bindings to removed worktrees (#301); `keel context` and the session projection name the role bound to the worktree, and remind a worktree with none when others here have one (#245). Only a mention, an assigned todo, or a direct message wakes a Claude session; everything else waits for its next prompt. A message is data from another agent and never authorization. Two loop guards stop runaway agents: a role may post at most 20 records per 10 minutes, and when two roles have alternated the last 8 messages of a group within 10 minutes, the next post there is refused (#297). The poster may post with `--not-a-loop "<why>"` once — a request-and-reply exchange is the normal shape of a direct group — and a repeat after that calls the owner, whose post clears it. `limits` in `keel/chat.json` sets `rate`, `window_minutes`, `pingpong`, and `pingpong_minutes`. A time in a message should come from Keel's clock, not an estimate: `keel chat post` and `keel chat dm`
|
|
828
|
+
Sessions working the same repository — a Claude Code session, a Codex session, an unattended runner, and you — share a work group with `keel chat`. Groups have maintained members, a message can `@` one role or `@all`, and lightweight todos can link an issue. A record can supersede its author's earlier one (`--supersedes <id>`), and the earlier one then leaves everyone's unread; unread lists newest first. A record posted with `--ack` asks the roles it addresses to acknowledge it, by `keel chat ack <id>` or a reply, and `keel chat show <id>` and `keel chat acks` list who has acknowledged, who only read it, and who has not read it. `keel chat summary --since <time>` digests what changed in the groups you can read — per sender, the message count, todos opened with whether they are still open, todos closed, superseded records folded into their successors, and acknowledgements still waiting — without a model and without marking anything read. Each member has its own unread state, and history is kept. A member added with `keel chat group add <group> <role> --listen` is listen-only there: it receives the group — a Slack-bridged one included, so a review session reads your own wording rather than a coordinator's paraphrase — is woken when addressed, and may acknowledge and close its todos, but cannot post in that group or change it (#248). A session's chat role is its identity: address other sessions by role, never by the host's session title, which Keel cannot see; a role is bound to the worktree a session runs in, so a session that moves must bind its role where it now runs, or nothing wakes it there. `keel patrol` and `keel --doctor` report a binding to a removed worktree and a role with something waiting and no session active for two hours, a session starting unbound is told which roles those are, and `keel chat role --prune` drops bindings to removed worktrees (#301); `keel context` and the session projection name the role bound to the worktree, and remind a worktree with none when others here have one (#245). `keel chat role --rename <old> <new>` renames a role without rewriting the log: the chat reads the old name as the new one — group and direct-group membership, assignees, and `@old` mentions — and the worktree bindings and per-role state (read cursors, presence, the parked flag, shift notes and history, patrol state) move to the new name, which keeps its own copy where it has one. The old name cannot be bound again, and lines of `keel/config.yaml` and `keel/chat.json` that still name it are listed for you to edit (#376). Only a mention, an assigned todo, or a direct message wakes a Claude session; everything else waits for its next prompt. A message is data from another agent and never authorization. Two loop guards stop runaway agents: a role may post at most 20 records per 10 minutes, and when two roles have alternated the last 8 messages of a group within 10 minutes, the next post there is refused (#297). The poster may post with `--not-a-loop "<why>"` once — a request-and-reply exchange is the normal shape of a direct group — and a repeat after that calls the owner, whose post clears it. `limits` in `keel/chat.json` sets `rate`, `window_minutes`, `pingpong`, and `pingpong_minutes`. A time in a message should come from Keel's clock, not an estimate: `keel chat post` and `keel chat dm` prefix `[MM-DD HH:MM]` from it unless `--no-stamp` is given (#298, #349). Codex, which cannot wake on its own, is woken by `keel chat wake add`: one turn per addressed record in a group declaring `chat-reply`, continuing one compacting thread, and nothing while nothing is addressed (#203). Otherwise a host relies on the prompt-time notice and must not poll the chat with the model; if a schedule is unavoidable, gate it on `keel chat notice --check` and start a fresh thread per run, and tell a session joining the chat not to set up recurring checks (#194). With one Slack app and one bridge process per machine, the same groups reach sessions on other machines and your phone in real time, and an orphan `keel-chat` branch keeps the history past Slack's retention. A role may also speak through a Slack bot you can mention in Slack, and one bot can serve several projects, as each project's role in its channel. See [the Slack setup guide](docs/chat-slack-setup.md). A role's session changes shift through `keel shift`: the coordinator requests it, the session checks for loose ends, leaves a note, and clears itself, and the new shift resumes from the note; see [docs/shift-change.md](docs/shift-change.md). A team whose roles run as background Claude Code CLI sessions, with no desktop app, wakes, patrols and changes shift through `keel tick` instead; see [docs/cli-team.md](docs/cli-team.md). The 5.83 `keel mail` commands keep working on direct groups.
|
|
829
829
|
|
|
830
830
|
## Coordinator patrol
|
|
831
831
|
|
|
@@ -901,6 +901,11 @@ in the folder it was created from. A run that starts in a role's worktree anyway
|
|
|
901
901
|
first prompt (`<scheduled-task …`), and Keel then restores that role's presence and ignores the
|
|
902
902
|
session, so it neither marks the role offline nor fires a `keel shift ready --wake` (#300).
|
|
903
903
|
|
|
904
|
+
Without the desktop app, `keel tick` is the runner: one model-free step that launchd calls every few
|
|
905
|
+
minutes, which runs the patrol once its recommended next run has passed. Declare `runner: tick`, and
|
|
906
|
+
`cadence: adaptive` to let the patrol choose that next run by what it saw; `keel tick task` prints the
|
|
907
|
+
launchd job. See [docs/cli-team.md](docs/cli-team.md).
|
|
908
|
+
|
|
904
909
|
## The owner's language
|
|
905
910
|
|
|
906
911
|
An agent reads mostly English — tool output, issues, specs, Keel's own output — and drifts into it when it answers you. Declare the language you want to be addressed in, and the rule is restated where replies are written: in `keel context`, the session-start note, and the chat hook on every prompt, in every worktree (#305) — and, on Claude, after every 15 tool calls or 10 minutes of them, since a status update written mid-turn follows no prompt (#311). The agent may still work in any language; identifiers, commands, paths, and quoted output stay as they are.
|
|
@@ -931,18 +936,23 @@ keel lenses list
|
|
|
931
936
|
keel lenses add <name> [--force]
|
|
932
937
|
|
|
933
938
|
# Group chat between sessions (see docs/chat-slack-setup.md for Slack)
|
|
934
|
-
keel chat role --set <role> [--alias <a>]
|
|
939
|
+
keel chat role --set <role> [--alias <a>] | --rename <old> <new>
|
|
935
940
|
keel chat group create <g> [--member <r>]... | add | remove | archive | list
|
|
936
941
|
keel chat <g> [<text>] [--since 2h] [--follow] # read, or post
|
|
937
942
|
keel chat dm <role> <text> | todo <g> --assignee <r> <text> | todos [--mine]
|
|
938
943
|
keel chat unread | read | notice | search <text>
|
|
939
944
|
keel chat bridge add | install | status | pause <2h> | stop | start | uninstall
|
|
945
|
+
keel chat wake now <role> # resume a role's ended CLI session
|
|
940
946
|
keel chat archive sync | pull
|
|
941
947
|
|
|
942
948
|
# Unattended triage — may this issue start work without asking?
|
|
943
949
|
# Keel never fetches the issue; pass what gh returned. At least one of the two.
|
|
944
950
|
keel triage [--labels <l1,l2>] [--issue <n>] [--json]
|
|
945
951
|
|
|
952
|
+
# Coordinator patrol, and the model-free step a host scheduler calls (docs/cli-team.md)
|
|
953
|
+
keel patrol [--since-last] [--notify] [--nudge] [--json]
|
|
954
|
+
keel tick [--json] | keel tick task # one step; print the launchd job
|
|
955
|
+
|
|
946
956
|
# External model CLIs — catalog, and the brief Keel compiles (it launches nothing)
|
|
947
957
|
keel agents [name] [--json]
|
|
948
958
|
keel agents brief <name> --mode helper|implementation --dir <path> --out <file>
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@christang/keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.159.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.159.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.159.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.159.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",
|
|
@@ -49,8 +49,8 @@ REQUIRED_SCRIPTS = [
|
|
|
49
49
|
"scripts/validate_plugin.py",
|
|
50
50
|
]
|
|
51
51
|
|
|
52
|
-
PACKAGE_VERSION = "5.
|
|
53
|
-
PROTOCOL_VERSION = "5.
|
|
52
|
+
PACKAGE_VERSION = "5.159.0"
|
|
53
|
+
PROTOCOL_VERSION = "5.159.0"
|
|
54
54
|
LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
|
|
55
55
|
OPENSPEC_SCHEMA_NAME = "keel-spec-driven"
|
|
56
56
|
# Mirrors KEEL_PACKAGE_NAME in scripts/install_to_repo.py, one of the two
|
|
@@ -2598,6 +2598,108 @@ def validate_chat_wake_now_cli_scenario() -> int:
|
|
|
2598
2598
|
return 0
|
|
2599
2599
|
|
|
2600
2600
|
|
|
2601
|
+
def validate_chat_role_rename_scenario() -> int:
|
|
2602
|
+
"""Issue #376: a renamed role kept nothing but its worktree binding.
|
|
2603
|
+
|
|
2604
|
+
kaiwu-ip renamed nine roles on 2026-10-19 with `role --set <new>`; the old
|
|
2605
|
+
name stayed a member of every direct group, kept the cursors, the shift
|
|
2606
|
+
note and the patrol state, and could not become an alias. `keel chat role
|
|
2607
|
+
--rename <old> <new>` reads the log through the rename and moves the state.
|
|
2608
|
+
"""
|
|
2609
|
+
label = "chat-role-rename:"
|
|
2610
|
+
with tempfile.TemporaryDirectory(prefix="keel-rename-376-") as raw:
|
|
2611
|
+
base = Path(raw)
|
|
2612
|
+
rtl, verify, env, _ = shift_scratch(base / "one")
|
|
2613
|
+
run_keel(rtl, "chat", "dm", "verify", "hello there", env=env)
|
|
2614
|
+
run_keel(rtl, "chat", "todo", "soc", "--assignee", "verify", "fix the lint", env=env)
|
|
2615
|
+
run_keel(verify, "chat", "read", env=env)
|
|
2616
|
+
readied = run_keel(verify, "shift", "ready", "--force-reason", "test", "half way through the lint", env=env)
|
|
2617
|
+
if readied.returncode != 0:
|
|
2618
|
+
report(f"{label} shift ready failed: {readied.stdout!r} {readied.stderr!r}")
|
|
2619
|
+
return 1
|
|
2620
|
+
write_text(verify / "keel/config.yaml", "patrol:\n role: verify\n every: 30m\n")
|
|
2621
|
+
for args, why, needle in ((("nobody", "check"), "an unknown role", "no role nobody"),
|
|
2622
|
+
(("verify", "verify"), "a rename onto itself", "itself"),
|
|
2623
|
+
(("verify", "rtl"), "a rename onto a role bound elsewhere", "both bound")):
|
|
2624
|
+
refused = run_keel(verify, "chat", "role", "--rename", *args, env=env)
|
|
2625
|
+
if refused.returncode == 0:
|
|
2626
|
+
report(f"{label} {why} was accepted: {refused.stdout!r}")
|
|
2627
|
+
return 1
|
|
2628
|
+
if needle not in refused.stderr:
|
|
2629
|
+
report(f"{label} {why} was not refused for that reason: {refused.stderr!r}")
|
|
2630
|
+
return 1
|
|
2631
|
+
renamed = run_keel(verify, "chat", "role", "--rename", "verify", "check", env=env)
|
|
2632
|
+
if renamed.returncode != 0:
|
|
2633
|
+
report(f"{label} keel chat role --rename was refused: {renamed.stdout!r} {renamed.stderr!r}")
|
|
2634
|
+
return 1
|
|
2635
|
+
if "role: verify" not in renamed.stdout:
|
|
2636
|
+
report(f"{label} the rename does not list keel/config.yaml's patrol line: {renamed.stdout!r}")
|
|
2637
|
+
return 1
|
|
2638
|
+
groups = json.loads(run_keel(verify, "chat", "group", "list", "--json", env=env).stdout)["groups"]
|
|
2639
|
+
for name in ("soc", "dm-rtl--verify"):
|
|
2640
|
+
members = next((g["members"] for g in groups if g["name"] == name), [])
|
|
2641
|
+
if "check" not in members:
|
|
2642
|
+
report(f"{label} check is not a member of {name}: {groups!r}")
|
|
2643
|
+
return 1
|
|
2644
|
+
todos = json.loads(run_keel(verify, "chat", "todos", "--mine", "--json", env=env).stdout)["todos"]
|
|
2645
|
+
if not any("fix the lint" in t.get("text", "") for t in todos):
|
|
2646
|
+
report(f"{label} check does not hold verify's todo: {todos!r}")
|
|
2647
|
+
return 1
|
|
2648
|
+
unread = json.loads(run_keel(verify, "chat", "unread", "--json", env=env).stdout)
|
|
2649
|
+
if "hello there" in json.dumps(unread):
|
|
2650
|
+
report(f"{label} a record verify had read is unread again: {unread!r}")
|
|
2651
|
+
return 1
|
|
2652
|
+
status = json.loads(run_keel(verify, "shift", "status", "--json", env=env).stdout)
|
|
2653
|
+
if not any(r.get("role") == "check" and r.get("note") for r in status.get("roles", [])):
|
|
2654
|
+
report(f"{label} shift status shows no note under check: {status!r}")
|
|
2655
|
+
return 1
|
|
2656
|
+
posted = run_keel(rtl, "chat", "post", "soc", "@verify please look", "--json", env=env)
|
|
2657
|
+
if posted.returncode != 0:
|
|
2658
|
+
report(f"{label} @verify was refused: {posted.stderr!r}")
|
|
2659
|
+
return 1
|
|
2660
|
+
if "check" not in json.loads(posted.stdout).get("mentions", []):
|
|
2661
|
+
report(f"{label} @verify does not mention check: {posted.stdout!r}")
|
|
2662
|
+
return 1
|
|
2663
|
+
if run_keel(verify, "chat", "notice", "--check", env=env).returncode != 0:
|
|
2664
|
+
report(f"{label} @verify does not wake check")
|
|
2665
|
+
return 1
|
|
2666
|
+
rebound = run_keel(rtl, "chat", "role", "--set", "verify", env=env)
|
|
2667
|
+
if rebound.returncode == 0:
|
|
2668
|
+
report(f"{label} binding the old name was accepted: {rebound.stdout!r}")
|
|
2669
|
+
return 1
|
|
2670
|
+
if "check" not in rebound.stderr:
|
|
2671
|
+
report(f"{label} binding the old name was refused without naming check: {rebound.stderr!r}")
|
|
2672
|
+
return 1
|
|
2673
|
+
|
|
2674
|
+
rtl2, verify2, env2, _ = shift_scratch(base / "two")
|
|
2675
|
+
run_keel(rtl2, "chat", "post", "soc", "first", env=env2)
|
|
2676
|
+
run_keel(verify2, "chat", "read", env=env2)
|
|
2677
|
+
run_keel(rtl2, "chat", "group", "add", "soc", "check", env=env2)
|
|
2678
|
+
run_keel(rtl2, "chat", "post", "soc", "second", env=env2)
|
|
2679
|
+
run_keel(verify2, "chat", "role", "--set", "check", env=env2)
|
|
2680
|
+
run_keel(verify2, "chat", "read", env=env2)
|
|
2681
|
+
merged = run_keel(verify2, "chat", "role", "--rename", "verify", "check", env=env2)
|
|
2682
|
+
if merged.returncode != 0:
|
|
2683
|
+
report(f"{label} keel chat role --rename was refused onto an existing role: {merged.stdout!r} {merged.stderr!r}")
|
|
2684
|
+
return 1
|
|
2685
|
+
left = json.loads(run_keel(verify2, "chat", "unread", "--json", env=env2).stdout)
|
|
2686
|
+
if "second" in json.dumps(left):
|
|
2687
|
+
report(f"{label} check's later cursor was not kept: {left!r}")
|
|
2688
|
+
return 1
|
|
2689
|
+
alias = run_keel(rtl2, "chat", "role", "--alias", "verify", env=env2)
|
|
2690
|
+
if alias.returncode == 0:
|
|
2691
|
+
report(f"{label} --alias verify was accepted: {alias.stdout!r}")
|
|
2692
|
+
return 1
|
|
2693
|
+
if "check" not in alias.stderr:
|
|
2694
|
+
report(f"{label} --alias verify was refused without naming check: {alias.stderr!r}")
|
|
2695
|
+
return 1
|
|
2696
|
+
if "chat-role-rename" not in {name for name, _ in SCENARIOS}:
|
|
2697
|
+
report(f"{label} scenario is not registered.")
|
|
2698
|
+
return 1
|
|
2699
|
+
report("chat-role-rename scenario passed.")
|
|
2700
|
+
return 0
|
|
2701
|
+
|
|
2702
|
+
|
|
2601
2703
|
def validate_two_live_sessions_on_one_role_scenario() -> int:
|
|
2602
2704
|
"""Issue #369 point 4: two live sessions bound to one role are reported.
|
|
2603
2705
|
|
|
@@ -42504,6 +42606,7 @@ SCENARIOS: tuple = (
|
|
|
42504
42606
|
("chat-supersedes", validate_chat_supersedes_scenario),
|
|
42505
42607
|
("chat-mention-skips-code", validate_chat_mention_skips_code_scenario),
|
|
42506
42608
|
("two-live-sessions-on-one-role", validate_two_live_sessions_on_one_role_scenario),
|
|
42609
|
+
("chat-role-rename", validate_chat_role_rename_scenario),
|
|
42507
42610
|
("chat-wake-now-cli", validate_chat_wake_now_cli_scenario),
|
|
42508
42611
|
("chat-ack", validate_chat_ack_scenario),
|
|
42509
42612
|
("coordinator-patrol", validate_coordinator_patrol_scenario),
|
package/src/core/chat/cli.js
CHANGED
|
@@ -17,6 +17,7 @@ const { ChatError } = store;
|
|
|
17
17
|
const USAGE = [
|
|
18
18
|
"keel chat role [--set <name>] [--alias <alias>] [--prune] [--json] (--prune: drop bindings to removed worktrees)",
|
|
19
19
|
"keel chat role --park <role> [--reason <text>] | --unpark <role> (a role parked on purpose is not nudged or reported by the patrol)",
|
|
20
|
+
"keel chat role --rename <old> <new> [--json] (the chat reads <old> as <new>; bindings and per-role state move to <new>)",
|
|
20
21
|
"keel chat group create <group> [--member <role>]...",
|
|
21
22
|
"keel chat group add|remove <group> <role> [--listen] (--listen: receives the group, may ack and close its todos, does not post)",
|
|
22
23
|
"keel chat group archive <group>",
|
|
@@ -59,6 +60,7 @@ const USAGE = [
|
|
|
59
60
|
const VALUED = {
|
|
60
61
|
"--set": "set",
|
|
61
62
|
"--alias": "alias",
|
|
63
|
+
"--rename": "rename",
|
|
62
64
|
"--park": "park",
|
|
63
65
|
"--unpark": "unpark",
|
|
64
66
|
"--reason": "reason",
|
|
@@ -366,6 +368,14 @@ function dispatch(where, options) {
|
|
|
366
368
|
else out(pruned.length ? pruned.map((entry) => `Pruned ${entry.role} from ${entry.worktree}.`).join("\n") : "No binding points at a removed worktree.");
|
|
367
369
|
return 0;
|
|
368
370
|
}
|
|
371
|
+
if (options.rename !== null && options.rename !== undefined) {
|
|
372
|
+
// `--rename <old> <new>` (#376 D7).
|
|
373
|
+
if (!rest[0]) throw new ChatError("keel chat role --rename needs the old and the new name: --rename <old> <new>.");
|
|
374
|
+
const rename = require("./rename");
|
|
375
|
+
const result = rename.rename(where, store.currentRole(where), String(options.rename).toLowerCase(), String(rest[0]).toLowerCase());
|
|
376
|
+
out(options.json ? JSON.stringify(result) : rename.render(result));
|
|
377
|
+
return 0;
|
|
378
|
+
}
|
|
369
379
|
let role = store.currentRole(where);
|
|
370
380
|
if (options.set !== null) role = store.setRole(where, options.set);
|
|
371
381
|
if (options.alias !== null) {
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// `keel chat role --rename <old> <new>` (#376). The log is never rewritten:
|
|
4
|
+
// `renames.json` records the identity and the store reads every role field
|
|
5
|
+
// through it (D1, D2). What moves is the per-role state outside the log (D5).
|
|
6
|
+
const fs = require("fs");
|
|
7
|
+
const path = require("path");
|
|
8
|
+
const store = require("./store");
|
|
9
|
+
|
|
10
|
+
const { ChatError } = store;
|
|
11
|
+
|
|
12
|
+
function exists(file) {
|
|
13
|
+
try {
|
|
14
|
+
fs.statSync(file);
|
|
15
|
+
return true;
|
|
16
|
+
} catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function list(dir) {
|
|
22
|
+
try {
|
|
23
|
+
return fs.readdirSync(dir).sort();
|
|
24
|
+
} catch {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Whether the store knows `role` at all: bound, a member file, a member of
|
|
30
|
+
// some group, or state of its own.
|
|
31
|
+
function known(where, role) {
|
|
32
|
+
if (store.knownRoles(where).has(role)) return true;
|
|
33
|
+
return ["cursors", "presence", "parked", "shift"].some((dir) => list(path.join(where.root, dir))
|
|
34
|
+
.some((name) => name === role || name.startsWith(`${role}.`)));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function check(where, actor, old, name) {
|
|
38
|
+
store.checkName(old, "Role");
|
|
39
|
+
store.checkName(name, "Role");
|
|
40
|
+
if (name === "keel" || old === "keel") throw new ChatError("Role name keel is reserved for Keel's own system records.");
|
|
41
|
+
if (old === name) throw new ChatError(`Role ${old} cannot be renamed to itself.`);
|
|
42
|
+
const renames = store.readRenames(where.root);
|
|
43
|
+
if (renames[old]) throw new ChatError(`Role ${old} was already renamed to ${store.canonicalRole(where.root, old)}.`);
|
|
44
|
+
if (store.canonicalRole(where.root, name) !== name) {
|
|
45
|
+
throw new ChatError(`Role ${name} is a former name of ${store.canonicalRole(where.root, name)}; rename to that role instead.`);
|
|
46
|
+
}
|
|
47
|
+
if (!known(where, old)) throw new ChatError(`There is no role ${old} in this repository's chat.`);
|
|
48
|
+
if (![old, name, store.OWNER].includes(actor)) {
|
|
49
|
+
throw new ChatError(`Only a worktree bound to ${old} or ${name}, or the owner (KEEL_CHAT_ROLE=owner), can rename ${old}.`);
|
|
50
|
+
}
|
|
51
|
+
const bound = Object.values(store.readRoles(where.root));
|
|
52
|
+
if (bound.includes(old) && bound.includes(name)) {
|
|
53
|
+
throw new ChatError(`Roles ${old} and ${name} are both bound to worktrees, so a rename would merge two live roles; `
|
|
54
|
+
+ `rebind one of the worktrees with \`keel chat role --set\` first.`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function rename(where, actor, old, name) {
|
|
59
|
+
check(where, actor, old, name);
|
|
60
|
+
const root = where.root;
|
|
61
|
+
const moved = [];
|
|
62
|
+
const kept = [];
|
|
63
|
+
|
|
64
|
+
const renames = store.readRenames(root);
|
|
65
|
+
for (const [from, to] of Object.entries(renames)) if (to === old) renames[from] = name;
|
|
66
|
+
renames[old] = name;
|
|
67
|
+
store.writeJsonAtomic(where, path.join(root, "renames.json"), renames);
|
|
68
|
+
|
|
69
|
+
const roles = store.readRoles(root);
|
|
70
|
+
for (const [worktree, role] of Object.entries(roles)) {
|
|
71
|
+
if (role !== old) continue;
|
|
72
|
+
roles[worktree] = name;
|
|
73
|
+
moved.push(`binding of ${worktree}`);
|
|
74
|
+
}
|
|
75
|
+
store.writeJsonAtomic(where, path.join(root, "roles.json"), roles);
|
|
76
|
+
|
|
77
|
+
// Aliases join the new role's (D5).
|
|
78
|
+
const former = store.readMember(root, old).aliases;
|
|
79
|
+
if (exists(path.join(root, "members", `${old}.json`))) {
|
|
80
|
+
const member = store.readMember(root, name);
|
|
81
|
+
for (const alias of former) if (!member.aliases.includes(alias) && alias !== name) member.aliases.push(alias);
|
|
82
|
+
store.writeJsonAtomic(where, path.join(root, "members", `${name}.json`), member);
|
|
83
|
+
fs.rmSync(path.join(root, "members", `${old}.json`), { force: true });
|
|
84
|
+
moved.push(`members/${old}.json`);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const moveFile = (from, to, edit = null) => {
|
|
88
|
+
const source = path.join(root, from);
|
|
89
|
+
if (!exists(source)) return;
|
|
90
|
+
if (exists(path.join(root, to))) {
|
|
91
|
+
kept.push(`${to} (${from} left in place)`);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
fs.mkdirSync(path.dirname(path.join(root, to)), { recursive: true });
|
|
95
|
+
if (edit) {
|
|
96
|
+
store.writeJsonAtomic(where, path.join(root, to), edit(store.readJsonFile(source)));
|
|
97
|
+
fs.rmSync(source, { force: true });
|
|
98
|
+
} else {
|
|
99
|
+
fs.renameSync(source, path.join(root, to));
|
|
100
|
+
}
|
|
101
|
+
moved.push(from);
|
|
102
|
+
};
|
|
103
|
+
const withRole = (value) => (value && typeof value === "object" && value.role ? { ...value, role: name } : value);
|
|
104
|
+
|
|
105
|
+
// Cursors: the later id per group wins.
|
|
106
|
+
for (const group of list(path.join(root, "cursors", old))) {
|
|
107
|
+
const mine = store.readCursor(where, old, group);
|
|
108
|
+
if (mine) store.advanceCursor(where, name, group, mine);
|
|
109
|
+
moved.push(`cursors/${old}/${group}`);
|
|
110
|
+
}
|
|
111
|
+
fs.rmSync(path.join(root, "cursors", old), { recursive: true, force: true });
|
|
112
|
+
|
|
113
|
+
moveFile(`presence/${old}.json`, `presence/${name}.json`);
|
|
114
|
+
moveFile(`presence/${old}.sessions.json`, `presence/${name}.sessions.json`);
|
|
115
|
+
moveFile(`parked/${old}.json`, `parked/${name}.json`, withRole);
|
|
116
|
+
moveFile(`shift/${old}.md`, `shift/${name}.md`);
|
|
117
|
+
moveFile(`shift/queue/${old}.json`, `shift/queue/${name}.json`, withRole);
|
|
118
|
+
moveFile(`patrol/${old}.json`, `patrol/${name}.json`);
|
|
119
|
+
for (const file of list(path.join(root, "shift", "history"))) {
|
|
120
|
+
if (file.startsWith(`${old}-`) && /^\d/.test(file.slice(old.length + 1))) {
|
|
121
|
+
moveFile(`shift/history/${file}`, `shift/history/${name}-${file.slice(old.length + 1)}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
for (const file of list(path.join(root, "shift", "transcripts", old))) {
|
|
125
|
+
moveFile(`shift/transcripts/${old}/${file}`, `shift/transcripts/${name}/${file}`);
|
|
126
|
+
}
|
|
127
|
+
if (!list(path.join(root, "shift", "transcripts", old)).length) fs.rmSync(path.join(root, "shift", "transcripts", old), { recursive: true, force: true });
|
|
128
|
+
|
|
129
|
+
// Segments concatenate, in start order.
|
|
130
|
+
const segmentsOf = (role) => {
|
|
131
|
+
const value = store.readJsonFile(path.join(root, "shift", "segments", `${role}.json`));
|
|
132
|
+
return Array.isArray(value.segments) ? value.segments : null;
|
|
133
|
+
};
|
|
134
|
+
const oldSegments = segmentsOf(old);
|
|
135
|
+
if (oldSegments) {
|
|
136
|
+
const segments = [...(segmentsOf(name) || []), ...oldSegments].sort((a, b) => String(a.started).localeCompare(String(b.started)));
|
|
137
|
+
store.writeJsonAtomic(where, path.join(root, "shift", "segments", `${name}.json`), { segments });
|
|
138
|
+
fs.rmSync(path.join(root, "shift", "segments", `${old}.json`), { force: true });
|
|
139
|
+
moved.push(`shift/segments/${old}.json`);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// The patrol log is appended to the new role's.
|
|
143
|
+
const log = path.join(root, "patrol", "log", `${old}.log`);
|
|
144
|
+
if (exists(log)) {
|
|
145
|
+
fs.appendFileSync(path.join(root, "patrol", "log", `${name}.log`), fs.readFileSync(log));
|
|
146
|
+
fs.rmSync(log, { force: true });
|
|
147
|
+
moved.push(`patrol/log/${old}.log`);
|
|
148
|
+
}
|
|
149
|
+
const nudgesFile = path.join(root, "patrol", "nudges.json");
|
|
150
|
+
const nudges = store.readJsonFile(nudgesFile);
|
|
151
|
+
if (nudges && nudges[old]) {
|
|
152
|
+
if (nudges[name]) kept.push(`patrol/nudges.json ${name} (${old}'s entry dropped)`);
|
|
153
|
+
else {
|
|
154
|
+
nudges[name] = nudges[old];
|
|
155
|
+
moved.push(`patrol/nudges.json ${old}`);
|
|
156
|
+
}
|
|
157
|
+
delete nudges[old];
|
|
158
|
+
store.writeJsonAtomic(where, nudgesFile, nudges);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// What describes the old session only is dropped.
|
|
162
|
+
fs.rmSync(path.join(root, "signal", old), { force: true });
|
|
163
|
+
const tickFile = path.join(root, "tick", "state.json");
|
|
164
|
+
const tick = store.readJsonFile(tickFile);
|
|
165
|
+
if (tick && tick.woken && tick.woken[old]) {
|
|
166
|
+
delete tick.woken[old];
|
|
167
|
+
store.writeJsonAtomic(where, tickFile, tick);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return { old, role: name, moved, kept, mentions: mentionsOf(where.worktree, old) };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Lines of the files Keel reads but does not own that still name `old` (D6).
|
|
174
|
+
function mentionsOf(worktree, old) {
|
|
175
|
+
const word = new RegExp(`(^|[^a-z0-9-])${old}($|[^a-z0-9-])`);
|
|
176
|
+
const found = [];
|
|
177
|
+
for (const relative of ["keel/config.yaml", "keel/chat.json"]) {
|
|
178
|
+
let text = "";
|
|
179
|
+
try {
|
|
180
|
+
text = fs.readFileSync(path.join(worktree, relative), "utf8");
|
|
181
|
+
} catch {
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
text.split(/\r?\n/).forEach((line, index) => {
|
|
185
|
+
if (word.test(line)) found.push({ file: relative, line: index + 1, text: line.trim() });
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
return found;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function render(result) {
|
|
192
|
+
const lines = [`Renamed role ${result.old} to ${result.role}: the chat now reads ${result.old} as ${result.role}, and @${result.old} mentions it.`];
|
|
193
|
+
if (result.moved.length) lines.push(`Moved to ${result.role}: ${result.moved.join(", ")}.`);
|
|
194
|
+
if (result.kept.length) lines.push(`Kept ${result.role}'s own: ${result.kept.join(", ")}.`);
|
|
195
|
+
if (result.mentions.length) {
|
|
196
|
+
lines.push(`Still naming ${result.old}; Keel does not edit these, so update them by hand:`);
|
|
197
|
+
for (const m of result.mentions) lines.push(` ${m.file}:${m.line}: ${m.text}`);
|
|
198
|
+
}
|
|
199
|
+
return lines.join("\n");
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
module.exports = { rename, render };
|
package/src/core/chat/store.js
CHANGED
|
@@ -129,11 +129,11 @@ function currentRole(where) {
|
|
|
129
129
|
const override = (process.env[variable] || "").trim();
|
|
130
130
|
if (override) {
|
|
131
131
|
checkName(override, variable);
|
|
132
|
-
return override;
|
|
132
|
+
return canonicalRole(where.root, override);
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
const bound = readRoles(where.root)[where.worktree];
|
|
136
|
-
return validName(bound) ? bound : null;
|
|
136
|
+
return validName(bound) ? canonicalRole(where.root, bound) : null;
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
function requireRole(where) {
|
|
@@ -155,6 +155,8 @@ function setRole(where, name) {
|
|
|
155
155
|
checkName(name, "Role");
|
|
156
156
|
// `keel` signs the loop guard's system records, so no member may take it.
|
|
157
157
|
if (name === "keel") throw new ChatError("Role name keel is reserved for Keel's own system records.");
|
|
158
|
+
const renamed = canonicalRole(where.root, name);
|
|
159
|
+
if (renamed !== name) throw new ChatError(`Role ${name} was renamed to ${renamed}; bind ${renamed} instead.`);
|
|
158
160
|
const roles = readRoles(where.root);
|
|
159
161
|
roles[where.worktree] = name;
|
|
160
162
|
writeRoles(where, roles);
|
|
@@ -188,9 +190,39 @@ function aliasMap(root) {
|
|
|
188
190
|
for (const role of listMemberRoles(root)) {
|
|
189
191
|
for (const alias of readMember(root, role).aliases) map[alias] = role;
|
|
190
192
|
}
|
|
193
|
+
// A former name addresses its role (#376 D3).
|
|
194
|
+
for (const former of Object.keys(readRenames(root))) map[former] = canonicalRole(root, former);
|
|
191
195
|
return map;
|
|
192
196
|
}
|
|
193
197
|
|
|
198
|
+
// --- renamed roles (#376) -------------------------------------------------------
|
|
199
|
+
|
|
200
|
+
// `{ "<old>": "<new>" }`: an identity record, never a rewrite of the log (D1).
|
|
201
|
+
function readRenames(root) {
|
|
202
|
+
const parsed = readJson(path.join(root, "renames.json"), {});
|
|
203
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// A name's current role, through chains of renames.
|
|
207
|
+
function canonicalRole(root, name, renames = readRenames(root)) {
|
|
208
|
+
let role = name;
|
|
209
|
+
for (let hops = 0; hops < 32 && validName(renames[role]); hops += 1) role = renames[role];
|
|
210
|
+
return role;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Every role field a record carries, read through the renames (D2); a direct
|
|
214
|
+
// group's members come from its name, so they are given as `direct`.
|
|
215
|
+
function mapRecord(record, renames) {
|
|
216
|
+
if (!record || !Object.keys(renames).length) return record;
|
|
217
|
+
const map = (name) => (validName(name) ? canonicalRole(null, name, renames) : name);
|
|
218
|
+
record.from = map(record.from);
|
|
219
|
+
if (record.assignee) record.assignee = map(record.assignee);
|
|
220
|
+
if (Array.isArray(record.mentions)) record.mentions = [...new Set(record.mentions.map(map))];
|
|
221
|
+
if ((record.kind === "join" || record.kind === "leave") && record.target) record.target = map(record.target);
|
|
222
|
+
if (record.group && isDirect(record.group)) record.direct = [...new Set(directMembers(record.group).map(map))];
|
|
223
|
+
return record;
|
|
224
|
+
}
|
|
225
|
+
|
|
194
226
|
function addAlias(where, role, rawAlias) {
|
|
195
227
|
const alias = String(rawAlias || "").toLowerCase();
|
|
196
228
|
checkName(alias, "Alias");
|
|
@@ -322,6 +354,7 @@ function readLog(where, group) {
|
|
|
322
354
|
return [];
|
|
323
355
|
}
|
|
324
356
|
const records = [];
|
|
357
|
+
const renames = readRenames(where.root);
|
|
325
358
|
for (const name of names) {
|
|
326
359
|
let parsed = null;
|
|
327
360
|
try {
|
|
@@ -329,7 +362,7 @@ function readLog(where, group) {
|
|
|
329
362
|
} catch {
|
|
330
363
|
continue;
|
|
331
364
|
}
|
|
332
|
-
if (parsed && parsed.id === name.slice(0, -3)) records.push(parsed);
|
|
365
|
+
if (parsed && parsed.id === name.slice(0, -3)) records.push(mapRecord(parsed, renames));
|
|
333
366
|
}
|
|
334
367
|
return records;
|
|
335
368
|
}
|
|
@@ -348,7 +381,7 @@ function writeRecord(where, fields, date = new Date()) {
|
|
|
348
381
|
// Each worktree bound to a woken role gets its own signal too, which a
|
|
349
382
|
// session watches from its start whether or not a role was bound yet
|
|
350
383
|
// (chat-wake-late-binding D2).
|
|
351
|
-
const targets = signalTargets(record);
|
|
384
|
+
const targets = signalTargets(mapRecord({ ...record, mentions: [...(record.mentions || [])] }, readRenames(where.root)));
|
|
352
385
|
const bound = targets.length ? readRoles(where.root) : {};
|
|
353
386
|
for (const role of targets) {
|
|
354
387
|
const signals = [path.join(where.root, "signal", role)];
|
|
@@ -392,7 +425,7 @@ function wakes(record, role) {
|
|
|
392
425
|
if (!READABLE_KINDS.has(record.kind) || record.from === role) return false;
|
|
393
426
|
if ((record.mentions || []).includes(role)) return true;
|
|
394
427
|
if (record.kind === "todo" && record.assignee === role) return true;
|
|
395
|
-
return directMembers(record.group).includes(role);
|
|
428
|
+
return (record.direct || directMembers(record.group)).includes(role);
|
|
396
429
|
}
|
|
397
430
|
|
|
398
431
|
function signalTargets(record) {
|
|
@@ -400,7 +433,7 @@ function signalTargets(record) {
|
|
|
400
433
|
const roles = new Set([
|
|
401
434
|
...(record.mentions || []),
|
|
402
435
|
...(record.kind === "todo" && record.assignee ? [record.assignee] : []),
|
|
403
|
-
...directMembers(record.group),
|
|
436
|
+
...(record.direct || directMembers(record.group)),
|
|
404
437
|
]);
|
|
405
438
|
return [...roles].filter((role) => validName(role) && wakes(record, role));
|
|
406
439
|
}
|
|
@@ -489,6 +522,7 @@ function createGroup(where, actor, group, members, { direct = false } = {}) {
|
|
|
489
522
|
|
|
490
523
|
function changeMember(where, actor, group, member, kind, { listen = false } = {}) {
|
|
491
524
|
checkName(member, "Member");
|
|
525
|
+
member = canonicalRole(where.root, member);
|
|
492
526
|
if (isDirect(group)) {
|
|
493
527
|
throw new ChatError(`Direct group ${group} has fixed members.`);
|
|
494
528
|
}
|
|
@@ -567,7 +601,7 @@ function findRecord(where, id) {
|
|
|
567
601
|
const file = path.join(groupDir(where, group), "log", `${id}.md`);
|
|
568
602
|
if (!fs.existsSync(file)) continue;
|
|
569
603
|
const record = parseRecord(fs.readFileSync(file, "utf8"));
|
|
570
|
-
if (record) return record;
|
|
604
|
+
if (record) return mapRecord(record, readRenames(where.root));
|
|
571
605
|
}
|
|
572
606
|
return null;
|
|
573
607
|
}
|
|
@@ -734,6 +768,7 @@ function normalizeIssue(issue) {
|
|
|
734
768
|
|
|
735
769
|
function todo(where, options) {
|
|
736
770
|
checkName(options.assignee, "Assignee");
|
|
771
|
+
options = { ...options, assignee: canonicalRole(where.root, options.assignee) };
|
|
737
772
|
const { state } = loadGroup(where, options.group);
|
|
738
773
|
if (!canAct(state, options.assignee)) {
|
|
739
774
|
throw new ChatError(`Assignee ${options.assignee} is not a member of group ${options.group}.`);
|
|
@@ -815,6 +850,7 @@ function search(where, text, { group = null } = {}) {
|
|
|
815
850
|
function directPost(where, target, text, extra = {}) {
|
|
816
851
|
const from = requireRole(where);
|
|
817
852
|
checkName(target, "Recipient");
|
|
853
|
+
target = canonicalRole(where.root, target);
|
|
818
854
|
if (target === from) throw new ChatError("A direct group needs two different roles.");
|
|
819
855
|
const group = directName(from, target);
|
|
820
856
|
if (!groupState(readLog(where, group)).exists) {
|
|
@@ -998,6 +1034,10 @@ function readGroups(where, role, group) {
|
|
|
998
1034
|
}
|
|
999
1035
|
|
|
1000
1036
|
module.exports = {
|
|
1037
|
+
readRenames,
|
|
1038
|
+
readRoles,
|
|
1039
|
+
knownRoles,
|
|
1040
|
+
canonicalRole,
|
|
1001
1041
|
wait,
|
|
1002
1042
|
mentionText,
|
|
1003
1043
|
openWaits,
|