@christang/keel 5.94.1 → 5.95.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- <!-- keel:start version=5.94.1 -->
1
+ <!-- keel:start version=5.95.1 -->
2
2
  ## Keel Bootstrap
3
3
 
4
4
  - Start every session with `keel context`; OpenSpec artifacts and Git are the only durable authority — never native memory, goals, or transcripts.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@christang/keel",
3
- "version": "5.94.1",
3
+ "version": "5.95.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@christang/keel",
9
- "version": "5.94.1",
9
+ "version": "5.95.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@fission-ai/openspec": "^1.4.1"
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@christang/keel",
3
3
  "displayName": "Keel",
4
4
  "description": "Keel OpenSpec execution discipline CLI for Claude Code, Codex, and OpenCode.",
5
- "version": "5.94.1",
5
+ "version": "5.95.1",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keel",
3
- "version": "5.94.1",
3
+ "version": "5.95.1",
4
4
  "description": "Keel OpenSpec execution discipline: stateless continuity, task capsules, deterministic gates, and expectation alignment for Codex and Claude Code.",
5
5
  "author": {
6
6
  "name": "TanglmChris",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keel",
3
- "version": "5.94.1",
3
+ "version": "5.95.1",
4
4
  "description": "Keel OpenSpec execution discipline: stateless continuity, task capsules, deterministic gates, and expectation alignment for Codex and Claude Code.",
5
5
  "author": {
6
6
  "name": "TanglmChris",
@@ -47,8 +47,8 @@ REQUIRED_SCRIPTS = [
47
47
  "scripts/validate_plugin.py",
48
48
  ]
49
49
 
50
- PACKAGE_VERSION = "5.94.1"
51
- PROTOCOL_VERSION = "5.94.1"
50
+ PACKAGE_VERSION = "5.95.1"
51
+ PROTOCOL_VERSION = "5.95.1"
52
52
  LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
53
53
  OPENSPEC_SCHEMA_NAME = "keel-spec-driven"
54
54
  # Mirrors KEEL_PACKAGE_NAME in scripts/install_to_repo.py, one of the two
@@ -3792,6 +3792,76 @@ def validate_chat_shared_bots_scenario() -> int:
3792
3792
  return 0
3793
3793
 
3794
3794
 
3795
+ def validate_chat_slack_format_scenario() -> int:
3796
+ """Issue #187: Markdown shows as formatting in Slack, and back.
3797
+
3798
+ A record's Markdown is posted as Slack mrkdwn — bold, italic, headings,
3799
+ bullets, links, escaped `&<>` — with code left alone and the local record
3800
+ unchanged; a person's mrkdwn arrives in the store as Markdown; and the
3801
+ setup guides tell sessions they may format with Markdown.
3802
+ """
3803
+ label = "chat-slack-format:"
3804
+ if chat_bridge_node_missing("chat-slack-format"):
3805
+ return 3
3806
+ FakeSlack = fake_slack_class()
3807
+ with tempfile.TemporaryDirectory(prefix="keel-chat-format-") as raw, FakeSlack() as slack:
3808
+ base = Path(raw)
3809
+ rtl, _verify, env = chat_scratch_group(base)
3810
+ chat_slack_config(rtl, {"soc": "CSOC"})
3811
+ benv = chat_bridge_environment(env, base / "home", slack)
3812
+ run_keel(rtl, "chat", "bridge", "add", env=benv)
3813
+ body = "# Plan\n**must** land *soon*\n- item\nsee [spec](https://example.com/s) and `a**b`\n```\n**raw**\n```\nx<y&z\n这是**重点**内容"
3814
+ record_id = chat_json(run_keel(rtl, "chat", "post", "soc", body, "--json", env=benv)).get("id", "")
3815
+ once = run_keel(rtl, "chat", "bridge", "run", "--once", env=benv)
3816
+ if once.returncode != 0:
3817
+ report(f"{label} bridge run --once failed: {once.stderr.strip()}")
3818
+ return 1
3819
+ sent = next((c["params"].get("text", "") for c in slack.calls_to("chat.postMessage") if slack_payload(c).get("id") == record_id), None)
3820
+ if sent is None:
3821
+ report(f"{label} the record was never posted.")
3822
+ return 1
3823
+ for needle in ("*Plan*", "*must*", "_soon_", "• item", "<https://example.com/s|spec>", "`a**b`", "```\n**raw**\n```", "x&lt;y&amp;z"):
3824
+ if needle not in sent:
3825
+ report(f"{label} the posted text lacks {needle!r}: {sent!r}")
3826
+ return 1
3827
+ # Slack needs a boundary beside a marker, and CJK text is not one.
3828
+ if "这是\u200b*重点*\u200b内容" not in sent:
3829
+ report(f"{label} bold beside CJK text carries no zero-width boundary: {sent!r}")
3830
+ return 1
3831
+ if "**must**" in sent:
3832
+ report(f"{label} Markdown bold reached Slack untranslated: {sent!r}")
3833
+ return 1
3834
+ if body not in (chat_log(rtl, "soc") / f"{record_id}.md").read_text(encoding="utf-8"):
3835
+ report(f"{label} translation changed the local record.")
3836
+ return 1
3837
+
3838
+ bridge = start_chat_bridge(rtl, benv)
3839
+ try:
3840
+ if not slack.wait_for(lambda: slack.sockets, 10):
3841
+ report(f"{label} the bridge never connected: {stop_chat_bridge(bridge).strip()}")
3842
+ return 1
3843
+ slack.push(slack_event("CSOC", user="UOWNER", text="*urgent* _today_ ~old~ see <https://example.com|this> a &lt; b", ts="1800000001.000100"))
3844
+ if not slack.wait_for(lambda: chat_records_with(rtl, "soc", "today")):
3845
+ report(f"{label} the owner's formatted message was not imported.")
3846
+ return 1
3847
+ stored = chat_records_with(rtl, "soc", "today")[0]
3848
+ if "**urgent** *today* ~~old~~ see [this](https://example.com) a < b" not in stored:
3849
+ report(f"{label} the owner's mrkdwn was not stored as Markdown:\n{stored}")
3850
+ return 1
3851
+ finally:
3852
+ stop_chat_bridge(bridge)
3853
+
3854
+ for relative, needle in (("docs/chat-slack-setup.md", "format with ordinary Markdown"), ("docs/chat-slack-setup.zh-CN.md", "用普通的 Markdown")):
3855
+ if needle not in (ROOT / relative).read_text(encoding="utf-8"):
3856
+ report(f"{label} {relative} does not say {needle!r}.")
3857
+ return 1
3858
+ if "chat-slack-format" not in {name for name, _ in SCENARIOS}:
3859
+ report(f"{label} scenario is not registered.")
3860
+ return 1
3861
+ report("chat-slack-format scenario passed.")
3862
+ return 0
3863
+
3864
+
3795
3865
  def validate_chat_role_apps_are_documented_scenario() -> int:
3796
3866
  """Issue #187: the setup guides and READMEs describe shared bots.
3797
3867
 
@@ -36195,6 +36265,10 @@ SCENARIOS: tuple = (
36195
36265
  "chat-shared-bots",
36196
36266
  validate_chat_shared_bots_scenario,
36197
36267
  ),
36268
+ (
36269
+ "chat-slack-format",
36270
+ validate_chat_slack_format_scenario,
36271
+ ),
36198
36272
  (
36199
36273
  "chat-archive",
36200
36274
  validate_chat_archive_scenario,
@@ -20,6 +20,7 @@ const path = require("path");
20
20
  const store = require("./store");
21
21
  const { slackSettings } = require("./config");
22
22
  const { redact } = require("./redact");
23
+ const mrkdwn = require("./mrkdwn");
23
24
  const slack = require("./slack");
24
25
  const lifecycle = require("./lifecycle");
25
26
 
@@ -167,10 +168,11 @@ function bodyText(record) {
167
168
  }
168
169
  }
169
170
 
170
- // Redact, then cut, then address: the cut must not split a `[redacted]`, and
171
- // the owner mention must survive the cut.
171
+ // Redact, translate, cut, then address: the cut must not split a
172
+ // `[redacted]`, and neither the cut pointer nor the owner mention is Markdown
173
+ // to translate (chat-slack-format D1).
172
174
  function slackText(project, record, text) {
173
- let result = redact(text);
175
+ let result = mrkdwn.toSlack(redact(text));
174
176
  if (result.length > TEXT_LIMIT) {
175
177
  result = `${result.slice(0, TEXT_LIMIT)}… (cut; full text: \`keel chat show ${record.id}\`)`;
176
178
  }
@@ -395,7 +397,7 @@ function unwrapText(project, text, kind) {
395
397
  if (project.settings.owner) result = result.replace(new RegExp(`^<@${project.settings.owner}> `), "");
396
398
  result = result.replace(/^↳ reply to \S+\n/, "");
397
399
  if (kind === "todo") result = result.replace(/^☐ todo → [^:]*: /, "");
398
- return result;
400
+ return mrkdwn.fromSlack(result);
399
401
  }
400
402
 
401
403
  function importKeelRecord(ctx, project, channel, payload, message) {
@@ -473,6 +475,7 @@ function humanText(project, event) {
473
475
  const role = project.settings.members[user] || project.settings.bots[user];
474
476
  return role ? `@${role}` : match;
475
477
  });
478
+ text = mrkdwn.fromSlack(text);
476
479
  for (const file of event.files || []) {
477
480
  const link = file.permalink || file.url_private || "";
478
481
  text += `${text ? "\n" : ""}📎 ${file.name || file.title || "file"}${link ? `: ${link}` : ""}`;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ // Formatting between the store's Markdown and Slack's mrkdwn (issue #187,
4
+ // chat-slack-format D2, D3). Sessions write Markdown; Slack renders its own
5
+ // dialect, so the bridge translates on the way out and back on the way in.
6
+ // Code spans and fenced blocks are escaped but otherwise left alone in both
7
+ // directions. The round trip keeps meaning, not the exact markers: a heading
8
+ // comes back as a bold line and a bullet as a `•` line.
9
+
10
+ const FENCE = /```[\s\S]*?```/g;
11
+ const SPAN = /`[^`\n]*`/g;
12
+ // A placeholder for a bold marker, so a later italic pass cannot read it.
13
+ const BOLD = "\u0001";
14
+ // Slack renders `*x*` only between word boundaries, and CJK text or
15
+ // full-width punctuation right beside a marker is not one: a zero-width space
16
+ // on each side of every marker pair supplies the boundary, checked against
17
+ // real Slack on 2026-10-05 (#187). Inbound text drops them again.
18
+ const ZWSP = "\u200b";
19
+
20
+ // Calls `prose` on the text outside code and `code` on the code itself.
21
+ function byCode(text, prose, code) {
22
+ const outside = (part) => {
23
+ let result = "";
24
+ let last = 0;
25
+ for (const match of part.matchAll(SPAN)) {
26
+ result += prose(part.slice(last, match.index)) + code(match[0]);
27
+ last = match.index + match[0].length;
28
+ }
29
+ return result + prose(part.slice(last));
30
+ };
31
+ let result = "";
32
+ let last = 0;
33
+ for (const match of text.matchAll(FENCE)) {
34
+ result += outside(text.slice(last, match.index)) + code(match[0]);
35
+ last = match.index + match[0].length;
36
+ }
37
+ return result + outside(text.slice(last));
38
+ }
39
+
40
+ function escape(text) {
41
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
42
+ }
43
+
44
+ function unescape(text) {
45
+ return text.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
46
+ }
47
+
48
+ function proseToSlack(text) {
49
+ return escape(text)
50
+ .replace(/\[([^\]\n]+)\]\((https?:\/\/[^)\s]+|mailto:[^)\s]+)\)/g, (match, label, url) => `<${url}|${label}>`)
51
+ .replace(/^(\s*)[-*+][ \t]+/gm, "$1• ")
52
+ .replace(/^#{1,6}[ \t]+(.+?)[ \t]*#*[ \t]*$/gm, `${BOLD}$1${BOLD}`)
53
+ .replace(/\*\*(?!\s)([^\n]+?)\*\*/g, `${BOLD}$1${BOLD}`)
54
+ .replace(/__(?!\s)([^\n]+?)__/g, `${BOLD}$1${BOLD}`)
55
+ .replace(/(^|[^\w*])\*(?![\s*])([^*\n]+?)\*(?![\w*])/g, `$1${ZWSP}_$2_${ZWSP}`)
56
+ .replace(/~~(?!\s)([^\n]+?)~~/g, `${ZWSP}~$1~${ZWSP}`)
57
+ .replace(new RegExp(`${BOLD}([^${BOLD}]+)${BOLD}`, "g"), `${ZWSP}*$1*${ZWSP}`);
58
+ }
59
+
60
+ function proseFromSlack(text) {
61
+ return unescape(text.split(ZWSP).join("")
62
+ .replace(/<((?:https?:\/\/|mailto:)[^|>\s]+)\|([^>]+)>/g, "[$2]($1)")
63
+ .replace(/<((?:https?:\/\/|mailto:)[^|>\s]+)>/g, "$1")
64
+ .replace(/(^|[^\w*])\*(?![\s*])([^*\n]+?)\*(?![\w*])/g, `$1${BOLD}${BOLD}$2${BOLD}${BOLD}`)
65
+ .replace(/(^|[^\w_])_(?![\s_])([^_\n]+?)_(?![\w_])/g, "$1*$2*")
66
+ .replace(/(^|[^\w~])~(?![\s~])([^~\n]+?)~(?![\w~])/g, "$1~~$2~~")
67
+ .split(BOLD).join("*"));
68
+ }
69
+
70
+ function toSlack(text) {
71
+ return byCode(String(text || ""), proseToSlack, escape);
72
+ }
73
+
74
+ function fromSlack(text) {
75
+ return byCode(String(text || ""), proseFromSlack, unescape);
76
+ }
77
+
78
+ module.exports = { fromSlack, toSlack };