@christang/keel 5.142.0 → 5.144.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/assets/bootstrap/AGENTS.md +1 -1
- package/bin/keel.js +18 -3
- 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 +209 -2
- package/src/core/chat/notice.js +32 -0
- package/src/core/shift.js +37 -7
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.144.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/bin/keel.js
CHANGED
|
@@ -1097,12 +1097,19 @@ function hostFails(executable, args) {
|
|
|
1097
1097
|
return Boolean(result.error) || result.status !== 0;
|
|
1098
1098
|
}
|
|
1099
1099
|
|
|
1100
|
+
// Why a host step failed: its spawn error, or its exit status with the last
|
|
1101
|
+
// line it wrote to stderr, so the cause is visible the first time (#359).
|
|
1102
|
+
function hostFailure(result) {
|
|
1103
|
+
if (result.error) return result.error.message;
|
|
1104
|
+
const last = String(result.stderr || "").trim().split(/\r?\n/).pop().trim();
|
|
1105
|
+
return `exited ${result.status}${last ? `: ${last}` : ""}`;
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1100
1108
|
function runHostSteps(component, name, executable, steps) {
|
|
1101
1109
|
for (const args of steps) {
|
|
1102
1110
|
const result = hostRun(executable, args);
|
|
1103
1111
|
if (result.error || result.status !== 0) {
|
|
1104
|
-
|
|
1105
|
-
updateLine(component, "failed", `\`${name} ${args.join(" ")}\` ${why}`);
|
|
1112
|
+
updateLine(component, "failed", `\`${name} ${args.join(" ")}\` ${hostFailure(result)}`);
|
|
1106
1113
|
return false;
|
|
1107
1114
|
}
|
|
1108
1115
|
}
|
|
@@ -1133,7 +1140,15 @@ function updateClaudePlugin(options) {
|
|
|
1133
1140
|
updateLine(component, "absent", "Claude Code is not installed here or has no Keel plugin");
|
|
1134
1141
|
return true;
|
|
1135
1142
|
}
|
|
1136
|
-
|
|
1143
|
+
// The refresh fetches over the network, and on a proxied link it has failed
|
|
1144
|
+
// once and passed on a direct retry; one retry absorbs that, as for Codex (#359).
|
|
1145
|
+
let refreshed = hostRun(executable, steps[0]);
|
|
1146
|
+
if (refreshed.error || refreshed.status !== 0) refreshed = hostRun(executable, steps[0]);
|
|
1147
|
+
if (refreshed.error || refreshed.status !== 0) {
|
|
1148
|
+
updateLine(component, "failed", `\`claude ${steps[0].join(" ")}\` failed twice; ${hostFailure(refreshed)}`);
|
|
1149
|
+
return false;
|
|
1150
|
+
}
|
|
1151
|
+
if (!runHostSteps(component, "claude", executable, [steps[1]])) return false;
|
|
1137
1152
|
const after = claudeKeel(executable);
|
|
1138
1153
|
if (after && after.failed) {
|
|
1139
1154
|
updateLine(component, "failed", `${after.failed} after the update, so its result is unverified`);
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@christang/keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.144.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.144.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.144.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.144.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",
|
|
@@ -5,6 +5,7 @@ from __future__ import annotations
|
|
|
5
5
|
|
|
6
6
|
import contextlib
|
|
7
7
|
import json
|
|
8
|
+
import gzip
|
|
8
9
|
import hashlib
|
|
9
10
|
import os
|
|
10
11
|
import re
|
|
@@ -48,8 +49,8 @@ REQUIRED_SCRIPTS = [
|
|
|
48
49
|
"scripts/validate_plugin.py",
|
|
49
50
|
]
|
|
50
51
|
|
|
51
|
-
PACKAGE_VERSION = "5.
|
|
52
|
-
PROTOCOL_VERSION = "5.
|
|
52
|
+
PACKAGE_VERSION = "5.144.0"
|
|
53
|
+
PROTOCOL_VERSION = "5.144.0"
|
|
53
54
|
LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
|
|
54
55
|
OPENSPEC_SCHEMA_NAME = "keel-spec-driven"
|
|
55
56
|
# Mirrors KEEL_PACKAGE_NAME in scripts/install_to_repo.py, one of the two
|
|
@@ -6260,6 +6261,118 @@ def validate_host_run_session_scenario() -> int:
|
|
|
6260
6261
|
return 0
|
|
6261
6262
|
|
|
6262
6263
|
|
|
6264
|
+
def validate_shift_keeps_transcripts_scenario() -> int:
|
|
6265
|
+
"""Issue #343: a shift's conversation outlives the host's transcript file.
|
|
6266
|
+
|
|
6267
|
+
Claude deletes transcripts after `cleanupPeriodDays` (30 by default), so
|
|
6268
|
+
when a role's session starts a new transcript the hook copies the ended
|
|
6269
|
+
one into Keel's store; `history` and `--grep` read the copy once the
|
|
6270
|
+
host's file is gone, and `--grep` reads a Codex rollout too.
|
|
6271
|
+
"""
|
|
6272
|
+
label = "shift-keeps-transcripts:"
|
|
6273
|
+
with tempfile.TemporaryDirectory(prefix="keel-shift-343-") as raw:
|
|
6274
|
+
base = Path(raw)
|
|
6275
|
+
rtl, verify, env, _ = shift_scratch(base)
|
|
6276
|
+
store_root = mailbox_common_dir(rtl) / "keel-chat"
|
|
6277
|
+
kept_dir = store_root / "shift" / "transcripts" / "verify"
|
|
6278
|
+
transcripts = base / "transcripts"
|
|
6279
|
+
transcripts.mkdir()
|
|
6280
|
+
|
|
6281
|
+
def claude_transcript(name: str, said: str) -> Path:
|
|
6282
|
+
path = transcripts / f"{name}.jsonl"
|
|
6283
|
+
path.write_text("\n".join(json.dumps(record) for record in (
|
|
6284
|
+
{"type": "user", "timestamp": "2026-10-12T01:00:00.000Z", "message": {"role": "user", "content": "carry on"}},
|
|
6285
|
+
{"type": "assistant", "timestamp": "2026-10-12T01:00:05.000Z",
|
|
6286
|
+
"message": {"role": "assistant", "content": [{"type": "text", "text": said}]}},
|
|
6287
|
+
)) + "\n", encoding="utf-8")
|
|
6288
|
+
return path
|
|
6289
|
+
|
|
6290
|
+
def hook(transcript: Path, session: str) -> None:
|
|
6291
|
+
for event, name in (("session-start", "SessionStart"), ("user-prompt-submit", "UserPromptSubmit")):
|
|
6292
|
+
subprocess.run(
|
|
6293
|
+
["node", str(ROOT / "bin" / "keel.js"), "chat", "hook", event],
|
|
6294
|
+
cwd=verify, env=env, text=True, capture_output=True, check=False,
|
|
6295
|
+
input=json.dumps({"cwd": str(verify), "hook_event_name": name, "session_id": session,
|
|
6296
|
+
"prompt": "go", "source": "startup", "transcript_path": str(transcript)}),
|
|
6297
|
+
)
|
|
6298
|
+
|
|
6299
|
+
def history(*args: str) -> subprocess.CompletedProcess[str]:
|
|
6300
|
+
return run_keel(verify, "shift", "history", *args, env=env)
|
|
6301
|
+
|
|
6302
|
+
a = claude_transcript("a", "The arbiter retry budget is four cycles.")
|
|
6303
|
+
b = claude_transcript("b", "Resumed from the note.")
|
|
6304
|
+
hook(a, "s1")
|
|
6305
|
+
hook(b, "s1")
|
|
6306
|
+
kept_a = kept_dir / "a.jsonl.gz"
|
|
6307
|
+
if not kept_a.is_file():
|
|
6308
|
+
report(f"{label} no kept copy of transcript A under {kept_dir}: {sorted(p.name for p in kept_dir.glob('*')) if kept_dir.exists() else 'no directory'}")
|
|
6309
|
+
return 1
|
|
6310
|
+
if gzip.decompress(kept_a.read_bytes()) != a.read_bytes():
|
|
6311
|
+
report(f"{label} the kept copy of A is not A's bytes.")
|
|
6312
|
+
return 1
|
|
6313
|
+
if (kept_dir / "b.jsonl.gz").exists():
|
|
6314
|
+
report(f"{label} the current transcript B was copied while it is still being written.")
|
|
6315
|
+
return 1
|
|
6316
|
+
|
|
6317
|
+
a.unlink()
|
|
6318
|
+
listed = history("verify")
|
|
6319
|
+
line_a = next((l for l in listed.stdout.splitlines() if str(a) in l), "")
|
|
6320
|
+
if "(missing)" in line_a:
|
|
6321
|
+
report(f"{label} A, deleted but kept, is still listed as missing: {line_a!r}")
|
|
6322
|
+
return 1
|
|
6323
|
+
if "(kept)" not in line_a:
|
|
6324
|
+
report(f"{label} A, deleted but kept, is not marked (kept): {line_a!r}")
|
|
6325
|
+
return 1
|
|
6326
|
+
found = history("verify", "--grep", "retry budget")
|
|
6327
|
+
if found.returncode != 0:
|
|
6328
|
+
report(f"{label} --grep for a phrase in the kept copy of A exited {found.returncode}: {found.stdout!r} {found.stderr!r}")
|
|
6329
|
+
return 1
|
|
6330
|
+
if "retry budget" not in found.stdout:
|
|
6331
|
+
report(f"{label} --grep does not print the phrase from the kept copy of A: {found.stdout!r}")
|
|
6332
|
+
return 1
|
|
6333
|
+
|
|
6334
|
+
# A Codex rollout is searched the same way.
|
|
6335
|
+
c = transcripts / "rollout-c.jsonl"
|
|
6336
|
+
c.write_text("\n".join(json.dumps(record) for record in (
|
|
6337
|
+
{"timestamp": "2026-10-18T09:50:18.096Z", "type": "session_meta", "payload": {}},
|
|
6338
|
+
{"timestamp": "2026-10-18T09:50:21.766Z", "type": "response_item",
|
|
6339
|
+
"payload": {"type": "message", "role": "user", "content": [{"type": "input_text", "text": "Check the FIFO depth for the IECC lane."}]}},
|
|
6340
|
+
{"timestamp": "2026-10-18T09:50:23.621Z", "type": "response_item",
|
|
6341
|
+
"payload": {"type": "message", "role": "assistant", "content": [{"type": "output_text", "text": "ok"}]}},
|
|
6342
|
+
)) + "\n", encoding="utf-8")
|
|
6343
|
+
hook(c, "s2")
|
|
6344
|
+
found = history("verify", "--grep", "FIFO depth")
|
|
6345
|
+
if found.returncode != 0:
|
|
6346
|
+
report(f"{label} --grep for a phrase in a Codex rollout exited {found.returncode}: {found.stdout!r} {found.stderr!r}")
|
|
6347
|
+
return 1
|
|
6348
|
+
if "FIFO depth" not in found.stdout:
|
|
6349
|
+
report(f"{label} --grep does not print the phrase from a Codex rollout: {found.stdout!r}")
|
|
6350
|
+
return 1
|
|
6351
|
+
|
|
6352
|
+
# A transcript that grew after its copy is copied again.
|
|
6353
|
+
with b.open("a", encoding="utf-8") as handle:
|
|
6354
|
+
handle.write(json.dumps({"type": "assistant", "timestamp": "2026-10-12T02:00:00.000Z",
|
|
6355
|
+
"message": {"role": "assistant", "content": [{"type": "text", "text": "late line"}]}}) + "\n")
|
|
6356
|
+
d = claude_transcript("d", "Next shift.")
|
|
6357
|
+
hook(d, "s3")
|
|
6358
|
+
kept_b = kept_dir / "b.jsonl.gz"
|
|
6359
|
+
if not kept_b.is_file():
|
|
6360
|
+
report(f"{label} B ended and has no kept copy.")
|
|
6361
|
+
return 1
|
|
6362
|
+
if gzip.decompress(kept_b.read_bytes()) != b.read_bytes():
|
|
6363
|
+
report(f"{label} B's kept copy does not match B after it ended.")
|
|
6364
|
+
return 1
|
|
6365
|
+
with b.open("a", encoding="utf-8") as handle:
|
|
6366
|
+
handle.write("{}\n")
|
|
6367
|
+
e = claude_transcript("e", "Another shift.")
|
|
6368
|
+
hook(e, "s4")
|
|
6369
|
+
if gzip.decompress(kept_b.read_bytes()) != b.read_bytes():
|
|
6370
|
+
report(f"{label} B grew after its copy and was not copied again.")
|
|
6371
|
+
return 1
|
|
6372
|
+
report("shift-keeps-transcripts scenario passed.")
|
|
6373
|
+
return 0
|
|
6374
|
+
|
|
6375
|
+
|
|
6263
6376
|
def validate_shift_history_scenario() -> int:
|
|
6264
6377
|
"""Issue #304: a cleared shift's conversation stays findable.
|
|
6265
6378
|
|
|
@@ -23658,6 +23771,7 @@ if (failOn && args.join(" ").includes(failOn)) {
|
|
|
23658
23771
|
if (failed < failTimes) {
|
|
23659
23772
|
state.failed = { ...(state.failed || {}), [host]: failed + 1 };
|
|
23660
23773
|
save();
|
|
23774
|
+
process.stderr.write(`fake ${host}: warming up\nfake ${host}: refused ${args.join(" ")}\n`);
|
|
23661
23775
|
process.exit(1);
|
|
23662
23776
|
}
|
|
23663
23777
|
}
|
|
@@ -23934,6 +24048,97 @@ def validate_update_host_query_timeout_scenario() -> int:
|
|
|
23934
24048
|
return 0
|
|
23935
24049
|
|
|
23936
24050
|
|
|
24051
|
+
def validate_update_claude_refresh_retry_scenario() -> int:
|
|
24052
|
+
"""Issue #359: the Claude marketplace refresh failed once and passed on a direct retry.
|
|
24053
|
+
|
|
24054
|
+
`keel --update` retries `claude plugin marketplace update` once, as it does
|
|
24055
|
+
Codex's refresh, and a step that still fails names the host's last stderr
|
|
24056
|
+
line instead of only its exit status.
|
|
24057
|
+
"""
|
|
24058
|
+
label = "update-claude-refresh-retry:"
|
|
24059
|
+
refresh = ["claude", "plugin", "marketplace", "update", "keel-marketplace"]
|
|
24060
|
+
plugin_update = ["claude", "plugin", "update", "keel@keel-marketplace"]
|
|
24061
|
+
with tempfile.TemporaryDirectory(prefix="keel-update-359-", ignore_cleanup_errors=True) as raw:
|
|
24062
|
+
tmp = Path(raw)
|
|
24063
|
+
fake = tmp / "fake.js"
|
|
24064
|
+
write_text(fake, UPDATE_FAKE)
|
|
24065
|
+
launchers = {}
|
|
24066
|
+
for host in ("npm", "claude", "codex"):
|
|
24067
|
+
launcher = tmp / f"fake-{host}"
|
|
24068
|
+
write_text(launcher, f'#!/bin/sh\nFAKE_HOST={host} exec node "{fake}" "$@"\n')
|
|
24069
|
+
launcher.chmod(0o755)
|
|
24070
|
+
launchers[host] = launcher
|
|
24071
|
+
|
|
24072
|
+
def update(fail_on: str, times: str):
|
|
24073
|
+
log, state = tmp / "log.jsonl", tmp / "state.json"
|
|
24074
|
+
for stale in (log, state):
|
|
24075
|
+
if stale.exists():
|
|
24076
|
+
stale.unlink()
|
|
24077
|
+
log.write_text("")
|
|
24078
|
+
env = dict(os.environ)
|
|
24079
|
+
env.update({
|
|
24080
|
+
"KEEL_UPDATE_NPM": str(launchers["npm"]), "KEEL_UPDATE_CLAUDE": str(launchers["claude"]),
|
|
24081
|
+
"KEEL_UPDATE_CODEX": str(launchers["codex"]), "CODEX_HOME": str(tmp / "codex-home"),
|
|
24082
|
+
"FAKE_LOG": str(log), "FAKE_STATE": str(state), "FAKE_CODEX_SOURCE": str(tmp / "codex-source"),
|
|
24083
|
+
"FAKE_FAIL_CLAUDE": fail_on, "FAKE_FAIL_TIMES_CLAUDE": times,
|
|
24084
|
+
})
|
|
24085
|
+
env.pop("KEEL_UPDATE_SOURCE", None)
|
|
24086
|
+
result = subprocess.run(["node", str(ROOT / "bin/keel.js"), "--update"], cwd=tmp, env=env,
|
|
24087
|
+
text=True, capture_output=True, check=False, timeout=60)
|
|
24088
|
+
calls = [json.loads(line) for line in log.read_text().splitlines() if line.strip()]
|
|
24089
|
+
line = [l for l in result.stdout.splitlines() if l.startswith("keel update: claude plugin:")]
|
|
24090
|
+
return result, calls, (line[0] if len(line) == 1 else "")
|
|
24091
|
+
|
|
24092
|
+
result, calls, line = update("marketplace update", "1")
|
|
24093
|
+
runs = sum(1 for c in calls if c[:5] == refresh)
|
|
24094
|
+
if runs != 2:
|
|
24095
|
+
report(f"{label} the Claude marketplace update ran {runs} time(s) after one failure, not 2: {calls!r}")
|
|
24096
|
+
return 1
|
|
24097
|
+
if sum(1 for c in calls if c[:4] == plugin_update) != 1:
|
|
24098
|
+
report(f"{label} a refresh that succeeded on retry did not run plugin update once: {calls!r}")
|
|
24099
|
+
return 1
|
|
24100
|
+
if "5.0.0 -> 5.1.0" not in line:
|
|
24101
|
+
report(f"{label} a refresh that succeeded on retry did not report the new version: {line!r}")
|
|
24102
|
+
return 1
|
|
24103
|
+
if result.returncode != 0:
|
|
24104
|
+
report(f"{label} a refresh that succeeded on retry exited {result.returncode}: {result.stdout!r}")
|
|
24105
|
+
return 1
|
|
24106
|
+
|
|
24107
|
+
result, calls, line = update("marketplace update", "9")
|
|
24108
|
+
runs = sum(1 for c in calls if c[:5] == refresh)
|
|
24109
|
+
if runs != 2:
|
|
24110
|
+
report(f"{label} a lasting failure ran the marketplace update {runs} time(s), not 2: {calls!r}")
|
|
24111
|
+
return 1
|
|
24112
|
+
if any(c[:4] == plugin_update for c in calls):
|
|
24113
|
+
report(f"{label} a lasting refresh failure still ran plugin update: {calls!r}")
|
|
24114
|
+
return 1
|
|
24115
|
+
if result.returncode == 0:
|
|
24116
|
+
report(f"{label} a lasting refresh failure left the exit status 0: {result.stdout!r}")
|
|
24117
|
+
return 1
|
|
24118
|
+
for needle in ("failed", "failed twice", "fake claude: refused plugin marketplace update"):
|
|
24119
|
+
if needle not in line:
|
|
24120
|
+
report(f"{label} the failed Claude line does not name {needle!r}: {line!r}")
|
|
24121
|
+
return 1
|
|
24122
|
+
if "warming up" in line:
|
|
24123
|
+
report(f"{label} the failed Claude line carries more than the last stderr line: {line!r}")
|
|
24124
|
+
return 1
|
|
24125
|
+
|
|
24126
|
+
# A step with no retry still names the host's own error, not only its status.
|
|
24127
|
+
result, calls, line = update("plugin update keel", "9")
|
|
24128
|
+
if sum(1 for c in calls if c[:4] == plugin_update) != 1:
|
|
24129
|
+
report(f"{label} a failing plugin update was retried or skipped: {calls!r}")
|
|
24130
|
+
return 1
|
|
24131
|
+
for needle in ("failed", "exited 1", "fake claude: refused plugin update"):
|
|
24132
|
+
if needle not in line:
|
|
24133
|
+
report(f"{label} the failed plugin-update line does not name {needle!r}: {line!r}")
|
|
24134
|
+
return 1
|
|
24135
|
+
if "update-claude-refresh-retry" not in {name for name, _ in SCENARIOS}:
|
|
24136
|
+
report(f"{label} scenario is not registered.")
|
|
24137
|
+
return 1
|
|
24138
|
+
report("update-claude-refresh-retry scenario passed.")
|
|
24139
|
+
return 0
|
|
24140
|
+
|
|
24141
|
+
|
|
23937
24142
|
def validate_update_codex_refresh_retry_scenario() -> int:
|
|
23938
24143
|
"""Issue #329: a slow link can cut Codex's whole-repository marketplace clone.
|
|
23939
24144
|
|
|
@@ -41222,6 +41427,7 @@ SCENARIOS: tuple = (
|
|
|
41222
41427
|
("adopted-update-is-silent-unless-reload", validate_adopted_update_is_silent_unless_reload_scenario),
|
|
41223
41428
|
("update-covers-installed-hosts", validate_update_covers_installed_hosts_scenario),
|
|
41224
41429
|
("update-codex-refresh-retry", validate_update_codex_refresh_retry_scenario),
|
|
41430
|
+
("update-claude-refresh-retry", validate_update_claude_refresh_retry_scenario),
|
|
41225
41431
|
("update-host-query-timeout", validate_update_host_query_timeout_scenario),
|
|
41226
41432
|
("refresh-covers-every-target", validate_refresh_covers_every_target_scenario),
|
|
41227
41433
|
("directory-branch-advances", validate_directory_branch_advances_scenario),
|
|
@@ -41238,6 +41444,7 @@ SCENARIOS: tuple = (
|
|
|
41238
41444
|
("owner-language", validate_owner_language_scenario),
|
|
41239
41445
|
("owner-language-after-tools", validate_owner_language_after_tools_scenario),
|
|
41240
41446
|
("shift-history", validate_shift_history_scenario),
|
|
41447
|
+
("shift-keeps-transcripts", validate_shift_keeps_transcripts_scenario),
|
|
41241
41448
|
("role-drift", validate_role_drift_scenario),
|
|
41242
41449
|
("host-run-session", validate_host_run_session_scenario),
|
|
41243
41450
|
("shift-without-role", validate_shift_without_role_scenario),
|
package/src/core/chat/notice.js
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
const fs = require("fs");
|
|
17
17
|
const path = require("path");
|
|
18
|
+
const zlib = require("zlib");
|
|
18
19
|
const store = require("./store");
|
|
19
20
|
const { relativeAge } = require("./view");
|
|
20
21
|
|
|
@@ -257,6 +258,36 @@ function segmentsFile(where, role) {
|
|
|
257
258
|
return path.join(where.root, "shift", "segments", `${role}.json`);
|
|
258
259
|
}
|
|
259
260
|
|
|
261
|
+
// Where Keel keeps a copy of a role's ended transcript (#343). It stays on this
|
|
262
|
+
// machine: the chat archive syncs none of `shift/`.
|
|
263
|
+
function keptFile(where, role, transcript) {
|
|
264
|
+
return path.join(where.root, "shift", "transcripts", role, `${path.basename(transcript)}.gz`);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// Copies each ended segment's transcript that exists and has no up-to-date
|
|
268
|
+
// copy. The host deletes transcripts after its cleanup period (30 days by
|
|
269
|
+
// default for Claude), so the copy is what keeps a shift's conversation. The
|
|
270
|
+
// current segment is left alone: it is still being written.
|
|
271
|
+
function keepEnded(where, role, segments) {
|
|
272
|
+
for (const segment of segments) {
|
|
273
|
+
if (!segment.ended || !segment.transcript) continue;
|
|
274
|
+
try {
|
|
275
|
+
const source = fs.statSync(segment.transcript);
|
|
276
|
+
const target = keptFile(where, role, segment.transcript);
|
|
277
|
+
const kept = segment.kept_from;
|
|
278
|
+
if (fs.existsSync(target) && kept && kept.size === source.size && kept.mtime === source.mtimeMs) continue;
|
|
279
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
280
|
+
const temporary = `${target}.${process.pid}.tmp`;
|
|
281
|
+
fs.writeFileSync(temporary, zlib.gzipSync(fs.readFileSync(segment.transcript)));
|
|
282
|
+
fs.renameSync(temporary, target);
|
|
283
|
+
segment.kept = target;
|
|
284
|
+
segment.kept_from = { size: source.size, mtime: source.mtimeMs };
|
|
285
|
+
} catch {
|
|
286
|
+
// The host's file may already be gone; a copy is a convenience.
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
260
291
|
function recordSegment(where, role, transcript) {
|
|
261
292
|
if (typeof transcript !== "string" || !path.isAbsolute(transcript)) return;
|
|
262
293
|
try {
|
|
@@ -267,6 +298,7 @@ function recordSegment(where, role, transcript) {
|
|
|
267
298
|
const now = store.isoLocal(new Date());
|
|
268
299
|
if (last && !last.ended) last.ended = now;
|
|
269
300
|
segments.push({ transcript, started: now, ended: null });
|
|
301
|
+
keepEnded(where, role, segments);
|
|
270
302
|
store.writeJsonAtomic(where, file, { segments });
|
|
271
303
|
} catch {
|
|
272
304
|
// A convenience, like presence: never fail the hook.
|
package/src/core/shift.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
const fs = require("fs");
|
|
15
15
|
const os = require("os");
|
|
16
|
+
const zlib = require("zlib");
|
|
16
17
|
const path = require("path");
|
|
17
18
|
const { spawn, spawnSync } = require("child_process");
|
|
18
19
|
const store = require("./chat/store");
|
|
@@ -649,6 +650,27 @@ function status(where) {
|
|
|
649
650
|
|
|
650
651
|
// --- history (#304 D3, D4) -------------------------------------------------------
|
|
651
652
|
|
|
653
|
+
// The speaker and text of a conversation record: Claude's `{type, message}`,
|
|
654
|
+
// or a Codex rollout's `{type: "response_item", payload: {type: "message"}}`
|
|
655
|
+
// (#343). Anything else is not conversation.
|
|
656
|
+
function conversationLine(record) {
|
|
657
|
+
if (!record) return null;
|
|
658
|
+
if (record.type === "user" || record.type === "assistant") return { speaker: record.type, text: transcriptText(record) };
|
|
659
|
+
const payload = record.type === "response_item" ? record.payload : null;
|
|
660
|
+
if (payload && payload.type === "message" && (payload.role === "user" || payload.role === "assistant")) {
|
|
661
|
+
const parts = Array.isArray(payload.content) ? payload.content : [];
|
|
662
|
+
const text = parts.filter((part) => part && typeof part.text === "string").map((part) => part.text).join("\n");
|
|
663
|
+
return { speaker: payload.role, text };
|
|
664
|
+
}
|
|
665
|
+
return null;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
// A transcript's text, from the host's file or Keel's gzip copy of it.
|
|
669
|
+
function readTranscript(file) {
|
|
670
|
+
const bytes = fs.readFileSync(file);
|
|
671
|
+
return (file.endsWith(".gz") ? zlib.gunzipSync(bytes) : bytes).toString("utf8");
|
|
672
|
+
}
|
|
673
|
+
|
|
652
674
|
function transcriptText(record) {
|
|
653
675
|
const content = record && record.message ? record.message.content : null;
|
|
654
676
|
if (typeof content === "string") return content;
|
|
@@ -659,7 +681,7 @@ function transcriptText(record) {
|
|
|
659
681
|
function grepTranscript(file, needle, limit = 3) {
|
|
660
682
|
const hits = [];
|
|
661
683
|
const lower = needle.toLowerCase();
|
|
662
|
-
for (const line of
|
|
684
|
+
for (const line of readTranscript(file).split("\n")) {
|
|
663
685
|
if (!line.trim()) continue;
|
|
664
686
|
let record;
|
|
665
687
|
try {
|
|
@@ -667,13 +689,14 @@ function grepTranscript(file, needle, limit = 3) {
|
|
|
667
689
|
} catch {
|
|
668
690
|
continue;
|
|
669
691
|
}
|
|
670
|
-
|
|
671
|
-
|
|
692
|
+
const said = conversationLine(record);
|
|
693
|
+
if (!said) continue;
|
|
694
|
+
const text = said.text;
|
|
672
695
|
const at = text.toLowerCase().indexOf(lower);
|
|
673
696
|
if (at < 0) continue;
|
|
674
697
|
const from = Math.max(0, at - 60);
|
|
675
698
|
const snippet = text.slice(from, at + needle.length + 60).replace(/\s+/g, " ");
|
|
676
|
-
const hit = { timestamp: record.timestamp || null, speaker:
|
|
699
|
+
const hit = { timestamp: record.timestamp || null, speaker: said.speaker, snippet: `${from ? "…" : ""}${snippet}…` };
|
|
677
700
|
// A transcript can hold the same message twice; report it once.
|
|
678
701
|
if (hits.some((seen) => seen.timestamp === hit.timestamp && seen.snippet === hit.snippet)) continue;
|
|
679
702
|
hits.push(hit);
|
|
@@ -734,12 +757,19 @@ function history(where, named, grep) {
|
|
|
734
757
|
const segments = [...recorded.slice().reverse(), ...earlier]
|
|
735
758
|
.filter((segment) => !seen.has(segment.transcript) && seen.add(segment.transcript))
|
|
736
759
|
.sort((a, b) => Date.parse(b.started) - Date.parse(a.started))
|
|
737
|
-
.map((segment) => ({
|
|
760
|
+
.map((segment) => ({
|
|
761
|
+
...segment,
|
|
762
|
+
exists: fs.existsSync(segment.transcript),
|
|
763
|
+
kept: segment.kept && fs.existsSync(segment.kept) ? segment.kept : null,
|
|
764
|
+
}));
|
|
738
765
|
const notes = safeList(path.join(shiftDir(where), "history"))
|
|
739
766
|
.filter((name) => name.startsWith(`${role}-`) && name.endsWith(".md"))
|
|
740
767
|
.sort().reverse().map((name) => path.join(shiftDir(where), "history", name));
|
|
741
768
|
if (grep) {
|
|
742
|
-
for (const segment of segments)
|
|
769
|
+
for (const segment of segments) {
|
|
770
|
+
const source = segment.exists ? segment.transcript : segment.kept;
|
|
771
|
+
segment.matches = source ? grepTranscript(source, grep) : [];
|
|
772
|
+
}
|
|
743
773
|
}
|
|
744
774
|
return { role, segments, notes };
|
|
745
775
|
}
|
|
@@ -748,7 +778,7 @@ function renderHistory(result, grep) {
|
|
|
748
778
|
const lines = [];
|
|
749
779
|
for (const segment of result.segments) {
|
|
750
780
|
if (grep && !segment.matches.length) continue;
|
|
751
|
-
lines.push(`${segment.started} → ${segment.ended || "now"} ${segment.transcript}${segment.found ? " (found)" : ""}${segment.exists ? "" : " (missing)"}`);
|
|
781
|
+
lines.push(`${segment.started} → ${segment.ended || "now"} ${segment.transcript}${segment.found ? " (found)" : ""}${segment.exists ? "" : segment.kept ? " (kept)" : " (missing)"}`);
|
|
752
782
|
for (const hit of segment.matches || []) lines.push(` ${hit.timestamp || "?"} ${hit.speaker}: ${hit.snippet}`);
|
|
753
783
|
}
|
|
754
784
|
if (!grep) for (const note of result.notes) lines.push(`note ${note}`);
|