@christang/keel 5.140.0 → 5.142.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.
@@ -0,0 +1,141 @@
1
+ {
2
+ "name": "keel",
3
+ "version": "5.142.0",
4
+ "description": "Keel OpenSpec execution discipline: stateless continuity, task capsules, deterministic gates, and expectation alignment for Codex and Claude Code.",
5
+ "author": {
6
+ "name": "TanglmChris",
7
+ "url": "https://github.com/TanglmChris"
8
+ },
9
+ "repository": "https://github.com/TanglmChris/keel",
10
+ "license": "MIT",
11
+ "keywords": [
12
+ "openspec",
13
+ "workflow",
14
+ "keel",
15
+ "discipline"
16
+ ],
17
+ "skills": [
18
+ "./plugins/keel/skills/"
19
+ ],
20
+ "agents": [
21
+ "./plugins/keel/agents/keel-single-task-goal-claude.md"
22
+ ],
23
+ "hooks": {
24
+ "SessionStart": [
25
+ {
26
+ "hooks": [
27
+ {
28
+ "type": "command",
29
+ "command": "node",
30
+ "args": [
31
+ "${CLAUDE_PLUGIN_ROOT}/plugins/keel/scripts/session-start.js"
32
+ ],
33
+ "timeout": 15
34
+ }
35
+ ]
36
+ },
37
+ {
38
+ "hooks": [
39
+ {
40
+ "type": "command",
41
+ "command": "node",
42
+ "args": [
43
+ "${CLAUDE_PLUGIN_ROOT}/plugins/keel/scripts/mail-hook.js",
44
+ "session-start"
45
+ ],
46
+ "timeout": 10
47
+ }
48
+ ]
49
+ }
50
+ ],
51
+ "PreToolUse": [
52
+ {
53
+ "matcher": "Edit|Write|NotebookEdit",
54
+ "hooks": [
55
+ {
56
+ "type": "command",
57
+ "command": "node",
58
+ "args": [
59
+ "${CLAUDE_PLUGIN_ROOT}/plugins/keel/scripts/pretooluse-guard.js"
60
+ ],
61
+ "timeout": 10
62
+ }
63
+ ]
64
+ },
65
+ {
66
+ "matcher": "Bash",
67
+ "hooks": [
68
+ {
69
+ "type": "command",
70
+ "command": "node",
71
+ "args": [
72
+ "${CLAUDE_PLUGIN_ROOT}/plugins/keel/scripts/pretooluse-guard.js"
73
+ ],
74
+ "timeout": 10
75
+ }
76
+ ]
77
+ }
78
+ ],
79
+ "UserPromptSubmit": [
80
+ {
81
+ "hooks": [
82
+ {
83
+ "type": "command",
84
+ "command": "node",
85
+ "args": [
86
+ "${CLAUDE_PLUGIN_ROOT}/plugins/keel/scripts/mail-hook.js",
87
+ "user-prompt-submit"
88
+ ],
89
+ "timeout": 10
90
+ }
91
+ ]
92
+ }
93
+ ],
94
+ "PostToolUse": [
95
+ {
96
+ "hooks": [
97
+ {
98
+ "type": "command",
99
+ "command": "node",
100
+ "args": [
101
+ "${CLAUDE_PLUGIN_ROOT}/plugins/keel/scripts/mail-hook.js",
102
+ "post-tool-use"
103
+ ],
104
+ "timeout": 10
105
+ }
106
+ ]
107
+ }
108
+ ],
109
+ "FileChanged": [
110
+ {
111
+ "hooks": [
112
+ {
113
+ "type": "command",
114
+ "command": "node",
115
+ "args": [
116
+ "${CLAUDE_PLUGIN_ROOT}/plugins/keel/scripts/mail-hook.js",
117
+ "file-changed"
118
+ ],
119
+ "timeout": 10,
120
+ "asyncRewake": true
121
+ }
122
+ ]
123
+ }
124
+ ],
125
+ "SessionEnd": [
126
+ {
127
+ "hooks": [
128
+ {
129
+ "type": "command",
130
+ "command": "node",
131
+ "args": [
132
+ "${CLAUDE_PLUGIN_ROOT}/plugins/keel/scripts/mail-hook.js",
133
+ "session-end"
134
+ ],
135
+ "timeout": 10
136
+ }
137
+ ]
138
+ }
139
+ ]
140
+ }
141
+ }
package/README.md CHANGED
@@ -47,16 +47,40 @@ Node.js `>=20.19.0` (the bundled OpenSpec CLI needs it).
47
47
 
48
48
  ## Install
49
49
 
50
- **Claude Code** — the plugin is the whole install. It is this repository at the release's tag,
51
- the same tree npm publishes as `@christang/keel`, so it carries the `keel` CLI along with the
50
+ **Claude Code** — the plugin is the whole install. It is the npm package `@christang/keel` at the
51
+ release version, the same package the `keel` CLI comes from, so it carries the CLI along with the
52
52
  skills and hooks, and Claude installs the pinned OpenSpec from its lockfile when it installs the
53
- plugin. The agent's `keel` commands run the copy the plugin brought:
53
+ plugin (#337). The agent's `keel` commands run the copy the plugin brought:
54
54
 
55
55
  ```bash
56
56
  claude plugin marketplace add TanglmChris/keel
57
57
  claude plugin install keel@keel-marketplace
58
58
  ```
59
59
 
60
+ The plugin is fetched with your npm client; only the marketplace catalog,
61
+ `.claude-plugin/marketplace.json`, is read from GitHub. If cloning GitHub fails on a machine — an SSH
62
+ host key, a proxy — read the catalog over HTTPS instead, with a `url` marketplace source:
63
+
64
+ ```bash
65
+ claude plugin marketplace add https://raw.githubusercontent.com/TanglmChris/keel/main/.claude-plugin/marketplace.json
66
+ ```
67
+
68
+ or, declared in `~/.claude/settings.json`:
69
+
70
+ ```json
71
+ "extraKnownMarketplaces": {
72
+ "keel-marketplace": {
73
+ "source": {
74
+ "source": "url",
75
+ "url": "https://raw.githubusercontent.com/TanglmChris/keel/main/.claude-plugin/marketplace.json"
76
+ }
77
+ }
78
+ }
79
+ ```
80
+
81
+ Claude Code does not yet load a marketplace from an npm package (its reference lists that source as
82
+ not implemented), so the catalog cannot come from npm too.
83
+
60
84
  Updates arrive by themselves once a project is set up: `keel --init --target claude` (and
61
85
  `keel --install`) declares auto-update for `keel-marketplace` in the project's
62
86
  `.claude/settings.json`, which Claude reads before its own default of off. A new release is fetched
package/README.zh-CN.md CHANGED
@@ -38,8 +38,8 @@ Node.js `>=20.19.0`(内置的 OpenSpec CLI 需要)。
38
38
 
39
39
  ## 安装
40
40
 
41
- **Claude Code** —— 装插件就够了。插件就是本仓库在发布 tag 上的那棵树,和 npm 发布的 `@christang/keel`
42
- 是同一份,技能和 hook 之外还带着 `keel` CLI;安装插件时 Claude 会按锁文件装好锁定版本的 OpenSpec。
41
+ **Claude Code** —— 装插件就够了。插件就是发布版本的 npm 包 `@christang/keel`,和 `keel` CLI 来自同一个包,
42
+ 技能和 hook 之外还带着 `keel` CLI;安装插件时 Claude 会按锁文件装好锁定版本的 OpenSpec(#337)。
43
43
  agent 运行的 `keel` 就是插件带来的这一份:
44
44
 
45
45
  ```bash
@@ -47,6 +47,28 @@ claude plugin marketplace add TanglmChris/keel
47
47
  claude plugin install keel@keel-marketplace
48
48
  ```
49
49
 
50
+ 插件用你的 npm 客户端获取;只有 marketplace 清单 `.claude-plugin/marketplace.json` 从 GitHub 读取。
51
+ 如果某台机器 clone GitHub 失败(SSH host key、代理等),可以改为用 `url` 来源、通过 HTTPS 读取清单:
52
+
53
+ ```bash
54
+ claude plugin marketplace add https://raw.githubusercontent.com/TanglmChris/keel/main/.claude-plugin/marketplace.json
55
+ ```
56
+
57
+ 或者在 `~/.claude/settings.json` 里声明:
58
+
59
+ ```json
60
+ "extraKnownMarketplaces": {
61
+ "keel-marketplace": {
62
+ "source": {
63
+ "source": "url",
64
+ "url": "https://raw.githubusercontent.com/TanglmChris/keel/main/.claude-plugin/marketplace.json"
65
+ }
66
+ }
67
+ }
68
+ ```
69
+
70
+ Claude Code 目前还不支持从 npm 包加载 marketplace(其参考文档把这种来源列为尚未实现),所以清单本身还不能也从 npm 来。
71
+
50
72
  项目初始化后,更新会自己到来:`keel --init --target claude`(以及 `keel --install`)会在项目的
51
73
  `.claude/settings.json` 里为 `keel-marketplace` 声明自动更新,Claude 先读这个声明,而不是它默认的"关闭"。
52
74
  新版本会在会话发出第一条消息后在后台下载。从 5.89.0 起,正在运行的会话在下一次 hook 调用时就用上新版;
@@ -1,4 +1,4 @@
1
- <!-- keel:start version=5.140.0 -->
1
+ <!-- keel:start version=5.142.0 -->
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.
package/bin/keel.js CHANGED
@@ -1013,13 +1013,34 @@ function hostRun(executable, args) {
1013
1013
  });
1014
1014
  }
1015
1015
 
1016
- function hostJson(executable, args) {
1017
- const result = hostRun(executable, args);
1018
- if (result.error || result.status !== 0) return null;
1016
+ // A read-only `plugin list --json` normally answers in 1–3 s, and once hung
1017
+ // for minutes through a proxy (#354). It gets its own short limit, and a query
1018
+ // that fails is reported as one, never as a host with no Keel.
1019
+ function hostQuery(executable, args) {
1020
+ const limit = Number(process.env.KEEL_UPDATE_QUERY_TIMEOUT_MS) || 30 * 1000;
1021
+ const result = spawnSync(executable, args, {
1022
+ encoding: "utf8",
1023
+ shell: process.platform === "win32",
1024
+ timeout: limit,
1025
+ });
1026
+ if (result.error && result.error.code === "ENOENT") return { absent: true };
1027
+ if (result.error && result.error.code === "ETIMEDOUT") {
1028
+ return { failed: `timed out after ${limit / 1000} s` };
1029
+ }
1030
+ if (result.error) return { failed: result.error.message };
1031
+ // On Windows the call goes through cmd.exe, which reports a missing command
1032
+ // as a nonzero exit rather than ENOENT.
1033
+ if (
1034
+ result.status !== 0 && process.platform === "win32"
1035
+ && /is not recognized as an internal or external command/i.test(result.stderr || "")
1036
+ ) {
1037
+ return { absent: true };
1038
+ }
1039
+ if (result.status !== 0) return { failed: `exited ${result.status}` };
1019
1040
  try {
1020
- return JSON.parse(result.stdout);
1041
+ return { json: JSON.parse(result.stdout) };
1021
1042
  } catch {
1022
- return null;
1043
+ return { failed: "printed no JSON" };
1023
1044
  }
1024
1045
  }
1025
1046
 
@@ -1027,8 +1048,12 @@ function hostJson(executable, args) {
1027
1048
  // host is absent or has none. Both hosts answer `plugin list --json`, in
1028
1049
  // different shapes (2026-10-03: Claude a list of {id, version, installPath},
1029
1050
  // Codex {installed: [{pluginId, version, marketplaceSource, source}]}).
1051
+ // Each returns the Keel entry, null for a host with none, or { failed } when
1052
+ // the query itself failed.
1030
1053
  function claudeKeel(executable) {
1031
- const listed = hostJson(executable, ["plugin", "list", "--json"]);
1054
+ const queried = hostQuery(executable, ["plugin", "list", "--json"]);
1055
+ if (queried.failed) return { failed: `\`claude plugin list --json\` ${queried.failed}` };
1056
+ const listed = queried.json;
1032
1057
  const entry = (Array.isArray(listed) ? listed : [])
1033
1058
  .find((item) => item && typeof item.id === "string" && item.id.startsWith("keel@"));
1034
1059
  if (!entry) return null;
@@ -1042,7 +1067,9 @@ const CODEX_SPARSE_PATHS = [".agents/plugins", "plugins/keel"];
1042
1067
  const CODEX_SPARSE_FLAGS = CODEX_SPARSE_PATHS.map((entry) => `--sparse ${entry}`).join(" ");
1043
1068
 
1044
1069
  function codexKeel(executable) {
1045
- const listed = hostJson(executable, ["plugin", "list", "--json"]);
1070
+ const queried = hostQuery(executable, ["plugin", "list", "--json"]);
1071
+ if (queried.failed) return { failed: `\`codex plugin list --json\` ${queried.failed}` };
1072
+ const listed = queried.json;
1046
1073
  const items = listed && Array.isArray(listed.installed) ? listed.installed : [];
1047
1074
  const entry = items.find((item) => item && item.name === "keel" && item.installed !== false);
1048
1075
  if (!entry) return null;
@@ -1089,7 +1116,8 @@ function versionChange(before, after) {
1089
1116
  function updateClaudePlugin(options) {
1090
1117
  const component = "claude plugin";
1091
1118
  const executable = process.env.KEEL_UPDATE_CLAUDE || "claude";
1092
- const installed = claudeKeel(executable);
1119
+ const queried = claudeKeel(executable);
1120
+ const installed = queried && !queried.failed ? queried : null;
1093
1121
  const id = installed ? installed.id : "keel@keel-marketplace";
1094
1122
  const market = installed ? installed.market : "keel-marketplace";
1095
1123
  const steps = [["plugin", "marketplace", "update", market], ["plugin", "update", id]];
@@ -1097,12 +1125,20 @@ function updateClaudePlugin(options) {
1097
1125
  for (const args of steps) process.stdout.write(`keel: would run claude ${args.join(" ")}\n`);
1098
1126
  return true;
1099
1127
  }
1128
+ if (queried && queried.failed) {
1129
+ updateLine(component, "failed", queried.failed);
1130
+ return false;
1131
+ }
1100
1132
  if (!installed) {
1101
1133
  updateLine(component, "absent", "Claude Code is not installed here or has no Keel plugin");
1102
1134
  return true;
1103
1135
  }
1104
1136
  if (!runHostSteps(component, "claude", executable, steps)) return false;
1105
1137
  const after = claudeKeel(executable);
1138
+ if (after && after.failed) {
1139
+ updateLine(component, "failed", `${after.failed} after the update, so its result is unverified`);
1140
+ return false;
1141
+ }
1106
1142
  updateLine(
1107
1143
  component,
1108
1144
  versionChange(installed.version, after && after.version),
@@ -1114,7 +1150,8 @@ function updateClaudePlugin(options) {
1114
1150
  function updateCodexPlugin(options) {
1115
1151
  const component = "codex plugin";
1116
1152
  const executable = process.env.KEEL_UPDATE_CODEX || "codex";
1117
- const installed = codexKeel(executable);
1153
+ const queried = codexKeel(executable);
1154
+ const installed = queried && !queried.failed ? queried : null;
1118
1155
  const id = installed ? installed.id : "keel@keel-marketplace";
1119
1156
  const market = installed ? installed.market : "keel-marketplace";
1120
1157
  const steps = [["plugin", "marketplace", "upgrade", market], ["plugin", "add", id]];
@@ -1122,6 +1159,10 @@ function updateCodexPlugin(options) {
1122
1159
  for (const args of steps) process.stdout.write(`keel: would run codex ${args.join(" ")}\n`);
1123
1160
  return true;
1124
1161
  }
1162
+ if (queried && queried.failed) {
1163
+ updateLine(component, "failed", queried.failed);
1164
+ return false;
1165
+ }
1125
1166
  if (!installed) {
1126
1167
  updateLine(component, "absent", "Codex is not installed here or has no Keel plugin");
1127
1168
  return true;
@@ -1159,10 +1200,18 @@ function updateCodexPlugin(options) {
1159
1200
  ? readOrNull(path.join(codexHome, "plugins", "cache", market, "keel", installed.version, "hooks", "codex.json"))
1160
1201
  : null;
1161
1202
  const upgraded = codexKeel(executable);
1203
+ if (upgraded && upgraded.failed) {
1204
+ updateLine(component, "failed", `${upgraded.failed} after the marketplace refresh`);
1205
+ return false;
1206
+ }
1162
1207
  const newHooks = upgraded && upgraded.path ? readOrNull(path.join(upgraded.path, "hooks", "codex.json")) : null;
1163
1208
  const hooksChanged = oldHooks && newHooks && !oldHooks.equals(newHooks);
1164
1209
  if (!runHostSteps(component, "codex", executable, [steps[1]])) return false;
1165
1210
  const after = codexKeel(executable);
1211
+ if (after && after.failed) {
1212
+ updateLine(component, "failed", `${after.failed} after the update, so its result is unverified`);
1213
+ return false;
1214
+ }
1166
1215
  updateLine(
1167
1216
  component,
1168
1217
  versionChange(installed.version, after && after.version),
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@christang/keel",
3
- "version": "5.140.0",
3
+ "version": "5.142.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@christang/keel",
9
- "version": "5.140.0",
9
+ "version": "5.142.0",
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.140.0",
5
+ "version": "5.142.0",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
@@ -19,6 +19,7 @@
19
19
  "README.md",
20
20
  "npm-shrinkwrap.json",
21
21
  "plugins/",
22
+ ".claude-plugin/plugin.json",
22
23
  "!**/__pycache__",
23
24
  "!**/*.pyc"
24
25
  ],
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keel",
3
- "version": "5.140.0",
3
+ "version": "5.142.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.140.0",
3
+ "version": "5.142.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",
@@ -62,9 +62,9 @@ function bumpPackageFiles(newVersion) {
62
62
  process.stdout.write(" updated npm-shrinkwrap.json\n");
63
63
  }
64
64
 
65
- // On Claude the plugin is the tagged repository tree. Its root manifest carries
66
- // the release version, and Keel's marketplace entry names that version and the
67
- // tag it installs from git. All three move, or a refresh installs the old tree.
65
+ // On Claude the plugin is the npm package (#337). Its root manifest carries the
66
+ // release version, and Keel's marketplace entry names that version and the
67
+ // package version it installs. All three move, or a refresh installs the old one.
68
68
  function bumpClaudeMarketplace(newVersion) {
69
69
  const manifestRel = ".claude-plugin/plugin.json";
70
70
  const manifestPath = path.join(ROOT, manifestRel);
@@ -81,12 +81,12 @@ function bumpClaudeMarketplace(newVersion) {
81
81
  !entry
82
82
  || !entry.source
83
83
  || typeof entry.source !== "object"
84
- || entry.source.source !== "url"
84
+ || entry.source.source !== "npm"
85
85
  ) {
86
- fail(`expected a git-sourced keel entry in ${relPath}`);
86
+ fail(`expected an npm-sourced keel entry in ${relPath}`);
87
87
  }
88
88
  entry.version = newVersion;
89
- entry.source.ref = `v${newVersion}`;
89
+ entry.source.version = newVersion;
90
90
  writeJson(filePath, market);
91
91
  process.stdout.write(` updated ${relPath}\n`);
92
92
  }
@@ -11,6 +11,7 @@ import re
11
11
  import shutil
12
12
  import subprocess
13
13
  import sys
14
+ import tarfile
14
15
  import tempfile
15
16
  import threading
16
17
  import time
@@ -47,8 +48,8 @@ REQUIRED_SCRIPTS = [
47
48
  "scripts/validate_plugin.py",
48
49
  ]
49
50
 
50
- PACKAGE_VERSION = "5.140.0"
51
- PROTOCOL_VERSION = "5.140.0"
51
+ PACKAGE_VERSION = "5.142.0"
52
+ PROTOCOL_VERSION = "5.142.0"
52
53
  LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
53
54
  OPENSPEC_SCHEMA_NAME = "keel-spec-driven"
54
55
  # Mirrors KEEL_PACKAGE_NAME in scripts/install_to_repo.py, one of the two
@@ -8834,10 +8835,10 @@ def validate_version_alignment_scenario() -> int:
8834
8835
  )
8835
8836
  return 1
8836
8837
 
8837
- # M5 — on Claude the plugin is the tagged repository: the root manifest
8838
- # carries the version, and the marketplace entry names it and the tag it
8839
- # installs, so all three are version markers, and the script that moves
8840
- # every marker has to move them.
8838
+ # M5 — on Claude the plugin is the npm package: the root manifest carries
8839
+ # the version, and the marketplace entry names it and the package version
8840
+ # it installs, so all three are version markers, and the script that moves
8841
+ # every marker has to move them (#337).
8841
8842
  def claude_entry_versions(root: Path) -> dict:
8842
8843
  market = json.loads(
8843
8844
  (root / ".claude-plugin/marketplace.json").read_text(encoding="utf-8")
@@ -8846,10 +8847,9 @@ def validate_version_alignment_scenario() -> int:
8846
8847
  (e for e in market.get("plugins", []) if e.get("name") == "keel"), {}
8847
8848
  )
8848
8849
  source = entry.get("source") if isinstance(entry.get("source"), dict) else {}
8849
- ref = source.get("ref")
8850
8850
  return {
8851
8851
  "version": entry.get("version"),
8852
- "source.ref": ref[1:] if isinstance(ref, str) and ref.startswith("v") else ref,
8852
+ "source.version": source.get("version"),
8853
8853
  }
8854
8854
 
8855
8855
  def root_manifest_version(root: Path) -> str | None:
@@ -21879,7 +21879,7 @@ def validate_native_plugin_manifests_scenario() -> int:
21879
21879
  ),
21880
21880
  None,
21881
21881
  )
21882
- # M1 — on Claude the plugin is the tagged repository tree, and the manifest
21882
+ # M1 — on Claude the plugin is the npm package's tree, and the manifest
21883
21883
  # at its root is the one Claude manifest, so a directory entry nobody here
21884
21884
  # controls only has to say where the repository is.
21885
21885
  root_manifest_path = ROOT / ".claude-plugin/plugin.json"
@@ -21981,15 +21981,15 @@ def validate_native_plugin_manifests_scenario() -> int:
21981
21981
  )
21982
21982
  return 1
21983
21983
 
21984
- # M2 — Keel's own entry installs the same tagged tree the official
21985
- # directory would, from git. It pins the tag rather than a commit because
21986
- # the file is part of the commit it would have to name, and it restates no
21987
- # component, so the root manifest stays the only place they are declared.
21984
+ # M2 — Keel's own entry installs the npm package the CLI comes from, at
21985
+ # exactly this release (#337). It restates no component, so the root
21986
+ # manifest stays the only place they are declared, and the package has to
21987
+ # ship that manifest or the installed plugin has no components at all.
21988
21988
  source = (claude_entry or {}).get("source")
21989
21989
  want_source = {
21990
- "source": "url",
21991
- "url": KEEL_REPOSITORY_GIT_URL,
21992
- "ref": f"v{package_version}",
21990
+ "source": "npm",
21991
+ "package": "@christang/keel",
21992
+ "version": package_version,
21993
21993
  }
21994
21994
  restated = [
21995
21995
  key for key in ("skills", "agents", "hooks") if key in (claude_entry or {})
@@ -22001,7 +22001,7 @@ def validate_native_plugin_manifests_scenario() -> int:
22001
22001
  ):
22002
22002
  report(
22003
22003
  "native-plugin-manifests claude marketplace entry is not the "
22004
- f"tagged repository at v{package_version}: source {source!r}, "
22004
+ f"npm package at {package_version}: source {source!r}, "
22005
22005
  f"version {(claude_entry or {}).get('version')!r}, restated "
22006
22006
  f"components {restated!r}"
22007
22007
  )
@@ -22035,6 +22035,7 @@ def validate_native_plugin_manifests_scenario() -> int:
22035
22035
  for name, ok in (
22036
22036
  ("bin/keel", modes.get("bin/keel", 0) & 0o111),
22037
22037
  ("npm-shrinkwrap.json", "npm-shrinkwrap.json" in modes),
22038
+ (".claude-plugin/plugin.json", ".claude-plugin/plugin.json" in modes),
22038
22039
  )
22039
22040
  if not ok
22040
22041
  ]
@@ -22561,9 +22562,6 @@ def validate_native_plugin_session_start_scenario() -> int:
22561
22562
  # one independently: the plugin's by planting a manifest beside a copy of the
22562
22563
  # shipping hook, the CLI's by what the fake CLI prints, and the repository's by
22563
22564
  # the managed block in its AGENTS.md.
22564
- # Where the Claude plugin is fetched from, by Keel's marketplace and by the
22565
- # official directory entry each release states.
22566
- KEEL_REPOSITORY_GIT_URL = "https://github.com/TanglmChris/keel.git"
22567
22565
  VERSION_DRIFT_STATEMENT = "runtime versions disagree"
22568
22566
  # How an update applies: the hooks are fixed when the plugin loads, and the
22569
22567
  # host's `/reload-plugins` reloads it in the running session (#164). A restart
@@ -23640,6 +23638,14 @@ const path = require("path");
23640
23638
  const host = process.env.FAKE_HOST;
23641
23639
  const args = process.argv.slice(2);
23642
23640
  fs.appendFileSync(process.env.FAKE_LOG, JSON.stringify([host, ...args]) + "\n");
23641
+ // FAKE_LIST_SLEEP_<HOST> holds `plugin list --json` for N seconds, and
23642
+ // FAKE_LIST_EXIT_<HOST> makes it exit with that status (#354).
23643
+ if (args.join(" ") === "plugin list --json") {
23644
+ const hold = Number(process.env[`FAKE_LIST_SLEEP_${host.toUpperCase()}`] || "0");
23645
+ if (hold > 0) Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, hold * 1000);
23646
+ const code = process.env[`FAKE_LIST_EXIT_${host.toUpperCase()}`];
23647
+ if (code) process.exit(Number(code));
23648
+ }
23643
23649
  const stateFile = process.env.FAKE_STATE;
23644
23650
  const state = fs.existsSync(stateFile) ? JSON.parse(fs.readFileSync(stateFile, "utf8")) : {};
23645
23651
  const save = () => fs.writeFileSync(stateFile, JSON.stringify(state));
@@ -23836,6 +23842,98 @@ OVERLAY_BLOCK_RE = re.compile(
23836
23842
  )
23837
23843
 
23838
23844
 
23845
+ def validate_update_host_query_timeout_scenario() -> int:
23846
+ """Issue #354: a hung or failed host query is `failed`, never `absent`.
23847
+
23848
+ `plugin list --json` once hung for minutes through a proxy; every host call
23849
+ had five minutes, and a query that failed read as a host with no Keel.
23850
+ """
23851
+ label = "update-host-query-timeout:"
23852
+ with tempfile.TemporaryDirectory(prefix="keel-update-354-", ignore_cleanup_errors=True) as raw:
23853
+ tmp = Path(raw)
23854
+ fake = tmp / "fake.js"
23855
+ write_text(fake, UPDATE_FAKE)
23856
+ launchers = {}
23857
+ for host in ("npm", "claude", "codex"):
23858
+ launcher = tmp / f"fake-{host}"
23859
+ write_text(launcher, f'#!/bin/sh\nFAKE_HOST={host} exec node "{fake}" "$@"\n')
23860
+ launcher.chmod(0o755)
23861
+ launchers[host] = launcher
23862
+ source = tmp / "codex-source"
23863
+ write_text(source / "hooks/codex.json", "{}\n")
23864
+
23865
+ def update(*extra: str, env_extra: dict[str, str]):
23866
+ log = tmp / "log.jsonl"
23867
+ state = tmp / "state.json"
23868
+ for stale in (log, state):
23869
+ if stale.exists():
23870
+ stale.unlink()
23871
+ log.write_text("")
23872
+ env = dict(os.environ)
23873
+ env.update({
23874
+ "KEEL_UPDATE_NPM": str(launchers["npm"]),
23875
+ "KEEL_UPDATE_CLAUDE": str(launchers["claude"]),
23876
+ "KEEL_UPDATE_CODEX": str(launchers["codex"]),
23877
+ "KEEL_UPDATE_QUERY_TIMEOUT_MS": "1500",
23878
+ "CODEX_HOME": str(tmp / "codex-home"),
23879
+ "FAKE_LOG": str(log), "FAKE_STATE": str(state),
23880
+ "FAKE_CODEX_SOURCE": str(source),
23881
+ })
23882
+ env.pop("KEEL_UPDATE_SOURCE", None)
23883
+ env.update(env_extra)
23884
+ started = time.monotonic()
23885
+ result = subprocess.run(["node", str(ROOT / "bin/keel.js"), "--update", *extra], cwd=tmp, env=env,
23886
+ text=True, capture_output=True, check=False, timeout=120)
23887
+ calls = [json.loads(line) for line in log.read_text().splitlines() if line.strip()]
23888
+ return result, calls, time.monotonic() - started
23889
+
23890
+ def line(output: str, component: str) -> str:
23891
+ return next((l for l in output.splitlines() if l.startswith(f"keel update: {component}:")), "")
23892
+
23893
+ result, _, _ = update(env_extra={"FAKE_LIST_EXIT_CLAUDE": "3"})
23894
+ claude = line(result.stdout, "claude plugin")
23895
+ if "absent" in claude:
23896
+ report(f"{label} a claude plugin list --json that exited 3 was reported absent: {claude!r}")
23897
+ return 1
23898
+ if "failed" not in claude or "exited 3" not in claude:
23899
+ report(f"{label} a claude plugin list --json that exited 3 does not read failed with exited 3: {claude!r}")
23900
+ return 1
23901
+
23902
+ result, calls, took = update(env_extra={"FAKE_LIST_SLEEP_CODEX": "10"})
23903
+ codex = line(result.stdout, "codex plugin")
23904
+ if "absent" in codex:
23905
+ report(f"{label} a hung codex plugin list --json was reported absent: {codex!r}")
23906
+ return 1
23907
+ for needle in ("failed", "codex plugin list --json", "timed out after 1.5 s"):
23908
+ if needle not in codex:
23909
+ report(f"{label} the hung-query line does not name {needle!r}: {codex!r}")
23910
+ return 1
23911
+ if any(c[:4] == ["codex", "plugin", "marketplace", "upgrade"] for c in calls):
23912
+ report(f"{label} a Codex update command ran after its query failed: {calls!r}")
23913
+ return 1
23914
+ if "updated" not in line(result.stdout, "claude plugin"):
23915
+ report(f"{label} the Claude line did not still report its update: {result.stdout!r}")
23916
+ return 1
23917
+ if result.returncode == 0:
23918
+ report(f"{label} a failed query left keel --update exiting 0.")
23919
+ return 1
23920
+ if took > 9:
23921
+ report(f"{label} the hung query held keel --update for {took:.1f} s, past its 1.5 s limit.")
23922
+ return 1
23923
+
23924
+ result, _, _ = update(env_extra={"KEEL_UPDATE_CODEX": str(tmp / "no-such-codex")})
23925
+ if "absent" not in line(result.stdout, "codex plugin"):
23926
+ report(f"{label} a missing codex executable no longer reads absent: {result.stdout!r}")
23927
+ return 1
23928
+
23929
+ result, _, _ = update("--dry-run", env_extra={"FAKE_LIST_SLEEP_CODEX": "10"})
23930
+ if result.returncode != 0:
23931
+ report(f"{label} --dry-run with a hung query exited {result.returncode}: {result.stdout!r}")
23932
+ return 1
23933
+ report("update-host-query-timeout scenario passed.")
23934
+ return 0
23935
+
23936
+
23839
23937
  def validate_update_codex_refresh_retry_scenario() -> int:
23840
23938
  """Issue #329: a slow link can cut Codex's whole-repository marketplace clone.
23841
23939
 
@@ -24252,39 +24350,37 @@ def validate_release_notes_name_the_directory_branch_scenario() -> int:
24252
24350
 
24253
24351
 
24254
24352
  def stage_claude_market_under_test(tmp: Path) -> tuple[Path, str, str] | str:
24255
- """A Claude marketplace that installs this tree rather than GitHub's.
24256
-
24257
- The committed entry installs the Keel repository at this release's tag,
24258
- which does not exist until the release lands, and at a tag that does exist
24259
- it installs GitHub's copy and tests nothing here. So an install smoke
24260
- stages the working tree — tracked and untracked-but-not-ignored files, as
24261
- they are on disk — as a scratch git repository tagged the same way, and
24262
- puts it behind a copy of the committed entry whose URL points at it and
24263
- whose other fields are unchanged. The host then fetches it through git and
24264
- installs its dependencies exactly as it would from GitHub. A sentinel only
24265
- the staged tree carries lets the caller prove which copy was installed.
24266
- Returns the marketplace directory, its name, and the sentinel, or a failure
24267
- message.
24353
+ """A Claude marketplace that installs this tree's npm package, not npm's.
24354
+
24355
+ The committed entry installs `@christang/keel` from npm at this release's
24356
+ version, which is not published until the release lands, and a published
24357
+ version installs npm's copy and tests nothing here. An npm source also
24358
+ refuses a local folder or `file:` package (#337). So an install smoke packs
24359
+ this tree with `npm pack`, unpacks the tarball — exactly the files the
24360
+ package publishes — and serves it as a scratch git repository behind a copy
24361
+ of the committed entry whose source points at it and whose other fields are
24362
+ unchanged. The host then copies it and installs its dependencies as it
24363
+ would from npm; only the transport differs. A sentinel only the staged
24364
+ package carries lets the caller prove which copy was installed. Returns the
24365
+ marketplace directory, its name, and the sentinel, or a failure message.
24268
24366
  """
24269
24367
  git = shutil.which("git")
24270
- if git is None:
24271
- return "needs git to stage the tree under test."
24272
- listed = subprocess.run(
24273
- [git, "ls-files", "-z", "--cached", "--others", "--exclude-standard"],
24274
- cwd=ROOT,
24275
- capture_output=True,
24276
- check=False,
24368
+ npm = shutil.which("npm")
24369
+ if git is None or npm is None:
24370
+ return "needs git and npm to stage the package under test."
24371
+ packs = tmp / "packed"
24372
+ packs.mkdir(parents=True, exist_ok=True)
24373
+ packed = subprocess.run(
24374
+ [npm, "pack", "--json", "--pack-destination", str(packs)],
24375
+ cwd=ROOT, capture_output=True, text=True, check=False,
24277
24376
  )
24278
- if listed.returncode != 0:
24279
- return "git ls-files failed: " + listed.stderr.decode("utf-8", "replace")
24280
- staged = tmp / "keel-under-test"
24281
- for relative in filter(None, listed.stdout.decode("utf-8").split("\0")):
24282
- source = ROOT / relative
24283
- if not source.is_file():
24284
- continue
24285
- target = staged / relative
24286
- target.parent.mkdir(parents=True, exist_ok=True)
24287
- shutil.copy2(source, target)
24377
+ try:
24378
+ tarball = packs / json.loads(packed.stdout)[0]["filename"]
24379
+ except (ValueError, KeyError, IndexError):
24380
+ return "npm pack failed: " + (packed.stderr or packed.stdout).strip()[:400]
24381
+ with tarfile.open(tarball) as archive:
24382
+ archive.extractall(packs, filter="data")
24383
+ staged = packs / "package"
24288
24384
  sentinel = ".keel-package-under-test"
24289
24385
  write_text(staged / sentinel, "\n")
24290
24386
  committed = json.loads(
@@ -24293,22 +24389,20 @@ def stage_claude_market_under_test(tmp: Path) -> tuple[Path, str, str] | str:
24293
24389
  entry = next(
24294
24390
  (e for e in committed.get("plugins", []) if e.get("name") == "keel"), None
24295
24391
  )
24296
- source_field = (entry or {}).get("source")
24297
- if not isinstance(source_field, dict) or not source_field.get("ref"):
24298
- return f"the committed Claude entry pins no git ref: {source_field!r}"
24392
+ if not isinstance((entry or {}).get("source"), dict):
24393
+ return f"the committed Claude entry has no source object: {entry!r}"
24299
24394
  identity = ["-c", "user.name=keel", "-c", "user.email=keel@invalid"]
24300
24395
  for args in (
24301
24396
  ["init", "-q"],
24302
24397
  ["add", "-A"],
24303
- [*identity, "commit", "-q", "-m", "tree under test"],
24304
- ["tag", source_field["ref"]],
24398
+ [*identity, "commit", "-q", "-m", "package under test"],
24305
24399
  ):
24306
24400
  done = subprocess.run(
24307
24401
  [git, *args], cwd=staged, capture_output=True, text=True, check=False
24308
24402
  )
24309
24403
  if done.returncode != 0:
24310
- return f"git {args[-1]} failed staging the tree: {done.stderr.strip()}"
24311
- source_field["url"] = staged.resolve().as_uri()
24404
+ return f"git {args[-1]} failed staging the package: {done.stderr.strip()}"
24405
+ entry["source"] = {"source": "url", "url": staged.resolve().as_uri()}
24312
24406
  market = tmp / "claude-market"
24313
24407
  write_text(
24314
24408
  market / ".claude-plugin/marketplace.json",
@@ -24852,7 +24946,7 @@ def validate_native_plugin_marketplaces_scenario() -> int:
24852
24946
  "which does not carry the sentinel the staged tree does."
24853
24947
  )
24854
24948
  return 1
24855
- # M4 — the git install is a working plugin: the host loaded the
24949
+ # M4 — the packaged install is a working plugin: the host loaded the
24856
24950
  # skills and both hooks from the root manifest, and installed the
24857
24951
  # OpenSpec the lockfile pins, since nothing in the tree carries it.
24858
24952
  details = run_claude("plugin", "details", f"keel@{claude_market_name}")
@@ -24870,12 +24964,12 @@ def validate_native_plugin_marketplaces_scenario() -> int:
24870
24964
  if details.returncode != 0:
24871
24965
  report(
24872
24966
  "native-plugin-marketplaces claude plugin details failed for "
24873
- f"the git-installed plugin: {(details.stderr or details_text).strip()!r}"
24967
+ f"the packaged plugin: {(details.stderr or details_text).strip()!r}"
24874
24968
  )
24875
24969
  return 1
24876
24970
  if missing:
24877
24971
  report(
24878
- "native-plugin-marketplaces the git-installed plugin lacks "
24972
+ "native-plugin-marketplaces the packaged plugin lacks "
24879
24973
  f"{missing!r} in claude plugin details: {details_text!r}"
24880
24974
  )
24881
24975
  return 1
@@ -24890,7 +24984,7 @@ def validate_native_plugin_marketplaces_scenario() -> int:
24890
24984
  openspec_bin = install_path / "node_modules/.bin/openspec"
24891
24985
  if not openspec_bin.exists():
24892
24986
  report(
24893
- "native-plugin-marketplaces the git-installed plugin has no "
24987
+ "native-plugin-marketplaces the packaged plugin has no "
24894
24988
  f"installed OpenSpec at {openspec_bin}; the host did not "
24895
24989
  "install the tree's dependencies."
24896
24990
  )
@@ -24904,13 +24998,13 @@ def validate_native_plugin_marketplaces_scenario() -> int:
24904
24998
  pinned = shrinkwrap_openspec_version()
24905
24999
  if probe.returncode != 0:
24906
25000
  report(
24907
- "native-plugin-marketplaces the git-installed OpenSpec failed "
25001
+ "native-plugin-marketplaces the packaged OpenSpec failed "
24908
25002
  f"to run: {(probe.stderr or probe.stdout).strip()!r}"
24909
25003
  )
24910
25004
  return 1
24911
25005
  if pinned not in probe.stdout:
24912
25006
  report(
24913
- "native-plugin-marketplaces the git-installed plugin does not "
25007
+ "native-plugin-marketplaces the packaged plugin does not "
24914
25008
  f"carry the pinned OpenSpec {pinned}: {probe.stdout.strip()!r}"
24915
25009
  )
24916
25010
  return 1
@@ -41128,6 +41222,7 @@ SCENARIOS: tuple = (
41128
41222
  ("adopted-update-is-silent-unless-reload", validate_adopted_update_is_silent_unless_reload_scenario),
41129
41223
  ("update-covers-installed-hosts", validate_update_covers_installed_hosts_scenario),
41130
41224
  ("update-codex-refresh-retry", validate_update_codex_refresh_retry_scenario),
41225
+ ("update-host-query-timeout", validate_update_host_query_timeout_scenario),
41131
41226
  ("refresh-covers-every-target", validate_refresh_covers_every_target_scenario),
41132
41227
  ("directory-branch-advances", validate_directory_branch_advances_scenario),
41133
41228
  ("release-notes-name-the-directory-branch", validate_release_notes_name_the_directory_branch_scenario),